Java Code Examples for ucar.nc2.dataset.NetcdfDataset#findGlobalAttributeIgnoreCase()

The following examples show how to use ucar.nc2.dataset.NetcdfDataset#findGlobalAttributeIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreddsWmsCatalogue.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public ThreddsWmsCatalogue(NetcdfDataset ncd, String id) throws IOException, EdalException {
  // in the TDS, we already have a NetcdfFile object, so let's use it to create
  // the edal-java related dataset. To do so, we use our own TdsWmsDatasetFactory, which
  // overrides the getNetcdfDatasetFromLocation method from CdmGridDatasetFactory to take
  // the NetcdfDataset directly. However, createDataset's signature does not take a NetcdfDataset,
  // so we need to make it available to TdsWmsDatasetFactory to use.
  datasetFactory.setNetcdfDataset(ncd);

  // set dataset title
  Attribute datasetTitleAttr;
  datasetTitle = ncd.getTitle();
  if (datasetTitle == null) {
    datasetTitleAttr = ncd.findGlobalAttributeIgnoreCase("title");
    if (datasetTitleAttr != null) {
      datasetTitle = datasetTitleAttr.getStringValue();
    }
  }

  String location = ncd.getLocation();
  dataset = datasetFactory.createDataset(id, location);
}
 
Example 2
Source File: UnidataObsDatasetHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Date getStartDate(NetcdfDataset ds) {
  Attribute att = ds.findGlobalAttributeIgnoreCase("time_coverage_start");
  if (null == att)
    throw new IllegalArgumentException("Must have a time_coverage_start global attribute");

  if (att.getDataType() == DataType.STRING) {
    return DateUnit.getStandardOrISO(att.getStringValue());
  } else {
    throw new IllegalArgumentException("time_coverage_start must be a ISO or udunit date string");
  }
}
 
Example 3
Source File: UnidataObsDatasetHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Date getEndDate(NetcdfDataset ds) {
  Attribute att = ds.findGlobalAttributeIgnoreCase("time_coverage_end");
  if (null == att)
    throw new IllegalArgumentException("Must have a time_coverage_end global attribute");

  Date result;
  if (att.getDataType() == DataType.STRING) {
    result = DateUnit.getStandardOrISO(att.getStringValue());
  } else {
    throw new IllegalArgumentException("time_coverage_end must be a ISO or udunit date string");
  }

  return result;
}
 
Example 4
Source File: UnidataObsDatasetHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static double getAttAsDouble(NetcdfDataset ds, String attname) {
  Attribute att = ds.findGlobalAttributeIgnoreCase(attname);
  if (null == att)
    throw new IllegalArgumentException("Must have a " + attname + " global attribute");

  if (att.getDataType() == DataType.STRING) {
    return Double.parseDouble(att.getStringValue());
  } else {
    return att.getNumericValue().doubleValue();
  }
}
 
Example 5
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private double findAttributeDouble(NetcdfDataset ds, String attname) {
  Attribute att = ds.findGlobalAttributeIgnoreCase(attname);
  if (att == null) {
    parseInfo.format("ERROR cant find attribute= %s%n", attname);
    return Double.NaN;
  }
  return att.getNumericValue().doubleValue();
}
 
Example 6
Source File: UnidataPointDatasetHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static double getAttAsDouble(NetcdfDataset ds, String attname) {
  Attribute att = ds.findGlobalAttributeIgnoreCase(attname);
  if (null == att)
    throw new IllegalArgumentException("Must have a " + attname + " global attribute");

  if (att.getDataType() == DataType.STRING) {
    return Double.parseDouble(att.getStringValue());
  } else {
    return att.getNumericValue().doubleValue();
  }
}