cdo_int.h 3.98 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
#include <string.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
28
29
30
#include <math.h>
#include <float.h>

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
41
#define  OPENMP4  201307
42
43
44
45
#if defined(_OPENMP) && defined(OPENMP4) && _OPENMP >= OPENMP4
#define  HAVE_OPENMP4  1
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
46

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
63

Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65
66
#define  cmpstr(s1, s2)          (strncmp(s1, s2, strlen(s2)))
#define  cmpstrlen(s1, s2, len)  (strncmp(s1, s2, len = strlen(s2)))

67

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

73
74
enum T_WEIGHT_MODE {WEIGHT_OFF, WEIGHT_ON};
enum T_EIGEN_MODE  {JACOBI, DANIELSON_LANCZOS};
75

76

Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
#ifndef  M_LN10
Uwe Schulzweida's avatar
Uwe Schulzweida committed
78
#define  M_LN10      2.30258509299404568402  /* log_e 10 */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
79
80
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
82
#ifndef  M_PI
#define  M_PI        3.14159265358979323846  /* pi */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
83
84
85
86
87
#endif


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

88
89
#define  MEMTYPE_DOUBLE  1
#define  MEMTYPE_FLOAT   2
Uwe Schulzweida's avatar
Uwe Schulzweida committed
90

91
92
#define  CDO_EXP_LOCAL   1
#define  CDO_EXP_REMOTE  2
93

Uwe Schulzweida's avatar
Uwe Schulzweida committed
94
95
96
97
98
99
100
101
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);

102
int zaxis2ltype(int zaxisID);
103

104
105

int nfc2nlat(int nfc, int ntr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
106
107
108
109
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
110
111
int compNlon(int nlat);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
112
void param2str(int param, char *paramstr, int maxlen);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
113
void datetime2str(int date, int time, char *datetimestr, int maxlen);
114
115
void date2str(int date, char *datestr, int maxlen);
void time2str(int time, char *timestr, int maxlen);
116

117
118
119
const char * tunit2str(int tunits);
const char * calendar2str(int calendar);

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

134
135
136
void openLock(void);
void openUnlock(void);

137
138
int  cdf_openread(const char *filename);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
139
void printFiletype(int streamID, int vlistID);
140

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

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

145
146
off_t filesize(const char *filename);

147
148
char *expand_filename(const char *string);

149
double parameter2double(const char *string);
150
int    parameter2int(const char *string);
151
152
int    parameter2intlist(const char *string);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
153

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