cdo_int.h 3.94 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-2015 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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
45
#define  OPENMP4  201307
46
47
48
49
#if defined(_OPENMP) && defined(OPENMP4) && _OPENMP >= OPENMP4
#define  HAVE_OPENMP4  1
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
50

Uwe Schulzweida's avatar
Uwe Schulzweida committed
51
#ifndef strdupx
Uwe Schulzweida's avatar
Uwe Schulzweida committed
52
53
54
55
56
#ifndef strdup
char *strdup(const char *s);
#endif
#define strdupx  strdup
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
57
58
59
60
#define strdupx(s)			          \
({					      	  \
   const char *__old = (s);			  \
   size_t __len = strlen(__old) + 1;		  \
61
   char *__new = Malloc(__len);	  \
Uwe Schulzweida's avatar
Uwe Schulzweida committed
62
63
   (char *) memcpy(__new, __old, __len);	  \
})
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
65
66
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
67

Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
69
70
#define  cmpstr(s1, s2)          (strncmp(s1, s2, strlen(s2)))
#define  cmpstrlen(s1, s2, len)  (strncmp(s1, s2, len = strlen(s2)))

71

72
/* sxxxYYYYMMDDhhmm0 */
73
74
#define  DATE_LEN  31        /* YYYYMMDDhhmmss allocate DTLEN+1 !!!! */
#define  SET_DATE(dtstr, date, time)      (sprintf(dtstr, "%*d%*d", DATE_LEN-6, date, 6, time))
75
76
#define  DATE_IS_NEQ(dtstr1, dtstr2, len) (memcmp(dtstr1, dtstr2, len) != 0)

77
78
enum T_WEIGHT_MODE {WEIGHT_OFF, WEIGHT_ON};
enum T_EIGEN_MODE  {JACOBI, DANIELSON_LANCZOS};
79

80

Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
#ifndef  M_LN10
Uwe Schulzweida's avatar
Uwe Schulzweida committed
82
#define  M_LN10      2.30258509299404568402  /* log_e 10 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
83
84
#endif

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


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

92
93
#define  MEMTYPE_DOUBLE  1
#define  MEMTYPE_FLOAT   2
Uwe Schulzweida's avatar
Uwe Schulzweida committed
94

95
96
#define  CDO_EXP_LOCAL   1
#define  CDO_EXP_REMOTE  2
97

Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
99
100
101
102
103
104
105
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);

106
int zaxis2ltype(int zaxisID);
107

108
109

int nfc2nlat(int nfc, int ntr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
111
112
113
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
114
115
int compNlon(int nlat);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
void param2str(int param, char *paramstr, int maxlen);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
void datetime2str(int date, int time, char *datetimestr, int maxlen);
118
119
void date2str(int date, char *datestr, int maxlen);
void time2str(int time, char *timestr, int maxlen);
120

121
122
123
const char * tunit2str(int tunits);
const char * calendar2str(int calendar);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
124
125
126
127
128
129
130
131
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
132
void    cdolog(const char *prompt, double cputime);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
133
134
void    cdologs(int noper);
void    cdologo(int noper);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
135
136
137
void    nospec(int vlistID);
void    gridWrite(FILE *fp, int gridID);

138
139
140
void openLock(void);
void openUnlock(void);

141
142
int  cdf_openread(const char *filename);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
143
void printFiletype(int streamID, int vlistID);
144

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

147
off_t fileSize(const char *restrict filename);
148

149
150
char *expand_filename(const char *string);

151
double parameter2double(const char *string);
152
int    parameter2int(const char *string);
153
154
int    parameter2intlist(const char *string);

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