Skip to content

Commit

Permalink
Fix coordinate attribute for constructed dates
Browse files Browse the repository at this point in the history
  • Loading branch information
lesserwhirls committed Feb 20, 2018
1 parent 43c106d commit 3a4fffe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/main/java/edu/ucar/unidata/rosetta/dsg/NetcdfFileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ protected Boolean findCoordAndNonCoordVars() {
value = getVariableNameMap().get(key);
if (!value.equals("Do Not Use")) {
variableMetadata = getVariableMetadataMap().get(key + "Metadata");
boolean updatedMetadataMap = false;
// check if variable is a coordinate variable!
if (variableMetadata.containsKey("_coordinateVariable")) {
String coordVarType = variableMetadata.get("_coordinateVariableType");
Expand All @@ -343,11 +344,27 @@ protected Boolean findCoordAndNonCoordVars() {
coordVarList.add(key);
coordVars.put(coordVarType, (ArrayList<String>) coordVarList);
} else {
if (coordVarType != null) {
if (coordVarType.toLowerCase().contains("only") ||
coordVarType.toLowerCase().equals("fulldatetime")) {
// this is a time variable that does not have udunit compliant unit,
// so rename the unit attribute to format
if (variableMetadata.containsKey("units")) {
variableMetadata.put("format", variableMetadata.get("units"));
variableMetadata.remove("units");
updatedMetadataMap = true;
}
}
}
nonCoordVarList.add(key);
}
} else {
nonCoordVarList.add(key);
}

if (updatedMetadataMap) {
variableMetadataMap.put(key + "Metadata", variableMetadata);
}
}
}

Expand Down Expand Up @@ -789,9 +806,11 @@ public String createNetcdfFile(AsciiFile file, List<List<String>> parseFileData,
}

} catch (IllegalArgumentException e) {
e.printStackTrace();
throw e;
} catch (Exception e) {
//TODO: Using this broad catch is not very good practice
e.printStackTrace();
logger.error(e.getMessage());
logger.error(e.getStackTrace());
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public SingleStationTimeSeries() {
@Override
protected void createCoordinateAttr(boolean hasRelTime) {
// if we have a relTime (a complete time variable), use that variable name
// otherwise, use a (yet-to-be-created) variable called "time"
// otherwise, use a (yet-to-be-created) variable called "dateTime"
if (hasRelTime) {
setCoordAttr(getRelTimeVarName() + " lat lon alt");
} else {
setCoordAttr("time lat lon alt");
setCoordAttr("dateTime lat lon alt");
}
}

Expand All @@ -58,7 +58,8 @@ protected NetcdfFileWriter createCoordVarsFromPlatform(NetcdfFileWriter ncFileWr

Variable theVar = ncFileWriter.addVariable(null, name.substring(0, 3), DataType.FLOAT, "");

ncFileWriter.addVariableAttribute(theVar, new Attribute("Units", coordVarUnits));

ncFileWriter.addVariableAttribute(theVar, new Attribute("units", coordVarUnits));
ncFileWriter.addVariableAttribute(theVar, new Attribute("standard_name", name));
ncFileWriter.addVariableAttribute(theVar, new Attribute("_platformMetadata", "true"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected void createCoordinateAttr(boolean hasRelTime) {
if (hasRelTime) {
setCoordAttr(getRelTimeVarName() + ca);
} else {
setCoordAttr("time" + ca);
setCoordAttr("dateTime" + ca);
}
}

Expand All @@ -68,7 +68,7 @@ protected NetcdfFileWriter createCoordVarsFromPlatform(NetcdfFileWriter ncFileWr

Variable theVar = ncFileWriter.addVariable(null, name.substring(0, 3), DataType.FLOAT, "");

ncFileWriter.addVariableAttribute(theVar, new Attribute("Units", coordVarUnits));
ncFileWriter.addVariableAttribute(theVar, new Attribute("units", coordVarUnits));
ncFileWriter.addVariableAttribute(theVar, new Attribute("standard_name", name));
ncFileWriter.addVariableAttribute(theVar, new Attribute("_platformMetadata", "true"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void initDateAndTimeArrays() throws IOException {
if (timeOnly && dateOnly) {
ArrayChar timeDataArray = (ArrayChar) timeOnlyVar.read();
ArrayChar dateDataArray = (ArrayChar) dateOnlyVar.read();
String dateFmt = dateOnlyVar.getUnitsString();
String timeFmt = timeOnlyVar.getUnitsString();
String dateFmt = dateOnlyVar.findAttributeIgnoreCase("format").getStringValue();
String timeFmt = timeOnlyVar.findAttributeIgnoreCase("format").getStringValue();
CalendarDateFormatter fmt = new CalendarDateFormatter(dateFmt + timeFmt);
String date, time, dateTimeStr;
CalendarDate dateTime;
Expand All @@ -80,7 +80,7 @@ public void initDateAndTimeArrays() throws IOException {
}
} else if (fullDateTime) {
ArrayChar fullDateTimeArray = (ArrayChar) fullDateTimeVar.read();
String dateFmt = fullDateTimeVar.getUnitsString();
String dateFmt = fullDateTimeVar.findAttributeIgnoreCase("format").toString();
CalendarDateFormatter fmt = new CalendarDateFormatter(dateFmt);
String dateTimeStr;
CalendarDate dateTime;
Expand Down

0 comments on commit 3a4fffe

Please sign in to comment.