Package ucar.unidata.io

Examples of ucar.unidata.io.RandomAccessFile


    // Reading of Grib files must be inside a try-catch block
    calendar = Calendar.getInstance();
    calendar.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
    PrintStream ps = System.out;
    try {
      RandomAccessFile raf = null;
      if (args.length == 3) {  // input file, output file, get data for dump
        raf = new RandomAccessFile(args[0], "r");
        ps = new PrintStream(
                new BufferedOutputStream(
                        new FileOutputStream(args[1], false)));
        displayData = args[2].equalsIgnoreCase("true");
      } else if (args.length == 2) {  // input file and output file for dump
        raf = new RandomAccessFile(args[0], "r");
        if (args[1].equalsIgnoreCase("true")
                || args[1].equalsIgnoreCase("false")) {
          displayData = args[1].equalsIgnoreCase("true");
        } else {
          ps = new PrintStream(
                  new BufferedOutputStream(
                          new FileOutputStream(args[1], false)));
        }
      } else if (args.length == 1) {
        raf = new RandomAccessFile(args[0], "r");
      } else {
        System.exit(0);
      }
      // test for a user defined parameter table read
      //GribPDSParamTable.addParameterUserLookup( "/local/robb/trunk20081229/grib/resources/resources/grib/tables/userlookup.lst");
      raf.order(RandomAccessFile.BIG_ENDIAN);
      // Create Grib1Input instance
      Grib1Input g1i = new Grib1Input(raf);
      // boolean params getProducts, oneRecord
      g1i.scan(false, false);
      // record contains objects for all 5 Grib1 sections
      ArrayList records = g1i.getRecords();
      for (int i = 0; i < records.size(); i++) {
        Grib1Record record = (Grib1Record) records.get(i);
        Grib1IndicatorSection is = record.getIs();
        Grib1ProductDefinitionSection pds = record.getPDS();
        Grib1GridDefinitionSection gds = record.getGDS();

        // create dump output here
        ps.println(
                "--------------------------------------------------------------------");
        ps.println("                        Header : "
                + record.getHeader());
        printIS(is, ps);
        printPDS(pds, ps);
        printGDS(gds, pds, ps);
        ps.println();

        if (displayData) {
          float[] data = null;
          ps.println(
                  "--------------------------------------------------------------------");
          Grib1Data gd = new Grib1Data(raf);
          // TODO: pds vars needed
          data = gd.getData(record.getDataOffset(),
                  pds.getDecimalScale(), pds.bmsExists());
          if (data != null) {
            for (int j = 0; j < data.length; j++) {
              ps.println("data[ " + j + " ]=" + data[j]);
            }
          }
          break// only display data for 1st record
        }
      }
      raf.close();    // done reading

      // Catch thrown errors from GribFile
    } catch (FileNotFoundException noFileError) {
      System.err.println("FileNotFoundException : " + noFileError);
    } catch (IOException ioError) {
View Full Code Here


      forecast = Integer.parseInt(args[4]);
    } else {
      System.out.println("Not correct number of parms, either 1 or 4");
      return;
    }
    RandomAccessFile raf = new RandomAccessFile(fileName, "r");
    Grib2ExtractRawData erd = new Grib2ExtractRawData(raf);
    erd.scan(discipline, category, number, forecast, gOffset, pOffset);
  }
View Full Code Here

   * @param args Grib name and PDS offset in Grib
   * @throws IOException on io error
   */
  // process command line switches
  static public void main(String[] args) throws IOException, NoValidGribException {
    RandomAccessFile raf = null;
    PrintStream ps = System.out;
    String infile = args[0];
    raf = new RandomAccessFile(infile, "r");
    raf.order(RandomAccessFile.BIG_ENDIAN);
    // This is the GDS offset
    raf.skipBytes(Integer.parseInt(args[1]));
    // backup to PDS; most of the time it's only 28 bytes
    //raf.skipBytes( -28 ); //TODO: check
    Grib1ProductDefinitionSection pds = new Grib1ProductDefinitionSection(raf);
    Grib1Pds gpv = pds.pdsVars;
    ps.println("Length = " + gpv.getLength());
View Full Code Here

      fileName = args[0];
    } else {
      System.out.println("No file name given");
      return;
    }
    RandomAccessFile raf = new RandomAccessFile(fileName, "r");
    Grib1SplitByGridID sbgid = new Grib1SplitByGridID(raf);
    sbgid.scan();
  }
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);
      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 );
View Full Code Here

  }


  private void comparePDS1(String gribFile) throws IOException {

    RandomAccessFile raf = new RandomAccessFile(gribFile, "r");
    raf.order(RandomAccessFile.BIG_ENDIAN);
    System.out.println("Comparing PDSs");
    try {
       Input1 g1i = new  Input1(raf);
      // params getProducts (implies  unique GDSs too), oneRecord
      g1i.scan(true, false);
      ArrayList  products =  g1i.getProducts();
      boolean passOne = true;
      for (int i = 0; i < products.size(); i++) {
        Grib1Product product = (Grib1Product) products.get(i);
        raf.seek(product.getOffset1());
        PdsReader1 pds = new PdsReader1(raf);
        Grib1Pds gpv = pds.pdsVars;
        if (passOne) {
          System.out.println(" Section = " + gpv.getSection());
          System.out.println(" Length = " + gpv.getLength());
View Full Code Here

  }

  private void compareGDS1(String gribFile) throws IOException {

    RandomAccessFile raf = new RandomAccessFile(gribFile, "r");
    raf.order(RandomAccessFile.BIG_ENDIAN);
    System.out.println("Comparing GDSs");
    try {

      Grib1Input g1i = new  Grib1Input(raf);
      // params getProducts (implies  unique GDSs too), oneRecord
      g1i.scan(true, false);
      List<Grib1Product> products = g1i.getProducts();
      boolean passOne = true;
      for (int i = 0; i < products.size(); i++) {
        Grib1Product product = products.get(i);
        Grib1ProductDefinitionSection pds = product.getPDS();
        Grib1Pds g1pdsv = pds.getPdsVars();
        if (product.getOffset1() == -1)
          break;
        raf.seek(product.getOffset1());
        GdsReader1 gds = new GdsReader1(raf, true);
        Grib1GDSVariables gpv = gds.gdsVars;
        if (passOne) {
          System.out.println(" Section = " + gpv.getSection());
          System.out.println(" Length = " + gpv.getLength());
View Full Code Here

   * test the Grib edition of the files.
   *
   * @throws IOException
   */
  public final void testEdition() throws IOException {
    RandomAccessFile raf;
    int edition = 0;
    System.out.println("\nTesting GRIB edition of RUC.wmo");
    raf = new RandomAccessFile(dataPath + "RUC.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("RUC.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of AVN.wmo");
    raf = new RandomAccessFile(dataPath + "AVN.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("AVN.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of MRF.wmo");
    raf = new RandomAccessFile(dataPath + "MRF.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("MRF.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of OCEAN.wmo");
    raf = new RandomAccessFile(dataPath + "OCEAN.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("OCEAN.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of RUC2.wmo");
    raf = new RandomAccessFile(dataPath + "RUC2.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("RUC2.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of WAVE.wmo");
    raf = new RandomAccessFile(dataPath + "WAVE.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("WAVE.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of ecmf.wmo");
    raf = new RandomAccessFile(dataPath + "ecmf.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("ecmf.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of ensemble.wmo");
    raf = new RandomAccessFile(dataPath + "ensemble.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("ensemble.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of extended.wmo");
    raf = new RandomAccessFile(dataPath + "extended.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("extended.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of thin.wmo");
    raf = new RandomAccessFile(dataPath + "thin.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("thin.wmo edition", 1, edition);
    System.out.println("\nTesting GRIB edition of ukm.wmo");
    raf = new RandomAccessFile(dataPath + "ukm.wmo", "r");
    edition = GribChecker.getEdition(raf);
    assertEquals("ukm.wmo edition", 1, edition);
  }
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);
      Grib2Pds gpv = pds.pdsVars;
      if (passOne) {
        System.out.println(" Section = " + gpv.getSection());
        System.out.println(" Length = " + gpv.getLength());
View Full Code Here

                return dataFile;
            } else {
                dataFile.close();
            }
        }
        dataFile = new RandomAccessFile(dataFilePath, "r");
        dataFile.order(getByteOrder());
        return dataFile;
    }
View Full Code Here

TOP

Related Classes of ucar.unidata.io.RandomAccessFile

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.