cdo_int.h 5 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
/*
  This file is part of CDO. CDO is a collection of Operators to
  manipulate and analyse Climate model Data.

5
  Copyright (C) 2003-2013 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
Uwe Schulzweida's avatar
Uwe Schulzweida committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  See COPYING file for copying and redistribution conditions.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

#ifndef _CDO_INT_H
#define _CDO_INT_H

Uwe Schulzweida's avatar
Uwe Schulzweida committed
21
22
23
24
#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
25
#include <assert.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
26
#include <stdio.h>
27
#include <string.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
28
29
30
#include <math.h>
#include <float.h>

31
#include "timebase.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
32
33
34
35
#include "field.h"
#include "functs.h"
#include "dmemory.h"
#include "process.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
#include "const.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
37
38

#ifndef strdupx
Uwe Schulzweida's avatar
Uwe Schulzweida committed
39
40
41
42
43
#ifndef strdup
char *strdup(const char *s);
#endif
#define strdupx  strdup
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
44
45
46
47
48
49
50
#define strdupx(s)			          \
({					      	  \
   const char *__old = (s);			  \
   size_t __len = strlen(__old) + 1;		  \
   char *__new = (char *) malloc(__len);	  \
   (char *) memcpy(__new, __old, __len);	  \
})
Uwe Schulzweida's avatar
Uwe Schulzweida committed
51
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
52
53
#endif

54
55

/* sxxxYYYYMMDDhhmm0 */
56
57
#define  DATE_LEN  31        /* YYYYMMDDhhmmss allocate DTLEN+1 !!!! */
#define  SET_DATE(dtstr, date, time)      (sprintf(dtstr, "%*d%*d", DATE_LEN-6, date, 6, time))
58
59
60
#define  DATE_IS_NEQ(dtstr1, dtstr2, len) (memcmp(dtstr1, dtstr2, len) != 0)


Uwe Schulzweida's avatar
Uwe Schulzweida committed
61
#if defined (__xlC__) /* performance problems on IBM */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
62
63
64
65
#ifndef DBL_IS_NAN
#  define DBL_IS_NAN(x)     ((x) != (x))
#endif
#else
66
#ifndef DBL_IS_NAN
67
#if  defined  (HAVE_DECL_ISNAN)
68
#  define DBL_IS_NAN(x)     (isnan(x))
69
#elif  defined  (FP_NAN)
70
#  define DBL_IS_NAN(x)     (fpclassify(x) == FP_NAN)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
71
#else
72
#  define DBL_IS_NAN(x)     ((x) != (x))
Uwe Schulzweida's avatar
Uwe Schulzweida committed
73
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
74
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76

77
78
79
80
81
#ifndef DBL_IS_EQUAL
/*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
#  define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
82
83
84
85
#ifndef IS_EQUAL
#  define IS_NOT_EQUAL(x,y) (x < y || y < x)
#  define IS_EQUAL(x,y)     (!IS_NOT_EQUAL(x,y))
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
86

87

Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
#ifndef  M_PI
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
#define  M_PI        3.14159265358979323846  /* pi */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
90
91
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
92
#ifndef  M_LN10
Uwe Schulzweida's avatar
Uwe Schulzweida committed
93
#define  M_LN10      2.30258509299404568402  /* log_e 10 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
94
95
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
96
97
98
99
100
101
102
103
104
105
106

#ifndef  RAD2DEG
#define  RAD2DEG  (180./M_PI)   /* conversion for rad to deg */
#endif

#ifndef  DEG2RAD
#define  DEG2RAD  (M_PI/180.)   /* conversion for deg to rad */
#endif

#define  IX2D(y,x,nx)  ((y)*(nx)+(x))

107
108
#define  MEMTYPE_DOUBLE  1
#define  MEMTYPE_FLOAT   2
Uwe Schulzweida's avatar
Uwe Schulzweida committed
109

110
111
#define  CDO_EXP_LOCAL   1
#define  CDO_EXP_REMOTE  2
112

113

114
enum {DATE_FIRST, DATE_LAST, DATE_MIDDLE};
115

Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
117
void strtolower(char *str);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
119
120
121
122
123
124
125
void print_pthread_info(void);

void cdoProcessTime(double *utime, double *stime);

void    setCommandLine(int argc, char **argv);
char   *commandLine(void);
int     readline(FILE *fp, char *line, int len);

126
int zaxis2ltype(int zaxisID);
127
128
129
int ztype2ltype(int zaxistype);
int ltype2ztype(int ltype);

130
131

int nfc2nlat(int nfc, int ntr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
133
134
135
int nlat2ntr(int nlat);
int nlat2ntr_linear(int nlat);
int ntr2nlat(int ntr);
int ntr2nlat_linear(int ntr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
136
137
int compNlon(int nlat);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
138
void param2str(int param, char *paramstr, int maxlen);
139
140
void date2str(int date, char *datestr, int maxlen);
void time2str(int time, char *timestr, int maxlen);
141

142
143
144
145
const char * tunit2str(int tunits);
const char * calendar2str(int calendar);


Uwe Schulzweida's avatar
Uwe Schulzweida committed
146
typedef struct {
147
148
149
150
  int   date;
  int   time;
} datetime_t;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152
153
154
155
typedef struct
{
  datetime_t v;
  datetime_t b[2];
} dtinfo_t;
156
157
158
159
160
161

typedef struct {
  int   julday;
  int   secofday;
} juldate_t;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
162

163
164
165
166
167
juldate_t juldate_encode(int calendar, int date, int time);
void      juldate_decode(int calendar, juldate_t juldate, int *date, int *time);
juldate_t juldate_sub(juldate_t juldate2, juldate_t juldate1);
juldate_t juldate_add_seconds(int seconds, juldate_t juldate);
double    juldate_to_seconds(juldate_t juldate);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
168

169
void    datetime_avg(int dpy, int ndates, datetime_t *datetime);
170
void    datetime_avg_dtinfo(int dpy, int ndates, dtinfo_t *dtinfo);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
171
172
void    taxisInqDTinfo(int taxisID, dtinfo_t *dtinfo);
void    taxisDefDTinfo(int taxisID, dtinfo_t dtinfo);
173

Uwe Schulzweida's avatar
Uwe Schulzweida committed
174
175
176
177
178
179
180
181
int     days_per_month(int calendar, int year, int month);
int     days_per_year(int calendar, int year);
int     calendar_dpy(int calendar);

void    defineGrid(const char *gridarg);
void    defineInstitution(char *instarg);
int     defineTable(char *tablearg);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
182
void    cdolog(const char *prompt, double cputime);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
183
184
void    cdologs(int noper);
void    cdologo(int noper);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
185
186
187
void    nospec(int vlistID);
void    gridWrite(FILE *fp, int gridID);

188
189
190
void openLock(void);
void openUnlock(void);

191
192
int  cdf_openread(const char *filename);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
193
void printFiletype(int streamID, int vlistID);
194

Uwe Schulzweida's avatar
Uwe Schulzweida committed
195
void job_submit(const char *expname, const char *jobfilename, const char *jobname, const char *tmppath, const char *ftppath);
196

Uwe Schulzweida's avatar
Uwe Schulzweida committed
197
198
199
void minmaxval(long nvals, double *array, int *imiss, double *minval, double *maxval);


Uwe Schulzweida's avatar
Uwe Schulzweida committed
200
#endif  /* _CDO_INT_H */