Package ucar.nc2.ogc.erddap.util
Class ErddapEDUnits
- java.lang.Object
-
- ucar.nc2.ogc.erddap.util.ErddapEDUnits
-
public class ErddapEDUnits extends Object
This class has static methods to convert units from one standard to another.
-
-
Field Summary
Fields Modifier and Type Field Description static String[]
metricAcronym
static String[]
metricName
UDUNITS and UCUM support metric prefixes.static int
nMetric
static int
nTwo
static String[]
twoAcronym
UCUM supports power-of-two prefixes, but UDUNITS doesn't.static String[]
twoValue
-
Constructor Summary
Constructors Constructor Description ErddapEDUnits()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static HashMap<String,String>
getHashMapStringString(InputStream inputStream, String charset)
Reads the contents ofinputStream
into a HashMap.static String
ucumToUdunits(String ucum)
This converts UCUM to UDUnits.static String
udunitsToUcum(String udunits)
This converts UDUnits to UCUM.
-
-
-
Field Detail
-
metricName
public static String[] metricName
UDUNITS and UCUM support metric prefixes.
-
metricAcronym
public static String[] metricAcronym
-
nMetric
public static int nMetric
-
twoAcronym
public static String[] twoAcronym
UCUM supports power-of-two prefixes, but UDUNITS doesn't.
-
twoValue
public static String[] twoValue
-
nTwo
public static int nTwo
-
-
Method Detail
-
udunitsToUcum
public static String udunitsToUcum(String udunits)
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
public static String ucumToUdunits(String ucum)
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 ofinputStream
into 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
-
-