Java Code Examples for ucar.ma2.DataType#SEQUENCE

The following examples show how to use ucar.ma2.DataType#SEQUENCE . 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: Table.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public StructureDataIterator getStructureDataIterator(Cursor cursor) {
  StructureData parentStruct = cursor.getParentStructure();

  StructureMembers members = parentStruct.getStructureMembers();
  StructureMembers.Member m = members.findMember(nestedTableName);

  if (m.getDataType() == DataType.SEQUENCE) {
    ArraySequence seq = parentStruct.getArraySequence(m);
    return seq.getStructureDataIterator();
  } else if (m.getDataType() == DataType.STRUCTURE) {
    ArrayStructure as = parentStruct.getArrayStructure(m);
    return as.getStructureDataIterator();
  }

  throw new IllegalStateException("Cant find nested table member = " + nestedTableName);
}
 
Example 2
Source File: CDMDSP.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Walk this variable, including fields, to construct sequence types
 * for any contained vlen dimensions
 *
 * @param cdmvar variable to walk
 */

protected void buildseqtypes(Variable cdmvar) throws DapException {
  if (CDMUtil.hasVLEN(cdmvar)) {
    buildseqtype(cdmvar);
  }
  if (cdmvar.getDataType() == DataType.STRUCTURE || cdmvar.getDataType() == DataType.SEQUENCE) {
    Structure struct = (Structure) cdmvar;
    List<Variable> fields = struct.getVariables();
    for (int i = 0; i < fields.size(); i++) {
      Variable field = fields.get(i);
      buildseqtypes(field); // recurse for inner vlen dims
    }
  }
}
 
Example 3
Source File: CdmDirect.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected TableConfig getStationProfileConfig(NetcdfDataset ds, Formatter errlog) {
  TableConfig stnTable = getStationConfig(ds, errlog);
  if (stnTable == null)
    return null;

  stnTable.featureType = FeatureType.STATION_PROFILE;
  TableConfig timeSeries = stnTable.children.get(0);
  Structure obsv = (Structure) ds.findVariable(timeSeries.name);
  Structure profile = null;
  for (Variable v : obsv.getVariables()) {
    if (v.getDataType() == DataType.SEQUENCE)
      profile = (Structure) v;
  }
  if (profile == null) {
    errlog.format("getStationProfileConfig: must have Sequence varibale for profile%n");
    return null;
  }
  TableConfig profileTc = new TableConfig(Table.Type.NestedStructure, profile.getFullName());
  profileTc.nestedTableName = profile.getShortName();
  Variable elev = findZAxisNotStationAlt(ds);
  if (elev == null) {
    errlog.format("getStationProfileConfig: must have ZAxis that is not the StationAlt%n");
    return null;
  }

  profileTc.elev = elev.getShortName();
  if (profileTc.elev == null) {
    errlog.format("Must have a level coordinate%n");
    return null;
  }
  timeSeries.addChild(profileTc);

  return stnTable;
}
 
Example 4
Source File: BufrFeatureDatasetFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
List<VariableSimpleIF> makeDataVariables(BufrCdmIndex index, Structure obs) {
  this.sdataName = obs.getShortName() + "Munged";

  List<Variable> members = obs.getVariables();
  List<VariableSimpleIF> result = new ArrayList<>(members.size());

  List<BufrCdmIndexProto.Field> flds = index.root.getFldsList();
  int count = 0;
  for (Variable v : members) {
    BufrCdmIndexProto.Field fld = flds.get(count++);
    if (fld.getAction() != null && fld.getAction() != BufrCdmIndexProto.FldAction.none) {
      needed = true;
      Action act = new Action(fld.getAction());
      actions.put(v.getShortName(), act);

      if (fld.getAction() == BufrCdmIndexProto.FldAction.remove) {
        continue; // skip

      } else if (fld.getAction() == BufrCdmIndexProto.FldAction.asMissing) {
        // promote the children
        Structure s = (Structure) v;
        for (Variable child : s.getVariables()) {
          result.add(child);
          vars.put(child.getShortName(), (VariableDS) child); // track ones we may have to create missing values for
        }
        continue;
      }
    }

    if (v.getDataType() == DataType.SEQUENCE)
      continue;
    result.add(v);
  }
  return result;
}
 
Example 5
Source File: TestPointDatasets.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static private void checkData(StructureData sdata) {

    for (StructureMembers.Member member : sdata.getMembers()) {
      DataType dt = member.getDataType();
      if (dt == DataType.FLOAT) {
        sdata.getScalarFloat(member);
        sdata.getJavaArrayFloat(member);
      } else if (dt == DataType.DOUBLE) {
        sdata.getScalarDouble(member);
        sdata.getJavaArrayDouble(member);
      } else if (dt == DataType.BYTE) {
        sdata.getScalarByte(member);
        sdata.getJavaArrayByte(member);
      } else if (dt == DataType.SHORT) {
        sdata.getScalarShort(member);
        sdata.getJavaArrayShort(member);
      } else if (dt == DataType.INT) {
        sdata.getScalarInt(member);
        sdata.getJavaArrayInt(member);
      } else if (dt == DataType.LONG) {
        sdata.getScalarLong(member);
        sdata.getJavaArrayLong(member);
      } else if (dt == DataType.CHAR) {
        sdata.getScalarChar(member);
        sdata.getJavaArrayChar(member);
        sdata.getScalarString(member);
      } else if (dt == DataType.STRING) {
        sdata.getScalarString(member);
      }

      if ((dt != DataType.STRING) && (dt != DataType.CHAR) && (dt != DataType.STRUCTURE) && (dt != DataType.SEQUENCE)) {
        sdata.convertScalarFloat(member.getName());
      }

    }
  }
 
Example 6
Source File: CDMTypeFcns.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static DataType daptype2cdmtype(DapType type) {
  assert (type != null);
  switch (type.getTypeSort()) {
    case Char:
      return DataType.CHAR;
    case UInt8:
      return DataType.UBYTE;
    case Int8:
      return DataType.BYTE;
    case Int16:
      return DataType.SHORT;
    case UInt16:
      return DataType.USHORT;
    case Int32:
      return DataType.INT;
    case UInt32:
      return DataType.UINT;
    case Int64:
      return DataType.LONG;
    case UInt64:
      return DataType.ULONG;
    case Float32:
      return DataType.FLOAT;
    case Float64:
      return DataType.DOUBLE;
    case String:
    case URL:
      return DataType.STRING;
    case Opaque:
      return DataType.OPAQUE;
    case Enum:
      // Coverity[FB.BC_UNCONFIRMED_CAST]
      DapEnumeration dapenum = (DapEnumeration) type;
      switch (dapenum.getBaseType().getTypeSort()) {
        case Char:
        case UInt8:
        case Int8:
          return DataType.ENUM1;
        case Int16:
        case UInt16:
          return DataType.ENUM2;
        case Int32:
        case UInt32:
          return DataType.ENUM4;
        case Int64:
        case UInt64:
          // since there is no ENUM8, use ENUM4
          return DataType.ENUM4;
        default:
          break;
      }
      break;
    case Structure:
      return DataType.STRUCTURE;
    case Sequence:
      return DataType.SEQUENCE;
    default:
      break;
  }
  return null;
}
 
Example 7
Source File: NcStream.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static DataType convertDataType(ucar.nc2.stream.NcStreamProto.DataType dtype) {
  switch (dtype) {
    case CHAR:
      return DataType.CHAR;
    case BYTE:
      return DataType.BYTE;
    case SHORT:
      return DataType.SHORT;
    case INT:
      return DataType.INT;
    case LONG:
      return DataType.LONG;
    case FLOAT:
      return DataType.FLOAT;
    case DOUBLE:
      return DataType.DOUBLE;
    case STRING:
      return DataType.STRING;
    case STRUCTURE:
      return DataType.STRUCTURE;
    case SEQUENCE:
      return DataType.SEQUENCE;
    case ENUM1:
      return DataType.ENUM1;
    case ENUM2:
      return DataType.ENUM2;
    case ENUM4:
      return DataType.ENUM4;
    case OPAQUE:
      return DataType.OPAQUE;
    case UBYTE:
      return DataType.UBYTE;
    case USHORT:
      return DataType.USHORT;
    case UINT:
      return DataType.UINT;
    case ULONG:
      return DataType.ULONG;
  }
  throw new IllegalStateException("illegal data type " + dtype);
}
 
Example 8
Source File: NcMLReaderNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Read the NcML variable element, and nested elements.
 *
 * @param groupBuilder put dimension into this group
 * @param refGroup parent Group in referenced dataset, may be null
 * @param varElem ncml variable element
 */
private void readVariable(Group.Builder groupBuilder, @Nullable Group refGroup, Element varElem) {
  String name = varElem.getAttributeValue("name");
  if (name == null) {
    errlog.format("NcML Variable name is required (%s)%n", varElem);
    return;
  }
  String nameInFile = Optional.ofNullable(varElem.getAttributeValue("orgName")).orElse(name);

  DataType dtype = null;
  String typeS = varElem.getAttributeValue("type");
  if (typeS != null) {
    dtype = DataType.getType(typeS);
  }

  // see if it already exists
  Variable refv = (refGroup == null) ? null : refGroup.findVariableLocal(nameInFile);
  Optional<Variable.Builder<?>> addedFromAgg = groupBuilder.findVariableLocal(nameInFile);
  if (refv == null && !addedFromAgg.isPresent()) { // new
    if (dtype == null) {
      errlog.format("NcML Variable dtype is required for new variable (%s)%n", name);
      return;
    }
    if (dtype == DataType.STRUCTURE || dtype == DataType.SEQUENCE) {
      groupBuilder.addVariable(readStructureNew(groupBuilder, varElem));
    } else {
      groupBuilder.addVariable(readVariableNew(groupBuilder, dtype, varElem));
    }
    return;
  }

  // refv exists
  if (refv != null) {
    if (dtype == null) {
      dtype = refv.getDataType();
    }
    if (dtype == DataType.STRUCTURE || dtype == DataType.SEQUENCE) {
      readStructureExisting(groupBuilder, null, dtype, (Structure) refv, varElem)
          .ifPresent(groupBuilder::addVariable);
    } else {
      readVariableExisting(groupBuilder, null, dtype, refv, varElem).ifPresent(groupBuilder::addVariable);
    }
    return;
  }

  // refv does not exist, but addedFromAgg may be present
  DataType finalDtype = dtype;
  addedFromAgg.ifPresent(agg -> {
    if (agg instanceof VariableDS.Builder<?>) {
      VariableDS.Builder<?> aggDs = (VariableDS.Builder<?>) agg;
      aggDs.setOriginalName(nameInFile);
    }
    DataType reallyFinalDtype = finalDtype != null ? finalDtype : agg.dataType;
    augmentVariableNew(agg, reallyFinalDtype, varElem);
  });
}
 
Example 9
Source File: NcMLReaderNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void readMemberVariable(Group.Builder groupBuilder, StructureDS.Builder<?> parentStructure,
    @Nullable Structure refParentStructure, Element varElem) {
  String name = varElem.getAttributeValue("name");
  if (name == null) {
    errlog.format("NcML Variable name is required (%s)%n", varElem);
    return;
  }
  String nameInFile = Optional.ofNullable(varElem.getAttributeValue("orgName")).orElse(name);

  DataType dtype = null;
  String typeS = varElem.getAttributeValue("type");
  if (typeS != null) {
    dtype = DataType.getType(typeS);
  }

  // see if it already exists
  Variable refv = (refParentStructure == null) ? null : refParentStructure.findVariable(nameInFile);
  if (refv == null) { // new
    if (dtype == null) {
      errlog.format("NcML Variable dtype is required for new (nested) variable (%s)%n", name);
      return;
    }
    if (dtype == DataType.STRUCTURE || dtype == DataType.SEQUENCE) {
      parentStructure.addMemberVariable(readStructureNew(groupBuilder, varElem));
    } else {
      parentStructure.addMemberVariable(readVariableNew(groupBuilder, dtype, varElem));
    }
    return;
  }

  // refv exists
  if (dtype == null) {
    dtype = refv.getDataType();
  }

  if (dtype == DataType.STRUCTURE || dtype == DataType.SEQUENCE) {
    readStructureExisting(groupBuilder, parentStructure, dtype, (Structure) refv, varElem)
        .ifPresent(parentStructure::addMemberVariable);
  } else {
    readVariableExisting(groupBuilder, parentStructure, dtype, refv, varElem)
        .ifPresent(parentStructure::addMemberVariable);
  }
}
 
Example 10
Source File: CdmDirect.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected TableConfig getStationConfig(NetcdfDataset ds, Formatter errlog) {
  // find lat coord
  Variable lat = CoordSysEvaluator.findCoordByType(ds, AxisType.Lat);
  if (lat == null) {
    errlog.format("CdmDirect: Must have a Latitude coordinate%n");
    return null;
  }

  // find lon coord
  Variable lon = CoordSysEvaluator.findCoordByType(ds, AxisType.Lon);
  if (lon == null) {
    errlog.format("CdmDirect: Must have a Longitude coordinate%n");
    return null;
  }

  if (lat.getRank() != lon.getRank()) {
    errlog.format("CdmDirect: Lat and Lon coordinate must have same rank");
    return null;
  }

  // should be a top level struct or sequence
  TableConfig stnTable = new TableConfig(Table.Type.Structure, "station");
  stnTable.featureType = FeatureType.STATION;
  stnTable.structureType = TableConfig.StructureType.Structure;

  stnTable.lat = lat.getShortName();
  stnTable.lon = lon.getShortName();

  // optional alt coord
  Variable alt = CoordSysEvaluator.findCoordByType(ds, AxisType.Height);
  if (alt != null)
    stnTable.stnAlt = alt.getShortName();

  // station id
  stnTable.stnId = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.CF_ROLE, CF.STATION_ID);
  if (stnTable.stnId == null)
    stnTable.stnId = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.STANDARD_NAME, CF.STATION_ID); // old way
  if (stnTable.stnId == null) {
    errlog.format("Must have a Station id variable with standard name station_id%n");
    return null;
  }

  // other station
  stnTable.stnDesc = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.STANDARD_NAME, CF.PLATFORM_NAME);
  if (stnTable.stnDesc == null)
    stnTable.stnDesc = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.STANDARD_NAME, CF.STATION_DESC);
  stnTable.stnWmoId = Evaluator.findNameOfVariableWithAttributeValue(ds, CF.STANDARD_NAME, CF.STATION_WMOID);

  // obs table
  Structure stnv = (Structure) ds.findVariable("station");
  Structure obsv = null;
  for (Variable v : stnv.getVariables()) {
    if (v.getDataType() == DataType.SEQUENCE)
      obsv = (Structure) v;
  }
  if (obsv == null) {
    errlog.format("Must have a SEQUENCE variable%n");
    return null;
  }
  TableConfig obs = new TableConfig(Table.Type.NestedStructure, obsv.getFullName());
  obs.nestedTableName = obsv.getShortName();
  obs.time = CoordSysEvaluator.findCoordShortNameByType(ds, AxisType.Time);
  if (obs.time == null) {
    errlog.format("Must have a time coordinate%n");
    return null;
  }
  stnTable.addChild(obs);

  return stnTable;
}