Package ucar.nc2.units

Examples of ucar.nc2.units.DateUnit


        CoordinateAxis time = gsys.getTimeAxis();
        if (time == null)
          continue;
       
        try {
          DateUnit du = new DateUnit( time.getUnitsString());
          Date minDate = du.makeDate(time.getMinValue());
          Date maxDate = du.makeDate(time.getMaxValue());
          dateRange = new DateRange( minDate, maxDate);
        } catch (Exception e) {
          logger.warn("Illegal Date Unit "+time.getUnitsString());
          continue;
        }
View Full Code Here


        startDate = new Date();
        endDate   = new Date();

        try {
            timeUnit = new DateUnit("hours since 1991-01-01T00:00");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
View Full Code Here

  TimeCoord(Date runDate, CoordinateAxis1DTime axis) {
    this.runDate = runDate;
    this.axisName = axis.getFullName();

    DateUnit unit = null;
    try {
      unit = new DateUnit(axis.getUnitsString());
    } catch (Exception e) {
      throw new IllegalArgumentException("Not a unit of time " + axis.getUnitsString());
    }

    int n = (int) axis.getSize();
    if (axis.isInterval()) {
      this.isInterval = true;
      this.bound1 = axis.getBound1();
      this.bound2 = axis.getBound2();
    } else {
      offset = new double[n];
      for (int i = 0; i < axis.getSize(); i++) {
        Date d = unit.makeDate(axis.getCoordValue(i));
        offset[i] = FmrcInv.getOffsetInHours(runDate, d);
      }
    }
  }
View Full Code Here

    Date d1 = sod.getStartDate();
    Date d2 = sod.getEndDate();
    if ((d1 != null) && (d2 != null))
      assert d1.before(d2) || d1.equals( d2);

    DateUnit du = sod.getTimeUnits();
    assert null != du;

    double startVal = du.makeValue( d1);
    double endVal = du.makeValue( d2);
    assert startVal <= endVal;

    Class dataClass = sod.getDataClass();
    assert dataClass == StationObsDatatype.class;

    List dataVars =  sod.getDataVariables();
    assert dataVars != null;
    for (int i = 0; i < dataVars.size(); i++) {
      VariableSimpleIF v = (VariableSimpleIF) dataVars.get(i);
      assert null != sod.getDataVariable( v.getShortName());
    }

    List stations = sod.getStations();
    assert null != stations;
    assert 0 < stations.size();
    System.out.println(" stations = "+stations.size());
    int n = stations.size();
    testStation( sod, (ucar.unidata.geoloc.Station) stations.get(0));
    if (n > 3) {
      testStation( sod, (ucar.unidata.geoloc.Station) stations.get(n-1));
      testStation( sod, (ucar.unidata.geoloc.Station) stations.get((n-1)/2));
    }

    // make a new bb
    LatLonRect bb = sod.getBoundingBox();
    assert null != bb;
    double h = bb.getUpperRightPoint().getLatitude() - bb.getLowerLeftPoint().getLatitude();
    LatLonRect bb2 = new LatLonRect(bb.getLowerLeftPoint(), bb.getWidth()/2, h/2);

    List<ucar.unidata.geoloc.Station> stationsBB= sod.getStations( bb2);
    assert null != stationsBB;
    assert stationsBB.size() <= stations.size();
    System.out.println(" bb2 stations = "+stationsBB.size());

    List data = sod.getData( bb2);
    testData( sod.getTimeUnits(), data.iterator());

    // make a new data range
    double diff = endVal - startVal;
    Date startRange = du.makeDate( startVal + .25 * diff);
    Date endRange = du.makeDate( startVal + .75 * diff);
    data = sod.getData( bb2, startRange, endRange);
    testData( sod.getTimeUnits(), data.iterator());

    data = sod.getData( stationsBB, startRange, endRange);
    testData( sod.getTimeUnits(), data.iterator());
View Full Code Here

    Date d1 = pod.getStartDate();
    Date d2 = pod.getEndDate();
    if ((d1 != null) && (d2 != null))
      assert d1.before(d2) || d1.equals( d2);

    DateUnit du = pod.getTimeUnits();
    assert null != du;

    double startVal = du.makeValue( d1);
    double endVal = du.makeValue( d2);
    assert startVal <= endVal;

    Class dataClass = pod.getDataClass();
    assert dataClass == PointObsDatatype.class;

    List dataVars =  pod.getDataVariables();
    assert dataVars != null;
    for (int i = 0; i < dataVars.size(); i++) {
      VariableSimpleIF v = (VariableSimpleIF) dataVars.get(i);
      assert null != pod.getDataVariable( v.getShortName());
    }

    // make a new bb
    LatLonRect bb = pod.getBoundingBox();
    assert null != bb;
    double h = bb.getUpperRightPoint().getLatitude() - bb.getLowerLeftPoint().getLatitude();
    LatLonRect bb2 = new LatLonRect(bb.getLowerLeftPoint(), bb.getWidth()/2, h/2);

    List data = pod.getData( bb2);
    testData( pod.getTimeUnits(), data.iterator());

    // make a new data range
    double diff = endVal - startVal;
    Date startRange = du.makeDate( startVal + .25 * diff);
    Date endRange = du.makeDate( startVal + .75 * diff);
    data = pod.getData( bb2, startRange, endRange);
    testData( pod.getTimeUnits(), data.iterator());

    data = pod.getData( bb2, startRange, endRange);
    testData( pod.getTimeUnits(), data.iterator());
View Full Code Here

   *  To get a Date, from a time value, call DateUnit.getStandardDate(double value).
   *  To get units as a String, call DateUnit.getUnitsString().
   */
  public ucar.nc2.units.DateUnit getTimeUnits() throws Exception {
    if (null == dateUnit) {
      dateUnit = new DateUnit( timeAxis.getUnitsString());
    }
    return dateUnit;
  }
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.append("Error on string = " + timeUnitString + " == " + e.getMessage()+"\n");
      try {
        timeUnit = new DateUnit("seconds since 1970-01-01");
      } catch (Exception e1) {
        // cant happen
      }
    }
  }
View Full Code Here

    private DateUnit dateUnit;
    private StructureMembers sm;

    ProtobufPointFeatureMaker(PointStreamProto.PointFeatureCollection pfc) throws IOException {
      try {
        dateUnit = new DateUnit(pfc.getTimeUnit());
      } catch (Exception e) {
        e.printStackTrace();
        dateUnit = DateUnit.getUnixDateUnit();
      }
View Full Code Here

     * @return The converted values. May contains {@code null} elements.
     */
    @Override
    public Date[] numberToDate(final String symbol, final Number... values) {
        final Date[] dates = new Date[values.length];
        final DateUnit unit;
        try {
            unit = new DateUnit(symbol);
        } catch (Exception e) { // Declared by the DateUnit constructor.
            listeners.warning(null, e);
            return dates;
        }
        for (int i=0; i<values.length; i++) {
            final Number value = values[i];
            if (value != null) {
                dates[i] = unit.makeDate(value.doubleValue());
            }
        }
        return dates;
    }
View Full Code Here

     * @return The converted values. May contains {@code null} elements.
     */
    @Override
    public Date[] numberToDate(final String symbol, final Number... values) {
        final Date[] dates = new Date[values.length];
        final DateUnit unit;
        try {
            unit = new DateUnit(symbol);
        } catch (Exception e) { // Declared by the DateUnit constructor.
            listeners.warning(null, e);
            return dates;
        }
        for (int i=0; i<values.length; i++) {
            final Number value = values[i];
            if (value != null) {
                dates[i] = unit.makeDate(value.doubleValue());
            }
        }
        return dates;
    }
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.