Change date origin of time expressed in udunits. More...
#include <utils.h>
Go to the source code of this file.
Functions | |
void | change_date_origin (double *timeout, char *tunits_out, double *timein, char *tunits_in, int ntime) |
Change date origin of time expressed in udunits. |
Change date origin of time expressed in udunits.
Definition in file change_date_origin.c.
void change_date_origin | ( | double * | timeout, | |
char * | tunits_out, | |||
double * | timein, | |||
char * | tunits_in, | |||
int | ntime | |||
) |
Change date origin of time expressed in udunits.
[out] | timeout | Output time vector |
[out] | tunits_out | Output time units (udunits) |
[in] | timein | Input time vector |
[in] | tunits_in | Input time units (udunits) |
[in] | ntime | Number of times |
Definition at line 58 of file change_date_origin.c.
References alloc_error(), and TRUE.
Referenced by read_large_scale_fields().
00058 { 00059 00068 int t; /* Time loop counter */ 00069 int istat; /* Diagnostic status */ 00070 00071 utUnit dataunit_in; /* Input data time units (udunits) */ 00072 utUnit dataunit_out; /* Output data time units (udunits) */ 00073 00074 int *year = NULL; /* Year vector */ 00075 int *month = NULL; /* Month vector */ 00076 int *day = NULL; /* Day vector */ 00077 int *hour = NULL; /* Hour vector */ 00078 int *minutes = NULL; /* Minutes vector */ 00079 float *seconds = NULL; /* Seconds vector */ 00080 00081 /* Initialize udunits */ 00082 if (utIsInit() != TRUE) 00083 istat = utInit(""); 00084 00085 /* Generate time units (udunits) */ 00086 istat = utScan(tunits_in, &dataunit_in); 00087 istat = utScan(tunits_out, &dataunit_out); 00088 00089 /* Allocate memory */ 00090 year = (int *) malloc(ntime * sizeof(int)); 00091 if (year == NULL) alloc_error(__FILE__, __LINE__); 00092 month = (int *) malloc(ntime * sizeof(int)); 00093 if (month == NULL) alloc_error(__FILE__, __LINE__); 00094 day = (int *) malloc(ntime * sizeof(int)); 00095 if (day == NULL) alloc_error(__FILE__, __LINE__); 00096 hour = (int *) malloc(ntime * sizeof(int)); 00097 if (hour == NULL) alloc_error(__FILE__, __LINE__); 00098 minutes = (int *) malloc(ntime * sizeof(int)); 00099 if (minutes == NULL) alloc_error(__FILE__, __LINE__); 00100 seconds = (float *) malloc(ntime * sizeof(float)); 00101 if (seconds == NULL) alloc_error(__FILE__, __LINE__); 00102 00103 /* Parse all times and convert time info */ 00104 for (t=0; t<ntime; t++) { 00105 istat = utCalendar(timein[t], &dataunit_in, &(year[t]), &(month[t]), &(day[t]), &(hour[t]), &(minutes[t]), &(seconds[t])); 00106 istat = utInvCalendar(year[t], month[t], day[t], hour[t], minutes[t], seconds[t], &dataunit_out, &(timeout[t])); 00107 } 00108 00109 /* Free memory */ 00110 (void) free(year); 00111 (void) free(month); 00112 (void) free(day); 00113 (void) free(hour); 00114 (void) free(minutes); 00115 (void) free(seconds); 00116 00117 /* Terminate udunits */ 00118 (void) utTerm(); 00119 }