[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UDUNITS #WMS-859994]: udunits2 units missing?



Tom,

> I'm having some issues in moving from udunits 1.11.7 to udunits2. I
> initially built with the new stuff (docs said it was backward
> compatible) and left the our software the same which has run great for
> a longtime with the old api calls.  We got numerous errors about two
> units are not convertable and package not initialized:
> 
> 17:13:23.683 Udunits.C PROBLEM: Unable to utConvert  from "kph" to "meter/sec"

I'm not surprised.  "kph" is the SI abbreviation for "kilophot":

$ udunits2
udunits2: Using default XML database
You have: kph
You want: 
    10000000 m⁻²·cd·rad²
You have: phot
You want: 
    10000 m⁻²·cd·rad²
You have: 

Apparently, the old UDUNITS-1 database allowed "kph" but the UDUNITS-2 database 
doesn't.

If you want "kph" (and "KPH") to mean "kilometers per hour", then add the line

    <import>localunits.xml</import>

To the file "$UDUNITS2_HOME/etc/udunits2.xml" and create the file 
"$UDUNITS2_HOME/etc/localunits.xml" with the following:

<?xml version="1.0" encoding="US-ASCII"?>
<!--This file contains locally-defined units that are not part of the UDUNITS-2 
package-->
<unit-system>
    <unit>
        <def>kilometers/hour</def>
        <aliases><name><singular>kph</singular></name></aliases>
    </unit>
</unit-system>

where "$UDUNITS2_HOME" is the installation-point for the UDUNITS-2 package.

> 17:13:23.683 Udunits.C PROBLEM: two units are not convertable
> 17:13:23.683 LdadNetcdfStorage.C PROBLEM: Netcdf var: windGust (float) = 
> '25'. Units conversion from kph to meter/sec failed.
> 17:13:23.683 Udunits.C PROBLEM: Unable to utConvert  from "mmph" to "m/s"
> 17:13:23.683 Udunits.C PROBLEM: package not initialized

If you want "mmph" to mean "millimeters per hour" then do something similar for 
"mmph".

> I'm assuming this has something to do with udunits2 using the new xml
> database and not the old udunits.dat even though the calls are from the
> old api??
> 
> I then changed the api calls to the new format and get similar errors
> from the xml database:
> 
> 16:50:14.759 Udunits.C PROBLEM: An arg violates the function's contract
> (e.g., it's NULL)
> the above error applies to each of these calls below........
> 16:50:09.097 Udunits.C PROBLEM: Unable to convert  from "F" to "Kelvin"
> 16:50:09.097 Udunits.C PROBLEM: Unable to convert  from "mph" to "m/s"
> 16:50:09.433 Udunits.C PROBLEM: Unable to convert  from "iph" to "m/s"
> 16:50:09.570 Udunits.C PROBLEM: Unable to convert  from "kph" to "meter/sec"
> 16:50:09.607 Udunits.C PROBLEM: Unable to convert  from "mmph" to "m/s"
> 16:50:14.633 Udunits.C PROBLEM: Unable to convert  from "F" to "Kelvin"
> 16:50:14.898 Udunits.C PROBLEM: Unable to convert  from "mm" to "m"
> 16:50:15.082 Udunits.C PROBLEM: Unable to convert  from "mB" to "Pa"
> 16:51:19.242 Udunits.C PROBLEM: Unable to convert  from "inHg" to "Pa"
> 16:51:19.242 Udunits.C PROBLEM: Unable to convert  from "knot" to "m/s"
> 16:51:19.253 Udunits.C PROBLEM: Unable to convert  from "inHg" to "Pa"

"F" mean "farad".  "deg_F" means "degrees fahrenheit".  I wouldn't mess with 
this.
"mph" means "milliphot".  You could do something similar to "kph".
"iph" is meaningless.  You could add it locally.
"mm" means "millimeters.  My udunits2(1) utility converts it.
"mB" is meaningless.  "mb" means "millibarn" (a unit of area).  "mbar" means 
"millibars".
"inHg" is meaningless.  "in_Hg" means "inches of mercury".
"knot" means "nautical miles per hour".  My udunits2(1) utility converts it.

> from this block of code:
> 
> fromUnit = ut_get_unit_by_name(_ut_system,fromString.stringPtr());
> if(fromUnit == NULL)
> {
> ut_free(fromUnit);
> return ut_get_status();
> }
> 
> toUnit = ut_get_unit_by_name(_ut_system,toString.stringPtr());
> if(toUnit == NULL)
> {
> ut_free(fromUnit);
> ut_free(toUnit);
> return ut_get_status();
> }
> 
> if(ut_are_convertible(fromUnit, toUnit) == 0)
> {
> errorMsg(ut_get_status());
> logProblem << "Unable to convert  from \"" << fromString << "\"
> to \"" << toString << "\"" << std::endl;
> ut_free(fromUnit);
> ut_free(toUnit);
> return ut_get_status();
> }
> 
> What's strange is that the fromUnit and toUnit are never NULL (they
> never go into the failure NULL block) in the previous calls to
> ut_get_unit_by_name and yet are NULL in the ut_are_convertible call.  I
> am again assuming these units don't exist in this format in the xml
> database. I couldn't find them if they did.
> 
> Should I just alias the names and add them to the common xml file? or
> one of the other xml files?

You can do what I suggested.  I wouldn't touch "F", however.  You might 
discover a mob of angry EE's outside your home.

> Why does a call to ut_get_status() always seem to give me zero? Maybe
> I'm not calling right?

ut_get_status() returns 0 because ut_are_convertible() didn't have any problems.

> The ut system call works fine and I am converting many of the basic
> units...just not the ones above.  I've dug into the docs and the
> archive a bunch and am still confused.  I'm just a little foggy on how
> the xml database works in regards to the aliases or units I might need
> to add....

Yeah.  I didn't document it.  Contact me if you have any questions.

>I'm hoping it's as simple as adding some new xml
> elements...much like we added to the old udunits.dat file...
> 
> Any help is much appreciated.
> Thanks!
> 
> Tom

Regards,
Steve Emmerson

Ticket Details
===================
Ticket ID: WMS-859994
Department: Support UDUNITS
Priority: Normal
Status: Closed