-
Notifications
You must be signed in to change notification settings - Fork 22
/
tc_gen.cc
951 lines (762 loc) · 29.5 KB
/
tc_gen.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
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2020
// ** 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
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
////////////////////////////////////////////////////////////////////////
//
// Filename: tc_gen.cc
//
// Description:
//
// Mod# Date Name Description
// ---- ---- ---- -----------
// 000 05/17/19 Halley Gotway New
//
////////////////////////////////////////////////////////////////////////
using namespace std;
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <dirent.h>
#include <iostream>
#include <fstream>
#include <map>
#include <math.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "tc_gen.h"
#include "vx_statistics.h"
#include "vx_tc_util.h"
#include "vx_grid.h"
#include "vx_util.h"
#include "vx_log.h"
#include "met_file.h"
////////////////////////////////////////////////////////////////////////
static void process_command_line (int, char **);
static void process_genesis ();
static void get_atcf_files (const StringArray &,
const StringArray &,
const char *,
StringArray &, StringArray &);
static void process_track_files (const StringArray &,
const StringArray &,
GenesisInfoArray &, bool);
static void process_genesis_pair (int, const ConcatString &,
const GenesisInfoArray &,
const GenesisInfoArray &,
const GenesisInfoArray &,
GenCTCInfo &);
static void setup_txt_files (int);
static void setup_table (AsciiTable &);
static void write_cts (int, GenCTCInfo &);
static void finish_txt_files ();
static void usage ();
static void set_genesis (const StringArray &);
static void set_track (const StringArray &);
static void set_config (const StringArray &);
static void set_out (const StringArray &);
static void set_logfile (const StringArray &);
static void set_verbosity (const StringArray &);
////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) {
// Set handler to be called for memory allocation error
set_new_handler(oom);
// Process the command line arguments
process_command_line(argc, argv);
// Identify and process genesis events and write output
process_genesis();
return(0);
}
////////////////////////////////////////////////////////////////////////
void process_command_line(int argc, char **argv) {
CommandLine cline;
ConcatString default_config_file;
int i;
// Default output file
out_base = "./tc_gen";
// Parse the command line into tokens
cline.set(argc, argv);
// Set the usage function
cline.set_usage(usage);
// Add function calls for the arguments
cline.add(set_genesis, "-genesis", -1);
cline.add(set_track, "-track", -1);
cline.add(set_config, "-config", 1);
cline.add(set_out, "-out", 1);
cline.add(set_logfile, "-log", 1);
cline.add(set_verbosity, "-v", 1);
// Parse the command line
cline.parse();
// Add empty suffix strings, as needed
for(i=genesis_model_suffix.n(); i<genesis_source.n(); i++) {
genesis_model_suffix.add("");
}
for(i=track_model_suffix.n(); i<track_source.n(); i++) {
track_model_suffix.add("");
}
// Check for the minimum number of arguments
if(genesis_source.n() == 0 ||
track_source.n() == 0 ||
config_file.length() == 0) {
mlog << Error
<< "\nprocess_command_line(int argc, char **argv) -> "
<< "the \"-genesis\", \"-track\", and \"-config\" command "
<< "line options are required\n\n";
usage();
}
// List the input genesis track files
for(i=0; i<genesis_source.n(); i++) {
mlog << Debug(1)
<< "[Source " << i+1 << " of " << genesis_source.n()
<< "] Genesis Source: " << genesis_source[i]
<< ", Model Suffix: " << genesis_model_suffix[i] << "\n";
}
// List the input track track files
for(i=0; i<track_source.n(); i++) {
mlog << Debug(1)
<< "[Source " << i+1 << " of " << track_source.n()
<< "] Track Source: " << track_source[i]
<< ", Model Suffix: " << track_model_suffix[i] << "\n";
}
// Create the default config file name
default_config_file = replace_path(default_config_filename);
// List the config files
mlog << Debug(1)
<< "Config File Default: " << default_config_file << "\n"
<< "Config File User: " << config_file << "\n";
// Read the config files
conf_info.read_config(default_config_file.c_str(),
config_file.c_str());
return;
}
////////////////////////////////////////////////////////////////////////
void process_genesis() {
int i, j;
StringArray genesis_files, genesis_files_model_suffix;
StringArray track_files, track_files_model_suffix;
GenesisInfoArray fcst_ga, anly_ga, cur_ga, best_ga, oper_ga;
map<ConcatString,GenesisInfoArray> fcst_ga_map;
map<ConcatString,GenesisInfoArray>::iterator it;
ConcatString atcf_id, cs;
GenCTCInfo cur_info;
// Get the list of genesis track files
get_atcf_files(genesis_source, genesis_model_suffix, atcf_gen_reg_exp,
genesis_files, genesis_files_model_suffix);
mlog << Debug(2)
<< "Processing " << genesis_files.n()
<< " forecast genesis track files.\n";
process_track_files(genesis_files, genesis_files_model_suffix,
fcst_ga, false);
// Get the list of verifing track files
get_atcf_files(track_source, track_model_suffix, atcf_reg_exp,
track_files, track_files_model_suffix);
mlog << Debug(2)
<< "Processing " << track_files.n()
<< " verifying track files.\n";
process_track_files(track_files, track_files_model_suffix,
anly_ga, true);
// Setup output files based on the number of techniques present
setup_txt_files(fcst_ga.n_technique());
// Process each verification filter
for(i=0; i<conf_info.n_vx(); i++) {
// Initialize
fcst_ga_map.clear();
// Subset the forecast genesis events
for(j=0; j<fcst_ga.n(); j++) {
// Check filters
if(conf_info.VxOpt[i].is_keeper(fcst_ga[j])) {
// Store the current forecast ATCF ID
atcf_id = fcst_ga[j].technique();
// Check specified forecast models
if(conf_info.VxOpt[i].Model.n() == 0 ||
conf_info.VxOpt[i].Model.has(atcf_id)) {
// Add a new map entry, if necessary
if(fcst_ga_map.count(atcf_id) == 0) {
cur_ga.clear();
fcst_ga_map[atcf_id] = cur_ga;
}
// Store the current object
fcst_ga_map[atcf_id].add(fcst_ga[j]);
}
}
} // end j
// Subset the BEST and operational genesis events
best_ga.clear();
oper_ga.clear();
for(j=0; j<anly_ga.n(); j++) {
// Check filters
if(conf_info.VxOpt[i].is_keeper(anly_ga[j])) {
if(anly_ga[j].technique() == conf_info.BestEventInfo.Technique) {
best_ga.add(anly_ga[j]);
}
else if(anly_ga[j].technique() == conf_info.OperEventInfo.Technique) {
oper_ga.add(anly_ga[j]);
}
}
} // end for j
// Loop through and process the genesis event pairs
for(j=0,it=fcst_ga_map.begin(); it!=fcst_ga_map.end(); it++,j++) {
mlog << Debug(2)
<< "[Filter " << i+1 << " (" << conf_info.VxOpt[i].Desc
<< ") " << ": Model " << j+1 << "] " << "For " << it->first
<< " model, comparing " << it->second.n()
<< " genesis forecasts to " << best_ga.n() << " "
<< conf_info.BestEventInfo.Technique << " and "
<< oper_ga.n() << " " << conf_info.OperEventInfo.Technique
<< " genesis events.\n";
process_genesis_pair(i, it->first, it->second,
best_ga, oper_ga, cur_info);
// Write output for the current model
cur_info.model = it->first;
write_cts(i, cur_info);
} // end for j
} // end for i n_vx
// Finish output files
finish_txt_files();
return;
}
////////////////////////////////////////////////////////////////////////
//
// For each genesis forecast, find the matching BEST tracks genesis
// event that is the closest in space and time, where:
// (1) The difference between the BEST and forecast track genesis falls
// within the configurable genesis_window.
// (2) The distance between the BEST and forecast genesis locations is
// less than the configurable genesis_radius.
// (3) For multiple BEST track matches, choose the one closest in space.
//
// If there are no BEST track matches, apply to same logic with the
// operational baseline genesis events.
//
// Any genesis forecast with a BEST or operational match is a HIT.
//
// Any genesis forecast with no BEST or operational match is a FALSE
// ALARM.
//
// For each BEST track genesis event, define the timing information for
// the model's opportunities to forecast that genesis event using the
// configurable init_freq and lead_window options. Any case for which
// no match exists is a MISS.
//
////////////////////////////////////////////////////////////////////////
void process_genesis_pair(int i_vx, const ConcatString &model,
const GenesisInfoArray &fga,
const GenesisInfoArray &bga,
const GenesisInfoArray &oga,
GenCTCInfo &info) {
int i, j, i_match;
unixtime ut, init_beg, init_end;
map<ConcatString,GenCTCInfo> info_map;
vector<const GenesisInfo *> fga_match;
const GenesisInfo *g_ptr;
bool match;
// Initialize
info.clear();
// Loop over the model genesis events to find HITS and FALSE ALARMS
for(i=0; i<fga.n(); i++) {
// Initialize
g_ptr = 0;
// Keep track of timing info
info.add_fcst_valid(fga[i].valid_min(), fga[i].valid_max());
// Find BEST track match
i_match = bga.find_match(fga[i],
conf_info.VxOpt[i_vx].GenesisRadius,
conf_info.VxOpt[i_vx].GenesisSecBeg,
conf_info.VxOpt[i_vx].GenesisSecEnd);
if(!is_bad_data(i_match)) g_ptr = &bga[i_match];
// Otherwise, find operational track match
if(is_bad_data(i_match)) {
i_match = oga.find_match(fga[i],
conf_info.VxOpt[i_vx].GenesisRadius,
conf_info.VxOpt[i_vx].GenesisSecBeg,
conf_info.VxOpt[i_vx].GenesisSecEnd);
if(!is_bad_data(i_match)) g_ptr = &oga[i_match];
}
// Store the match pointer
fga_match.push_back(g_ptr);
// Print log messages about matches
if(g_ptr) {
mlog << Debug(4) << fga[i].technique() << " "
<< unix_to_yyyymmdd_hhmmss(fga[i].init())
<< " initialization, "
<< fga[i].lead_time()/sec_per_hour << " lead, "
<< unix_to_yyyymmdd_hhmmss(fga[i].genesis_time())
<< " genesis at ("
<< fga[i].lat() << ", " << fga[i].lon()
<< ") is a HIT for " << g_ptr->technique() << " "
<< unix_to_yyyymmdd_hhmmss(g_ptr->genesis_time())
<< " genesis at (" << g_ptr->lat() << ", "
<< g_ptr->lon() << ").\n";
// Increment the HIT count
info.cts_info.cts.inc_fy_oy();
}
else {
mlog << Debug(4) << fga[i].technique() << " "
<< unix_to_yyyymmdd_hhmmss(fga[i].init())
<< " initialization, "
<< fga[i].lead_time()/sec_per_hour << " lead, "
<< unix_to_yyyymmdd_hhmmss(fga[i].genesis_time())
<< " genesis at (" << fga[i].lat() << ", "
<< fga[i].lon() << ") is a FALSE ALARM.\n";
// Increment the FALSE ALARM count
info.cts_info.cts.inc_fy_on();
}
} // end for i fga
// Loop over the BEST track genesis events to find MISSES
for(i=0; i<bga.n(); i++) {
// Keep track of timing info
info.add_obs_valid(bga[i].valid_min(), bga[i].valid_max());
// Define opportunities to forecast this genesis event
init_beg = bga[i].genesis_time() - conf_info.LeadSecEnd;
init_end = bga[i].genesis_time() - conf_info.LeadSecBeg;
// Loop over the model opportunities
for(ut=init_beg; ut<=init_end; ut+=conf_info.InitFreqSec) {
// Search for forecast genesis events matching this BEST track
// genesis event for each possible combination of initialization
// and lead time.
for(j=0, match=false; j<fga.n(); j++) {
if(fga_match[j] == &bga[i] && fga[j].init() == ut) {
mlog << Debug(4) << bga[i].technique() << " "
<< unix_to_yyyymmdd_hhmmss(bga[i].genesis_time())
<< " genesis at (" << bga[i].lat() << ", "
<< bga[i].lon() << ") for "
<< unix_to_yyyymmdd_hhmmss(ut)
<< " initialization "
<< (bga[i].genesis_time() - ut)/sec_per_hour
<< " lead matches " << fga[j].technique() << " "
<< unix_to_yyyymmdd_hhmmss(fga[j].genesis_time())
<< " genesis at (" << fga[j].lat() << ", "
<< fga[j].lon() << ").\n";
match = true;
break;
}
}
// Increment the MISS count
if(!match) {
mlog << Debug(4) << bga[i].technique() << " "
<< unix_to_yyyymmdd_hhmmss(bga[i].genesis_time())
<< " genesis at (" << bga[i].lat() << ", "
<< bga[i].lon() << ") for "
<< unix_to_yyyymmdd_hhmmss(ut) << " initialization "
<< (bga[i].genesis_time() - ut)/sec_per_hour
<< " lead is a MISS.\n";
info.cts_info.cts.inc_fn_oy();
}
} // end for ut
} // end for i bga
mlog << Debug(3) << "For " << model
<< " model, contingency table hits = "
<< info.cts_info.cts.fy_oy() << ", false alarms = "
<< info.cts_info.cts.fy_on() << ", and misses = "
<< info.cts_info.cts.fn_oy() << ".\n";
return;
}
////////////////////////////////////////////////////////////////////////
void get_atcf_files(const StringArray &source,
const StringArray &model_suffix,
const char *reg_exp,
StringArray &files,
StringArray &files_model_suffix) {
StringArray cur_source, cur_files;
int i, j;
// Initialize
files.clear();
files_model_suffix.clear();
// Build list of files and corresponding model suffix list
for(i=0; i<source.n(); i++) {
cur_source.clear();
cur_source.add(source[i]);
cur_files = get_filenames(cur_source, NULL, reg_exp);
for(j=0; j<cur_files.n(); j++) {
files.add(cur_files[j]);
files_model_suffix.add(model_suffix[i]);
}
}
return;
}
////////////////////////////////////////////////////////////////////////
void process_track_files(const StringArray &files,
const StringArray &model_suffix,
GenesisInfoArray &genesis, bool is_anly) {
int i, j, k;
int n_lines, tot_lines, tot_tracks, n_genesis;
ConcatString cs, atcf_ids;
LineDataFile f;
ATCFTrackLine line;
TrackInfoArray tracks;
bool keep;
// Analysis ATCF ID's
if(is_anly) {
atcf_ids << conf_info.BestEventInfo.Technique;
if(conf_info.OperEventInfo.Technique.nonempty()) {
atcf_ids << " or " << conf_info.OperEventInfo.Technique << " analysis";
}
}
// Forecast ATCF ID's
else {
atcf_ids << "forecast";
}
// Initialize
genesis.clear();
tot_lines = tot_tracks = n_genesis = 0;
// Process each of the input ATCF files
for(i=0; i<files.n(); i++) {
// Open the current file
if(!f.open(files[i].c_str())) {
mlog << Error
<< "\nprocess_track_files() -> "
<< "unable to open file \"" << files[i] << "\"\n\n";
exit(1);
}
// Initialize
tracks.clear();
n_lines = 0;
// Read each input line. Track lines may be interleaved
// within a file but cannot span multiple files.
while(f >> line) {
// Increment the line counts
n_lines++;
// Add model suffix, if specified
if(model_suffix[i].length() > 0) {
cs << cs_erase << line.technique() << model_suffix[i];
line.set_technique(cs);
}
// Check for BEST and operational track technqiue
line.set_best_track(line.technique() == conf_info.BestEventInfo.Technique);
line.set_oper_track(line.technique() == conf_info.OperEventInfo.Technique);
// Only process the specified BEST and operational track
if(is_anly && !line.is_best_track() && !line.is_oper_track()) {
continue;
}
// Add the current line checking for analysis tracks
tracks.add(line, false, true);
}
// Increment counts
tot_lines += n_lines;
tot_tracks += tracks.n();
// Close the current file
f.close();
// Search the tracks for genesis events
for(j=0; j<tracks.n(); j++) {
// Check for empty tracks
if(tracks[j].n_points() == 0) {
continue;
}
// Check the model genesis event criteria
if(!is_anly) {
// Check the lead time window
if(tracks[j][0].lead() < conf_info.LeadSecBeg ||
tracks[j][0].lead() > conf_info.LeadSecEnd) {
continue;
}
// Check the minimum duration
if(tracks[j].duration() < conf_info.MinDur*sec_per_hour) {
continue;
}
// Check the genesis event criteria for each track point
keep = false;
for(k=0; k<tracks[j].n_points(); k++) {
if(conf_info.FcstEventInfo.is_keeper(tracks[j][k])) {
keep = true;
break;
}
} // end for k
if(!keep) continue;
}
// Store the genesis event
genesis.add(tracks[j]);
} // end for j
// Dump out the current number of lines
mlog << Debug(4)
<< "[File " << i+1 << " of " << files.n() << "] Found "
<< genesis.n() - n_genesis << " " << atcf_ids
<< " genesis events, from " << tracks.n()
<< " tracks, from " << n_lines
<< " input lines, from file \"" << files[i] << "\".\n";
n_genesis = genesis.n();
} // end for i
// Dump out the total number of lines
mlog << Debug(3)
<< "Found a total of " << genesis.n() << " " << atcf_ids
<< " genesis events, from " << tot_tracks << " tracks, from "
<< tot_lines << " input lines, from " << files.n()
<< " input files.\n";
// Compute the distance to land
for(i=0; i<genesis.n(); i++) {
genesis.set_dland(i, conf_info.compute_dland( genesis[i].lat(),
-1.0*genesis[i].lon()));
}
// Dump out the track information
mlog << Debug(2)
<< "Identified " << genesis.n() << " "
<< (is_anly ? "analysis" : "forecast")
<< " genesis events.\n";
// Dump out very verbose output
if(mlog.verbosity_level() >= 6) {
mlog << Debug(6)
<< genesis.serialize_r() << "\n";
}
// Dump out track info
else {
for(i=0; i<genesis.n(); i++) {
mlog << Debug(6)
<< "[Genesis " << i+1 << " of " << genesis.n()
<< "] " << genesis[i].serialize() << "\n";
}
}
return;
}
////////////////////////////////////////////////////////////////////////
//
// Setup the output ASCII files
//
////////////////////////////////////////////////////////////////////////
void setup_txt_files(int n_model) {
int i, n_rows, n_cols;
// Initialize file stream
stat_out = (ofstream *) 0;
// Build the file name
stat_file << out_base << stat_file_ext;
// Create the output STAT file
open_txt_file(stat_out, stat_file.c_str());
// Setup the STAT AsciiTable
n_rows = 1 + 3 * n_model * conf_info.n_vx();
n_cols = 1 + n_header_columns + n_cts_columns;
stat_at.set_size(n_rows, n_cols);
setup_table(stat_at);
// Write the text header row
write_header_row((const char **) 0, 0, 1, stat_at, 0, 0);
// Initialize the row index to 1 to account for the header
i_stat_row = 1;
// Setup each of the optional output text files
for(i=0; i<n_txt; i++) {
// Only set it up if requested in the config file
if(conf_info.OutputMap[txt_file_type[i]] == STATOutputType_Both) {
// Initialize file stream
txt_out[i] = (ofstream *) 0;
// Build the file name
txt_file[i] << out_base << "_" << txt_file_abbr[i]
<< txt_file_ext;
// Create the output text file
open_txt_file(txt_out[i], txt_file[i].c_str());
// Setup the text AsciiTable
n_rows = 1 + n_model * conf_info.n_vx();
n_cols = 1 + n_header_columns + n_txt_columns[i];
txt_at[i].set_size(n_rows, n_cols);
setup_table(txt_at[i]);
// Write header row
write_header_row(txt_columns[i], n_txt_columns[i], 1,
txt_at[i], 0, 0);
// Initialize the row index to 1 to account for the header
i_txt_row[i] = 1;
}
}
return;
}
////////////////////////////////////////////////////////////////////////
void setup_table(AsciiTable &at) {
// Justify the STAT AsciiTable objects
justify_stat_cols(at);
// Set the precision
at.set_precision(conf_info.Conf.output_precision());
// Set the bad data value
at.set_bad_data_value(bad_data_double);
// Set the bad data string
at.set_bad_data_str(na_str);
// Don't write out trailing blank rows
at.set_delete_trailing_blank_rows(1);
return;
}
////////////////////////////////////////////////////////////////////////
void write_cts(int i_vx, GenCTCInfo &info) {
ConcatString var_name("GENESIS");
// Setup header columns
shc.set_model(info.model.c_str());
shc.set_desc(conf_info.VxOpt[i_vx].Desc.c_str());
if(conf_info.VxOpt[i_vx].Lead.n() == 1) {
shc.set_fcst_lead_sec(conf_info.VxOpt[i_vx].Lead[0]);
}
shc.set_fcst_valid_beg(conf_info.VxOpt[i_vx].ValidBeg != 0 ?
conf_info.VxOpt[i_vx].ValidBeg : info.fbeg);
shc.set_fcst_valid_end(conf_info.VxOpt[i_vx].ValidEnd != 0 ?
conf_info.VxOpt[i_vx].ValidEnd : info.fend);
shc.set_obs_valid_beg(conf_info.VxOpt[i_vx].ValidBeg != 0 ?
conf_info.VxOpt[i_vx].ValidBeg : info.obeg);
shc.set_obs_valid_end(conf_info.VxOpt[i_vx].ValidEnd != 0 ?
conf_info.VxOpt[i_vx].ValidEnd : info.oend);
shc.set_fcst_var(var_name);
shc.set_obs_var(var_name);
shc.set_obtype(conf_info.BestEventInfo.Technique.c_str());
if(!conf_info.VxOpt[i_vx].VxMaskName.empty()) {
shc.set_mask(conf_info.VxOpt[i_vx].VxMaskName.c_str());
}
// Write out FHO
if(conf_info.OutputMap[stat_fho] != STATOutputType_None) {
write_fho_row(shc, info.cts_info,
conf_info.OutputMap[stat_fho],
stat_at, i_stat_row,
txt_at[i_fho], i_txt_row[i_fho]);
}
// Write out CTC
if(conf_info.OutputMap[stat_ctc] != STATOutputType_None) {
write_ctc_row(shc, info.cts_info,
conf_info.OutputMap[stat_ctc],
stat_at, i_stat_row,
txt_at[i_ctc], i_txt_row[i_ctc]);
}
// Write out CTS
if(conf_info.OutputMap[stat_cts] != STATOutputType_None) {
// Compute the statistics
info.cts_info.allocate_n_alpha(1);
info.cts_info.alpha[0] = conf_info.CIAlpha;
info.cts_info.compute_stats();
info.cts_info.compute_ci();
write_cts_row(shc, info.cts_info,
conf_info.OutputMap[stat_cts],
stat_at, i_stat_row,
txt_at[i_cts], i_txt_row[i_cts]);
}
return;
}
////////////////////////////////////////////////////////////////////////
void finish_txt_files() {
int i;
// Write out the contents of the STAT AsciiTable and close the STAT
// output files
if(stat_out) {
*stat_out << stat_at;
close_txt_file(stat_out, stat_file.c_str());
}
// Finish up each of the optional text files
for(i=0; i<n_txt; i++) {
// Only write the table if requested in the config file
if(conf_info.OutputMap[txt_file_type[i]] == STATOutputType_Both) {
// Write the AsciiTable to a file
if(txt_out[i]) {
*txt_out[i] << txt_at[i];
close_txt_file(txt_out[i], txt_file[i].c_str());
}
}
}
return;
}
////////////////////////////////////////////////////////////////////////
void usage() {
cout << "\n*** Model Evaluation Tools (MET" << met_version
<< ") ***\n\n"
<< "Usage: " << program_name << "\n"
<< "\t-genesis path\n"
<< "\t-track path\n"
<< "\t-config file\n"
<< "\t[-out base]\n"
<< "\t[-log file]\n"
<< "\t[-v level]\n\n"
<< "\twhere\t\"-genesis path\" specifies an ATCF genesis file "
<< "or top-level directory with files matching the regular "
<< "expression \"" << atcf_gen_reg_exp << "\" (required).\n"
<< "\t\t\"-track path\" specifies an ATCF track file or "
<< "top-level directory with files matching the regular "
<< "expression \"" << atcf_reg_exp << "\" for the verifying "
<< "BEST and operational tracks (required).\n"
<< "\t\t\"-config file\" is used once to specify the "
<< "TCGenConfig file containing the desired configuration "
<< "settings (required).\n"
<< "\t\t\"-out base\" overrides the default output file base "
<< "(" << out_base << ") (optional).\n"
<< "\t\t\"-log file\" outputs log messages to the specified "
<< "file (optional).\n"
<< "\t\t\"-v level\" overrides the default level of logging ("
<< mlog.verbosity_level() << ") (optional).\n\n";
exit(1);
}
////////////////////////////////////////////////////////////////////////
void set_genesis(const StringArray & a) {
int i;
StringArray sa;
ConcatString cs;
// Check for optional suffix sub-argument
for(i=0; i<a.n(); i++) {
cs = a[i];
if(cs.startswith("suffix")) {
sa = cs.split("=");
if(sa.n() != 2) {
mlog << Error << "\nset_genesis() -> "
<< "the model suffix must be specified as "
<< "\"suffix=string\".\n\n";
}
else {
genesis_model_suffix.add(sa[1]);
}
}
else {
genesis_source.add(a[i]);
}
}
// Check for consistent usage
if(genesis_model_suffix.n() > 0 &&
genesis_model_suffix.n() != genesis_source.n()) {
mlog << Error << "\nset_genesis() -> "
<< "the number of \"suffix=string\" options must match the "
<< "number of -genesis options.\n\n";
exit(1);
}
return;
}
////////////////////////////////////////////////////////////////////////
void set_track(const StringArray & a) {
int i;
StringArray sa;
ConcatString cs;
// Check for optional suffix sub-argument
for(i=0; i<a.n(); i++) {
cs = a[i];
if(cs.startswith("suffix")) {
sa = cs.split("=");
if(sa.n() != 2) {
mlog << Error << "\nset_track() -> "
<< "the model suffix must be specified as "
<< "\"suffix=string\".\n\n";
}
else {
track_model_suffix.add(sa[1]);
}
}
else {
track_source.add(a[i]);
}
}
// Check for consistent usage
if(track_model_suffix.n() > 0 &&
track_model_suffix.n() != track_source.n()) {
mlog << Error << "\nset_track() -> "
<< "the number of \"suffix=string\" options must match the "
<< "number of -track options.\n\n";
exit(1);
}
return;
}
////////////////////////////////////////////////////////////////////////
void set_config(const StringArray & a) {
config_file = a[0];
}
////////////////////////////////////////////////////////////////////////
void set_out(const StringArray & a) {
out_base = a[0];
}
////////////////////////////////////////////////////////////////////////
void set_logfile(const StringArray & a) {
ConcatString filename;
filename = a[0];
mlog.open_log_file(filename);
}
////////////////////////////////////////////////////////////////////////
void set_verbosity(const StringArray & a) {
mlog.set_verbosity_level(atoi(a[0].c_str()));
}
////////////////////////////////////////////////////////////////////////