1 /********************************************************************* 2 * Copyright 2008, University Corporation for Atmospheric Research 3 * See netcdf/COPYRIGHT file for copying and redistribution conditions. 4 * $Id: nctime.h,v 1.6 2010/03/18 19:24:26 russ Exp $ 5 *********************************************************************/ 6 7 #ifndef _NCTIME_H 8 #define _NCTIME_H 9 10 #define CU_FATAL 1 /* Exit immediately on fatal error */ 11 #define CU_VERBOSE 2 /* Report errors */ 12 13 struct bounds_node{ 14 int ncid; /* group (or file) in which variable with associated 15 * bounds variable resides */ 16 int varid; /* has "bounds" attribute naming its bounds variable */ 17 char *bounds_name; /* the named variable, which stores bounds for varid */ 18 struct bounds_node *next; /* next node on list or NULL ifn last list node */ 19 }; 20 21 typedef struct bounds_node bounds_node_t; 22 23 /* 24 * This code was extracted with permission from the CDMS time 25 * conversion and arithmetic routines developed by Bob Drach, Lawrence 26 * Livermore National Laboratory as part of the cdtime library. 27 * Changes and additions were made to support the "-t" option of the 28 * netCDF ncdump utility. 29 * 30 * For the complete time conversion and climate calendar facilities of 31 * the CDMS library, get the original sources from LLNL. 32 */ 33 34 #define CD_MAX_RELUNITS 64 /* Max characters in relative units */ 35 #define CD_MAX_CHARTIME 48 /* Max characters in character time */ 36 #define CD_NULL_DAY 1 /* Null day value */ 37 #define CD_NULL_HOUR 0.0 /* Null hour value */ 38 #define CD_NULL_ID 0 /* Reserved ID */ 39 #define CD_NULL_MONTH 1 /* Null month value */ 40 #define CD_NULL_YEAR 0 /* Null year value, component time */ 41 42 /* Why do we have same enum defined twice? */ 43 44 typedef enum CdTimeUnit { 45 CdBadTimeUnit = 0, 46 CdMinute = 1, 47 CdHour = 2, 48 CdDay = 3, 49 CdWeek = 4, /* Always = 7 days */ 50 CdMonth = 5, 51 CdSeason = 6, /* Always = 3 months */ 52 CdYear = 7, 53 CdSecond = 8 54 } CdTimeUnit; 55 56 typedef enum cdUnitTime { 57 cdBadUnit = CdBadTimeUnit, 58 cdMinute = CdMinute, 59 cdHour = CdHour, 60 cdDay = CdDay, 61 cdWeek = CdWeek, /* Always = 7 days */ 62 cdMonth = CdMonth, 63 cdSeason = CdSeason, /* Always = 3 months */ 64 cdYear = CdYear, 65 cdSecond = CdSecond, 66 cdFraction /* Fractional part of absolute time */ 67 } cdUnitTime; 68 69 #define CdChronCal 0x1 70 #define CdClimCal 0x0 71 #define CdBaseRel 0x00 72 #define CdBase1970 0x10 73 #define CdHasLeap 0x100 74 #define CdNoLeap 0x000 75 #define Cd366 0x2000 76 #define Cd365 0x1000 77 #define Cd360 0x0000 78 #define CdJulianType 0x10000 79 80 typedef enum CdTimeType { 81 CdChron = ( CdChronCal | CdBase1970 | CdHasLeap | Cd365), /* 4369 */ 82 CdJulianCal = ( CdChronCal | CdBase1970 | CdHasLeap | Cd365 | CdJulianType), 83 CdChronNoLeap = ( CdChronCal | CdBase1970 | CdNoLeap | Cd365), /* 4113 */ 84 CdChron360 = ( CdChronCal | CdBase1970 | CdNoLeap | Cd360), /* 17 */ 85 CdRel = ( CdChronCal | CdBaseRel | CdHasLeap | Cd365), /* 4353 */ 86 CdRelNoLeap = ( CdChronCal | CdBaseRel | CdNoLeap | Cd365), /* 4097 */ 87 CdClim = ( CdClimCal | CdBaseRel | CdNoLeap | Cd365), /* 4096 */ 88 CdClimLeap = ( CdClimCal | CdBaseRel | CdHasLeap | Cd365), 89 CdClim360 = ( CdClimCal | CdBaseRel | CdNoLeap | Cd365), 90 CdChron366 = ( CdChronCal | CdBase1970 | CdNoLeap | Cd366) 91 } CdTimeType; 92 93 typedef struct { 94 long year; /* e.g., 1979 */ 95 short month; /* e.g., CdDec */ 96 short day; /* e.g., 30 */ 97 double hour; /* hour and fractional hour */ 98 long baseYear; /* base year for relative, 1970 for CdChron */ 99 CdTimeType timeType; /* e.g., CdChron */ 100 } CdTime; 101 102 #define cdStandardCal 0x11 103 #define cdClimCal 0x0 104 #define cdHasLeap 0x100 105 #define cdHasNoLeap 0x000 106 #define cd366Days 0x2000 107 #define cd365Days 0x1000 108 #define cd360Days 0x0000 109 #define cdJulianCal 0x10000 110 #define cdMixedCal 0x20000 111 112 typedef enum cdCalenType { 113 cdStandard = ( cdStandardCal | cdHasLeap | cd365Days), 114 cdJulian = ( cdStandardCal | cdHasLeap | cd365Days | cdJulianCal), 115 cdNoLeap = ( cdStandardCal | cdHasNoLeap | cd365Days), 116 cd360 = ( cdStandardCal | cdHasNoLeap | cd360Days), 117 cd366 = ( cdStandardCal | cdHasNoLeap | cd366Days), 118 cdClim = ( cdClimCal | cdHasNoLeap | cd365Days), 119 cdClimLeap = ( cdClimCal | cdHasLeap | cd365Days), 120 cdClim360 = ( cdClimCal | cdHasNoLeap | cd360Days), 121 cdMixed = ( cdStandardCal | cdHasLeap | cd365Days | cdMixedCal) 122 } cdCalenType; 123 124 /* Component time */ 125 typedef struct { 126 long year; /* Year */ 127 short month; /* Numerical month (1..12) */ 128 short day; /* Day of month (1..31) */ 129 double hour; /* Hour and fractional hours */ 130 } cdCompTime; 131 132 typedef struct { 133 long count; /* units count */ 134 CdTimeUnit units; /* time interval units */ 135 } CdDeltaTime; 136 137 typedef struct timeinfo_t { 138 cdCalenType calendar; 139 cdUnitTime unit; 140 char *units; 141 cdCompTime origin; 142 } timeinfo_t; 143 144 145 146 #if defined(DLL_NETCDF) /* Defined when library is a DLL */ 147 # if defined(DLL_EXPORT) /* define when building the library. */ 148 # define MSC_NCTIME_EXTRA __declspec(dllexport) 149 # else 150 # define MSC_NCTIME_EXTRA __declspec(dllimport) 151 # endif 152 153 MSC_NCTIME_EXTRA extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime); 154 MSC_NCTIME_EXTRA extern void cdChar2Comp(cdCalenType timetype, char* chartime, cdCompTime* comptime); 155 MSC_NCTIME_EXTRA extern void Cdh2e(CdTime *htime, double *etime); 156 MSC_NCTIME_EXTRA extern void Cde2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime); 157 MSC_NCTIME_EXTRA extern int cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTime* base_comptime); 158 MSC_NCTIME_EXTRA extern int cdSetErrOpts(int opts); 159 #else 160 extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime); 161 extern void cdChar2Comp(cdCalenType timetype, char* chartime, cdCompTime* comptime); 162 extern void Cdh2e(CdTime *htime, double *etime); 163 extern void Cde2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime); 164 extern int cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTime* base_comptime); 165 extern int cdSetErrOpts(int opts); 166 #endif /* DLL Considerations. */ 167 168 169 #endif /* ifdef */ 170