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

[Support #LXO-177503]: [udunits] Behavior of ut_decode_time depends on call order?



David,

[I moved your email into our support-system.]

> 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?

Congratulations!  You've uncovered a bug in the initialization of the core 
module of the UDUNITS-2 package.

I'm making a new release as I write this.  I'll let you know when it's 
available.

> 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)    address@hidden
> -------------------------------------------------------------------
> 
> 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);
> }

Regards,
Steve Emmerson

Ticket Details
===================
Ticket ID: LXO-177503
Department: Support UDUNITS
Priority: Normal
Status: Open


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.