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 Details

    • 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
  • Constructor Details

    • ErddapEDUnits

      public ErddapEDUnits()
  • Method Details

    • 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}.

      return the UDUnits converted to UCUM. null returns null. "" returns "". throws Exception if trouble.

    • 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.html

      UCUM 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.

      return the UCUM converted to UDUNITS. null returns null. "" returns "".

    • getHashMapStringString

      public static HashMap<String,String> getHashMapStringString(InputStream inputStream, String charset) throws IOException
      Reads the contents of inputStream 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 supported charset.
      Returns:
      a HashMap initialized from the stream.
      Throws:
      IOException - if an I/O error occurs