10
10
*/
11
11
#include < algorithm>
12
12
#include < cstring>
13
- #include < sstream>
14
13
#include < iostream>
14
+ #include < sstream>
15
15
#include < typeinfo>
16
16
17
17
#include " eckit/exception/Exceptions.h"
22
22
#include " nwp_definitions.h"
23
23
24
24
namespace nwp_emulator {
25
+ void codesHandleDeleter::operator ()(codes_handle* h) {
26
+ if (h) {
27
+ codes_handle_delete (h);
28
+ }
29
+ }
30
+
31
+ void fileDeleter::operator ()(FILE* f) {
32
+ if (f) {
33
+ fclose (f);
34
+ }
35
+ }
36
+
25
37
GRIBFileReader::GRIBFileReader (const eckit::PathName& inputPath, size_t rank, size_t root, int stepCountLimit) :
26
38
rank_ (rank), root_(root), DataReader(stepCountLimit) {
27
39
if (rank_ != root_) {
@@ -44,10 +56,10 @@ GRIBFileReader::GRIBFileReader(const eckit::PathName& inputPath, size_t rank, si
44
56
// 2. Field names & metadata (parameters)
45
57
std::string paramBuffer;
46
58
if (rank_ == root_) {
47
- for (const auto & param: params_) {
59
+ for (const auto & param : params_) {
48
60
paramBuffer += param + " ;" ;
49
61
}
50
- paramBuffer.pop_back (); // remove last ';' separator
62
+ paramBuffer.pop_back (); // remove last ';' separator
51
63
}
52
64
size_t paramSize = paramBuffer.size ();
53
65
eckit::mpi::comm ().broadcast (paramSize, root_);
@@ -169,8 +181,8 @@ void GRIBFileReader::validateSrcFiles(bool isRoot) {
169
181
for (int i = 0 ; i < count_ - 1 ; ++i) {
170
182
readMsgMetadata (gridName, paramMd);
171
183
if (gridName != gridName_) {
172
- eckit::Log::error () << " Grid in " << filename << " is different from setup ("
173
- << gridName_ << " ), exit..." << std::endl;
184
+ eckit::Log::error () << " Grid in " << filename << " is different from setup (" << gridName_
185
+ << " ), exit..." << std::endl;
174
186
eckit::mpi::comm ().abort (1 );
175
187
}
176
188
fileParams.push_back (paramMd);
@@ -179,10 +191,10 @@ void GRIBFileReader::validateSrcFiles(bool isRoot) {
179
191
eckit::mpi::comm ().abort (1 );
180
192
}
181
193
}
182
- readMsgMetadata (gridName, paramMd); // read the last message in the file
194
+ readMsgMetadata (gridName, paramMd); // read the last message in the file
183
195
if (gridName != gridName_) {
184
- eckit::Log::error () << " Grid in " << filename << " is different from setup ("
185
- << gridName_ << " ), exit... " << std::endl;
196
+ eckit::Log::error () << " Grid in " << filename << " is different from setup (" << gridName_ << " ), exit... "
197
+ << std::endl;
186
198
eckit::mpi::comm ().abort (1 );
187
199
}
188
200
fileParams.push_back (paramMd);
@@ -314,7 +326,7 @@ bool GRIBFileReader::nextMessage(std::string& shortName, std::string& levtype, s
314
326
++index_;
315
327
eckit::mpi::comm ().broadcast (count_, root_);
316
328
if (rank_ == root_ && index_ < count_) {
317
- return resetGribHandle (); // Load the next message
329
+ return resetGribHandle (); // Load the next message
318
330
}
319
331
return true ;
320
332
}
0 commit comments