spv.util
Class XUnits

java.lang.Object
  extended by spv.util.Units
      extended by spv.util.XUnits
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Constant
Direct Known Subclasses:
UnknownXUnits, VelocityUnits

public class XUnits
extends Units
implements java.lang.Cloneable, java.io.Serializable

This class supports physical units associated with the independent variable.

The standard units associated with the independent variable is "Angstrom".

Static methods in this class support conversion of entire arrays of double data (for the sake of efficiency).

Currently supported units are:

"Angstrom", "micron", "nm", "cm", "m", "Hz", "kHz", "MHz", "GHz", "THz", "eV", "keV", "MeV", "1/micron".

Note that the "micron" value is specified as the string '?' + "m" since a unicode value is present. Alternate forms are "micron", "microns" and "um", with any capitalization.

Version:
1.0 - 31Jul00
Author:
Ivo Busko (Space Telescope Science Institute)
See Also:
Serialized Form

Nested Class Summary
(package private) static interface XUnits.Converter
           
private static class XUnits.SymmetricalConverter
           
private static class XUnits.WavelengthConverter
           
 
Field Summary
private static java.lang.String ANGSTROM_STRING
           
static java.lang.String BIN_NUMBER
          If units is set to this value, all returned arrays contain bin numbers.
private static java.lang.String CENTIMETER_STRING
           
protected  XUnits.Converter converter
           
protected static KeyedVector converters
           
static java.util.Map<java.lang.String,java.lang.String> correct
           
private static java.lang.String ENERGY_LABEL
           
private static java.lang.String ENERGY_UCD
           
private static java.lang.String EV_STRING
           
private static java.lang.String FREQUENCY_LABEL
           
private static java.lang.String FREQUENCY_UCD
           
private static java.lang.String GHZ_STRING
           
private static java.lang.String HZ_STRING
           
private static java.lang.String KEV_STRING
           
private static java.lang.String KHZ_STRING
           
private static java.lang.String METER_STRING
           
private static java.lang.String MEV_STRING
           
private static java.lang.String MHZ_STRING
           
private static java.lang.String MICRON_STRING
           
private static java.lang.String MILLIMETER_STRING
           
private static java.lang.String NANOMETER_STRING
           
private static java.util.Map<java.lang.String,java.lang.String> sed
           
(package private) static long serialVersionUID
           
private static java.lang.String THZ_STRING
           
private static java.lang.String WAVELENGTH_LABEL
           
private static java.lang.String WAVELENGTH_UCD
           
private static java.lang.String WAVENUMBER_LABEL
           
static java.lang.String WAVENUMBER_STRING
           
private static java.lang.String WAVENUMBER_UCD
           
 
Fields inherited from class spv.util.Units
C, E, ERROR_MSG, H, original_spelling, ucd, UNITLESS, units_string
 
Fields inherited from interface spv.util.Constant
DATA_MARKER, DMAX, DMIN, IINDEF, IMAX, IMIN, MODEL_ID, NORMALIZED_ID, RESIDUALS_ID
 
Constructor Summary
XUnits()
           
XUnits(java.lang.String arg)
          Constructor.
XUnits(XUnits units)
          Constructor.
 
Method Summary
 java.lang.Object clone()
          Returns a clone copy of this object.
static double[] convert(double[] x, XUnits xunit, XUnits nunit)
          Converts independent variable array from one unit to another.
 double convertFromStandardUnits(double value, double avalue)
          Converts argument from standard units to this units.
 double convertToStandardUnits(double value, double avalue)
          Converts argument from this units to standard units.
protected  void getConverterObject()
          Grabs and stores the object that converts this units type to/from standard units.
static java.lang.String GetCorrectSpelling(java.lang.String value)
          Corrects spelling errors.
 java.lang.String getLabel()
          Returns a string appropriate to be used as a label in the X axis.
static Units GetPreferredUnits()
          Returns the preferred independent variable units.
 java.lang.String getSEDSpelling()
          Returns the units string spelled according to SED specs.
static XUnits GetStandardUnits()
          Returns the standard independent variable units.
 java.util.Enumeration getSupportedUnits()
          Returns an Enumeration with the string designations of all supported units for the independent variable.
 java.lang.String getUCD()
          Returns a string appropriate to be used as a UCD.
static java.lang.String[] GetUnitsStrings()
          Gets an array with the strings representing all valid X units.
 boolean isValid()
          Checks if this units instance is internally consistent; that is, its string representation matches one of the supported units types.
static boolean IsValidUnits(Units units)
          Checks if the supplied Units instance is a valid independent variable units.
static void main(java.lang.String[] args)
          Self-test.
 
Methods inherited from class spv.util.Units
equals, getOriginalSpelling, hashCode, setFromString, setUCD, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

converter

protected XUnits.Converter converter

BIN_NUMBER

public static final java.lang.String BIN_NUMBER
If units is set to this value, all returned arrays contain bin numbers.

See Also:
Constant Field Values

ANGSTROM_STRING

private static final java.lang.String ANGSTROM_STRING
See Also:
Constant Field Values

NANOMETER_STRING

private static final java.lang.String NANOMETER_STRING
See Also:
Constant Field Values

MICRON_STRING

private static final java.lang.String MICRON_STRING
See Also:
Constant Field Values

MILLIMETER_STRING

private static final java.lang.String MILLIMETER_STRING
See Also:
Constant Field Values

CENTIMETER_STRING

private static final java.lang.String CENTIMETER_STRING
See Also:
Constant Field Values

METER_STRING

private static final java.lang.String METER_STRING
See Also:
Constant Field Values

EV_STRING

private static final java.lang.String EV_STRING
See Also:
Constant Field Values

KEV_STRING

private static final java.lang.String KEV_STRING
See Also:
Constant Field Values

MEV_STRING

private static final java.lang.String MEV_STRING
See Also:
Constant Field Values

HZ_STRING

private static final java.lang.String HZ_STRING
See Also:
Constant Field Values

KHZ_STRING

private static final java.lang.String KHZ_STRING
See Also:
Constant Field Values

MHZ_STRING

private static final java.lang.String MHZ_STRING
See Also:
Constant Field Values

GHZ_STRING

private static final java.lang.String GHZ_STRING
See Also:
Constant Field Values

THZ_STRING

private static final java.lang.String THZ_STRING
See Also:
Constant Field Values

WAVENUMBER_STRING

public static final java.lang.String WAVENUMBER_STRING
See Also:
Constant Field Values

WAVELENGTH_LABEL

private static final java.lang.String WAVELENGTH_LABEL
See Also:
Constant Field Values

ENERGY_LABEL

private static final java.lang.String ENERGY_LABEL
See Also:
Constant Field Values

FREQUENCY_LABEL

private static final java.lang.String FREQUENCY_LABEL
See Also:
Constant Field Values

WAVENUMBER_LABEL

private static final java.lang.String WAVENUMBER_LABEL
See Also:
Constant Field Values

WAVELENGTH_UCD

private static final java.lang.String WAVELENGTH_UCD
See Also:
Constant Field Values

WAVENUMBER_UCD

private static final java.lang.String WAVENUMBER_UCD
See Also:
Constant Field Values

FREQUENCY_UCD

private static final java.lang.String FREQUENCY_UCD
See Also:
Constant Field Values

ENERGY_UCD

private static final java.lang.String ENERGY_UCD
See Also:
Constant Field Values

correct

public static java.util.Map<java.lang.String,java.lang.String> correct

sed

private static java.util.Map<java.lang.String,java.lang.String> sed

converters

protected static KeyedVector converters
Constructor Detail

XUnits

public XUnits()

XUnits

public XUnits(java.lang.String arg)
Constructor.

This constructor is capable of fixing some common mispellings and alternate spellings.

Parameters:
arg - string with the units

XUnits

public XUnits(XUnits units)
Constructor.

Parameters:
units - a pre-existing XUnits instance
Method Detail

GetCorrectSpelling

public static java.lang.String GetCorrectSpelling(java.lang.String value)
Corrects spelling errors.

Parameters:
value - the input string
Returns:
the correct string

GetUnitsStrings

public static java.lang.String[] GetUnitsStrings()
Gets an array with the strings representing all valid X units.

Returns:
the array with the strings representing all valid X units

isValid

public boolean isValid()
Checks if this units instance is internally consistent; that is, its string representation matches one of the supported units types.

Specified by:
isValid in class Units
Returns:
true if this is a valid instance

getLabel

public java.lang.String getLabel()
Returns a string appropriate to be used as a label in the X axis. The string may look like "Wavelength", "Energy" or "Frequency" depending on the units type.

Specified by:
getLabel in class Units
Returns:
a string with an axis title, or null if the units type is not supported.

getSEDSpelling

public java.lang.String getSEDSpelling()
Returns the units string spelled according to SED specs.

Overrides:
getSEDSpelling in class Units
Returns:
the units string spelled according to SED specs

getUCD

public java.lang.String getUCD()
Returns a string appropriate to be used as a UCD.

Specified by:
getUCD in class Units
Returns:
a string with an axis title, or null if the units type is not supported.

GetStandardUnits

public static XUnits GetStandardUnits()
Returns the standard independent variable units.

Returns:
the standard independent variable units

GetPreferredUnits

public static Units GetPreferredUnits()
Returns the preferred independent variable units.

Returns:
the preferred independent variable units

getSupportedUnits

public java.util.Enumeration getSupportedUnits()
Returns an Enumeration with the string designations of all supported units for the independent variable.

Specified by:
getSupportedUnits in class Units
Returns:
an Enumeration with all supported units for the independent variable

IsValidUnits

public static boolean IsValidUnits(Units units)
Checks if the supplied Units instance is a valid independent variable units.

Parameters:
units - the units to be tested
Returns:
true if the supplied Units instance is a valid independent variable units, false otherwise.

convertToStandardUnits

public double convertToStandardUnits(double value,
                                     double avalue)
Converts argument from this units to standard units.

Specified by:
convertToStandardUnits in class Units
Parameters:
value - the value expressed in this units
avalue - auxiliary value expressed in standard units,. Not used.
Returns:
the value after conversion to standard units

convertFromStandardUnits

public double convertFromStandardUnits(double value,
                                       double avalue)
Converts argument from standard units to this units.

Specified by:
convertFromStandardUnits in class Units
Parameters:
value - the value expressed in standard units
avalue - auxiliary value expressed in standard units. Not used.
Returns:
the value after conversion to this units

getConverterObject

protected void getConverterObject()
Grabs and stores the object that converts this units type to/from standard units. If no conversion is possible/supported, the converter references remain null.

Specified by:
getConverterObject in class Units

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a clone copy of this object.

Overrides:
clone in class Units
Returns:
the clone
Throws:
java.lang.CloneNotSupportedException

convert

public static double[] convert(double[] x,
                               XUnits xunit,
                               XUnits nunit)
                        throws UnitsException
Converts independent variable array from one unit to another.

Parameters:
x - the independent variable array, usually wavelength.
xunit - independent variable units
nunit - independent variable new (output) units
Returns:
new array with the converted values
Throws:
UnitsException - if the units aren't of the appropriate type

main

public static void main(java.lang.String[] args)
Self-test. To run, type this command after running make:

% java spv.util.XUnits