Java Code Examples for ucar.nc2.time.CalendarDate#of()

The following examples show how to use ucar.nc2.time.CalendarDate#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Grib2Pds.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected CalendarDate calcTime(int startIndex) {

    int year = GribNumbers.int2(getOctet(startIndex++), getOctet(startIndex++));
    int month = getOctet(startIndex++);
    int day = getOctet(startIndex++);
    int hour = getOctet(startIndex++);
    int minute = getOctet(startIndex++);
    int second = getOctet(startIndex++);

    if ((year == 0) && (month == 0) && (day == 0) && (hour == 0) && (minute == 0) && (second == 0))
      return CalendarDate.UNKNOWN;

    // href.t00z.prob.f36.grib2
    if (hour > 23) {
      day += (hour / 24);
      hour = hour % 24;
    }

    return CalendarDate.of(null, year, month, day, hour, minute, second);
  }
 
Example 2
Source File: CoordinateTime2D.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Object extract(Grib1Record gr) {
  Long run = (Long) runBuilder.extract(gr);
  CoordinateBuilderImpl<Grib1Record> timeBuilder = timeBuilders.get(run);
  if (timeBuilder == null) {
    timeBuilder = isTimeInterval ? new CoordinateTimeIntv.Builder1(cust, code, timeUnit, CalendarDate.of(run))
        : new CoordinateTime.Builder1(cust, code, timeUnit, CalendarDate.of(run));
    timeBuilders.put(run, timeBuilder);
  }
  Object time = timeBuilder.extract(gr);
  if (time instanceof Integer)
    return new Time2D(run, (Integer) time, null);
  else
    return new Time2D(run, null, (TimeCoordIntvValue) time);
}
 
Example 3
Source File: TestRadarUF.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Collection metadata() {
  Object[][] data = new Object[][] {
      {"010820_2101-2107.uf", "EDOP/P1", "FLORIDAT", -85.02, 18.358, 19686.,
          CalendarDate.of(null, 2001, 8, 20, 21, 1, 20), CalendarDate.of(null, 2001, 8, 20, 21, 7, 32)},
      {"CHL20080702_225125_B.uf", "CSU-CHIL", "default", -104.637, 40.446, 1432.,
          CalendarDate.of(null, 2008, 7, 2, 22, 52, 0), CalendarDate.of(null, 2008, 7, 2, 22, 53, 42)},
      {"KTLX__sur_20080624.214247.uf", "NEXRAD", "NEXRAD", -97.277, 35.333, 384.,
          CalendarDate.of(null, 2008, 6, 24, 21, 42, 47), CalendarDate.of(null, 2008, 6, 24, 21, 42, 47)},
      {"NPOL_vol_010822_0000.uf", "ntr2", "ntr2", -81.675, 24.577, 2., CalendarDate.of(null, 2001, 8, 22, 0, 0, 23),
          CalendarDate.of(null, 2001, 8, 22, 0, 5, 14)},};
  return Arrays.asList(data);
}
 
Example 4
Source File: TestCFRadial.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDates() throws IOException {
  try (RadialDatasetSweep ds = testData()) {
    CalendarDate trueStart = CalendarDate.of(null, 2008, 6, 4, 0, 15, 3);
    Assert.assertEquals(trueStart, ds.getCalendarDateStart());
    CalendarDate trueEnd = CalendarDate.of(null, 2008, 6, 4, 0, 22, 17);
    Assert.assertEquals(trueEnd, ds.getCalendarDateEnd());
  }
}
 
Example 5
Source File: TestRadialDatasetNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Collection params() {
  Object[][] data = new Object[][] {
      {"formats/nexrad/level3/N0R_20041119_2147", CalendarDate.of(null, 2004, 11, 19, 21, 47, 44),
          CalendarDate.of(null, 2004, 11, 19, 21, 47, 44)},
      {"formats/dorade/swp.1020511015815.SP0L.573.1.2_SUR_v1",
          CalendarDate.of(null, 2002, 5, 11, 1, 58, 15).add(573, CalendarPeriod.Field.Millisec),
          CalendarDate.of(null, 2002, 5, 11, 1, 59, 5).add(687, CalendarPeriod.Field.Millisec)}};
  return Arrays.asList(data);
}
 
Example 6
Source File: DateUnit.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static CalendarDate parseCalendarDate(String text) {
  Date result = getStandardDate(text);
  if (result == null) {
    DateFormatter formatter = new DateFormatter();
    result = formatter.getISODate(text);
  }
  return CalendarDate.of(result);
}
 
Example 7
Source File: DsgSubsetWriterTest.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void setupClass() throws URISyntaxException {
  // The WaterML marshaller usually initializes wml2:generationDate and om:resultTime to "now". This is a problem,
  // because those values will always differ from the fixed values we have in our expectedResultResource files.
  // So, to facilitate testing, we're going to fix the values that the marshaller emits.
  MarshallingUtil.fixedGenerationDate = CalendarDate.of(Calendar.gregorian, 1970, 1, 1, 0, 0, 0);
  MarshallingUtil.fixedResultTime = CalendarDate.of(Calendar.gregorian, 1970, 1, 1, 0, 0, 0);

  ncssDiskCache = new NcssDiskCache(DiskCache2.getDefault().getRootDirectory());

  subsetParamsAll = new SubsetParams();
  subsetParamsAll.setVariables(Arrays.asList("pr", "tas"));

  subsetParamsPoint = new SubsetParams();
  subsetParamsPoint.setVariables(Arrays.asList("pr"));
  subsetParamsPoint.setTime(CalendarDate.parseISOformat(null, "1970-01-01 02:00:00Z"));
  // Full extension is (40.0, -100.0) to (68.0, -58.0).
  LatLonRect bbox = new LatLonRect(LatLonPoint.create(40.0, -100.0), LatLonPoint.create(53.0, -58.0));
  subsetParamsPoint.setLatLonBoundingBox(bbox);

  subsetParamsStation1 = new SubsetParams();
  subsetParamsStation1.setVariables(Arrays.asList("tas"));
  CalendarDate start = CalendarDate.parseISOformat(null, "1970-01-05T00:00:00Z");
  CalendarDate end = CalendarDate.parseISOformat(null, "1970-02-05T00:00:00Z");
  subsetParamsStation1.setTimeRange(CalendarDateRange.of(start, end));
  subsetParamsStation1.setStations(Arrays.asList("AAA", "CCC"));

  subsetParamsStation2 = new SubsetParams();
  subsetParamsStation2.setVariables(Arrays.asList("pr", "tas"));
  // The nearest will be "1970-01-21 00:00:00Z"
  subsetParamsStation2.setTime(CalendarDate.parseISOformat(null, "1970-01-21 01:00:00Z"));
}
 
Example 8
Source File: InvDatasetFcGrib.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void addFileDatasets(DatasetBuilder parent, String parentPath, GribCollectionImmutable fromGc)
    throws IOException {

  DatasetBuilder filesParent = new DatasetBuilder(parent);
  filesParent.setName("Raw Files");
  filesParent.addServiceToCatalog(downloadService);
  ThreddsMetadata tmi = filesParent.getInheritableMetadata();
  tmi.set(Dataset.ServiceName, downloadService.getName());
  parent.addDataset(filesParent);

  List<MFile> mfiles = new ArrayList<>(fromGc.getFiles());
  Collections.sort(mfiles);

  // if not increasing (i.e. we WANT newest file listed first), reverse sort
  if (!this.config.getSortFilesAscending()) {
    Collections.reverse(mfiles);
  }

  for (MFile mfile : mfiles) {
    DatasetBuilder ds = new DatasetBuilder(parent);
    ds.setName(mfile.getName());
    String lpath = parentPath + "/" + FILES + "/" + mfile.getName();
    ds.put(Dataset.UrlPath, lpath);
    ds.put(Dataset.Id, lpath);
    ds.put(Dataset.DataSize, mfile.getLength());
    if (mfile.getLastModified() > 0) {
      CalendarDate cdate = CalendarDate.of(mfile.getLastModified());
      ds.put(Dataset.Dates, new DateType(cdate).setType("modified"));
    }
    filesParent.addDataset(ds);
  }
}
 
Example 9
Source File: CoordinateTime2D.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Object extract(Grib2Record gr) {
  Long run = (Long) runBuilder.extract(gr);
  CoordinateBuilderImpl<Grib2Record> timeBuilder = timeBuilders.get(run);
  if (timeBuilder == null) {
    timeBuilder = isTimeInterval ? new CoordinateTimeIntv.Builder2(cust, code, timeUnit, CalendarDate.of(run))
        : new CoordinateTime.Builder2(code, timeUnit, CalendarDate.of(run));
    timeBuilders.put(run, timeBuilder);
  }
  Object time = timeBuilder.extract(gr);
  if (time instanceof Integer)
    return new Time2D(run, (Integer) time, null);
  else
    return new Time2D(run, null, (TimeCoordIntvValue) time);
}
 
Example 10
Source File: CFPointWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addNetcdf3UnknownAtts(boolean noTimeCoverage) {
  // dummy values, update in finish()
  if (!noTimeCoverage) {
    CalendarDate now = CalendarDate.of(new Date());
    writer.addGroupAttribute(null, new Attribute(ACDD.TIME_START, CalendarDateFormatter.toDateTimeStringISO(now)));
    writer.addGroupAttribute(null, new Attribute(ACDD.TIME_END, CalendarDateFormatter.toDateTimeStringISO(now)));
  }
  writer.addGroupAttribute(null, new Attribute(ACDD.LAT_MIN, 0.0));
  writer.addGroupAttribute(null, new Attribute(ACDD.LAT_MAX, 0.0));
  writer.addGroupAttribute(null, new Attribute(ACDD.LON_MIN, 0.0));
  writer.addGroupAttribute(null, new Attribute(ACDD.LON_MAX, 0.0));
}
 
Example 11
Source File: PartitionCollectionImmutable.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String toString() {
  return "Partition{ " + name + '\'' +
  // ", directory='" + directory + '\'' +
      ", filename='" + filename + '\'' + ", partitionDate='" + partitionDate + '\'' + ", lastModified='"
      + CalendarDate.of(lastModified) + '\'' + ", fileSize='" + fileSize + '\'' + '}';
}
 
Example 12
Source File: DateExtractorFromName.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public CalendarDate getCalendarDateFromPath(String path) {
  Date d;
  if (useName) {
    Path p = Paths.get(path);
    d = DateFromString.getDateUsingDemarkatedCount(p.getFileName().toString(), dateFormatMark, '#');
  } else
    d = DateFromString.getDateUsingDemarkatedMatch(path, dateFormatMark, '#');

  return (d == null) ? null : CalendarDate.of(d);
}
 
Example 13
Source File: CalendarDateFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public CalendarDateFactory(CoordinateRuntime master) {
  map = new HashMap<>(master.getSize() * 2);
  for (Object valo : master.getValues()) {
    CalendarDate cd = CalendarDate.of((Long) valo);
    map.put(cd.getMillis(), cd);
  }
}
 
Example 14
Source File: AbstractRadialAdapter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public CalendarDate getCalendarDateEnd() {
  return CalendarDate.of(getEndDate());
}
 
Example 15
Source File: DateType.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Constructor.
 *
 * @param text string representation
 * @param format using java.text.SimpleDateFormat, or null
 * @param type type of date, or null
 * @throws java.text.ParseException if error parsing text
 */
public DateType(String text, String format, String type) throws java.text.ParseException {

  text = (text == null) ? "" : text.trim();
  this.text = text;
  this.format = format;
  this.type = type;

  // see if its blank
  if (text.isEmpty()) {
    isBlank = true;
    date = null;
    return;
  }

  // see if its the string "present"
  isPresent = text.equalsIgnoreCase("present");
  if (isPresent) {
    this.date = null;
    return;
  }

  // see if its got a format
  if (format != null) {
    SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(format);
    Date d = dateFormat.parse(text);
    date = CalendarDate.of(d);
    return;
  }

  // see if its a udunits string
  if (text.indexOf("since") > 0) {
    date = CalendarDate.parseUdunits(null, text);
    if (date == null)
      throw new java.text.ParseException("invalid udunit date unit =" + text, 0);
    return;
  }

  date = CalendarDate.parseISOformat(null, text);
  if (date == null)
    throw new java.text.ParseException("invalid ISO date unit =" + text, 0);
}
 
Example 16
Source File: CdmrfReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
CalendarDateRange decodeDateRange(CdmrFeatureProto.CalendarDateRange proto) {
  ucar.nc2.time.Calendar cal = convertCalendar(proto.getCalendar());
  CalendarDate start = CalendarDate.of(cal, proto.getStart());
  CalendarDate end = CalendarDate.of(cal, proto.getEnd());
  return CalendarDateRange.of(start, end);
}
 
Example 17
Source File: Grib2PartitionBuilderFromIndex.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private PartitionCollectionMutable.Partition makePartition(GribCollectionProto.Partition proto) {
  long partitionDateMillisecs = proto.getPartitionDate();
  CalendarDate partitionDate = partitionDateMillisecs > 0 ? CalendarDate.of(partitionDateMillisecs) : null;
  return pc.addPartition(proto.getName(), proto.getFilename(), proto.getLastModified(), proto.getLength(), null,
      partitionDate);
}
 
Example 18
Source File: DateExtractorFromName.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public CalendarDate getCalendarDate(MFile mfile) {
  Date d = getDate(mfile);
  return (d == null) ? null : CalendarDate.of(d);
}
 
Example 19
Source File: Cinrad2Record.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void readCC20Header(RandomAccessFile din) throws IOException {

    message_offset = 0;
    din.seek(message_offset);
    // site info 170
    din.skipBytes(62);

    // Message Header
    String stationId = din.readString(40);
    String stationNbr = din.readString(10);

    din.skipBytes(20);

    String clon = din.readString(16);
    String clat = din.readString(16);
    // latlon
    int lon = din.readInt();
    int lat = din.readInt();
    int hhh = din.readInt();

    din.skipBytes(40);

    // ObservationInfo
    short scanMode = convertunsignedByte2Short(din.readByte());
    if (scanMode == 10) {
      sweepN = 1;
    } else if (scanMode >= 100) {
      sweepN = scanMode - 100;
    } else {
      throw new IOException("Error reading CINRAD CC data: Unsupported product: RHI/FFT");
    }

    short syear = (short) din.readUnsignedShort();
    short smm = convertunsignedByte2Short(din.readByte());
    short sdd = convertunsignedByte2Short(din.readByte());
    short shh = convertunsignedByte2Short(din.readByte());
    short smi = convertunsignedByte2Short(din.readByte());
    short sss = convertunsignedByte2Short(din.readByte());

    dateTime0 = CalendarDate.of(null, syear, smm, sdd, shh, smi, sss);

    din.skipBytes(14); // 14+ (35 - 21)

    // remain2[660]
    elev = new int[sweepN];
    recordNum = new int[sweepN];
    for (int i = 0; i < sweepN; i++) {
      din.skipBytes(14);
      int zbinWidth = din.readUnsignedShort();
      int vbinWidth = din.readUnsignedShort();
      int sbinWidth = din.readUnsignedShort();
      int zbinNum = din.readUnsignedShort();
      int vbinNum = din.readUnsignedShort();
      int sbinNum = din.readUnsignedShort();
      recordNum[i] = din.readUnsignedShort();
      // if(i > 0)
      // recordNum[i] = recordNum[i] + recordNum[i-1];
      elev[i] = din.readShort();
      cDataForm = din.readByte();
      if (cDataForm != 22 && cDataForm != 23 && cDataForm != 24)
        throw new IOException("Unsupported CC data format");
      int dataP = din.readInt();
      // din.skipBytes(2);
      // System.out.println("zbin num: " + zbinNum + " vbin num: " + vbinNum + " sbin num: " + sbinNum + " dataForm " +
      // cDataForm);
    }

    for (int i = sweepN; i < 32; i++) {
      din.skipBytes(35);
    }

    din.skipBytes(6);

    syear = (short) din.readUnsignedShort();
    smm = convertunsignedByte2Short(din.readByte());
    sdd = convertunsignedByte2Short(din.readByte());
    shh = convertunsignedByte2Short(din.readByte());
    smi = convertunsignedByte2Short(din.readByte());
    sss = convertunsignedByte2Short(din.readByte());

    dateTimeE = CalendarDate.of(null, syear, smm, sdd, shh, smi, sss);

  }
 
Example 20
Source File: BufrIdentificationSection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * return record header time as a CalendarDate
 *
 * @return referenceTime
 */
public final CalendarDate getReferenceTime() {
  int sec = (second < 0 || second > 59) ? 0 : second;
  return CalendarDate.of(null, year, month, day, hour, minute, sec);
}