Esempio n. 1
0
  public Unit[] getDefaultRangeUnits() {
    FlatField fld = getAdaptedFlatField();
    if (fld == null) {
      return null;
    }

    return fld.getDefaultRangeUnits();
  }
  /**
   * Converts grid-relative wind to true (or absolute) wind. The U and V components of true wind are
   * {@link WesterlyWind} and {@link SoutherlyWind}, respectively. The domain of the input {@link
   * visad.FlatField} must have a manifold dimension of two or greater and it must have a reference
   * system which contains {@link visad.RealType#Latitude} and {@link visad.RealType#Longitude}. The
   * number of components in the range of the input {@link visad.FlatField} must be two. Both
   * components must have units convertible with {@link #DEFAULT_SPEED_UNIT}. The first and second
   * components are assumed to be the wind components in the direction of increasing first and
   * second manifold dimension indexes, respectively. The {@link visad.MathType} of the range of the
   * returned {@link visad.FlatField} will be <code>CartesianHorizontalWind.getEarthVectorType()
   * </code> and the domain will be the same as the input domain.
   *
   * @param rel The field of grid-relative wind.
   * @return The field of true wind corresponding to the input field.
   * @throws NullPointerException if <code>rel</code> is <code>null</code>.
   * @throws IllegalArgumentException if the input field doesn't have two and only two components in
   *     its range, or if the default units of the input range aren't equal, or if the domain of the
   *     input field doesn't have a transformation to latitude and longitude, or the grid is
   *     irregular or has too few points.
   * @throws VisADException if a VisAD failure occurs.
   * @throws RemoteException if a Java RMI failure occurs.
   * @see CartesianHorizontalWind
   */
  public static FlatField cartesianHorizontalWind(FlatField rel)
      throws VisADException, RemoteException {

    FunctionType funcType = (FunctionType) rel.getType();
    MathType rangeType = funcType.getRange();

    if (rel.getRangeDimension() != 2) {
      throw new IllegalArgumentException(rangeType.toString());
    }

    Unit[] units = rel.getDefaultRangeUnits();

    if (!units[0].equals(units[1])) {
      throw new IllegalArgumentException(units.toString());
    }

    SampledSet grid = (SampledSet) rel.getDomainSet();
    // check for single point grid
    if (grid instanceof SingletonSet) {
      return rel;
    } else if (grid instanceof GriddedSet) {
      int[] lengths = ((GriddedSet) grid).getLengths();
      if ((lengths[0] == 1) && (lengths[1] == 1)) {
        return rel;
      }
    }
    FlatField abs =
        new FlatField(
            new FunctionType(funcType.getDomain(), CartesianHorizontalWind.getEarthVectorType()),
            grid,
            (CoordinateSystem[]) null,
            rel.getRangeSets(),
            units);

    abs.setSamples(trueWind(rel.getFloats(), grid), false);

    return abs;
  }