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

The following examples show how to use ucar.nc2.dataset.NetcdfDataset#findAttValueIgnoreCase() . 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: OldUnidataStationObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public OldUnidataStationObsDataset(NetcdfDataset ds) throws IOException {
  super(ds);
  this.dataset = ds;

  String ncmlURL = null;

  String kind = ds.findAttValueIgnoreCase(null, "title", null);
  if ("METAR definition".equals(kind)) {
    Variable v = ds.findVariable("station");
    if (v != null)
      ncmlURL = CoordSysBuilder.resourcesDir + "metar2ncMetar.ncml";
    else // older form
      ncmlURL = CoordSysBuilder.resourcesDir + "metar2ncMetar2.ncml";

  } else if ("SYNOPTIC definition".equals(kind)) {
    ncmlURL = CoordSysBuilder.resourcesDir + "metar2ncSynoptic.ncml";

  } else if ("BUOY definition".equals(kind)) {
    ncmlURL = CoordSysBuilder.resourcesDir + "metar2ncBuoy.ncml";
  }

  if (ncmlURL == null)
    throw new IOException("unknown StationObsDataset type " + ds.getLocation());

  init(ncmlURL);
}
 
Example 2
Source File: Suomi.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) {
  String start_date = ds.findAttValueIgnoreCase(null, "start_date", null);
  if (start_date == null)
    return;

  SimpleDateFormat df = new SimpleDateFormat("yyyy.DDD.HH.mm.ss"); // "2006.105.00.00.00"
  DateFormatter dfo = new DateFormatter();

  Date start;
  try {
    start = df.parse(start_date);
  } catch (ParseException e) {
    throw new RuntimeException("Cant read start_date=" + start_date);
  }

  Variable v = ds.findVariable("time_offset");
  v.addAttribute(new Attribute(CDM.UNITS, "seconds since " + dfo.toDateTimeString(start)));

  Group root = ds.getRootGroup();
  root.addAttribute(new Attribute(CDM.CONVENTIONS, "Suomi-Station-CDM"));
  ds.finish();
}
 
Example 3
Source File: UnidataObsConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean hasAxisType(NetcdfDataset ds, AxisType a) {
  List<Variable> varList = ds.getVariables();
  for (Variable v : varList) {
    String axisType = ds.findAttValueIgnoreCase(v, "CoordinateAxisType", null);
    if ((axisType != null) && axisType.equals(a.toString()))
      return true;
  }
  return false;
}
 
Example 4
Source File: NdbcDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public NdbcDataset(NetcdfDataset ds) throws IOException {
  super(ds);

  recordHelper = new RecordDatasetHelper(ds, "time", null, dataVariables);
  removeDataVariable("time");
  timeUnit = recordHelper.timeUnit;

  Variable latVar = ds.findVariable("lat");
  double lat = latVar.readScalarDouble();
  Variable lonVar = ds.findVariable("lon");
  double lon = lonVar.readScalarDouble();

  // LOOK assume its time ordered
  Variable dateVar = ds.findVariable("time");
  dates = (ArrayInt.D1) dateVar.read();
  int count = (int) dates.getSize();
  int firstDate = dates.get(0);
  int lastDate = dates.get(count - 1);

  startDate = timeUnit.makeDate((double) firstDate);
  endDate = timeUnit.makeDate((double) lastDate);

  String name = ds.findAttValueIgnoreCase(null, "station", null);
  String stationDesc = ds.findAttValueIgnoreCase(null, "description", null);

  // only one station in the file
  station = new StationImpl(name, stationDesc, lat, lon, Double.NaN, count);
  stations.add(station);

  // typed dataset fields
  title = ds.findAttValueIgnoreCase(null, "data_provider", null) + " Station " + name;
  desc = title + "\n" + ds.findAttValueIgnoreCase(null, "data_quality", null);

  setBoundingBox();
}
 
Example 5
Source File: IFPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {
  if (null != ds.findVariable("xCoord"))
    return; // check if its already been done - aggregating enhanced datasets.

  parseInfo.format("IFPS augmentDataset %n");

  // Figure out projection info. Assume the same for all variables
  VariableDS lonVar = (VariableDS) ds.findVariable("longitude");
  lonVar.setUnitsString(CDM.LON_UNITS);
  lonVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lon.toString()));
  VariableDS latVar = (VariableDS) ds.findVariable("latitude");
  latVar.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Lat.toString()));
  latVar.setUnitsString(CDM.LAT_UNITS);

  projVar = latVar;
  String projName = ds.findAttValueIgnoreCase(projVar, "projectionType", null);
  if ("LAMBERT_CONFORMAL".equals(projName)) {
    Projection proj = makeLCProjection(ds);
    makeXYcoords(ds, proj, latVar, lonVar);
  }

  // figure out the time coordinate for each data variable
  // LOOK : always seperate; could try to discover if they are the same
  List<Variable> vars = ds.getVariables();
  for (Variable ncvar : vars) {
    // variables that are used but not displayable or have no data have DIM_0, also don't want history, since those
    // are just how the person edited the grids
    if ((!ncvar.getDimension(0).getShortName().equals("DIM_0")) && !ncvar.getShortName().endsWith("History")
        && (ncvar.getRank() > 2) && !ncvar.getShortName().startsWith("Tool")) {
      createTimeCoordinate(ds, ncvar);
    } else if (ncvar.getShortName().equals("Topo")) {
      // Deal with Topography variable
      ncvar.addAttribute(new Attribute(CDM.LONG_NAME, "Topography"));
      ncvar.addAttribute(new Attribute(CDM.UNITS, "ft"));
    }
  }

  ds.finish();
}
 
Example 6
Source File: SequenceObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Variable findVariable(NetcdfDataset ds, String name) {
  Variable result = ds.findVariable(name);
  if (result == null) {
    String aname = ds.findAttValueIgnoreCase(null, name + "_variable", null);
    if (aname == null)
      aname = ds.findAttValueIgnoreCase(null, name, null);
    if (aname != null)
      result = ds.findVariable(aname);
  }

  return result;
}
 
Example 7
Source File: SequenceObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Dimension findDimension(NetcdfDataset ds, String name) {
  Dimension result = ds.findDimension(name);
  if (result == null) {
    String aname = ds.findAttValueIgnoreCase(null, name + "Dimension", null);
    if (aname != null)
      result = ds.findDimension(aname);
  }
  return result;
}
 
Example 8
Source File: TypedDatasetImpl.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Construtor when theres a NetcdfFile underneath
 * 
 * @param netcdfDataset adapt this NetcdfDataset
 */
public TypedDatasetImpl(NetcdfDataset netcdfDataset) {
  this.netcdfDataset = netcdfDataset;
  this.location = netcdfDataset.getLocation();

  this.title = netcdfDataset.getTitle();
  if (title == null)
    title = netcdfDataset.findAttValueIgnoreCase(null, "title", null);
  if (desc == null)
    desc = netcdfDataset.findAttValueIgnoreCase(null, "description", null);
}
 
Example 9
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CoordinateAxis makeTimeCoordAxisFromReference(NetcdfDataset ds, Variable timeVar, Array vals) {
  Variable refVar = ds.findVariable("reftime");
  if (refVar == null)
    return null;
  double refValue;
  try {
    Array refArray = refVar.read();
    refValue = refArray.getDouble(refArray.getIndex()); // get the first value
  } catch (IOException ioe) {
    return null;
  }
  if (refValue == N3iosp.NC_FILL_DOUBLE)
    return null;

  // construct the values array - make it a double to be safe
  Array dvals = Array.factory(DataType.DOUBLE, vals.getShape());
  IndexIterator diter = dvals.getIndexIterator();
  IndexIterator iiter = vals.getIndexIterator();
  while (iiter.hasNext())
    diter.setDoubleNext(iiter.getDoubleNext() + refValue); // add reftime to each of the values

  String units = ds.findAttValueIgnoreCase(refVar, CDM.UNITS, "seconds since 1970-1-1 00:00:00");
  units = normalize(units);
  String desc = "synthesized time coordinate from reftime, valtimeMINUSreftime";
  CoordinateAxis1D timeCoord = new CoordinateAxis1D(ds, null, "timeCoord", DataType.DOUBLE, "record", units, desc);

  timeCoord.setCachedData(dvals, true);

  parseInfo.format("Created Time Coordinate Axis From Reference = ");
  timeCoord.getNameAndDimensions(parseInfo, true, false);
  parseInfo.format("%n");

  return timeCoord;
}
 
Example 10
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 11
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String getZisPositive(NetcdfDataset ds, CoordinateAxis v) {

    String attValue = ds.findAttValueIgnoreCase(v, "positive", null);
    if (null != attValue)
      return attValue.equalsIgnoreCase("up") ? "up" : "down";

    String unit = v.getUnitsString();
    if ((unit != null) && SimpleUnit.isCompatible("millibar", unit))
      return "down";
    if ((unit != null) && SimpleUnit.isCompatible("m", unit))
      return "up";

    // dunno
    return null;
  }
 
Example 12
Source File: CFstationObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public CFstationObsDataset(NetcdfDataset ds) throws IOException {
  super(ds);

  // coordinate variables
  latVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Lat);
  lonVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Lon);
  altVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Height);
  timeVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Time);

  if (latVar == null)
    throw new IllegalStateException("Missing latitude variable");
  if (lonVar == null)
    throw new IllegalStateException("Missing longitude coordinate variable");
  if (timeVar == null)
    throw new IllegalStateException("Missing time coordinate variable");

  // variables that link the structures together
  lastVar = UnidataObsDatasetHelper.findVariable(ds, "lastChild");
  prevVar = UnidataObsDatasetHelper.findVariable(ds, "prevChild");
  firstVar = UnidataObsDatasetHelper.findVariable(ds, "firstChild");
  nextVar = UnidataObsDatasetHelper.findVariable(ds, "nextChild");
  numChildrenVar = UnidataObsDatasetHelper.findVariable(ds, "numChildren");
  stationIndexVar = UnidataObsDatasetHelper.findVariable(ds, "parent_index");

  if (stationIndexVar == null)
    throw new IllegalStateException("Missing parent_index variable");

  hasForwardLinkedList = (firstVar != null) && (nextVar != null);
  hasBackwardLinkedList = (lastVar != null) && (prevVar != null);
  hasContiguousList = (firstVar != null) && (numChildrenVar != null); // ??

  // station variables
  stationIdVar = UnidataObsDatasetHelper.findVariable(ds, "station_id");
  stationDescVar = UnidataObsDatasetHelper.findVariable(ds, "station_description");
  numStationsVar = UnidataObsDatasetHelper.findVariable(ds, "number_stations");

  if (stationIdVar == null)
    throw new IllegalStateException("Missing station id variable");

  // fire up the record helper - LOOK assumes its the record dimension
  recordHelper = new RecordDatasetHelper(ds, timeVar.getShortName(), null, dataVariables, parseInfo);
  recordHelper.setStationInfo(stationIndexVar.getShortName(),
      stationDescVar == null ? null : stationDescVar.getShortName());

  removeDataVariable(stationIndexVar.getShortName());
  removeDataVariable(timeVar.getShortName());
  if (prevVar != null)
    removeDataVariable(prevVar.getShortName());
  if (nextVar != null)
    removeDataVariable(nextVar.getShortName());

  recordVar = recordHelper.recordVar;
  timeUnit = recordHelper.timeUnit;

  title = ds.findAttValueIgnoreCase(null, "title", "");
  desc = ds.findAttValueIgnoreCase(null, "description", "");

  readStationTable();
}
 
Example 13
Source File: Nimbus.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {
  ds.addAttribute(null, new Attribute("cdm_data_type", ucar.nc2.constants.FeatureType.TRAJECTORY.name())); // deprecated
  ds.addAttribute(null, new Attribute(CF.FEATURE_TYPE, ucar.nc2.constants.FeatureType.TRAJECTORY.name()));

  if (!setAxisType(ds, "LATC", AxisType.Lat))
    if (!setAxisType(ds, "LAT", AxisType.Lat))
      setAxisType(ds, "GGLAT", AxisType.Lat);

  if (!setAxisType(ds, "LONC", AxisType.Lon))
    if (!setAxisType(ds, "LON", AxisType.Lon))
      setAxisType(ds, "GGLON", AxisType.Lon);

  if (!setAxisType(ds, "PALT", AxisType.Height))
    setAxisType(ds, "GGALT", AxisType.Height);

  boolean hasTime = setAxisType(ds, "Time", AxisType.Time);
  if (!hasTime)
    hasTime = setAxisType(ds, "time", AxisType.Time);

  // do we need to version this ?
  // String version = ds.findAttValueIgnoreCase(null, "version", null);

  if (!hasTime) {
    Variable time = ds.findVariable("time_offset");
    if (time != null) {
      Variable base = ds.findVariable("base_time");
      int base_time = base.readScalarInt();
      try {
        DateUnit dunit = new DateUnit("seconds since 1970-01-01 00:00");
        String time_units = "seconds since " + dunit.makeStandardDateString(base_time);
        time.addAttribute(new Attribute(CDM.UNITS, time_units));
        time.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.name()));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  // look for coordinates
  String coordinates = ds.findAttValueIgnoreCase(null, "coordinates", null);
  if (coordinates != null) {
    String[] vars = coordinates.split(" ");
    for (String vname : vars) {
      Variable v = ds.findVariable(vname);
      if (v != null) {
        AxisType atype = getAxisType(ds, (VariableEnhanced) v);
        if (atype != null)
          v.addAttribute(new Attribute(_Coordinate.AxisType, atype.name()));
      }
    }
  }

}
 
Example 14
Source File: RecordDatasetHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Constructor.
 *
 * @param ncfile the netccdf file
 * @param typedDataVariables list of data variables; all record variables will be added to this list, except . You
 *        can remove extra
 * @param obsTimeVName observation time variable name (required)
 * @param nomTimeVName nominal time variable name (may be null)
 * @throws IllegalArgumentException if ncfile has no unlimited dimension and recDimName is null.
 */
public RecordDatasetHelper(NetcdfDataset ncfile, String obsTimeVName, String nomTimeVName,
    List<VariableSimpleIF> typedDataVariables, String recDimName, Formatter errBuffer) {
  this.ncfile = ncfile;
  this.obsTimeVName = obsTimeVName;
  this.nomTimeVName = nomTimeVName;
  this.errs = errBuffer;

  // check if we already have a structure vs if we have to add it.

  if (this.ncfile.hasUnlimitedDimension()) {
    this.ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);
    this.recordVar = (StructureDS) this.ncfile.getRootGroup().findVariableLocal("record");
    this.obsDim = ncfile.getUnlimitedDimension();

  } else {
    if (recDimName == null)
      throw new IllegalArgumentException("File <" + this.ncfile.getLocation()
          + "> has no unlimited dimension, specify psuedo record dimension with observationDimension global attribute.");
    this.obsDim = this.ncfile.getRootGroup().findDimension(recDimName);
    this.recordVar = new StructurePseudoDS(this.ncfile, null, "record", null, obsDim);
  }

  // create member variables
  List<Variable> recordMembers = ncfile.getVariables();
  for (Variable v : recordMembers) {
    if (v == recordVar)
      continue;
    if (v.isScalar())
      continue;
    if (v.getDimension(0) == this.obsDim)
      typedDataVariables.add(v);
  }

  // need the time units
  Variable timeVar = ncfile.findVariable(obsTimeVName);
  String timeUnitString = ncfile.findAttValueIgnoreCase(timeVar, CDM.UNITS, "seconds since 1970-01-01");
  Calendar cal = TimeHelper.getCalendarFromAttribute(timeVar);

  try {
    timeUnit = CalendarDateUnit.withCalendar(cal, timeUnitString);

  } catch (Exception e) {
    if (null != errs)
      errs.format("Error on string = %s == %s%n", timeUnitString, e.getMessage());
    timeUnit = CalendarDateUnit.unixDateUnit;
  }
}
 
Example 15
Source File: MadisPointObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public MadisPointObsDataset(NetcdfDataset ds) throws IOException {
  super(ds);

  // dork around with the variable names
  altVName = "elevation";

  String timeNames = ds.findAttValueIgnoreCase(null, "timeVariables", null);
  StringTokenizer stoker = new StringTokenizer(timeNames, ", ");
  obsTimeVName = stoker.nextToken();

  if (ds.findVariable("timeNominal") != null)
    nomTimeVName = "timeNominal";

  String idNames = ds.findAttValueIgnoreCase(null, "idVariables", null);
  stoker = new StringTokenizer(idNames, ", ");
  stnIdVName = stoker.nextToken();

  if (stnIdVName.equals("stationName")) { // metars, sao, maritime
    if (ds.findVariable("locationName") != null)
      stnDescVName = "locationName";
    if (debug)
      System.out.println("filetype 1 (metars)");

  } else if (stnIdVName.equals("latitude")) { // acars LOOK this is not station - move to trajectory !!
    if (ds.findVariable("en_tailNumber") != null)
      stnIdVName = "en_tailNumber";
    altVName = "altitude";
    if (debug)
      System.out.println("filetype 3 (acars)");

  } else { // coop, hydro, mesonet, radiometer
    if (ds.findVariable("stationId") != null)
      stnIdVName = "stationId";
    if (ds.findVariable("stationName") != null)
      stnDescVName = "stationName";
    if (debug)
      System.out.println("filetype 2 (mesonet)");
  }
  if (debug)
    System.out.println("title= " + netcdfDataset.findAttValueIgnoreCase(null, "title", null));

  recordHelper = new RecordDatasetHelper(ds, obsTimeVName, nomTimeVName, dataVariables, parseInfo);
  removeDataVariable("prevRecord");

  timeUnit = recordHelper.timeUnit;

  // construct the stations
  Variable lastRecordVar = ds.findVariable("lastRecord");
  ArrayInt.D1 lastRecord = (ArrayInt.D1) lastRecordVar.read();

  Variable inventoryVar = ds.findVariable("inventory");
  ArrayInt.D1 inventoryData = (ArrayInt.D1) inventoryVar.read();

  Variable v = ds.findVariable("nStaticIds");
  int n = v.readScalarInt();

  recordHelper.stnHash = new HashMap(2 * n);
  recordVar = (Structure) ds.findVariable("record");
  for (int stnIndex = 0; stnIndex < n; stnIndex++) {
    int lastValue = lastRecord.get(stnIndex);
    int inventory = inventoryData.get(stnIndex);

    if (lastValue < 0)
      continue;

    // get an obs record for this, and extract the station info
    StructureData sdata = null;
    try {
      sdata = recordVar.readStructure(lastValue);
    } catch (InvalidRangeException e) {
      parseInfo.append("Invalid lastValue=" + lastValue + " for station at index " + stnIndex + "\n");
      continue;
    }

    String stationId = sdata.getScalarString(stnIdVName).trim();
    String stationDesc = (stnDescVName == null) ? null : sdata.getScalarString(stnDescVName);
  }
  // if (debug) System.out.println("total stations " + stations.size()+" should be = "+n);

  // get min, max date
  Variable timeVar = ds.findVariable(obsTimeVName);
  Array timeData = timeVar.read();
  MAMath.MinMax minmax = MAMath.getMinMax(timeData);

  startDate = timeUnit.makeDate(minmax.min);
  endDate = timeUnit.makeDate(minmax.max);

  setBoundingBox();
}
 
Example 16
Source File: UnidataStationObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public UnidataStationObsDataset(NetcdfDataset ds) throws IOException {
  super(ds);

  // coordinate variables
  latVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Lat);
  lonVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Lon);
  altVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Height);
  timeVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Time);

  if (latVar == null)
    throw new IllegalStateException("Missing latitude variable");
  if (lonVar == null)
    throw new IllegalStateException("Missing longitude coordinate variable");
  if (timeVar == null)
    throw new IllegalStateException("Missing time coordinate variable");

  // variables that link the structures together
  timeNominalVar = UnidataObsDatasetHelper.findVariable(ds, "time_nominal");
  lastVar = UnidataObsDatasetHelper.findVariable(ds, "lastChild");
  prevVar = UnidataObsDatasetHelper.findVariable(ds, "prevChild");
  firstVar = UnidataObsDatasetHelper.findVariable(ds, "firstChild");
  nextVar = UnidataObsDatasetHelper.findVariable(ds, "nextChild");
  numChildrenVar = UnidataObsDatasetHelper.findVariable(ds, "numChildren");
  stationIndexVar = UnidataObsDatasetHelper.findVariable(ds, "parent_index");

  isForwardLinkedList = (firstVar != null) && (nextVar != null);
  isBackwardLinkedList = (lastVar != null) && (prevVar != null);
  isContiguousList = !isForwardLinkedList && !isBackwardLinkedList && (firstVar != null) && (numChildrenVar != null);

  if (!isForwardLinkedList && !isBackwardLinkedList && !isContiguousList) {
    if (firstVar != null)
      throw new IllegalStateException("Missing nextVar (linked list) or numChildrenVar (contiguous list) variable");
    if (lastVar != null)
      throw new IllegalStateException("Missing prevVar (linked list) variable");
    if (nextVar != null)
      throw new IllegalStateException("Missing firstVar (linked list) variable");
    if (prevVar != null)
      throw new IllegalStateException("Missing lastVar (linked list) variable");
  }

  // station variables
  stationIdVar = UnidataObsDatasetHelper.findVariable(ds, "station_id");
  stationDescVar = UnidataObsDatasetHelper.findVariable(ds, "station_description");
  numStationsVar = UnidataObsDatasetHelper.findVariable(ds, "number_stations");

  if (stationIdVar == null)
    throw new IllegalStateException("Missing station id variable");

  // fire up the record helper - LOOK assumes its the record dimension
  recordHelper = new RecordDatasetHelper(ds, timeVar.getShortName(),
      timeNominalVar == null ? null : timeNominalVar.getShortName(), dataVariables, parseInfo);
  recordHelper.setStationInfo(stationIndexVar.getShortName(),
      stationDescVar == null ? null : stationDescVar.getShortName());

  removeDataVariable(stationIndexVar.getShortName());
  removeDataVariable(timeVar.getShortName());
  if (timeNominalVar != null)
    removeDataVariable(timeNominalVar.getShortName());
  if (prevVar != null)
    removeDataVariable(prevVar.getShortName());
  if (nextVar != null)
    removeDataVariable(nextVar.getShortName());

  recordVar = recordHelper.recordVar;
  timeUnit = recordHelper.timeUnit;

  readStations(); // LOOK try to defer this

  // get min, max date
  startDate = UnidataObsDatasetHelper.getStartDate(ds);
  endDate = UnidataObsDatasetHelper.getEndDate(ds);
  boundingBox = UnidataObsDatasetHelper.getBoundingBox(ds);
  if (null == boundingBox)
    setBoundingBox();

  // kludge Robb not following spec
  if (null == startDate) {
    Variable minTimeVar = ds.findVariable("minimum_time_observation");
    int minTimeValue = minTimeVar.readScalarInt();
    startDate = timeUnit.makeDate(minTimeValue);
  }

  if (null == endDate) {
    Variable maxTimeVar = ds.findVariable("maximum_time_observation");
    int maxTimeValue = maxTimeVar.readScalarInt();
    endDate = timeUnit.makeDate(maxTimeValue);
  }

  title = ds.findAttValueIgnoreCase(null, "title", "");
  desc = ds.findAttValueIgnoreCase(null, "description", "");
}
 
Example 17
Source File: SequenceObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SequenceObsDataset(NetcdfDataset ds, CancelTask task) throws IOException {
  super(ds);

  // identify key variables
  sequenceVar = (Structure) findVariable(ds, "obs_sequence");
  latVar = findVariable(ds, "latitude_coordinate");
  lonVar = findVariable(ds, "longitude_coordinate");
  altVar = findVariable(ds, "zaxis_coordinate");
  timeVar = findVariable(ds, "time_coordinate");

  if (latVar == null) {
    parseInfo.append("Missing latitude variable");
    fatal = true;
  }
  if (lonVar == null) {
    parseInfo.append("Missing longitude variable");
    fatal = true;
  }
  if (altVar == null) {
    parseInfo.append("Missing altitude variable");
  }
  if (timeVar == null) {
    parseInfo.append("Missing time variable");
    fatal = true;
  }

  // variables that link the structures together
  timeNominalVar = findVariable(ds, "time_nominal");

  // station variables
  stationIdVar = findVariable(ds, "station_id");
  stationDescVar = findVariable(ds, "station_description");
  numStationsVar = findVariable(ds, "number_stations");

  if (stationIdVar == null) {
    parseInfo.append("Missing station id variable");
    fatal = true;
  }

  /*
   * sequenceHelper = new SequenceHelper(ds, sequenceVar, latVar, lonVar, altVar, timeVar, timeNominalVar,
   * dataVariables, parseInfo);
   * sequenceHelper.setStationInfo( stationIdVar, stationDescVar);
   * 
   * //removeDataVariable(timeVar.getName());
   * timeUnit = sequenceHelper.timeUnit;
   * 
   * stations = sequenceHelper.readStations( cancel);
   * setBoundingBox();
   * 
   * startDate = sequenceHelper.minDate;
   * endDate = sequenceHelper.maxDate;
   */

  /*
   * Variable minTimeVar = ds.findVariable("minimum_time_observation");
   * int minTimeValue = minTimeVar.readScalarInt();
   * startDate = timeUnit.makeDate( minTimeValue);
   * 
   * Variable maxTimeVar = ds.findVariable("maximum_time_observation");
   * int maxTimeValue = maxTimeVar.readScalarInt();
   * endDate = timeUnit.makeDate( maxTimeValue);
   */

  title = ds.findAttValueIgnoreCase(null, "title", "");
  desc = ds.findAttValueIgnoreCase(null, "description", "");
}
 
Example 18
Source File: UnidataStationObsMultidimDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public UnidataStationObsMultidimDataset(NetcdfDataset ds) throws IOException {
  super(ds);

  stationDim = UnidataObsDatasetHelper.findDimension(ds, "station");
  obsDim = UnidataObsDatasetHelper.findDimension(ds, "observation");
  if (obsDim == null)
    obsDim = ds.getUnlimitedDimension();
  if (obsDim == null)
    throw new IllegalStateException("must specify the observation dimension or use unlimited dimension");

  // coordinate variables
  latVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Lat);
  lonVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Lon);
  altVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Height);
  timeVar = UnidataObsDatasetHelper.getCoordinate(ds, AxisType.Time);
  timeNominalVar = UnidataObsDatasetHelper.findVariable(ds, "time_nominal");

  if (latVar == null)
    throw new IllegalStateException("Missing latitude variable");
  if (lonVar == null)
    throw new IllegalStateException("Missing longitude coordinate variable");
  if (timeVar == null)
    throw new IllegalStateException("Missing time coordinate variable");

  if (!latVar.getDimension(0).equals(stationDim))
    throw new IllegalStateException("latitude variable must use the station dimension");
  if (!lonVar.getDimension(0).equals(stationDim))
    throw new IllegalStateException("longitude variable must use the station dimension");
  if (!timeVar.getDimension(0).equals(stationDim))
    throw new IllegalStateException("time variable must use the station dimension");
  if ((altVar != null) && !altVar.getDimension(0).equals(stationDim))
    throw new IllegalStateException("altitude variable must use the station dimension");
  if ((timeNominalVar != null) && !timeNominalVar.getDimension(0).equals(stationDim))
    throw new IllegalStateException("timeNominal variable must use the station dimension");

  // station variables
  stationIdVar = UnidataObsDatasetHelper.findVariable(ds, "station_id");
  stationDescVar = UnidataObsDatasetHelper.findVariable(ds, "station_description");
  numStationsVar = UnidataObsDatasetHelper.findVariable(ds, "number_stations");

  if (stationIdVar == null)
    throw new IllegalStateException("Missing station id variable");
  if (!stationIdVar.getDimension(0).equals(stationDim))
    throw new IllegalStateException("stationId variable must use the station dimension");

  if ((stationDescVar != null) && !stationDescVar.getDimension(0).equals(stationDim))
    throw new IllegalStateException("stationDesc variable must use the station dimension");

  // create member variables
  structureMembers = new StructureMembers("UnidataStationObsMultidimDataset_obsStructure");
  for (Variable v : netcdfDataset.getVariables()) {
    if (v.getRank() < 2)
      continue;
    if (v.getDimension(0).equals(this.stationDim) && v.getDimension(1).equals(this.obsDim)) {
      dataVariables.add(v);
      int[] shape = v.getShape();
      shape[0] = 1;
      shape[1] = 1;
      structureMembers.addMember(v.getShortName(), v.getDescription(), v.getUnitsString(), v.getDataType(), shape);
    }
  }

  readStations(); // LOOK try to defer this

  // get min, max date
  startDate = UnidataObsDatasetHelper.getStartDate(ds);
  endDate = UnidataObsDatasetHelper.getEndDate(ds);
  boundingBox = UnidataObsDatasetHelper.getBoundingBox(ds);
  if (null == boundingBox)
    setBoundingBox();

  setTimeUnits();

  title = ds.findAttValueIgnoreCase(null, "title", "");
  desc = ds.findAttValueIgnoreCase(null, "description", "");
}