[udunits] Naming Units created by ucar.units.UnitFormat.parse(String)

Hello,

I'm wondering, is there a better way to name Units that were created by parse other than:

       UnitFormat format = UnitFormatManager.instance();
Unit precipRateUnit = format.parse("in per day").clone(UnitName.newUnitName("in per day"));

Aside from being verbose and inefficient (two distinct Unit instances created just to get one that's named), I've found some cases in which Units created in this manner are not compatible with other Units that they should be. For example:

       UnitFormat format = UnitFormatManager.instance();
Unit kelvinUnit = format.parse("kelvin") .clone(UnitName.newUnitName("kelvin")); Unit fahrenUnit = format.parse("fahrenheit").clone(UnitName.newUnitName("fahrenheit"));

System.out.println(kelvinUnit.isCompatible(fahrenUnit)); // Prints "false"

Please advise.

Thanks,
Christian Ward-Garrison





  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the udunits archives: