public Calendar getCalendar() { return dateUnit.getCalendar(); }
public TimeHelper setReferenceDate(CalendarDate refDate) { CalendarDateUnit cdUnit = CalendarDateUnit.of(dateUnit.getCalendar(), dateUnit.getCalendarField(), refDate); return new TimeHelper(cdUnit); }
public void writeHeader(PointFeature pf) throws IOException { List<VariableSimpleIF> coords = new ArrayList<>(); coords.add(VariableSimpleImpl.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); coords.add(VariableSimpleImpl.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE)); coords.add(VariableSimpleImpl.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE)); Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName); if (altUnits != null) { coords.add( VariableSimpleImpl.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE) .add(new Attribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)))); coordNames.format(" %s", altName); } super.writeHeader(coords, null, pf.getDataAll(), coordNames.toString()); }
private void writeHeader(TrajectoryFeature feature, PointFeature obs) throws IOException { // obs data List<VariableSimpleIF> coords = new ArrayList<>(); coords.add(VariableSimpleImpl.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); coords.add(VariableSimpleImpl.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE)); coords.add(VariableSimpleImpl.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE)); Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName); if (altUnits != null) { coords.add( VariableSimpleImpl.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE) .add(new Attribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)))); coordNames.format(" %s", altName); } super.writeHeader(coords, feature.getFeatureData(), obs.getFeatureData(), coordNames.toString()); }
private Element writeTimeUnit(CalendarDateUnit dateUnit) { Element elem = new Element("TimeUnit"); elem.addContent(dateUnit.getUdUnit()); elem.setAttribute("calendar", dateUnit.getCalendar().toString()); return elem; }
.add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString())));
private void testCalendar(Calendar cal, String s) { CalendarDateUnit cdu; try { cdu = CalendarDateUnit.withCalendar(cal, s); } catch (Exception e) { e.printStackTrace(); return; } System.out.printf("%s == %s unit (cal=%s)%n", s, cdu, cdu.getCalendar()); CalendarDate base = null; for (int i = 0; i < 13; i++) { CalendarDate cd = cdu.makeCalendarDate(i); if (base == null) base = cd; double diff = cd.getDifferenceInMsecs(base) * 1.0e-6; System.out.printf(" %d %s == %s diff = %f%n", i, cdu, CalendarDateFormatter.toDateTimeStringISO(cd), diff); } System.out.printf("%n"); }
@Test public void testZeroYear() { double[] times = new double[] {366.0, 1096.485, 1826.97, 2557.455, 3287.94, 4018.425, 4748.91, 5479.395, 6209.88, 6940.365, 7670.85, 8401.335}; CalendarDateUnit unit = CalendarDateUnit.withCalendar(null, "hour since 0000-01-01 00:00:00"); for (double time : times) { CalendarDate cd1 = unit.makeCalendarDate(time); System.out.printf("%s with Calendar %s%n", cd1, null); } // year0 fails in gregorian. kluge in CalendarDateFormatter CalendarDateUnit unit2 = CalendarDateUnit.withCalendar(Calendar.gregorian, "hour since 0000-01-01 00:00:00"); assert unit2.getCalendar() == Calendar.proleptic_gregorian; }
protected void makeFeatureVariables(StructureData featureData, boolean isExtended) throws IOException { // LOOK why not unlimited here ? Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // Dimension profileDim = isExtendedModel ? writer.addUnlimitedDimension(profileDimName) : writer.addDimension(null, profileDimName, nprofiles); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID))); // profileId:cf_role = "profile_id"; profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); // rowSize:sample_dimension = "obs" profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); for (StructureMembers.Member m : featureData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, featureVarMap); } }
@Override protected void makeMiddleVariables(StructureData profileData, boolean isExtended) throws IOException { Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID)) // profileId:cf_role = "profile_id"; .add(new Attribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)))); profileVars.add(VariableSimpleImpl.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); profileVars.add(VariableSimpleImpl.makeScalar(trajectoryIndexName, "trajectory index for this profile", null, DataType.INT) .add(new Attribute(CF.INSTANCE_DIMENSION, trajDimName))); profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); for (StructureMembers.Member m : profileData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, profileVarMap); } }
@Override protected void makeMiddleVariables(StructureData profileData, boolean isExtended) throws IOException { Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID)) // profileId:cf_role = "profile_id"; .add(new Attribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)))); profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); // rowSize:sample_dimension = "obs" profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); profileVars.add(VariableSimpleImpl.makeScalar(stationIndexName, "station index for this profile", null, DataType.INT) .add(new Attribute(CF.INSTANCE_DIMENSION, stationDimName))); for (StructureMembers.Member m : profileData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, profileVarMap); } }
Assert.assertNotNull("cdu", cdu); logger.debug("CalendarDateUnit= {}", cdu); logger.debug("Calendar= {}", cdu.getCalendar());