cdo_int.h 4.52 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-2016 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.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
#if defined(HAVE_CONFIG_H)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
22
23
24
#  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
28
#include <stdlib.h>
#include <stdbool.h>
29
#include <string.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
30
31
#include <math.h>
#include <float.h>
32
33
#include <ctype.h>
#include <stdarg.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
34

Uwe Schulzweida's avatar
Uwe Schulzweida committed
35
#include "compare.h"
36
#include "timebase.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
37
38
39
40
#include "field.h"
#include "functs.h"
#include "dmemory.h"
#include "process.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
41
#include "const.h"
42
43
#include "util.h"
#include "datetime.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#if defined(_OPENMP)
#define  OPENMP3   200805 
#define  OPENMP4   201307
#define  OPENMP45  201511

#if _OPENMP >= OPENMP3
#define  HAVE_OPENMP3   1
#endif

#if _OPENMP >= OPENMP4
#define  HAVE_OPENMP4   1
#endif

#if _OPENMP >= OPENMP45
#define  HAVE_OPENMP45  1
#endif
61
62
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
63

Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
#ifndef strdupx
Uwe Schulzweida's avatar
Uwe Schulzweida committed
65
66
67
68
69
#ifndef strdup
char *strdup(const char *s);
#endif
#define strdupx  strdup
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
70
71
72
73
#define strdupx(s)			          \
({					      	  \
   const char *__old = (s);			  \
   size_t __len = strlen(__old) + 1;		  \
74
   char *__new = Malloc(__len);	  \
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
76
   (char *) memcpy(__new, __old, __len);	  \
})
Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
78
79
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
80

Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
82
83
#define  cmpstr(s1, s2)          (strncmp(s1, s2, strlen(s2)))
#define  cmpstrlen(s1, s2, len)  (strncmp(s1, s2, len = strlen(s2)))

84

85
/* sxxxYYYYMMDDhhmm0 */
86
87
#define  DATE_LEN  31        /* YYYYMMDDhhmmss allocate DTLEN+1 !!!! */
#define  SET_DATE(dtstr, date, time)      (sprintf(dtstr, "%*d%*d", DATE_LEN-6, date, 6, time))
88
89
#define  DATE_IS_NEQ(dtstr1, dtstr2, len) (memcmp(dtstr1, dtstr2, len) != 0)

90
91
enum T_WEIGHT_MODE {WEIGHT_OFF, WEIGHT_ON};
enum T_EIGEN_MODE  {JACOBI, DANIELSON_LANCZOS};
92

93

Uwe Schulzweida's avatar
Uwe Schulzweida committed
94
#ifndef  M_LN10
95
#define  M_LN10      2.30258509299404568401799145468436421  /* log_e 10 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
96
97
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
#ifndef  M_PI
99
#define  M_PI        3.14159265358979323846264338327950288  /* pi */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
100
101
102
103
104
#endif


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

105
106
#define  MEMTYPE_DOUBLE  1
#define  MEMTYPE_FLOAT   2
Uwe Schulzweida's avatar
Uwe Schulzweida committed
107

108
109
#define  CDO_EXP_LOCAL   1
#define  CDO_EXP_REMOTE  2
110

Uwe Schulzweida's avatar
Uwe Schulzweida committed
111
112
113
114
115
116
117
118
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);

119
int zaxis2ltype(int zaxisID);
120

121
122

int nfc2nlat(int nfc, int ntr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
124
125
126
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
127
128
int compNlon(int nlat);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
129
void param2str(int param, char *paramstr, int maxlen);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
void datetime2str(int date, int time, char *datetimestr, int maxlen);
131
132
void date2str(int date, char *datestr, int maxlen);
void time2str(int time, char *timestr, int maxlen);
133

134
135
136
const char * tunit2str(int tunits);
const char * calendar2str(int calendar);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
void    defineGrid(const char *gridarg);
138
139
void    defineInstitution(const char *instarg);
int     defineTable(const char *tablearg);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
140

Uwe Schulzweida's avatar
Uwe Schulzweida committed
141
void    cdolog(const char *prompt, double cputime);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
142
143
void    cdologs(int noper);
void    cdologo(int noper);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
144
145
146
void    nospec(int vlistID);
void    gridWrite(FILE *fp, int gridID);

147
148
149
void openLock(void);
void openUnlock(void);

150
151
int  cdf_openread(const char *filename);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
152
void printFiletype(int streamID, int vlistID);
153

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

156
off_t fileSize(const char *restrict filename);
157

158
159
char *expand_filename(const char *string);

160
double parameter2double(const char *string);
161
int    parameter2int(const char *string);
162
163
int    parameter2intlist(const char *string);

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
int referenceToGrid(int gridID1);

#ifdef __cplusplus
extern "C" {
#endif

void cdiDefTableID(int tableID);

void gridGenXvals(int xsize, double xfirst, double xlast, double xinc, double *xvals);
void gridGenYvals(int gridtype, int ysize, double yfirst, double ylast, double yinc, double *yvals);

void gaussaw(double *restrict pa, double *restrict pw, size_t nlat);

int qu2reg3_double(double *pfield, int *kpoint, int klat, int klon,
		   double msval, int *kret, int omisng, int operio, int oveggy);

#if defined (__cplusplus)
}
#endif

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