Ejemplo n.º 1
0
        /// <summary>
        /// Enumerates the messages in the underlying stream.
        /// </summary>
        /// <returns>The messages in the GRIB 2 stream.</returns>
        public IEnumerable <Message> ReadMessages()
        {
            reader.Seek(0, SeekOrigin.Begin);

            do
            {
                var indicatorSection      = IndicatorSection.BuildFrom(reader);
                var identificationSection = IdentificationSection.BuildFrom(reader);

                var message = new Message(indicatorSection, identificationSection);

                LocalUseSection localUseSection = null;
                do
                {
                    if (reader.PeekSection().Is(SectionCode.LocalUseSection))
                    {
                        localUseSection = LocalUseSection.BuildFrom(reader);
                    }

                    while (reader.PeekSection().Is(SectionCode.GridDefinitionSection))
                    {
                        var gridDefinitionSection = GridDefinitionSection.BuildFrom(reader);

                        while (reader.PeekSection().Is(SectionCode.ProductDefinitionSection))
                        {
                            var productDefinitionSection  = ProductDefinitionSection.BuildFrom(reader, indicatorSection.Discipline);
                            var dataRepresentationSection = DataRepresentationSection.BuildFrom(reader);

                            var bitmapSection = BitmapSection.BuildFrom(reader, dataRepresentationSection.DataPointsNumber);

                            var dataSection = DataSection.BuildFrom(reader);

                            message.AddDataset(
                                localUseSection,
                                gridDefinitionSection,
                                productDefinitionSection,
                                dataRepresentationSection,
                                bitmapSection,
                                dataSection);
                        }
                    }
                } while (!reader.PeekSection().Is(SectionCode.EndSection));
                EndSection.BuildFrom(reader);

                // Saves and restore the current position
                // to avoid losing track of the current message
                // if a data set read happens during the enumeration
                var currentPosition = reader.Position;
                yield return(message);

                reader.Seek(currentPosition, SeekOrigin.Begin);
            } while (!reader.HasReachedStreamEnd && reader.PeekSection().Is(SectionCode.IndicatorSection));
        }
Ejemplo n.º 2
0
        public void BuildFrom_ValidGribFile_Test()
        {
            using var gribFileStream = File.OpenRead(GribFileSamples.ValidFile);
            var reader = new BufferedBinaryReader(gribFileStream);

            var indicatorSection = IndicatorSection.BuildFrom(reader);

            Check.That(indicatorSection).IsNotNull();
            Check.That(indicatorSection.GribEdition).Equals(2);
            Check.That(indicatorSection.Discipline).Equals(Discipline.MeteorologicalProducts);
            Check.That(indicatorSection.TotalLength.Sign).IsStrictlyPositive();
        }
Ejemplo n.º 3
0
 internal Message(IndicatorSection indicatorSection, IdentificationSection identificationSection)
 {
     IndicatorSection      = indicatorSection ?? throw new ArgumentNullException(nameof(indicatorSection));
     IdentificationSection = identificationSection ?? throw new ArgumentNullException(nameof(identificationSection));
     dataSets = new List <DataSet>();
 }