1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#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 );*/
printf( "decoding time location A: tval=%f %d/%d/%d %d:%d:%06.3f\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 B: tval=%lf %d/%d/%d %d:%d:%06.3lf\n",
tval, year, month, day, hour, minute, second );*/
printf( "decoding time location B: tval=%f %d/%d/%d %d:%d:%06.3f\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 );*/
printf( "decoding time location C: tval=%f %d/%d/%d %d:%d:%06.3f\n",
tval, year, month, day, hour, minute, second );
return(0);
}
|