public Float10TrajectoryObsDataset(NetcdfDataset ncd) throws IOException {
    super(ncd);

    // Get the names of the two coordinate variables and dimensions
    // and grab the variables and dimensions themselves.
    trajDimName = trajDimNameDefault;
    trajVarName = trajVarNameDefault;
    timeDimName = timeDimNameDefault;
    timeVarName = timeVarNameDefault;

    latVarName = latVarNameDefault;
    lonVarName = lonVarNameDefault;
    elevVarName = elevVarNameDefault;

    Variable latVar = ncd.getRootGroup().findVariable(latVarName);
    latVar.addAttribute(new Attribute("units", "degrees_north"));

    Variable lonVar = ncd.getRootGroup().findVariable(lonVarName);
    lonVar.addAttribute(new Attribute("units", "degrees_east"));

    this.setTrajectoryInfo(
        netcdfDataset.getRootGroup().findDimension(trajDimName),
        netcdfDataset.getRootGroup().findVariable(trajVarName),
        netcdfDataset.getRootGroup().findDimension(timeDimName),
        netcdfDataset.getRootGroup().findVariable(timeVarName),
        netcdfDataset.getRootGroup().findVariable(latVarName),
        netcdfDataset.getRootGroup().findVariable(lonVarName),
        netcdfDataset.getRootGroup().findVariable(elevVarName));
  }
  public UnidataTrajectoryObsDataset(NetcdfDataset ncd) throws IOException {
    super(ncd);

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

    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 (elevVar == null) throw new IllegalStateException("Missing height coordinate variable");

    timeDimName = timeVar.getDimension(0).getName();
    timeVarName = timeVar.getShortName();
    latVarName = latVar.getShortName();
    lonVarName = lonVar.getShortName();
    elevVarName = elevVar.getShortName();

    Config trajConfig =
        new Config(
            "1Hz data",
            ncd.getRootGroup().findDimension(timeDimName),
            ncd.getRootGroup().findVariable(timeVarName),
            ncd.getRootGroup().findVariable(latVarName),
            ncd.getRootGroup().findVariable(lonVarName),
            ncd.getRootGroup().findVariable(elevVarName));
    this.setTrajectoryInfo(trajConfig);
  }
  /**
   * Build the configuration from the dataset
   *
   * @param ncd NetcdfDataset
   * @return the trajectory configuration
   */
  private static Config buildConfig(NetcdfDataset ncd) {

    // already did this in isValid, but we'll keep here for later refactor
    Attribute attrib = ncd.findGlobalAttributeIgnoreCase("center");
    if (attrib == null) {
      return null;
    }
    if (!attrib.isString()) {
      return null;
    }
    if (!attrib.getStringValue().equals("UCAR/CDAAC")) {
      return null;
    }

    // Check for start_time, stop_time
    attrib = ncd.findGlobalAttributeIgnoreCase("start_time");
    if (attrib == null) {
      return null;
    }
    if (attrib.isString()) {
      return null;
    }
    double startTime = attrib.getNumericValue().doubleValue();
    attrib = ncd.findGlobalAttributeIgnoreCase("stop_time");
    if (attrib == null) {
      return null;
    }
    if (attrib.isString()) {
      return null;
    }
    double endTime = attrib.getNumericValue().doubleValue();

    // Check that only one dimension and that it is the alt dimension.
    List list = ncd.getRootGroup().getDimensions();
    if (list.size() != 1) {
      return null;
    }
    Dimension d = (Dimension) list.get(0);
    if (!d.getName().equals(timeDimName)) {
      return null;
    }

    Config trajConfig = new Config();
    trajConfig.setTimeDim(d);

    // Check for latitude variable with time dimension and units convertable to "degrees_north".
    Variable var = ncd.getRootGroup().findVariable(latVarName);
    if (var == null) {
      return null;
    }
    list = var.getDimensions();
    if (list.size() != 1) {
      return null;
    }
    d = (Dimension) list.get(0);
    if (!d.getName().equals(timeDimName)) {
      return null;
    }
    String units = var.findAttribute("units").getStringValue();
    if (!SimpleUnit.isCompatible(units, "degrees_north")) {
      return null;
    }

    trajConfig.setLatVar(var);

    // Make the time Variable
    int numTimes = d.getLength();
    double[] times = new double[numTimes];
    // Variable timeVar = new Variable(var);
    // timeVar.setName(timeVarName);
    VariableDS timeVar =
        new VariableDS(
            ncd,
            ncd.getRootGroup(),
            null,
            timeVarName,
            DataType.DOUBLE,
            timeDimName,
            "seconds since 1980-01-06 00:00:00",
            "Time coordinate");
    // Variable timeVar = new Variable(ncd, ncd.getRootGroup(), null,
    //                              timeVarName);
    // timeVar.setDataType(DataType.DOUBLE);
    // timeVar.setDimensions(list);
    // Attribute newUnits =
    //    new Attribute("units", "seconds since 1980-01-06 00:00:00");
    // timeVar.addAttribute(newUnits);
    timeVar.setCachedData(
        Array.makeArray(DataType.DOUBLE, numTimes, endTime, ((startTime - endTime) / numTimes)),
        true);
    ncd.addVariable(ncd.getRootGroup(), timeVar);
    trajConfig.setTimeVar(timeVar);

    // Check for longitude variable with time dimension and units convertable to "degrees_east".
    var = ncd.getRootGroup().findVariable(lonVarName);
    if (var == null) {
      return null;
    }
    list = var.getDimensions();
    if (list.size() != 1) {
      return null;
    }
    d = (Dimension) list.get(0);
    if (!d.getName().equals(timeDimName)) {
      return null;
    }
    units = var.findAttribute("units").getStringValue();
    if (!SimpleUnit.isCompatible(units, "degrees_east")) {
      return null;
    }

    trajConfig.setLonVar(var);

    // Check for altitude variable with time dimension and units convertable to "m".
    var = ncd.getRootGroup().findVariable(elevVarName);
    if (var == null) {
      return null;
    }
    list = var.getDimensions();
    if (list.size() != 1) {
      return null;
    }
    d = (Dimension) list.get(0);
    if (!d.getName().equals(timeDimName)) {
      return null;
    }
    units = var.findAttribute("units").getStringValue();
    if (!SimpleUnit.isCompatible(units, "meters")) {
      return null;
    }

    trajConfig.setElevVar(var);

    trajConfig.setTrajectoryId(trajId);

    return trajConfig;
  }
  public static boolean isValidFile(NetcdfDataset ds) {
    // Check that has a time dimension and a trajectory dimension.
    List list = ds.getRootGroup().getDimensions();
    if (list.size() != 2) return (false);
    Dimension d;
    for (int i = 0; i < 2; i++) {
      d = (Dimension) list.get(i);
      if (!d.getShortName().equals(timeDimNameDefault)
          && !d.getShortName().equals(trajDimNameDefault)) return (false);
    }

    // Check that has a trajectory coordinate variable.
    Variable var = ds.getRootGroup().findVariable(trajVarNameDefault);
    if (var == null) return (false);
    list = var.getDimensions();
    if (list.size() != 1) return (false);
    d = (Dimension) list.get(0);
    if (!d.getShortName().equals(trajDimNameDefault)) return (false);

    // Check that has a time coordinate variable with units that are udunits time
    var = ds.getRootGroup().findVariable(timeVarNameDefault);
    if (var == null) return (false);
    list = var.getDimensions();
    if (list.size() != 1) return (false);
    d = (Dimension) list.get(0);
    if (!d.getShortName().equals(timeDimNameDefault)) return (false);
    String units = var.findAttribute("units").getStringValue();
    Date date = DateUnit.getStandardDate("0 " + units);
    if (date == null) return (false);

    // Check for variable latitude(time) with units of "deg".
    var = ds.getRootGroup().findVariable(latVarNameDefault);
    if (var == null) return (false);
    list = var.getDimensions();
    if (list.size() != 2) return (false);
    for (int i = 0; i < 2; i++) {
      d = (Dimension) list.get(i);
      if (!d.getShortName().equals(timeDimNameDefault)
          && !d.getShortName().equals(trajDimNameDefault)) return (false);
    }
    //    units = var.findAttribute( "units").getStringValue();
    //    if ( ! SimpleUnit.isCompatible( units, "degrees_north")) return( false);

    // Check for variable longitude(time) with units of "deg".
    var = ds.getRootGroup().findVariable(lonVarNameDefault);
    if (var == null) return (false);
    list = var.getDimensions();
    if (list.size() != 2) return (false);
    for (int i = 0; i < 2; i++) {
      d = (Dimension) list.get(i);
      if (!d.getShortName().equals(timeDimNameDefault)
          && !d.getShortName().equals(trajDimNameDefault)) return (false);
    }
    //    units = var.findAttribute( "units").getStringValue();
    //    if ( ! SimpleUnit.isCompatible( units, "degrees_east")) return( false);

    // Check for variable altitude(time) with units of "m".
    var = ds.getRootGroup().findVariable(elevVarNameDefault);
    if (var == null) return (false);
    list = var.getDimensions();
    if (list.size() != 2) return (false);
    for (int i = 0; i < 2; i++) {
      d = (Dimension) list.get(i);
      if (!d.getShortName().equals(timeDimNameDefault)
          && !d.getShortName().equals(trajDimNameDefault)) return (false);
    }
    units = var.findAttribute("units").getStringValue();
    if (!SimpleUnit.isCompatible(units, "m")) return (false);

    return (true);
  }