Esempio n. 1
0
    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());
    }
Esempio n. 2
0
  /** 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;
            }
          }
        }
      }
    }
  }