Пример #1
0
  /**
   * Sync the file
   *
   * @return true if needed to sync
   * @throws IOException problem synching the file
   */
  public boolean sync() throws IOException {
    // printStack("***************************** sync ************************", 100);
    // System.out.printf("check sync on %s (%s) %n", raf.getLocation(),
    // Calendar.getInstance().getTime());

    if (gemreader.getInitFileSize() < raf.length()) {
      long start = System.currentTimeMillis();
      Trace.msg(
          "GEMPAKStationIOSP.sync: file "
              + raf.getLocation()
              + " is bigger: "
              + raf.length()
              + " > "
              + gemreader.getInitFileSize());
      Trace.call1("GEMPAKStationIOSP.sync: reader.init");
      gemreader.init(raf, true);
      Trace.call2("GEMPAKStationIOSP.sync: reader.init");
      Trace.call1("GEMPAKStationIOSP.sync: buildNCFile");
      // reconstruct the ncfile objects
      buildNCFile();
      Trace.call2("GEMPAKSIOSP.sync: buildNCFile");
      // System.out.printf("sync on %s took %d msecs%n", raf.getLocation(),
      // (System.currentTimeMillis()-start));
      return true;
    }
    return false;
  }
Пример #2
0
 /**
  * Is this a valid file?
  *
  * @param raf RandomAccessFile to check
  * @return true if a valid Gempak grid file
  * @throws IOException problem reading file
  */
 public boolean isValidFile(RandomAccessFile raf) throws IOException {
   try {
     gemreader = makeStationReader();
     Trace.call1("GEMPAKSIOSP.isValidFile: reader.init");
     gemreader.init(raf, false);
     Trace.call2("GEMPAKSIOSP.isValidFile: reader.init");
   } catch (Exception ioe) {
     return false;
   }
   return true;
 }
Пример #3
0
 /** Add on global attributes for all types */
 protected void addGlobalAttributes() {
   // global stuff
   ncfile.addAttribute(null, new Attribute("Conventions", getConventions()));
   String fileType = "GEMPAK " + gemreader.getFileType();
   ncfile.addAttribute(null, new Attribute("file_format", fileType));
   ncfile.addAttribute(
       null,
       new Attribute(
           "history",
           "Direct read of "
               + fileType
               + " into NetCDF-Java 4.2 API")); //  at " + dateFormat.toDateTimeStringISO(new
   // Date())));
   ncfile.addAttribute(null, new Attribute(CF.FEATURE_TYPE, getCFFeatureType()));
 }
Пример #4
0
 /**
  * Make a structure for the part
  *
  * @param partName partname
  * @param dimensions dimensions for the structure
  * @param includeMissing true to include the missing variable
  * @return a Structure
  */
 protected Structure makeStructure(String partName, List dimensions, boolean includeMissing) {
   List<GempakParameter> params = gemreader.getParameters(partName);
   if (params == null) {
     return null;
   }
   Structure sVar = new Structure(ncfile, null, null, partName);
   sVar.setDimensions(dimensions);
   for (GempakParameter param : params) {
     sVar.addMemberVariable(makeParamVariable(param, null));
   }
   if (includeMissing) {
     sVar.addMemberVariable(makeMissingVariable());
   }
   return sVar;
 }
Пример #5
0
  /**
   * Open the service provider for reading.
   *
   * @param raf file to read from
   * @param ncfile netCDF file we are writing to (memory)
   * @param cancelTask task for cancelling
   * @throws IOException problem reading file
   */
  public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask)
      throws IOException {

    // System.out.printf("GempakSurfaceIOSP open %s (%s) %n", raf.getLocation(),
    // Calendar.getInstance().getTime());

    this.raf = raf;
    this.ncfile = ncfile;
    long start = System.currentTimeMillis();
    if (gemreader == null) {
      gemreader = makeStationReader();
    }
    Trace.call1("GEMPAKStationIOSP.open: initTables");
    initTables();
    Trace.call2("GEMPAKStationIOSP.open: initTables");
    Trace.call1("GEMPAKStationIOSP.open: reader.init");
    gemreader.init(raf, true);
    Trace.call2("GEMPAKStationIOSP.open: reader.init");
    buildNCFile();
  }
Пример #6
0
 /**
  * Make the station variables from a representative station
  *
  * @param stations list of stations
  * @param dim station dimension
  * @return the list of variables
  */
 protected List<Variable> makeStationVars(List<GempakStation> stations, Dimension dim) {
   int numStations = stations.size();
   boolean useSTID = true;
   for (GempakStation station : stations) {
     if (station.getSTID().equals("")) {
       useSTID = false;
       break;
     }
   }
   List<Variable> vars = new ArrayList<Variable>();
   List<String> stnKeyNames = gemreader.getStationKeyNames();
   for (String varName : stnKeyNames) {
     Variable v = makeStationVariable(varName, dim);
     // use STNM or STID as the name or description
     Attribute stIDAttr = new Attribute("standard_name", "station_id");
     if (varName.equals(GempakStation.STID) && useSTID) {
       v.addAttribute(stIDAttr);
     }
     if (varName.equals(GempakStation.STNM) && !useSTID) {
       v.addAttribute(stIDAttr);
     }
     vars.add(v);
   }
   // see if we fill these in completely now
   if ((dim != null) && (numStations > 0)) {
     for (Variable v : vars) {
       Array varArray;
       if (v.getDataType().equals(DataType.CHAR)) {
         int[] shape = v.getShape();
         varArray = new ArrayChar.D2(shape[0], shape[1]);
       } else {
         varArray = get1DArray(v.getDataType(), numStations);
       }
       int index = 0;
       String varname = v.getFullName();
       for (GempakStation stn : stations) {
         String test = "";
         if (varname.equals(GempakStation.STID)) {
           test = stn.getName();
         } else if (varname.equals(GempakStation.STNM)) {
           ((ArrayInt.D1) varArray)
               .set(
                   index,
                   // (int) (stn.getSTNM() / 10));
                   (int) (stn.getSTNM()));
         } else if (varname.equals(GempakStation.SLAT)) {
           ((ArrayFloat.D1) varArray).set(index, (float) stn.getLatitude());
         } else if (varname.equals(GempakStation.SLON)) {
           ((ArrayFloat.D1) varArray).set(index, (float) stn.getLongitude());
         } else if (varname.equals(GempakStation.SELV)) {
           ((ArrayFloat.D1) varArray).set(index, (float) stn.getAltitude());
         } else if (varname.equals(GempakStation.STAT)) {
           test = stn.getSTAT();
         } else if (varname.equals(GempakStation.COUN)) {
           test = stn.getCOUN();
         } else if (varname.equals(GempakStation.STD2)) {
           test = stn.getSTD2();
         } else if (varname.equals(GempakStation.SPRI)) {
           ((ArrayInt.D1) varArray).set(index, stn.getSPRI());
         } else if (varname.equals(GempakStation.SWFO)) {
           test = stn.getSWFO();
         } else if (varname.equals(GempakStation.WFO2)) {
           test = stn.getWFO2();
         }
         if (!test.equals("")) {
           ((ArrayChar.D2) varArray).setString(index, test);
         }
         index++;
       }
       v.setCachedData(varArray, false);
     }
   }
   return vars;
 }