Package ucar.grib.grib2

Examples of ucar.grib.grib2.Grib2DataSection


    if (raf == null) return false;

    float[] data1 = null, data2 = null;
    try {
      if (ggr1.getEdition() == 2) {
        Grib2Data g2read = new Grib2Data(raf);
        data1 =  g2read.getData(ggr1.getGdsOffset(), ggr1.getPdsOffset(), ggr1.getReferenceTimeInMsecs());
        data2 =  g2read.getData(ggr2.getGdsOffset(), ggr2.getPdsOffset(), ggr2.getReferenceTimeInMsecs());
      } else  {
        Grib1Data g1read = new Grib1Data(raf);
        data1 =  g1read.getData(ggr1.getGdsOffset(), ggr1.getPdsOffset(), ggr1.getDecimalScale(), ggr1.isBmsExists());
        data2 =  g1read.getData(ggr2.getGdsOffset(), ggr2.getPdsOffset(), ggr2.getDecimalScale(), ggr2.isBmsExists());
      }
View Full Code Here


      // read in whole GDS as byte[]
      byte[] gdsData = new byte[length];
      // reset to beginning of section and read data
      raf.skipBytes(-4);
      raf.read(gdsData);
      gdsVars = new Grib2GDSVariables(gdsData);
      // reset for variable section read and set sectionEnd
      raf.seek(sectionEnd + 4);
      sectionEnd += length;
      // octet 5
      section = raf.read()// This is section 3
View Full Code Here

    boolean passOne = true;
    for (int i = 0; i < products.size(); i++) {
      Grib2Product product = products.get(i);
      raf.seek(product.getGdsOffset());
      GdsReader2 gds = new GdsReader2(raf, true);
      Grib2GDSVariables gpv = gds.gdsVars;
      if (passOne) {
        System.out.println(" Section = " + gpv.getSection());
        System.out.println(" Length = " + gpv.getLength());
        System.out.println(" Grid Template Number = " + gpv.getGdtn());
        passOne = false;
      }

      assert (gds.length == gpv.getLength());
      assert (gds.section == gpv.getSection());
      assert (gds.numberPoints == gpv.getNumberPoints());
      assert (gds.source == gpv.getSource());
      assert (gds.olon == gpv.getOlon());
      assert (gds.gdtn == gpv.getGdtn());

      int gdtn = gpv.getGdtn();

      switch (gdtn) {  // Grid Definition Template Number

        case 0:
        case 1:
        case 2:
        case 3:       // Latitude/Longitude Grid
          assert (gds.shape == gpv.getShape());
          assert (gds.nx == gpv.getNx());
          //System.out.println( "nx=" + nx);
          assert (gds.ny == gpv.getNy());
          //System.out.println( "ny=" + ny);
          assert (gds.basicAngle == gpv.getBasicAngle());
          assert (gds.subdivisionsangle == gpv.getSubDivisions());
          assert (gds.la1 == gpv.getLa1());
          assert (gds.lo1 == gpv.getLo1());
          assert (gds.resolution == gpv.getResolution());
          assert (gds.la2 == gpv.getLa2());
          assert (gds.lo2 == gpv.getLo2());
          assert (gds.dx == gpv.getDx());
          assert (gds.dy == gpv.getDy());
          assert (gds.grid_units.equals(gpv.getGridUnits()));
          assert (gds.scanMode == gpv.getScanMode());
          assert (gds.angle == gpv.getAngle());
         
          //  1, 2, and 3 needs checked
          if (gdtn == 1) {         //Rotated Latitude/longitude
            assert (gds.spLat == gpv.getSpLat());
            assert (gds.spLon == gpv.getSpLon());
            assert (gds.rotationangle == gpv.getRotationAngle());

          } else if (gdtn == 2) {  //Stretched Latitude/longitude
            assert (gds.poleLat == gpv.getPoleLat());
            assert (gds.poleLon == gpv.getPoleLon());
            assert (gds.factor == gpv.getStretchingFactor());

          } else if (gdtn == 3) {  //Stretched and Rotated
            // Latitude/longitude
            assert (gds.spLat == gpv.getSpLat());
            assert (gds.spLon == gpv.getSpLon());
            assert (gds.rotationangle == gpv.getRotationAngle());
            assert (gds.poleLat == gpv.getPoleLat());
            assert (gds.poleLon == gpv.getPoleLon());
            assert (gds.factor == gpv.getStretchingFactor());
          }
          break;

        case 10// Mercator
          // la1, lo1, lad, la2, and lo2 need checked
          assert (gds.shape == gpv.getShape());
          ;
          //System.out.println( "shape=" + shape );
          assert (gds.nx == gpv.getNx());
          //System.out.println( "nx=" + nx);
          assert (gds.ny == gpv.getNy());
          //System.out.println( "ny=" + ny);
          assert (gds.la1 == gpv.getLa1());
          assert (gds.lo1 == gpv.getLo1());
          assert (gds.resolution == gpv.getResolution());
          assert (gds.lad == gpv.getLaD());
          assert (gds.la2 == gpv.getLa2());
          assert (gds.lo2 == gpv.getLo2());
          assert (gds.scanMode == gpv.getScanMode());
          assert (gds.angle == gpv.getAngle());
          assert (gds.dx == gpv.getDx());
          assert (gds.dy == gpv.getDy());
          assert (gds.grid_units.equals(gpv.getGridUnits()));

          break;

        case 20// Polar stereographic projection
          // la1, lo1, lad, and lov need checked
          assert (gds.shape == gpv.getShape());
          ;
          //System.out.println( "shape=" + shape );
          assert (gds.nx == gpv.getNx());
          //System.out.println( "nx=" + nx);
          assert (gds.ny == gpv.getNy());
          //System.out.println( "ny=" + ny);
          assert (gds.la1 == gpv.getLa1());
          assert (gds.lo1 == gpv.getLo1());
          assert (gds.resolution == gpv.getResolution());
          assert (gds.lad == gpv.getLaD());
          assert (gds.lov == gpv.getLoV());
          assert (gds.dx == gpv.getDx());
          assert (gds.dy == gpv.getDy());
          assert (gds.grid_units.equals(gpv.getGridUnits()));
          assert (gds.projectionCenter == gpv.getProjectionFlag());
          assert (gds.scanMode == gpv.getScanMode());

          break;

        case 30// Lambert Conformal
          assert (gds.shape == gpv.getShape());
          ;
          //System.out.println( "shape=" + shape );
          assert (gds.nx == gpv.getNx());
          //System.out.println( "nx=" + nx);
          assert (gds.ny == gpv.getNy());
          //System.out.println( "ny=" + ny);
          assert (gds.la1 == gpv.getLa1());
          //System.out.println( "la1=" + la1 );
          assert (gds.lo1 == gpv.getLo1());
          //System.out.println( "lo1=" + lo1);
          assert (gds.resolution == gpv.getResolution());
          assert (gds.lad == gpv.getLaD());
          assert (gds.lov == gpv.getLoV());
          assert (gds.dx == gpv.getDx());
          assert (gds.dy == gpv.getDy());
          assert (gds.grid_units.equals(gpv.getGridUnits()));

          assert (gds.projectionCenter == gpv.getProjectionFlag());
          assert (gds.scanMode == gpv.getScanMode());
          assert (gds.latin1 == gpv.getLatin1());
          assert (gds.latin2 == gpv.getLatin2());
          //System.out.println( "latin1=" + latin1);
          //System.out.println( "latin2=" + latin2);
          assert (gds.spLat == gpv.getSpLat());
          assert (gds.spLon == gpv.getSpLon());
          //System.out.println( "spLat=" + spLat);
          //System.out.println( "spLon=" + spLon);

          break;

        case 31// Albers Equal Area
          // la1, lo1, lad, and lov need checked
          assert (gds.shape == gpv.getShape());
          //System.out.println( "shape=" + shape );
          assert (gds.nx == gpv.getNx());
          //System.out.println( "nx=" + nx);
          assert (gds.ny == gpv.getNy());
          //System.out.println( "ny=" + ny);
          assert (gds.la1 == gpv.getLa1());
          //System.out.println( "la1=" + la1 );
          assert (gds.lo1 == gpv.getLo1());
          //System.out.println( "lo1=" + lo1);
          assert (gds.resolution == gpv.getResolution());
          assert (gds.lad == gpv.getLaD());
          assert (gds.lov == gpv.getLoV());
          assert (gds.dx == gpv.getDx());
          assert (gds.dy == gpv.getDy());
          assert (gds.grid_units.equals(gpv.getGridUnits()));

          assert (gds.projectionCenter == gpv.getProjectionFlag());
          assert (gds.scanMode == gpv.getScanMode());
          assert (gds.latin1 == gpv.getLatin1());
          assert (gds.latin2 == gpv.getLatin2());
          //System.out.println( "latin1=" + latin1);
          //System.out.println( "latin2=" + latin2);
          assert (gds.spLat == gpv.getSpLat());
          assert (gds.spLon == gpv.getSpLon());
          //System.out.println( "spLat=" + spLat);
          //System.out.println( "spLon=" + spLon);

          break;

        case 40:
        case 41:
        case 42:
        case 43// Gaussian latitude/longitude
          // octet 15
          assert (gds.shape == gpv.getShape());
          //System.out.println( "shape=" + shape );
          // octets 31-34
          assert (gds.nx == gpv.getNx());
          //System.out.println( "nx=" + nx);
          // octets 35-38
          assert (gds.ny == gpv.getNy());
          //System.out.println( "ny=" + ny);
          // octets 39-42
          assert (gds.angle == gpv.getBasicAngle());
          // octets 43-46
          assert (gds.subdivisionsangle == gpv.getSubDivisions());
          //System.out.println( "ratio =" + ratio );
          // octets 47-50
          assert (gds.la1 == gpv.getLa1());
          // octets 51-54
          assert (gds.lo1 == gpv.getLo1());
          // octet 55
          assert (gds.resolution == gpv.getResolution());
          // octets 56-59
          assert (gds.la2 == gpv.getLa2());
          // octets 60-63
          assert (gds.lo2 == gpv.getLo2());
          // octets 64-67
          assert (gds.dx == gpv.getDx());
          assert (gds.grid_units.equals(gpv.getGridUnits()));

          // octet 68-71
          assert (gds.np == gpv.getNp());
          // octet 72
          assert (gds.scanMode == gpv.getScanMode());

          if (gdtn == 41) {  //Rotated Gaussian Latitude/longitude
            // octets 73-76
            assert (gds.spLat == gpv.getSpLat());
            // octets 77-80
            assert (gds.spLon == gpv.getSpLon());
            // octets 81-84
            assert (gds.rotationangle == gpv.getRotationAngle());

          } else if (gdtn == 42) {  //Stretched Gaussian
            // Latitude/longitude
            // octets 73-76
            assert (gds.poleLat == gpv.getPoleLat());
            // octets 77-80
            assert (gds.poleLon == gpv.getPoleLon());
            // octets 81-84
            assert (gds.factor == gpv.getStretchingFactor());

          } else if (gdtn == 43) {  //Stretched and Rotated Gaussian
            // Latitude/longitude
            // octets 73-76
            assert (gds.spLat == gpv.getSpLat());
            // octets 77-80
            assert (gds.spLon == gpv.getSpLon());
            // octets 81-84
            assert (gds.rotationangle == gpv.getRotationAngle());
            // octets 85-88
            assert (gds.poleLat == gpv.getPoleLat());
            // octets 89-92
            assert (gds.poleLon == gpv.getPoleLon());
            // octets 93-96
            assert (gds.factor == gpv.getStretchingFactor());
          }
          break;

        case 50:
        case 51:
        case 52:
        case 53:                     // Spherical harmonic coefficients

          gds.j = raf.readFloat();
          gds.k = raf.readFloat();
          gds.m = raf.readFloat();
          gds.method = raf.read();
          gds.mode = raf.read();
          assert (gds.grid_units.equals(gpv.getGridUnits()));
          if (gdtn == 51) {         //Rotated Spherical harmonic coefficients
            assert (gds.spLat == gpv.getSpLat());
            assert (gds.spLon == gpv.getSpLon());
            assert (gds.rotationangle == gpv.getRotationAngle());

          } else if (gdtn == 52) {  //Stretched Spherical
            // harmonic coefficients
            assert (gds.poleLat == gpv.getPoleLat());
            assert (gds.poleLon == gpv.getPoleLon());
            assert (gds.factor == gpv.getStretchingFactor());

          } else if (gdtn == 53) {  //Stretched and Rotated
            // Spherical harmonic coefficients
            assert (gds.spLat == gpv.getSpLat());
            assert (gds.spLon == gpv.getSpLon());
            assert (gds.rotationangle == gpv.getRotationAngle());
            assert (gds.poleLat == gpv.getPoleLat());
            assert (gds.poleLon == gpv.getPoleLon());
            assert (gds.factor == gpv.getStretchingFactor());
          }
          break;

        case 90// Space view perspective or orthographic
          assert (gds.shape == gpv.getShape());
          //System.out.println( "shape=" + shape );
          assert (gds.nx == gpv.getNx());
          //System.out.println( "nx=" + nx);
          assert (gds.ny == gpv.getNy());
          //System.out.println( "ny=" + ny);
          assert (gds.lap == gpv.getLap());
          assert (gds.lop == gpv.getLop());
          assert (gds.resolution == gpv.getResolution());
          assert (gds.dx == gpv.getDx());
          assert (gds.dy == gpv.getDy());
          assert (gds.grid_units.equals(gpv.getGridUnits()));
          assert (gds.xp == gpv.getXp());
          assert (gds.yp == gpv.getYp());
          assert (gds.scanMode == gpv.getScanMode());
          assert (gds.angle == gpv.getAngle());
          //altitude = GribNumbers.int4( raf ) * 1000000;
          assert (gds.altitude == gpv.getNr());
          assert (gds.xo == gpv.getXo());
          assert (gds.yo == gpv.getYo());

          break;

          /*
          case 100 :  // Triangular grid based on an icosahedron

              n2          = raf.read();
              checkSum = 7 * checkSum + n2;
              n3          = raf.read();
              checkSum = 7 * checkSum + n3;
              ni          = GribNumbers.int2(raf);
              checkSum = 7 * checkSum + ni;
              nd          = raf.read();
              checkSum = 7 * checkSum + nd;
              poleLat     = GribNumbers.int4(raf) / tenToSix;
              checkSum = 7 * checkSum + poleLat;
              poleLon     = GribNumbers.int4(raf) / tenToSix;
              checkSum = 7 * checkSum + poleLon;
              lonofcenter = GribNumbers.int4(raf);
              position    = raf.read();
              order       = raf.read();
              scanMode    = raf.read();
              n           = GribNumbers.int4(raf);
              grid_units = "";
              break;

          case 110 :  // Equatorial azimuthal equidistant projection
              shape = raf.read();
              //System.out.println( "shape=" + shape );
              scalefactorradius = raf.read();
              scaledvalueradius = GribNumbers.int4(raf);
              scalefactormajor  = raf.read();
              scaledvaluemajor  = GribNumbers.int4(raf);
              scalefactorminor  = raf.read();
              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) / tenToSix;
              checkSum = 7 * checkSum + la1;
              lo1              = GribNumbers.int4(raf) / tenToSix;
              checkSum = 7 * checkSum + lo1;
              resolution       = raf.read();
              dx = (float) (GribNumbers.int4(raf) / tenToThree);
              //checkSum = 7 * checkSum + dx;
              dy = (float) (GribNumbers.int4(raf) / tenToThree);
              //checkSum = 7 * checkSum + dy;
              grid_units = "";
              projectionCenter = raf.read();
              scanMode         = raf.read();

              break;

          case 120 :  // Azimuth-range Projection
              nb       = GribNumbers.int4(raf);
              checkSum = 7 * checkSum + nb;
              nr       = GribNumbers.int4(raf);
              checkSum = 7 * checkSum + nr;
              la1      = GribNumbers.int4(raf);
              checkSum = 7 * checkSum + la1;
              lo1      = GribNumbers.int4(raf);
              checkSum = 7 * checkSum + lo1;
              dx       = GribNumbers.int4(raf);
              //checkSum = 7 * checkSum + dx;
              grid_units = "";
              dstart   = raf.readFloat();
              scanMode = raf.read();
              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.out.println("need code to get azi and adelta");

              break;
          */
        case 204// Curvilinear orthographic
          assert (gds.shape == gpv.getShape());
          //System.out.println( "shape=" + shape );
          assert (gds.nx == gpv.getNx());
          //System.out.println( "nx=" + nx);
          assert (gds.ny == gpv.getNy());
          //System.out.println( "ny=" + ny);
          // octets 39 - 54 not used, set to 0
          assert (gds.resolution == gpv.getResolution());
          // octets 56 - 71 not used
          assert (gds.scanMode == gpv.getScanMode());
          assert (gds.grid_units.equals(gpv.getGridUnits()));
          break;

        default:
          System.out.println("Unknown Grid Type "
              + Integer.toString(gdtn));
      // end switch

      // calculate earth radius
      if (((gdtn < 50) || (gdtn > 53)) && (gdtn != 100) && (gdtn != 120)) {
        if (gds.shape == 0) {
          assert (gds.earthRadius == gpv.getEarthRadius());
        } else if (gds.shape == 1) {
          assert (gds.earthRadius == gpv.getEarthRadius());
        } else if (gds.shape == 2) {
          assert (gds.majorAxis == gpv.getMajorAxis());
          assert (gds.minorAxis == gpv.getMinorAxis());
        } else if (gds.shape == 3) {
          //System.out.println( "majorAxisScale =" + scalefactormajor );
          //System.out.println( "majorAxisiValue =" + scaledvaluemajor );
          assert (gds.majorAxis == gpv.getMajorAxis());

          //System.out.println( "minorAxisScale =" + scalefactorminor );
          //System.out.println( "minorAxisValue =" + scaledvalueminor );
          assert (gds.minorAxis == gpv.getMinorAxis());
        } else if (gds.shape == 4) {
          assert (gds.majorAxis == gpv.getMajorAxis());
          assert (gds.minorAxis == gpv.getMinorAxis());
        } else if (gds.shape == 6) {
          assert (gds.earthRadius == gpv.getEarthRadius());
        }
      }
      // This is a quasi-regular grid, save the number of pts in each parallel
      if (gds.olon != 0) {
        //System.out.println( "olon ="+ olon +" iolon ="+ iolon );
        int numPts;
        if ((gds.scanMode & 32) == 0) {
          numPts = gds.ny;
        } else {
          numPts = gds.nx;
        }
        gds.olonPts = new int[numPts];
        //int count = 0;
        gds.maxPts = 0;
        if (gds.olon == 1) {
          for (int ii = 0; i < numPts; i++) {
            gds.olonPts[ii] = raf.read();
            if (gds.maxPts < gds.olonPts[ii]) {
              gds.maxPts = gds.olonPts[ii];
            }
            //count += olonPts[ i ];
            //System.out.println( "parallel =" + i +" number pts ="+ latPts );
          }
        } else if (gds.olon == 2) {
          for (int ii = 0; i < numPts; i++) {
            gds.olonPts[ii] = raf.readUnsignedShort();
            if (gds.maxPts < gds.olonPts[ii]) {
              gds.maxPts = gds.olonPts[ii];
            }
            //count += olonPts[ i ];
            //System.out.println( "parallel =" + i +" number pts ="+ latPts );
          }
        }
        if ((gds.scanMode & 32) == 0) {
          gds.nx = gds.maxPts;
        } else {
          gds.ny = gds.maxPts;
        }
        //double lodiff = gds.getLo2() - gds.getLo1();
        gds.dx = (float) (gds.lo2 - gds.lo1) / (gds.nx - 0);
        //System.out.println( "total number pts ="+ count );
      }
      assert (gds.gdskey == gpv.getGdsKey());
      gds = null;
    }
    products = null;
  }
View Full Code Here

            populateGDS1(ggdr, gdsv, gdskey);
            gridIndex.addHorizCoordSys(ggdr);
            //System.out.println("GDS length =" + gdsv.getLength());
            //System.out.println("GDS GdsKey =" + gdsv.getOldTypeGdsKey());
          } else {
            Grib2GDSVariables gdsv = new Grib2GDSVariables(gdsData);
            GribGridDefRecord ggdr = new GribGridDefRecord(gdsv);
            if (index_version.startsWith("8.0")) {
              gdskey = gdsv.get80TypeGdsKey();
            } else {
              gdskey = gdsv.getGdsKey(); // version higher than 8.0
            }
            populateGDS2(ggdr, gdsv, gdskey);
            gridIndex.addHorizCoordSys(ggdr);
            //System.out.println("GDS length =" + gdsv.getLength());
            //System.out.println("GDS GdsKey =" + gdsv.getGdsKey());
View Full Code Here

    ncfile.addAttribute(null, new Attribute("Conventions", "CF-1.4"));

    String center = null;
    String subcenter = null;
    if ( lookup instanceof Grib2GridTableLookup ) {
      Grib2GridTableLookup g2lookup = (Grib2GridTableLookup) lookup;
      GribGridRecord ggr = (GribGridRecord) firstRecord;
      center = g2lookup.getFirstCenterName();
      ncfile.addAttribute(null, new Attribute("Originating_center", center));
      subcenter = g2lookup.getFirstSubcenterName();
      if (subcenter != null)
        ncfile.addAttribute(null, new Attribute("Originating_subcenter", subcenter));

      String model = g2lookup.getModel();
      if (model != null)
        ncfile.addAttribute(null, new Attribute("Generating_Model", model));
      if (null != g2lookup.getFirstProductStatusName())
        ncfile.addAttribute(null, new Attribute("Product_Status", g2lookup.getFirstProductStatusName()));
      ncfile.addAttribute(null, new Attribute("Product_Type", g2lookup.getFirstProductTypeName()));

    } else if ( lookup instanceof Grib1GridTableLookup ) {
      Grib1GridTableLookup g1lookup = (Grib1GridTableLookup) lookup;
      center = g1lookup.getFirstCenterName();
      subcenter = g1lookup.getFirstSubcenterName();
View Full Code Here

    } else {
      flag = Grib2Tables.VectorComponentFlag.gridRelative.toString();
    }

    if (lookup instanceof Grib2GridTableLookup) {
      Grib2GridTableLookup g2lookup = (Grib2GridTableLookup) lookup;
      GribGridRecord ggr = (GribGridRecord) firstRecord;
      Grib2Pds pds2 = (Grib2Pds) ggr.getPds();

      int[] paramId = g2lookup.getParameterId(firstRecord);
      v.addAttribute(new Attribute("GRIB_param_discipline", lookup.getDisciplineName(firstRecord)));
      v.addAttribute(new Attribute("GRIB_param_category", lookup.getCategoryName(firstRecord)));
      v.addAttribute(new Attribute("GRIB_param_name", param.getName()));
      v.addAttribute(new Attribute("GRIB_generating_process_type", g2lookup.getGenProcessTypeName(firstRecord)));
      v.addAttribute(new Attribute("GRIB_param_id", Array.factory(int.class, new int[]{paramId.length}, paramId)));
      v.addAttribute(new Attribute("GRIB_product_definition_template", pds2.getProductDefinitionTemplate()));
      v.addAttribute(new Attribute("GRIB_product_definition_template_desc", Grib2Tables.codeTable4_0( pds2.getProductDefinitionTemplate())));
      v.addAttribute(new Attribute("GRIB_level_type", new Integer(pds2.getLevelType1())));
      v.addAttribute(new Attribute("GRIB_level_type_name", lookup.getLevelName(firstRecord)));
View Full Code Here

  private void comparePDS2(String gribFile) throws IOException {

    RandomAccessFile raf = new RandomAccessFile(gribFile, "r");
    raf.order(RandomAccessFile.BIG_ENDIAN);
    System.out.println("Comparing PDSs");
    Grib2Input g2i = new Grib2Input(raf);
    // params getProducts (implies  unique GDSs too), oneRecord
    g2i.scan(true, false);
    List<Grib2Product> products = g2i.getProducts();
    boolean passOne = true;
    for (int i = 0; i < products.size(); i++) {
      Grib2Product product = products.get(i);
      raf.seek(product.getPdsOffset());
      PdsReader2 pds = new PdsReader2(raf);
View Full Code Here

  private void compareGDS2(String gribFile) throws IOException {

    RandomAccessFile raf = new RandomAccessFile(gribFile, "r");
    raf.order(RandomAccessFile.BIG_ENDIAN);
    System.out.println("Comparing GDSs");
    Grib2Input g2i = new Grib2Input(raf);
    // params getProducts (implies  unique GDSs too), oneRecord
    g2i.scan(true, false);
    List<Grib2Product> products = g2i.getProducts();
    boolean passOne = true;
    for (int i = 0; i < products.size(); i++) {
      Grib2Product product = products.get(i);
      raf.seek(product.getGdsOffset());
      GdsReader2 gds = new GdsReader2(raf, true);
View Full Code Here

    boolean passOne = true;
    for (int i = 0; i < products.size(); i++) {
      Grib2Product product = products.get(i);
      raf.seek(product.getPdsOffset());
      PdsReader2 pds = new PdsReader2(raf);
      Grib2Pds gpv = pds.pdsVars;
      if (passOne) {
        System.out.println(" Section = " + gpv.getSection());
        System.out.println(" Length = " + gpv.getLength());
        System.out.println(" ProductDefinition = " + gpv.getProductDefinitionTemplate());
        passOne = false;
      }

      assert (pds.length == gpv.getLength());
      assert (pds.section == gpv.getSection());
      assert (pds.coordinates == gpv.getNumberCoordinates());
      assert (pds.productDefinition == gpv.getProductDefinitionTemplate());
      assert (pds.parameterCategory == gpv.getParameterCategory());
      assert (pds.parameterNumber == gpv.getParameterNumber());
      if (pds.productDefinition < 20) {  // NCEP models
        assert (pds.typeGenProcess == gpv.getGenProcessType());
        assert (pds.timeRangeUnit == gpv.getTimeUnit());
        //System.out.println( i +" "+ pds.forecastTime +" "+ gpv.getForecastTime());
        assert (pds.forecastTime == gpv.getForecastTime());
        assert (pds.typeFirstFixedSurface == gpv.getLevelType1());
        assert (pds.FirstFixedSurfaceValue == gpv.getLevelValue1());
        assert (pds.typeSecondFixedSurface == gpv.getLevelType2());
        assert (pds.SecondFixedSurfaceValue == gpv.getLevelValue2());
      }

      if ((pds.productDefinition == 1) || (pds.productDefinition == 11)) {
        assert (pds.typeEnsemble == gpv.getPerturbationType());
        assert (pds.perturbNumber == gpv.getPerturbationNumber());
        assert (pds.numberForecasts == gpv.getNumberEnsembleForecasts());

      } else if (pds.productDefinition == 2) {
        assert (pds.typeEnsemble == gpv.getPerturbationType());
        assert (pds.numberForecasts == gpv.getNumberEnsembleForecasts());

      } else if (pds.productDefinition == 5) {
        assert (pds.typeEnsemble == gpv.getPerturbationType());
        assert (pds.lowerLimit == gpv.getProbabilityLowerLimit());
        assert (pds.upperLimit == gpv.getProbabilityUpperLimit());

      } else if (pds.productDefinition == 9) {
        assert (pds.typeEnsemble == gpv.getPerturbationType());
        assert (pds.numberForecasts == gpv.getNumberEnsembleForecasts());
        // probability type
        assert (pds.lowerLimit == gpv.getProbabilityLowerLimit());
        assert (pds.upperLimit == gpv.getProbabilityUpperLimit());
      }
      pds = null;
    }
    products = null;
View Full Code Here

    }

    if (lookup instanceof Grib2GridTableLookup) {
      Grib2GridTableLookup g2lookup = (Grib2GridTableLookup) lookup;
      GribGridRecord ggr = (GribGridRecord) firstRecord;
      Grib2Pds pds2 = (Grib2Pds) ggr.getPds();

      int[] paramId = g2lookup.getParameterId(firstRecord);
      v.addAttribute(new Attribute("GRIB_param_discipline", lookup.getDisciplineName(firstRecord)));
      v.addAttribute(new Attribute("GRIB_param_category", lookup.getCategoryName(firstRecord)));
      v.addAttribute(new Attribute("GRIB_param_name", param.getName()));
      v.addAttribute(new Attribute("GRIB_generating_process_type", g2lookup.getGenProcessTypeName(firstRecord)));
      v.addAttribute(new Attribute("GRIB_param_id", Array.factory(int.class, new int[]{paramId.length}, paramId)));
      v.addAttribute(new Attribute("GRIB_product_definition_template", pds2.getProductDefinitionTemplate()));
      v.addAttribute(new Attribute("GRIB_product_definition_template_desc", Grib2Tables.codeTable4_0( pds2.getProductDefinitionTemplate())));
      v.addAttribute(new Attribute("GRIB_level_type", new Integer(pds2.getLevelType1())));
      v.addAttribute(new Attribute("GRIB_level_type_name", lookup.getLevelName(firstRecord)));
      if (pds2.isInterval())
        v.addAttribute(new Attribute("GRIB_interval_stat_type", ggr.getStatisticalProcessTypeName() ));
      if (pds2.isEnsembleDerived()) {
        Grib2Pds.PdsEnsembleDerived pdsDerived = (Grib2Pds.PdsEnsembleDerived) pds2;
        v.addAttribute(new Attribute("GRIB_ensemble_derived_type", new Integer(pdsDerived.getDerivedForecastType()) ));
      }
      if (pds2.isEnsemble())
        v.addAttribute(new Attribute("GRIB_ensemble", "true"));
      if (pds2.isProbability()) {
        Grib2Pds.PdsProbability pdsProb = (Grib2Pds.PdsProbability) pds2;
        v.addAttribute(new Attribute("GRIB_probability_type", new Integer(pdsProb.getProbabilityType()) ));
        v.addAttribute(new Attribute("GRIB_probability_lower_limit", new Double(pdsProb.getProbabilityLowerLimit()) ));
        v.addAttribute(new Attribute("GRIB_probability_upper_limit", new Double(pdsProb.getProbabilityUpperLimit()) ));
      }
View Full Code Here

TOP

Related Classes of ucar.grib.grib2.Grib2DataSection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.