-
Notifications
You must be signed in to change notification settings - Fork 1
/
latstime.h
198 lines (179 loc) · 7.66 KB
/
latstime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* -*-Mode: C;-*-
* Module: LATS time definitions
*
* Copyright: 1996, Regents of the University of California
* This software may not be distributed to others without
* permission of the author.
*
* Author: Bob Drach, Lawrence Livermore National Laboratory
*
* Version: $Id: latstime.h,v 1.4 1996/10/22 19:05:14 fiorino Exp $
*
* Revision History:
*
* $Log: latstime.h,v $
* Revision 1.4 1996/10/22 19:05:14 fiorino
* latsgrib bug in .ctl creator
*
* Revision 1.3 1996/08/20 18:34:12 drach
* - lats_create has a new argument: calendar
* - lats_grid: longitude, latitude dimension vectors are now double
* precision (double, C).
* - lats_vert_dim: vector of levels is now double precision (double,
* C). lats_vert_dim need not be called for single-value/surface
* dimensions, if defined in the parameter table. Multi-valued vertical
* dimensions, such as pressure levels, must be defined with
* lats_vert_dim.
* - lats_var: set level ID to 0 for implicitly defined surface
* dimension.
* - lats_write: level value is double precision (double, C).
* - lats_parmtab: replaces routine lats_vartab.
* - FORTRAN latserropt added: allows program to set error handling
* options.
* - The parameter file format changed.
*
* Revision 1.2 1996/07/12 00:36:28 drach
* - (GRIB) use undefined flag only when set via lats_miss_XX
* - (GRIB) use delta when checking for missing data
* - (GRIB) define maximum and default precision
* - fixed lats_vartab to work correctly.
* - Added report of routine names, vertical dimension types
*
* Revision 1.1 1996/05/03 18:48:07 drach
* - Initial repository version
*
*
*/
/*
* =================================================================
* Macros and Enums
* =================================================================
*/
#ifndef _LATSTIME_H
#define _LATSTIME_H
#include "lats.h"
#define CD_LAST_DAY -1 /* Last day of month */
#define CD_MAX_CHARTIME 48 /* Max characters in character time */
#define CD_MAX_RELUNITS 64 /* Max characters in relative units */
#define CD_MAX_TIME_DELTA 64 /* Max characters in time delta */
#define CD_NULL_DAY 1 /* Null day value */
#define CD_NULL_HOUR 0.0 /* Null hour value */
#define CD_NULL_MONTH 1 /* Null month value */
#define CD_NULL_YEAR 0 /* Null year value, component time */
typedef enum cdMonths {cdJan = 1, cdFeb, cdMar, cdApr, cdMay, cdJun, cdJul, cdAug,
cdSep, cdOct, cdNov, cdDec } cdMonths;
typedef enum cdSeasons {cdDJF = cdDec, /* DJF */
cdMAM = cdMar, /* MAM */
cdJJA = cdJun, /* JJA */
cdSON = cdSep} cdSeasons; /* SON */
typedef enum cdCalenType {cdStandard = LATS_STANDARD, cdJulian = LATS_JULIAN, cdNoLeap = LATS_NOLEAP, cd360 = LATS_360, cdClim = LATS_CLIM, cdClimLeap = LATS_CLIMLEAP, cdClim360 = LATS_CLIM360 } cdCalenType;
/*
* =================================================================
* Structures
* =================================================================
*/
/* Component time */
typedef struct {
long year; /* Year */
short month; /* Numerical month (1..12) */
short day; /* Day of month (1..31) */
double hour; /* Hour and fractional hours */
} cdCompTime;
/*
* =================================================================
* This stuff is used in the original time stuff,
* =================================================================
*/
typedef enum CdMonths {CdJan = 1, CdFeb, CdMar, CdApr, CdMay, CdJun, CdJul, CdAug,
CdSep, CdOct, CdNov, CdDec } CdMonths;
typedef enum CdSeasons {CdWinter = CdDec, /* DJF */
CdSpring = CdMar, /* MAM */
CdSummer = CdJun, /* JJA */
CdFall = CdSep} CdSeasons; /* SON */
typedef enum CdTimeUnit {
CdMinute = 1,
CdHour = 2,
CdDay = 3,
CdWeek = 4, /* Always = 7 days */
CdMonth = 5,
CdSeason = 6, /* Always = 3 months */
CdYear = 7,
CdSecond = 8
} CdTimeUnit;
typedef enum cdUnit {
cdMinute = CdMinute,
cdHour = CdHour,
cdDay = CdDay,
cdWeek = CdWeek, /* Always = 7 days */
cdMonth = CdMonth,
cdSeason = CdSeason, /* Always = 3 months */
cdYear = CdYear,
cdSecond = CdSecond
} cdUnitTime;
#define CdChronCal 0x1
#define CdClimCal 0x0
#define CdBaseRel 0x00
#define CdBase1970 0x10
#define CdHasLeap 0x100
#define CdNoLeap 0x000
#define Cd365 0x1000
#define Cd360 0x0000
#define CdJulianType 0x10000
typedef enum CdTimeType {
CdChron = ( CdChronCal | CdBase1970 | CdHasLeap | Cd365), /* 4369 */
CdJulianCal = ( CdChronCal | CdBase1970 | CdHasLeap | Cd365 | CdJulianType),
CdChronNoLeap = ( CdChronCal | CdBase1970 | CdNoLeap | Cd365), /* 4113 */
CdChron360 = ( CdChronCal | CdBase1970 | CdNoLeap | Cd360), /* 17 */
CdRel = ( CdChronCal | CdBaseRel | CdHasLeap | Cd365), /* 4353 */
CdRelNoLeap = ( CdChronCal | CdBaseRel | CdNoLeap | Cd365), /* 4097 */
CdClim = ( CdClimCal | CdBaseRel | CdNoLeap | Cd365), /* 4096 */
CdClimLeap = ( CdClimCal | CdBaseRel | CdHasLeap | Cd365),
CdClim360 = ( CdClimCal | CdBaseRel | CdNoLeap | Cd365)
} CdTimeType;
#define CdNullYear 0
#define CdNullMonth CdJan
#define CdNullDay 1
#define CdLastDay -1
#define CdNullHour 0.0
typedef struct {
long year; /* e.g., 1979 */
short month; /* e.g., CdDec */
short day; /* e.g., 30 */
double hour; /* hour and fractional hour */
long baseYear; /* base year for relative, 1970 for CdChron */
CdTimeType timeType; /* e.g., CdChron */
} CdTime;
typedef struct {
long count; /* units count */
CdTimeUnit units; /* time interval units */
} CdDeltaTime;
/*
* =================================================================
* Function Prototypes
* =================================================================
*/
extern void latsChar2Comp(cdCalenType timetype, char* chartime, cdCompTime* comptime);
extern void latsChar2Rel(cdCalenType timetype, char* chartime, char* relunits, double* reltime);
extern void latsComp2Char(cdCalenType timetype, cdCompTime comptime, char* time);
extern void latsComp2Rel(cdCalenType timetype, cdCompTime comptime, char* relunits, double* reltime);
extern void latsRel2Char(cdCalenType timetype, char* relunits, double reltime, char* chartime);
extern void latsRel2Comp(cdCalenType timetype, char* relunits, double reltime, cdCompTime* comptime);
extern void latsRel2Rel(cdCalenType timetype, char* relunits, double reltime, char* outunits, double* outtime);
int latsParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTime* base_comptime);
int latsParseDeltaTime(cdCalenType timetype, char* deltaTime, double* value, cdUnitTime* unit);
extern void latsDayOfYear(CdTime *date, int *doy);
extern void latsDaysInMonth(CdTime *date, int *days);
extern void latsMonthDay(int *doy, CdTime *date);
extern void latsc2e(char *ctime, CdTimeType timeType, double *etime, long *baseYear);
extern void latsc2h(char *ctime, CdTimeType timeType, CdTime *htime);
extern void latse2c(double etime, CdTimeType timeType, long baseYear, char *ctime);
extern void latse2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime);
extern void latsh2c(CdTime *htime, char *ctime);
extern void latsh2e(CdTime *htime, double *etime);
extern void latsAddDelTime(double begEtm, long nDel, CdDeltaTime delTime, CdTimeType timeType, long baseYear, double *endEtm);
extern void latsDivDelTime(double begEtm, double endEtm, CdDeltaTime delTime, CdTimeType timeType, long baseYear, long *nDel);
extern int latsToOldTimetype(cdCalenType newtype, CdTimeType* oldtype);
extern void latsTrim(char* s, int n);
extern int latsValidateTime(cdCalenType timetype, cdCompTime comptime);
#endif