cdo_int.h 3.78 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-2008 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
22
23
24
#if defined (HAVE_CONFIG_H)
#  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
36
37
#include "field.h"
#include "functs.h"
#include "dmemory.h"
#include "process.h"

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

53
54
55
56
57
58
59

/* sxxxYYYYMMDDhhmm0 */
#define  DATE_LEN  16        /* allocate DTLEN+1 !!!! */
#define  SET_DATE(dtstr, date, time)        (sprintf(dtstr, "%*d%*d", DATE_LEN-4, date, 4, time))
#define  DATE_IS_NEQ(dtstr1, dtstr2, len) (memcmp(dtstr1, dtstr2, len) != 0)


Uwe Schulzweida's avatar
Uwe Schulzweida committed
60
#ifndef DBL_IS_EQUAL
Uwe Schulzweida's avatar
Uwe Schulzweida committed
61
#if  defined  (XXX_HAVE_ISNAN)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
62
63
#  define DBL_IS_NAN(x)  (isnan(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))
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
#elif  defined  (XXX_FP_NAN)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
65
66
#  define DBL_IS_NAN(x)  (fpclassify(x) == FP_NAN)
#  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))
Uwe Schulzweida's avatar
Uwe Schulzweida committed
67
#else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
#  define DBL_IS_EQUAL(x,y) (!(x < y || y < x))
Uwe Schulzweida's avatar
Uwe Schulzweida committed
69
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
70
71
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
72

Uwe Schulzweida's avatar
Uwe Schulzweida committed
73
74
#ifndef  M_PI
#define  M_PI		3.14159265358979323846	/* pi */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
76
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
77
78
#ifndef  M_LN10
#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
83
84
85
86
87
88
89
90
91
92

#ifndef  RAD2DEG
#define  RAD2DEG  (180./M_PI)   /* conversion for rad to deg */
#endif

#ifndef  DEG2RAD
#define  DEG2RAD  (M_PI/180.)   /* conversion for deg to rad */
#endif

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


93
94
95
#define CDO_EXP_LOCAL   1
#define CDO_EXP_REMOTE  2

96
enum {DATE_FIRST, DATE_LAST, DATE_MIDDLE};
97

Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
99
void strtolower(char *str);

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

108
int zaxis2ltype(int zaxisID);
109
110
111
int ztype2ltype(int zaxistype);
int ltype2ztype(int ltype);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
112
113
114
115
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
116
117
int compNlon(int nlat);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
119
120
121
122
123
124
125
126
typedef struct {
  int      date;
  int      time;
  int      julval;
}
DATETIME;

void    datetime_avg(int dpy, int ndates, DATETIME *datetime);

127
128
129
double encode_julval(int dpy, int date, int time);
void decode_julval(int dpy, double value, int *date, int *time);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
131
132
133
134
135
136
137
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
138
void    cdolog(const char *prompt, double cputime);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
139
140
void    cdologs(int noper);
void    cdologo(int noper);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
141
142
143
void    nospec(int vlistID);
void    gridWrite(FILE *fp, int gridID);

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

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

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