testcalendar_val.c File Reference

Test calendar conversion functions on one value. More...

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <libgen.h>
#include <utils.h>
Include dependency graph for testcalendar_val.c:

Go to the source code of this file.

Defines

#define _GNU_SOURCE
 GNU extensions.

Functions

void show_usage (char *pgm)
 C prototypes.
int main (int argc, char **argv)
 Main program.

Detailed Description

Test calendar conversion functions on one value.

Definition in file testcalendar_val.c.


Define Documentation

#define _GNU_SOURCE

GNU extensions.

Definition at line 59 of file testcalendar_val.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Main program.

Parameters:
[in] argc Number of command-line arguments.
[in] argv Vector of command-line argument strings.
Returns:
Status.

Definition at line 99 of file testcalendar_val.c.

References banner(), and show_usage().

00100 {
00108   int i;
00109 
00110   int istat;
00111   double val;
00112   int year, month, day, hour, min;
00113   double sec;
00114   
00115   ut_system *unitSystem = NULL; /* Unit System (udunits) */
00116   ut_unit *dataunits = NULL; /* udunits variable */
00117   char time_units[1000];
00118 
00119   /* Print BEGIN banner */
00120   (void) banner(basename(argv[0]), "1.0", "BEGIN");
00121 
00122   /* Get command-line arguments and set appropriate variables */
00123   for (i=1; i<argc; i++) {
00124     if ( !strcmp(argv[i], "-h") ) {
00125       (void) show_usage(basename(argv[0]));
00126       (void) banner(basename(argv[0]), "OK", "END");
00127       return 0;
00128     }
00129     else {
00130       (void) fprintf(stderr, "%s:: Wrong arg %s.\n\n", basename(argv[0]), argv[i]);
00131       (void) show_usage(basename(argv[0]));
00132       (void) banner(basename(argv[0]), "ABORT", "END");
00133       (void) abort();
00134     }
00135   }
00136 
00137   val = 146000;
00138   (void) strcpy(time_units, "days since 0001-01-01");
00139   
00140   /* Initialize udunits */
00141   ut_set_error_message_handler(ut_ignore);
00142   unitSystem = ut_read_xml(NULL);
00143   ut_set_error_message_handler(ut_write_to_stderr);
00144   dataunits = ut_parse(unitSystem, time_units, UT_ASCII);
00145 
00146   // istat = utCalendar(val, &dataunits, &year, &month, &day, &hour, &min, &sec);
00147   istat = utCalendar2_cal(val, dataunits, &year, &month, &day, &hour, &min, &sec, "noleap");
00148   printf("Value=%.0f YYYYMMDD HHmmss %04d %02d %02d %02d:%02d:%02.0f\n", val, year, month, day, hour, min, sec);
00149 
00150   /* Print END banner */
00151   (void) banner(basename(argv[0]), "OK", "END");
00152 
00153   (void) ut_free(dataunits);
00154   (void) ut_free_system(unitSystem);  
00155 
00156   return 0;
00157 }

void show_usage ( char *  pgm  ) 

C prototypes.

Local Subroutines.

Show usage for program command-line arguments.

Parameters:
[in] pgm Program name.

Definition at line 163 of file testcalendar_val.c.

00163                            {
00168   (void) fprintf(stderr, "%s: usage:\n", pgm);
00169   (void) fprintf(stderr, "-h: help\n");
00170 
00171 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1