1 /*
2   This file is part of CDO. CDO is a collection of Operators to manipulate and analyse Climate model Data.
3 
4   Author: Uwe Schulzweida
5 
6 */
7 
8 #include "config.h"
9 
10 #include <cdi.h>
11 #include "cdo_options.h"
12 #include "cdo_output.h"
13 
14 #include <cstring>
15 
16 namespace cdo
17 {
18 const char *progname;
19 char File_Suffix[32];
20 const char *Version = "Climate Data Operators version " VERSION " (https://mpimet.mpg.de/cdo)";
21 const char *Username;
22 const char *DownloadPath;
23 const char *IconGrids;
24 }  // namespace cdo
25 
26 namespace Options
27 {
28 int numStreamWorker;
29 bool benchmark = false;
30 bool silentMode = false;
31 
32 bool cdoCompress = false;
33 int cdoCompType = CDI_COMPRESS_NONE;
34 int cdoCompLevel = 0;
35 bool cdoInteractive = false;
36 bool cdoVerbose = false;
37 int cdoExitStatus = 0;
38 bool Timer = false;
39 
40 bool CheckDatarange = false;
41 
42 int CDO_flt_digits = 7;   // TODO:rename
43 int CDO_dbl_digits = 15;  // TODO:rename
44 
45 bool Use_FFTW = true;
46 bool VersionInfo = true;
47 int CMOR_Mode = false;
48 
49 bool cdoDiag = false;
50 
51 MemType CDO_Memtype(MemType::Native);
52 bool CDO_Parallel_Read = false;
53 
54 int CDO_Reduce_Dim = false;
55 int CDO_Append_History = true;
56 bool CDO_Reset_History = false;
57 bool CDO_task = false;
58 
59 unsigned Random_Seed = 1;
60 
61 int cdoChunkType = CDI_UNDEFID;
62 bool cdoOverwriteMode = false;
63 bool cdoParIO = false;
64 bool cdoRegulargrid = false;
65 std::vector<std::string> cdoVarnames;
66 size_t
cdo_num_varnames()67 cdo_num_varnames()
68 {
69   return cdoVarnames.size();
70 }
71 
72 bool REMAP_genweights = true;
73 
74 const char *cdoExpName = nullptr;
75 }  // namespace Options
76 
77 namespace Threading
78 {
79 int ompNumThreads = 1;
80 bool cdoLockIO = false;
81 }  // namespace Threading
82 
83 const char *
cdo_comment(void)84 cdo_comment(void)
85 {
86   return cdo::Version;
87 }
88 
89 void
set_compression(int fileID,int filetype)90 set_compression(int fileID, int filetype)
91 {
92   if (Options::cdoCompress)
93     {
94       if (filetype == CDI_FILETYPE_GRB)
95         {
96           Options::cdoCompType = CDI_COMPRESS_SZIP;
97           Options::cdoCompLevel = 0;
98         }
99       else if (filetype == CDI_FILETYPE_NC4 || filetype == CDI_FILETYPE_NC4C)
100         {
101           Options::cdoCompType = CDI_COMPRESS_ZIP;
102           Options::cdoCompLevel = 1;
103         }
104     }
105 
106   if (Options::cdoCompType != CDI_COMPRESS_NONE)
107     {
108       streamDefCompType(fileID, Options::cdoCompType);
109       streamDefCompLevel(fileID, Options::cdoCompLevel);
110 
111       if (Options::cdoCompType == CDI_COMPRESS_SZIP
112           && (filetype != CDI_FILETYPE_GRB && filetype != CDI_FILETYPE_GRB2 && filetype != CDI_FILETYPE_NC4
113               && filetype != CDI_FILETYPE_NC4C))
114         cdo_warning("SZIP compression not available for non GRIB/NetCDF4 data!");
115 
116       if (Options::cdoCompType == CDI_COMPRESS_JPEG && filetype != CDI_FILETYPE_GRB2)
117         cdo_warning("JPEG compression not available for non GRIB2 data!");
118 
119       if (Options::cdoCompType == CDI_COMPRESS_ZIP && (filetype != CDI_FILETYPE_NC4 && filetype != CDI_FILETYPE_NC4C))
120         cdo_warning("Deflate compression not available for non NetCDF4 data!");
121     }
122 }
123