Ejemplo n.º 1
0
  static void test(String urlString) {
    try {
      long start = System.currentTimeMillis();
      System.out.println(" get " + urlString);

      AddePointDataReader reader = new AddePointDataReader(urlString);

      System.out.println(" took= " + (System.currentTimeMillis() - start) + " msec");
      System.out.println(reader.toString());

      System.out.println(" Param  Unit Scale");

      String[] params = reader.getParams();
      String[] units = reader.getUnits();
      int[] scales = reader.getScales();
      for (int i = 0; i < params.length; i++) {
        System.out.println(" " + params[i] + " " + units[i] + " " + scales[i]);
      }

      int[][] data = reader.getData();
      System.out.println(" nparams= " + params.length);
      System.out.println(" n= " + data.length);
      System.out.println(" m= " + data[0].length);

    } catch (AddeException e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
    }
  }
Ejemplo n.º 2
0
  static AddePointDataReader callAdde(String request) throws IOException {
    try {
      System.out.println("Call ADDE request= " + request);
      long start = System.currentTimeMillis();
      AddePointDataReader reader = new AddePointDataReader(request);
      System.out.println(" took= " + (System.currentTimeMillis() - start) + " msec");

      return reader;

    } catch (AddeException e) {
      e.printStackTrace();
      throw new IOException(e.getMessage());
    }
  }
Ejemplo n.º 3
0
 /**
  * _more_
  *
  * @param range _more_
  * @param var _more_
  * @return _more_
  * @throws Exception _more_
  */
 protected float[] getFloatData(Range range, String var) throws Exception {
   long t1 = System.currentTimeMillis();
   float[] f =
       SqlUtil.readFloat(
           SqlUtil.getIterator(select("(" + var + ")", TABLE_DATA, "order by " + varTime)),
           1,
           (float) getMissingValue(var));
   long t2 = System.currentTimeMillis();
   //            System.err.println("length:" + f.length + " time:" + (t2-t1));
   if (f.length == 0) {
     throw new BadDataException("No observations found in data base");
   }
   return f;
 }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
0
  public boolean compare(
      NetcdfFile org, NetcdfFile copy, boolean showCompare, boolean showEach, boolean compareData) {
    this.compareData = compareData;
    this.showCompare = showCompare;
    this.showEach = showEach;

    f.format("First file = %s%n", org.getLocation());
    f.format("Second file= %s%n", copy.getLocation());

    long start = System.currentTimeMillis();

    boolean ok = compareGroups(org.getRootGroup(), copy.getRootGroup());
    f.format(" Files are the same = %s%n", ok);

    long took = System.currentTimeMillis() - start;
    f.format(" Time to compare = %d msecs%n", took);

    return ok;
  }
Ejemplo n.º 6
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();
  }
  public static void main(String args[]) throws Exception {
    long start = System.currentTimeMillis();
    Map<String, ucar.unidata.geoloc.Station> staHash =
        new HashMap<String, ucar.unidata.geoloc.Station>();

    String location = "R:/testdata/sounding/netcdf/Upperair_20070401_0000.nc";
    NetcdfDataset ncfile = NetcdfDataset.openDataset(location);
    ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);

    // look through record varibles, for those that have "manLevel" dimension
    // make a StructureData object for those
    StructureMembers sm = new StructureMembers("manLevel");
    Dimension manDim = ncfile.findDimension("manLevel");
    Structure record = (Structure) ncfile.findVariable("record");
    List<Variable> allList = record.getVariables();
    List<VariableSimpleIF> varList = new ArrayList<VariableSimpleIF>();
    for (Variable v : allList) {
      if ((v.getRank() == 1) && v.getDimension(0).equals(manDim)) {
        // public VariableDS(NetcdfDataset ds, Group group, Structure parentStructure, String
        // shortName, DataType dataType,
        // String dims, String units, String desc) {
        varList.add(
            new VariableDS(
                ncfile,
                null,
                null,
                v.getShortName(),
                v.getDataType(),
                "",
                v.getUnitsString(),
                v.getDescription()));
        // (String name, String desc, String units, DataType dtype, int []shape)
        sm.addMember(
            v.getShortName(),
            v.getDescription(),
            v.getUnitsString(),
            v.getDataType(),
            new int[0]); // scalar
      }
    }

    ArrayStructureMA manAS = new ArrayStructureMA(sm, new int[] {manDim.getLength()});

    // need the date units
    Variable time = ncfile.findVariable("synTime");
    String timeUnits = ncfile.findAttValueIgnoreCase(time, "units", null);
    timeUnits = StringUtil.remove(timeUnits, '('); // crappy fsl'ism
    timeUnits = StringUtil.remove(timeUnits, ')');
    DateUnit timeUnit = new DateUnit(timeUnits);

    // extract stations
    int nrecs = 0;
    StructureDataIterator iter = record.getStructureIterator();
    while (iter.hasNext()) {
      StructureData sdata = iter.next();
      String name = sdata.getScalarString("staName");
      ucar.unidata.geoloc.Station s = staHash.get(name);
      if (s == null) {
        float lat = sdata.convertScalarFloat("staLat");
        float lon = sdata.convertScalarFloat("staLon");
        float elev = sdata.convertScalarFloat("staElev");
        s = new StationImpl(name, "", lat, lon, elev);
        staHash.put(name, s);
      }
      nrecs++;
    }
    List<ucar.unidata.geoloc.Station> stnList =
        Arrays.asList(staHash.values().toArray(new ucar.unidata.geoloc.Station[staHash.size()]));
    Collections.sort(stnList);

    // create the writer
    WriterProfileObsDataset writer =
        new WriterProfileObsDataset(location + ".out", "rewrite " + location);
    writer.writeHeader(stnList, varList, nrecs, "prMan");

    // extract records
    iter = record.getStructureIterator();
    while (iter.hasNext()) {
      StructureData sdata = iter.next();
      String name = sdata.getScalarString("staName");
      double timeValue = sdata.convertScalarDouble("synTime");
      Date date = timeUnit.makeDate(timeValue);

      // transfer to the ArrayStructure
      List<String> names = sm.getMemberNames();
      for (String mname : names) {
        manAS.setMemberArray(mname, sdata.getArray(mname));
      }

      // each level is weritten as a seperate structure
      int numMand = sdata.getScalarInt("numMand");
      if (numMand >= manDim.getLength()) continue;

      for (int i = 0; i < numMand; i++) {
        StructureData useData = manAS.getStructureData(i);
        writer.writeRecord(name, date, useData);
      }
    }

    writer.finish();

    long took = System.currentTimeMillis() - start;
    System.out.println("That took = " + took);
  }