Exemplo n.º 1
0
 public List<Dimension> getDimensions() {
   if (pov.getLen() > 1) {
     List<Dimension> dims = new ArrayList<Dimension>(1);
     String suffix =
         (pov.getDataType() == DataType.STRING) || (pov.getDataType() == DataType.CHAR)
             ? "_strlen"
             : "_len";
     dims.add(new Dimension(pov.getName() + suffix, pov.getLen(), false, false, false));
     return dims;
   } else return new ArrayList<Dimension>(0);
 }
Exemplo n.º 2
0
  /**
   * write data from a ucar.nc2.dt.PointObsDataset into CF point format.
   *
   * @param pobsDataset rewrite data from here
   * @param fileOut write to tehis netcdf-3 file
   * @throws IOException on read/write error
   */
  public static void writePointObsDataset(PointObsDataset pobsDataset, String fileOut)
      throws IOException {

    // see if we have an altitude
    String altUnits = null;
    DataIterator iterOne = pobsDataset.getDataIterator(-1);
    while (iterOne.hasNext()) {
      PointObsDatatype pobsData = (PointObsDatatype) iterOne.nextData();
      ucar.unidata.geoloc.EarthLocation loc = pobsData.getLocation();
      altUnits = Double.isNaN(loc.getAltitude()) ? null : "meters";
      break;
    }

    List<VariableSimpleIF> vars = pobsDataset.getDataVariables();
    List<PointObVar> nvars = new ArrayList<PointObVar>(vars.size());

    // put vars in order
    for (VariableSimpleIF v : vars) {
      if (v.getDataType().isNumeric()) nvars.add(new PointObVar(v));
    }
    int ndoubles = vars.size();
    double[] dvals = new double[ndoubles];

    for (VariableSimpleIF v : vars) {
      if (v.getDataType().isString()) nvars.add(new PointObVar(v));
    }
    String[] svals = new String[vars.size() - ndoubles];

    FileOutputStream fos = new FileOutputStream(fileOut);
    DataOutputStream out = new DataOutputStream(fos);
    CFPointObWriter writer =
        new CFPointObWriter(out, pobsDataset.getGlobalAttributes(), altUnits, nvars, -1);

    DataIterator iter = pobsDataset.getDataIterator(1000 * 1000);
    while (iter.hasNext()) {
      PointObsDatatype pobsData = (PointObsDatatype) iter.nextData();
      StructureData sdata = pobsData.getData();

      int dcount = 0;
      int scount = 0;
      for (PointObVar v : nvars) {
        if (v.getDataType().isNumeric()) {
          Array data = sdata.getArray(v.getName());
          data.resetLocalIterator();
          if (data.hasNext()) dvals[dcount++] = data.nextDouble();

        } else if (v.getDataType().isString()) {
          ArrayChar data = (ArrayChar) sdata.getArray(v.getName());
          svals[scount++] = data.getString();
        }
      }

      ucar.unidata.geoloc.EarthLocation loc = pobsData.getLocation();
      writer.addPoint(
          loc.getLatitude(),
          loc.getLongitude(),
          loc.getAltitude(),
          pobsData.getObservationTimeAsDate(),
          dvals,
          svals);
    }

    writer.finish();
  }
Exemplo n.º 3
0
 public String getShortName() {
   return pov.getName();
 }