diff --git a/CSMatIO.sln b/CSMatIO.sln index 9cb1aa6..2c056a8 100644 --- a/CSMatIO.sln +++ b/CSMatIO.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +VisualStudioVersion = 12.0.40629.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csmatio", "src\csmatio.csproj", "{D6EB17BF-9074-484F-9950-E06169A3C39D}" EndProject diff --git a/src/AssemblyInfo.cs b/src/AssemblyInfo.cs index 6a98f88..d390e56 100644 --- a/src/AssemblyInfo.cs +++ b/src/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("csmatio")] -[assembly: AssemblyCopyright("Copyright © 2007, David A. Zier")] +[assembly: AssemblyCopyright("Copyright © 2016, Mike Williams, Copyright © 2007, David A. Zier")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -29,5 +29,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("1.0.0")] -[assembly: AssemblyFileVersion("1.0.0")] +[assembly: AssemblyVersion("1.0.1")] +[assembly: AssemblyFileVersion("1.0.1")] diff --git a/src/CSMatIO.nuspec b/src/CSMatIO.nuspec index da8304d..06034d5 100644 --- a/src/CSMatIO.nuspec +++ b/src/CSMatIO.nuspec @@ -2,8 +2,8 @@ CSMatIO - 1.0.0 - Sérgio aka AlienEnginner + 1.0.1 + Sérgio aka AlienEnginner, Mike Williams https://raw.githubusercontent.com/AlienEngineer/CSMatIO/master/LICENSE https://github.com/AlienEngineer/CSMatIO/wiki @@ -12,7 +12,7 @@ - Copyright (c) 2015 AlienEngineer + Copyright (c) 2016 Mike Williams, Copyright (c) 2015 AlienEngineer Matlab csmatio diff --git a/src/io/MatFileReader.cs b/src/io/MatFileReader.cs index 674e6d4..3e1f1e1 100644 --- a/src/io/MatFileReader.cs +++ b/src/io/MatFileReader.cs @@ -35,6 +35,7 @@ namespace csmatio.io /// Hashtable content = mfr.Content; /// /// + /// Mike Williams (mswillia) /// David Zier (david.zier@gmail.com) public class MatFileReader { @@ -55,7 +56,6 @@ public class MatFileReader /// private MatFileFilter _filter; - /// /// Creates instance of MatFileReader and reads MAT-file with then name /// fileName. @@ -81,22 +81,26 @@ public MatFileReader(string fileName) : /// The name of the MAT-file to open /// MatFileFilter public MatFileReader(string fileName, MatFileFilter filter) + : this(new FileStream(fileName, FileMode.Open, FileAccess.Read), filter) + { + } + + /// + /// Creates instance of MatFileReader and reads MAT-file from the + /// FileStream. + /// + /// + /// Results are filtered by MatFileFilter. Arrays that do not meet + /// filter match condition will not be available in results. + /// + /// The stream the MAT-stream will read + /// MatFileFilter + public MatFileReader(Stream dataIn, MatFileFilter filter) { _filter = filter; _data = new Dictionary(); - // Try to open up the file as read-only - FileStream dataIn; - try - { - dataIn = new FileStream(fileName, FileMode.Open, FileAccess.Read); - } - catch (FileNotFoundException) - { - throw new MatlabIOException("Could not open the file '" + fileName + "' for reading!"); - } - - // try and read in the file until completed + // try and read in the stream until completed try { ReadHeader(dataIn); @@ -112,14 +116,14 @@ public MatFileReader(string fileName, MatFileFilter filter) } catch (IOException e) { - throw new MatlabIOException("Error in reading MAT-file '" + fileName + "':\n" + e.ToString()); + throw new MatlabIOException("Error in reading MAT-stream:\n" + e.ToString()); } finally { dataIn.Close(); } } - + /// /// Gets MAT-file header. /// @@ -208,7 +212,7 @@ private Stream Inflate(Stream buf, int numOfBytes) return inflatedStream; #endif #if NET40 || NET45 - // skip CRC (at end) and zip format (0x789C at begin) + // skip CRC (at end) and zip format (0x789C at begin) buf.Position += 2; numOfBytes -= 6; @@ -240,7 +244,7 @@ private Stream Inflate(Stream buf, int numOfBytes) } while (data != -1); } - decompressedStream.Position = 0; + decompressedStream.Position = 0; return decompressedStream; #endif } @@ -412,14 +416,14 @@ private MLArray ReadMatrix(Stream buf, bool isRoot) //read real tag = new ISMatTag(buf); tag.ReadToByteBuffer(((MLNumericArray)mlArray).RealByteBuffer, - (IByteStorageSupport)mlArray); + (IByteStorageSupport)mlArray); // read complex if (mlArray.IsComplex) { tag = new ISMatTag(buf); tag.ReadToByteBuffer(((MLNumericArray)mlArray).ImaginaryByteBuffer, - (IByteStorageSupport)mlArray); + (IByteStorageSupport)mlArray); } break; case MLArray.mxSINGLE_CLASS: @@ -534,14 +538,14 @@ private MLArray ReadMatrix(Stream buf, bool isRoot) //read real tag = new ISMatTag(buf); tag.ReadToByteBuffer(((MLNumericArray)mlArray).RealByteBuffer, - (IByteStorageSupport)mlArray); + (IByteStorageSupport)mlArray); // read complex if (mlArray.IsComplex) { tag = new ISMatTag(buf); - tag.ReadToByteBuffer(((MLNumericArray)mlArray).ImaginaryByteBuffer, - (IByteStorageSupport)mlArray); + tag.ReadToByteBuffer(((MLNumericArray)mlArray).ImaginaryByteBuffer, + (IByteStorageSupport)mlArray); } break; case MLArray.mxINT64_CLASS: @@ -549,14 +553,14 @@ private MLArray ReadMatrix(Stream buf, bool isRoot) //read real tag = new ISMatTag(buf); tag.ReadToByteBuffer(((MLNumericArray)mlArray).RealByteBuffer, - (IByteStorageSupport)mlArray); + (IByteStorageSupport)mlArray); // read complex if (mlArray.IsComplex) { tag = new ISMatTag(buf); - tag.ReadToByteBuffer(((MLNumericArray)mlArray).ImaginaryByteBuffer, - (IByteStorageSupport)mlArray); + tag.ReadToByteBuffer(((MLNumericArray)mlArray).ImaginaryByteBuffer, + (IByteStorageSupport)mlArray); } break; case MLArray.mxCHAR_CLASS: @@ -773,7 +777,7 @@ public ISMatTag(Stream buf) : ///// //public int Size //{ - // get { return (int)Buf.BaseStream.Length; } + // get { return (int)Buf.BaseStream.Length; } //} /// @@ -781,7 +785,7 @@ public ISMatTag(Stream buf) : /// /// ByteBuffer /// ByteStorageSupport - public void ReadToByteBuffer( ByteBuffer buff, IByteStorageSupport storage ) + public void ReadToByteBuffer(ByteBuffer buff, IByteStorageSupport storage) { MatFileInputStream mfis = new MatFileInputStream(Buf, _type); int elements = _size / SizeOf();