// *** constructors ******************************************************* /// <summary> Constructs a <tt>Grib2DataRepresentationSection</tt> object from a raf. /// /// </summary> /// <param name="raf">RandomAccessFile with Section DRS content /// </param> /// <throws> IOException if stream 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 Grib2DataRepresentationSection(System.IO.FileStream raf) { InitBlock(); // octets 1-4 (Length of DRS) length = GribNumbers.int4(raf); //System.out.println( "DRS length=" + length ); section = raf.ReadByte(); //System.out.println( "DRS is 5 section=" + section ); dataPoints = GribNumbers.int4(raf); //System.out.println( "DRS dataPoints=" + dataPoints ); dataTemplate = (int)GribNumbers.uint2(raf); //System.out.println( "DRS dataTemplate=" + dataTemplate ); switch (dataTemplate) { // Data Template Number case 0: case 1: // 0 - Grid point data - simple packing // 1 - Matrix values - simple packing //System.out.println( "DRS dataTemplate=" + dataTemplate ); referenceValue = GribNumbers.IEEEfloat4(raf); binaryScaleFactor = GribNumbers.int2(raf); decimalScaleFactor = GribNumbers.int2(raf); numberOfBits = raf.ReadByte(); //System.out.println( "DRS numberOfBits=" + numberOfBits ); originalType = raf.ReadByte(); //System.out.println( "DRS originalType=" + originalType ); if (dataTemplate == 0) { break; } // case 1 not implememted System.Console.Out.WriteLine("DRS dataTemplate=1 not implemented yet"); break; case 2: case 3: // Grid point data - complex packing //System.out.println( "DRS dataTemplate=" + dataTemplate ); // octet 12 - 15 referenceValue = GribNumbers.IEEEfloat4(raf); // octet 16 - 17 binaryScaleFactor = GribNumbers.int2(raf); // octet 18 - 19 decimalScaleFactor = GribNumbers.int2(raf); // octet 20 numberOfBits = raf.ReadByte(); //System.out.println( "DRS numberOfBits=" + numberOfBits ); // octet 21 originalType = raf.ReadByte(); //System.out.println( "DRS originalType=" + originalType ); // octet 22 splittingMethod = raf.ReadByte(); //System.out.println( "DRS splittingMethod=" + // splittingMethod ); // octet 23 missingValueManagement = raf.ReadByte(); //System.out.println( "DRS missingValueManagement=" + // missingValueManagement ); // octet 24 - 27 primaryMissingValue = GribNumbers.IEEEfloat4(raf); // octet 28 - 31 secondaryMissingValue = GribNumbers.IEEEfloat4(raf); // octet 32 - 35 numberOfGroups = GribNumbers.int4(raf); //System.out.println( "DRS numberOfGroups=" + // numberOfGroups ); // octet 36 referenceGroupWidths = raf.ReadByte(); //System.out.println( "DRS referenceGroupWidths=" + // referenceGroupWidths ); // octet 37 bitsGroupWidths = raf.ReadByte(); // according to documentation subtract referenceGroupWidths bitsGroupWidths = bitsGroupWidths - referenceGroupWidths; //System.out.println( "DRS bitsGroupWidths=" + // bitsGroupWidths ); // octet 38 - 41 referenceGroupLength = GribNumbers.int4(raf); //System.out.println( "DRS referenceGroupLength=" + // referenceGroupLength ); // octet 42 lengthIncrement = raf.ReadByte(); //System.out.println( "DRS lengthIncrement=" + // lengthIncrement ); // octet 43 - 46 lengthLastGroup = GribNumbers.int4(raf); //System.out.println( "DRS lengthLastGroup=" + // lengthLastGroup ); // octet 47 bitsScaledGroupLength = raf.ReadByte(); //System.out.println( "DRS bitsScaledGroupLength=" + // bitsScaledGroupLength ); if (dataTemplate == 2) { break; } // case 3 // complex packing & spatial differencing orderSpatial = raf.ReadByte(); //System.out.println( "DRS orderSpatial=" + orderSpatial); descriptorSpatial = raf.ReadByte(); //System.out.println( "DRS descriptorSpatial=" + descriptorSpatial); break; case 40: case 40000: // Grid point data - JPEG 2000 Code Stream Format //System.out.println( "DRS dataTemplate=" + dataTemplate ); referenceValue = GribNumbers.IEEEfloat4(raf); binaryScaleFactor = GribNumbers.int2(raf); decimalScaleFactor = GribNumbers.int2(raf); numberOfBits = raf.ReadByte(); //System.out.println( "DRS numberOfBits=" + numberOfBits ); originalType = raf.ReadByte(); //System.out.println( "DRS originalType=" + originalType ); compressionMethod = raf.ReadByte(); //System.out.println( "DRS compressionMethod=" + compressionMethod ); compressionRatio = raf.ReadByte(); //System.out.println( "DRS compressionRatio=" + compressionRatio ); break; default: break; } } // end of Grib2DataRepresentationSection
// *** constructors ******************************************************* /// <summary> Constructs a <tt>Grib2GridDefinitionSection</tt> object from a raf. /// /// </summary> /// <param name="raf">RandomAccessFile /// </param> /// <param name="doCheckSum"> calculate the checksum /// </param> /// <throws> IOException if raf contains no valid GRIB product </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 Grib2GridDefinitionSection(System.IO.FileStream raf, bool doCheckSum) { int scalefactorradius = 0; int scaledvalueradius = 0; int scalefactormajor = 0; int scaledvaluemajor = 0; int scalefactorminor = 0; int scaledvalueminor = 0; // octets 1-4 (Length of GDS) length = GribNumbers.int4(raf); //System.out.println( "GDS length=" + length ); if (doCheckSum) { /* * // get byte array for this gds, then reset raf to same position * // calculate checksum for this gds via the byte array * long mark = raf.Position; * sbyte[] dst = new sbyte[length - 4]; * SupportClass.ReadInput(raf, dst, 0, dst.Length); * raf.Seek(mark, System.IO.SeekOrigin.Begin); * //UPGRADE_ISSUE: Class 'java.util.zip.CRC32' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'" * //UPGRADE_ISSUE: Constructor 'java.util.zip.CRC32.CRC32' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'" * CRC32 cs = new CRC32(); * //UPGRADE_ISSUE: Method 'java.util.zip.CRC32.update' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'" * cs.update(dst); * //UPGRADE_ISSUE: Method 'java.util.zip.CRC32.getValue' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipCRC32'" * checksum = System.Convert.ToString(cs.getValue()); * //System.out.println( "GDS checksum =" + checksum ); */ // TODO Check this } section = raf.ReadByte(); // This is section 3 //System.out.println( "GDS is 3, section=" + section ); source = raf.ReadByte(); //System.out.println( "GDS source=" + source ); numberPoints = GribNumbers.int4(raf); //System.out.println( "GDS numberPoints=" + numberPoints ); olon = raf.ReadByte(); //System.out.println( "GDS olon=" + olon ); iolon = raf.ReadByte(); //System.out.println( "GDS iolon=" + iolon ); gdtn = GribNumbers.int2(raf); //System.out.println( "GDS gdtn=" + gdtn ); name = getGridName(gdtn); float ratio; switch (gdtn) { // Grid Definition Template Number case 0: case 1: case 2: case 3: // Latitude/Longitude Grid shape = raf.ReadByte(); //System.out.println( "shape=" + shape ); scalefactorradius = raf.ReadByte(); scaledvalueradius = GribNumbers.int4(raf); scalefactormajor = raf.ReadByte(); scaledvaluemajor = GribNumbers.int4(raf); scalefactorminor = raf.ReadByte(); scaledvalueminor = GribNumbers.int4(raf); nx = GribNumbers.int4(raf); //System.out.println( "nx=" + nx); ny = GribNumbers.int4(raf); //System.out.println( "ny=" + ny); angle = GribNumbers.int4(raf); subdivisionsangle = GribNumbers.int4(raf); if (angle == 0) { ratio = tenToNegSix; } else { ratio = angle / subdivisionsangle; } //System.out.println( "ratio =" + ratio ); la1 = (float)(GribNumbers.int4(raf) * ratio); lo1 = (float)(GribNumbers.int4(raf) * ratio); resolution = raf.ReadByte(); la2 = (float)(GribNumbers.int4(raf) * ratio); lo2 = (float)(GribNumbers.int4(raf) * ratio); dx = (float)(GribNumbers.int4(raf) * ratio); dy = (float)(GribNumbers.int4(raf) * ratio); scanMode = raf.ReadByte(); // 1, 2, and 3 needs checked if (gdtn == 1) { //Rotated Latitude/longitude spLat = GribNumbers.int4(raf) * tenToNegSix; spLon = GribNumbers.int4(raf) * tenToNegSix; rotationangle = GribNumbers.IEEEfloat4(raf); } else if (gdtn == 2) { //Stretched Latitude/longitude poleLat = GribNumbers.int4(raf) * tenToNegSix; poleLon = GribNumbers.int4(raf) * tenToNegSix; factor = GribNumbers.int4(raf); } else if (gdtn == 3) { //Stretched and Rotated // Latitude/longitude spLat = GribNumbers.int4(raf) * tenToNegSix; spLon = GribNumbers.int4(raf) * tenToNegSix; rotationangle = GribNumbers.IEEEfloat4(raf); poleLat = GribNumbers.int4(raf) * tenToNegSix; poleLon = GribNumbers.int4(raf) * tenToNegSix; factor = GribNumbers.int4(raf); } break; case 10: // Mercator // la1, lo1, lad, la2, and lo2 need checked shape = raf.ReadByte(); //System.out.println( "shape=" + shape ); scalefactorradius = raf.ReadByte(); scaledvalueradius = GribNumbers.int4(raf); scalefactormajor = raf.ReadByte(); scaledvaluemajor = GribNumbers.int4(raf); scalefactorminor = raf.ReadByte(); scaledvalueminor = GribNumbers.int4(raf); nx = GribNumbers.int4(raf); //System.out.println( "nx=" + nx); ny = GribNumbers.int4(raf); //System.out.println( "ny=" + ny); la1 = GribNumbers.int4(raf) * tenToNegSix; lo1 = GribNumbers.int4(raf) * tenToNegSix; resolution = raf.ReadByte(); lad = GribNumbers.int4(raf) * tenToNegSix; la2 = GribNumbers.int4(raf) * tenToNegSix; lo2 = GribNumbers.int4(raf) * tenToNegSix; scanMode = raf.ReadByte(); angle = GribNumbers.int4(raf); dx = (float)(GribNumbers.int4(raf) * tenToNegThree); dy = (float)(GribNumbers.int4(raf) * tenToNegThree); break; case 20: // Polar stereographic projection // la1, lo1, lad, and lov need checked shape = raf.ReadByte(); //System.out.println( "shape=" + shape ); scalefactorradius = raf.ReadByte(); scaledvalueradius = GribNumbers.int4(raf); scalefactormajor = raf.ReadByte(); scaledvaluemajor = GribNumbers.int4(raf); scalefactorminor = raf.ReadByte(); scaledvalueminor = GribNumbers.int4(raf); nx = GribNumbers.int4(raf); //System.out.println( "nx=" + nx); ny = GribNumbers.int4(raf); //System.out.println( "ny=" + ny); la1 = GribNumbers.int4(raf) * tenToNegSix; lo1 = GribNumbers.int4(raf) * tenToNegSix; resolution = raf.ReadByte(); lad = GribNumbers.int4(raf) * tenToNegSix; lov = GribNumbers.int4(raf) * tenToNegSix; dx = (float)(GribNumbers.int4(raf) * tenToNegThree); dy = (float)(GribNumbers.int4(raf) * tenToNegThree); projectionCenter = raf.ReadByte(); scanMode = raf.ReadByte(); break; case 30: // Lambert Conformal shape = raf.ReadByte(); //System.out.println( "shape=" + shape ); scalefactorradius = raf.ReadByte(); scaledvalueradius = GribNumbers.int4(raf); scalefactormajor = raf.ReadByte(); scaledvaluemajor = GribNumbers.int4(raf); scalefactorminor = raf.ReadByte(); scaledvalueminor = GribNumbers.int4(raf); nx = GribNumbers.int4(raf); //System.out.println( "nx=" + nx); ny = GribNumbers.int4(raf); //System.out.println( "ny=" + ny); la1 = (float)(GribNumbers.int4(raf) * tenToNegSix); //System.out.println( "la1=" + la1 ); lo1 = (float)(GribNumbers.int4(raf) * tenToNegSix); //System.out.println( "lo1=" + lo1); resolution = raf.ReadByte(); lad = (float)(GribNumbers.int4(raf) * tenToNegSix); lov = (float)(GribNumbers.int4(raf) * tenToNegSix); dx = (float)(GribNumbers.int4(raf) * tenToNegThree); dy = (float)(GribNumbers.int4(raf) * tenToNegThree); projectionCenter = raf.ReadByte(); scanMode = raf.ReadByte(); latin1 = (float)(GribNumbers.int4(raf) * tenToNegSix); latin2 = (float)(GribNumbers.int4(raf) * tenToNegSix); //System.out.println( "latin1=" + latin1); //System.out.println( "latin2=" + latin2); spLat = (float)(GribNumbers.int4(raf) * tenToNegSix); spLon = (float)(GribNumbers.int4(raf) * tenToNegSix); //System.out.println( "spLat=" + spLat); //System.out.println( "spLon=" + spLon); break; case 31: // Albers Equal Area // la1, lo1, lad, and lov need checked shape = raf.ReadByte(); //System.out.println( "shape=" + shape ); scalefactorradius = raf.ReadByte(); scaledvalueradius = GribNumbers.int4(raf); scalefactormajor = raf.ReadByte(); scaledvaluemajor = GribNumbers.int4(raf); scalefactorminor = raf.ReadByte(); scaledvalueminor = GribNumbers.int4(raf); nx = GribNumbers.int4(raf); //System.out.println( "nx=" + nx); ny = GribNumbers.int4(raf); //System.out.println( "ny=" + ny); la1 = GribNumbers.int4(raf) * tenToNegSix; //System.out.println( "la1=" + la1 ); lo1 = GribNumbers.int4(raf) * tenToNegSix; //System.out.println( "lo1=" + lo1); resolution = raf.ReadByte(); lad = GribNumbers.int4(raf) * tenToNegSix; lov = GribNumbers.int4(raf) * tenToNegSix; dx = (float)(GribNumbers.int4(raf) * tenToNegThree); dy = (float)(GribNumbers.int4(raf) * tenToNegThree); projectionCenter = raf.ReadByte(); scanMode = raf.ReadByte(); latin1 = GribNumbers.int4(raf) * tenToNegSix; latin2 = GribNumbers.int4(raf) * tenToNegSix; //System.out.println( "latin1=" + latin1); //System.out.println( "latin2=" + latin2); spLat = GribNumbers.int4(raf) * tenToNegSix; spLon = GribNumbers.int4(raf) * tenToNegSix; //System.out.println( "spLat=" + spLat); //System.out.println( "spLon=" + spLon); break; case 40: case 41: case 42: case 43: // Gaussian latitude/longitude shape = raf.ReadByte(); //System.out.println( "shape=" + shape ); scalefactorradius = raf.ReadByte(); scaledvalueradius = GribNumbers.int4(raf); scalefactormajor = raf.ReadByte(); scaledvaluemajor = GribNumbers.int4(raf); scalefactorminor = raf.ReadByte(); scaledvalueminor = GribNumbers.int4(raf); nx = GribNumbers.int4(raf); //System.out.println( "nx=" + nx); ny = GribNumbers.int4(raf); //System.out.println( "ny=" + ny); angle = GribNumbers.int4(raf); subdivisionsangle = GribNumbers.int4(raf); if (angle == 0) { ratio = tenToNegSix; } else { ratio = angle / subdivisionsangle; } //System.out.println( "ratio =" + ratio ); la1 = (float)(GribNumbers.int4(raf) * ratio); lo1 = (float)(GribNumbers.int4(raf) * ratio); resolution = raf.ReadByte(); la2 = (float)(GribNumbers.int4(raf) * ratio); lo2 = (float)(GribNumbers.int4(raf) * ratio); dx = (float)(GribNumbers.int4(raf) * ratio); n = raf.ReadByte(); scanMode = raf.ReadByte(); if (gdtn == 41) { //Rotated Gaussian Latitude/longitude spLat = GribNumbers.int4(raf) * ratio; spLon = GribNumbers.int4(raf) * ratio; rotationangle = GribNumbers.IEEEfloat4(raf); } else if (gdtn == 42) { //Stretched Gaussian // Latitude/longitude poleLat = GribNumbers.int4(raf) * ratio; poleLon = GribNumbers.int4(raf) * ratio; factor = GribNumbers.int4(raf); } else if (gdtn == 43) { //Stretched and Rotated Gaussian // Latitude/longitude spLat = GribNumbers.int4(raf) * ratio; spLon = GribNumbers.int4(raf) * ratio; rotationangle = GribNumbers.IEEEfloat4(raf); poleLat = GribNumbers.int4(raf) * ratio; poleLon = GribNumbers.int4(raf) * ratio; factor = GribNumbers.int4(raf); } break; case 50: case 51: case 52: case 53: // Spherical harmonic coefficients j = GribNumbers.IEEEfloat4(raf); k = GribNumbers.IEEEfloat4(raf); m = GribNumbers.IEEEfloat4(raf); method = raf.ReadByte(); mode = raf.ReadByte(); if (gdtn == 51) { //Rotated Spherical harmonic coefficients spLat = GribNumbers.int4(raf) * tenToNegSix; spLon = GribNumbers.int4(raf) * tenToNegSix; rotationangle = GribNumbers.IEEEfloat4(raf); } else if (gdtn == 52) { //Stretched Spherical // harmonic coefficients poleLat = GribNumbers.int4(raf) * tenToNegSix; poleLon = GribNumbers.int4(raf) * tenToNegSix; factor = GribNumbers.int4(raf); } else if (gdtn == 53) { //Stretched and Rotated // Spherical harmonic coefficients spLat = GribNumbers.int4(raf) * tenToNegSix; spLon = GribNumbers.int4(raf) * tenToNegSix; rotationangle = GribNumbers.IEEEfloat4(raf); poleLat = GribNumbers.int4(raf) * tenToNegSix; poleLon = GribNumbers.int4(raf) * tenToNegSix; factor = GribNumbers.int4(raf); } break; case 90: // Space view perspective or orthographic shape = raf.ReadByte(); //System.out.println( "shape=" + shape ); scalefactorradius = raf.ReadByte(); scaledvalueradius = GribNumbers.int4(raf); scalefactormajor = raf.ReadByte(); scaledvaluemajor = GribNumbers.int4(raf); scalefactorminor = raf.ReadByte(); scaledvalueminor = GribNumbers.int4(raf); nx = GribNumbers.int4(raf); //System.out.println( "nx=" + nx); ny = GribNumbers.int4(raf); //System.out.println( "ny=" + ny); lap = GribNumbers.int4(raf); lop = GribNumbers.int4(raf); resolution = raf.ReadByte(); dx = GribNumbers.int4(raf); dy = GribNumbers.int4(raf); xp = (float)(GribNumbers.int4(raf) * tenToNegThree); yp = (float)(GribNumbers.int4(raf) * tenToNegThree); scanMode = raf.ReadByte(); angle = GribNumbers.int4(raf); altitude = GribNumbers.int4(raf) * 1000000; xo = GribNumbers.int4(raf); yo = GribNumbers.int4(raf); break; case 100: // Triangular grid based on an icosahedron n2 = raf.ReadByte(); n3 = raf.ReadByte(); ni = GribNumbers.int2(raf); nd = raf.ReadByte(); poleLat = GribNumbers.int4(raf) * tenToNegSix; poleLon = GribNumbers.int4(raf) * tenToNegSix; lonofcenter = GribNumbers.int4(raf); position = raf.ReadByte(); order = raf.ReadByte(); scanMode = raf.ReadByte(); n = GribNumbers.int4(raf); break; case 110: // Equatorial azimuthal equidistant projection shape = raf.ReadByte(); //System.out.println( "shape=" + shape ); scalefactorradius = raf.ReadByte(); scaledvalueradius = GribNumbers.int4(raf); scalefactormajor = raf.ReadByte(); scaledvaluemajor = GribNumbers.int4(raf); scalefactorminor = raf.ReadByte(); scaledvalueminor = GribNumbers.int4(raf); nx = GribNumbers.int4(raf); //System.out.println( "nx=" + nx); ny = GribNumbers.int4(raf); //System.out.println( "ny=" + ny); la1 = GribNumbers.int4(raf) * tenToNegSix; lo1 = GribNumbers.int4(raf) * tenToNegSix; resolution = raf.ReadByte(); dx = (float)(GribNumbers.int4(raf) * tenToNegThree); dy = (float)(GribNumbers.int4(raf) * tenToNegThree); projectionCenter = raf.ReadByte(); scanMode = raf.ReadByte(); break; case 120: // Azimuth-range Projection nb = GribNumbers.int4(raf); nr = GribNumbers.int4(raf); la1 = GribNumbers.int4(raf); lo1 = GribNumbers.int4(raf); dx = GribNumbers.int4(raf); dstart = GribNumbers.IEEEfloat4(raf); scanMode = raf.ReadByte(); for (int i = 0; i < nr; i++) { // get azi (33+4(Nr-1))-(34+4(Nr-1)) // get adelta (35+4(Nr-1))-(36+4(Nr-1)) } System.Console.Out.WriteLine("need code to get azi and adelta"); break; default: System.Console.Out.WriteLine("Unknown Grid Type " + System.Convert.ToString(gdtn)); break; } // end switch // calculate earth radius if ((gdtn < 50 || gdtn > 53) && gdtn != 100 && gdtn != 120) { if (shape == 0) { earthRadius = 6367470; } else if (shape == 1) { earthRadius = scaledvalueradius; if (scalefactorradius != 0) { earthRadius = (float)(earthRadius / System.Math.Pow(10, scalefactorradius)); } } else if (shape == 2) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" majorAxis = (float)6378160.0; //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" minorAxis = (float)6356775.0; } else if (shape == 3) { majorAxis = scaledvaluemajor; //System.out.println( "majorAxisScale =" + scalefactormajor ); //System.out.println( "majorAxisiValue =" + scaledvaluemajor ); majorAxis = (float)(majorAxis / System.Math.Pow(10, scalefactormajor)); minorAxis = scaledvalueminor; //System.out.println( "minorAxisScale =" + scalefactorminor ); //System.out.println( "minorAxisValue =" + scaledvalueminor ); minorAxis = (float)(minorAxis / System.Math.Pow(10, scalefactorminor)); } else if (shape == 4) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" majorAxis = (float)6378137.0; minorAxis = (float)SupportClass.Identity(6356752.314); } else if (shape == 6) { earthRadius = 6371229; } } } // end of Grib2GridDefinitionSection