Java Code Examples for ucar.nc2.VariableSimpleIF#getShortName()

The following examples show how to use ucar.nc2.VariableSimpleIF#getShortName() . 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: ThreddsMetadataExtractor.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public ThreddsMetadata.VariableGroup extractVariables(FeatureDatasetPoint fd) {
  List<ThreddsMetadata.Variable> vars = new ArrayList<>();

  List<VariableSimpleIF> dataVars = fd.getDataVariables();
  if (dataVars == null)
    return null;

  for (VariableSimpleIF v : dataVars) {
    String name = v.getShortName();
    String desc = v.getDescription();
    String units = v.getUnitsString();
    String vname = null;
    String id = null;

    ucar.nc2.Attribute att = v.attributes().findAttributeIgnoreCase("standard_name");
    if (att != null)
      vname = att.getStringValue();
    vars.add(new ThreddsMetadata.Variable(name, desc, vname, units, id));
  }

  Collections.sort(vars);
  // String vocab, String vocabHref, URI vocabUri, URI mapUri, List<Variable> variables
  return new ThreddsMetadata.VariableGroup("CF-1.0", null, null, vars);
}
 
Example 2
Source File: WriterCFPointAbstract.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void addCoordinatesClassic(Dimension recordDim, List<VariableSimpleIF> coords, Set<String> varSet) {
  addDimensionsClassic(coords);

  for (VariableSimpleIF oldVar : coords) {
    List<Dimension> dims = makeDimensionList(oldVar.getDimensions());
    dims.add(0, recordDim);
    Variable.Builder newVar;

    if (oldVar.getDataType() == DataType.STRING && !this.isExtendedModel) {
      // What should the string length be ?? Should read variable to find out....see old
      // writer.addStringVariable(null, (Variable) oldVar, dims)
      String name = oldVar.getShortName();
      Dimension strlen = new Dimension(name + "_strlen", defaultStringLength);
      newVar = Variable.builder().setName(name).setDataType(DataType.CHAR).setDimensions(dims).addDimension(strlen);
      writerb.getRootGroup().addDimensionIfNotExists(strlen);
    } else {
      newVar =
          Variable.builder().setName(oldVar.getShortName()).setDataType(oldVar.getDataType()).setDimensions(dims);
    }

    if (writerb.getRootGroup().replaceVariable(newVar)) {
      logger.info("Variable was already added =" + oldVar.getShortName());
    }

    newVar.addAttributes(oldVar.attributes());
    varSet.add(oldVar.getShortName());
  }

}
 
Example 3
Source File: WriterCFPointAbstract.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addDataVariablesClassic(Dimension recordDim, StructureData stnData, HashSet<String> varSet,
    String coordVars) {
  addDimensionsClassic(dataVars);

  for (StructureMembers.Member m : stnData.getMembers()) {
    VariableSimpleIF oldVar = findDataVar(m.getName());
    if (oldVar == null)
      continue;

    List<Dimension> dims = makeDimensionList(oldVar.getDimensions());
    dims.add(0, recordDim);

    Variable.Builder newVar;
    if (oldVar.getDataType() == DataType.STRING && !isExtendedModel) {
      // What should the string length be ??
      String name = oldVar.getShortName();
      Dimension strlen = new Dimension(name + "_strlen", defaultStringLength);
      newVar = Variable.builder().setName(name).setDataType(DataType.CHAR).setDimensions(dims).addDimension(strlen);
      writerb.getRootGroup().addDimensionIfNotExists(strlen);
    } else {
      newVar =
          Variable.builder().setName(oldVar.getShortName()).setDataType(oldVar.getDataType()).setDimensions(dims);
    }

    if (writerb.getRootGroup().replaceVariable(newVar)) {
      logger.warn("Variable was already added =" + oldVar.getShortName());
    }

    for (Attribute att : oldVar.attributes()) {
      String attName = att.getShortName();
      if (!reservedVariableAtts.contains(attName) && !attName.startsWith("_Coordinate"))
        newVar.addAttribute(att);
    }
    newVar.addAttribute(new Attribute(CF.COORDINATES, coordVars));
    varSet.add(oldVar.getShortName());
  }

}
 
Example 4
Source File: FeatureDatasetImpl.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VariableSimpleIF getDataVariable(String shortName) {
  for (VariableSimpleIF s : getDataVariables()) {
    String ss = s.getShortName();
    if (shortName.equals(ss))
      return s;
  }
  return null;
}