@SuppressWarnings("unchecked")
Enumeration<String> names = das.getNames();
while (names.hasMoreElements()) {
String attName = names.nextElement();
LOG.log(Level.FINE, "Extracting DAS attribute: " + attName);
AttributeTable at = das.getAttributeTable(attName);
Enumeration<String> e = at.getNames();
// NetCDF global attributes
// store attribute name, all values for ALL attributes (strings and numerics)
ProcessingInstructions processingInstructions = config.getProcessingInstructions();
if (attName.equals(NC_GLOBAL)) {
while (e.hasMoreElements()) {
String key = e.nextElement();
Attribute att = at.getAttribute(key);
// convert all DAS attribute names to lower case
String lkey = key.toLowerCase();
// look for global attribute name in date/time configuration specification
String dateTimeFormatKey = OpendapConfigMetKeys.DATETIME_FORMAT_ATTR + ":" + lkey;
String dateTimeFormatValue = processingInstructions.getInstructionValue(dateTimeFormatKey);
// add this attribute as properly formatted date/time
if (StringUtils.hasText(dateTimeFormatValue)) {
DateFormat inFormat = new SimpleDateFormat(dateTimeFormatValue);
Enumeration<String> edt = att.getValues();
while (edt.hasMoreElements()) {
String value = edt.nextElement();
try {
Date date = inFormat.parse(value);
ProfileUtils.addIfNotNull(metadata, lkey, outputDatetimeFormat.format(date));
} catch(ParseException pe) {
LOG.log(Level.WARNING,
"Error parsing date/time from DAS attribute: "+key+" value="+value+" error="+pe.getMessage());
}
}
// add this global attribute as string
} else {
ProfileUtils.addIfNotExisting(metadata, lkey, att.getValues());
}
}
// NetCDF coordinates
} else {
if ( attName.equalsIgnoreCase("lat") || attName.equalsIgnoreCase("latitude")
|| attName.equalsIgnoreCase("lon") || attName.equalsIgnoreCase("longitude")
|| attName.equalsIgnoreCase("time")
|| attName.equalsIgnoreCase("alt") || attName.equalsIgnoreCase("altitude")
|| attName.equalsIgnoreCase("lev") || attName.equalsIgnoreCase("level")
|| attName.equalsIgnoreCase("depth")
) {
if (!excludedVariables.contains(attName)) {
// store coordinate name
ProfileUtils.addIfNotNull(metadata, OpendapProfileMetKeys.COORDINATES, attName);
}
} else if (attName.toLowerCase().startsWith("time_") || attName.toLowerCase().endsWith("_time")) {
// ignore for now - it's not a coordinate neither a variable you would want to search on
// NetCDF variables
} else {
if (!excludedVariables.contains(attName)) {
// store variable name
ProfileUtils.addIfNotNull(metadata, OpendapProfileMetKeys.VARIABLES, attName);
// store "standard_name", "long_name"
while (e.hasMoreElements()) {
String key = e.nextElement();
Attribute att = at.getAttribute(key);
if (key.equalsIgnoreCase(STANDARD_NAME)) {
ProfileUtils.addIfNotNull(metadata, OpendapProfileMetKeys.CF_STANDARD_NAMES, att.getValueAt(0));
} else if (key.equalsIgnoreCase(LONG_NAME)) {
ProfileUtils.addIfNotNull(metadata, OpendapProfileMetKeys.VARIABLES_LONG_NAMES, att.getValueAt(0));
}