Package ucar.nc2.units
Class SimpleUnit
java.lang.Object
ucar.nc2.units.SimpleUnit
- Direct Known Subclasses:
TimeUnit
Convenience routines on top of ucar.units package.
The ucar.units package handles
- scientific units, which are factors of the fundamental dimensions such as length, time, mass, etc
- dates, represented as "n units of time since reference date" eg "1203 days since 1970-01-01 00:00:00"
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SimpleUnitstatic final SimpleUnitstatic final SimpleUnit -
Method Summary
Modifier and TypeMethodDescriptiondoubleconvertTo(double value, SimpleUnit outputUnit) Convert given value of this unit to the new unit.static SimpleUnitCreate a SimpleUnit from the given name, catch Exceptions.static SimpleUnitfactoryWithExceptions(String name) Create a SimpleUnit from the given name, allow Exceptions.static doublegetConversionFactor(String inputUnitString, String outputUnitString) Get the conversion factor to convert inputUnit to outputUnit.ucar.units.UnitgetUnit()Get underlying ucar.units.Unit.Extract the simple unit string (no number), eg "s" or "m".doublegetValue()Extract the value, can only be called for ScaledUnit.booleanisCompatible(String unitString) Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other.static booleanisCompatible(String unitString1, String unitString2) Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other.static booleanisCompatibleWithExceptions(String unitString1, String unitString2) Return true if unitString1 is convertible to unitString2static booleanisDateUnit(String unitString) Return true if the given unit is convertible to a date Unit.static booleanisDateUnit(ucar.units.Unit uu) Return true if this ucar.units.Unit is a Date.static booleanisTimeUnit(String unitString) Return true if the given unit is a time Unit, eg "seconds".static booleanisTimeUnit(ucar.units.Unit uu) Return true if this ucar.units.Unit is convertible to secs.booleanIs this an instance of an UnknownUnit?toString()Unit string representation.
-
Field Details
-
kmUnit
-
meterUnit
-
pressureUnit
-
-
Method Details
-
factory
Create a SimpleUnit from the given name, catch Exceptions.- Parameters:
name- parse this name to create a unit.- Returns:
- SimpleUnit, DateUnit, TimeUnit, or null if failed
- See Also:
-
UnitFormat.parse(java.lang.String)
-
factoryWithExceptions
Create a SimpleUnit from the given name, allow Exceptions.- Parameters:
name- parse this name to create a unit.- Returns:
- SimpleUnit, DateUnit, or TimeUnit
- Throws:
ucar.units.UnitException- when date parser fails- See Also:
-
UnitFormat.parse(java.lang.String)
-
isCompatible
Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other. If either unit string is illegal, return false.- Parameters:
unitString1- compare this unitunitString2- compare this unit- Returns:
- true if the 2 units are compatible
-
isCompatibleWithExceptions
public static boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws ucar.units.UnitException Return true if unitString1 is convertible to unitString2- Parameters:
unitString1- compare this unitunitString2- compare this unit- Returns:
- true if the 2 units are compatible
- Throws:
ucar.units.UnitException- if units parsing fails
-
isDateUnit
public static boolean isDateUnit(ucar.units.Unit uu) Return true if this ucar.units.Unit is a Date.- Parameters:
uu- check this Unit- Returns:
- true if its a Date
-
isTimeUnit
public static boolean isTimeUnit(ucar.units.Unit uu) Return true if this ucar.units.Unit is convertible to secs.- Parameters:
uu- check this Unit- Returns:
- true if its a Time
-
isDateUnit
Return true if the given unit is convertible to a date Unit. allowed format is something like:[-]Y[Y[Y[Y]]]-MM-DD[(T| )hh[:mm[:ss[.sss*]]][ [+|-]hh[[:]mm]]]
- Parameters:
unitString- check this unit string- Returns:
- true if its a Date
-
isTimeUnit
Return true if the given unit is a time Unit, eg "seconds".- Parameters:
unitString- check this unit string- Returns:
- true if its a Time
-
getConversionFactor
public static double getConversionFactor(String inputUnitString, String outputUnitString) throws IllegalArgumentException Get the conversion factor to convert inputUnit to outputUnit.- Parameters:
inputUnitString- inputUnit in string formoutputUnitString- outputUnit in string form- Returns:
- conversion factor
- Throws:
IllegalArgumentException- if not convertible
-
toString
Unit string representation. -
getUnit
public ucar.units.Unit getUnit()Get underlying ucar.units.Unit.- Returns:
- underlying ucar.units.Unit.
-
convertTo
Convert given value of this unit to the new unit.- Parameters:
value- value in this unitoutputUnit- convert to this unit- Returns:
- value in outputUnit
- Throws:
IllegalArgumentException- if outputUnit not convertible from this unit
-
isCompatible
Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other. If either unit string is illegal, return false.- Parameters:
unitString- check if this is compatible with unitString- Returns:
- true if compatible
-
isUnknownUnit
public boolean isUnknownUnit()Is this an instance of an UnknownUnit?- Returns:
- true if an instance of an UnknownUnit
-
getValue
public double getValue()Extract the value, can only be called for ScaledUnit.- Returns:
- value of this unit if ScaledUnit, else NaN
-
getUnitString
Extract the simple unit string (no number), eg "s" or "m".- Returns:
- unit string with no value
-
getCanonicalString
-
getImplementingClass
-