compute_time_info.c File Reference

Compute time info from NetCDF time. More...

#include <io.h>
Include dependency graph for compute_time_info.c:

Go to the source code of this file.

Functions

int compute_time_info (time_vect_struct *time_s, double *timeval, char *time_units, char *cal_type, int ntime)
 Compute time info from NetCDF time.

Detailed Description

Compute time info from NetCDF time.

Definition in file compute_time_info.c.


Function Documentation

int compute_time_info ( time_vect_struct time_s,
double *  timeval,
char *  time_units,
char *  cal_type,
int  ntime 
)

Compute time info from NetCDF time.

Parameters:
[out] time_s Time field in time structure
[in] timeval Time field
[in] time_units Time units (udunits)
[in] cal_type Calendar type (udunits)
[in] ntime Time dimension
Returns:
Status.

Definition at line 67 of file compute_time_info.c.

References alloc_error(), time_vect_struct::day, time_vect_struct::hour, time_vect_struct::minutes, time_vect_struct::month, time_vect_struct::seconds, and time_vect_struct::year.

Referenced by read_field_subdomain_period(), and read_large_scale_fields().

00067                                                                                                           {
00068 
00079   int istat; /* Diagnostic status */
00080   ut_system *unitSystem = NULL; /* Unit System (udunits) */
00081   ut_unit *dataunits = NULL; /* Data units (udunits) */
00082   int t; /* Time loop counter */
00083 
00084   /* Check values of time variable because many times they are all zero. In that case assume a 1 increment and a start at zero. */
00085   for (t=0; t<ntime; t++)
00086     if (timeval[t] != 0.0)
00087       break;
00088   if (t == ntime) {
00089     (void) fprintf(stderr, "WARNING: Time variable values all zero!!! Fixing time variable to index value...\n");
00090     for (t=0; t<ntime; t++)
00091       timeval[t] = (double) t;
00092   }
00093 
00094   /* Compute time info */
00095   time_s->year = (int *) malloc(ntime * sizeof(int));
00096   if (time_s->year == NULL) alloc_error(__FILE__, __LINE__);
00097   time_s->month = (int *) malloc(ntime * sizeof(int));
00098   if (time_s->month == NULL) alloc_error(__FILE__, __LINE__);
00099   time_s->day = (int *) malloc(ntime * sizeof(int));
00100   if (time_s->day == NULL) alloc_error(__FILE__, __LINE__);
00101   time_s->hour = (int *) malloc(ntime * sizeof(int));
00102   if (time_s->hour == NULL) alloc_error(__FILE__, __LINE__);
00103   time_s->minutes = (int *) malloc(ntime * sizeof(int));
00104   if (time_s->minutes == NULL) alloc_error(__FILE__, __LINE__);
00105   time_s->seconds = (double *) malloc(ntime * sizeof(double));
00106   if (time_s->seconds == NULL) alloc_error(__FILE__, __LINE__);
00107 
00108   /* Initialize udunits */
00109   ut_set_error_message_handler(ut_ignore);
00110   unitSystem = ut_read_xml(NULL);
00111   ut_set_error_message_handler(ut_write_to_stderr);
00112 
00113   dataunits = ut_parse(unitSystem, time_units, UT_ASCII);
00114   for (t=0; t<ntime; t++) {
00115     istat = utCalendar2_cal(timeval[t], dataunits, &(time_s->year[t]), &(time_s->month[t]), &(time_s->day[t]),
00116                             &(time_s->hour[t]), &(time_s->minutes[t]), &(time_s->seconds[t]), cal_type);
00117     if (istat < 0) {
00118       (void) ut_free(dataunits);
00119       (void) ut_free_system(unitSystem);  
00120       return -1;
00121     }
00122   }
00123 
00124   (void) ut_free(dataunits);
00125   (void) ut_free_system(unitSystem);  
00126 
00127   /* Success status */
00128   return 0;
00129 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1