Java Code Examples for ucar.nc2.Variable#getNameAndDimensions()

The following examples show how to use ucar.nc2.Variable#getNameAndDimensions() . 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: RadialCoordSys.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Determine if the CoordinateSystem cs can be made into a GridCoordSys for the Variable v.
 * 
 * @param parseInfo put debug information into this StringBuffer; may be null.
 * @param cs CoordinateSystem to check.
 * @param v Variable to check.
 * @return the RadialCoordSys made from cs, else null.
 */
public static RadialCoordSys makeRadialCoordSys(Formatter parseInfo, CoordinateSystem cs, Variable v) {
  if (parseInfo != null) {
    parseInfo.format(" ");
    v.getNameAndDimensions(parseInfo, true, false);
    parseInfo.format(" check CS " + cs.getName());
  }
  if (isRadialCoordSys(parseInfo, cs)) {
    RadialCoordSys rcs = new RadialCoordSys(cs);
    if (cs.isComplete(v)) {
      if (parseInfo != null)
        parseInfo.format(" OK%n");
      return rcs;
    } else {
      if (parseInfo != null)
        parseInfo.format(" NOT complete%n");
    }
  }

  return null;
}
 
Example 2
Source File: SimpleGeometryCS.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static SimpleGeometryCS makeSGCoordSys(Formatter sbuff, CoordinateSystem cs, Variable v) {
  if (sbuff != null) {
    sbuff.format(" ");
    v.getNameAndDimensions(sbuff, false, true);
    sbuff.format(" check CS %s: ", cs.getName());
  }

  SimpleGeometryCS gcs = new SimpleGeometryCS(new SimpleGeometryCSBuilder(null, cs, null));
  return gcs;
}
 
Example 3
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createNewVariables(NetcdfDataset ds, Variable ncVar, List<Dimension> newDims, Dimension levelDim)
    throws InvalidRangeException {

  List<Dimension> dims = ncVar.getDimensions();
  int newDimIndex = dims.indexOf(levelDim);
  // String shapeS = ncVar.getShapeS();

  int[] origin = new int[ncVar.getRank()];
  int[] shape = ncVar.getShape();
  int count = 0;
  for (Dimension dim : newDims) {
    String name = ncVar.getShortName() + "-" + dim.getShortName();

    origin[newDimIndex] = count;
    shape[newDimIndex] = dim.getLength();

    Variable varNew = ncVar.section(new Section(origin, shape));
    varNew.setName(name);
    varNew.setDimension(newDimIndex, dim);

    // synthesize long name
    String long_name = ds.findAttValueIgnoreCase(ncVar, CDM.LONG_NAME, ncVar.getShortName());
    long_name = long_name + "-" + dim.getShortName();
    ds.addVariableAttribute(varNew, new Attribute(CDM.LONG_NAME, long_name));

    ds.addVariable(null, varNew);

    parseInfo.format("Created New Variable as section = ");
    varNew.getNameAndDimensions(parseInfo, true, false);
    parseInfo.format("%n");

    count += dim.getLength();
  }
}
 
Example 4
Source File: CDLWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void writeCDL(Variable v, Indent indent, boolean useFullName) {
  out.format("%s", indent);
  DataType dataType = v.getDataType();
  if (dataType == null)
    out.format("Unknown");
  else if (dataType.isEnum()) {
    if (v.getEnumTypedef() == null)
      out.format("enum UNKNOWN");
    else
      out.format("enum %s", NetcdfFile.makeValidCDLName(v.getEnumTypedef().getShortName()));
  } else
    out.format("%s", dataType.toString());

  // if (isVariableLength) out.append("(*)"); // LOOK
  out.format(" ");
  v.getNameAndDimensions(out, useFullName, strict);
  out.format(";");
  out.format("%n");

  indent.incr();
  for (Attribute att : v.attributes()) {
    if (Attribute.isspecial(att))
      continue;
    out.format("%s", indent);
    writeCDL(att, v.getShortName());
    out.format(";");
    if (!strict && (att.getDataType() != DataType.STRING))
      out.format(" // %s", att.getDataType());
    out.format("%n");
  }
  indent.decr();
}
 
Example 5
Source File: NetcdfDatasetInfo.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private String getDecl(Variable ve) {
  Formatter sb = new Formatter();
  sb.format("%s ", ve.getDataType().toString());
  ve.getNameAndDimensions(sb, true, true);
  return sb.toString();
}