-
Notifications
You must be signed in to change notification settings - Fork 24
/
config_util.cc
3149 lines (2503 loc) · 102 KB
/
config_util.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2022
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Research Applications Lab (RAL)
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
///////////////////////////////////////////////////////////////////////////////
using namespace std;
#include <sys/types.h>
#include <dirent.h>
#include <limits.h>
#include "config_util.h"
#include "vx_math.h"
#include "vx_util.h"
#include "GridTemplate.h"
///////////////////////////////////////////////////////////////////////////////
static const double default_vld_thresh = 1.0;
static const char conf_key_prepbufr_map_bad[] = "obs_prefbufr_map"; // for backward compatibility
///////////////////////////////////////////////////////////////////////////////
// MetConfig object containing config value constants
static MetConfig conf_const(replace_path(config_const_filename).c_str());
///////////////////////////////////////////////////////////////////////////////
GaussianInfo::GaussianInfo()
: weights(0)
{
clear();
}
///////////////////////////////////////////////////////////////////////////////
void GaussianInfo::clear() {
weight_sum = 0.0;
if (weights) {
delete weights;
weights = (double *)0;
}
max_r = weight_cnt = 0;
radius = dx = bad_data_double;
trunc_factor = default_trunc_factor;
}
///////////////////////////////////////////////////////////////////////////////
int GaussianInfo::compute_max_r() {
max_r = nint(radius / dx * trunc_factor);
return max_r;
}
///////////////////////////////////////////////////////////////////////////////
//
// Compute the Gaussian filter
// g(x,y) = (1 / (2 * pi * sigma**2)) * exp(-(x**2 + y**2) / (2 * sigma**2))
//
///////////////////////////////////////////////////////////////////////////////
void GaussianInfo::compute() {
double weight, distance_sq;
const double g_sigma = radius / dx;
const double g_sigma_sq = g_sigma * g_sigma;
const double f_sigma_exp_divider = (2 * g_sigma_sq);
const double f_sigma_divider = (2 * M_PI * g_sigma_sq);
const double max_r_sq = pow((g_sigma * trunc_factor), 2);
validate();
if (0 < max_r && weights) delete weights;
compute_max_r();
int index = 0;
int g_nx = max_r * 2 + 1;
weight_cnt = 0;
weight_sum = 0.0;
weights = new double[g_nx*g_nx];
for(int idx_x=-max_r; idx_x<=max_r; idx_x++) {
for(int idx_y=-max_r; idx_y<=max_r; idx_y++) {
weight = 0.0;
distance_sq = (double)idx_x*idx_x + idx_y*idx_y;
if (distance_sq <= max_r_sq) {
weight_cnt++;
weight = exp(-(distance_sq) / f_sigma_exp_divider) / f_sigma_divider;
weight_sum += weight;
}
weights[index++] = weight;
} // end for idx_y
} // end for idx_x
mlog << Debug(7) << "GaussianInfo::compute() max_r: " << max_r << "\n";
}
///////////////////////////////////////////////////////////////////////////////
void GaussianInfo::validate() {
if (is_eq(radius, bad_data_double) || is_eq(radius, 0.)) {
mlog << Error << "\nGaussianInfo::validate() -> "
<< "gaussian raduis is missing\n\n";
exit(1);
}
if (is_eq(dx, bad_data_double) || is_eq(dx, 0.)) {
mlog << Error << "\nGaussianInfo::validate() -> "
<< "gaussian dx is missing\n\n";
exit(1);
}
}
///////////////////////////////////////////////////////////////////////////////
void RegridInfo::clear() {
enable = false;
field = FieldType_None;
vld_thresh = bad_data_double;
name.clear();
method = InterpMthd_None;
width = bad_data_int;
gaussian.clear();
shape = GridTemplateFactory::GridTemplate_None;
convert_fx.clear();
censor_thresh.clear();
censor_val.clear();
}
///////////////////////////////////////////////////////////////////////////////
RegridInfo::RegridInfo() {
clear();
}
///////////////////////////////////////////////////////////////////////////////
void RegridInfo::validate() {
// Check for unsupported regridding options
if(method == InterpMthd_Best ||
method == InterpMthd_Geog_Match ||
method == InterpMthd_Gaussian ||
method == InterpMthd_HiRA) {
mlog << Error << "\nRegridInfo::validate() -> "
<< "\"" << interpmthd_to_string(method)
<< "\" not valid for regridding, only interpolating.\n\n";
exit(1);
}
// Check the nearest neighbor special case
if(width == 1 &&
method != InterpMthd_None &&
method != InterpMthd_Nearest &&
method != InterpMthd_Force &&
method != InterpMthd_Upper_Left &&
method != InterpMthd_Upper_Right &&
method != InterpMthd_Lower_Right &&
method != InterpMthd_Lower_Left &&
method != InterpMthd_AW_Mean &&
method != InterpMthd_MaxGauss) {
mlog << Warning << "\nRegridInfo::validate() -> "
<< "Resetting the regridding method from \""
<< interpmthd_to_string(method) << "\" to \""
<< interpmthd_nearest_str
<< "\" since the regridding width is 1.\n\n";
method = InterpMthd_Nearest;
}
// Check for some methods, that width is 1
if((method == InterpMthd_Nearest ||
method == InterpMthd_Force ||
method == InterpMthd_Upper_Left ||
method == InterpMthd_Upper_Right ||
method == InterpMthd_Lower_Right ||
method == InterpMthd_Lower_Left ||
method == InterpMthd_AW_Mean) &&
width != 1) {
mlog << Warning << "\nRegridInfo::validate() -> "
<< "Resetting regridding width from "
<< width << " to 1 for interpolation method \""
<< interpmthd_to_string(method) << "\".\n\n";
width = 1;
}
// Check the bilinear and budget special cases
if((method == InterpMthd_Bilin ||
method == InterpMthd_Budget) &&
width != 2) {
mlog << Warning << "\nRegridInfo::validate() -> "
<< "Resetting the regridding width from "
<< width << " to 2 for regridding method \""
<< interpmthd_to_string(method) << "\".\n\n";
width = 2;
}
// Check the Gaussian filter
if(method == InterpMthd_MaxGauss) {
if(gaussian.radius < gaussian.dx) {
mlog << Error << "\nRegridInfo::validate() -> "
<< "The radius of influence (" << gaussian.radius
<< ") is less than the delta distance (" << gaussian.dx
<< ") for regridding method \"" << interpmthd_to_string(method) << "\".\n\n";
exit(1);
}
}
// Check for equal number of censor thresholds and values
if(censor_thresh.n() != censor_val.n()) {
mlog << Error << "\nRegridInfo::validate() -> "
<< "The number of censor thresholds in \""
<< conf_key_censor_thresh << "\" (" << censor_thresh.n()
<< ") must match the number of replacement values in \""
<< conf_key_censor_val << "\" (" << censor_val.n() << ").\n\n";
exit(1);
}
}
///////////////////////////////////////////////////////////////////////////////
void RegridInfo::validate_point() {
// Check for unsupported regridding options
if(method != InterpMthd_Max &&
method != InterpMthd_Min &&
method != InterpMthd_Median &&
method != InterpMthd_UW_Mean) {
mlog << Warning << "\nRegridInfo::validate_point() -> "
<< "Resetting the regridding method from \""
<< interpmthd_to_string(method) << "\" to \""
<< interpmthd_uw_mean_str << ".\n"
<< "\tAvailable methods: "
<< interpmthd_to_string(InterpMthd_UW_Mean) << ", "
<< interpmthd_to_string(InterpMthd_Max) << ", "
<< interpmthd_to_string(InterpMthd_Min) << ", "
<< interpmthd_to_string(InterpMthd_Median) << ".\n\n";
method = InterpMthd_UW_Mean;
}
}
///////////////////////////////////////////////////////////////////////////////
ConcatString parse_conf_version(Dictionary *dict) {
ConcatString s;
if(!dict) {
mlog << Error << "\nparse_conf_version() -> "
<< "empty dictionary!\n\n";
exit(1);
}
s = dict->lookup_string(conf_key_version);
if(dict->last_lookup_status()) {
check_met_version(s.c_str());
}
return(s);
}
///////////////////////////////////////////////////////////////////////////////
ConcatString parse_conf_string(Dictionary *dict, const char *conf_key,
bool check_empty) {
ConcatString s;
const char *method_name = "parse_conf_string() -> ";
if(!dict) {
mlog << Error << "\n" << method_name << "empty dictionary!\n\n";
exit(1);
}
s = dict->lookup_string(conf_key);
if(dict->last_lookup_status()) {
// Check for an empty string
if(check_empty && s.empty()) {
mlog << Error << "\n" << method_name
<< "The \"" << conf_key << "\" entry (\"" << s
<< "\") cannot be empty.\n\n";
exit(1);
}
// Check for embedded whitespace in non-empty strings
if(!s.empty() && check_reg_exp(ws_reg_exp, s.c_str()) == true) {
mlog << Error << "\n" << method_name
<< "The \"" << conf_key << "\" entry (\"" << s
<< "\") cannot contain embedded whitespace.\n\n";
exit(1);
}
}
return(s);
}
///////////////////////////////////////////////////////////////////////////////
StringArray parse_conf_string_array(Dictionary *dict, const char *conf_key, const char *caller) {
StringArray sa, cur, sid_sa;
if(!dict) {
mlog << Error << "\n" << caller << "empty dictionary!\n\n";
exit(1);
}
return dict->lookup_string_array(conf_key);
}
///////////////////////////////////////////////////////////////////////////////
GrdFileType parse_conf_file_type(Dictionary *dict) {
GrdFileType t = FileType_None;
int v;
if(!dict) {
mlog << Error << "\nparse_conf_file_type() -> "
<< "empty dictionary!\n\n";
exit(1);
}
// Get the integer flag value for the current entry
v = dict->lookup_int(conf_key_file_type, false);
if(dict->last_lookup_status()) {
// Convert integer to enumerated GrdFileType
if(v == conf_const.lookup_int(conf_val_grib1)) t = FileType_Gb1;
else if(v == conf_const.lookup_int(conf_val_grib2)) t = FileType_Gb2;
else if(v == conf_const.lookup_int(conf_val_netcdf_met)) t = FileType_NcMet;
else if(v == conf_const.lookup_int(conf_val_netcdf_pint)) t = FileType_NcPinterp;
else if(v == conf_const.lookup_int(conf_val_netcdf_nccf)) t = FileType_NcCF;
else if(v == conf_const.lookup_int(conf_val_python_numpy)) t = FileType_Python_Numpy;
else if(v == conf_const.lookup_int(conf_val_python_xarray)) t = FileType_Python_Xarray;
else {
mlog << Error << "\nparse_conf_file_type() -> "
<< "Unexpected config file value of " << v << " for \""
<< conf_key_file_type << "\".\n\n";
exit(1);
}
}
return(t);
}
///////////////////////////////////////////////////////////////////////////////
map<STATLineType,STATOutputType> parse_conf_output_flag(Dictionary *dict,
const STATLineType *line_type, int n_lty) {
map<STATLineType,STATOutputType> output_map;
STATOutputType t = STATOutputType_None;
ConcatString cs;
int i, v;
if(!dict) {
mlog << Error << "\nparse_conf_output_flag() -> "
<< "empty dictionary!\n\n";
exit(1);
}
// Loop over the requested line types
for(i=0; i<n_lty; i++) {
// Build the string
cs << cs_erase << conf_key_output_flag << "."
<< statlinetype_to_string(line_type[i]);
cs.set_lower();
// Get the integer flag value for the current entry
v = dict->lookup_int(cs.c_str());
// Convert integer to enumerated STATOutputType
if(v == conf_const.lookup_int(conf_val_none)) t = STATOutputType_None;
else if(v == conf_const.lookup_int(conf_val_stat)) t = STATOutputType_Stat;
else if(v == conf_const.lookup_int(conf_val_both)) t = STATOutputType_Both;
else {
mlog << Error << "\nparse_conf_output_flag() -> "
<< "Unexpected config file value of " << v << " for \""
<< cs << "\".\n\n";
exit(1);
}
// Store entry line type and corresponding output type
output_map[line_type[i]] = t;
}
// Make sure the map is the expected size
if((int) output_map.size() != n_lty) {
mlog << Error << "\nparse_conf_output_flag() -> "
<< "Unexpected number of entries found in \""
<< conf_key_output_flag << "\" ("
<< (int) output_map.size()
<< " != " << n_lty << ").\n\n";
exit(1);
}
return(output_map);
}
///////////////////////////////////////////////////////////////////////////////
map<STATLineType,StringArray> parse_conf_output_stats(Dictionary *dict) {
Dictionary *out_dict = (Dictionary *) 0;
map<STATLineType,StringArray> output_map;
STATLineType line_type;
StringArray sa;
int i;
if(!dict) {
mlog << Error << "\nparse_conf_output_stats() -> "
<< "empty dictionary!\n\n";
exit(1);
}
// Get the output flag dictionary
out_dict = dict->lookup_dictionary(conf_key_output_stats);
// Loop over the output flag dictionary entries
for(i=0; i<out_dict->n_entries(); i++) {
// Get the line type for the current entry
line_type = string_to_statlinetype((*out_dict)[i]->name().c_str());
// Get the StringArray value for the current entry
sa = out_dict->lookup_string_array((*out_dict)[i]->name().c_str());
// Set ignore case to true
sa.set_ignore_case(true);
// Store entry line type and corresponding list of statistics
output_map[line_type].add(sa);
}
return(output_map);
}
///////////////////////////////////////////////////////////////////////////////
//
// Compute the number of verification tasks specified in the current
// dictionary array.
//
///////////////////////////////////////////////////////////////////////////////
int parse_conf_n_vx(Dictionary *dict) {
int i, total;
StringArray lvl;
if(!dict) return(0);
// Check that this dictionary is an array
if(!dict->is_array()) {
mlog << Error << "\nparse_conf_n_vx() -> "
<< "This function must be passed a Dictionary array.\n\n";
exit(1);
}
// Loop over the fields to be verified
for(i=0,total=0; i<dict->n_entries(); i++) {
// Get the level array, which may or may not be defined.
// If defined, use its length. If not, use a length of 1.
lvl = (*dict)[i]->dict_value()->lookup_string_array(conf_key_level, false);
// Increment count by the length of the level array
total += (lvl.n() > 0 ? lvl.n() : 1);
}
return(total);
}
///////////////////////////////////////////////////////////////////////////////
//
// Retrieve the dictionary for the i-th verification task.
//
///////////////////////////////////////////////////////////////////////////////
Dictionary parse_conf_i_vx_dict(Dictionary *dict, int index) {
Dictionary i_dict;
DictionaryEntry entry;
StringArray lvl;
int i, total, n_lvl;
if(!dict) {
mlog << Error << "\nparse_conf_i_vx_dict() -> "
<< "empty dictionary!\n\n";
exit(1);
}
// Check that this dictionary is an array
if(!dict->is_array()) {
mlog << Error << "\nparse_conf_i_vx_dict() -> "
<< "This function must be passed a Dictionary array.\n\n";
exit(1);
}
// Loop over the fields to be verified
for(i=0,total=0; i<dict->n_entries(); i++) {
// Get the level array, which may or may not be defined.
// If defined, use its length. If not, use a length of 1.
lvl = (*dict)[i]->dict_value()->lookup_string_array(conf_key_level, false);
n_lvl = (lvl.n() > 0 ? lvl.n() : 1);
total += n_lvl;
// Check if we're in the correct entry
if(total > index) {
// Copy the current entry's dictionary
i_dict = *((*dict)[i]->dict_value());
// Set up the new entry, taking only a single level value
if(lvl.n() > 0) {
entry.set_string(conf_key_level, lvl[index-(total-n_lvl)].c_str());
i_dict.store(entry);
}
break;
}
} // end for i
return(i_dict);
}
///////////////////////////////////////////////////////////////////////////////
StringArray parse_conf_tc_model(Dictionary *dict, bool error_out) {
const char *method_name = "parse_conf_tc_model() -> ";
StringArray sa = parse_conf_string_array(dict, conf_key_model, method_name);
// Print a warning if AVN appears in the model list
for(int i=0; i<sa.n(); i++) {
if(sa[i].find("AVN") != string::npos) {
mlog << Warning << "\n" << method_name
<< "Requesting tropical cyclone model name \"" << sa[i]
<< "\" will yield no results since \"AVN\" is automatically "
<< "replaced with \"GFS\" when reading ATCF inputs. Please use "
<< "\"GFS\" in the \"" << conf_key_model << "\" entry of the "
<< "configuration file to read/process \"AVN\" entries.\n\n";
}
}
return(sa);
}
///////////////////////////////////////////////////////////////////////////////
StringArray parse_conf_message_type(Dictionary *dict, bool error_out) {
const char *method_name = "parse_conf_message_type() -> ";
StringArray sa = parse_conf_string_array(dict, conf_key_message_type, method_name);
// Check that at least one message type is provided
if(error_out && sa.n() == 0) {
mlog << Error << "\n" << method_name
<< "At least one message type must be provided.\n\n";
exit(1);
}
return(sa);
}
///////////////////////////////////////////////////////////////////////////////
StringArray parse_conf_sid_list(Dictionary *dict, const char *conf_key) {
StringArray sa, cur, sid_sa;
ConcatString mask_name;
int i;
const char *method_name = "parse_conf_sid_list() -> ";
sa = parse_conf_string_array(dict, conf_key, method_name);
// Parse station ID's to exclude from each entry
for(i=0; i<sa.n(); i++) {
parse_sid_mask(string(sa[i]), cur, mask_name);
sid_sa.add(cur);
}
mlog << Debug(4) << method_name
<< "Station ID \"" << conf_key << "\" list contains "
<< sid_sa.n() << " entries.\n";
return(sid_sa);
}
///////////////////////////////////////////////////////////////////////////////
//
// This function is passed a string containing either a file name or a list of
// values. If it's a filename, parse out whitespace-separated values. The
// first value is the name of the mask and the remaining values are the station
// ID's to be used. If it's a string, interpret anything before a colon as the
// name of the mask and parse after the colon as a comma-separated list of
// station ID's to be used. If no colon is present, select a default mask name.
// Store the results in the output StringArray.
//
///////////////////////////////////////////////////////////////////////////////
void parse_sid_mask(const ConcatString &mask_sid_str,
StringArray &mask_sid, ConcatString &mask_name) {
ifstream in;
ConcatString tmp_file;
std::string sid_str;
// Initialize
mask_sid.clear();
mask_name = na_str;
// Check for an empty length string
if(mask_sid_str.empty()) return;
// Replace any instances of MET_BASE with it's expanded value
tmp_file = replace_path(mask_sid_str.c_str());
// Process file name
if(file_exists(tmp_file.c_str())) {
mlog << Debug(4) << "parse_sid_mask() -> "
<< "parsing station ID masking file \"" << tmp_file << "\"\n";
// Open the mask station id file specified
in.open(tmp_file.c_str());
if(!in) {
mlog << Error << "\nparse_sid_mask() -> "
<< "Can't open the station ID masking file \""
<< tmp_file << "\".\n\n";
exit(1);
}
// Store the first entry as the name of the mask
in >> sid_str;
mask_name = sid_str;
// Store the rest of the entries as masking station ID's
while(in >> sid_str) mask_sid.add(sid_str.c_str());
// Close the input file
in.close();
mlog << Debug(4) << "parse_sid_mask() -> "
<< "parsed " << mask_sid.n() << " station ID's for the \""
<< mask_name << "\" mask from file \"" << tmp_file << "\"\n";
}
// Process list of strings
else {
// Print a warning if the string contains a dot which suggests
// the user was trying to specify a file name.
if(check_reg_exp("[.]", mask_sid_str.c_str())) {
mlog << Warning << "\nparse_sid_mask() -> "
<< "unable to process \"" << mask_sid_str
<< "\" as a file name and processing it as a single "
<< "station ID mask instead.\n\n";
}
mlog << Debug(4) << "parse_sid_mask() -> "
<< "storing single station ID mask \"" << mask_sid_str << "\"\n";
// Check for embedded whitespace or slashes
if(check_reg_exp(ws_reg_exp, mask_sid_str.c_str()) ||
check_reg_exp("[/]", mask_sid_str.c_str())) {
mlog << Error << "\nparse_sid_mask() -> "
<< "masking station ID string can't contain whitespace or "
<< "slashes \"" << mask_sid_str << "\".\n\n";
exit(1);
}
// Check for the optional mask name
StringArray sa;
sa = mask_sid_str.split(":");
// One elements means no colon was specified
if(sa.n() == 1) {
mask_sid.add_css(sa[0]);
mask_name = ( mask_sid.n() == 1 ? mask_sid[0] : "MASK_SID" );
}
// Two elements means one colon was specified
else if(sa.n() == 2) {
mask_name = sa[0];
mask_sid.add_css(sa[1]);
}
else {
mlog << Error << "\nparse_sid_mask() -> "
<< "masking station ID string may contain at most one colon to "
<< "specify the mask name \"" << mask_sid_str << "\".\n\n";
exit(1);
}
}
// Sort the mask_sid's
mask_sid.sort();
return;
}
///////////////////////////////////////////////////////////////////////////////
void MaskLatLon::clear() {
name.clear();
lat_thresh.clear();
lon_thresh.clear();
}
///////////////////////////////////////////////////////////////////////////////
bool MaskLatLon::operator==(const MaskLatLon &v) const {
bool match = true;
if(!(name == v.name ) ||
!(lat_thresh == v.lat_thresh) ||
!(lon_thresh == v.lon_thresh)) {
match = false;
}
return(match);
}
///////////////////////////////////////////////////////////////////////////////
vector<MaskLatLon> parse_conf_llpnt_mask(Dictionary *dict) {
const DictionaryEntry *entry;
Dictionary *llpnt_dict;
vector<MaskLatLon> v;
MaskLatLon m;
int i, n_entries;
if(!dict) {
mlog << Error << "\nparse_conf_llpnt_mask() -> "
<< "empty dictionary!\n\n";
exit(1);
}
// Lookup the mask.point entry
entry = dict->lookup(conf_key_mask_llpnt);
// Process an array of dictionaries
if(entry->is_array()) {
llpnt_dict = entry->array_value();
n_entries = llpnt_dict->n_entries();
}
// Process a single dictionary
else {
llpnt_dict = entry->dict_value();
n_entries = 1;
}
// Loop through the array entries
for(i=0; i<n_entries; i++) {
// Get the methods and widths for the current entry
if(entry->type() == ArrayType) {
m.name = (*llpnt_dict)[i]->dict_value()->lookup_string(conf_key_name);
m.lat_thresh = (*llpnt_dict)[i]->dict_value()->lookup_thresh(conf_key_lat_thresh);
m.lon_thresh = (*llpnt_dict)[i]->dict_value()->lookup_thresh(conf_key_lon_thresh);
}
else {
m.name = llpnt_dict->lookup_string(conf_key_name);
m.lat_thresh = llpnt_dict->lookup_thresh(conf_key_lat_thresh);
m.lon_thresh = llpnt_dict->lookup_thresh(conf_key_lon_thresh);
}
// Add current MaskLatLon to the vector
v.push_back(m);
}
return(v);
}
///////////////////////////////////////////////////////////////////////////////
StringArray parse_conf_obs_qty_inc(Dictionary *dict) {
StringArray sa;
const char *method_name = "parse_conf_obs_qty_inc() -> ";
// Check for old "obs_quality" entry
sa = dict->lookup_string_array(conf_key_obs_qty, false);
// Print a warning if the deprecated option was used
if(dict->last_lookup_status()) {
mlog << Warning << "\nparse_conf_obs_qty_inc() -> "
<< "Set the \"" << conf_key_obs_qty_inc << "\" value ("
<< write_css(sa) << ") from the deprecated \""
<< conf_key_obs_qty << "\" configuration entry.\n"
<< "Replace \"" << conf_key_obs_qty << "\" with \""
<< conf_key_obs_qty_inc << "\"!\n\n";
}
else {
sa = parse_conf_string_array(dict, conf_key_obs_qty_inc, method_name);
}
return(sa);
}
///////////////////////////////////////////////////////////////////////////////
StringArray parse_conf_obs_qty_exc(Dictionary *dict) {
const char *method_name = "parse_conf_obs_qty_exc() -> ";
StringArray sa = parse_conf_string_array(dict, conf_key_obs_qty_exc, method_name);
return(sa);
}
///////////////////////////////////////////////////////////////////////////////
NumArray parse_conf_ci_alpha(Dictionary *dict) {
NumArray na;
int i;
if(!dict) {
mlog << Error << "\nparse_conf_ci_alpha() -> "
<< "empty dictionary!\n\n";
exit(1);
}
na = dict->lookup_num_array(conf_key_ci_alpha);
// Check that at least one alpha value is provided
if(na.n() == 0) {
mlog << Error << "\nparse_conf_ci_alpha() -> "
<< "At least one confidence interval alpha value must be "
<< "specified.\n\n";
exit(1);
}
// Check that the values for alpha are between 0 and 1
for(i=0; i<na.n(); i++) {
if(na[i] <= 0.0 || na[i] >= 1.0) {
mlog << Error << "\nparse_conf_ci_alpha() -> "
<< "All confidence interval alpha values ("
<< na[i] << ") must be greater than 0 "
<< "and less than 1.\n\n";
exit(1);
}
}
return(na);
}
///////////////////////////////////////////////////////////////////////////////
NumArray parse_conf_eclv_points(Dictionary *dict) {
NumArray na;
int i;
if(!dict) {
mlog << Error << "\nparse_conf_eclv_points() -> "
<< "empty dictionary!\n\n";
exit(1);
}
na = dict->lookup_num_array(conf_key_eclv_points);
// Check that at least one value is provided
if(na.n() == 0) {
mlog << Error << "\nparse_conf_eclv_points() -> "
<< "At least one \"" << conf_key_eclv_points
<< "\" entry must be specified.\n\n";
exit(1);
}
// Intrepet a single value as the step size
if(na.n() == 1) {
for(i=2; i*na[0] < 1.0; i++) na.add(na[0]*i);
}
// Range check cost/loss ratios
for(i=0; i<na.n(); i++) {
if(na[i] <= 0.0 || na[i] >= 1.0) {
mlog << Error << "\nparse_conf_eclv_points() -> "
<< "All cost/loss ratios (" << na[i]
<< ") must be greater than 0 and less than 1.\n\n";
exit(1);
}
}
return(na);
}
///////////////////////////////////////////////////////////////////////////////
TimeSummaryInfo parse_conf_time_summary(Dictionary *dict) {
Dictionary *ts_dict = (Dictionary *) 0;
TimeSummaryInfo info;
bool is_correct_type = false;
if(!dict) {
mlog << Error << "\nparse_conf_time_summary() -> "
<< "empty dictionary!\n\n";
exit(1);
}
// Conf: time_summary
ts_dict = dict->lookup_dictionary(conf_key_time_summary);
// Conf: flag
info.flag = ts_dict->lookup_bool(conf_key_flag);
// Conf: flag
info.raw_data = ts_dict->lookup_bool(conf_key_raw_data);
// Conf: beg
info.beg = timestring_to_sec(ts_dict->lookup_string(conf_key_beg).c_str());
// Conf: end
info.end = timestring_to_sec(ts_dict->lookup_string(conf_key_end).c_str());
// Conf: step
info.step = ts_dict->lookup_int(conf_key_step);
if(info.step <= 0) {
mlog << Error << "\nparse_conf_time_summary() -> "
<< "The \"" << conf_key_step << "\" parameter (" << info.step
<< ") must be greater than 0!\n\n";
exit(1);
}
// Conf: width
const DictionaryEntry * entry = ts_dict->lookup(conf_key_width);
// Check that width is specified correctly
if(entry) is_correct_type = (entry->type() == IntegerType ||
entry->type() == DictionaryType);
if(!entry || !is_correct_type) {
mlog << Error << "\nparse_conf_time_summary() -> "
<< "Lookup failed for name \"" << conf_key_width << "\"\n\n";
exit(1);
}
// Parse width as an integer centered on the current timestamp
if(entry->type() == IntegerType) {
if(entry->i_value() <= 0) {
mlog << Error << "\nparse_conf_time_summary() -> "
<< "The \"" << conf_key_width << "\" parameter ("
<< entry->i_value() << ") must be greater than 0!\n\n";
exit(1);
}
info.width = entry->i_value();
info.width_beg = -1.0*nint(info.width/2.0);
info.width_end = nint(info.width/2.0);
}
// Parse width as a dictionary
else {
parse_conf_range_int(entry->dict_value(), info.width_beg, info.width_end);
info.width = info.width_end - info.width_beg;
}
// Conf: grib_code
info.grib_code = ts_dict->lookup_int_array(conf_key_grib_code, false);
info.obs_var = ts_dict->lookup_string_array(conf_key_obs_var, false);
// Conf: type
info.type = ts_dict->lookup_string_array(conf_key_type);
// Conf: vld_freq
info.vld_freq = ts_dict->lookup_int(conf_key_vld_freq);
// Conf: vld_thresh
info.vld_thresh = ts_dict->lookup_double(conf_key_vld_thresh);
// Check that the interpolation threshold is between 0 and 1.
if(info.vld_thresh < 0.0 || info.vld_thresh > 1.0) {
mlog << Error << "\nparse_conf_time_summary() -> "
<< "The \"" << conf_key_time_summary << "."
<< conf_key_vld_thresh << "\" parameter (" << info.vld_thresh
<< ") must be set between 0 and 1.\n\n";
exit(1);
}
return(info);
}
///////////////////////////////////////////////////////////////////////////////
void parse_add_conf_key_value_map(
Dictionary *dict, const char *conf_key_map_name, map<ConcatString,ConcatString> *m) {
Dictionary *map_dict = (Dictionary *) 0;
ConcatString key, val;
int i;
if(!dict) {
mlog << Error << "\nparse_conf_key_value_type_map() -> "
<< "empty dictionary!\n\n";
exit(1);
}
// Conf: map_name: message_type_map, obs)var_map, etc
map_dict = dict->lookup_array(conf_key_map_name);
// Loop through the array entries
for(i=0; i<map_dict->n_entries(); i++) {
// Lookup the key and value
key = (*map_dict)[i]->dict_value()->lookup_string(conf_key_key);
val = (*map_dict)[i]->dict_value()->lookup_string(conf_key_val);
if(m->count(key) >= 1) {