cdo_features.cc 7.78 KB
Newer Older
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-2020 Uwe Schulzweida, <uwe.schulzweida AT mpimet.mpg.de>
6
7
8
9
10
11
12
13
14
15
16
  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.
*/
17
18
#ifdef HAVE_CONFIG_H
#include "config.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
19
20
#endif

21
22
#include <cdi.h>

23
#ifdef HAVE_HDF5_H
24
25
26
#include <hdf5.h>
#endif

27
#ifdef HAVE_ZLIB_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
28
29
30
#include <zlib.h>
#endif

31
#ifdef HAVE_LIBXML2
Uwe Schulzweida's avatar
Uwe Schulzweida committed
32
33
34
#include <libxml/xmlversion.h>
#endif

35
#ifdef HAVE_CURL_CURL_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
37
38
#include <curl/curl.h>
#endif

39
#ifdef HAVE_PROJ_H
40
#include <proj.h>
41
42
#endif

43
#ifdef HAVE_LIBCMOR
Uwe Schulzweida's avatar
Uwe Schulzweida committed
44
45
extern "C"
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
46
#include "cmor.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
47
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
48
49
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
50
51
#include <stdio.h>

Uwe Schulzweida's avatar
Uwe Schulzweida committed
52
// HAVE_OPENMP4
53
#include "process_int.h"
54
#include "cdo_features.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
55
#include "cimdOmp.h"
56

Uwe Schulzweida's avatar
Uwe Schulzweida committed
57
#include <thread>  // std::thread::hardware_concurrency()
58

Uwe Schulzweida's avatar
Uwe Schulzweida committed
59
extern "C" size_t getMemorySize(void);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
60

61
62
void
printFeatures(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
63
64
{
  fprintf(stderr, "Features:");
65
  const size_t memory_size = getMemorySize() / (1024 * 1024 * 1024);
66
  if (memory_size > 0) fprintf(stderr, " %zuGB", memory_size);
67
  fprintf(stderr, " %uthreads", std::thread::hardware_concurrency());
Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
  fprintf(stderr, " C++%d", (int) ((__cplusplus - (__cplusplus / 10000) * 10000) / 100));
69
#ifdef _OPENMP
Uwe Schulzweida's avatar
Uwe Schulzweida committed
70
  fprintf(stderr, " OpenMP");
71
72
73
#if defined(HAVE_OPENMP45)
  fprintf(stderr, "45");
#elif defined(HAVE_OPENMP4)
74
  fprintf(stderr, "4");
75
76
#elif defined(HAVE_OPENMP3)
  fprintf(stderr, "3");
77
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
78
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
79
80
81
82
83
84
#ifdef HAVE_CF_INTERFACE
  fprintf(stderr, " Fortran");
#endif
#ifdef HAVE_LIBPTHREAD
  fprintf(stderr, " PTHREADS");
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
85
#ifdef HAVE_LIBHDF5
86
87
  fprintf(stderr, " HDF5");
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
#ifdef HAVE_NETCDF4
Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
  fprintf(stderr, " NC4");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
90
#ifdef HAVE_NC4HDF5
91
  fprintf(stderr, "/HDF5");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
92
#ifdef HAVE_NC4HDF5_THREADSAFE
93
94
95
  fprintf(stderr, "/threadsafe");
#endif
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
96
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
97
#ifdef HAVE_LIBNC_DAP
Uwe Schulzweida's avatar
Uwe Schulzweida committed
98
99
  fprintf(stderr, " OPeNDAP");
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
100
#ifdef HAVE_LIBSZ
Uwe Schulzweida's avatar
Uwe Schulzweida committed
101
102
  fprintf(stderr, " SZ");
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
103
/*
104
#ifdef HAVE_LIBZ
Uwe Schulzweida's avatar
Uwe Schulzweida committed
105
fprintf(stderr, " Z");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
106
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
107
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
108
#ifdef HAVE_LIBUDUNITS2
Uwe Schulzweida's avatar
Uwe Schulzweida committed
109
110
  fprintf(stderr, " UDUNITS2");
#endif
111
#ifdef HAVE_LIBPROJ
112
  fprintf(stderr, " PROJ");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
113
#endif
114
#ifdef HAVE_LIBXML2
Uwe Schulzweida's avatar
Uwe Schulzweida committed
115
116
  fprintf(stderr, " XML2");
#endif
117
#ifdef HAVE_LIBMAGICS
Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
119
  fprintf(stderr, " MAGICS");
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
120
#ifdef HAVE_LIBDRMAA
Uwe Schulzweida's avatar
Uwe Schulzweida committed
121
122
  fprintf(stderr, " DRMAA");
#endif
123
#ifdef HAVE_LIBCURL
Uwe Schulzweida's avatar
Uwe Schulzweida committed
124
  fprintf(stderr, " CURL");
125
#endif
126
#ifdef HAVE_LIBFFTW3
127
  fprintf(stderr, " FFTW3");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
128
#endif
129
#ifdef HAVE_LIBCMOR
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
131
  fprintf(stderr, " CMOR");
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
133
134
135
136
137
138
139
140
141
142
143
#if defined(__AVX2__)
  fprintf(stderr, " AVX2");
#elif defined(__AVX__)
  fprintf(stderr, " AVX");
#elif defined(__SSE4_2__)
  fprintf(stderr, " SSE4_2");
#elif defined(__SSE4_1__)
  fprintf(stderr, " SSE4_1");
#elif defined(__SSE3__)
  fprintf(stderr, " SSE3");
#elif defined(__SSE2__)
  fprintf(stderr, " SSE2");
144
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
145
146
147
  fprintf(stderr, "\n");
}

148
149
void
printLibraries(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
150
151
{
  fprintf(stderr, "Libraries:");
152
#ifdef HAVE_LIBHDF5
153
  fprintf(stderr, " HDF5");
154
#ifdef H5_VERS_MAJOR
155
156
  unsigned h5l_majnum, h5l_minnum, h5l_relnum;
  H5get_libversion(&h5l_majnum, &h5l_minnum, &h5l_relnum);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
157
158
159
160
  fprintf(stderr, "/%u.%u.%u", h5l_majnum, h5l_minnum, h5l_relnum);

  unsigned h5h_majnum = H5_VERS_MAJOR, h5h_minnum = H5_VERS_MINOR, h5h_relnum = H5_VERS_RELEASE;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
161
  if ((h5h_majnum != h5l_majnum) || (h5h_minnum != h5l_minnum) || (h5h_relnum != h5l_relnum))
Uwe Schulzweida's avatar
Uwe Schulzweida committed
162
    fprintf(stderr, "(h%u.%u.%u)", h5h_majnum, h5h_minnum, h5h_relnum);
163
164
#endif
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
165
/*
166
#ifdef HAVE_LIBZ
Uwe Schulzweida's avatar
Uwe Schulzweida committed
167
168
{
  fprintf(stderr, " zlib/%s", zlibVersion());
169
#ifdef ZLIB_VERSION
Uwe Schulzweida's avatar
Uwe Schulzweida committed
170
171
172
173
174
175
176
177
  if ( strcmp(ZLIB_VERSION, zlibVersion()) != 0 )
    fprintf(stderr, "(h%s)", ZLIB_VERSION);
#else
  fprintf(stderr, "(header not found)");
#endif
}
#endif
*/
178
#ifdef HAVE_LIBPROJ
179
  fprintf(stderr, " proj");
180
181
#ifdef PROJ_VERSION_MAJOR
  fprintf(stderr, "/%u.%u.%u", PROJ_VERSION_MAJOR, PROJ_VERSION_MINOR, PROJ_VERSION_PATCH);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
182
183
#endif
#endif
184
185

#ifdef HAVE_LIBCMOR
Uwe Schulzweida's avatar
Uwe Schulzweida committed
186
  fprintf(stderr, " CMOR");
187
#ifdef CMOR_VERSION_MAJOR
Uwe Schulzweida's avatar
Uwe Schulzweida committed
188
  fprintf(stderr, "/%u.%u.%u", CMOR_VERSION_MAJOR, CMOR_VERSION_MINOR, CMOR_VERSION_PATCH);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
190
#endif
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
191

192
#ifdef HAVE_LIBXML2
193
  fprintf(stderr, " xml2");
194
#ifdef LIBXML_DOTTED_VERSION
195
  fprintf(stderr, "/%s", LIBXML_DOTTED_VERSION);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
196
197
198
#endif
#endif

199
#ifdef HAVE_LIBCURL
Uwe Schulzweida's avatar
Uwe Schulzweida committed
200
  {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
201
    const auto version_data = curl_version_info(CURLVERSION_NOW);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
202
    fprintf(stderr, " curl/%s", version_data->version);
203
#ifdef LIBCURL_VERSION
Uwe Schulzweida's avatar
Uwe Schulzweida committed
204
    if (strcmp(LIBCURL_VERSION, version_data->version) != 0) fprintf(stderr, "(h%s)", LIBCURL_VERSION);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
205
206
207
208
209
210
211
212
#else
    fprintf(stderr, "(header not found)");
#endif
  }
#endif

  fprintf(stderr, "\n");
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
213

Uwe Schulzweida's avatar
Uwe Schulzweida committed
214
void
215
cdoConfig(const std::string &option)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
216
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  std::map<std::string, std::pair<std::string, bool>> configMap;

  // clang-format off
  configMap["has-srv"]      = {"SERVICE",          cdiHaveFiletype(CDI_FILETYPE_SRV)};
  configMap["has-ext"]      = {"EXTRA",            cdiHaveFiletype(CDI_FILETYPE_EXT)};
  configMap["has-ieg"]      = {"IEG",              cdiHaveFiletype(CDI_FILETYPE_IEG)};
  configMap["has-grb"]      = {"GRIB 1",           cdiHaveFiletype(CDI_FILETYPE_GRB)};
  configMap["has-grb1"]     = {"GRIB 1",           cdiHaveFiletype(CDI_FILETYPE_GRB)};
  configMap["has-grb2"]     = {"GRIB 2",           cdiHaveFiletype(CDI_FILETYPE_GRB2)};
  configMap["has-nc"]       = {"NetCDF",           cdiHaveFiletype(CDI_FILETYPE_NC)};
  configMap["has-nc2"]      = {"NetCDF 2",         cdiHaveFiletype(CDI_FILETYPE_NC2)};
  configMap["has-nc4"]      = {"NetCDF 4",         cdiHaveFiletype(CDI_FILETYPE_NC4)};
  configMap["has-nc4c"]     = {"NetCDF 4 classic", cdiHaveFiletype(CDI_FILETYPE_NC4C)};
  configMap["has-nc5"]      = {"NetCDF 5",         cdiHaveFiletype(CDI_FILETYPE_NC5)};
  configMap["has-hdf5"]     = {"HDF5",             false};
  configMap["has-cgribex"]  = {"CGRIBEX",          false};
  configMap["has-cmor"]     = {"CMOR",             false};
  configMap["has-proj"]     = {"PROJ",             false};
  configMap["has-threads"]  = {"PTHREADS",         false};
  configMap["has-openmp"]   = {"OPENMP",           false};
  configMap["has-wordexp"]  = {"WORDEXP",          false};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
238
  // clang-format on
239

Uwe Schulzweida's avatar
Uwe Schulzweida committed
240
#ifdef HAVE_LIBHDF5
Uwe Schulzweida's avatar
Uwe Schulzweida committed
241
  configMap["has-hdf5"].second = true;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
242
#endif
243

244
#ifdef HAVE_LIBCGRIBEX
Uwe Schulzweida's avatar
Uwe Schulzweida committed
245
  configMap["has-cgribex"].second = true;
246
247
#endif

248
#ifdef HAVE_LIBCMOR
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249
  configMap["has-cmor"].second = true;
250
251
252
#endif

#ifdef HAVE_LIBPROJ
Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
  configMap["has-proj"].second = true;
254
255
256
#endif

#ifdef HAVE_LIBPTHREAD
Uwe Schulzweida's avatar
Uwe Schulzweida committed
257
  configMap["has-threads"].second = true;
258
259
260
#endif

#ifdef _OPENMP
Uwe Schulzweida's avatar
Uwe Schulzweida committed
261
  configMap["has-openmp"].second = true;
262
263
#endif

264
#ifdef HAVE_WORDEXP_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
265
  configMap["has-wordexp"].second = true;
266
267
#endif

268
  if ("all-json" == option || "all" == option)
269
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
270
271
      std::cout << "{";
      int i = 0;
272
      for (const auto &entry : configMap)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
273
274
275
276
277
        {
          if (i++) fprintf(stdout, ",");
          std::cout << "\"" << entry.first << "\":\"" << (entry.second.second ? "yes" : "no") << "\"";
        }
      std::cout << "}\n";
278
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
279
280
  else
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
281
      bool foundOption = false;
282
      for (const auto &entry : configMap)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
283
        {
284
          if (entry.first == option)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
285
286
287
288
289
            {
              foundOption = true;
              std::cout << (entry.second.second ? "yes" : "no") << "\n";
            }
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
290
291

      if (!foundOption)
292
        {
293
          fprintf(stdout, "unknown config option: %s\n", option.c_str());
294
295
296
          fprintf(stdout, "\n");
          fprintf(stdout, "Available config option:\n");
          fprintf(stdout, "\n");
297
          for (const auto &entry : configMap)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
298
            fprintf(stdout, "  %-12s  whether %s is enabled\n", entry.first.c_str(), entry.second.first.c_str());
Uwe Schulzweida's avatar
Uwe Schulzweida committed
299

300
301
          exit(EXIT_FAILURE);
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
302
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
303

Uwe Schulzweida's avatar
Uwe Schulzweida committed
304
305
  exit(EXIT_SUCCESS);
}