} // end complexUnpackingWithSpatial /// <summary> Jpeg2000 unpacking method for Grib2 data.</summary> /// <param name="raf"> /// </param> /// <param name="gds"> /// </param> /// <param name="drs"> /// </param> /// <param name="bms">bit-map section object /// </param> //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'" private void jpeg2000Unpacking(System.IO.FileStream raf, Grib2GridDefinitionSection gds, Grib2DataRepresentationSection drs, Grib2BitMapSection bms) { // 6-xx jpeg2000 data block to decode // dataPoints are number of points encoded, it could be less than the // numberPoints in the grid record if bitMap is used, otherwise equal int dataPoints = drs.DataPoints; //System.out.println( "DS DRS dataPoints=" + drs.getDataPoints() ); //System.out.println( "DS length=" + length ); float pmv = drs.PrimaryMissingValue; //System.out.println( "DS pmv=" + pmv ); int nb = drs.NumberOfBits; //System.out.println( "DS nb = " + nb ); int D = drs.DecimalScaleFactor; //System.out.println( "DS D=" + D ); //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'" float DD = (float)System.Math.Pow((double)10, (double)D); //System.out.println( "DS DD=" + DD ); float R = drs.ReferenceValue; //System.out.println( "DS R=" + R ); int E = drs.BinaryScaleFactor; //System.out.println( "DS E=" + E ); //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'" float EE = (float)System.Math.Pow((double)2.0, (double)E); //System.out.println( "DS EE=" + EE ); /*Grib2JpegDecoder g2j = null; * if (nb != 0) * { * // there's data to decode * System.String[] argv = new System.String[4]; * argv[0] = "-rate"; * argv[1] = System.Convert.ToString(nb); * argv[2] = "-verbose"; * argv[3] = "off"; * //argv[ 2 ] = "-nocolorspace" ; * //argv[ 3 ] = "-Rno_roi" ; * //argv[ 4 ] = "-cdstr_info" ; * //argv[ 5 ] = "-verbose" ; * //argv[ 6 ] = "-debug" ; * g2j = new Grib2JpegDecoder(argv); * g2j.decode(raf, length - 5); * } */ Jpeg2000Decoder decoder = new Jpeg2000Decoder(); byte[] buf = new byte[length - 5]; // TODO Check cast int res = raf.Read(buf, 0, length - 5); int[] values = null; if (res == length - 5) { values = decoder.Decode(buf, dataPoints); } else { // TODO Error handling } int numberPoints = gds.NumberPoints; //System.out.println( "DS GDS NumberPoints=" + gds.getNumberPoints() ); data = new float[numberPoints]; bool[] bitmap = bms.Bitmap; if (bitmap == null) { if (nb == 0) { // no data decoded, set to primaryMissingValue for (int i = 0; i < numberPoints; i++) { data[i] = pmv; } } else { //System.out.println( "DS jpeg data length ="+ g2j.data.length ); // record has missing bitmap if (values.Length != numberPoints) { data = null; return; } for (int i = 0; i < numberPoints; i++) { //Y = (R + ( 0 + X2) * EE)/DD ; data[i] = (R + values[i] * EE) / DD; //System.out.println( "DS data[ " + i +" ]=" + data[ i ] ); } } } else { for (int i = 0, j = 0; i < bitmap.Length; i++) { if (bitmap[i]) { data[i] = (R + values[j++] * EE) / DD; } else { data[i] = pmv; } } } scanMode = gds.ScanMode; scanningModeCheck(); } // end jpeg2000Unpacking
/// <summary> Jpeg2000 unpacking method for Grib2 data.</summary> /// <param name="raf"> /// </param> /// <param name="gds"> /// </param> /// <param name="drs"> /// </param> /// <param name="bms">bit-map section object /// </param> //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'" private void jpeg2000Unpacking(System.IO.FileStream raf, Grib2GridDefinitionSection gds, Grib2DataRepresentationSection drs, Grib2BitMapSection bms) { // 6-xx jpeg2000 data block to decode // dataPoints are number of points encoded, it could be less than the // numberPoints in the grid record if bitMap is used, otherwise equal int dataPoints = drs.DataPoints; //System.out.println( "DS DRS dataPoints=" + drs.getDataPoints() ); //System.out.println( "DS length=" + length ); float pmv = drs.PrimaryMissingValue; //System.out.println( "DS pmv=" + pmv ); int nb = drs.NumberOfBits; //System.out.println( "DS nb = " + nb ); int D = drs.DecimalScaleFactor; //System.out.println( "DS D=" + D ); //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'" float DD = (float) System.Math.Pow((double) 10, (double) D); //System.out.println( "DS DD=" + DD ); float R = drs.ReferenceValue; //System.out.println( "DS R=" + R ); int E = drs.BinaryScaleFactor; //System.out.println( "DS E=" + E ); //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'" float EE = (float) System.Math.Pow((double) 2.0, (double) E); //System.out.println( "DS EE=" + EE ); /*Grib2JpegDecoder g2j = null; if (nb != 0) { // there's data to decode System.String[] argv = new System.String[4]; argv[0] = "-rate"; argv[1] = System.Convert.ToString(nb); argv[2] = "-verbose"; argv[3] = "off"; //argv[ 2 ] = "-nocolorspace" ; //argv[ 3 ] = "-Rno_roi" ; //argv[ 4 ] = "-cdstr_info" ; //argv[ 5 ] = "-verbose" ; //argv[ 6 ] = "-debug" ; g2j = new Grib2JpegDecoder(argv); g2j.decode(raf, length - 5); } */ Jpeg2000Decoder decoder = new Jpeg2000Decoder(); byte[] buf = new byte[length-5]; // TODO Check cast int res = raf.Read(buf, 0, length-5); int[] values = null; if( res == length-5 ) { values = decoder.Decode(buf, dataPoints); } else { // TODO Error handling } int numberPoints = gds.NumberPoints; //System.out.println( "DS GDS NumberPoints=" + gds.getNumberPoints() ); data = new float[numberPoints]; bool[] bitmap = bms.Bitmap; if (bitmap == null) { if (nb == 0) { // no data decoded, set to primaryMissingValue for (int i = 0; i < numberPoints; i++) { data[i] = pmv; } } else { //System.out.println( "DS jpeg data length ="+ g2j.data.length ); // record has missing bitmap if (values.Length != numberPoints) { data = null; return ; } for (int i = 0; i < numberPoints; i++) { //Y = (R + ( 0 + X2) * EE)/DD ; data[i] = (R + values[i] * EE) / DD; //System.out.println( "DS data[ " + i +" ]=" + data[ i ] ); } } } else { for (int i = 0, j = 0; i < bitmap.Length; i++) { if (bitmap[i]) { data[i] = (R + values[j++] * EE) / DD; } else { data[i] = pmv; } } } scanMode = gds.ScanMode; scanningModeCheck(); }