Example #1
0
  public boolean compareVariables(
      Variable org, Variable copy, boolean compareData, boolean justOne) {
    boolean ok = true;

    if (showCompare)
      f.format("compare Variable %s to %s %n", org.getFullName(), copy.getFullName());
    if (!org.getFullName().equals(copy.getFullName())) {
      f.format(" ** names are different %s != %s %n", org.getFullName(), copy.getFullName());
      ok = false;
    }

    // dimensions
    ok &= checkAll(org.getDimensions(), copy.getDimensions(), null);

    // attributes
    ok &= checkAll(org.getAttributes(), copy.getAttributes(), null);

    // coord sys
    if ((org instanceof VariableEnhanced) && (copy instanceof VariableEnhanced)) {
      VariableEnhanced orge = (VariableEnhanced) org;
      VariableEnhanced copye = (VariableEnhanced) copy;
      ok &= checkAll(orge.getCoordinateSystems(), copye.getCoordinateSystems(), null);
    }

    // data !!
    if (compareData) {
      try {
        compareVariableData(org, copy, showCompare, justOne);

      } catch (IOException e) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
        e.printStackTrace(new PrintStream(bos));
        f.format("%s", bos.toString());
      }
    }

    // nested variables
    if (org instanceof Structure) {
      if (!(copy instanceof Structure)) {
        f.format("  ** %s not Structure%n", org);
        ok = false;

      } else {
        Structure orgS = (Structure) org;
        Structure ncmlS = (Structure) copy;

        List vars = new ArrayList();
        ok &= checkAll(orgS.getVariables(), ncmlS.getVariables(), vars);
        for (int i = 0; i < vars.size(); i += 2) {
          Variable orgV = (Variable) vars.get(i);
          Variable ncmlV = (Variable) vars.get(i + 1);
          ok &= compareVariables(orgV, ncmlV, false, true);
        }
      }
    }

    return ok;
  }
 private String tryGrid(VariableEnhanced v) {
   Formatter buff = new Formatter();
   buff.format("%s:", v.getFullName());
   List<CoordinateSystem> csList = v.getCoordinateSystems();
   if (csList.size() == 0) buff.format(" No Coord System found");
   else {
     for (CoordinateSystem cs : csList) {
       buff.format("%s:", cs.getName());
       if (GridCoordSys.isGridCoordSys(buff, cs, v)) {
         buff.format("GRID OK%n");
       } else {
         buff.format(" NOT GRID");
       }
     }
   }
   return buff.toString();
 }
    public VariableBean(VariableEnhanced v) {
      this.ve = v;

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

      // collect dimensions
      StringBuilder lens = new StringBuilder();
      StringBuilder names = new StringBuilder();
      java.util.List dims = v.getDimensions();
      for (int j = 0; j < dims.size(); j++) {
        ucar.nc2.Dimension dim = (ucar.nc2.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());

      StringBuilder buff = new StringBuilder();
      List<CoordinateSystem> csList = v.getCoordinateSystems();
      for (CoordinateSystem cs : csList) {
        if (firstCoordSys == null) firstCoordSys = cs;
        else buff.append("; ");

        buff.append(cs.getName());

        Formatter gridBuff = new Formatter();
        if (GridCoordSys.isGridCoordSys(gridBuff, cs, v)) {
          addDataType("grid");
        } /* else if (PointDatasetDefaultHandler.isPointFeatureDataset(ds)) {
            addDataType("point");
          } */
      }
      setCoordSys(buff.toString());
    }
 public String getAbbrev() {
   Attribute att = ve.findAttributeIgnoreCase(CDM.ABBREV);
   return (att == null) ? null : att.getStringValue();
 }
 private String getCalendarAttribute(VariableEnhanced vds) {
   Attribute cal = vds.findAttribute("calendar");
   return (cal == null) ? null : cal.getStringValue();
 }
  /** create a NetcdfDataset out of this NetcdfFile, adding coordinates etc. */
  public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {

    // latitude
    if (!hasAxisType(ds, AxisType.Lat)) { // already has _CoordinateAxisType

      if (!addAxisType(ds, "latitude", AxisType.Lat)) { // directly named

        String vname = ds.findAttValueIgnoreCase(null, "latitude_coordinate", null);
        if (!addAxisType(ds, vname, AxisType.Lat)) { // attribute named

          Variable v =
              hasUnits(ds, "degrees_north,degrees_N,degreesN,degree_north,degree_N,degreeN");
          if (v != null) addAxisType(v, AxisType.Lat); // CF-1
        }
      }
    }

    // longitude
    if (!hasAxisType(ds, AxisType.Lon)) { // already has _CoordinateAxisType

      if (!addAxisType(ds, "longitude", AxisType.Lon)) { // directly named

        String vname = ds.findAttValueIgnoreCase(null, "longitude_coordinate", null);
        if (!addAxisType(ds, vname, AxisType.Lon)) { // attribute named

          Variable v = hasUnits(ds, "degrees_east,degrees_E,degreesE,degree_east,degree_E,degreeE");
          if (v != null) addAxisType(v, AxisType.Lon); // CF-1
        }
      }
    }

    // altitude
    if (!hasAxisType(ds, AxisType.Height)) { // already has _CoordinateAxisType

      if (!addAxisType(ds, "altitude", AxisType.Height)) { // directly named
        if (!addAxisType(ds, "depth", AxisType.Height)) { // directly named

          String vname = ds.findAttValueIgnoreCase(null, "altitude_coordinate", null);
          if (!addAxisType(ds, vname, AxisType.Height)) { // attribute named

            for (int i = 0; i < ds.getVariables().size(); i++) {
              VariableEnhanced ve = (VariableEnhanced) ds.getVariables().get(i);
              String positive = ds.findAttValueIgnoreCase((Variable) ve, "positive", null);
              if (positive != null) {
                addAxisType((Variable) ve, AxisType.Height); // CF-1
                break;
              }
            }
          }
        }
      }
    }

    // time
    if (!hasAxisType(ds, AxisType.Time)) { // already has _CoordinateAxisType

      if (!addAxisType(ds, "time", AxisType.Time)) { // directly named

        String vname = ds.findAttValueIgnoreCase(null, "time_coordinate", null);
        if (!addAxisType(ds, vname, AxisType.Time)) { // attribute named

          for (int i = 0; i < ds.getVariables().size(); i++) {
            VariableEnhanced ve = (VariableEnhanced) ds.getVariables().get(i);
            String unit = ve.getUnitsString();
            if (unit == null) continue;
            if (SimpleUnit.isDateUnit(unit)) {
              addAxisType((Variable) ve, AxisType.Time); // CF-1
              break;
            }
          }
        }
      }
    }
  }