Skip to content

Commit

Permalink
Per #1870, move the subset_write_valid() functionality to the library…
Browse files Browse the repository at this point in the history
… code and support it for both track and probability arrays.
  • Loading branch information
JohnHalleyGotway committed Aug 5, 2021
1 parent d471bbf commit d78cc12
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 53 deletions.
17 changes: 17 additions & 0 deletions met/src/libcode/vx_tc_util/prob_rirw_pair_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,20 @@ bool ProbRIRWPairInfoArray::add(const ProbRIRWInfo &p, const TrackInfo &t) {

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

void ProbRIRWPairInfoArray::subset_write_valid(const TimeArray &ta) {

// Check for no work to do
if(ta.n() == 0) return;

ProbRIRWPairInfoArray new_pairs;
for(int i=0; i<Pairs.size(); i++) {
if(ta.has(Pairs[i].prob_rirw().valid())) new_pairs.add(Pairs[i]);
}

// Save the subset
*this = new_pairs;

return;
}

////////////////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions met/src/libcode/vx_tc_util/prob_rirw_pair_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class ProbRIRWPairInfoArray {

void add(const ProbRIRWPairInfo &);
bool add(const ProbRIRWInfo &, const TrackInfo &);
void subset_write_valid(const TimeArray &);
};

////////////////////////////////////////////////////////////////////////
Expand Down
36 changes: 15 additions & 21 deletions met/src/libcode/vx_tc_util/track_pair_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -980,23 +980,6 @@ void TrackPairInfoArray::extend(int n, bool exact) {

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

void TrackPairInfoArray::set_keep(int i, int j, int val) {

// Check range
if(i < 0 || i >= NPairs) {
mlog << Error
<< "\nTrackPairInfoArray::set_keep(int, int, int) -> "
<< "range check error for index value " << i << "\n\n";
exit(1);
}

Pair[i].set_keep(j, val);

return;
}

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

const TrackPairInfo & TrackPairInfoArray::operator[](int n) const {

// Check range
Expand Down Expand Up @@ -1045,11 +1028,22 @@ void TrackPairInfoArray::add_watch_warn(const ConcatString &ww_sid,

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

void TrackPairInfoArray::do_keep_subset() {
int i;
void TrackPairInfoArray::subset_write_valid(const TimeArray &ta) {

// Loop through the track pairs
for(i=0; i<NPairs; i++) Pair[i] = Pair[i].keep_subset();
// Check for no work to do
if(ta.n() == 0) return;

// Check each point for requested valid times
int i, j, keep;
for(i=0; i<NPairs; i++) {
for(j=0; j<Pair[i].n_points(); j++) {
keep = (ta.has(Pair[i].valid(j)) ? 1 : 0);
Pair[i].set_keep(j, keep);
}

// Subset the track
Pair[i] = Pair[i].keep_subset();
}

return;
}
Expand Down
4 changes: 1 addition & 3 deletions met/src/libcode/vx_tc_util/track_pair_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ class TrackPairInfoArray {
// set stuff
//

void set_keep(int, int, int);

//
// get stuff
//
Expand All @@ -217,7 +215,7 @@ class TrackPairInfoArray {

void add(const TrackPairInfo &);
void add_watch_warn(const ConcatString &, WatchWarnType, unixtime);
void do_keep_subset();
void subset_write_valid(const TimeArray &);
};

////////////////////////////////////////////////////////////////////////
Expand Down
45 changes: 16 additions & 29 deletions met/src/tools/tc_utils/tc_pairs/tc_pairs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ static void compute_track_err (const TrackInfo &, const TrackInfo &,
TimeArray &, NumArray &, NumArray &,
NumArray &, NumArray &, NumArray &);
static void process_watch_warn (TrackPairInfoArray &);
static void subset_write_valid (TrackPairInfoArray &);
static void write_tracks (const TrackPairInfoArray &);
static void write_prob_rirw (const ProbRIRWPairInfoArray &);
static void setup_table (AsciiTable &);
Expand Down Expand Up @@ -404,8 +403,13 @@ void process_adecks(const TrackInfoArray &bdeck_tracks) {
<< pairs.serialize_r() << "\n";
}

// Subset tracks based on requested valid output times
subset_write_valid(pairs);
// Subset pairs based on requested valid output times
if(conf_info.WriteValid.n() > 0) {
mlog << Debug(3) << "Subsetting output for "
<< conf_info.WriteValid.n()
<< " requested valid time(s).\n";
pairs.subset_write_valid(conf_info.WriteValid);
}

// Write out the track pairs
write_tracks(pairs);
Expand Down Expand Up @@ -487,6 +491,14 @@ void process_edecks(const TrackInfoArray &bdeck_tracks) {
<< prob_rirw_pairs.serialize_r() << "\n";
}

// Subset pairs based on requested valid output times
if(conf_info.WriteValid.n() > 0) {
mlog << Debug(3) << "Subsetting output for "
<< conf_info.WriteValid.n()
<< " requested valid time(s).\n";
prob_rirw_pairs.subset_write_valid(conf_info.WriteValid);
}

// Write out the ProbRIRW pairs
if(prob_rirw_pairs.n_pairs() > 0) write_prob_rirw(prob_rirw_pairs);

Expand Down Expand Up @@ -1934,31 +1946,6 @@ void process_watch_warn(TrackPairInfoArray &p) {

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

void subset_write_valid(TrackPairInfoArray &p) {

// Check for no work to do
if(conf_info.WriteValid.n() == 0) return;

mlog << Debug(3) << "Writing output for "
<< conf_info.WriteValid.n() << " requested valid time(s).\n";

// Check each point for requested valid times
int i, j, keep;
for(i=0; i<p.n_pairs(); i++) {
for(j=0; j<p[i].n_points(); j++) {
keep = (conf_info.WriteValid.has(p[i].valid(j)) ? 1 : 0);
p.set_keep(i, j, keep);
}
}

// Do the track subsetting
p.do_keep_subset();

return;
}

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

void write_tracks(const TrackPairInfoArray &p) {
int i_row, i;
TcHdrColumns tchc;
Expand Down Expand Up @@ -2081,7 +2068,7 @@ void write_prob_rirw(const ProbRIRWPairInfoArray &p) {
tchc.set_cyclone(p[i].prob_rirw().cyclone());
tchc.set_storm_name(p[i].bdeck()->storm_name());

// Write the current TrackPairInfo object
// Write the current ProbRIRWPairInfo object
write_prob_rirw_row(tchc, p[i], out_at, i_row);
}

Expand Down

0 comments on commit d78cc12

Please sign in to comment.