Пример #1
0
        private void ReadSpectralTableBlock(BinaryReader reader, ref SpectralTableBlock spectralTableBlock)
        {
            int tableBlockSize = 0;

            for (int i = 0; i < FileHeader.NumberOfSpectralTables; i++)
            {
                SpectralTable table = new SpectralTable();
                table.Numberofpairs = reader.ReadInt32();
                if (table.Numberofpairs <= 0)
                {
                    throw new InvalidTM25Exception("Number of DataPairs must be > 0");
                }
                table.Data      = new List <SpectralData>();
                tableBlockSize += 4 * ((2 * table.Numberofpairs) + 1);
                for (int j = 0; j < table.Numberofpairs; j++)
                {
                    SpectralDataPair dataPair = new SpectralDataPair();
                    dataPair.Wavelength = reader.ReadSingle();
                    if (dataPair.Wavelength <= 0.0)
                    {
                        throw new InvalidTM25Exception("Spectral Data Wavelength Cannot be 0 or negative");
                    }
                    dataPair.RelativeWeight = reader.ReadSingle();
                    if (dataPair.RelativeWeight < 0.0)
                    {
                        throw new InvalidTM25Exception("Relative Weights Cannot be negative");
                    }
                    table.Data.Add(dataPair);
                }
                spectralTableBlock.SpectralTables.Add(table);
            }

            if (tableBlockSize % 32 != 0)
            {
                int numberToPad = (((tableBlockSize / 32) + 1) * 32 - tableBlockSize) / 4;
                for (int i = 0; i < numberToPad; i++)
                {
                    reader.ReadSingle();
                    spectralTableBlock.SpectralTables[FileHeader.NumberOfSpectralTables - 1].Data.Add(new SpectralPadding());
                }
            }
        }
Пример #2
0
        public IESTM25File(string fileName, ulong numrays)
        {
            using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
            {
                FileHeaderBlock fileHeader = new FileHeaderBlock();
                ReadHeaderBlock(reader, ref fileHeader);
                if (!fileHeader.CheckHeaderBlockisValid())
                {
                    throw new InvalidTM25Exception("Header Block Not Correct Size", "");
                }
                FileHeader = fileHeader;

                KnownDataFlagBlock knownDataFlag = new KnownDataFlagBlock();
                ReadDataFlagBlock(reader, ref knownDataFlag);
                if (!knownDataFlag.CheckKnownDataFlagBlockisValid())
                {
                    throw new InvalidTM25Exception("Data Flag Block Not Correct Size", "");
                }
                DataFlags = knownDataFlag;

                DescriptionHeaderBlock descriptionHeader = new DescriptionHeaderBlock();
                ReadDescriptionHeaderBlock(reader, ref descriptionHeader);
                if (!descriptionHeader.CheckDescriptionBlockisValid())
                {
                    throw new InvalidTM25Exception("Description Header Block is Not Correct Size", "");
                }
                DescriptionHeader = descriptionHeader;

                if (FileHeader.NumberOfSpectralTables > 0)
                {
                    SpectralTableBlock spectralTables = new SpectralTableBlock();
                    spectralTables.SpectralTables = new List <SpectralTable>();
                    ReadSpectralTableBlock(reader, ref spectralTables);
                    if (!spectralTables.CheckSpectralTableisValid())
                    {
                        throw new InvalidTM25Exception("Spectral Table Block is Not Correct Size", "");
                    }
                    SpectralTables = spectralTables;
                }

                if (FileHeader.NumberOfAdditionalRayDataItemsPerRay > 0)
                {
                    AdditionalRayDataColumnLabelsBlock columnLabelsBlock = new AdditionalRayDataColumnLabelsBlock();
                    ReadColumnsLabelsBlock(reader, ref columnLabelsBlock);
                    if (!columnLabelsBlock.CheckAdditionalRayDataColumnisValid())
                    {
                        throw new InvalidTM25Exception("Additional Ray Data Columns Block is incorrect");
                    }
                    AdditionalRayDataColumnLabels = columnLabelsBlock;
                }

                if (FileHeader.SizeOfAdditionalTextBlock > 0)
                {
                    AdditionalTextBlock additionalTextBlock = new AdditionalTextBlock();
                    ReadAdditionalTextBlock(reader, ref additionalTextBlock);
                    AdditionalText = additionalTextBlock;
                }

                RayDataLinesBlock rayDataLines = new RayDataLinesBlock();
                rayDataLines.Rays = new float[FileHeader.NumberOfRays][];
                ReadPartialRayDataBlock(reader, ref rayDataLines, numrays);
                rayDataLines.RayDataMembers = TM25HelperFunctions.GetListofRayDataFieldsPresent(DataFlags, FileHeader, AdditionalRayDataColumnLabels);
                RayData = rayDataLines;
            }
        }