示例#1
0
 /* Constructs 'DataMapper' with DTED file data */
 public DataMapper(DTED_Data data)
 {
     fileData = data;
 }
示例#2
0
        /*
         * Function will read and parse the '*.dt1' file and
         * populate the 'DTED_buffer' parameter passed.
         */
        public void read(out DTED_Data dtedData)
        {
            BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open));

            // Declare variables to store token buffer
            string result;
            string lonInterval;
            string latInterval;
            int    numLat;
            int    numLon;

            int[][] elevGrid; // Create array of arrays where each element contains a page of each data record

            // Skip bytes to origin buffer
            reader.BaseStream.Seek((FileConstants.SIZE_UHL_RECOGNITION_SENTINEL +
                                    FileConstants.SIZE_SKIP), SeekOrigin.Current);

            // Read Longitude Origin
            buffer = reader.ReadBytes(FileConstants.SIZE_LONGITUDE_ORIGIN);
            result = Encoding.ASCII.GetString(buffer);

            // Now parse the resulting 'string' into the components of longitude
            Longitude lonOrigin = new
                                  Longitude(result.Substring(FileConstants.LOC_UHL_DEG, FileConstants.SIZE_UHL_DEG),
                                            result.Substring(FileConstants.LOC_UHL_MIN, FileConstants.SIZE_UHL_MIN),
                                            result.Substring(FileConstants.LOC_UHL_SEC, FileConstants.SIZE_UHL_SEC),
                                            result.Substring(FileConstants.LOC_UHL_DIRECTION, FileConstants.SIZE_UHL_DIRECTION));

            // Read Latitude Origin
            buffer = reader.ReadBytes(FileConstants.SIZE_LATITUDE_ORIGIN);
            result = Encoding.ASCII.GetString(buffer);

            // Now parse the resulting 'string' into the components of latitude
            Latitude latOrigin = new
                                 Latitude(result.Substring(FileConstants.LOC_UHL_DEG, FileConstants.SIZE_UHL_DEG),
                                          result.Substring(FileConstants.LOC_UHL_MIN, FileConstants.SIZE_UHL_MIN),
                                          result.Substring(FileConstants.LOC_UHL_SEC, FileConstants.SIZE_UHL_SEC),
                                          result.Substring(FileConstants.LOC_UHL_DIRECTION, FileConstants.SIZE_UHL_DIRECTION));

            // Read Longitude Interval
            buffer      = reader.ReadBytes(FileConstants.SIZE_LONGITUDE_INTERVAL);
            lonInterval = Encoding.ASCII.GetString(buffer).Insert(FileConstants.LOC_UHL_INTERVAL_DECIMAL,
                                                                  "."); // Insert decimal point at 3rd element as specified in docuement

            // Read Latitude Interval
            buffer      = reader.ReadBytes(FileConstants.SIZE_LATITUDE_INTERVAL);
            latInterval = Encoding.ASCII.GetString(buffer).Insert(FileConstants.LOC_UHL_INTERVAL_DECIMAL,
                                                                  "."); // Insert decimal point at 3rd element as specified in docuement

            // Skip past tokens that are NOT needed
            reader.BaseStream.Seek((FileConstants.SIZE_ABSOLUTE_VERTICAL_ACC +
                                    FileConstants.SIZE_UNCLASSIFIED_SECURITY +
                                    FileConstants.SIZE_UNIQUE_REFERENCE), SeekOrigin.Current);

            // Read Number of Latitude
            buffer = reader.ReadBytes(FileConstants.SIZE_NUMBER_LONGITUDE);
            numLon = int.Parse(Encoding.ASCII.GetString(buffer));

            // Read Number of Longitude
            buffer = reader.ReadBytes(FileConstants.SIZE_NUMBER_LATITUDE);
            numLat = int.Parse(Encoding.ASCII.GetString(buffer));

            elevGrid = new int[numLon][]; // Allocate 'elevData' based on size of latitude and longitude amount

            // Skip the rest of the UHL header file
            reader.BaseStream.Seek((FileConstants.SIZE_MULTIPLE_ACC + FileConstants.SIZE_RESERVED),
                                   SeekOrigin.Current);

            UHL_Header header = new UHL_Header(lonOrigin, latOrigin, lonInterval,
                                               latInterval, numLat, numLon); // Header is fully read initialize the object

            // Reader is now at start of DSI part of the file
            reader.BaseStream.Seek(FileConstants.SIZE_DSI, SeekOrigin.Current); // Skip DSI

            // Reader is now at start of ACC part of the file
            reader.BaseStream.Seek(FileConstants.SIZE_ACC, SeekOrigin.Current); // Skip ACC

            // Reader is now at the start of the 'buffer Record(s)'
            Array.Resize(ref buffer, FileConstants.SIZE_DATA_REC); // Must resize buffer to hold at least one data record

            int numBytesRead;
            int recordNum = 0;

            numBytesRead = reader.Read(buffer, 0, FileConstants.SIZE_DATA_REC);

            while (numBytesRead == FileConstants.SIZE_DATA_REC) // Check if number of bytes read was successful
            {
                elevGrid[recordNum] = parseDataRecord(buffer);
                numBytesRead        = reader.Read(buffer, 0, FileConstants.SIZE_DATA_REC);
                ++recordNum;
            }

            dtedData = new DTED_Data(header, elevGrid); // Assign paramter to newly constructed data

            reader.Close();                             // Close file stream
        }