Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ucar.nc2.Group;
import ucar.nc2.NetcdfFile;
import ucar.nc2.Variable;
import ucar.nc2.constants.CF;
import ucar.nc2.constants._Coordinate;
import ucar.nc2.dataset.CoordinateAxis;
import ucar.nc2.dataset.NetcdfDataset;
Expand Down Expand Up @@ -60,8 +61,13 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
.setParentGroupBuilder(root).setDimensionsByName(dimName);
root.addVariable(joinAggCoordVar);
joinAggCoordVar.setProxyReader(this);
if (isDate)
if (isDate) {
joinAggCoordVar.addAttribute(new Attribute(_Coordinate.AxisType, "Time"));
String coordUnits = ((AggDatasetOuter) typicalDataset).coordUdunit;
if (coordUnits != null && !coordUnits.isEmpty()) {
joinAggCoordVar.addAttribute(new Attribute(CF.UNITS, coordUnits));
}
}

// if speced externally, this variable will get replaced
// LOOK was CacheVar cv = new CoordValueVar(joinAggCoordVar.getFullName(), joinAggCoordVar.dataType,
Expand Down
9 changes: 8 additions & 1 deletion cdm/core/src/main/java/ucar/nc2/ncml/AggregationNew.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package ucar.nc2.ncml;

import ucar.nc2.constants.CF;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.dataset.VariableDS;
import ucar.nc2.dataset.DatasetConstructor;
Expand Down Expand Up @@ -55,8 +56,14 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
joinAggCoord = new VariableDS(ncDataset, null, null, dimName, coordType, dimName, null, null);
ncDataset.addVariable(null, joinAggCoord);
joinAggCoord.setProxyReader(this);
if (isDate)
if (isDate) {
joinAggCoord.addAttribute(new ucar.nc2.Attribute(_Coordinate.AxisType, "Time"));
String coordUnits = ((DatasetOuterDimension) typicalDataset).coordUdunit;
if (coordUnits != null && !coordUnits.isEmpty()) {
joinAggCoord.addAttribute(new Attribute(CF.UNITS, coordUnits));
}
}


// if speced externally, this variable will get replaced
CacheVar cv =
Expand Down
9 changes: 9 additions & 0 deletions cdm/core/src/test/data/ncml/aggNewOne.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<aggregation dimName="time2" type="joinNew" recheckEvery="4 sec">
<scan dateFormatMark="CG#yyyyDDD_HHmmss"
location="nc/cg/"
suffix=".nc"
subdirs="false"/>
</aggregation>
</netcdf>
10 changes: 10 additions & 0 deletions cdm/core/src/test/data/ncml/aggNewOneNumericTime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<aggregation dimName="time2" type="joinNew" recheckEvery="4 sec">
<scan dateFormatMark="CG#yyyyDDD_HHmmss"
location="nc/cg/"
suffix=".nc"
subdirs="false"
numericTimeSettings="int seconds since 2006-06-07T11:00:00Z"/>
</aggregation>
</netcdf>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ucar.nc2.Variable;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.dataset.NetcdfDatasets;
import ucar.nc2.internal.ncml.NcmlReader;
import ucar.nc2.time.Calendar;
import ucar.nc2.time.CalendarDate;
import ucar.nc2.time.CalendarDateFormatter;
Expand All @@ -30,7 +31,7 @@ public void testNumericTime() throws IOException, InvalidRangeException, Interru

try (NetcdfDataset ncStr = NetcdfDataset.openDataset(aggStringTime);
NetcdfDataset ncNum = NetcdfDataset.openDataset(aggNumericTime)) {
compareTimes(ncStr, ncNum);
compareTimes(ncStr, ncNum, "time");
}
}

Expand All @@ -41,14 +42,34 @@ public void testNumericTimeWithBuilders() throws IOException, InvalidRangeExcept

try (NetcdfDataset ncStr = NetcdfDatasets.openDataset(aggStringTime);
NetcdfDataset ncNum = NetcdfDatasets.openDataset(aggNumericTime)) {
compareTimes(ncStr, ncNum);
compareTimes(ncStr, ncNum, "time");
}
}

void compareTimes(NetcdfDataset ncStr, NetcdfDataset ncNum) throws IOException {
Variable isoTimeVar = ncStr.findVariable("time");
@Test
public void testNumericTimeNcmlReader() throws IOException, InvalidRangeException, InterruptedException {
String aggStringTime = "file:./" + TestNcmlRead.topDir + "aggNewOne.xml";
String aggNumericTime = "file:./" + TestNcmlRead.topDir + "aggNewOneNumericTime.xml";
try (NetcdfDataset ncStr = NcMLReader.readNcML(aggStringTime, null);
NetcdfDataset ncNum = NcMLReader.readNcML(aggNumericTime, null)) {
compareTimes(ncStr, ncNum, "time2");
}
}

@Test
public void testNumericTimeNcmlReaderWithBuilders() throws IOException, InvalidRangeException, InterruptedException {
String aggStringTime = "file:./" + TestNcmlRead.topDir + "aggNewOne.xml";
String aggNumericTime = "file:./" + TestNcmlRead.topDir + "aggNewOneNumericTime.xml";
try (NetcdfDataset ncStr = NcmlReader.readNcml(aggStringTime, null, null).build();
NetcdfDataset ncNum = NcmlReader.readNcml(aggNumericTime, null, null).build()) {
compareTimes(ncStr, ncNum, "time2");
}
}

void compareTimes(NetcdfDataset ncStr, NetcdfDataset ncNum, String timeVarName) throws IOException {
Variable isoTimeVar = ncStr.findVariable(timeVarName);
assertThat(isoTimeVar != null).isTrue();
Variable numericTimeVar = ncNum.findVariable("time");
Variable numericTimeVar = ncNum.findVariable(timeVarName);
assertThat(numericTimeVar != null).isTrue();
Array isoTime = isoTimeVar.read();
Array numericTime = numericTimeVar.read();
Expand Down