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

The following examples show how to use ucar.nc2.Dimension#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: TestGeoGrid.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int[] getWeights(GeoGrid gg) {
  int rank = gg.getRank();
  int[] w = new int[rank];

  for (int n = 0; n < rank; n++) {
    Dimension dim = gg.getDimension(n);
    String dimName = dim.getShortName();
    if (dimName.equals("time"))
      w[n] = 1000;
    if (dimName.equals("z"))
      w[n] = 100;
    if (dimName.equals("y"))
      w[n] = 10;
    if (dimName.equals("x"))
      w[n] = 1;
  }

  return w;
}
 
Example 2
Source File: RafNimbus.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public TableConfig getConfig(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) {
  TableConfig topTable = new TableConfig(Table.Type.Top, "singleTrajectory");

  CoordinateAxis coordAxis = CoordSysEvaluator.findCoordByType(ds, AxisType.Time);
  if (coordAxis == null) {
    errlog.format("Cant find a time coordinate");
    return null;
  }
  Dimension innerDim = coordAxis.getDimension(0);
  boolean obsIsStruct = Evaluator.hasNetcdf3RecordStructure(ds) && innerDim.isUnlimited();

  TableConfig obsTable = new TableConfig(Table.Type.Structure, innerDim.getShortName());
  obsTable.dimName = innerDim.getShortName();
  obsTable.time = coordAxis.getFullName();
  obsTable.structName = obsIsStruct ? "record" : innerDim.getShortName();
  obsTable.structureType =
      obsIsStruct ? TableConfig.StructureType.Structure : TableConfig.StructureType.PsuedoStructure;
  CoordSysEvaluator.findCoords(obsTable, ds, axis -> innerDim.equals(axis.getDimension(0)));

  topTable.addChild(obsTable);
  return topTable;
}
 
Example 3
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private TableConfig makeSingle(NetcdfDataset ds, Dimension obsDim, Formatter errlog) {

    Table.Type obsTableType = Table.Type.Structure;
    TableConfig obsTable = new TableConfig(obsTableType, "single");
    obsTable.dimName = obsDim.getShortName();

    obsTable.lat = matchAxisTypeAndDimension(ds, AxisType.Lat, obsDim);
    obsTable.lon = matchAxisTypeAndDimension(ds, AxisType.Lon, obsDim);
    obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Height, obsDim);
    if (obsTable.elev == null)
      obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Pressure, obsDim);
    if (obsTable.elev == null)
      obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.GeoZ, obsDim);
    obsTable.time = matchAxisTypeAndDimension(ds, AxisType.Time, obsDim);

    makeStructureInfo(obsTable, ds, null, obsDim);
    return obsTable;
  }
 
Example 4
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void makeStructureInfo(TableConfig tableConfig, NetcdfDataset ds, Structure parent, Dimension dim) {
  tableConfig.dimName = dim.getShortName();
  if (parent != null) {
    tableConfig.structureType = TableConfig.StructureType.Structure;
    tableConfig.structName = parent.getShortName();
  } else {
    boolean hasNetcdf3Struct = Evaluator.hasNetcdf3RecordStructure(ds) && dim.isUnlimited();
    tableConfig.structureType =
        hasNetcdf3Struct ? TableConfig.StructureType.Structure : TableConfig.StructureType.PsuedoStructure;
    tableConfig.structName = hasNetcdf3Struct ? "record" : dim.getShortName();
  }

}
 
Example 5
Source File: WriterCFPointAbstract.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addDataVariablesExtended(Structure.Builder<?> recordb, StructureData obsData, String coordNames) {
  for (StructureMembers.Member m : obsData.getMembers()) {
    VariableSimpleIF oldVar = findDataVar(m.getName());
    if (oldVar == null)
      continue;

    // make dimension list
    StringBuilder dimNames = new StringBuilder();
    for (Dimension d : oldVar.getDimensions()) {
      if (d.isUnlimited())
        continue;
      if (d.getShortName() == null || !d.getShortName().equals(recordDimName))
        dimNames.append(" ").append(d.getLength()); // anonymous
    }

    Variable.Builder newVar = Variable.builder().setName(oldVar.getShortName()).setDataType(oldVar.getDataType())
        .setParentGroupBuilder(writerb.getRootGroup()).setDimensionsByName(dimNames.toString());
    recordb.addMemberVariable(newVar);

    // TODO
    /*
     * Variable newVar =
     * writer.addStructureMember(record, oldVar.getShortName(), oldVar.getDataType(), dimNames.toString());
     * if (newVar == null) {
     * logger.warn("Variable already exists =" + oldVar.getShortName()); // LOOK barf
     * continue;
     * }
     */

    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, coordNames));
  }

}
 
Example 6
Source File: NdbcNetcdf4.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TableConfig getConfig(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) {
  Dimension obsDim = ds.findDimension("time");
  if (obsDim == null) {
    CoordinateAxis axis = CoordSysEvaluator.findCoordByType(ds, AxisType.Time);
    if ((axis != null) && axis.isScalar())
      obsDim = axis.getDimension(0);
  }

  if (obsDim == null) {
    errlog.format("Must have an Observation dimension: unlimited dimension, or from Time Coordinate");
    return null;
  }
  boolean hasStruct = Evaluator.hasNetcdf3RecordStructure(ds);



  // otherwise, make it a Station
  TableConfig nt = new TableConfig(Table.Type.Top, "station");
  nt.featureType = FeatureType.STATION;

  nt.lat = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Lat);
  nt.lon = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Lon);

  nt.stnId = ds.getRootGroup().findAttributeString("station_name", null);
  nt.stnWmoId = ds.getRootGroup().findAttributeString("wmo_id", null);

  nt.stnDesc = ds.getRootGroup().findAttributeString("description", null);
  if (nt.stnDesc == null)
    nt.stnDesc = ds.getRootGroup().findAttributeString("comment", null);

  TableConfig obs = new TableConfig(Table.Type.Structure, hasStruct ? "record" : obsDim.getShortName());
  obs.structName = "record";
  obs.structureType = hasStruct ? TableConfig.StructureType.Structure : TableConfig.StructureType.PsuedoStructure;
  obs.dimName = obsDim.getShortName();
  obs.time = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Time);
  nt.addChild(obs);

  return nt;
}
 
Example 7
Source File: NetcdfUtils.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void createZVariable(NetcdfFileWriter netcdfFileWriter, Dimension zDimension) {
	String zVariableName = zDimension.getShortName();
	ArrayList<Dimension> dimensions = new ArrayList<>();
	dimensions.add(zDimension);
	Variable myVar = netcdfFileWriter.addVariable(null,zVariableName, DataType.DOUBLE, dimensions);
	netcdfFileWriter.addVariableAttribute(myVar,new Attribute(UNITS_ATTRIBUTE_NAME, Z_UNITS));
	netcdfFileWriter.addVariableAttribute(myVar,new Attribute(AXIS_ATTRIBUTE_NAME, Z_AXIS));
	netcdfFileWriter.addVariableAttribute(myVar,new Attribute(POSITIVE_ATTRIBUTE_NAME, Z_POSITIVE));
	netcdfFileWriter.addVariableAttribute(myVar,new Attribute(FILL_VALUE_ATTRIBUTE_NAME, DEFAULT_FILL_VALUE_DOUBLE));
}
 
Example 8
Source File: CoordSysTable.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public AxisBean(CoordinateAxis v) {
  this.axis = v;

  setName(v.getFullName());
  setCoordVar(v.isIndependentCoordinate());
  setDescription(v.getDescription());
  setUnits(v.getUnitsString());

  // collect dimensions
  StringBuilder lens = new StringBuilder();
  StringBuilder names = new StringBuilder();
  List dims = v.getDimensions();
  for (int j = 0; j < dims.size(); j++) {
    Dimension dim = (Dimension) dims.get(j);
    if (j > 0) {
      lens.append(",");
      names.append(",");
    }
    String name = dim.isShared() ? dim.getShortName() : "anon";
    names.append(name);
    lens.append(dim.getLength());
  }
  setDims(names.toString());
  setShape(lens.toString());

  AxisType at = v.getAxisType();
  if (at != null)
    setAxisType(at.toString());
  String p = v.getPositive();
  if (p != null)
    setPositive(p);

  if (v instanceof CoordinateAxis1D) {
    CoordinateAxis1D v1 = (CoordinateAxis1D) v;
    if (v1.isRegular())
      setRegular(Double.toString(v1.getIncrement()));
  }
  isLayer = (null != axis.findAttribute(_Coordinate.ZisLayer));
  isInterval = axis.isInterval();
}
 
Example 9
Source File: NcStream.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static NcStreamProto.Dimension.Builder encodeDim(Dimension dim) {
  NcStreamProto.Dimension.Builder dimBuilder = NcStreamProto.Dimension.newBuilder();
  if (dim.getShortName() != null)
    dimBuilder.setName(dim.getShortName());
  if (!dim.isVariableLength())
    dimBuilder.setLength(dim.getLength());
  dimBuilder.setIsPrivate(!dim.isShared());
  dimBuilder.setIsVlen(dim.isVariableLength());
  dimBuilder.setIsUnlimited(dim.isUnlimited());
  return dimBuilder;
}
 
Example 10
Source File: FmrcDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private VariableDS makeTimeCoordinate(NetcdfDataset result, Group group, String dimName, CalendarDate base,
    FmrcInvLite.ValueB valueb) {
  DataType dtype = DataType.DOUBLE;
  VariableDS timeVar = new VariableDS(result, group, null, dimName, dtype, dimName, null, null); // LOOK could just
                                                                                                 // make a
                                                                                                 // CoordinateAxis1D
  timeVar.addAttribute(new Attribute(CDM.LONG_NAME, "Forecast time for ForecastModelRunCollection"));
  timeVar.addAttribute(new ucar.nc2.Attribute("standard_name", "time"));
  timeVar.addAttribute(new ucar.nc2.Attribute(CF.CALENDAR, base.getCalendar().name()));
  // timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base));

  // Ensure a valid udunit
  timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base.getTimeUnits()));

  timeVar.addAttribute(new ucar.nc2.Attribute(CDM.MISSING_VALUE, Double.NaN));
  timeVar.addAttribute(new ucar.nc2.Attribute(_Coordinate.AxisType, AxisType.Time.toString()));

  // construct the values
  int ntimes = valueb.offset.length;
  timeVar.setCachedData(Array.factory(DataType.DOUBLE, new int[] {ntimes}, valueb.offset));
  group.addVariable(timeVar);

  if (valueb.bounds != null) {
    String bname = timeVar.getShortName() + "_bounds";
    timeVar.addAttribute(new ucar.nc2.Attribute("bounds", bname));
    Dimension bd = ucar.nc2.dataset.DatasetConstructor.getBoundsDimension(result);
    VariableDS boundsVar =
        new VariableDS(result, group, null, bname, dtype, dimName + " " + bd.getShortName(), null, null);
    boundsVar.addAttribute(new Attribute(CDM.LONG_NAME, "bounds for " + timeVar.getShortName()));
    boundsVar.setCachedData(Array.factory(DataType.DOUBLE, new int[] {ntimes, 2}, valueb.bounds));
    group.addVariable(boundsVar);
  }

  return timeVar;
}
 
Example 11
Source File: CDLWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void writeCDL(Dimension dim, Indent indent) {
  String name = strict ? NetcdfFiles.makeValidCDLName(dim.getShortName()) : dim.getShortName();
  out.format("%s%s", indent, name);
  if (dim.isUnlimited())
    out.format(" = UNLIMITED;   // (%d currently)", dim.getLength());
  else if (dim.isVariableLength())
    out.format(" = UNKNOWN;");
  else
    out.format(" = %d;", dim.getLength());
}
 
Example 12
Source File: DatasetWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VariableBean(Variable vs) {
  this.vs = vs;

  setName(vs.getShortName());
  setDescription(vs.getDescription());
  setUnits(vs.getUnitsString());
  setDataType(vs.getDataType().toString());

  // collect dimensions
  Formatter lens = new Formatter();
  Formatter names = new Formatter();
  lens.format("(");
  List<Dimension> dims = vs.getDimensions();
  for (int j = 0; j < dims.size(); j++) {
    Dimension dim = dims.get(j);
    if (j > 0) {
      lens.format(",");
      names.format(",");
    }
    String name = dim.isShared() ? dim.getShortName() : "anon";
    names.format("%s", name);
    lens.format("%d", dim.getLength());
  }
  lens.format(")");
  setDimensions(names.toString());
  setShape(lens.toString());
}
 
Example 13
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createNewVariables(VariableDS.Builder ncVar, List<Dimension> newDims, Dimension levelDim)
    throws InvalidRangeException {

  ArrayList<Dimension> dims = new ArrayList<>(ncVar.orgVar.getDimensions());
  int newDimIndex = dims.indexOf(levelDim);

  int[] origin = new int[ncVar.getRank()];
  int[] shape = ncVar.orgVar.getShape();
  int count = 0;
  for (Dimension dim : newDims) {
    origin[newDimIndex] = count;
    shape[newDimIndex] = dim.getLength();
    Variable varSection = ncVar.orgVar.section(new Section(origin, shape));

    String name = ncVar.shortName + "-" + dim.getShortName();
    VariableDS.Builder varNew =
        VariableDS.builder().setName(name).setOriginalVariable(varSection).setDataType(ncVar.dataType);
    dims.set(newDimIndex, dim);
    varNew.addDimensions(dims);
    varNew.addAttributes(ncVar.getAttributeContainer());

    // synthesize long name
    String long_name = ncVar.getAttributeContainer().findAttributeString(CDM.LONG_NAME, ncVar.shortName);
    long_name = long_name + "-" + dim.getShortName();
    varNew.getAttributeContainer().addAttribute(new Attribute(CDM.LONG_NAME, long_name));

    rootGroup.addVariable(varNew);
    parseInfo.format("Created New Variable as section = %s%n", name);
    count += dim.getLength();
  }
}
 
Example 14
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 15
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private TableConfig makeStationTable(NetcdfDataset ds, FeatureType ftype, EncodingInfo info, Formatter errlog) {
  Variable lat = CoordSysEvaluator.findCoordByType(ds, AxisType.Lat);
  Variable lon = CoordSysEvaluator.findCoordByType(ds, AxisType.Lon);
  if (lat == null || lon == null) {
    errlog.format("CFpointObs: must have lat and lon coordinates%n");
    return null;
  }
  // Dimension stationDim = (info.encoding == Encoding.single) ? null : lat.getDimension(0); // assumes outer dim of
  // lat is parent dimension, single = scalar

  Table.Type stationTableType = Table.Type.Structure;
  if (info.encoding == Encoding.single)
    stationTableType = Table.Type.Top;
  if (info.encoding == Encoding.flat)
    stationTableType = Table.Type.Construct;

  Dimension stationDim = (info.encoding == Encoding.flat) ? info.childDim : info.parentDim;
  String name = (stationDim == null) ? " single" : stationDim.getShortName();
  TableConfig stnTable = new TableConfig(stationTableType, name);
  stnTable.featureType = ftype;

  // stnId
  Variable stnIdVar =
      Evaluator.findVariableWithAttributeAndDimension(ds, CF.CF_ROLE, CF.TIMESERIES_ID, stationDim, errlog);
  if (stnIdVar == null)
    stnIdVar =
        Evaluator.findVariableWithAttributeAndDimension(ds, CF.STANDARD_NAME, CF.STATION_ID, stationDim, errlog);
  if (stnIdVar == null) {
    errlog.format("CFpointObs: must have a Station id variable with %s = %s%n", CF.CF_ROLE, CF.TIMESERIES_ID);
    return null;
  }
  stnTable.stnId = stnIdVar.getFullName();
  info.instanceId = stnIdVar;

  stnTable.stnDesc = Evaluator.findNameVariableWithStandardNameAndDimension(ds, CF.PLATFORM_NAME, stationDim, errlog);
  if (stnTable.stnDesc == null)
    stnTable.stnDesc =
        Evaluator.findNameVariableWithStandardNameAndDimension(ds, CF.STATION_DESC, stationDim, errlog);
  stnTable.stnWmoId = Evaluator.findNameVariableWithStandardNameAndDimension(ds, CF.PLATFORM_ID, stationDim, errlog);
  if (stnTable.stnWmoId == null)
    stnTable.stnWmoId =
        Evaluator.findNameVariableWithStandardNameAndDimension(ds, CF.STATION_WMOID, stationDim, errlog);
  stnTable.stnAlt =
      Evaluator.findNameVariableWithStandardNameAndDimension(ds, CF.SURFACE_ALTITUDE, stationDim, errlog);
  if (stnTable.stnAlt == null)
    stnTable.stnAlt =
        Evaluator.findNameVariableWithStandardNameAndDimension(ds, CF.STATION_ALTITUDE, stationDim, errlog);
  stnTable.lat = lat.getFullName();
  stnTable.lon = lon.getFullName();

  if (info.encoding != Encoding.single && stationDim != null) {
    stnTable.dimName = stationDim.getShortName();
    makeStructureInfo(stnTable, ds, stnIdVar.getParentStructure(), stationDim);
  }

  // LOOK probably need a standard name here
  // optional alt coord - detect if its a station height or actually associated with the obs, eg for a profile
  if (stnTable.stnAlt == null) {
    Variable alt = CoordSysEvaluator.findCoordByType(ds, AxisType.Height);
    if (alt != null) {
      if ((info.encoding == Encoding.single) && alt.getRank() == 0)
        stnTable.stnAlt = alt.getFullName();

      if ((info.encoding != Encoding.single) && (lat.getRank() == alt.getRank()) && alt.getRank() > 0
          && alt.getDimension(0).equals(stationDim))
        stnTable.stnAlt = alt.getFullName();
    }
  }

  return stnTable;
}
 
Example 16
Source File: CFpointObs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private TableConfig makeMultidimInner(NetcdfDataset ds, TableConfig parentTable, Dimension obsDim, EncodingInfo info,
    Formatter errlog) {
  Dimension parentDim = ds.findDimension(parentTable.dimName);

  Table.Type obsTableType =
      (parentTable.structureType == TableConfig.StructureType.PsuedoStructure) ? Table.Type.MultidimInnerPsuedo
          : Table.Type.MultidimInner;
  // if (info.time.isMemberOfStructure()) obsTableType = Table.Type.Structure;

  TableConfig obsTable = new TableConfig(obsTableType, obsDim.getShortName());

  obsTable.lat = matchAxisTypeAndDimension(ds, AxisType.Lat, parentDim, obsDim);
  obsTable.lon = matchAxisTypeAndDimension(ds, AxisType.Lon, parentDim, obsDim);
  obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Height, parentDim, obsDim);
  if (obsTable.elev == null)
    obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Pressure, parentDim, obsDim);
  if (obsTable.elev == null)
    obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.GeoZ, parentDim, obsDim);
  obsTable.time = matchAxisTypeAndDimension(ds, AxisType.Time, parentDim, obsDim);

  // divide up the variables between the parent and the obs
  List<String> obsVars;
  List<Variable> vars = ds.getVariables();
  List<String> parentVars = new ArrayList<>(vars.size());
  obsVars = new ArrayList<>(vars.size());
  for (Variable orgV : vars) {
    if (orgV instanceof Structure)
      continue;

    Dimension dim0 = orgV.getDimension(0);
    if ((dim0 != null) && dim0.equals(parentDim)) {
      if ((orgV.getRank() == 1) || ((orgV.getRank() == 2) && orgV.getDataType() == DataType.CHAR)) {
        parentVars.add(orgV.getShortName());
      } else {
        Dimension dim1 = orgV.getDimension(1);
        if (obsDim.equals(dim1))
          obsVars.add(orgV.getShortName());
      }
    }
  }
  parentTable.vars = parentVars;
  // parentTable.vars = parentTable.isPsuedoStructure ? parentVars : null; // restrict to these if psuedoStruct

  obsTable.structureType = parentTable.structureType;
  obsTable.outerName = parentDim.getShortName();
  obsTable.innerName = obsDim.getShortName();
  obsTable.dimName = (parentTable.structureType == TableConfig.StructureType.PsuedoStructure) ? obsTable.outerName
      : obsTable.innerName;
  obsTable.structName = obsDim.getShortName();
  obsTable.vars = obsVars;

  return obsTable;
}
 
Example 17
Source File: FmrcDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void transferGroup(Group srcGroup, Group targetGroup, NetcdfDataset target) throws IOException {
  // group attributes
  DatasetConstructor.transferGroupAttributes(srcGroup, targetGroup);

  // dimensions
  for (Dimension d : srcGroup.getDimensions()) {
    if (null == targetGroup.findDimensionLocal(d.getShortName())) {
      Dimension newd =
          new Dimension(d.getShortName(), d.getLength(), d.isShared(), d.isUnlimited(), d.isVariableLength());
      targetGroup.addDimension(newd);
    }
  }

  // transfer variables - eliminate any references to component files
  for (Variable v : srcGroup.getVariables()) {
    Variable targetV = targetGroup.findVariableLocal(v.getShortName());

    if (null == targetV) { // add it
      if (v instanceof Structure) {
        targetV = new StructureDS(target, targetGroup, null, v.getShortName(), v.getDimensionsString(),
            v.getUnitsString(), v.getDescription());
        // LOOK - not adding the members here - what to do ??

      } else {
        targetV = new VariableDS(target, targetGroup, null, v.getShortName(), v.getDataType(),
            v.getDimensionsString(), v.getUnitsString(), v.getDescription());
      }

      DatasetConstructor.transferVariableAttributes(v, targetV);
      VariableDS vds = (VariableDS) v;
      targetV.setSPobject(vds); // temporary, for non-agg variables when proto is made
      if (vds.hasCachedDataRecurse()) {
        if (vds.getSize() > 1000 * 1000) {
          boolean wtf = vds.hasCachedDataRecurse();
        }
        targetV.setCachedData(vds.read()); //
      }
      targetGroup.addVariable(targetV);
    }
  }

  // nested groups - check if target already has it
  for (Group srcNested : srcGroup.getGroups()) {
    Group nested = targetGroup.findGroupLocal(srcNested.getShortName());
    if (null == nested) {
      nested = new Group(target, targetGroup, srcNested.getShortName());
      targetGroup.addGroup(nested);
      for (EnumTypedef et : srcNested.getEnumTypedefs()) {
        targetGroup.addEnumeration(et);
      }
    }
    transferGroup(srcNested, nested, target);
  }
}
 
Example 18
Source File: WriterCFPointAbstract.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Returns a name for {@code dim} that is suitable for a shared dimension. If the dimension is anonymous, meaning
 * that its name is {@code null}, we return a default name: {@code "len" + dim.getLength()}. Otherwise, we return the
 * dimension's existing name.
 *
 * @param dim a dimension.
 * @return a name that is suitable for a shared dimension, i.e. not {@code null}.
 */
private String getSharedDimName(Dimension dim) {
  if (dim.getShortName() == null) { // Dim is anonymous.
    return "len" + dim.getLength();
  } else {
    return dim.getShortName();
  }
}
 
Example 19
Source File: NetcdfUtils.java    From OpenDA with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Creates y and x variables with the given properties.
 *
 * @param netcdfFileWriter
 * @param yDimension
 * @param xDimension
 * @param yStandardName
 * @param xStandardName
 * @param yLongName
 * @param xLongName
 * @param yUnits
 * @param xUnits
 * @param gridVariableProperties
 */
private static void createYX1DVariables(NetcdfFileWriter netcdfFileWriter,
		Dimension yDimension, Dimension xDimension, String yStandardName, String xStandardName,
		String yLongName, String xLongName, String yUnits, String xUnits, GridVariableProperties gridVariableProperties) {

	String yVariableName = yDimension.getShortName();
	String xVariableName = xDimension.getShortName();
	createCoordinateVariable(netcdfFileWriter, yVariableName, yDimension, yStandardName, yLongName, yUnits, Y_AXIS,
			DEFAULT_FILL_VALUE_DOUBLE);
	createCoordinateVariable(netcdfFileWriter, xVariableName, xDimension, xStandardName, xLongName, xUnits, X_AXIS,
			DEFAULT_FILL_VALUE_DOUBLE);
	gridVariableProperties.setY1DVariableName(yVariableName);
	gridVariableProperties.setX1DVariableName(xVariableName);
}
 
Example 20
Source File: Evaluator.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Find the dimension pointed to by key
 *
 * @param ds in this dataset
 * @param key may be dimension name or ":gatt" where gatt is local attribute whose value is the dimension name
 * @param errlog error messages here
 * @return name of dimension or null if not exist
 */
public static String getDimensionName(NetcdfDataset ds, String key, Formatter errlog) {
  Dimension d = getDimension(ds, key, errlog);
  return (d == null) ? null : d.getShortName();
}