Skip to content

Commit

Permalink
Support for NAN in Define expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
tskille committed Sep 2, 2022
1 parent d50dbd0 commit 7049a1f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
24 changes: 24 additions & 0 deletions appl/derived_smry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,29 @@ std::vector<float> DerivedSmry::calc_derived_vect(const std::string& expr,
return derived_vect;
}

int DerivedSmry::replace_all(std::string& line, const std::string& repstr1, const std::string& repstr2, const std::string& newstr)
{
int count = 0;

for (auto& repstr : {
repstr1, repstr2
}) {

int p1 = line.find(repstr);

while ( p1 != std::string::npos ) {

line.replace(p1, repstr.size(), newstr);
count ++;

p1 = line.find(repstr);
}
}

return count;
}



void DerivedSmry::calc_math_expr(std::vector<float>& derived_vect, const std::string& expr,
const std::vector<std::string>& param_name_list,
Expand Down Expand Up @@ -599,6 +622,7 @@ void DerivedSmry::calc_derived_smry(const std::vector<FileType>& file_type,
param_data.push_back(smry_vect);
}

int ant = replace_all(expr_str, "NaN", "NAN", "0.0/0.0");
auto derived_vect = calc_derived_vect(expr_str, param_name_list, time_vect, param_time_vect_ind, param_data);

std::tuple<int, std::string> smry_key = std::make_tuple(var_smry_id, var_smry_key);
Expand Down
4 changes: 2 additions & 2 deletions appl/derived_smry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ class DerivedSmry

std::map<std::tuple<int, std::string>, std::string> m_unit_list;


std::vector<define_type> m_define_table;


int param_exists(const param_list_type& param_list, int smry_id, const std::string& key);
void make_define_table(const define_vect_type& define_vect);

Expand Down Expand Up @@ -118,6 +116,8 @@ class DerivedSmry
const std::vector<std::vector<float>>& param_vect);


int replace_all(std::string& line, const std::string& repstr1, const std::string& repstr2, const std::string& newstr);

};

#endif
Binary file modified tests/REF_DEFINE.DATA
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/cmd_files/test1h.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


DEFINE ?:FOWR = IF(${FWPR}>25.0,${FOPR}/${FWPR},0.0)
DEFINE ?:FOWR = IF(${FWPR}>25.0,${FOPR}/${FWPR},NAN)

FOR SMRY_ID IN RANGE(1, $NUM_CASES)
ADD CHART
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cmdf_define.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,9 @@ void TestQsummary::test_1h()
ref_params_vect.resize(3);
ref_expr_vect.resize(3);

ref_expr_vect[0] = "IF(X1>25.0,X2/X1,0.0)";
ref_expr_vect[1] = "IF(X1>25.0,X2/X1,0.0)";
ref_expr_vect[2] = "IF(X1>25.0,X2/X1,0.0)";
ref_expr_vect[0] = "IF(X1>25.0,X2/X1,NAN)";
ref_expr_vect[1] = "IF(X1>25.0,X2/X1,NAN)";
ref_expr_vect[2] = "IF(X1>25.0,X2/X1,NAN)";

ref_var_vect[0] = {0, "FOWR", "None"};
ref_var_vect[1] = {1, "FOWR", "None"};
Expand Down

0 comments on commit 7049a1f

Please sign in to comment.