private void ReadBody(BinaryReader reader, int recordLength) { // First check that we have collected sufficient grid // parameters to continue parameters.VerifyAndCompleteParameters(); parameters.Build(builder); int numValues = parameters.INum.Value * parameters.JNum.Value; if (recordLength != numValues * sizeof(float)) { throw new OpenException("EarthVision Binary Grid data block is wrong size."); } float fNull = (float)parameters.ZNull.Value; for (int counter = 0; counter < numValues; ++counter) { int i = counter % parameters.INum.Value; int j = counter / parameters.INum.Value; float z = reader.ReadSingle(); if (z != fNull) { builder[i, j] = z; } } }
private void ReadHeader(ILineReader lineReader) { // TODO: Cope with truncated headers string header1 = lineReader.ReadLine(); string[] fields1 = header1.Split(separator, StringSplitOptions.RemoveEmptyEntries); parameters.JNum = Int32.Parse(fields1[1]); parameters.IInc = Double.Parse(fields1[2]); parameters.JInc = Double.Parse(fields1[3]); string header2 = lineReader.ReadLine(); string[] fields2 = header2.Split(separator, StringSplitOptions.RemoveEmptyEntries); parameters.XOrigin = Double.Parse(fields2[0]); parameters.XMax = Double.Parse(fields2[1]); parameters.YOrigin = Double.Parse(fields2[2]); parameters.YMax = Double.Parse(fields2[3]); string header3 = lineReader.ReadLine(); string[] fields3 = header3.Split(separator, StringSplitOptions.RemoveEmptyEntries); parameters.INum = Int32.Parse(fields3[0]); parameters.Orientation = Double.Parse(fields3[1]); // Two other unused fields here lineReader.ReadLine(); // Header 4 - Always seems to contain seven zeros parameters.VerifyAndCompleteParameters(); parameters.Build(builder); }
/// <summary> /// Verify that we have collected enough information from the /// header to describe the grid. /// </summary> private void VerifyHeaderCompleteness() { parameters.VerifyAndCompleteParameters(); if (name != null) { // TODO: Build a grid name from the filename name = uri.LocalPath; } }
private void OpenSurferAscii() { using (ILineReader reader = new SkippingLineReader(Location.LocalPath, blanksPattern)) { // TODO: Create a wrapper for the StreamReader which // skips comment lines and tracks line numbers try { ReadAsciiHeader(reader); parameters.VerifyAndCompleteParameters(); parameters.Build(builder); ReadAsciiBody(reader); } catch (System.FormatException) { StringBuilder message = new StringBuilder(); message.AppendFormat("Invalid grid format at line {0}", reader.PhysicalLineNumber); throw new OpenException(message.ToString()); } } }
public void Read(ILineReader lineReader, IGeoModel model) { // Pre-condition: The next line to be read will be the first line // of the header builder = model.CreateGridBuilder(); try { ReadHeader(lineReader); parameters.VerifyAndCompleteParameters(); parameters.Build(builder); ReadBody(lineReader); } catch (FormatException formatException) { StringBuilder message = new StringBuilder(); message.AppendFormat("Unable to parse ZMap file at line {0} because {1}", lineReader.PhysicalLineNumber, formatException.Message); throw new OpenException(message.ToString()); } builder.Build(); }
private void ReadHeader() { // Read the first part of the file using a LineReader using (StreamReader reader = new StreamReader(Location.LocalPath)) using (LineReader lineReader = new LineReader(reader)) { bool foundMagic = ReadMagic(lineReader); if (!foundMagic) { StringBuilder message = new StringBuilder(); message.AppendFormat("Incorrect STORM grid header at line {0}", lineReader.PhysicalLineNumber); throw new OpenException(message.ToString()); } // Skip one line lineReader.ReadLine(); // Read the grid dimensions and spacing string header1 = lineReader.ReadLine(); string[] fields1 = Regex.Split(header1.Trim(), @"\s+"); parameters.INum = Int32.Parse(fields1[0]); parameters.JNum = Int32.Parse(fields1[1]); parameters.IInc = Double.Parse(fields1[2]); parameters.JInc = Double.Parse(fields1[3]); // Read xmin xmax ymin ymax string header2 = lineReader.ReadLine(); string[] fields2 = Regex.Split(header2.Trim(), @"\s+"); parameters.XOrigin = Double.Parse(fields2[0]); parameters.XMax = Double.Parse(fields2[1]); parameters.YOrigin = Double.Parse(fields2[2]); parameters.YMax = Double.Parse(fields2[3]); parameters.VerifyAndCompleteParameters(); parameters.Build(builder); } }
private void BuildGridParameters() { Debug.Assert(builder != null); parameters.VerifyAndCompleteParameters(); parameters.Build(builder); }