Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

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

[UDUNITS #ZNC-874842]: Outputting UDUnits Slope and Intercept from the API



Peter,

> Full Name: Peter Bosler
> Email Address: pbosler@xxxxxxxx
> Organization: NCAR-SIParCS
> Package Version: UDUnits-2.1.8
> Operating System: Various
> Hardware: Various
> Description of problem: Is there a function in UDUnits2 API similar to  
> ut_get_converter that returns simply the appropriate numerical values for the 
> Slope and Intercept (rather than the whole converter structure)?
> 
> This would be very similar to the output from the UDUnit2 utility when the 
> input is 1 source unit...

With the advent of logarithmic units in the UDUNITS-2 package, it is *very* 
dangerous to assume a Gallilean (i.e., slope/intercept) transformation between 
units, so no, there isn't a function to return such values.

If you know, a priori, that two units have a Gallilean transformation between 
them, then you can use the returned converter to obtain slope and intercept 
values by first converting the value zero (to obtain the intercept) and then 
converting the value one (to obtain the sum of the slope plus the intercept).  
Subtracting the intercept from this latter value will give you the slope.

I strongly advise you not to do this as it probably indicates you're making 
unwarranted assumptions about the units in question, which can lead to brittle 
code.

Regards,
Steve Emmerson

Ticket Details
===================
Ticket ID: ZNC-874842
Department: Support UDUNITS
Priority: Normal
Status: Closed


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690