testcalendar_val.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifdef HAVE_CONFIG_H
00055 #include <config.h>
00056 #endif
00057
00059 #define _GNU_SOURCE
00060
00061
00062 #ifdef HAVE_SYS_TYPES_H
00063 #include <sys/types.h>
00064 #endif
00065 #ifdef HAVE_SYS_STAT_H
00066 #include <sys/stat.h>
00067 #endif
00068 #ifdef HAVE_FCNTL_H
00069 #include <fcntl.h>
00070 #endif
00071 #ifdef HAVE_UNSTD_H
00072 #include <unistd.h>
00073 #endif
00074 #ifdef HAVE_STDIO_H
00075 #include <stdio.h>
00076 #endif
00077 #ifdef HAVE_STRING_H
00078 #include <string.h>
00079 #endif
00080 #ifdef HAVE_STDLIB_H
00081 #include <stdlib.h>
00082 #endif
00083 #ifdef HAVE_MATH_H
00084 #include <math.h>
00085 #endif
00086 #ifdef HAVE_TIME_H
00087 #include <time.h>
00088 #endif
00089 #ifdef HAVE_LIBGEN_H
00090 #include <libgen.h>
00091 #endif
00092
00093 #include <utils.h>
00094
00096 void show_usage(char *pgm);
00097
00099 int main(int argc, char **argv)
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;
00116 ut_unit *dataunits = NULL;
00117 char time_units[1000];
00118
00119
00120 (void) banner(basename(argv[0]), "1.0", "BEGIN");
00121
00122
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
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
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
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 }
00158
00159
00163 void show_usage(char *pgm) {
00168 (void) fprintf(stderr, "%s: usage:\n", pgm);
00169 (void) fprintf(stderr, "-h: help\n");
00170
00171 }