Skip to content

Commit

Permalink
Per #2805, update STATAnalysisJob::dump_stat_line() to take an option…
Browse files Browse the repository at this point in the history
…al argument to indicate whether the set_hdr options should be applied. Update Stat-Analysis to only call dump_stat_line() with set_hdr for filter jobs.
  • Loading branch information
JohnHalleyGotway committed Jan 30, 2024
1 parent 88ee7fa commit fc5913d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
51 changes: 41 additions & 10 deletions src/libcode/vx_analysis_util/stat_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1450,14 +1450,6 @@ void STATAnalysisJob::parse_job_command(const char *jobstring) {
i+=2;
}
else if(jc_array[i] == "-set_hdr") {
n = METHdrTable.header(met_version, "STAT", na_str)->col_offset(to_upper(jc_array[i+1]).c_str());
if(is_bad_data(n)) {
mlog << Error << "\nSTATAnalysisJob::parse_job_command() -> "
<< "no match found for header column named: \""
<< to_upper((string)jc_array[i+1]) << "\"\n\n";
if(line) { delete [] line; line = (char *) 0; }
throw(1);
}
hdr_name.add_css(to_upper(jc_array[i+1]));
hdr_value.add_css(jc_array[i+2]);
i+=2;
Expand Down Expand Up @@ -1650,6 +1642,28 @@ void STATAnalysisJob::parse_job_command(const char *jobstring) {

} // end for

// Validate set_hdr column names
if(hdr_name.n() > 0) {

string lt_str = (line_type.n() == 1 ?
line_type[0] : na_str);

for(i=0; i<hdr_name.n(); i++) {

n = METHdrTable.header(met_version, "STAT", lt_str.c_str())->
col_offset(hdr_name[i].c_str());

if(is_bad_data(n)) {
mlog << Error << "\nSTATAnalysisJob::parse_job_command() -> "
<< "no match found for "
<< (line_type.n() == 1 ? line_type[0] : "header")
<< " column named \"" << hdr_name[i] << "\"\n\n";
if(line) { delete [] line; line = (char *) 0; }
throw(1);
}
} // end for
}

// Expand out_eclv_points
if(out_eclv_points.n() == 1) {
for(i=2; i*out_eclv_points[0] < 1.0; i++) out_eclv_points.add(i*out_eclv_points[0]);
Expand Down Expand Up @@ -2130,7 +2144,8 @@ void STATAnalysisJob::close_stat_file() {

////////////////////////////////////////////////////////////////////////

void STATAnalysisJob::dump_stat_line(const STATLine &line) {
void STATAnalysisJob::dump_stat_line(const STATLine &line,
bool do_set_hdr) {
int i;

//
Expand Down Expand Up @@ -2268,8 +2283,24 @@ void STATAnalysisJob::dump_stat_line(const STATLine &line) {
// Store the data line
//
for(i=0; i<line.n_items(); i++) {
dump_at.set_entry(n_dump%dump_at.nrows(), i, (string)line.get_item(i));
dump_at.set_entry(n_dump%dump_at.nrows(), i,
(string) line.get_item(i));
}

//
// Apply -set_hdr options, if requested
//
if(do_set_hdr) {
for(i=0; i<hdr_name.n(); i++) {
dump_at.set_entry(n_dump%dump_at.nrows(),
line.get_offset(hdr_name[i].c_str()),
(string) hdr_value[i]);
}
}

//
// Increment the counter
//
n_dump++;

//
Expand Down
7 changes: 5 additions & 2 deletions src/libcode/vx_analysis_util/stat_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ class STATAnalysisJob {
void set_boot_rng (const char *);
void set_boot_seed(const char *);

void set_perc_thresh(const NumArray &, const NumArray &, const NumArray &);
void set_perc_thresh(const NumArray &,
const NumArray &,
const NumArray &);

void open_dump_row_file ();
void close_dump_row_file();
void dump_stat_line (const STATLine &);
void dump_stat_line(const STATLine &,
bool do_set_hdr = false);

void open_stat_file ();
void setup_stat_file(int n_row, int n);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/core/stat_analysis/stat_analysis_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void do_job_filter(const ConcatString &jobstring, LineDataFile &f,

if(job.is_keeper(line)) {

job.dump_stat_line(line);
job.dump_stat_line(line, true);

n_out++;
}
Expand Down

0 comments on commit fc5913d

Please sign in to comment.