/// <summary> /// Creates instance of <c>MatFileReader</c> and reads MAT-file from the /// <c>FileStream</c>. /// </summary> /// <remarks> /// Results are filtered by <c>MatFileFilter</c>. Arrays that do not meet /// filter match condition will not be available in results. /// </remarks> /// <param name="dataIn">The stream the MAT-stream will read</param> /// <param name="filter"><c>MatFileFilter</c></param> public MatFileReader(Stream dataIn, MatFileFilter filter) { _filter = filter; _data = new Dictionary <string, MLArray>(); // try and read in the stream until completed try { ReadHeader(dataIn); for (; ;) { ReadData(dataIn); } } catch (EndOfStreamException) { // Catch to break out of the for loop } catch (IOException e) { throw new MatlabIOException("Error in reading MAT-stream:\n" + e.ToString()); } finally { dataIn.Close(); } }
/// <summary> /// Creates instance of <c>MatFileReader</c> and reads MAT-file with then name /// <c>fileName</c>. /// </summary> /// <remarks> /// Results are filtered by <c>MatFileFilter</c>. Arrays that do not meet /// filter match condition will not be available in results. /// </remarks> /// <param name="fileName">The name of the MAT-file to open</param> /// <param name="filter"><c>MatFileFilter</c></param> public MatFileReader(string fileName, MatFileFilter filter) { _filter = filter; _data = new Dictionary <string, MLArray>(); // 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 { ReadHeader(dataIn); for (; ;) { ReadData(dataIn); } } catch (EndOfStreamException) { // Catch to break out of the for loop } catch (IOException e) { throw new MatlabIOException("Error in reading MAT-file '" + fileName + "':\n" + e); } finally { dataIn.Close(); } }
/// <summary> /// Creates instance of <c>MatFileReader</c> and reads MAT-file with then name /// <c>fileName</c>. /// </summary> /// <remarks> /// Results are filtered by <c>MatFileFilter</c>. Arrays that do not meet /// filter match condition will not be available in results. /// </remarks> /// <param name="fileName">The name of the MAT-file to open</param> /// <param name="filter"><c>MatFileFilter</c></param> public MatFileReader( string fileName, MatFileFilter filter ) { _filter = filter; _data = new Dictionary<string,MLArray>(); // 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 { ReadHeader( dataIn ); for(;;) { if (dataIn.Position == dataIn.Length) break; ReadData( dataIn ); } } catch( EndOfStreamException ) { // Catch to break out of the for loop } catch( IOException e ) { throw new MatlabIOException( "Error in reading MAT-file '" + fileName + "':\n" + e.ToString() ); } dataIn.Close(); }
/// <summary> /// Creates instance of <c>MatFileReader</c> and reads MAT-file with then name /// <c>fileName</c>. /// </summary> /// <remarks> /// Results are filtered by <c>MatFileFilter</c>. Arrays that do not meet /// filter match condition will not be available in results. /// </remarks> /// <param name="fileName">The name of the MAT-file to open</param> /// <param name="filter"><c>MatFileFilter</c></param> public MatFileReader(string fileName, MatFileFilter filter) : this(new FileStream(fileName, FileMode.Open, FileAccess.Read), filter) { }