Package ucar.grid

Examples of ucar.grid.GridIndex


        if (gemreader == null) {
            gemreader = new GempakGridReader(raf.getLocation());
        }
        initTables();
        gemreader.init(raf, true);
        GridIndex index = gemreader.getGridIndex();
        open(index, cancelTask);
        if (debugOpen) {
            System.out.println(" GridServiceProvider.open "
                               + ncfile.getLocation() + " took "
                               + (System.currentTimeMillis() - start));
View Full Code Here


     * @throws IOException problem synching the file
     */
    public boolean sync() throws IOException {
        if ((gemreader.getInitFileSize() < raf.length()) && extendIndex) {
            gemreader.init(true);
            GridIndex index = gemreader.getGridIndex();
            // reconstruct the ncfile objects
            ncfile.empty();
            open(index, null);
            return true;
        }
View Full Code Here

    protected boolean init(boolean fullCheck) throws IOException {
        if (rf == null) {
            logError("File is null");
            return false;
        }
        gridIndex = new GridIndex(rf.getLocation());

        rf.order(RandomAccessFile.BIG_ENDIAN);
        int numEntries = Math.abs(readInt(10));
        if (numEntries > 1000000) {
            needToSwap = true;
View Full Code Here

        String file = "GRID2001";
        if (args.length > 0) {
            file = args[0];
        }
        McIDASGridReader mg        = new McIDASGridReader(file);
        GridIndex        gridIndex = mg.getGridIndex();
        List             grids     = gridIndex.getGridRecords();
        System.out.println("found " + grids.size() + " grids");
        int num = Math.min(grids.size(), 10);
        for (int i = 0; i < num; i++) {
            System.out.println(grids.get(i));
        }
View Full Code Here

   */
  public GridIndex open(String location, InputStream ios) throws IOException {

    long start = System.currentTimeMillis();

    GridIndex gridIndex = new GridIndex(location);
    BufferedReader dataIS = null;
    boolean old_index_version = false;
    try {
      dataIS = new BufferedReader(new InputStreamReader(ios));

      // section 1 - global attributes
      String centerS = null, sub_centerS = null, table_versionS = null;
      while (true) {
        String line = dataIS.readLine();
        if (line == null || line.length() == 0) { // 0 length/corrupted index
          return gridIndex;
        }
        if (line.startsWith("--")) {
          break;
        }

        int pos = line.indexOf(" = ");
        if (pos > 0) {
          String key = line.substring(0, pos);
          String value = line.substring(pos + 3).replaceAll( " ", "%20" );
          gridIndex.addGlobalAttribute(key, value);
          if (key.equals("center")) {
            centerS = value;
          } else if (key.equals("sub_center")) {
            sub_centerS = value;
          } else if (key.equals("table_version")) {
            table_versionS = value;
          } else if (key.equals("index_version")) {
            old_index_version = ! value.startsWith( currentTextIndexVersion );
          }
        }
      }

      // section 2 -- grib records
      while (true) {
        String line = dataIS.readLine();
        if (line == null || line.length() == 0) { // 0 length/corrupted index
          return gridIndex;
        }
        if (line.startsWith("--")) {
          break;
        }

        StringTokenizer stoke = new StringTokenizer(line);

        String productType = stoke.nextToken();
        String discipline = stoke.nextToken();
        String category = stoke.nextToken();
        String param = stoke.nextToken();
        String typeGenProcess = stoke.nextToken();
        String levelType1 = stoke.nextToken();
        String levelValue1 = stoke.nextToken();
        String levelType2 = stoke.nextToken();
        String levelValue2 = stoke.nextToken();
        String refTime = stoke.nextToken();
        String foreTime = stoke.nextToken();
        String gdsKey = stoke.nextToken();
        if( old_index_version )
          gdsKey = Integer.toString( gdsKey.hashCode() );
        String offset1 = stoke.nextToken();
        String offset2 = stoke.nextToken();
        String decimalScale = stoke.hasMoreTokens()
            ? stoke.nextToken()
            : null;
        String bmsExists = stoke.hasMoreTokens()
            ? stoke.nextToken()
            : null;
        String center = stoke.hasMoreTokens()
            ? stoke.nextToken()
            : centerS;
        String subCenter = stoke.hasMoreTokens()
            ? stoke.nextToken()
            : sub_centerS;
        String table = stoke.hasMoreTokens()
            ? stoke.nextToken()
            : table_versionS;

        /* GribGridRecord ggr = new GribGridRecord(calendar, dateFormat,
            productType,
            discipline, category,
            param, typeGenProcess, levelType1,
            levelValue1, levelType2,
            levelValue2, refTime, foreTime,
            gdsKey, offset1, offset2,
            decimalScale, bmsExists,
            center, subCenter, table);

        gridIndex.addGridRecord(ggr);
        if (debugParse) {
          System.out.println(ggr.toString());
        }    */
      }

      // section 3+ - GDS
      GribGridDefRecord gds;
      StringBuilder sb = new StringBuilder();
      while (true) {
        String line = dataIS.readLine();
        if (line == null || line.length() == 0) {
          break;
        }
        if (line.startsWith("--")) {
          gds = new GribGridDefRecord(sb.toString());
          sb.setLength(0); //reset it
          gridIndex.addHorizCoordSys(gds);
          continue;
        }
        int pos = line.indexOf(" = ");
        // need to convert long GDSkey to int
        if ( line.startsWith(GridDefRecord.GDS_KEY)) {
          if( old_index_version ) {
            int hc = line.substring(pos + 3).hashCode();
            sb.append(line.substring(0, pos)).append("\t").append(Integer.toString(hc));
          } else {
            sb.append(line.substring(0, pos)).append("\t").append(line.substring(pos + 3));
          }
          continue;
        }
        if (pos > 0) {
          sb.append("\t").append(line.substring(0, pos)).append("\t").append(line.substring(pos + 3));
        }
      }
      // remove the Grib1 and Grib2 text indexes differences
      String gdsStr = sb.toString();
      if( ! gdsStr.contains( GridDefRecord.RADIUS_SPHERICAL_EARTH ))
        gdsStr = gdsStr.replace( "radius_spherical_earth", GridDefRecord.RADIUS_SPHERICAL_EARTH);
      gds = new GribGridDefRecord( gdsStr );
      gridIndex.addHorizCoordSys( gds );

      //dataIS.close();

      if (debugTiming) {
        long took = System.currentTimeMillis() - start;
        System.out.println(" Index read " + location + " count="
            + gridIndex.getGridCount() + " took=" + took + " msec ");
      }
      log.debug("Text index read: " + location);
      log.debug("Number Records =" + gridIndex.getGridCount() + " at " +
          dateFormat.format(Calendar.getInstance().getTime()));
      return gridIndex;

    } catch (IOException e) {
      log.error("open(): reading text index " + "[" + location + "]");
View Full Code Here

      gbx = new File( "/local/robb/data/grib/ruc_sample.grib2.gbx");
    }

    //debugTiming = true;
    //debugParse = true;
    GridIndex index;
    if (args.length < 1) {
      index = new GribReadTextIndex().open(gbx.getPath());
    } else {
      index = new GribReadTextIndex().open(args[0]);
    }
View Full Code Here

   * @param location URL or local filename of Grib Index file
   * @throws java.io.IOException
   */
  public final void show(String location) throws IOException {
    try {
      GridIndex index = new GribIndexReader().open(location);
      Map<String, String> attrs = index.getGlobalAttributes();
      System.out.println("index_version = " + attrs.get("index_version"));
      System.out.println("grid_edition = " + attrs.get("grid_edition"));
      System.out.println("location = " + attrs.get("location"));
      System.out.println("length = " + attrs.get("length"));
      System.out.println("created = " + attrs.get("created"));
      System.out.println("center = " + attrs.get("center"));
      System.out.println("sub_center = " + attrs.get("sub_center"));
      System.out.println("table_version = " + attrs.get("table_version"));
      String basetime = attrs.get("basetime");
      System.out.println("basetime = " + basetime);
      System.out.println("ensemble = " + attrs.get("ensemble"));
      System.out.println("-----------------------------------------------------------------");

      List<GridRecord> records = index.getGridRecords();
      for (GridRecord gr : records) {
        GribGridRecord ggr = (GribGridRecord) gr;
        /* System.out.println(ggr.productTemplate + " " + ggr.discipline + " " +
            ggr.category + " " + ggr.paramNumber + " " +
            ggr.typeGenProcess + " " + ggr.levelType1 + " " +
            ggr.levelValue1 + " " + ggr.levelType2 + " " +
            //ggr.levelValue2 + " " + dateFormat.format(ggr.getValidTime()) + " " +
            ggr.levelValue2 + " " + basetime + " " +
            ggr.forecastTime + " " + ggr.gdsKey + " " + ggr.offset1 + " " + ggr.offset2 + " " +
            ggr.decimalScale + " " + ggr.bmsExists + " " + ggr.center + " " +
            ggr.subCenter + " " + ggr.table + " " +
            ggr.type + " " + ggr.numberForecasts + " " + ggr.lowerLimit + " " + ggr.upperLimit);  */
      }

      System.out.println("-----------------------------------------------------------------");

      List<GridDefRecord> gdrs = index.getHorizCoordSys();

      for (GridDefRecord gdr : gdrs) {
        System.out.println(GridDefRecord.GDS_KEY + " = " + gdr.getParam(GridDefRecord.GDS_KEY));
        System.out.println(GridDefRecord.GRID_TYPE + " = " + gdr.getParamInt(GridDefRecord.GRID_TYPE));
        System.out.println(GridDefRecord.GRID_NAME + " = " + gdr.getParam(GridDefRecord.GRID_NAME));
View Full Code Here

        if ( !fullCheck) {
            return true;
        }

        gridIndex = new GridIndex(filename);
        // Make the NAV and ANAL blocks
        float[] headerArray = getFileHeader(NAVB);
        if (headerArray == null) {
            return false;
        }
View Full Code Here

      System.out.println("Creating new test index " + args[1]);
      Grib2WriteIndex.main(args);
    } else {
      args[1] = dataPath + "ndfd.wmo"+ GribIndexName.currentSuffix;
      Grib2WriteIndex.main(args);
      GridIndex index1 = new GribIndexReader().open(args[1]);

      GridIndex index2 = new GribIndexReader().open(testPath + "ndfd.wmo"+ GribIndexName.currentSuffix);
      // Compare Indexes
      testEquals(index1, index2);
      f = new File(args[1]);
      f.delete();
    }
    //if (true )
    //  return;

    System.out.println("\nTesting indexing of AVN.5deg.wmo");
    args[0] = dataPath + "AVN.5deg.wmo";
    if (reset) {
      args[1] = testPath + "AVN.5deg.wmo"+ GribIndexName.currentSuffix;
      f = new File(args[1]);
      f.delete();
      System.out.println("Creating new test index " + args[1]);
      Grib2WriteIndex.main(args);
    } else {
      args[1] = dataPath + "AVN.5deg.wmo"+ GribIndexName.currentSuffix;
      Grib2WriteIndex.main(args);
      GridIndex index1 = new GribIndexReader().open(args[1]);

      GridIndex index2 = new GribIndexReader().open(testPath + "AVN.5deg.wmo"+ GribIndexName.currentSuffix);
      // Compare Indexes
      testEquals(index1, index2);
      f = new File(args[1]);
      f.delete();
    }


    System.out.println("\nTesting indexing of CLDGRIB2.2005040905");
    args[0] = dataPath + "CLDGRIB2.2005040905";
    if (reset) {
      args[1] = testPath + "CLDGRIB2.2005040905"+ GribIndexName.currentSuffix;
      f = new File(args[1]);
      f.delete();
      System.out.println("Creating new test index " + args[1]);
      Grib2WriteIndex.main(args);
    } else {
      args[1] = dataPath + "CLDGRIB2.2005040905"+ GribIndexName.currentSuffix;
      Grib2WriteIndex.main(args);
      GridIndex index1 = new GribIndexReader().open(args[1]);

      GridIndex index2 = new GribIndexReader().open(testPath + "CLDGRIB2.2005040905"+ GribIndexName.currentSuffix);
      // Compare Indexes
      testEquals(index1, index2);
      f = new File(args[1]);
      f.delete();
    }

    System.out.println("\nTesting indexing of Global_1p0deg_Ensemble.grib2");
    args[0] = dataPath + "Global_1p0deg_Ensemble.grib2";
    if (reset) {
      args[1] = testPath + "Global_1p0deg_Ensemble.grib2"+ GribIndexName.currentSuffix;
      f = new File(args[1]);
      f.delete();
      System.out.println("Creating new test index " + args[1]);
      Grib2WriteIndex.main(args);
    } else {
      args[1] = dataPath + "Global_1p0deg_Ensemble.grib2"+ GribIndexName.currentSuffix;
      Grib2WriteIndex.main(args);
      GridIndex index1 = new GribIndexReader().open(args[1]);

      GridIndex index2 = new GribIndexReader().open(testPath + "Global_1p0deg_Ensemble.grib2"+ GribIndexName.currentSuffix);
      // Compare Indexes
      testEquals(index1, index2);
      f = new File(args[1]);
      f.delete();
    }
View Full Code Here

      System.out.printf("Failed on %s = %s%n", filename, t.getMessage());
      return;
    }

    GribGridServiceProvider iosp = (GribGridServiceProvider) ncd.getIosp();
    GridIndex index = (GridIndex) iosp.sendIospMessage("GridIndex");
    boolean isGrib1 = iosp.getFileTypeId().equals("GRIB1");

    boolean first = true;
    Map<Integer, List<String>> map = new HashMap<Integer, List<String>>();

    List<GridRecord> grList = index.getGridRecords();
    for (GridRecord gr : grList) {
      GribGridRecord ggr = (GribGridRecord) gr;
      int genType = ggr.getPds().getGenProcessId();
      if (!isGrib1) {
        Grib2Pds pds =  (Grib2Pds) ggr.getPds();
View Full Code Here

TOP

Related Classes of ucar.grid.GridIndex

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.