util.h 6.57 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-2017 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 _UTIL_H
#define _UTIL_H

21
#include <stdio.h>
22
#include <stdbool.h>
23
#include "percentiles.h"
24
25
26
27
28
29
30
31
32
33
34
35
36
37

/* dummy use of unused parameters to silence compiler warnings */
#define  UNUSED(x) (void)x

#undef   TRUE
#define  TRUE   1
#undef   FALSE
#define  FALSE  0

#undef   MIN
#define  MIN(a,b)  ((a) < (b) ? (a) : (b))
#undef   MAX
#define  MAX(a,b)  ((a) > (b) ? (a) : (b))

38
39
40
41
#undef   SQR
#define  SQR(a)    ((a)*(a))


Uwe Schulzweida's avatar
Uwe Schulzweida committed
42
#define  ADD_PLURAL(n)  ((n)!=1 ? "s" : "")
43
44
45

#define  UNCHANGED_RECORD  (processSelf() == 0 && cdoStreamName(0)->argv[0][0] != '-' && cdoRegulargrid == FALSE && cdoDefaultFileType == -1 && cdoDefaultDataType == -1 && cdoDefaultByteorder == -1 )

46
47
48
extern char *Progname;
extern char *cdoGridSearchDir;
extern int CDO_Reduce_Dim;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
49
extern int CDO_Memtype;
50
extern int CDO_Parallel_Read;
51
52
extern int CDO_Append_History;
extern int CDO_Reset_History;
53
extern int timer_read, timer_write; // refactor: both pstream.c and CDIread.c CDIwrite.c defined in cdo.c
54

Uwe Schulzweida's avatar
Uwe Schulzweida committed
55
extern int CDO_optind;
56
extern const char *CDO_optarg;
57
extern int CDO_opterr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
58
59
60
61

extern int CDO_flt_digits;
extern int CDO_dbl_digits;

62
extern int remap_genweights;
63

64
extern const char *cdoExpName;
65
66
67
68
69
70
71
72
73
74
extern int ompNumThreads;

extern int stdin_is_tty;
extern int stdout_is_tty;
extern int stderr_is_tty;

extern int cdoDefaultFileType;
extern int cdoDefaultDataType;
extern int cdoDefaultByteorder;
extern int cdoDefaultTableID;
75
76
extern int cdoDefaultInstID;
extern int cdoDefaultTimeType;
Yvonne Kuestermann's avatar
Yvonne Kuestermann committed
77
extern int cdoLogOff;
78
79
80
81
82
83
84
85
86
87
88
89
90
91

extern int cdoLockIO;
extern int cdoCheckDatarange;

extern int cdoSilentMode;
extern int cdoOverwriteMode;
extern int cdoRegulargrid;
extern int cdoBenchmark;
extern int cdoTimer;
extern int cdoVerbose;
extern int cdoDebug;
extern int cdoCompress;
extern int cdoInteractive;
extern int cdoParIO;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
92
extern int cdoDebugExt;
93
94
95
96
97
98
99
100
101
102

extern int cdoCompType;
extern int cdoCompLevel;

extern int cdoChunkType;

extern int cdoExpMode;

extern int CDO_Color;
extern int CDO_Use_FFTW;
103
extern int CDO_Version_Info;
104
extern int CDO_CMOR_Mode;
105
106
107
108
extern int cdoDiag;

extern int cdoNumVarnames;
extern char **cdoVarnames;
109
extern char CDO_File_Suffix[32]; // refactor: added keyword extern
110

111
extern const char *CDO_Version;
112

113

114
115
116
117
118
119
120
typedef struct {
  int    argc;
  int    argl;
  char **argv;
  char  *args;
} argument_t;

121
122
argument_t *file_argument_new(const char *filename);
void        file_argument_free(argument_t *argument);
123
124
125
126
argument_t *argument_new(size_t argc, size_t len);
void        argument_free(argument_t *argument);
void        argument_fill(argument_t *argument, int argc, char *argv[]);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
127
128
char *getProgname(char *string);
char *getOperator(const char *argument);
129
const char *getOperatorName(const char *xoperator);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
const char *cdoComment(void);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
131

132
argument_t makeArgument(int argc, char *argv[]);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
133
134
char *getFileArg(char *argument);

135
136
enum {START_DEC, START_JAN};
int get_season_start(void);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
void get_season_name(const char *seas_name[]);
138
int month_to_season(int month);
139

140
void init_is_tty(void);
141

142
143
char *double_to_attstr(int digits, char *str, size_t len, double value);

144
void progressInit(void);
145
void progressStatus(double offset, double refval, double curval);
146

147
148
bool fileExists(const char *filename);
bool userFileOverwrite(const char *filename);
149

Uwe Schulzweida's avatar
Uwe Schulzweida committed
150
151
/* convert a CDI datatype to string */
int datatype2str(int datatype, char *datatypestr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
152
int str2datatype(const char *datatypestr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
153

154
155
156
157
158
/* filename manipulation */
const char *filetypeext(int filetype);
void rm_filetypeext(char *file, const char *ext);
void repl_filetypeext(char file[], const char *oldext, const char *newext);

159
160
161
162
163
164

/* moved here from cdo.h */
void    cdiOpenError(int cdiErrno, const char *fmt, const char *path);
void    cdoAbort(const char *fmt, ...);
void    cdoWarning(const char *fmt, ...);
void    cdoPrint(const char *fmt, ...);
165
166
void    cdoPrintBlue(const char *fmt, ...);
void    cdoPrintRed(const char *fmt, ...);
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

int  timer_new(const char *text);
void timer_report(void);
void timer_start(int it);
void timer_stop(int it);
double timer_val(int it);


void    operatorInputArg(const char *enter);
int     operatorArgc(void);
char  **operatorArgv(void);
void    operatorCheckArgc(int numargs);

const argument_t *cdoStreamName(int cnt);

void    cdoInitialize(void *argument);
void    cdoFinish(void);

int     cdoStreamNumber(void);
int     cdoStreamCnt(void);
int     cdoOperatorAdd(const char *name, int func, int intval, const char *enter);
int     cdoOperatorID(void);
int     cdoOperatorF1(int operID);
int     cdoOperatorF2(int operID);
const char *cdoOperatorName(int operID);
const char *cdoOperatorEnter(int operID);

int     cdoFiletype(void);

196
197
void cdoSetNAN(double missval, size_t gridsize, double *array);

198
199
void    cdoInqHistory(int fileID);
void    cdoDefHistory(int fileID, char *histstring);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
200
void cdo_def_tracking_id(int vlistID, const char *uuid_attribute);
201
void cdo_def_creation_date(int vlistID);
202
203
204
205
206
207

int     cdoDefineGrid(const char *gridfile);
int     cdoDefineZaxis(const char *zaxisfile);

int     vlistInqNWPV(int vlistID, int varID);
int     vlistIsSzipped(int vlistID);
208
int     vlist_check_gridsize(int vlistID);
209
int     vlist_get_psvarid(int vlistID, int zaxisID);
210
double *vlist_read_vct(int vlistID, int *rzaxisIDh, int *rnvct, int *rnhlev, int *rnhlevf, int *rnhlevh);
211
void vlist_change_hybrid_zaxis(int vlistID1, int vlistID2, int zaxisID1, int zaxisID2);
212
213
214
215
216
217

void cdoGenFileSuffix(char *filesuffix, size_t maxlen, int filetype, int vlistID, const char *refname);

void writeNCgrid(const char *gridfile, int gridID, int *imask);
void defineZaxis(const char *zaxisarg);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
218
int grid_from_name(const char *gridname);
219
220
int zaxisFromName(const char *zaxisname);

Yvonne Kuestermann's avatar
layout    
Yvonne Kuestermann committed
221
/* refactor: moved here from cdo.h */
222
223
int cdo_omp_get_thread_num(void);
void strtolower(char *str);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
224
void strtoupper(char *str);
225

Yvonne Kuestermann's avatar
layout    
Yvonne Kuestermann committed
226
/* refactor: moved here from cdo.c */
227
void exp_run(int argc, char *argv[], const char *cdoExpName); // job.c
228
229
230
void printFeatures(void); // features.c
void printLibraries(void);  // features.c  

231
232
int wildcardmatch(const char *w, const char *s);

233
234
void cdo_check_round(void);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
235
#endif  /* _UTIL_H */