[udunits] Behavior of ut_decode_time depends on call order?

Hello udunits people,

I've encountered what is, to me, surprising behavior in routine
"ut_decode_time", and I'm wondering if it's a bug or a feature. :)

Specifically, the results returned seem to depend on the order of calls to
other, not-obviously-related udunits-2 routines.  For example, the use of
the ut_decode_time routine is supposed to be related to "encoding [time]
as a double-precision value, which can then be acted upon arithmetically"
(from the udunits-2 docs).  Which would suggest that the values to be
acted upon arithmetically shouldn't have different interpretations
depending on call order. But on my system at least, it (schematically)
does this:

timeval = whatever
ut_decode_time( timeval, etc) gives Date #1
...
ut_decode_time( timeval, etc) gives Date #1 again, as you expect

-but-

timeval = whatever
ut_decode_time( timeval, etc) gives Date #1
...
ut_parse( "days since some origin time" )
...
ut_decode_time( timeval, etc) gives a *different* date, as you don't expect


Minimal example code is appended below that shows this.  The output on my
system (omitting the "definition overrides" warnings) is:

decoding time location A: tval=0.000000  -4713/1/1 0:0:00.000
decoding time location A-2: tval=0.000000  -4713/1/1 0:0:00.000
decoding time location B: tval=0.000000  2001/1/1 0:0 0.000000

Is this expected behavior?

Regards,

--Dave

-------------------------------------------------------------------
David W. Pierce
Division of Climate, Atmospheric Science, and Physical Oceanography
Scripps Institution of Oceanography
(858) 534-8276 (voice)  /  (858) 534-8561 (fax)    dpierce@xxxxxxxx
-------------------------------------------------------------------

code example:

#include <stdio.h>
#include <udunits2.h>
#include <stdlib.h>

#define BUFLEN 1024

/*===========================================================================================================*/
int main( int argc, char *argv[] )
{
        int     year, month, day, hour, minute;
        double  second, resolution;
        double  tval;
        ut_system *unitSystem;
        ut_unit   *utu1;

        /* Initialize unit system */
        unitSystem = ut_read_xml(NULL);
        if( unitSystem == NULL ) {
                fprintf( stderr, "error initializing unit system\n" );
                exit(-1);
                }

        /* Decode a time value of 0, print its date */
        tval = 0.0;
        ut_decode_time( tval, &year, &month, &day, &hour, &minute,
&second, &resolution );
        printf( "decoding time location A: tval=%lf  %d/%d/%d
%d:%d:%06.3lf\n",
                tval, year, month, day, hour, minute, second );

        /* Repeat just to make sure */
        ut_decode_time( tval, &year, &month, &day, &hour, &minute,
&second, &resolution );
        printf( "decoding time location A-2: tval=%lf  %d/%d/%d
%d:%d:%06.3lf\n",
                tval, year, month, day, hour, minute, second );

        /* Parse a timestamp string */
        utu1 = ut_parse( unitSystem, "days since 2010-01-08 11:44",
UT_ASCII );
        if( utu1 == NULL ) {
                fprintf( stderr, "Error parsing unit string with current
date\n" );
                exit(-1);
                }

        /* Repeat decoding a time value of 0, print its date */
        tval = 0.0;
        ut_decode_time( tval, &year, &month, &day, &hour, &minute,
&second, &resolution );
        printf( "decoding time location B: tval=%lf  %d/%d/%d %d:%d %lf\n",
                tval, year, month, day, hour, minute, second );

        return(0);
}





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