Exemplo n.º 1
0
        private static int ReadHeader(SkippingLineReader lineReader)
        {
            int numSurfaces = 0;
            // Read the header
            int searchLimit = 50;

            do
            {
                string line = lineReader.ReadLineNoSkip().Trim();
                if (Charisma.surfaceRegex.IsMatch(line))
                {
                    // The header line has been located
                    // TODO Extract the Charisma surface names, and
                    //      and determine how many there are.
                    numSurfaces = 1; // TODO: Fix numSurfaces
                    break;
                }
            }while (lineReader.PhysicalLineNumber < searchLimit);

            if (numSurfaces == 0)
            {
                throw new OpenException("No surfaces found in Charisma file");
            }
            return(numSurfaces);
        }
Exemplo n.º 2
0
        public void Open(IGeoModel model)
        {
            Debug.Assert(uri != null);
            Debug.Assert(model != null);
            builder = model.CreateGridBuilder();
            int postHeaderLine = ParseHeader();

            // Read the body of the grid, skipping comment and blank lines
            using (SkippingLineReader lineReader = new SkippingLineReader(uri.LocalPath, Cps3.commentBlanksPattern))
            {
                // Skip forward over the header
                while (lineReader.PhysicalLineNumber < postHeaderLine)
                {
                    lineReader.ReadLineNoSkip();
                }

                // Parse the body of the grid
                string line;
                int    counter = 0;
                while ((line = lineReader.ReadLine()) != null)
                {
                    string[] fields = Regex.Split(line, @"\s+");
                    foreach (string field in fields)
                    {
                        double z;
                        if (double.TryParse(field, out z))
                        {
                            int i = counter % parameters.INum.Value;
                            int j = counter / parameters.INum.Value;
                            if (z != parameters.ZNull)
                            {
                                builder[i, j] = z;
                            }
                            ++counter;
                        }
                        else
                        {
                            StringBuilder message = new StringBuilder();
                            message.AppendFormat("Bad grid data '{0}' at line {1}", field, lineReader.PhysicalLineNumber);
                            throw new OpenException(message.ToString());
                        }
                    }
                }
            }
        }