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
@@ -1,4 +1,8 @@
/* Copyright Unidata */
/*
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
* See LICENSE.txt for license information.
*/

package ucar.nc2.internal.ncml;

import java.io.IOException;
Expand All @@ -11,6 +15,7 @@
import javax.annotation.Nullable;
import thredds.inventory.MFile;
import ucar.ma2.Array;
import ucar.ma2.DataType;
import ucar.ma2.InvalidRangeException;
import ucar.ma2.Range;
import ucar.ma2.Section;
Expand All @@ -32,7 +37,8 @@ class AggDatasetOuter extends AggDataset {
@Nullable
final String coordValue; // if theres a coordValue on the netcdf element - may be multiple, blank separated
final Date coordValueDate; // if its a date
final boolean isStringValued; // if coordinat is a String
final DataType coordDataType; // coordinate data type
final String coordUdunit; // coordinate udunit string, if numeric

// not final because of deffered read
int ncoord; // number of coordinates in outer dimension
Expand Down Expand Up @@ -68,18 +74,18 @@ class AggDatasetOuter extends AggDataset {
}
}

boolean isString = false;
DataType aggCoordDataType = DataType.DOUBLE;
if ((aggregationOuter.type == Type.joinNew) || (aggregationOuter.type == Type.joinExistingOne)
|| (aggregationOuter.type == Type.forecastModelRunCollection)) {
if (coordValueS == null) {
coordValueS = extractCoordNameFromFilename(this.getLocation());
isString = true;
aggCoordDataType = DataType.STRING;
} else {
// we just need to know if its string valued
try {
Double.parseDouble(coordValueS);
} catch (NumberFormatException e) {
isString = true;
aggCoordDataType = DataType.STRING;
}
}
}
Expand All @@ -90,8 +96,10 @@ class AggDatasetOuter extends AggDataset {
this.ncoord = stoker.countTokens();
}

this.isStringValued = isString; // LOOK ??
coordDataType = aggCoordDataType;
this.coordValue = coordValueS;
// not dealing with scan
this.coordUdunit = "";
this.coordValueDate = null; // LOOK why isnt this set?
}

Expand All @@ -115,13 +123,21 @@ private String extractCoordNameFromFilename(String loc) {
// default is that the coordinates are just the filenames
// this can be overriden by an explicit declaration, which will replace the variable after ther agg is processed in
// NcMLReader
DataType aggCoordDataType = DataType.DOUBLE;
String coordUdunit = "";
if ((aggregationOuter.type == Type.joinNew) || (aggregationOuter.type == Type.joinExistingOne)
|| (aggregationOuter.type == Type.forecastModelRunCollection)) {
coordValueS = extractCoordNameFromFilename(this.getLocation());
this.isStringValued = true;
} else {
this.isStringValued = false; // LOOK ??
if (aggregationOuter.numericTimeSettings != null) {
String[] settings = aggregationOuter.numericTimeSettings.split(" ", 2);
aggCoordDataType = DataType.getType(settings[0]);
coordUdunit = settings[1];
} else {
aggCoordDataType = DataType.STRING;
}
}
this.coordDataType = aggCoordDataType;
this.coordUdunit = coordUdunit;

if (null != aggregationOuter.dateFormatMark) {
String filename = cd.getName(); // LOOK operates on name, not path
Expand Down
11 changes: 9 additions & 2 deletions cdm/core/src/main/java/ucar/nc2/internal/ncml/Aggregation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* Copyright (c) 1998-2020 John Caron and University Corporation for Atmospheric Research/Unidata
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
* See LICENSE.txt for license information.
*/

package ucar.nc2.internal.ncml;

import org.jdom2.Element;
Expand Down Expand Up @@ -95,6 +97,7 @@ else if (mode.equalsIgnoreCase("first"))

// experimental
protected String dateFormatMark;
protected String numericTimeSettings;
// protected EnumSet<NetcdfDataset.Enhance> enhance = null; // default no enhancement
protected boolean isDate;
protected DateFormatter dateFormatter = new DateFormatter();
Expand Down Expand Up @@ -153,13 +156,17 @@ public void addDataset(AggDataset nested) {
* @param subdirs equals "false" if should not descend into subdirectories
* @param olderThan files must be older than this time (now - lastModified >= olderThan); must be a time unit, may ne
* bull
* @param numericTimeSettings numeric time settings (data type and udunits compatible string,
* e.g. "float seconds since 1985-10-18T12:31:00", may be null)
*/
public void addDatasetScan(Element crawlableDatasetElement, String dirName, String suffix, String regexpPatternString,
String dateFormatMark, Set<NetcdfDataset.Enhance> enhanceMode, String subdirs, String olderThan) {
String dateFormatMark, Set<NetcdfDataset.Enhance> enhanceMode, String subdirs, String olderThan,
String numericTimeSettings) {

datasetManager.addDirectoryScan(dirName, suffix, regexpPatternString, subdirs, olderThan, enhanceMode);

this.dateFormatMark = dateFormatMark;
this.numericTimeSettings = numericTimeSettings;
if (dateFormatMark != null) {
isDate = true;
if (type == Type.joinExisting)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
* See LICENSE for license information.
*/

Expand Down Expand Up @@ -76,7 +76,13 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
}

} else {
coordCacheVar = new CoordValueVar(dimName, DataType.STRING, "");
DataType coordDataType = DataType.STRING;
String coordUnits = "";
if (typicalDataset instanceof AggDatasetOuter) {
coordDataType = ((AggDatasetOuter) typicalDataset).coordDataType;
coordUnits = ((AggDatasetOuter) typicalDataset).coordUdunit;
}
coordCacheVar = new CoordValueVar(dimName, coordDataType, coordUnits);
}
if (coordCacheVar != null) {
cacheList.add(coordCacheVar); // coordinate variable is always cached
Expand Down Expand Up @@ -134,8 +140,14 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
if (type == Type.joinExistingOne) {
// replace aggregation coordinate variable
joinAggCoordOpt.ifPresent(joinAgg -> rootGroup.removeVariable(joinAgg.shortName));
DataType coordDataType = DataType.STRING;
String coordUnits = "";
if (typicalDataset instanceof AggDatasetOuter) {
coordDataType = ((AggDatasetOuter) typicalDataset).coordDataType;
coordUnits = ((AggDatasetOuter) typicalDataset).coordUdunit;
}

joinAggCoord = VariableDS.builder().setName(dimName).setDataType(DataType.STRING).setParentGroupBuilder(rootGroup)
joinAggCoord = VariableDS.builder().setName(dimName).setDataType(coordDataType).setParentGroupBuilder(rootGroup)
.setDimensionsByName(dimName);
joinAggCoord.setProxyReader(this);
rootGroup.addVariable(joinAggCoord);
Expand All @@ -144,6 +156,9 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
joinAggCoord.addAttribute(new Attribute(_Coordinate.AxisType, "Time"));
joinAggCoord.addAttribute(new Attribute(CDM.LONG_NAME, "time coordinate"));
joinAggCoord.addAttribute(new Attribute(CF.STANDARD_NAME, "time"));
if (coordUnits != null && !coordUnits.equals("")) {
joinAggCoord.addAttribute(new Attribute(CF.UNITS, coordUnits));
}
}

if (timeUnitsChange && joinAggCoord != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
* See LICENSE for license information.
*/

Expand Down Expand Up @@ -149,7 +149,7 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
private DataType getCoordinateType() {
List<AggDataset> nestedDatasets = getDatasets();
AggDatasetOuter first = (AggDatasetOuter) nestedDatasets.get(0);
return first.isStringValued ? DataType.STRING : DataType.DOUBLE;
return first.coordDataType;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
* See LICENSE for license information.
*/

package ucar.nc2.internal.ncml;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -1526,6 +1527,7 @@ private Aggregation readAgg(Element aggElem, String ncmlLocation, NetcdfDataset.
String olderS = scanElem.getAttributeValue("olderThan");

String dateFormatMark = scanElem.getAttributeValue("dateFormatMark");
String numericTimeSettings = scanElem.getAttributeValue("numericTimeSettings");
Set<NetcdfDataset.Enhance> enhanceMode = NetcdfDataset.parseEnhanceMode(scanElem.getAttributeValue("enhance"));

// possible relative location
Expand All @@ -1534,7 +1536,7 @@ private Aggregation readAgg(Element aggElem, String ncmlLocation, NetcdfDataset.
// can embed a full-blown crawlableDatasetImpl element
Element cdElement = scanElem.getChild("crawlableDatasetImpl", ncNS); // ok if null
agg.addDatasetScan(cdElement, dirLocation, suffix, regexpPatternString, dateFormatMark, enhanceMode, subdirs,
olderS);
olderS, numericTimeSettings);

if ((cancelTask != null) && cancelTask.isCancel()) {
return agg;
Expand Down
26 changes: 26 additions & 0 deletions cdm/core/src/main/java/ucar/nc2/ncml/Aggregation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
* See LICENSE.txt for license information.
*/

package ucar.nc2.ncml;

import org.jdom2.Element;
Expand Down Expand Up @@ -153,6 +154,7 @@ else if (mode.equalsIgnoreCase("first"))

// experimental
protected String dateFormatMark;
protected String numericTimeSettings;
// protected EnumSet<NetcdfDataset.Enhance> enhance = null; // default no enhancement
protected boolean isDate;
protected DateFormatter dateFormatter = new DateFormatter();
Expand Down Expand Up @@ -199,6 +201,7 @@ public void addDataset(Dataset nested) {
explicitDatasets.add(nested);
}


/**
* Add a dataset scan
*
Expand All @@ -214,10 +217,33 @@ public void addDataset(Dataset nested) {
*/
public void addDatasetScan(Element crawlableDatasetElement, String dirName, String suffix, String regexpPatternString,
String dateFormatMark, Set<NetcdfDataset.Enhance> enhanceMode, String subdirs, String olderThan) {
addDatasetScan(crawlableDatasetElement, dirName, suffix, regexpPatternString, dateFormatMark, enhanceMode, subdirs,
olderThan, null);
}

/**
* Add a dataset scan
*
* @param crawlableDatasetElement defines a CrawlableDataset, or null
* @param dirName scan this directory
* @param suffix filter on this suffix (may be null)
* @param regexpPatternString include if full name matches this regular expression (may be null)
* @param dateFormatMark create dates from the filename (may be null)
* @param enhanceMode how should files be enhanced
* @param subdirs equals "false" if should not descend into subdirectories
* @param olderThan files must be older than this time (now - lastModified >= olderThan); must be a time unit, may ne
* bull
* @param numericTimeSettings numeric time settings (data type and udunits compatible string,
* e.g. "float seconds since 1985-10-18T12:31:00", may be null)
*/
public void addDatasetScan(Element crawlableDatasetElement, String dirName, String suffix, String regexpPatternString,
String dateFormatMark, Set<NetcdfDataset.Enhance> enhanceMode, String subdirs, String olderThan,
String numericTimeSettings) {

datasetManager.addDirectoryScan(dirName, suffix, regexpPatternString, subdirs, olderThan, enhanceMode);

this.dateFormatMark = dateFormatMark;
this.numericTimeSettings = numericTimeSettings;
if (dateFormatMark != null) {
isDate = true;
if (type == Type.joinExisting)
Expand Down
23 changes: 19 additions & 4 deletions cdm/core/src/main/java/ucar/nc2/ncml/AggregationExisting.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
* See LICENSE for license information.
*/

Expand Down Expand Up @@ -71,7 +71,13 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
}

} else {
coordCacheVar = new CoordValueVar(dimName, DataType.STRING, "");
DataType coordDataType = DataType.STRING;
String coordUnits = null;
if (typicalDataset instanceof AggregationOuterDimension.DatasetOuterDimension) {
coordDataType = ((AggregationOuterDimension.DatasetOuterDimension) typicalDataset).coordDataType;
coordUnits = ((AggregationOuterDimension.DatasetOuterDimension) typicalDataset).coordUdunit;
}
coordCacheVar = new CoordValueVar(dimName, coordDataType, coordUnits);
}
if (coordCacheVar != null) {
cacheList.add(coordCacheVar); // coordinate variable is always cached
Expand Down Expand Up @@ -128,15 +134,24 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
// replace aggregation coordinate variable
ncDataset.getRootGroup().removeVariable(joinAggCoord.getShortName());
}

joinAggCoord = new VariableDS(ncDataset, null, null, dimName, DataType.STRING, dimName, null, null);
DataType coordDataType = DataType.STRING;
String coordUnits = null;
if (typicalDataset instanceof AggregationOuterDimension.DatasetOuterDimension) {
coordDataType = ((AggregationOuterDimension.DatasetOuterDimension) typicalDataset).coordDataType;
coordUnits = ((AggregationOuterDimension.DatasetOuterDimension) typicalDataset).coordUdunit;
}
coordCacheVar = new CoordValueVar(dimName, coordDataType, coordUnits);
joinAggCoord = new VariableDS(ncDataset, null, null, dimName, coordDataType, dimName, coordUnits, null);
joinAggCoord.setProxyReader(this);
ncDataset.getRootGroup().addVariable(joinAggCoord);
aggVars.add(joinAggCoord);

joinAggCoord.addAttribute(new ucar.nc2.Attribute(_Coordinate.AxisType, "Time"));
joinAggCoord.addAttribute(new Attribute(CDM.LONG_NAME, "time coordinate"));
joinAggCoord.addAttribute(new ucar.nc2.Attribute(CF.STANDARD_NAME, "time"));
if (coordUnits != null && !coordUnits.equals("")) {
joinAggCoord.addAttribute(new Attribute(CF.UNITS, coordUnits));
}
}

if (timeUnitsChange && joinAggCoord != null) {
Expand Down
4 changes: 2 additions & 2 deletions cdm/core/src/main/java/ucar/nc2/ncml/AggregationNew.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
* Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
* See LICENSE for license information.
*/

Expand Down Expand Up @@ -134,7 +134,7 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
private DataType getCoordinateType() {
List<Dataset> nestedDatasets = getDatasets();
DatasetOuterDimension first = (DatasetOuterDimension) nestedDatasets.get(0);
return first.isStringValued ? DataType.STRING : DataType.DOUBLE;
return first.coordDataType;
}

}
Loading