// *** constructors ******************************************************* /// <summary> Constructs a <tt>Grib1ProductDefinitionSection</tt> object from a raf. /// /// </summary> /// <param name="raf">with PDS content /// /// </param> /// <throws> NotSupportedException if raf contains no valid GRIB file </throws> //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'Stream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'" public Grib1ProductDefinitionSection(Stream raf) { // octets 1-3 PDS length length = (int)GribNumbers.uint3(raf); //System.out.println( "PDS length = " + length ); // Paramter table octet 4 table_version = raf.ReadByte(); // Center octet 5 center_id = raf.ReadByte(); // octet 6 Generating Process - See Table A process_id = raf.ReadByte(); // octet 7 (id of grid type) - not supported yet grid_id = raf.ReadByte(); //octet 8 (flag for presence of GDS and BMS) int exists = raf.ReadByte(); //BKSystem.IO.BitStream s = new BKSystem.IO.BitStream(8); // s.WriteByte((byte)raf.ReadByte()); // s.Position = 0; // sbyte exists; // s.Read(out exists); // bms_exists = (exists & 64) == 64; gds_exists = (exists & 128) == 128; bms_exists = (exists & 64) == 64; // octet 9 (parameter and unit) parameterNumber = raf.ReadByte(); // octets 10-12 (level) int levelType = raf.ReadByte(); int levelValue1 = raf.ReadByte(); int levelValue2 = raf.ReadByte(); level = new GribPDSLevel(levelType, levelValue1, levelValue2); // octets 13-17 (base time for reference time) int year = raf.ReadByte(); int month = raf.ReadByte(); int day = raf.ReadByte(); int hour = raf.ReadByte(); int minute = raf.ReadByte(); // get info for forecast time // octet 18 Forecast time unit timeUnit = raf.ReadByte(); switch (timeUnit) { case 0: // minute tUnit = "minute"; break; case 1: // hours tUnit = "hour"; break; case 2: // day tUnit = "day"; break; case 3: // month tUnit = "month"; break; case 4: //1 year tUnit = "1year"; break; case 5: // decade tUnit = "decade"; break; case 6: // normal tUnit = "day"; break; case 7: // century tUnit = "century"; break; case 10: //3 hours tUnit = "3hours"; break; case 11: // 6 hours tUnit = "6hours"; break; case 12: // 12 hours tUnit = "12hours"; break; case 254: // second tUnit = "second"; break; default: // System.Console.Error.WriteLine("PDS: Time Unit " + timeUnit + " is not yet supported"); break; } // octet 19 & 20 used to create Forecast time p1 = raf.ReadByte(); p2 = raf.ReadByte(); // octet 21 (time range indicator) timeRangeValue = raf.ReadByte(); // forecast time is always at the end of the range //System.out.println( "PDS timeRangeValue =" + timeRangeValue ); switch (timeRangeValue) { case 0: timeRange = "product valid at RT + P1"; forecastTime = p1; break; case 1: timeRange = "product valid for RT, P1=0"; forecastTime = 0; break; case 2: timeRange = "product valid from (RT + P1) to (RT + P2)"; forecastTime = p2; break; case 3: timeRange = "product is an average between (RT + P1) to (RT + P2)"; forecastTime = p2; break; case 4: timeRange = "product is an accumulation between (RT + P1) to (RT + P2)"; forecastTime = p2; break; case 5: timeRange = "product is the difference (RT + P2) - (RT + P1)"; forecastTime = p2; break; case 6: timeRange = "product is an average from (RT - P1) to (RT - P2)"; forecastTime = - p2; break; case 7: timeRange = "product is an average from (RT - P1) to (RT + P2)"; forecastTime = p2; break; case 10: timeRange = "product valid at RT + P1"; // p1 really consists of 2 bytes p1 and p2 forecastTime = p1 = GribNumbers.int2(p1, p2); p2 = 0; break; case 51: timeRange = "mean value from RT to (RT + P2)"; forecastTime = p2; break; default: // System.Console.Error.WriteLine("PDS: Time Range Indicator " + timeRangeValue + " is not yet supported"); break; } // octet 22 & 23 int avgInclude = GribNumbers.int2(raf); // octet 24 int avgMissing = raf.ReadByte(); // octet 25 int century = raf.ReadByte() - 1; // octet 26, sub center subcenter_id = raf.ReadByte(); // octets 27-28 (decimal scale factor) decscale = GribNumbers.int2(raf); refTime = new DateTime(century * 100 + year, month, day, hour, minute, 0, DateTimeKind.Utc); baseTime = refTime; referenceTime = refTime.ToString(dateFormat); //System.out.println( "PDS referenceTime raw = " + //(century * 100 + year) +"-" + //month + "-" + day + "T" + hour +":" + minute +":00Z" ); //System.out.println( "PDS referenceTime = " + referenceTime ); // TODO /* parameter_table = GribPDSParamTable.getParameterTable(center_id, subcenter_id, table_version); parameter = parameter_table.getParameter(parameterNumber); */ parameter = new Parameter(); if (center_id == 7 && subcenter_id == 2) { // ensemble product epds = new Grib1Ensemble(raf, parameterNumber); } // Special handling of 2D Wave Spectra (single) else if(table_version==140 && parameterNumber==251) { SupportClass.Skip(raf, 12); int extDef = raf.ReadByte(); // Extension definition // Read ECMWF extension for 2D wave spectra single if (extDef == 13) { waveSpectra2DDirFreq = new Grib1WaveSpectra2DDirFreq(raf); } } else if (length != 28) { // check if all bytes read in section //lengthErr = true; int extra; for (int i = 29; i <= length; i++) extra = raf.ReadByte(); } }
// *** constructors ******************************************************* /// <summary> Constructs a <tt>Grib1ProductDefinitionSection</tt> object from a raf. /// /// </summary> /// <param name="raf">with PDS content /// /// </param> /// <throws> NotSupportedException if raf contains no valid GRIB file </throws> //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'" public Grib1ProductDefinitionSection(System.IO.FileStream raf) { // octets 1-3 PDS length length = (int)GribNumbers.uint3(raf); //System.out.println( "PDS length = " + length ); // Paramter table octet 4 table_version = raf.ReadByte(); // Center octet 5 center_id = raf.ReadByte(); // octet 6 Generating Process - See Table A process_id = raf.ReadByte(); // octet 7 (id of grid type) - not supported yet grid_id = raf.ReadByte(); //octet 8 (flag for presence of GDS and BMS) int exists = raf.ReadByte(); //BKSystem.IO.BitStream s = new BKSystem.IO.BitStream(8); // s.WriteByte((byte)raf.ReadByte()); // s.Position = 0; // sbyte exists; // s.Read(out exists); // bms_exists = (exists & 64) == 64; gds_exists = (exists & 128) == 128; bms_exists = (exists & 64) == 64; // octet 9 (parameter and unit) parameterNumber = raf.ReadByte(); // octets 10-12 (level) int levelType = raf.ReadByte(); int levelValue1 = raf.ReadByte(); int levelValue2 = raf.ReadByte(); level = new GribPDSLevel(levelType, levelValue1, levelValue2); // octets 13-17 (base time for reference time) int year = raf.ReadByte(); int month = raf.ReadByte(); int day = raf.ReadByte(); int hour = raf.ReadByte(); int minute = raf.ReadByte(); // get info for forecast time // octet 18 Forecast time unit timeUnit = raf.ReadByte(); switch (timeUnit) { case 0: // minute tUnit = "minute"; break; case 1: // hours tUnit = "hour"; break; case 2: // day tUnit = "day"; break; case 3: // month tUnit = "month"; break; case 4: //1 year tUnit = "1year"; break; case 5: // decade tUnit = "decade"; break; case 6: // normal tUnit = "day"; break; case 7: // century tUnit = "century"; break; case 10: //3 hours tUnit = "3hours"; break; case 11: // 6 hours tUnit = "6hours"; break; case 12: // 12 hours tUnit = "12hours"; break; case 254: // second tUnit = "second"; break; default: System.Console.Error.WriteLine("PDS: Time Unit " + timeUnit + " is not yet supported"); break; } // octet 19 & 20 used to create Forecast time p1 = raf.ReadByte(); p2 = raf.ReadByte(); // octet 21 (time range indicator) timeRangeValue = raf.ReadByte(); // forecast time is always at the end of the range //System.out.println( "PDS timeRangeValue =" + timeRangeValue ); switch (timeRangeValue) { case 0: timeRange = "product valid at RT + P1"; forecastTime = p1; break; case 1: timeRange = "product valid for RT, P1=0"; forecastTime = 0; break; case 2: timeRange = "product valid from (RT + P1) to (RT + P2)"; forecastTime = p2; break; case 3: timeRange = "product is an average between (RT + P1) to (RT + P2)"; forecastTime = p2; break; case 4: timeRange = "product is an accumulation between (RT + P1) to (RT + P2)"; forecastTime = p2; break; case 5: timeRange = "product is the difference (RT + P2) - (RT + P1)"; forecastTime = p2; break; case 6: timeRange = "product is an average from (RT - P1) to (RT - P2)"; forecastTime = -p2; break; case 7: timeRange = "product is an average from (RT - P1) to (RT + P2)"; forecastTime = p2; break; case 10: timeRange = "product valid at RT + P1"; // p1 really consists of 2 bytes p1 and p2 forecastTime = p1 = GribNumbers.int2(p1, p2); p2 = 0; break; case 51: timeRange = "mean value from RT to (RT + P2)"; forecastTime = p2; break; default: System.Console.Error.WriteLine("PDS: Time Range Indicator " + timeRangeValue + " is not yet supported"); break; } // octet 22 & 23 int avgInclude = GribNumbers.int2(raf); // octet 24 int avgMissing = raf.ReadByte(); // octet 25 int century = raf.ReadByte() - 1; // octet 26, sub center subcenter_id = raf.ReadByte(); // octets 27-28 (decimal scale factor) decscale = GribNumbers.int2(raf); refTime = new DateTime(century * 100 + year, month, day, hour, minute, 0, DateTimeKind.Utc); baseTime = refTime; referenceTime = refTime.ToString(dateFormat); //System.out.println( "PDS referenceTime raw = " + //(century * 100 + year) +"-" + //month + "-" + day + "T" + hour +":" + minute +":00Z" ); //System.out.println( "PDS referenceTime = " + referenceTime ); // TODO /* * parameter_table = GribPDSParamTable.getParameterTable(center_id, subcenter_id, table_version); * parameter = parameter_table.getParameter(parameterNumber); */ parameter = new Parameter(); if (center_id == 7 && subcenter_id == 2) { // ensemble product epds = new Grib1Ensemble(raf, parameterNumber); } // Special handling of 2D Wave Spectra (single) else if (table_version == 140 && parameterNumber == 251) { SupportClass.Skip(raf, 12); int extDef = raf.ReadByte(); // Extension definition // Read ECMWF extension for 2D wave spectra single if (extDef == 13) { waveSpectra2DDirFreq = new Grib1WaveSpectra2DDirFreq(raf); } } else if (length != 28) { // check if all bytes read in section //lengthErr = true; int extra; for (int i = 29; i <= length; i++) { extra = raf.ReadByte(); } } } // end Grib1ProductDefinitionSection