cdo_int.h 4.16 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-2014 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
#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"
37
38
#include "util.h"
#include "datetime.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
39

Uwe Schulzweida's avatar
Uwe Schulzweida committed
40
41
#define  OPENMP4  201307

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

58
59
#define strcompare(s1, s2)  (strncmp(s1, s2, strlen(s2)))

60
61

/* sxxxYYYYMMDDhhmm0 */
62
63
#define  DATE_LEN  31        /* YYYYMMDDhhmmss allocate DTLEN+1 !!!! */
#define  SET_DATE(dtstr, date, time)      (sprintf(dtstr, "%*d%*d", DATE_LEN-6, date, 6, time))
64
65
66
#define  DATE_IS_NEQ(dtstr1, dtstr2, len) (memcmp(dtstr1, dtstr2, len) != 0)


Uwe Schulzweida's avatar
Uwe Schulzweida committed
67
#if defined(__xlC__) /* performance problems on IBM */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
69
70
71
#ifndef DBL_IS_NAN
#  define DBL_IS_NAN(x)     ((x) != (x))
#endif
#else
72
#ifndef DBL_IS_NAN
Uwe Schulzweida's avatar
Uwe Schulzweida committed
73
#if defined(HAVE_DECL_ISNAN)
74
#  define DBL_IS_NAN(x)     (isnan(x))
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
#elif defined(FP_NAN)
76
#  define DBL_IS_NAN(x)     (fpclassify(x) == FP_NAN)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
#else
78
#  define DBL_IS_NAN(x)     ((x) != (x))
Uwe Schulzweida's avatar
Uwe Schulzweida committed
79
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
82

83
84
85
86
87
#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
88
89
90
91
#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
92

93

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
99
#ifndef  M_PI
#define  M_PI        3.14159265358979323846  /* 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);
130
131
void date2str(int date, char *datestr, int maxlen);
void time2str(int time, char *timestr, int maxlen);
132

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
136
137
138
139
140
141
142
143
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
144
void    cdolog(const char *prompt, double cputime);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
145
146
void    cdologs(int noper);
void    cdologo(int noper);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
147
148
149
void    nospec(int vlistID);
void    gridWrite(FILE *fp, int gridID);

150
151
152
void openLock(void);
void openUnlock(void);

153
154
int  cdf_openread(const char *filename);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
155
void printFiletype(int streamID, int vlistID);
156

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

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

161
162
off_t filesize(const char *filename);

163
164
char *expand_filename(const char *string);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
165

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