File: test_decode_time.c

package info (click to toggle)
udunits 2.2.28-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,748 kB
  • sloc: sh: 11,655; ansic: 11,164; xml: 2,619; yacc: 492; lex: 337; makefile: 221
file content (56 lines) | stat: -rw-r--r-- 1,973 bytes parent folder | download | duplicates (4)
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);
}