Ejemplo n.º 1
0
  /**
   * Create e field description from the field
   *
   * @param fi field to use
   */
  protected void makeFieldDescription(FieldImpl fi) {
    if (fi == null) {
      fieldsDescription = "Bad data: null";
      return;
    }
    try {
      if (ucar.unidata.data.grid.GridUtil.isTimeSequence(fi)) {
        fi = (FieldImpl) fi.getSample(0);
      }
      PointOb ob = (PointOb) fi.getSample(0);
      Tuple tuple = (Tuple) ob.getData();
      MathType[] comps = ((TupleType) tuple.getType()).getComponents();
      Trace.msg("PointDataSource #vars=" + comps.length);
      StringBuffer params = new StringBuffer(comps.length + " Fields:<ul>");
      String dataSourceName = getName();
      DataChoice.addCurrentName(new TwoFacedObject("Point Data>Time", "Time"));
      DataChoice.addCurrentName(new TwoFacedObject("Point Data>Latitude", "Latitude"));
      DataChoice.addCurrentName(new TwoFacedObject("Point Data>Altitude", "Altitude"));

      for (int i = 0; i < comps.length; i++) {
        params.append("<li>");
        String paramName = ucar.visad.Util.cleanTypeName(comps[i].toString());
        DataAlias alias = DataAlias.findAlias(paramName);
        params.append(paramName);
        if (alias != null) {
          params.append(" --  " + alias.getLabel());
          DataChoice.addCurrentName(
              new TwoFacedObject(
                  dataSourceName + ">" + alias.getLabel() + " -- " + paramName, paramName));
        } else {
          DataChoice.addCurrentName(
              new TwoFacedObject(dataSourceName + ">" + paramName, paramName));
        }
        Data data = tuple.getComponent(i);
        if (data instanceof Real) {
          Unit unit = ((Real) data).getUnit();
          if (unit != null) {
            params.append("  [" + unit.toString() + "]");
          }
        }
      }
      fieldsDescription = params.toString();
    } catch (Exception exc) {
      logException("getting description", exc);
    }
  }
Ejemplo n.º 2
0
  /** Make the <code>DataChoices</code> for this <code>DataSource</code>. */
  public void doMakeDataChoices() {

    if (sources == null) {
      return;
    }
    String stationModelName = (String) getProperty(PROP_STATIONMODELNAME);
    Hashtable properties =
        Misc.newHashtable(DataChoice.PROP_ICON, "/auxdata/ui/icons/Placemark16.gif");
    if (stationModelName != null) {
      properties.put(PROP_STATIONMODELNAME, stationModelName);
    }
    if (!getDefaultLevels().isEmpty()) {
      properties.put(DataSelection.PROP_DEFAULT_LEVELS, getDefaultLevels());
    }
    DataChoice uberChoice = null;
    /*  Might want to do this someday
    uberChoice = new DirectDataChoice(this,
                                        sources, getName(),
                                        getDataName(),
                                        getPointCategories(),
                                        properties);
    */

    if (sources.size() > 1) {
      uberChoice =
          new CompositeDataChoice(
              this, sources, getName(), getDataName(), getPointCategories(), properties);
      addDataChoice(uberChoice);
    }

    for (int i = 0; i < sources.size(); i++) {
      String dataChoiceDesc = getDescription();
      String dataChoiceName = getDataName();
      if (uberChoice != null) {
        dataChoiceDesc = IOUtil.getFileTail(sources.get(i).toString());
        dataChoiceName = IOUtil.getFileTail(sources.get(i).toString());
      }

      DataChoice choice =
          new DirectDataChoice(
              this,
              new Integer(i),
              dataChoiceDesc,
              dataChoiceName,
              getPointCategories(),
              properties);

      /*
      We'd like to create sub choices for each parameter but we don't really
      know the parameters until we read the data and that can be expensive
                  DirectDataChoice subChoice = new DirectDataChoice(this,
                            (String) sources.get(i),
                            getDescription(), getDataName(),
                            getPointCategories(), properties);
                            choice.addDataChoice(subChoice);*/

      if (uberChoice != null) {
        ((CompositeDataChoice) uberChoice).addDataChoice(choice);
      } else {
        addDataChoice(choice);
      }
      // Only add the grid data choices for the first source
      if (i > 0) {
        continue;
      }
      try {
        FieldImpl sample = (makeGridFields ? getSample(choice) : null);
        if (sample != null) {
          for (int dataChoiceType = 0; dataChoiceType < 2; dataChoiceType++) {
            Hashtable seenFields = new Hashtable();
            if (ucar.unidata.data.grid.GridUtil.isTimeSequence(sample)) {
              sample = (FieldImpl) sample.getSample(0);
            }
            PointOb ob = (PointOb) sample.getSample(0);
            Tuple tuple = (Tuple) ob.getData();
            TupleType tupleType = (TupleType) tuple.getType();
            MathType[] types = tupleType.getComponents();
            CompositeDataChoice compositeDataChoice = null;
            for (int typeIdx = 0; typeIdx < types.length; typeIdx++) {
              if (!(types[typeIdx] instanceof RealType)) {
                continue;
              }
              RealType type = (RealType) types[typeIdx];
              if (!canCreateGrid(type)) {
                continue;
              }
              //                        List gridCategories =
              //                            DataCategory.parseCategories("OA Fields;GRID-2D-TIME;");
              List gridCategories = DataCategory.parseCategories("GRID-2D-TIME;", false);
              if (compositeDataChoice == null) {
                compositeDataChoice =
                    new CompositeDataChoice(
                        this,
                        "",
                        "Grid Fields from Objective Analysis",
                        "Gridded Fields " + ((dataChoiceType == 0) ? "" : "(with first guess)"),
                        Misc.newList(DataCategory.NONE_CATEGORY),
                        null);
                addDataChoice(compositeDataChoice);
              }
              String name = ucar.visad.Util.cleanTypeName(type.toString());
              if (seenFields.get(name) != null) {
                continue;
              }
              seenFields.put(name, name);
              List idList = Misc.newList(new Integer(i), type);
              if (dataChoiceType == 1) {
                idList.add(new Boolean(true));
              }
              DataChoice gridChoice =
                  new DirectDataChoice(this, idList, name, name, gridCategories, (Hashtable) null);
              compositeDataChoice.addDataChoice(gridChoice);
            }
          }
        }
      } catch (Exception exc) {
        throw new WrapperException("Making grid parameters", exc);
      }
      //            if(true) break;
    }
  }