Package ucar.nc2.units

Examples of ucar.nc2.units.DateUnit


    return (timeVE != null) && (latVE != null) && (lonVE != null);
  }

  public DateUnit getTimeUnit() {
    try {
      return new DateUnit(timeVE.getUnitsString());
    } catch (Exception e) {
      throw new IllegalArgumentException("Error on time string = " + timeVE.getUnitsString() + " == " + e.getMessage());
    }
  }
View Full Code Here


        List axes = ncd.getCoordinateAxes();
        for (int i = 0; i < axes.size(); i++) {
          CoordinateAxis axis = (CoordinateAxis) axes.get(i);
          if (axis.getAxisType() == AxisType.Time) {
            String units = axis.getUnitsString();
            dateUnits =  new DateUnit(units);
            return;
          }
        }
        parseInfo.append("*** Time Units not Found\n");
    }
View Full Code Here

  protected void setTimeUnits() {
    // need the time units
    String timeUnitString = ncfile.findAttValueIgnoreCase(timeVar, "units", "seconds since 1970-01-01");
    try {
      timeUnit = new DateUnit(timeUnitString);
    } catch (Exception e) {
      parseInfo.append("Error on units = ").append(timeUnitString).append(" == ").append(e.getMessage()).append("\n");
      try {
        timeUnit = new DateUnit("seconds since 1970-01-01");
      } catch (Exception e1) {
        // cant happen
      }
    }
  }
View Full Code Here

    List axes = ds.getCoordinateAxes();
    for (int i = 0; i < axes.size(); i++) {
      CoordinateAxis axis = (CoordinateAxis) axes.get(i);
      if (axis.getAxisType() == AxisType.Time) {
        String units = axis.getUnitsString();
        dateUnits =  new DateUnit(units);
        return;
      }
    }
    parseInfo.append("*** Time Units not Found\n");
  }
View Full Code Here

    dataVariables.remove( ds.findVariable("attributes"));
    dataVariables.remove( ds.findVariable("variable_attributes"));
    setBoundingBox();

    try {
      timeUnit = new DateUnit(timeVar.getUnitsString());
    } catch (Exception e) {
      parseInfo.append("Bad time units= "+ timeVar.getUnitsString());
      fatal = true;
    }
View Full Code Here

    assert time.getShape()[0] == nagg;
    assert time.getShape()[1] == ntimes;
    assert time.getDataType() == DataType.DOUBLE;

    String units = time.getUnitsString();
    DateUnit du = new DateUnit( units);

    DateFormatter formatter = new DateFormatter();
    try {
      Array data = time.read();
      assert data.getSize() == nagg * ntimes;
      assert data.getShape()[0] == nagg;
      assert data.getShape()[1] == ntimes;
      assert data.getElementType() == double.class;

      IndexIterator dataI = data.getIndexIterator();
      while (dataI.hasNext()) {
        double val = dataI.getDoubleNext();
        Date date = du.makeDate(val);
        if (date != null)
          System.out.println(" date= "+ formatter.toDateTimeStringISO(date));
      }

    } catch (IOException io) {
View Full Code Here

          try {
            timeUnit = flatTable.getTimeUnit();
          } catch (Exception e) {
            if (null != errlog) errlog.format("%s\n", e.getMessage());
            try {
              timeUnit = new DateUnit("seconds since 1970-01-01");
            } catch (Exception e1) {
              log.error("Illegal time units", e1); // cant happen i hope
            }
          }
        }
View Full Code Here

    // need the time units
    Variable timeVar = ncfile.findVariable(obsTimeVName);
    String timeUnitString = ncfile.findAttValueIgnoreCase(timeVar, "units", "seconds since 1970-01-01");
    try {
      timeUnit = new DateUnit(timeUnitString);
    } catch (Exception e) {
      if (null != errs)
        errs.format("Error on string = %s == %s\n", timeUnitString, e.getMessage());
      try {
        timeUnit = new DateUnit("seconds since 1970-01-01");
      } catch (Exception e1) {
        // cant happen
      }
    }
  }
View Full Code Here

    // 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));
View Full Code Here

      List axes = ds.getCoordinateAxes();
      for (int i = 0; i < axes.size(); i++) {
        CoordinateAxis axis = (CoordinateAxis) axes.get(i);
        if (axis.getAxisType() == AxisType.Time) {
          String units = axis.getUnitsString();
          dateUnits =  new DateUnit(units);
          return;
        }
      }
      parseInfo.append("*** Time Units not Found\n");
    }
View Full Code Here

TOP

Related Classes of ucar.nc2.units.DateUnit

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.