예제 #1
1
    // create from a dataset
    public VariableBean(Variable vs) {
      this.vs = vs;
      // vs = (v instanceof VariableEnhanced) ? (VariableEnhanced) v : new VariableStandardized( v);

      setName(vs.getShortName());
      setDescription(vs.getDescription());
      setUnits(vs.getUnitsString());
      setDataType(vs.getDataType().toString());

      // Attribute csAtt = vs.findAttribute("_coordSystems");
      // if (csAtt != null)
      //  setCoordSys( csAtt.getStringValue());

      // collect dimensions
      StringBuilder lens = new StringBuilder();
      StringBuilder names = new StringBuilder();
      java.util.List dims = vs.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.getName() : "anon";
        names.append(name);
        lens.append(dim.getLength());
      }
      setDimensions(names.toString());
      setShape(lens.toString());
    }
  /* Structure {
      int LAT[0];
      ...
      int LAT[149];
  } IMAGE_LAT_ARRAY(3600);
     type = Layout(8);  type= 2 (chunked) storageSize = (1,600) dataSize=0 dataAddress=2548046
  */
  @Test
  public void testReadOneAtATime() throws java.io.IOException, InvalidRangeException {
    try (NetcdfFile ncfile = TestH5.openH5("IASI/IASI.h5")) {

      Variable dset = ncfile.findVariable("U-MARF/EPS/IASI_xxx_1C/DATA/IMAGE_LAT_ARRAY");
      assert (null != dset);
      assert (dset.getDataType() == DataType.STRUCTURE);
      assert (dset.getRank() == 1);
      assert (dset.getSize() == 3600);

      Dimension d = dset.getDimension(0);
      assert (d.getLength() == 3600);

      Structure s = (Structure) dset;

      // read last one - chunked
      StructureData sd = s.readStructure(3599);
      assert sd.getScalarInt("LAT[0]") == 70862722;
      assert sd.getScalarInt("LAT[149]") == 85302263;

      // read one at a time
      for (int i = 3590; i < d.getLength(); i++) {
        s.readStructure(i);
        System.out.println(" read structure " + i);
      }
    }
    System.out.println("*** testReadIASI ok");
  }
 private void writeVariable(DataOutputStream stream, Variable variable, int numScores)
     throws IOException {
   stream.writeUTF(variable.getName());
   stream.writeByte(variable.getCardinality());
   for (String instantiation : variable.getInstantiations()) stream.writeUTF(instantiation);
   stream.writeInt(numScores);
 }
예제 #4
0
  private void showDeclaration(BeanTableSorted from, boolean isNcml) {
    Variable v = getCurrentVariable(from);
    if (v == null) return;
    infoTA.clear();
    if (isNcml) {
      Formatter out = new Formatter();
      try {
        NCdumpW.writeNcMLVariable(v, out);
      } catch (IOException e) {
        e.printStackTrace();
      }
      infoTA.appendLine(out.toString());

    } else {
      infoTA.appendLine(v.toString());
    }

    if (Debug.isSet("Xdeveloper")) {
      infoTA.appendLine("\n");
      infoTA.appendLine("FULL NAME = " + v.getFullName());
      infoTA.appendLine("\n");
      infoTA.appendLine(v.toStringDebug());
    }
    infoTA.gotoTop();
    infoWindow.setTitle("Variable Info");
    infoWindow.show();
  }
  /*
   Structure {
    int a_name;
    byte b_name(3);
    byte c_name(3);
    short d_name(3);
    int e_name(3);
    long f_name(3);
    int g_name(3);
    short h_name(3);
    int i_name(3);
    long j_name(3);
    float k_name(3);
    double l_name(3);
  } CompoundNative(15);
      type = Layout(8);  type= 1 (contiguous) storageSize = (15,144) dataSize=0 dataAddress=2048
  */
  @Test
  public void testReadH5StructureArrayMembers() throws java.io.IOException {
    try (NetcdfFile ncfile = TestH5.openH5("complex/compound_native.h5")) {

      Variable dset = ncfile.findVariable("CompoundNative");
      assert (null != dset);
      assert (dset.getDataType() == DataType.STRUCTURE);
      assert (dset.getRank() == 1);
      assert (dset.getSize() == 15);

      Dimension d = dset.getDimension(0);
      assert (d.getLength() == 15);

      Structure s = (Structure) dset;

      // read all with the iterator
      StructureDataIterator iter = s.getStructureIterator();
      while (iter.hasNext()) {
        StructureData sd = iter.next();

        for (StructureMembers.Member m : sd.getMembers()) {
          Array data = sd.getArray(m);
          NCdumpW.printArray(data, m.getName(), out, null);
        }
      }
    }
    System.out.println("*** testReadH5StructureArrayMembers ok");
  }
예제 #6
0
  /**
   * Method to invoke when we encounter a block of text in the CSV file that is the contents of a
   * predicate variable.
   *
   * @param csvFile The csvFile we are currently parsing.
   * @param var The variable that we will be adding cells too.
   * @param arg The matrix template we are using when parsing individual matrix elements to put in
   *     the spreadsheet.
   * @return The next line in the file that is not part of the block of text in the CSV file.
   * @throws IOException If unable to read the file correctly.
   */
  private String parseMatrixVariable(
      final BufferedReader csvFile, final Variable var, final Argument arg) throws IOException {
    String line = csvFile.readLine();

    while ((line != null) && Character.isDigit(line.charAt(0))) {

      // Split the line into tokens using a comma delimiter.
      String[] tokens = line.split(",");

      Cell newCell = var.createCell();
      // Set the onset and offset from tokens in the line.
      newCell.setOnset(tokens[DATA_ONSET]);
      newCell.setOffset(tokens[DATA_OFFSET]);

      // Strip the brackets from the first and last argument.
      tokens[DATA_INDEX] = tokens[DATA_INDEX].substring(1, tokens[DATA_INDEX].length());

      int end = tokens.length - 1;
      tokens[end] = tokens[end].substring(0, tokens[end].length() - 1);
      parseFormalArgs(tokens, DATA_INDEX, var.getVariableType(), (MatrixValue) newCell.getValue());

      // Get the next line in the file for reading.
      line = csvFile.readLine();
    }

    return line;
  }
예제 #7
0
 public void definiteAssignment() {
   if (getOperand().isVariable()) {
     Variable v = getOperand().varDecl();
     if (v != null && v.isFinal()) {
       error("++ and -- can not be applied to final variable " + v);
     }
   }
 }
예제 #8
0
  void CheckS(Variable v) throws IOException {

    // string
    // assert(null != (v = dodsfile.findVariable("types.strings.s")));
    // assert v.getName().equals("types.strings.s");
    assert v.getRank() == 0;
    assert v.getDataType() == DataType.STRING : v.getDataType();
    CheckSValue(v.read());
  }
예제 #9
0
 void CheckInt16(Variable v) throws IOException {
   // int16
   // assert(null != (v = dodsfile.findVariable("types.integers.i16")));
   // assert v.getName().equals("types.integers.i16");
   assert v.getRank() == 0;
   assert v.getSize() == 1;
   assert v.getDataType() == DataType.SHORT;
   CheckInt16Value(v.read());
 }
예제 #10
0
  void CheckD(Variable v) throws IOException {

    // double
    // assert(null != (v = dodsfile.findVariable("types.floats.f64")));
    // assert v.getName().equals("types.floats.f64");
    assert v.getRank() == 0;
    assert v.getSize() == 1;
    assert v.getDataType() == DataType.DOUBLE : v.getDataType();
    CheckDValue(v.read());
  }
예제 #11
0
  void CheckF(Variable v) throws IOException {

    // float
    // assert(null != (v = dodsfile.findVariable("types.floats.f32")));
    // assert v.getName().equals("types.floats.f32");
    assert v.getRank() == 0;
    assert v.getSize() == 1;
    assert v.getDataType() == DataType.FLOAT : v.getDataType();
    CheckFValue(v.read());
  }
예제 #12
0
  void CheckUrl(Variable v) throws IOException {

    // url
    // assert(null != (v = dodsfile.findVariable("types.strings.u")));
    // assert v.getName().equals("types.strings.u");
    assert v.getRank() == 0;
    assert v.getDataType() == DataType.STRING : v.getDataType();
    String str = v.readScalarString();
    assert str.equals("http://www.opendap.org") || str.equals("http://www.dods.org") : str;
  }
예제 #13
0
  void CheckLong32(Variable v) throws IOException {

    // uint32
    // assert(null != (v = dodsfile.findVariable("types.integers.ui32")));
    // assert v.getName().equals("types.integers.ui32");
    assert v.getRank() == 0;
    assert v.getSize() == 1;
    assert v.getDataType() == DataType.LONG : v.getDataType();
    CheckLongValue(v.read());
  }
예제 #14
0
 @Override
 public VariableReference plus(Variable v) throws ScriptException {
   if (v == null) throw new ScriptException(composeMessage("Binary '+' operand cannot be null"));
   String urlSide = encodedURL;
   if (v.hasURLPathValue()) urlSide += "/" + v.getURLPathValue();
   String argSide = encodedArgs;
   if (v.hasQueryArgumentValue()) {
     if (argSide == null) argSide = v.getQueryArgumentValue();
     else argSide += "&" + v.getQueryArgumentValue();
   }
   return new VariableURL(urlSide, argSide);
 }
  /**
   * Set extra information used by station obs datasets. Use stnIdVName or stnIndexVName.
   *
   * @param stnIdVName the obs variable that is used to find the station in the stnHash; may be type
   *     int or a String (char).
   * @param stnDescVName optional station var containing station description
   */
  public void setStationInfo(
      String stnIdVName, String stnDescVName, String stnIndexVName, StationHelper stationHelper) {
    this.stnIdVName = stnIdVName;
    this.stnDescVName = stnDescVName;
    this.stnIndexVName = stnIndexVName;
    this.stationHelper = stationHelper;

    if (stnIdVName != null) {
      Variable stationVar = ncfile.findVariable(stnIdVName);
      stationIdType = stationVar.getDataType();
    }
  }
  /**
   * 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().findVariable("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");
    try {
      timeUnit = new DateUnit(timeUnitString);
    } catch (Exception e) {
      if (null != errs) errs.format("Error on string = %s == %s%n", timeUnitString, e.getMessage());
      try {
        timeUnit = new DateUnit("seconds since 1970-01-01");
      } catch (Exception e1) {
        // cant happen
      }
    }
  }
예제 #17
0
  public static void main(String[] args) throws IOException {

    Variable va = new Variable();
    // va.Megas();
    // va.Array();
    // va.array2();
    // va.array3();
    // va.array4();er
    // va.array6();
    // System.out.println(va.array7(7));
    // va.array8();
    va.array9();
  }
예제 #18
0
  private void doWrite2(NetcdfFileWriteable ncfile, String varName) throws Exception {
    Variable v = ncfile.findVariable(varName);
    int[] w = getWeights(v);

    int[] shape = v.getShape();
    Array aa = Array.factory(v.getDataType().getPrimitiveClassType(), shape);
    Index ima = aa.getIndex();
    for (int i = 0; i < shape[0]; i++) {
      for (int j = 0; j < shape[1]; j++) {
        aa.setDouble(ima.set(i, j), (double) (i * w[0] + j * w[1]));
      }
    }

    ncfile.write(varName, aa);
  }
예제 #19
0
  private int[] getWeights(Variable v) {
    int rank = v.getRank();
    int[] w = new int[rank];

    for (int n = 0; n < rank; n++) {
      Dimension dim = v.getDimension(n);
      String dimName = dim.getName();
      if (dimName.equals("time")) w[n] = 1000;
      if (dimName.equals("z")) w[n] = 100;
      if (dimName.equals("y")) w[n] = 10;
      if (dimName.equals("x")) w[n] = 1;
    }

    return w;
  }
예제 #20
0
 /**
  * performs the action, adding the specified Annotation. Returns the position of the end of the
  * Annotation.
  */
 @Override
 public int perform(Document doc, PatternApplication patap) {
   Span span;
   HashMap bindings = patap.bestBindings;
   // System.out.println ("bindings (for new annotation): " + bindings);
   if (spanVariable == null) {
     span = new Span(patap.startPosition, patap.bestPosition);
   } else if (spanVariable.name.toString() == "0") {
     span = new Span(patap.startPosition, patap.startPosition);
   } else {
     Object value = bindings.get(spanVariable.name);
     if (value instanceof Span) {
       span = (Span) value;
     } else if (value instanceof Annotation) {
       span = ((Annotation) value).span();
     } else {
       System.out.println("Value of " + spanVariable.toString() + " is not a span.or annotation");
       return -1;
     }
   }
   if (Pat.trace)
     Console.println(
         "Annotating "
             + doc.text(span)
             + " as "
             + type
             + " "
             + features.substitute(bindings).toSGMLString());
   hideAnnotations(doc, type, span);
   hideAnnotations(doc, "token", span);
   Annotation newAnnotation = new Annotation(type, span, features.substitute(bindings));
   doc.addAnnotation(newAnnotation);
   if (bindingVariable != null) bindings.put(bindingVariable.name, newAnnotation);
   return span.end();
 }
  @Test
  public void testH5StructureDS() throws java.io.IOException {
    int a_name = 0;
    String[] b_name =
        new String[] {
          "A fight is a contract that takes two people to honor.",
          "A combative stance means that you've accepted the contract.",
          "In which case, you deserve what you get.",
          "  --  Professor Cheng Man-ch'ing"
        };
    String c_name = "Hello!";

    // H5header.setDebugFlags(new ucar.nc2.util.DebugFlagsImpl("H5header/header"));
    try (NetcdfDataset ncfile =
        NetcdfDataset.openDataset(TestH5.testDir + "complex/compound_complex.h5")) {

      Variable dset = ncfile.findVariable("CompoundComplex");
      assert (null != dset);
      assert (dset.getDataType() == DataType.STRUCTURE);
      assert (dset.getRank() == 1);
      assert (dset.getSize() == 6);

      Dimension d = dset.getDimension(0);
      assert (d.getLength() == 6);

      Structure s = (Structure) dset;

      // read all with the iterator
      StructureDataIterator iter = s.getStructureIterator();
      while (iter.hasNext()) {
        StructureData sd = iter.next();
        assert sd.getScalarInt("a_name") == a_name;
        a_name++;
        assert sd.getScalarString("c_name").equals(c_name);
        String[] results = sd.getJavaArrayString(sd.findMember("b_name"));
        assert results.length == b_name.length;
        int count = 0;
        for (String r : results) assert r.equals(b_name[count++]);

        for (StructureMembers.Member m : sd.getMembers()) {
          Array data = sd.getArray(m);
          NCdumpW.printArray(data, m.getName(), out, null);
        }
      }
    }
    System.out.println("*** testH5StructureDS ok");
  }
예제 #22
0
  /* is the given variable a neighbor of this variable?*/
  public boolean isNeighbor(Variable v) {

    for (int i = 0; i < neighbors.size(); i++) {
      Variable vv = (Variable) neighbors.elementAt(i);
      if (v.equalVar(vv)) return true;
    }
    return false;
  }
예제 #23
0
 public String toString() {
   //    return lhs + " := " + rhs + ";";
   return new StringBuilder(lhs.toString())
       .append(" := ")
       .append(rhs.toString())
       .append(";")
       .toString();
 }
예제 #24
0
  private void setSelected(Variable v) {
    eventsOK = false;

    List<Variable> vchain = new ArrayList<Variable>();
    vchain.add(v);

    Variable vp = v;
    while (vp.isMemberOfStructure()) {
      vp = vp.getParentStructure();
      vchain.add(0, vp); // reverse
    }

    for (int i = 0; i < vchain.size(); i++) {
      vp = vchain.get(i);
      NestedTable ntable = setNestedTable(i, vp.getParentStructure());
      ntable.setSelected(vp);
    }

    eventsOK = true;
  }
예제 #25
0
  private void compareDataset(CompareDialog.Data data) {
    if (data.name == null) return;

    NetcdfFile compareFile = null;
    try {
      compareFile = NetcdfDataset.openFile(data.name, null);

      Formatter f = new Formatter();
      CompareNetcdf2 cn = new CompareNetcdf2(f, data.showCompare, data.showDetails, data.readData);
      if (data.howMuch == CompareDialog.HowMuch.All) cn.compare(ds, compareFile);
      else {
        NestedTable nested = nestedTableList.get(0);
        Variable org = getCurrentVariable(nested.table);
        if (org == null) return;
        Variable ov = compareFile.findVariable(org.getFullNameEscaped());
        if (ov != null) cn.compareVariable(org, ov);
      }

      infoTA.setText(f.toString());
      infoTA.gotoTop();
      infoWindow.setTitle("Compare");
      infoWindow.show();

    } catch (Throwable ioe) {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
      ioe.printStackTrace(new PrintStream(bos));
      infoTA.setText(bos.toString());
      infoTA.gotoTop();
      infoWindow.show();

    } finally {
      if (compareFile != null)
        try {
          compareFile.close();
        } catch (Exception eek) {
        }
    }
  }
예제 #26
0
    public JIPList getSingletonVariables() {
      Hashtable<String, Variable> svar = m_parser.getSingletonVariables();

      JIPList singletonVars = null;

      //        	Hashtable<String, JIPVariable> sjvar = new Hashtable<String, JIPVariable>();

      for (String key : svar.keySet()) {
        Variable var = svar.get(key);
        if (!var.isAnonymous())
          singletonVars =
              JIPList.create(
                  JIPFunctor.create(
                      "=",
                      JIPCons.create(
                          JIPAtom.create(var.getName()),
                          JIPCons.create(new JIPVariable(var), null))),
                  singletonVars);

        //        		sjvar.put(key, new JIPVariable(var));
      }
      if (singletonVars == null) return JIPList.NIL;
      else return singletonVars; // .reverse();
    }
예제 #27
0
  /**
   * Method to invoke when we encounter a block of text in the CSV file that is the contents of a
   * variable.
   *
   * @param csvFile The csvFile we are currently parsing.
   * @param var The variable that we will be adding cells too.
   * @param The populator to use when converting the contents of the cell into a datavalue that can
   *     be inserted into the spreadsheet.
   * @return The next line in the file that is not part of the block of text in the CSV file.
   * @throws IOException If unable to read the file correctly.
   */
  private String parseEntries(
      final BufferedReader csvFile, final Variable var, final EntryPopulator populator)
      throws IOException {

    // Keep parsing lines and putting them in the newly formed nominal
    // variable until we get to a line indicating the end of file or a new
    // variable section.
    String line = csvFile.readLine();

    while ((line != null) && Character.isDigit(line.charAt(0))) {

      // Split the line into tokens using a comma delimiter.
      String[] tokens = line.split(",");

      // BugzID: 1075 - If the line ends with an escaped new line - add
      // the next line to the current text field.
      while ((line != null) && line.endsWith("\\") && !line.endsWith("\\\\")) {
        line = csvFile.readLine();

        String content = tokens[tokens.length - 1];
        content = content.substring(0, content.length() - 1);
        tokens[tokens.length - 1] = content + '\n' + line;
      }

      Cell newCell = var.createCell();

      // Set the onset and offset from tokens in the line.
      newCell.setOnset(tokens[DATA_ONSET]);
      newCell.setOffset(tokens[DATA_OFFSET]);
      populator.populate(tokens, newCell.getValue());

      // Get the next line in the file for reading.
      line = csvFile.readLine();
    }

    return line;
  }
  /*  Structure {
    char EntryName(64);
    char Definition(1024);
    char Unit(1024);
    char Scale Factor(1024);
  } TIME_DESCR(60);
     type = Layout(8);  type= 2 (chunked) storageSize = (1,3136) dataSize=0 dataAddress=684294
  */
  @Test
  public void testReadManyAtATime() throws java.io.IOException, InvalidRangeException {
    try (NetcdfFile ncfile = TestH5.openH5("IASI/IASI.h5")) {

      Variable dset = ncfile.findVariable("U-MARF/EPS/IASI_xxx_1C/DATA/TIME_DESCR");
      assert (null != dset);
      assert (dset.getDataType() == DataType.STRUCTURE);
      assert (dset.getRank() == 1);
      assert (dset.getSize() == 60);

      Dimension d = dset.getDimension(0);
      assert (d.getLength() == 60);

      ArrayStructure data = (ArrayStructure) dset.read();
      StructureMembers.Member m = data.getStructureMembers().findMember("EntryName");
      assert m != null;
      for (int i = 0; i < dset.getSize(); i++) {
        String r = data.getScalarString(i, m);
        if (i % 2 == 0) assert r.equals("TIME[" + i / 2 + "]-days") : r + " at " + i;
        else assert r.equals("TIME[" + i / 2 + "]-milliseconds") : r + " at " + i;
      }
    }
    System.out.println("*** testReadManyAtATime ok");
  }
  public static void main(String args[]) throws Exception {
    long start = System.currentTimeMillis();
    Map<String, ucar.unidata.geoloc.Station> staHash =
        new HashMap<String, ucar.unidata.geoloc.Station>();

    String location = "R:/testdata/sounding/netcdf/Upperair_20070401_0000.nc";
    NetcdfDataset ncfile = NetcdfDataset.openDataset(location);
    ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);

    // look through record varibles, for those that have "manLevel" dimension
    // make a StructureData object for those
    StructureMembers sm = new StructureMembers("manLevel");
    Dimension manDim = ncfile.findDimension("manLevel");
    Structure record = (Structure) ncfile.findVariable("record");
    List<Variable> allList = record.getVariables();
    List<VariableSimpleIF> varList = new ArrayList<VariableSimpleIF>();
    for (Variable v : allList) {
      if ((v.getRank() == 1) && v.getDimension(0).equals(manDim)) {
        // public VariableDS(NetcdfDataset ds, Group group, Structure parentStructure, String
        // shortName, DataType dataType,
        // String dims, String units, String desc) {
        varList.add(
            new VariableDS(
                ncfile,
                null,
                null,
                v.getShortName(),
                v.getDataType(),
                "",
                v.getUnitsString(),
                v.getDescription()));
        // (String name, String desc, String units, DataType dtype, int []shape)
        sm.addMember(
            v.getShortName(),
            v.getDescription(),
            v.getUnitsString(),
            v.getDataType(),
            new int[0]); // scalar
      }
    }

    ArrayStructureMA manAS = new ArrayStructureMA(sm, new int[] {manDim.getLength()});

    // need the date units
    Variable time = ncfile.findVariable("synTime");
    String timeUnits = ncfile.findAttValueIgnoreCase(time, "units", null);
    timeUnits = StringUtil.remove(timeUnits, '('); // crappy fsl'ism
    timeUnits = StringUtil.remove(timeUnits, ')');
    DateUnit timeUnit = new DateUnit(timeUnits);

    // extract stations
    int nrecs = 0;
    StructureDataIterator iter = record.getStructureIterator();
    while (iter.hasNext()) {
      StructureData sdata = iter.next();
      String name = sdata.getScalarString("staName");
      ucar.unidata.geoloc.Station s = staHash.get(name);
      if (s == null) {
        float lat = sdata.convertScalarFloat("staLat");
        float lon = sdata.convertScalarFloat("staLon");
        float elev = sdata.convertScalarFloat("staElev");
        s = new StationImpl(name, "", lat, lon, elev);
        staHash.put(name, s);
      }
      nrecs++;
    }
    List<ucar.unidata.geoloc.Station> stnList =
        Arrays.asList(staHash.values().toArray(new ucar.unidata.geoloc.Station[staHash.size()]));
    Collections.sort(stnList);

    // create the writer
    WriterProfileObsDataset writer =
        new WriterProfileObsDataset(location + ".out", "rewrite " + location);
    writer.writeHeader(stnList, varList, nrecs, "prMan");

    // extract records
    iter = record.getStructureIterator();
    while (iter.hasNext()) {
      StructureData sdata = iter.next();
      String name = sdata.getScalarString("staName");
      double timeValue = sdata.convertScalarDouble("synTime");
      Date date = timeUnit.makeDate(timeValue);

      // transfer to the ArrayStructure
      List<String> names = sm.getMemberNames();
      for (String mname : names) {
        manAS.setMemberArray(mname, sdata.getArray(mname));
      }

      // each level is weritten as a seperate structure
      int numMand = sdata.getScalarInt("numMand");
      if (numMand >= manDim.getLength()) continue;

      for (int i = 0; i < numMand; i++) {
        StructureData useData = manAS.getStructureData(i);
        writer.writeRecord(name, date, useData);
      }
    }

    writer.finish();

    long took = System.currentTimeMillis() - start;
    System.out.println("That took = " + took);
  }
    // create from a dataset
    public ObsBean(Structure obs, StructureData sdata) {
      // first choice
      for (Variable v : obs.getVariables()) {
        Attribute att = v.findAttribute("BUFR:TableB_descriptor");
        if (att == null) continue;
        String val = att.getStringValue();
        if (val.equals("0-5-1") && Double.isNaN(lat)) {
          lat = sdata.convertScalarDouble(v.getShortName());
        } else if (val.equals("0-6-1") && Double.isNaN(lon)) {
          lon = sdata.convertScalarDouble(v.getShortName());
        } else if (val.equals("0-7-30") && Double.isNaN(alt)) {

          alt = sdata.convertScalarDouble(v.getShortName());
        } else if (val.equals("0-4-1") && (year < 0)) {
          year = sdata.convertScalarInt(v.getShortName());
        } else if (val.equals("0-4-2") && (month < 0)) {
          month = sdata.convertScalarInt(v.getShortName());
        } else if (val.equals("0-4-3") && (day < 0)) {
          day = sdata.convertScalarInt(v.getShortName());
        } else if (val.equals("0-4-4") && (hour < 0)) {
          hour = sdata.convertScalarInt(v.getShortName());
        } else if (val.equals("0-4-5") && (minute < 0)) {
          minute = sdata.convertScalarInt(v.getShortName());
        } else if (val.equals("0-4-6") && (sec < 0)) {
          sec = sdata.convertScalarInt(v.getShortName());

        } else if (val.equals("0-1-1") && (wmo_block < 0)) {
          wmo_block = sdata.convertScalarInt(v.getShortName());
        } else if (val.equals("0-1-2") && (wmo_id < 0)) {
          wmo_id = sdata.convertScalarInt(v.getShortName());

        } else if ((stn == null)
            && (val.equals("0-1-7")
                || val.equals("0-1-194")
                || val.equals("0-1-11")
                || val.equals("0-1-18"))) {
          if (v.getDataType().isString()) stn = sdata.getScalarString(v.getShortName());
          else stn = Integer.toString(sdata.convertScalarInt(v.getShortName()));
        }
      }

      // second choice
      for (Variable v : obs.getVariables()) {
        Attribute att = v.findAttribute("BUFR:TableB_descriptor");
        if (att == null) continue;
        String val = att.getStringValue();
        if (val.equals("0-5-2") && Double.isNaN(lat)) {
          lat = sdata.convertScalarDouble(v.getShortName());
        } else if (val.equals("0-6-2") && Double.isNaN(lon)) {
          lon = sdata.convertScalarDouble(v.getShortName());
        } else if (val.equals("0-7-1") && Double.isNaN(alt)) {
          alt = sdata.convertScalarDouble(v.getShortName());
        } else if ((val.equals("0-4-7")) && (sec < 0)) {
          sec = sdata.convertScalarInt(v.getShortName());
        }
      }

      // third choice
      for (Variable v : obs.getVariables()) {
        Attribute att = v.findAttribute("BUFR:TableB_descriptor");
        if (att == null) continue;
        String val = att.getStringValue();
        if (val.equals("0-7-10") && Double.isNaN(alt)) {
          alt = sdata.convertScalarDouble(v.getShortName());
        } else if (val.equals("0-7-2") && Double.isNaN(alt)) {
          alt = sdata.convertScalarDouble(v.getShortName());
        }
      }
    }