/// <summary> /// Given stream and traceCount, reads the requested number /// of traces into memory. The given traceCount may exceed /// the number of traces in the file; /// in that case all the traces in the file are read. /// Assumes the stream is at the start of the file. /// </summary> public virtual ISegyFile Read(Stream stream, int traceCount, IReadingProgress progress = null) { using (var reader = new BinaryReader(stream)) { var fileHeader = ReadFileHeader(reader); var traces = new List <ITrace>(); for (int i = 0; i < traceCount; i++) { if (progress != null) { // TODO: Check if stream.Length breaks when streaming from web int percentage = (int)(100 * stream.Position / stream.Length); progress.ReportProgress(percentage); if (progress.CancellationPending) { break; } } var trace = ReadTrace(reader, fileHeader.SampleFormat, fileHeader.IsLittleEndian); if (trace == null) { break; } traces.Add(trace); } return(new SegyFile { Header = fileHeader, Traces = traces }); } }
/// <summary> /// Given stream and traceCount, reads the requested number /// of traces into memory. The given traceCount may exceed /// the number of traces in the file; /// in that case all the traces in the file are read. /// Assumes the stream is at the start of the file. /// </summary> public virtual ISegyFile Read(Stream stream, int traceCount, IReadingProgress progress = null) { using (var reader = new BinaryReader(stream)) { var fileHeader = ReadFileHeader(reader); var traces = new List<ITrace>(); for (int i = 0; i < traceCount; i++) { if (progress != null) { // TODO: Check if stream.Length breaks when streaming from web int percentage = (int)(100 * stream.Position / stream.Length); progress.ReportProgress(percentage); if (progress.CancellationPending) break; } var trace = ReadTrace(reader, fileHeader.SampleFormat, fileHeader.IsLittleEndian); if (trace == null) break; traces.Add(trace); } return new SegyFile { Header = fileHeader, Traces = traces }; } }
/// <summary> /// Given stream, reads entire SEGY file into memory. /// Assumes the stream is at the start of the file. /// </summary> public virtual ISegyFile Read(Stream stream, IReadingProgress progress = null) { return(Read(stream, int.MaxValue, progress)); }
/// <summary> /// Given a file path, reads entire SEGY file into memory /// </summary> public virtual ISegyFile Read(string path, IReadingProgress progress = null) { using (var stream = File.OpenRead(path)) return(Read(stream, progress)); }
/// <summary> /// Given stream, reads entire SEGY file into memory. /// Assumes the stream is at the start of the file. /// </summary> public virtual ISegyFile Read(Stream stream, IReadingProgress progress = null) { return Read(stream, int.MaxValue, progress); }
/// <summary> /// Given a file path, reads entire SEGY file into memory /// </summary> public virtual ISegyFile Read(string path, IReadingProgress progress = null) { using (var stream = File.OpenRead(path)) return Read(stream, progress); }