Skip to content

Commit

Permalink
Per #1809, update the ProbInfoArray class to store arrays of both Pro…
Browse files Browse the repository at this point in the history
…bRIRWInfo and ProbGenInfo objects.
  • Loading branch information
JohnHalleyGotway committed Nov 5, 2021
1 parent 2a159e1 commit 8b8fc96
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 34 deletions.
142 changes: 111 additions & 31 deletions met/src/libcode/vx_tc_util/prob_info_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ void ProbInfoArray::init_from_scratch() {

void ProbInfoArray::clear() {

// Erase the entire vector
// Erase the entire vectors
ProbRIRW.erase(ProbRIRW.begin(), ProbRIRW.end());
ProbGen.erase(ProbGen.begin(), ProbGen.end());

return;
}
Expand All @@ -82,15 +83,23 @@ void ProbInfoArray::clear() {

void ProbInfoArray::dump(ostream &out, int indent_depth) const {
Indent prefix(indent_depth);
int i;

out << prefix << "ProbInfoArray:\n"
<< prefix << "NProbRIRW = " << n_prob_rirw() << "\n";
<< prefix << "NProbRIRW = " << n_prob_rirw() << "\n";

for(unsigned int i=0; i<ProbRIRW.size(); i++) {
for(i=0; i<ProbRIRW.size(); i++) {
out << prefix << "ProbRIRW[" << i+1 << "]:\n";
ProbRIRW[i].dump(out, indent_depth+1);
}

out << prefix << "NProbGen = " << n_prob_gen() << "\n";

for(i=0; i<ProbGen.size(); i++) {
out << prefix << "ProbGen[" << i+1 << "]:\n";
ProbGen[i].dump(out, indent_depth+1);
}

out << flush;

return;
Expand All @@ -102,7 +111,8 @@ ConcatString ProbInfoArray::serialize() const {
ConcatString s;

s << "ProbInfoArray: "
<< "NProbRIRW = " << n_prob_rirw();
<< "NProbRIRW = " << n_prob_rirw()
<< ", NProbGen = " << n_prob_gen();

return(s);
}
Expand All @@ -112,13 +122,23 @@ ConcatString ProbInfoArray::serialize() const {
ConcatString ProbInfoArray::serialize_r(int indent_depth) const {
Indent prefix(indent_depth);
ConcatString s;
int i;

s << prefix << serialize() << ", ProbRIRW:\n";

for(unsigned int i=0; i<ProbRIRW.size(); i++) {
if(ProbRIRW.size() > 0 ) {
s << prefix << serialize() << ", ProbRIRW:\n";
}
for(i=0; i<ProbRIRW.size(); i++) {
s << ProbRIRW[i].serialize_r(i+1, indent_depth+1);
}

if(ProbGen.size() > 0 ) {
s << prefix << serialize() << ", ProbGen:\n";
}

for(i=0; i<ProbGen.size(); i++) {
s << ProbGen[i].serialize_r(i+1, indent_depth+1);
}

return(s);
}

Expand All @@ -128,10 +148,8 @@ void ProbInfoArray::assign(const ProbInfoArray &p) {

clear();

// Allocate space and copy each element
for(unsigned int i=0; i<p.ProbRIRW.size(); i++) {
ProbRIRW.push_back(p.ProbRIRW[i]);
}
ProbRIRW = p.ProbRIRW;
ProbGen = p.ProbGen;

return;
}
Expand All @@ -142,16 +160,23 @@ const ProbInfoBase * ProbInfoArray::operator[](int n) const {

// Check range
if((n < 0) || (n >= n_probs())) {
mlog << Error
<< "\nProbInfoBase * ProbInfoArray::operator[] -> "
mlog << Error << "\nProbInfoBase * ProbInfoArray::operator[] -> "
<< "range check error for index value " << n << "\n\n";
exit(1);
}

// Return a base pointer to the n-th probability
// Need to revise for each new probability vector
// Get a base pointer to the n-th probability
const ProbInfoBase *ptr;

return(&ProbRIRW[n]);
if(ProbRIRW.size() > 0 && n < ProbRIRW.size()) {
ptr = &ProbRIRW[n];
}
else {
n -= ProbRIRW.size();
ptr = &ProbGen[n];
}

return(ptr);
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -160,8 +185,7 @@ const ProbRIRWInfo & ProbInfoArray::prob_rirw(int n) const {

// Check range
if((n < 0) || (n >= (int) ProbRIRW.size())) {
mlog << Error
<< "\nProbRIRWInfo & ProbInfoArray::prob_rirw(int) -> "
mlog << Error << "\nProbRIRWInfo & ProbInfoArray::prob_rirw(int) -> "
<< "range check error for index value " << n << "\n\n";
exit(1);
}
Expand All @@ -171,14 +195,29 @@ const ProbRIRWInfo & ProbInfoArray::prob_rirw(int n) const {

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

const ProbGenInfo & ProbInfoArray::prob_gen(int n) const {

// Check range
if((n < 0) || (n >= (int) ProbGen.size())) {
mlog << Error << "\nProbGenInfo & ProbInfoArray::prob_gen(int) -> "
<< "range check error for index value " << n << "\n\n";
exit(1);
}

return(ProbGen[n]);
}

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

bool ProbInfoArray::add(const ATCFProbLine &l, bool check_dup) {
bool status = false;

// Range check the probability value
if(l.prob() < 0 || l.prob() > 100) {
mlog << Debug(4)
<< "\nbool ProbInfoArray::add() -> "
mlog << Debug(4)
<< "bool ProbInfoArray::add() -> "
<< "skipping probability value (" << l.prob()
<< ") outside of range (0, 100).\n\n";
<< ") outside of range (0, 100).\n";
return(false);
}

Expand All @@ -187,27 +226,61 @@ bool ProbInfoArray::add(const ATCFProbLine &l, bool check_dup) {

case(ATCFLineType_ProbRI):

// Check for no entries or a mismatch with the latest entry
if( ProbRIRW.size() == 0 ||
(ProbRIRW.size() > 0 &&
!ProbRIRW[ProbRIRW.size()-1].add(l, check_dup))) {

// Store new entry
// Add line to an existing entry
if(ProbRIRW.size() > 0 &&
ProbRIRW[ProbRIRW.size()-1].add(l, check_dup)) {
status = true;
}
// Add a new entry
else {
ProbRIRWInfo ri;
ri.add(l, check_dup);
ProbRIRW.push_back(ri);
status = true;
}
break;

case(ATCFLineType_ProbGN):

// Add line to an existing entry
if(ProbGen.size() > 0 &&
ProbGen[ProbGen.size()-1].add(l, check_dup)) {
status = true;
}
// Add a new entry
else {
ProbGenInfo gi;
gi.add(l, check_dup);

// Check for the expected genesis type and predicted location
if(gi.gen_or_dis() != "genFcst") {
mlog << Debug(4)
<< "bool ProbInfoArray::add() -> "
<< "skipping ATCF " << atcflinetype_to_string(ATCFLineType_ProbGN)
<< " line with non-genesis probability type ("
<< gi.gen_or_dis() << " != genFcst).\n";
}
else if(is_bad_data(gi.lat()) || is_bad_data(gi.lon())) {
mlog << Debug(4)
<< "bool ProbInfoArray::add() -> "
<< "skipping ATCF " << atcflinetype_to_string(ATCFLineType_ProbGN)
<< " line with no predicted genesis location.\n";
}
else {
ProbGen.push_back(gi);
status = true;
}
}
break;

default:
mlog << Warning
<< "\nbool ProbInfoArray::add() -> "
mlog << Warning << "\nbool ProbInfoArray::add() -> "
<< "unexpected ATCF line type ("
<< atcflinetype_to_string(l.type()) << ")\n\n";
return(false);
status = false;
}

return(true);
return(status);
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -218,3 +291,10 @@ void ProbInfoArray::add(const ProbRIRWInfo &rirw) {
}

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

void ProbInfoArray::add(const ProbGenInfo &gn) {
ProbGen.push_back(gn);
return;
}

////////////////////////////////////////////////////////////////////////
12 changes: 9 additions & 3 deletions met/src/libcode/vx_tc_util/prob_info_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "atcf_prob_line.h"
#include "prob_info_base.h"
#include "prob_rirw_info.h"
#include "prob_gen_info.h"

#include "vx_util.h"

Expand All @@ -36,6 +37,7 @@ class ProbInfoArray {
void assign(const ProbInfoArray &);

vector<ProbRIRWInfo> ProbRIRW;
vector<ProbGenInfo> ProbGen;

public:

Expand All @@ -60,19 +62,23 @@ class ProbInfoArray {
int n_prob_rirw() const;
const ProbRIRWInfo & prob_rirw(int) const;

int n_prob_gen() const;
const ProbGenInfo & prob_gen(int) const;

//
// do stuff
//

bool add(const ATCFProbLine &, bool check_dup = false);
void add(const ProbRIRWInfo &);

void add(const ProbGenInfo &);
};

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

inline int ProbInfoArray::n_probs() const { return(ProbRIRW.size()); }
inline int ProbInfoArray::n_prob_rirw() const { return(ProbRIRW.size()); }
inline int ProbInfoArray::n_probs() const { return(ProbRIRW.size() + ProbGen.size()); }
inline int ProbInfoArray::n_prob_rirw() const { return(ProbRIRW.size()); }
inline int ProbInfoArray::n_prob_gen() const { return(ProbGen.size()); }

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

Expand Down

0 comments on commit 8b8fc96

Please sign in to comment.