/// <summary> /// 构造函数 /// </summary> /// <param name="raf">with PDS content</param> public Grib1ProductDefinitionSection(FileStream fs) { // octets 1-3 PDS length _sectionLength = (int)GribNumberHelper.Uint3(fs); // Paramter table octet 4 _tableVersion = fs.ReadByte(); // Center octet 5 _centerId = fs.ReadByte(); // octet 6 Generating Process - See Table A _processId = fs.ReadByte(); // octet 7 (id of grid type) - not supported yet _gridId = fs.ReadByte(); //octet 8 (flag for presence of GDS and BMS) SetGdsBmsExits(fs.ReadByte()); // octet 9 (parameter and unit) _parameterNumber = fs.ReadByte(); // octets 10-12 (level) int levelType = fs.ReadByte(); int levelValue1 = fs.ReadByte(); int levelValue2 = fs.ReadByte(); _level = new GribPDSLevel(levelType, levelValue1, levelValue2); // octets 13-17 (base time for reference time)依次为year/month/day/hour/minute byte[] timeBytes = new Byte[5]; fs.Read(timeBytes, 0, 5); // octet 18 Forecast time unit _timeUnit = fs.ReadByte(); // octet 19 & 20 used to create Forecast time int p1 = fs.ReadByte(); int p2 = fs.ReadByte(); // octet 21 (time range indicator) _timeRangeValue = fs.ReadByte(); // forecast time is always at the end of the range SetTimeRange(p1, p2); // octet 22 & 23 int avgInclude = GribNumberHelper.Int2(fs); // octet 24 int avgMissing = fs.ReadByte(); // octet 25 int century = fs.ReadByte() - 1; // octet 26, sub center _subcenterId = fs.ReadByte(); // octets 27-28 (decimal scale factor) _decscale = GribNumberHelper.Int2(fs); SetReferenceTime(timeBytes, century); _parameterTable = GribPDSParamTable.GetParameterTable(_centerId, _subcenterId, _tableVersion); _parameter = _parameterTable.GetParameter(_parameterNumber); }
/** * Looks for the parameter table which matches the center, subcenter * and table version from the tables array. * If this is the first time asking for this table, then the parameters for * this table have not been read in yet, so this is done as well. * @param center - integer from PDS octet 5, representing Center. * @param subcenter - integer from PDS octet 26, representing Subcenter * @param number - integer from PDS octet 4, representing Parameter Table Version * @return GribPDSParamTable matching center, subcenter, and number * @throws NotSupportedException */ //////////////////////// public static GribPDSParamTable GetParameterTable(int subcenter, int center, int number) { try { GribPDSParamTable._tables = new List <GribPDSParamTable>(); InitDefaultTableEntries(_tables); _paramTables = _tables; } catch (Exception e) { } /* 1) search excact match (center, table) * 2) if (1) failed, search matching table ( - ,table(1..3)) */ for (int i = _paramTables.Count - 1; i >= 0; i--) { GribPDSParamTable table = _paramTables[i]; if (table._centerId == -1) { continue; } if (center == table._centerId) { if (table._subcenterId == -1 || subcenter == table._subcenterId) { if (number == table._tableNumber) { // now that this table is being used, check to see if the // parameters for this table have been read in yet. // If not, initialize table and read them in now. //table.readParameterTable(); return(table); } } } } //search matching table ( - ,table(1..3)) for (int i = _paramTables.Count - 1; i >= 0; i--) { GribPDSParamTable table = _paramTables[i]; if (table._centerId == -1 && number == table._tableNumber) { return(table); } } return(null); }