Examples of DateFormatter


Examples of ucar.nc2.units.DateFormatter

  public NetcdfDataset getRunTimeDataset(Date wantRuntime) throws IOException {
    if (wantRuntime == null) return null;
    if (!runtimes.contains(wantRuntime)) return null;

    DateFormatter df = new DateFormatter();
    String runTimeString = df.toDateTimeStringISO(wantRuntime);

    NetcdfDataset ncd = createDataset(new RuntimeInvGetter(wantRuntime), RUN, runTimeString);
    ncd.addAttribute(null, new Attribute(_Coordinate.ModelRunDate, runTimeString));
    ncd.finish();
    return ncd;
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

  public NetcdfDataset getForecastTimeDataset(Date forecastTimethrows IOException {
    if (forecastTime == null) return null;
    if (!forecasts.contains(forecastTime)) return null;

    DateFormatter df = new DateFormatter();
    String name = df.toDateTimeStringISO(forecastTime);
    return createDataset(new ForecastInvGetter(forecastTime), FORECAST, name);
  }
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

    String newHistory = "Synthetic dataset from TDS fmrc (" + type + ") aggregation, original data from " + ncd_2dtime.getLocation();
    String history = (oldHistory != null) ? oldHistory + "; " + newHistory : newHistory;
    target.addAttribute(new Attribute("history", history));

    // need this attribute for fmrInventory
    DateFormatter df = new DateFormatter();
    target.addAttribute(new Attribute(_Coordinate.ModelBaseDate, df.toDateTimeStringISO(baseDate)));

    // dimensions
    for (Dimension d : src.getDimensions()) {
      target.addDimension(new Dimension(d.getName(), d));
    }
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

    return sb.toString();
  }

  private void addTime3Coordinates(NetcdfDataset newds, Gridset gridset, List<Inventory> invList, String type) {
    DateFormatter formatter = new DateFormatter();
    boolean useRun = type.equals(FORECAST);

    // add the time dimensions
    int n = invList.size();
    String dimName = gridset.timeDimName;

    Group g = newds.getRootGroup();
    g.remove(g.findDimension(dimName));
    g.addDimension(new Dimension(dimName, n));

    // make the time coordinate variable data
    ArrayDouble.D1 offsetData = new ArrayDouble.D1(n);
    for (int i = 0; i < n; i++) {
      Inventory inv = invList.get(i);
      double offsetHour = getOffsetHour(baseDate, useRun ? inv.runTime : inv.forecastTime);
      offsetData.set(i, offsetHour);
    }

    // add the time coordinate variable
    String typeName = useRun ? "run" : "forecast";
    String desc = typeName + " time coordinate";
    VariableDS timeCoordinate = new VariableDS(newds, g, null, dimName, DataType.DOUBLE, dimName,
            "hours since " + formatter.toDateTimeStringISO(baseDate), desc);
    timeCoordinate.setCachedData(offsetData, true);
    timeCoordinate.addAttribute(new Attribute("long_name", desc));
    timeCoordinate.addAttribute(new Attribute("standard_name", useRun ? "forecast_reference_time" : "time"));
    timeCoordinate.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
    newds.addVariable(g, timeCoordinate);

    // add the runtime coordinate
    ArrayObject.D1 runData = new ArrayObject.D1(String.class, n);
    for (int i = 0; i < n; i++) {
      Inventory inv = invList.get(i);
      runData.set(i, formatter.toDateTimeStringISO(inv.runTime));
    }
    desc = "model run dates for coordinate = " + dimName;

    VariableDS runtimeCoordinate = new VariableDS(newds, newds.getRootGroup(), null, dimName + "_run",
            DataType.STRING, dimName, null, desc);
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

      Collections.sort(bestList);
    }

    void dump(Formatter f) throws IOException {

      DateFormatter df = new DateFormatter();
      f.format("Gridset timeDimName= %s%n grids= %n", timeDimName);
      for (GridDatatype grid : gridList) {
        f.format("  %s%n", grid.getFullName());
      }

      f.format("%nRun Dates= %s%n", runtimes.size());
      for (Date date : runtimes) {
        f.format(" %s (", df.toDateTimeString(date));
        List<Inventory> list = runMap.get(date);
        if (list == null)
          f.format(" none");
        else {
          for (Inventory inv : list) {
            f.format(" %s", inv.hourOffset);
          }
        }
        f.format(") %n");
      }

      f.format("%nForecast Dates= %d %n",forecasts.size());
      for (Date date : forecasts) {
        f.format(" %s(", df.toDateTimeString(date));
        List<Inventory> list = timeMap.get(date);
        if (list == null)
          f.format(" none");
        else {
          for (Inventory inv : list) {
            f.format(" %d/%f", inv.run, inv.hourOffset);
          }
        }
        f.format(")%n");
      }

      f.format("\nForecast Hours= %d%n", offsets.size());
      for (Double hour : offsets) {
        List<Inventory> offsetList = offsetMap.get(hour);
        f.format(" %s: (", hour);
        if (offsetList == null)
          f.format(" none");
        else {
          for (int j = 0; j < offsetList.size(); j++) {
            Inventory inv = offsetList.get(j);
            if (j > 0) System.out.print(", ");
            f.format("%d/%s", inv.run, df.toDateTimeStringISO(inv.runTime));
          }
        }
        f.format(")%n");
      }

      f.format("\nBest Forecast = %d%n", bestList.size());
      for (Inventory inv : bestList) {
        f.format(" %s (run=%s) offset=%f%n", df.toDateTimeStringISO(inv.forecastTime), df.toDateTimeStringISO(inv.runTime), inv.hourOffset);
      }

    }
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

        // Calculating base time so subtract seconds in time variable first value.
        calendar.add( Calendar.SECOND, - (int) tmpTimeArray.getFloat( tmpTimeArray.getIndex() ));
        baseTimeDate = calendar.getTime();
      }

      DateFormatter formatter = new DateFormatter();             
      String timeUnitsString = "seconds since " + formatter.toDateTimeStringISO( baseTimeDate );
      ncfile.findVariable( timeVarName ).addAttribute( new Attribute( "units", timeUnitsString ) );

      // Make sure alt units are "meters" convertible.
      String elevVarUnitsString = ncfile.findVariable( elevVarName ).findAttribute( "units").getStringValue();
      if ( ! SimpleUnit.isCompatible( elevVarUnitsString, "meters"))
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

    }

    Collections.sort(errs);
    Date currentDate = null;
    String currentType = null;
    DateFormatter formatter = new  DateFormatter();

    for (ErrMessage err : errs) {
      if (err.runDate != currentDate) {
        if (currentDate != null) out.println();
        out.println(" Run " + formatter.toDateTimeString(err.runDate));
        currentDate = err.runDate;
        currentType = null;
      }

      if (!err.type.equals(currentType)) {
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

    }
  }

  public static void main(String args[]) throws IOException, ParseException {
    StationDatasetCollection sdc = new StationDatasetCollection();
    DateFormatter format = new DateFormatter();

    sdc.add("C:/data/metars/Surface_METAR_20070326_0000.nc");
    sdc.add("C:/data/metars/Surface_METAR_20070329_0000.nc");
    sdc.add("C:/data/metars/Surface_METAR_20070330_0000.nc");
    sdc.add("C:/data/metars/Surface_METAR_20070331_0000.nc");

    ucar.unidata.geoloc.Station s = sdc.getStation("ACK");
    DataIterator iter = sdc.getDataIterator(s);
    while (iter.hasNext()) {
      Object o = iter.nextData();
      assert (o instanceof StationObsDatatype);
      StationObsDatatype sod = (StationObsDatatype) o;
      ucar.unidata.geoloc.Station ss = sod.getStation();
      assert (ss.getName().equals(s.getName()));

      System.out.println(ss.getName() + " " + format.toDateTimeStringISO( sod.getObservationTimeAsDate()));

      StructureData sdata = sod.getData();
      assert sdata != null;
    }

    System.out.println("------------------\n");
    Date start = format.isoDateTimeFormat("2007-03-27T09:18:56Z");
    Date end = format.isoDateTimeFormat("2007-03-30T10:52:48Z");

    iter = sdc.getDataIterator(s, start, end);
    while (iter.hasNext()) {
      Object o = iter.nextData();
      assert (o instanceof StationObsDatatype);
      StationObsDatatype sod = (StationObsDatatype) o;
      ucar.unidata.geoloc.Station ss = sod.getStation();
      assert (ss.getName().equals(s.getName()));

      System.out.println(ss.getName() + " " + format.toDateTimeStringISO( sod.getObservationTimeAsDate()));

      StructureData sdata = sod.getData();
      assert sdata != null;
    }
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

    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) {
      io.printStackTrace();
      assert false;
View Full Code Here

Examples of ucar.nc2.units.DateFormatter

      rootElem.addContent(writeBoundingBox(bb));

    // add date range
    DateRange dateRange = fdp.getDateRange();
    if (dateRange != null) {
      DateFormatter format = new DateFormatter();
      Element drElem = new Element("TimeSpan"); // from KML
      drElem.addContent(new Element("begin").addContent(dateRange.getStart().toDateTimeStringISO()));
      drElem.addContent(new Element("end").addContent(dateRange.getEnd().toDateTimeStringISO()));
      if (dateRange.getResolution() != null)
        drElem.addContent(new Element("resolution").addContent(dateRange.getResolution().toString()));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.