Package ucar.visad

Class Util

java.lang.Object
ucar.visad.Util

public final class Util extends Object
Provides support for utility functions.
Version:
$Revision: 1.81 $ $Date: 2007/08/19 15:55:31 $
Author:
Unidata Development Team
  • Field Details

    • TEXT_IDENTIFIER

      public static final String TEXT_IDENTIFIER
      The suffix added to text type names
      See Also:
    • REALTYPE_ROOT

      public static String REALTYPE_ROOT
      The default root name for generic RealTypes
  • Method Details

    • getDefaultUnits

      protected static Unit[] getDefaultUnits(FlatField field, int[] indexes, RealType[] types) throws IllegalArgumentException, TypeException, VisADException
      Gets the default units of the given range components of a FlatField.
      Parameters:
      field - The field to be examined.
      indexes - Indexes of the components in the range of the field.
      types - Expected, compatible types for the components.
      Returns:
      The units of the range components.
      Throws:
      IllegalArgumentException - field == null || indexes.length != types.length, or indexes out-of-bounds.
      TypeException - Type of component in range of field not compatible with expected type.
      VisADException - Couldn't create necessary VisAD object.
    • clone

      public static RealType clone(RealType realType, String name) throws VisADException
      Clones a RealType but changes the name.
      Parameters:
      realType - The realtype to be cloned.
      name - The new name for the clone.
      Returns:
      The cloned realtype with the new name.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
    • isCompatible

      public static boolean isCompatible(Data data, MathType type) throws VisADException, RemoteException
      Indicates if a Data object is compatible with a MathType.
      Parameters:
      data - The Data object.
      type - The MathType.
      Returns:
      true if and only if the given Data object is compatible with the given MathType.
      Throws:
      VisADException - if a VisAD failure occurs.
      RemoteException - if a Java RMI failure occurs.
    • vetType

      public static Data vetType(MathType type, Data data) throws TypeException, VisADException, RemoteException
      Vets a data object against a MathType. The data object must be compatible with the MathType or an exception is thrown.

      This method should probably become MathType.vet(Data).

      Parameters:
      type - The MathType that the data object must be compatible with.
      data - The data object.
      Returns:
      data (as a programming convenience).
      Throws:
      TypeException - The MathType and data object are incompatible.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • ensureUnit

      public static RealType ensureUnit(RealType type, Unit u) throws VisADException
      Ensure that the units for the RealType are compatible with the given unit.
      Parameters:
      type - RealType to check
      u - unit to check
      Returns:
      the original RealType or a RealType with compatible units.
      Throws:
      VisADException - couldn't get a new RealType
    • getCompatibleUnitName

      public static String getCompatibleUnitName(Unit u)
      Replace illegal RealType characters in a Unit spec with underscores.
      Parameters:
      u - Unit
      Returns:
      a compatible unit name
    • cleanName

      public static String cleanName(String name)
      Make a valid VisAD RealType name from the string. Remove spaces, "." and parens.
      Parameters:
      name - name to clean
      Returns:
      cleaned up name
    • ensureUnit

      public static RealType[] ensureUnit(RealType[] types, Unit u) throws VisADException
      Ensure that the units for the array of RealTypes are compatible with the given unit.
      Parameters:
      types - array of RealTypes to check
      u - unit to check
      Returns:
      the original RealTypes or an array of RealTypes with compatible units.
      Throws:
      VisADException - couldn't get a new RealType
    • ensureMathType

      public static Data ensureMathType(Data data, MathType type) throws UnimplementedException, VisADException, RemoteException
      Ensures that a data object has a particular MathType. Clones the data object only if necessary.

      This method should probably become "abstract Data Data.ensureMathType(MathType)" with subclass-dependent implementations.

      Parameters:
      data - The data object.
      type - The type for the returned data object. Must be compatible with the current type of the data object. The data object will be cloned only if necessary.
      Returns:
      A data object with the given MathType.
      Throws:
      UnimplementedException - Method not yet implemented.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • ensureDomain

      public static Field ensureDomain(Field field, Set domain) throws UnimplementedException, VisADException, RemoteException
      Ensures that a Field has a particular domain Set. Clones the Field only if necessary.
      Parameters:
      field - The Field the have a particular domain Set.
      domain - The particular domain Set for the Field to have. Must be compatible with the Field's existing domain set.
      Returns:
      The Field with the particular domain set.
      Throws:
      UnimplementedException - Can't yet clone the class of the Field.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • ensureDomain

      public static Field ensureDomain(Field field, RealTupleType newDomainType, CoordinateSystem coordinateSystem) throws UnimplementedException, VisADException, RemoteException
      Ensures that a Field has a particular domain MathType. Clones the Field only if necessary.
      Parameters:
      field - The Field the have a particular domain Set.
      newDomainType - The particular MathType for the domain of the Field to have. Coordinate conversions are done if and when necessary and possible.
      coordinateSystem - The CoordinateSystem which, together with newDomainType, form the basis for the desired domain. May be null.
      Returns:
      The Field with the particular domain set.
      Throws:
      UnimplementedException - Can't yet clone the class of the Field.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • ensureTupleRange

      public static Field ensureTupleRange(Field field) throws RemoteException, VisADException
      Ensures that the range of a Field is a Tuple.
      Parameters:
      field - The Field.
      Returns:
      A Field identical to the input field but with a Tuple range. May be the same field. The range will be a RealTuple if possible.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • clone

      public static Field clone(Field field, Set domain) throws UnimplementedException, VisADException, RemoteException
      Clones a Field replacing the domain Set and copying the range values.
      Parameters:
      field - The Field to be cloned..
      domain - The domain Set for the cloned Field to have. Must be compatible with the Field's existing domain set.
      Returns:
      A clone of the Field with the particular domain set.
      Throws:
      UnimplementedException - Can't yet clone the class of the Field.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • clone

      public static Field clone(Field field, Set domain, boolean copyRange) throws UnimplementedException, VisADException, RemoteException
      Clones a Field replacing the domain Set.
      Parameters:
      field - The Field to be cloned.
      domain - The domain Set for the cloned Field to have. Need only be topologically equivalent to the Field's existing domain set.
      copyRange - If true then the range of the old Field will be copied to the new Field; otherwise not.
      Returns:
      A clone of the Field with the particular domain set.
      Throws:
      UnimplementedException - Can't yet clone the class of the Field.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • clone

      public static FlatField clone(FlatField flatField, Set domain, boolean copyRange) throws VisADException, RemoteException
      Clones a FlatField replacing the domain Set. The actual range units in the clone may differ from those of the input FlatField.
      Parameters:
      flatField - The FlatField to be cloned.
      domain - The domain Set for the cloned FlatField to have. Need only be topologically equivalent to existing domain.
      copyRange - If true then the range of the old FlatField will be copied to the new Field; otherwise not.
      Returns:
      A clone of the FlatField with the particular domain set.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • convertDomain

      public static Field convertDomain(Field field, RealTupleType newDomainType, CoordinateSystem coordinateSystem) throws UnimplementedException, VisADException, RemoteException
      Converts the MathType of the domain of a Field.
      Parameters:
      field - The Field to be converted.
      newDomainType - The MathType of the domain for the converted Field to have. Coordinate conversions are done if and when necessary and possible.
      coordinateSystem - The CoordinateSystem which, together with newDomainType, form the basis for the desired domain. May be null.
      Returns:
      A clone of the Field with the particular domain type.
      Throws:
      UnimplementedException - Can't yet clone the class of the Field.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • convertDomain

      public static FlatField convertDomain(FlatField field, RealTupleType newDomainType, CoordinateSystem coordinateSystem) throws VisADException, RemoteException
      Converts the domain of a FlatField.
      Parameters:
      field - The FlatField to be converted.
      newDomainType - The MathType for the converted FlatField. Coordinate conversions are done if and when necessary and possible.
      coordinateSystem - The CoordinateSystem which, together with newDomainType, form the basis for the desired domain. May be null.
      Returns:
      A copy of the input Field but with the domain converted to the new MathType.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • convertDomain

      public static SampledSet convertDomain(SampledSet oldDomain, RealTupleType newDomainType, CoordinateSystem coordinateSystem) throws VisADException, RemoteException
      Converts a SampledSet domain.
      Parameters:
      oldDomain - The domain to be converted.
      newDomainType - The type of the new domain.
      coordinateSystem - The CoordinateSystem which, together with newDomainType, form the basis for the desired domain. May be null.
      Returns:
      The old domain converted into the new type. Coordinate system transformations are done if and when necessary and possible.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • newSampledSet

      public static SampledSet newSampledSet(SampledSet oldSampledSet, float[][] newValues, int[] manifoldLengths) throws VisADException, RemoteException
      Creates a new SampledSet based on an existing SampledSet and new values.
      Parameters:
      oldSampledSet - The existing SampledSet.
      newValues - The values for the new SampledSet.
      manifoldLengths - The manifold dimensionality (i.e. the number and size of each dimension). May be null in which case an IrregularSet is created and returned; otherwise, the first element is the size of the innermost dimension, etc.
      Returns:
      The new SampledSet corresponding to the input arguments.
      Throws:
      VisADException - Couldn't perform necessary VisAD operation.
      RemoteException - Java RMI failure.
    • newSampledSet

      public static SampledSet newSampledSet(SampledSet oldSampledSet, double[][] newValues, int[] manifoldLengths) throws VisADException, RemoteException
      Creates a new SampledSet based on an existing SampledSet and new values.
      Parameters:
      oldSampledSet - The existing SampledSet.
      newValues - The values for the new SampledSet.
      manifoldLengths - The manifold dimensionality (i.e. the number and size of each dimension). May be null in which case an IrregularSet is created and returned; otherwise, the first element is the size of the innermost dimension, etc.
      Returns:
      The new SampledSet corresponding to the input arguments.
      Throws:
      VisADException - Couldn't perform necessary VisAD operation.
      RemoteException - Java RMI failure.
    • newSampledSet

      public static SampledSet newSampledSet(SampledSet oldSampledSet, RealTupleType newSampledSetType, float[][] newValues, CoordinateSystem coordinateSystem, Unit[] newUnits, ErrorEstimate[] newErrors) throws VisADException, RemoteException
      Creates a new SampledSet using the topology of an existing SampledSet.
      Parameters:
      oldSampledSet - The old SampledSet to be used for the topology of the new SampledSet.
      newSampledSetType - The type of the new SampledSet.
      newValues - The values for the new SampledSet.
      coordinateSystem - The CoordinateSystem for the new SampledSet.
      newUnits - The units for the new SampledSet.
      newErrors - The new ErrorEstimate-s for the new SampledSet.
      Returns:
      The new SampledSet corresponding to the input arguments.
      Throws:
      VisADException - Couldn't perform necessary VisAD operation.
      RemoteException - Java RMI failure.
    • newSampledSet

      public static SampledSet newSampledSet(SampledSet oldSampledSet, RealTupleType newSampledSetType, double[][] newValues, CoordinateSystem coordinateSystem, Unit[] newUnits, ErrorEstimate[] newErrors) throws VisADException, RemoteException
      Creates a new SampledSet using the topology of an existing SampledSet.
      Parameters:
      oldSampledSet - The old SampledSet to be used for the topology of the new SampledSet.
      newSampledSetType - The type of the new SampledSet.
      newValues - The values for the new SampledSet.
      coordinateSystem - The CoordinateSystem for the new SampledSet.
      newUnits - The units for the new SampledSet.
      newErrors - The new ErrorEstimate-s for the new SampledSet.
      Returns:
      The new SampledSet corresponding to the input arguments.
      Throws:
      VisADException - Couldn't perform necessary VisAD operation.
      RemoteException - Java RMI failure.
    • newSampledSet

      public static SampledSet newSampledSet(int[] manifoldLengths, RealTupleType newSampledSetType, double[][] newValues, CoordinateSystem coordinateSystem, Unit[] newUnits, ErrorEstimate[] newErrors) throws VisADException, RemoteException
      Creates a new SampledSet using a given manifold dimensionality.
      Parameters:
      manifoldLengths - The manifold dimensionality (i.e. the number and size of each dimension). May be null in which case an IrregularSet is created and returned; otherwise, the first element is the size of the innermost dimension, etc.
      newSampledSetType - The type of the new SampledSet.
      newValues - The values for the new SampledSet.
      coordinateSystem - The CoordinateSystem for the new SampledSet.
      newUnits - The units for the new SampledSet.
      newErrors - The new ErrorEstimate-s for the new SampledSet.
      Returns:
      The new SampledSet corresponding to the input arguments. Will be an IrregularSet, a GriddedSet, or a SingletonSet.
      Throws:
      VisADException - Couldn't perform necessary VisAD operation.
      RemoteException - Java RMI failure.
    • newSampledSet

      public static SampledSet newSampledSet(int[] manifoldLengths, RealTupleType newSampledSetType, float[][] newValues, CoordinateSystem coordinateSystem, Unit[] newUnits, ErrorEstimate[] newErrors) throws VisADException, RemoteException
      Creates a new SampledSet using a given manifold dimensionality.
      Parameters:
      manifoldLengths - The manifold dimensionality (i.e. the number and size of each dimension). May be null in which case an IrregularSet is created and returned; otherwise, the first element is the size of the innermost dimension, etc.
      newSampledSetType - The type of the new SampledSet.
      newValues - The values for the new SampledSet.
      coordinateSystem - The CoordinateSystem for the new SampledSet.
      newUnits - The units for the new SampledSet.
      newErrors - The new ErrorEstimate-s for the new SampledSet.
      Returns:
      The new SampledSet corresponding to the input arguments. Will be an IrregularSet, a GriddedSet, or a SingletonSet.
      Throws:
      VisADException - Couldn't perform necessary VisAD operation.
      RemoteException - Java RMI failure.
    • getRangeCoordinateSystem

      public static CoordinateSystem getRangeCoordinateSystem(Field field) throws VisADException, RemoteException
      Gets the coordinate sytem of the RealTuple range of a Field.
      Parameters:
      field - The Field.
      Returns:
      The CoordinateSystem of the range of the Field if appropriate; otherwise null.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • getRangeCoordinateSystems

      public static CoordinateSystem[] getRangeCoordinateSystems(Field field) throws VisADException, RemoteException
      Gets the coordinate sytems of the components of the range of a Field.
      Parameters:
      field - The Field.
      Returns:
      The CoordinateSystems of the components of the range of the Field if appropriate; otherwise, null.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • getRangeUnits

      public static Unit[] getRangeUnits(FlatField field)
      Gets the units of the (flat) components of the range of a FlatField.
      Parameters:
      field - The FlatField.
      Returns:
      The units of the (flat) components of the range of the FlatField. Won't be null.
    • getDefaultRangeUnits

      public static Unit[] getDefaultRangeUnits(FieldImpl field)
      Gets the default units of the (flat) components of the range of a FlatField.
      Parameters:
      field - The FlatField.
      Returns:
      The default units of the (flat) components of the range of the FlatField. Won't be null.
    • clone

      public static Data clone(Data data, MathType type) throws UnimplementedException, VisADException, RemoteException
      Clones a data object, replacing the MathType. If the input data object is a FlatField, then the actual range units of the clone may differ from those of the input data object.

      This method should probably become "abstract Data Data.clone(MathType)" with subclass-dependent implementations.

      Parameters:
      data - The data object to be cloned.
      type - The type for the returned data object. Must be compatible with the current type of the data object.
      Returns:
      The cloned data object with the new MathType.
      Throws:
      UnimplementedException - Method not yet implemented.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • getDomainSet

      public static Set getDomainSet(Field field)
      Utility method to get the domain set from the given field. This is a bit of a hack in that it checks if the field is a AreaImageFlatField. If it is then call a special getDomainSetNoRead method
      Parameters:
      field - The field
      Returns:
      Its domain set
    • getDomainSetForClone

      public static Set getDomainSetForClone(Field field)
      Get the domain for cloning
      Parameters:
      field - the field
      Returns:
      the domain
    • clone

      public static Data clone(Data data, MathType type, boolean unitOverride, boolean copy) throws UnimplementedException, VisADException, RemoteException
      Clones a data object, replacing the MathType. If the input data object is a FlatField, then the actual range units of the clone may differ from those of the input data object.

      This method should probably become "abstract Data Data.clone(MathType)" with subclass-dependent implementations.

      Parameters:
      data - The data object to be cloned.
      type - The type for the returned data object. Must be compatible with the current type of the data object.
      unitOverride - if the units are not compatible, if true, assume values are in units of new type.
      copy - if true, copy the data values for Fields.
      Returns:
      The cloned data object with the new MathType.
      Throws:
      UnimplementedException - Method not yet implemented.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • clone

      public static Data clone(Data data, MathType type, boolean unitOverride, boolean copy, boolean copyDomain) throws UnimplementedException, VisADException, RemoteException
      Clones a data object, replacing the MathType. If the input data object is a FlatField, then the actual range units of the clone may differ from those of the input data object.

      This method should probably become "abstract Data Data.clone(MathType)" with subclass-dependent implementations.

      Parameters:
      data - The data object to be cloned.
      type - The type for the returned data object. Must be compatible with the current type of the data object.
      unitOverride - if the units are not compatible, if true, assume values are in units of new type.
      copy - if true, copy the data values for Fields.
      copyDomain - if true, make a copy of the domain as well
      Returns:
      The cloned data object with the new MathType.
      Throws:
      UnimplementedException - Method not yet implemented.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • ensureCoordinateSystem

      public static Set ensureCoordinateSystem(Set set, CoordinateSystem coordSys) throws UnimplementedException, VisADException, RemoteException
      Ensures that a set has a particular CoordinateSystem. Clones the set only if necessary

      This method should probably become "abstract Set Set.ensureCoordinateSystem(CoordinateSystem)".

      Parameters:
      set - The set.
      coordSys - The CoordinateSystem for the returned Set. May be null.
      Returns:
      A set like set with the given coordinate system. Clones the set only if necessary.
      Throws:
      UnimplementedException - Can't clone set.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • clone

      public static Set clone(Set set, CoordinateSystem coordSys) throws UnimplementedException, VisADException, RemoteException
      Clones a set, replacing the CoordinateSystem.

      This method should probably become "abstract Set Set.clone(CoordinateSystem)".

      Parameters:
      set - The set to be cloned.
      coordSys - The CoordinateSystem for the returned Set. May be null.
      Returns:
      A clone of set but with the given CoordinateSystem.
      Throws:
      UnimplementedException - Method not yet implemented for particular set.
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • getRangeSampledSet

      public static SampledSet getRangeSampledSet(Field field, MathType type) throws VisADException, RemoteException
      Extracts the given range component from a Field as a SampledSet.
      Parameters:
      field - The field to have a component extracted.
      type - The MathType of the component to be extracted.
      Returns:
      The SampledSet of component values.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • ensureFlatFieldRangeType

      public static FlatField ensureFlatFieldRangeType(FlatField flatField, RealType realType) throws VisADException, RemoteException
      Ensures that the MathType of the range of a FlatField is a specified RealType. Clones the FlatField only if necessary.
      Parameters:
      flatField - The FlatField to have it's range be type.
      realType - The type for the returned FlatField.
      Returns:
      A FlatField identical to flatFieldield with realType as the MathType of the range. May be flatField.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • newSampledSet

      public static SampledSet newSampledSet(MathType type, float[][] values, int[] manifoldLengths, CoordinateSystem coordinateSystem, Unit[] units, ErrorEstimate[] errors, boolean copy) throws VisADException, RemoteException
      Creates a new SampledSet.
      Parameters:
      type - The type for the SampledSet.
      values - The values for the SampledSet.
      manifoldLengths - The dimensionality of the manifold with the first element corresponding to the innermost manifold dimension. Ignored if the values constitute a single data point. May be null, in which case the manifold is assumed to be 1-dimensional and the resulting set will be an IrregularSet. If non- null, then the resulting set will be a GriddedSet.
      coordinateSystem - The coordinate system transformation for the SampledSet. May be null.
      units - The units of the values. May be null.
      errors - The uncertainty of the values. May be null.
      copy - Whether or not to copy the values.
      Returns:
      A SampledSet with the given attributes.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure.
    • getSample

      public static RealTuple getSample(Set set, int index) throws VisADException, RemoteException
      Gets the specified sample of a VisAD Set.
      Parameters:
      set - The set to have a sample returned.
      index - The index of the sample to be returned.
      Returns:
      The sample at the specified index. Will be empty if the index is out-of-bounds. Will have a single component if the set is one-dimensional.
      Throws:
      VisADException - Couldn't create necessary VisAD object.
      RemoteException - Java RMI failure. deprecated use visad.util.DataUtility.getSample() now
    • take

      public static float[] take(float[] values, int[] indexes)
      Takes indicated values from an array.
      Parameters:
      values - The input array of values.
      indexes - Which elements to extract.
      Returns:
      A new array with the indicated elements.
    • take

      public static double[] take(double[] values, int[] indexes)
      Takes indicated values from an array.
      Parameters:
      values - The input array of values.
      indexes - Which elements to extract.
      Returns:
      A new array with the indicated elements.
    • isSorted

      public static boolean isSorted(float[] values)
      Indicates if an array is sorted. The sense (increasing or decreasing) is irrelevant and is non-strict.
      Parameters:
      values - The array to check.
      Returns:
      True if and only if the array is sorted.
    • isSorted

      public static boolean isSorted(double[] values)
      Indicates if an array is sorted. The sense (increasing or decreasing) is irrelevant and is non-strict.
      Parameters:
      values - The array to check.
      Returns:
      True if and only if the array is sorted.
    • isStrictlySorted

      public static boolean isStrictlySorted(float[] values)
      Indicates if an array is strictly sorted. The sense (increasing or decreasing) is irrelevant.
      Parameters:
      values - The array to check.
      Returns:
      True if and only if the array is strictly sorted.
    • isStrictlySorted

      public static boolean isStrictlySorted(double[] values)
      Indicates if an array is strictly sorted. The sense (increasing or decreasing) is irrelevant.
      Parameters:
      values - The array to check.
      Returns:
      True if and only if the array is strictly sorted.
    • sortedIndexes

      public static int[] sortedIndexes(float[] values, boolean increasing)
      Returns the element indexes that would sort an array. The first elements of the output index array will index the NaN-s in the input array, if any.
      Parameters:
      values - The array to examine.
      increasing - Whether the sort is to be increasing or decreasing.
      Returns:
      The indexes of the elements that would sort the array when taken in order. The first indexes will index the NaN-s of the input array, if any.
    • sortedIndexes

      public static int[] sortedIndexes(double[] values, boolean increasing)
      Returns the element indexes that would sort an array. The first elements of the output index array will index the NaN-s in the input array, if any.
      Parameters:
      values - The array to examine.
      increasing - Whether the sort is to be increasing or decreasing.
      Returns:
      The indexes of the elements that would sort the array when taken in order. The first indexes will index the NaN-s of the input array, if any.
    • strictlySortedIndexes

      public static int[] strictlySortedIndexes(float[] values, boolean increasing)
      Returns the element indexes that would strictly sort an array. Nan-s in the input array will be ignored.
      Parameters:
      values - The array to examine.
      increasing - Whether the sort is to be increasing or decreasing.
      Returns:
      The indexes of the elements that would strictly sort the array when taken in order.
    • strictlySortedIndexes

      public static int[] strictlySortedIndexes(double[] values, boolean increasing)
      Returns the element indexes that would strictly sort an array. Nan-s in the input array will be ignored.
      Parameters:
      values - The array to examine.
      increasing - Whether the sort is to be increasing or decreasing.
      Returns:
      The indexes of the elements that would strictly sort the array when taken in order.
    • getRealType

      public static RealType getRealType(RealTupleType type, String start) throws VisADException
      Get the RealType from the RealTupleType that corresponds to one that begins with start.
      Parameters:
      type - type to search
      start - starting characters of name. This is useful when Plain import creates names like "pres_0"
      Returns:
      RealType that matches or null if no match
      Throws:
      VisADException
    • parseUnit

      public static Unit parseUnit(String unitIdentifier) throws VisADException
      Parse a unit string specification and return the appropriate unit. Handles some non-standard units.
      Parameters:
      unitIdentifier - unit specification
      Returns:
      unit that corresponds to that specification
      Throws:
      VisADException - problem parsing unit
    • parseUnit

      public static Unit parseUnit(String unitIdentifier, String unitName) throws VisADException
      Parse a unit string specification and return the appropriate unit. Handles some non-standard units.
      Parameters:
      unitIdentifier - unit specification
      unitName - Name to clone unit with
      Returns:
      unit that corresponds to that specification
      Throws:
      VisADException - problem parsing unit
    • formatUtcDate

      public static String formatUtcDate(DateTime dt, String pattern)
      Return a formated date in UTC time. Uses DateTime.formatString() with the UTC (GMT) time zone.
      Parameters:
      dt - DateTime object
      pattern - format pattern
      Returns:
      formatted date. deprecated use UtcDate.formatUtcDate(DateTime, String)
    • makeDate

      public static Date makeDate(DateTime dttm) throws VisADException
      Make a date from a DateTime
      Parameters:
      dttm - DateTime to use
      Returns:
      the Date
      Throws:
      VisADException - problem converting units
    • getGregorianDateTime

      public static DateTime getGregorianDateTime(TimeZone zone, int year, int month, int day, int hour, int min, int sec) throws VisADException
      Make a datetime from a year,...
      Parameters:
      zone - timezone to use
      Returns:
      the DateTime
      Throws:
      VisADException - problem converting units
    • makeDates

      public static List<Date> makeDates(DateTime[] timesArray) throws VisADException
      Make a list of Date object from the array of DateTime's
      Parameters:
      timesArray - array of DateTimes
      Returns:
      a List of Date objects
      Throws:
      VisADException - problem createing the dates
    • toReal

      public static Real toReal(String value) throws Exception
      Parses the given String and returns the Real (if possible) that the string represents. The String may be of the form:
       dddd
       dddd unit
       dddd[unit]
       dddd(unit)
       dddd{unit}
       dddd
       
      Parameters:
      value - The string value
      Returns:
      The real or null if it could not convert the given value
      Throws:
      Exception - problem with unit spec or parsing.
    • toReal

      public static Real toReal(String value, String unitOpener, String unitCloser) throws Exception
      Create a Real from a string value
      Parameters:
      value - numeric value
      unitOpener - character for start of Unit spec
      unitCloser - character for end of Unit spec
      Returns:
      a Real
      Throws:
      Exception - problem parsing the strings or creating the Real
    • distance

      public static double distance(LatLonPoint p1, LatLonPoint p2)
      Return the distance between the 2 points
      Parameters:
      p1 - Point 1
      p2 - Point 2
      Returns:
      The distance
    • toLatLonPoint

      public static ucar.unidata.geoloc.LatLonPointImpl toLatLonPoint(LatLonPoint llp) throws VisADException
      Create a LatLonPointImpl from the VisAD LatLonPoint
      Parameters:
      llp - the LatLonPoint
      Returns:
      the corresponding LatLonPointImpl
      Throws:
      VisADException - problem getting values from LatLonPoint
    • calculateBearing

      public static ucar.unidata.geoloc.Bearing calculateBearing(LatLonPoint pt1, LatLonPoint pt2, ucar.unidata.geoloc.Bearing result) throws VisADException
      Calculate the bearing between the 2 points. See calculateBearing below.
      Parameters:
      pt1 - Point 1
      pt2 - Point 2
      result - Object to use if non-null
      Returns:
      The bearing
      Throws:
      VisADException - When pt2 cannot be converted to the unit of pt1
    • calculateBearing

      public static ucar.unidata.geoloc.Bearing calculateBearing(LatLonPoint pt1, LatLonPoint pt2) throws VisADException
      Calculate the bearing between the 2 points. See calculateBearing below.
      Parameters:
      pt1 - Point 1
      pt2 - Point 2
      Returns:
      The bearing
      Throws:
      VisADException - When pt2 cannot be converted to the unit of pt1
    • formatReal

      public static String formatReal(Real r)
      Format a real value to a nice looking number
      Parameters:
      r - real to format
      Returns:
      formatted value
    • labeledReal

      public static TwoFacedObject labeledReal(Real r)
      Wrap a Real as a TwoFacedObject with a formatted label
      Parameters:
      r - real to wrap
      Returns:
      Real with a nice label
    • labeledReal

      public static TwoFacedObject labeledReal(Real r, boolean includeUnit)
      Wrap a Real as a TwoFacedObject with a formatted label
      Parameters:
      r - real to wrap
      includeUnit - if true, add the unit to the label
      Returns:
      Real with a nice label
    • indexedField

      public static FieldImpl indexedField(Data[] datas, boolean copy) throws VisADException, RemoteException
      Get a FieldImpl with a domain of index and the range of the datas.
      Parameters:
      datas - Data objects for range. Must all be of same type.
      copy - true to copy data.
      Returns:
      FieldImpl of index -> datas.getType()
      Throws:
      RemoteException - Java RMI problem
      VisADException - problem creating field
    • main

      public static void main(String[] args)
      Test
      Parameters:
      args - cmd line args
    • bearingDistance

      public static Real bearingDistance(EarthLocation el1, EarthLocation el2) throws Exception
      Return the distance from a bearing as Real
      Parameters:
      el1 - start location
      el2 - end location
      Returns:
      the distance between them
      Throws:
      Exception - problem calculating the distance
    • getValueAs

      public static double getValueAs(Real r, String unitString) throws VisADException, RemoteException
      Get the value of a Real in the unit specified
      Parameters:
      r - Real
      unitString - string representation of the return Unit
      Returns:
      the value in the unit
      Throws:
      RemoteException - Java RMI Exception
      VisADException - Unit problem
    • getReal

      public static Real getReal(double value, String unitString) throws VisADException, RemoteException
      Get a Real with the specified value and Unit
      Parameters:
      value - the value
      unitString - the Unit
      Returns:
      a Real with the value and Unit
      Throws:
      RemoteException - Java RMI Exception
      VisADException - Unit problem
    • getReal

      public static Real getReal(double value, Unit unit) throws VisADException, RemoteException
      Get a Real with the specified value and Unit
      Parameters:
      value - the value
      unit - the Unit
      Returns:
      a Real with the value and Unit
      Throws:
      RemoteException - Java RMI Exception
      VisADException - Unit problem
    • getRealType

      public static RealType getRealType(Unit unit) throws VisADException, RemoteException
      Get a realtype with the unit
      Parameters:
      unit - unit
      Returns:
      RealType of that unit (or null if unit incompatible with a RealType with the same name)
      Throws:
      RemoteException - Java RMI Exception
      VisADException - Unit problem
    • getRayPositionAtZ

      public static double[] getRayPositionAtZ(VisADRay ray, double zValue)
      Get the position of the ray at a particular Z value.
      Parameters:
      ray - ray to use
      zValue - Z value
      Returns:
      coordinates at Z value
    • cleanTypeName

      public static String cleanTypeName(String name)
      A utility to strip off the unit name that gets appended to the real type name. This also strips off the '(Text)' for text types
      Parameters:
      name - Initial real type name
      Returns:
      name with unit part stripped off
    • cleanTypeName

      public static String cleanTypeName(MathType mathType)
      Remove any of the extra unit suffixes that get added to the type name
      Parameters:
      mathType - the type
      Returns:
      the type name cleaned up
    • getIndex

      public static int getIndex(TupleType tupleType, String lookingFor)
      Find the index of the MathType in the given tuple type whose cleaned name is equals to the lookingFor parameter.
      Parameters:
      tupleType - Tuple type
      lookingFor - String to search for
      Returns:
      The index or -1 if not found
    • makeRealType

      public static RealType makeRealType(String name, Unit unit) throws VisADException
      Create a RealType from the name and unit. The unit is used as part of the name so it should be unique.
      Parameters:
      name - name of type
      unit - can be null
      Returns:
      RealType of form "name_unit"
      Throws:
      VisADException - unable to create the RealType (shouldn't happen)
    • makeRealType

      public static RealType makeRealType(String name, String alias, Unit unit) throws VisADException
      Make a RealType
      Parameters:
      name - name of the RealType
      alias - the alias
      unit - the default unit
      Returns:
      the RealType
      Throws:
      VisADException - problem creating the RealType
    • formatLatLonPoint

      public static String formatLatLonPoint(LatLonPoint llp)
      Format an LatLonPoint as a lat/lon string.
      Parameters:
      llp - LatLonPoint to format
      Returns:
      The formatted LatLonPoint
    • makeEarthLocation

      public static EarthLocation makeEarthLocation(double lat, double lon) throws Exception
      Utility to make an earth location with a 0 altitude
      Parameters:
      lat - latitude
      lon - longitude
      Returns:
      earth location
      Throws:
      Exception - problem creating earth location
    • makeEarthLocation

      public static EarthLocation makeEarthLocation(double lat, double lon, double alt) throws Exception
      Utility to make an earth location with a altitude
      Parameters:
      lat - latitude
      lon - longitude
      alt - longitude
      Returns:
      earth location
      Throws:
      Exception - problem creating earth location
    • makeEarthLocation

      public static EarthLocation makeEarthLocation(LatLonPoint llp) throws Exception
      Utility to make an earth location with a 0 altitude
      Parameters:
      llp - lat/lon
      Returns:
      earth location
      Throws:
      Exception - problem creating earth location
    • formatEarthLocation

      public static String formatEarthLocation(EarthLocation el, boolean includeAlt)
      Format a EarthLocation as a lat/lon/(alt) string.
      Parameters:
      el - EarthLocation to format
      includeAlt - include Altitude in the return
      Returns:
      The formatted lat/lon/alt
    • formatAltitude

      public static String formatAltitude(Real alt)
      Format an Altitude
      Parameters:
      alt - The altitude
      Returns:
      The formatted alt
    • dumpTypes

      public static void dumpTypes(Data d) throws VisADException
      Wrapper for JPythonMethods.dumpTypes(Data)
      Parameters:
      d - the Data object
      Throws:
      VisADException - problem dumping the data
    • getVWorldCoords

      public static double[] getVWorldCoords(DisplayImpl display, int x, int y, double[] retVals)
      Get the VisAD Virtual World x,y coordinates for the given screen coords
      Parameters:
      display - the display
      x - the canvas X coordinate
      y - the canvas Y coordinate
      retVals - the return array (may be null)
      Returns:
      an array of the x,y,z coordinates or null
    • makeField

      public static FlatField makeField(Image image, boolean makeNansForAnyAlpha) throws IOException, VisADException
      Create a VisAD Data object from the given Image
      Parameters:
      image - image to use
      makeNansForAnyAlpha - If true then we make a field with an alpha value and we turn the other values into nan-s
      Returns:
      a FlatField representation of the image
      Throws:
      IOException - problem reading the image
      VisADException - problem creating the FlatField
    • makeField

      public static FlatField makeField(Image image, float alphaThreshold) throws IOException, VisADException
      Create a VisAD Data object from the given Image
      Parameters:
      image - image to use
      alphaThreshold - If there is an alpha channel in the image then set the field value to nan for any alhpa greater than the given threshold. Do nothing if thresholdinvalid input: '<'0 value and we turn the other values into nan-s
      Returns:
      a FlatField representation of the image
      Throws:
      IOException - problem reading the image
      VisADException - problem creating the FlatField
    • makeField

      public static FlatField makeField(Image image, float alphaThreshold, boolean makeAlpha) throws IOException, VisADException
      Create a VisAD Data object from the given Image
      Parameters:
      image - image to use
      alphaThreshold - If there is an alpha channel in the image then set the field value to nan for any alhpa greater than the given threshold. Do nothing if thresholdinvalid input: '<'0 value and we turn the other values into nan-s
      makeAlpha - if true, make an alpha channel as well
      Returns:
      a FlatField representation of the image
      Throws:
      IOException - problem reading the image
      VisADException - problem creating the FlatField
    • makeField

      public static FlatField makeField(Image image, float alphaThreshold, boolean makeAlpha, boolean incNames) throws IOException, VisADException
      Create a VisAD Data object from the given Image
      Parameters:
      image - image to use
      alphaThreshold - If there is an alpha channel in the image then set the field value to nan for any alhpa greater than the given threshold. Do nothing if thresholdinvalid input: '<'0 value and we turn the other values into nan-s
      makeAlpha - if true, make an alpha channel as well
      incNames - if true, make new names
      Returns:
      a FlatField representation of the image
      Throws:
      IOException - problem reading the image
      VisADException - problem creating the FlatField
    • makeMapProjection

      public static MapProjection makeMapProjection(double lat1, double lon1, double lat2, double lon2) throws VisADException
      Make a map projection from the points
      Parameters:
      lat1 - lower left latitude
      lon1 - lower left longitude
      lat2 - upper right latitude
      lon2 - upper right longitude
      Returns:
      a corresponding MapProjection
      Throws:
      VisADException - problem creating the map projection
      VisADException - problem making projection
    • makeMapProjection

      public static MapProjection makeMapProjection(double lat1, double lon1, double lat2, double lon2, boolean makeSquare) throws VisADException
      Make a map projection from the bounds
      Parameters:
      lat1 - min latitude
      lon1 - min longitude
      lat2 - max latitude
      lon2 - max longitude
      makeSquare - if true, normalize to a square
      Returns:
      the MapProjection
      Throws:
      VisADException - problem making the projection or invalid input
    • propertySet

      public static boolean propertySet(Object object, String name, Object value, boolean ignoreError) throws Exception
      Use reflection to find the Method with name "set" + Name. If found then convert the given value to the appropriate type and invoke the method.
      Parameters:
      object - The object to invoke the set property method on.
      name - The name of the method.
      value - The String representation of the value to set.
      ignoreError - If true then don't print out an error
      Returns:
      Did we successfully set the property
      Throws:
      Exception - problem setting the property
    • makeTimeField

      public static Data makeTimeField(Data range, List times) throws VisADException, RemoteException
      This makes a field of T->range for the times in the list. If the times list if null or empty it just returns the range
      Parameters:
      range - The range
      times - List of times
      Returns:
      The time field or the range if times is null
      Throws:
      RemoteException - Java RMI problem
      VisADException - VisAD problem
    • makeTimeField

      public static FieldImpl makeTimeField(List ranges, List times) throws VisADException, RemoteException
      Make a time field
      Parameters:
      ranges - ranges for each time
      times - list of times
      Returns:
      the time field
      Throws:
      RemoteException - Java RMI problem
      VisADException - VisAD problem
    • makeTimeField

      public static FieldImpl[] makeTimeField(Data[] ranges, Object time) throws VisADException, RemoteException
      Make a time field
      Parameters:
      ranges - ranges for each time
      time - list of times
      Returns:
      the time field
      Throws:
      RemoteException - Java RMI problem
      VisADException - VisAD problem
    • makeTimeRangeField

      public static Data makeTimeRangeField(Data range, List times) throws VisADException, RemoteException
      This makes a field of T->range for the times in the list. If the times list if null or empty it just returns the range
      Parameters:
      range - The range
      times - List of times
      Returns:
      The time field or the range if times is null
      Throws:
      RemoteException - Java RMI problem
      VisADException - VisAD problem
    • findIndex

      public static int findIndex(Set set, Real value) throws VisADException, RemoteException
      Find the index of a value in a Set
      Parameters:
      set - the set
      value - the value
      Returns:
      the index or -1 if units not convertible
      Throws:
      RemoteException - Java RMI problem
      VisADException - VisAD problem
    • toList

      public static List toList(Set set) throws VisADException, RemoteException
      Convert the elements in the set to a List
      Parameters:
      set - The set
      Returns:
      The list if items in the set
      Throws:
      RemoteException - Java RMI problem
      VisADException - VisAD problem
    • makeTimeSet

      public static Set makeTimeSet(List times) throws VisADException, RemoteException
      Make a time set from a list of times
      Parameters:
      times - the times
      Returns:
      the Set
      Throws:
      RemoteException - Java RMI problem
      VisADException - VisAD problem
    • exportAsNetcdf

      public static boolean exportAsNetcdf(Data data) throws Exception
      Export the data object as a netCDF file
      Parameters:
      data - the VisAD data to export
      Returns:
      true if successful
      Throws:
      Exception - can't write data as netCDF
    • makeField

      public static FlatField makeField(float lon1, float lon2, int length1, float lat1, float lat2, int length2, float fill, String unitString) throws VisADException, RemoteException
      this makes a empty flat field with the given lat/lon bounds and lengths, the given fill value and the unit
      Parameters:
      lon1 - longitude 1
      lon2 - longitude 2
      length1 - number of lon points
      lat1 - lat 1
      lat2 - lat 2
      length2 - number of lat points
      fill - the fill value for the range
      unitString - the unit
      Returns:
      the field
      Throws:
      RemoteException - on badness
      VisADException - on badness
    • makeEarthDomainSet

      public static GriddedSet makeEarthDomainSet(float[] lats, float[] lons, float[] alts) throws VisADException
      This makes a gridded earth domain set with the given lats, lons and (possible null) alts It uses RealTupleType.LatitudeLongitudeAltitude or RealTupleType.LatitudeLongitudeTuple as the type
      Parameters:
      lats - the lats
      lons - the lons
      alts - the (possibly null) altitudes
      Returns:
      the griddedset
      Throws:
      VisADException - on badness
    • makeEarthDomainSet

      public static GriddedSet makeEarthDomainSet(float[] lats, float[] lons, float[] alts, Unit[] units) throws VisADException
      This makes a gridded earth domain set with the given lats, lons and (possible null) alts It uses RealTupleType.LatitudeLongitudeAltitude or RealTupleType.LatitudeLongitudeTuple as the type
      Parameters:
      lats - the lats
      lons - the lons
      alts - the (possibly null) altitudes
      Returns:
      the griddedset
      Throws:
      VisADException - on badness
    • toLLP

      public static ucar.unidata.geoloc.LatLonPoint toLLP(EarthLocation el)
      convert the visad EarthLocation into a ucar.unidata.geoloc.LatLonPoint
      Parameters:
      el - the earth location
      Returns:
      The LatLonPoint
    • toLLP

      public static ucar.unidata.geoloc.LatLonPoint toLLP(LatLonPoint llp)
      Convert the visad LatLonPoint to a unidata.geoloc.LatLonPoint
      Parameters:
      llp - the visad llp
      Returns:
      the unidata llp
    • convertRange

      public static Range convertRange(Range range, Unit rangeUnit, Unit outUnit)
      Utility to convert the given raw data range into the other units
      Parameters:
      range - data range
      rangeUnit - the unit for the range
      outUnit - the converted unit
      Returns:
      Converted range
    • allMissing

      public static boolean allMissing(RealTuple rt)
      Check to see if a RealTuple is all missing data. RealTuple.isMissing() only checks if it has null components, not if each component is missing.
      Parameters:
      rt - RealTuple in question
      Returns:
      true if RealTuple is null, isMissing() or all Real components have NaN values
    • performRotationAboutArbitraryVector

      public static double[] performRotationAboutArbitraryVector(MouseBehavior mouse, double[] initialTransFormMatrix, double angle, double axisIComp, double axisJComp, double axisKComp, double offsetIComp, double offsetJComp, double offsetKComp)
      Perform rotation about an arbitrary vector
      Parameters:
      mouse - MouseBehavior for matrix manipulation
      initialTransFormMatrix - the initial matrix
      angle - the angle of rotation
      axisIComp - i component of the axis
      axisJComp - j component of the axis
      axisKComp - k component of the axis
      offsetIComp - offset i component
      offsetJComp - offset j component
      offsetKComp - offset k component
      Returns:
      the rotated matrix
    • isEarthCoordinates

      public static boolean isEarthCoordinates(RealTuple position)
      Check if these are earth coordinates
      Parameters:
      position - the position
      Returns:
      true if earth coordinates
    • setGlobeRadius

      public static void setGlobeRadius(float[] position, float radius)
      Set the globe radious based on the position
      Parameters:
      position - the position
      radius - the radius
    • printData

      public static void printData(Data d)
      Print out the data summary. Wrapper around visad.python.JPythonMethods.dumpTypes(Data d)
      Parameters:
      d - the Data to print
    • printDataType

      public static void printDataType(Data d)
      Print out the data type summary. Wrapper around visad.python.JPythonMethods.dumpType(Data d)
      Parameters:
      d - the Data to print