public GRIB2Record(int disciplineNo, IGRIB2GridDefinitionSection gds, IGRIB2ProductDefinitionSection pds, IGRIB2DataRepresentationSection drs, IGribBitMapSection bms, GRIB2DataSection ds, long gdsOffset, long pdsOffset, long dataOffset) { _gdsOffset = gdsOffset; _pdsOffset = pdsOffset; _dataOffset = dataOffset; _gds = gds; _pds = pds; _drs = drs; _bms = bms; _ds = ds; _parameter = ParametersFactory.GetParameter(disciplineNo, pds.ParameterCategory, pds.ParameterNumber); }
private void ReadToDataProvider() { if (string.IsNullOrEmpty(_fileName) || !File.Exists(_fileName)) { return; } long gdsOffset = 0; // GDS offset from start of file bool startAtHeader = true; // otherwise skip to GDS bool processGDS = true; FileStream _fs = new FileStream(_fileName, FileMode.Open, FileAccess.Read); GRIB2IndicatorSection iSection = null; GRIB2IdentificationSection idSection = null; GRIB2LocalUseSection lus = null; GRIB2GridDefinitionSection gds = null; while (_fs.Position < _fs.Length) { if (startAtHeader) { // begining of record if (!SeekHeader(_fs, _fs.Length)) { goto setAttributes; } // Read Section 0 Indicator Section iSection = new GRIB2IndicatorSection(_fs); // section 0 _discipline = iSection.Displine; // Read other Sections idSection = new GRIB2IdentificationSection(_fs); // Section 1 _referenceTime = idSection.ReferenceTime; } // end startAtHeader if (processGDS) { // check for Local Use Section 2 lus = new GRIB2LocalUseSection(_fs); // obtain GDS offset in the file for this record gdsOffset = _fs.Position; // Section 3 gds = new GRIB2GridDefinitionSection(_fs); } // obtain PDS offset in the file for this record long pdsOffset = _fs.Position; IGRIB2ProductDefinitionSection pds = new GRIB2ProductDefinitionSection(_fs); // Section 4 IGRIB2DataRepresentationSection drs = new GRIB2DataRepresentationSection(_fs); // Section 5 IGribBitMapSection bms = new GRIB2BitMapSection(_fs, gds.PointsNumber); // Section 6 long dataOffset = _fs.Position + 5; GRIB2DataSection ds = new GRIB2DataSection(_fs, dataOffset); //Section 7 GRIB2Record record = new GRIB2Record(iSection.Displine, gds, pds, drs, bms, ds, gdsOffset, pdsOffset, dataOffset); _records.Add(record); _parameterList.Add(record.ParameterName); if (_fs.Position > _fs.Length) { _fs.Seek(0, System.IO.SeekOrigin.Begin); goto setAttributes; } int ending = GribNumberHelper.Int4(_fs); if (ending == 926365495) { // record ending string 7777 as a number startAtHeader = true; processGDS = true; } else { //_fs.Seek(4, SeekOrigin.Current); int section = _fs.ReadByte(); // check if GDS or PDS section, 3 or 4 //reset back to begining of section _fs.Seek(_fs.Position - 5, System.IO.SeekOrigin.Begin); if (section == 3) { startAtHeader = false; processGDS = true; } else if (section == 4) { startAtHeader = false; processGDS = false; } else { GribEndSection es = new GribEndSection(_fs); if (es.IsEndFound) { startAtHeader = true; processGDS = true; } else { goto setAttributes; } } } } setAttributes: SetAttribute(gds); }