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

[UDUNITS #GXI-877591]: Adding custom unit to XML database


I'm afraid you have a problem. The UDUNITS package was created for units of 
physical quantities -- quantities for which 1 kg of salt has the same mass as 1 
kg of anything else. This is not the case for the international unit, however: 
1 IU of vitamin A is equivalent to 0.3 ug of retinol but 0.6 ug of 
beta-carotene (it's also equivalent to 50 ug of L-ascorbic acid -- assuming it 
would make sense to convert between the two vitamins, which it wouldn't). Such 
quantity-dependent definitions violate the fundamental meaning of "unit" -- 
and, consequently, the assumptions built into the UDUNITS package.

The only way I can think of that the UDUNITS package *might* be able to do what 
you want would be to create an "international unit" for each substance. For 

    <def>0.3 ug</def>
    <def>0.6 ug</def>

Also note that
  * The <name> and <symbol> elements have been moved inside the <aliases> 
  * The element </base> has been removed;
  * The singular form has been changed from "international_units" to 
"..._international_unit" (the plural form will take care of itself);
  * The <singular> element is no longer within the <symbol> element (symbols 
can't be singular or plural; only names can); and
  * The symbol "U" has been eliminated because its reserved for the 
"international unit of enzyme activity", which is not the IU according to 

The attachment of such information to a unit is anathema to me for the reasons 
given in section 7.4 of 
 In my considered opinion, such matters are better handled by a "quantities" 
package rather than a "units" package.

Good luck.

> I have been using the UDUNITS2 library for about a year now.  I've come
> across a unit that isn't in the library and I would like to add it.
> The unit is "Internation Unit" and is a mass or mole based unit for
> measuring quantities of proteins.  The unit is coming from a database
> file, and I'd like to enable conversion of the various proteins from
> U/L to pmol/mL or ng/mL.  I think if I can define U (alias IU, and iU)
> in the database I should be able to do the conversions by multiplying
> a constant of the form mol/U or mg/U to eliminate the U and move on to
> more standard units.
> I've tried to add a new xml file to the database, which would make it
> pretty convenient to add other units as needed.
> <unit-system>
> <import>udunits2-prefixes.xml</import>
> <import>udunits2-base.xml</import>
> <import>udunits2-derived.xml</import>
> <import>udunits2-accepted.xml</import>
> <import>udunits2-common.xml</import>
> <import>udunits2-custom.xml</import>
> </unit-system>
> In my custom file I have:
> <unit-system>
> <unit>
> <!--
> Custom
> -->
> </base>
> <name><singular>international_units</singular></name>
> <symbol>U</symbol>
> <aliases>
> <symbol><singular>iU</singular></symbol>
> <symbol><singular>IU</singular></symbol>
> </aliases>
> </unit>
> </unit-system>
> Can you tell me where I'm going wrong here?

Steve Emmerson

Ticket Details
Ticket ID: GXI-877591
Department: Support UDUNITS
Priority: Normal
Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.