Exemple #1
0
 /**
  * Create a scalar numeric-valued Attribute.
  *
  * @param name name of Attribute
  * @param val value of Attribute
  */
 public Attribute(String name, Number val) {
   this.name = name;
   int[] shape = new int[1];
   shape[0] = 1;
   DataType dt = DataType.getType(val.getClass());
   Array vala = Array.factory(dt.getPrimitiveClassType(), shape);
   Index ima = vala.getIndex();
   vala.setDouble(ima.set0(0), val.doubleValue());
   setValues(vala);
 }
Exemple #2
0
  /**
   * A copy constructor using a ucar.unidata.util.Parameter. Need to do this so ucar.unidata.geoloc
   * package doesnt depend on ucar.nc2 library
   *
   * @param param copy info from here.
   */
  public Attribute(ucar.unidata.util.Parameter param) {
    this.name = param.getName();

    if (param.isString()) {
      setStringValue(param.getStringValue());

    } else {
      double[] values = param.getNumericValues();
      int n = values.length;
      Array vala = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[] {n}, values);
      setValues(vala);
    }
  }
Exemple #3
0
  /**
   * Construct attribute with list of String or Number values.
   *
   * @param name name of attribute
   * @param values list of values. must be String or Number, must all be the same type, and have at
   *     least 1 member
   */
  public Attribute(String name, List values) {
    this.name = name;
    int n = values.size();
    Object pa = null;

    Class c = values.get(0).getClass();
    if (c == String.class) {
      String[] va = new String[n];
      pa = va;
      for (int i = 0; i < n; i++) va[i] = (String) values.get(i);

    } else if (c == Integer.class) {
      int[] va = new int[n];
      pa = va;
      for (int i = 0; i < n; i++) va[i] = (Integer) values.get(i);

    } else if (c == Double.class) {
      double[] va = new double[n];
      pa = va;
      for (int i = 0; i < n; i++) va[i] = (Double) values.get(i);

    } else if (c == Float.class) {
      float[] va = new float[n];
      pa = va;
      for (int i = 0; i < n; i++) va[i] = (Float) values.get(i);

    } else if (c == Short.class) {
      short[] va = new short[n];
      pa = va;
      for (int i = 0; i < n; i++) va[i] = (Short) values.get(i);

    } else if (c == Byte.class) {
      byte[] va = new byte[n];
      pa = va;
      for (int i = 0; i < n; i++) va[i] = (Byte) values.get(i);

    } else if (c == Long.class) {
      long[] va = new long[n];
      pa = va;
      for (int i = 0; i < n; i++) va[i] = (Long) values.get(i);

    } else {
      throw new IllegalArgumentException("unknown type for Attribute = " + c.getName());
    }

    setValues(Array.factory(c, new int[] {n}, pa));
  }
Exemple #4
0
 /**
  * Construct attribute with Array of values.
  *
  * @param name name of attribute
  * @param values array of values.
  */
 public Attribute(String name, Array values) {
   this.name = name;
   setValues(values);
 }