cdo_int.h 4.95 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.

Uwe Schulzweida's avatar
Uwe Schulzweida committed
5
  Copyright (C) 2003-2014 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
#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"
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
#define strdupx(s)			          \
({					      	  \
   const char *__old = (s);			  \
   size_t __len = strlen(__old) + 1;		  \
48
   char *__new = malloc(__len);	  \
Uwe Schulzweida's avatar
Uwe Schulzweida committed
49
50
   (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
#define strcompare(s1, s2)  (strncmp(s1, s2, strlen(s2)))

56
57

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


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

79
80
81
82
83
#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
84
85
86
87
#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
88

89

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
94
95
#ifndef  M_PI
#define  M_PI        3.14159265358979323846  /* pi */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
96
97
98
99
100
#endif


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

101
102
#define  MEMTYPE_DOUBLE  1
#define  MEMTYPE_FLOAT   2
Uwe Schulzweida's avatar
Uwe Schulzweida committed
103

104
105
#define  CDO_EXP_LOCAL   1
#define  CDO_EXP_REMOTE  2
106

107

108
enum {DATE_FIRST, DATE_LAST, DATE_MIDDLE};
109

Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
111
void strtolower(char *str);

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

120
int zaxis2ltype(int zaxisID);
121
122
123
int ztype2ltype(int zaxistype);
int ltype2ztype(int ltype);

124
125

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
void param2str(int param, char *paramstr, int maxlen);
133
134
void date2str(int date, char *datestr, int maxlen);
void time2str(int time, char *timestr, int maxlen);
135

136
137
138
139
const char * tunit2str(int tunits);
const char * calendar2str(int calendar);


Uwe Schulzweida's avatar
Uwe Schulzweida committed
140
typedef struct {
141
142
143
144
  int   date;
  int   time;
} datetime_t;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
145
146
147
148
149
typedef struct
{
  datetime_t v;
  datetime_t b[2];
} dtinfo_t;
150
151
152
153
154
155

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
156

157
158
159
160
161
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
162

163
void    get_timestat_date(int *tstat_date);
164
void    datetime_avg(int dpy, int ndates, datetime_t *datetime);
165
void    datetime_avg_dtinfo(int dpy, int ndates, dtinfo_t *dtinfo);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
166
167
void    taxisInqDTinfo(int taxisID, dtinfo_t *dtinfo);
void    taxisDefDTinfo(int taxisID, dtinfo_t dtinfo);
168

Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
170
171
172
173
174
175
176
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
177
void    cdolog(const char *prompt, double cputime);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
178
179
void    cdologs(int noper);
void    cdologo(int noper);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
180
181
182
void    nospec(int vlistID);
void    gridWrite(FILE *fp, int gridID);

183
184
185
void openLock(void);
void openUnlock(void);

186
187
int  cdf_openread(const char *filename);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
188
void printFiletype(int streamID, int vlistID);
189

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

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

194
195
off_t filesize(const char *filename);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
196

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