Package ucar.grid

Examples of ucar.grid.GridIndex


    String chk =  args[1].replace( GribIndexName.currentSuffix, ".chk");

    boolean same = true;
    // read in Indexes and compare record count
    GridIndex gbxIdx = new GribIndexReader().open( args[1] );
    GridIndex chkIdx = new GribIndexReader().open( chk );
    if ( gbxIdx.getGridCount() != chkIdx.getGridCount() ) {
      sb.append("\n\tDuplicates Not removed" );
      sb.append( "\n\tNumber of Grid records differ: " );
      sb.append( gbxIdx.getGridCount() );
      sb.append( " not equal to check record count " );
      sb.append( chkIdx.getGridCount() );
      same = false;
    }
    return same;
  }
View Full Code Here


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

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

    //String file = "RUC2_CONUS_20km_surface_20051011_2300.grib1";
    String file = "wrf.grib";
    System.out.println("\nTesting indexing of "+ file);
    args[0] = dataPath + file;
    if (reset) {
      args[1] = testPath + file+ GribIndexName.currentSuffix;
      f = new File( args[1] );
      f.delete();
      System.out.println("Creating new test index " + args[1]);
      Grib1WriteIndex.main(args);
    } else {
      args[1] = dataPath + file+ GribIndexName.currentSuffix;
      Grib1WriteIndex.main(args);
      GridIndex index1 = new GribIndexReader().open(args[1]);

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

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

    public boolean sync() {
        try {
            if ( !mcGridReader.init()) {
                return false;
            }
            GridIndex index =
                ((McIDASGridReader) mcGridReader).getGridIndex();
            // reconstruct the ncfile objects
            ncfile.empty();
            open(index, null);
          return true;
View Full Code Here

    this.rafLength = raf.length();
    raf.order(RandomAccessFile.BIG_ENDIAN);

    long start = System.currentTimeMillis();

    GridIndex index = getIndex(raf.getLocation());
    Map<String, String> attr = index.getGlobalAttributes();
    saveEdition = attr.get("grid_edition").equals("2") ? 2 : 1;
    version = Float.parseFloat(attr.get("index_version"));
    GridTableLookup lookup = (saveEdition == 2) ? getLookup2() : getLookup1();

    // make it into netcdf objects
View Full Code Here

        return new GribIndexReader().open(indexLocation, ios);
      }
    }

    File indexFile = getIndexFile(dataLocation);
    GridIndex index = null;

    // if index exist already, read it
    if (!forceNewIndex && indexFile.exists()) {
      try {
        index = new GribIndexReader().open(indexFile.getPath());
        if (index != null) {
          log.debug("  opened index = " + indexFile.getPath());

          // deal with possiblity that the grib file has changed, and the index should be extended or rewritten.
          if ((indexFileModeOnOpen != IndexExtendMode.readonly)) {

            String lengthS = index.getGlobalAttributes().get("length");
            long indexRafLength = (lengthS == null) ? 0 : Long.parseLong(lengthS);
            if (indexRafLength != rafLength) {
              if (log.isDebugEnabled())
                log.debug("  dataFile " + dataLocation + " length has changed: indexRafLength= " + indexRafLength + " rafLength= " + rafLength);
View Full Code Here

    return indexFile;
  }


  private GridIndex writeIndex(File indexFile, RandomAccessFile raf) throws IOException {
    GridIndex index = null;

    if (indexFile.exists()) {
      boolean ok = indexFile.delete();
      log.debug("Deleted old index " + indexFile.getPath() + " = " + ok);
    }
View Full Code Here

  public boolean sync() throws IOException {

    // has the file changed?
    File indexFile = getIndexFile(raf.getLocation());
    if (rafLength != raf.length() || indexLength != indexFile.length()) {
      GridIndex index;
      if (indexFileModeOnSync == IndexExtendMode.readonly) {
        log.debug("  sync() read Index = " + indexFile.getPath());
        try {
          index = new GribIndexReader().open(indexFile.getPath());
        } catch (Exception e) {
View Full Code Here

    return false;
  }

  private GridIndex extendIndex(File gribFile, File indexFile, RandomAccessFile raf) throws IOException {

    GridIndex index = null;

    if (saveEdition == 0) {
      raf.seek(0);
      Grib2Input g2i = new Grib2Input(raf);
      saveEdition = g2i.getEdition();
View Full Code Here

    ncfileBinary.close();
    ncfileText.close();
  }

  void compareIndexes(String fileBinary, String fileText) throws IOException {
    GridIndex giB = new GribIndexReader().open(fileBinary + ".gbx8");
    GridIndex giT = new GribIndexReader().open(fileText + ".gbx");

    // Coordinate systems
    List<GridDefRecord> hcsB = giB.getHorizCoordSys();
    List<GridDefRecord> hcsT = giT.getHorizCoordSys();

    for (int i = 0; i < hcsB.size(); i++) {
      GridDefRecord gdrB = hcsB.get(i);
      GridDefRecord gdrT = hcsT.get(i);

      java.util.Set<String> keysB = gdrB.getKeys();
      for (String key : keysB) {
        if (key.equals("grid_units") || key.equals("created") || key.equals("location")
            || key.equals("VectorComponentFlag") || key.equals("GDSkey")
            || key.equals("grid_name") || key.equals("scanning_mode")
            || key.equals("grid_shape") )
          continue;
        String valueB = gdrB.getParam(key);
        String valueT = gdrT.getParam(key);
        if (!valueB.equals(valueT))
          System.out.println("hcs " + key + " differ for Binary and Text  " + valueB + " " + valueT);
        assert( valueB.equals(valueT) );
      }
      java.util.Set<String> keysT = gdrT.getKeys();
      for (String key : keysT) {
        if (key.equals("grid_units") || key.equals("created") || key.equals("location")
            || key.equals("VectorComponentFlag") || key.equals("GDSkey")
            || key.equals("grid_name") || key.equals("ScanningMode")
            || key.equals("grid_shape") )
          continue;
        String valueB = gdrB.getParam(key);
        String valueT = gdrT.getParam(key);
        if (!valueT.equals(valueB))
          System.out.println("hcs " + key + " differ for Text and Binary " + valueT + " " + valueB);
        assert( valueB.equals(valueT) );
      }
    }

    // Attribubutes
    Map<String, String> attB = giB.getGlobalAttributes();
    Map<String, String> attT = giT.getGlobalAttributes();
    java.util.Set<String> keysB = attB.keySet();
    for (String key : keysB) {
      if (key.equals("basetime") || key.equals("created") || key.equals("location")
          || key.equals("grid_units") || key.equals("ensemble"))
        continue;
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.