Package ucar.nc2.ogc.erddap.util
Class ErddapEDUnits
java.lang.Object
ucar.nc2.ogc.erddap.util.ErddapEDUnits
This class has static methods to convert units from one standard to another.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetHashMapStringString(InputStream inputStream, String charset) Reads the contents ofinputStreaminto a HashMap.static StringucumToUdunits(String ucum) This converts UCUM to UDUnits.static StringudunitsToUcum(String udunits) This converts UDUnits to UCUM.
-
Field Details
-
metricName
UDUNITS and UCUM support metric prefixes. -
metricAcronym
-
nMetric
public static int nMetric -
twoAcronym
UCUM supports power-of-two prefixes, but UDUNITS doesn't. -
twoValue
-
nTwo
public static int nTwo
-
-
Constructor Details
-
ErddapEDUnits
public ErddapEDUnits()
-
-
Method Details
-
udunitsToUcum
This converts UDUnits to UCUM.
UDUnits: https://www.unidata.ucar.edu/software/udunits/udunits-1/etc/udunits.dat https://www.unidata.ucar.edu/software/udunits/udunits-2/udunits2.html I worked with v 2.1.9
UCUM: http://unitsofmeasure.org/ucum.html I worked with Version: 1.8, $Revision: 28894 $UDUnits supports lots of aliases (short and long) and plurals (usually by adding 's'). These all get reduced to UCUM's short and canonical-only units.
Notes:
- This method is a strictly case sensitive.
The only UDUnits that should be capitalized (other than acronyms) are
Btu, Gregorian..., Julian..., PI.
The only UDUnits that may be capitalized are Celsius, Fahrenheit, Kelvin, Rankine. - For "10 to the", UCUM allows 10* or 10^. This method uses 10^.
- NTU becomes {ntu}.
- PSU or psu becomes {psu}.
- This method is a strictly case sensitive.
The only UDUnits that should be capitalized (other than acronyms) are
Btu, Gregorian..., Julian..., PI.
-
ucumToUdunits
This converts UCUM to UDUnits.
UDUnits: https://www.unidata.ucar.edu/software/udunits/udunits-1/etc/udunits.dat https://www.unidata.ucar.edu/software/udunits/udunits-2/udunits2.html
UCUM: http://unitsofmeasure.org/ucum.htmlUCUM tends to be short, canonical-only, and strict. Many UCUM units are the same in UDUnits.
UDUnits supports lots of aliases (short and long) and plurals (usually by adding 's'). This tries to convert UCUM to a short, common UDUNIT units.
Problems:
- UCUM has only "deg", no concept of degree_east|north|true|true.
Notes:
- This method is a strictly case sensitive.
- For "10 to the", UCUM allows 10* or 10^. This method uses 10^.
- {ntu} becomes NTU.
- {psu} becomes PSU.
-
getHashMapStringString
public static HashMap<String,String> getHashMapStringString(InputStream inputStream, String charset) throws IOException Reads the contents ofinputStreaminto a HashMap. Each key-value pair in the input will result in an entry in the map. The specified stream remains open after this method returns.- Parameters:
inputStream- a stream with line-based, key-value pairs.charset- the name of a supportedcharset.- Returns:
- a HashMap initialized from the stream.
- Throws:
IOException- if an I/O error occurs
-