From 1871b026ca8487c23a025415dbc0b2eca01f9af4 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 1 Jun 2020 12:06:43 -0600 Subject: [PATCH 1/2] fixed some c2011 warnings, added more info for -formula errors, fixed pressure llnl examples --- Parser.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Parser.cxx b/Parser.cxx index c0e13059..0c39edd7 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -27,6 +27,11 @@ m_next_keyword(Keywords::KEY_NONE) if (!io) { error_msg("This parser constructor requires non-null phrq_io", PHRQ_io::OT_STOP); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; + phrq_io_only = true; + m_line_type = PHRQ_io::LT_EMPTY; } else { @@ -55,6 +60,7 @@ m_next_keyword(Keywords::KEY_NONE) echo_stream = EO_NONE; accumulate = false; phrq_io_only = false; + m_line_type = PHRQ_io::LT_EMPTY; } CParser::~CParser() @@ -326,7 +332,7 @@ PHRQ_io::LINE_TYPE CParser::get_logical_line() // remove '\\' for (; pos < m_line_save.size(); pos++) { - m_line_save[pos] = m_line_save[pos + 1]; + m_line_save[pos] = m_line_save[(size_t) pos + 1]; } m_line_save.erase(m_line_save.size() - 1, 1); break; From aa4d02340a185360f70c4c4b703ac04f5eba3973 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 1 Jun 2020 12:06:43 -0600 Subject: [PATCH 2/2] fixed some c2011 warnings, added more info for -formula errors, fixed pressure llnl examples --- common/Parser.cxx | 8 +++++++- global_structures.h | 2 ++ kinetics.cpp | 18 +++++++++++++++--- model.cpp | 24 ++++++++++++------------ parse.cpp | 8 ++++---- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/common/Parser.cxx b/common/Parser.cxx index c0e13059..0c39edd7 100644 --- a/common/Parser.cxx +++ b/common/Parser.cxx @@ -27,6 +27,11 @@ m_next_keyword(Keywords::KEY_NONE) if (!io) { error_msg("This parser constructor requires non-null phrq_io", PHRQ_io::OT_STOP); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; + phrq_io_only = true; + m_line_type = PHRQ_io::LT_EMPTY; } else { @@ -55,6 +60,7 @@ m_next_keyword(Keywords::KEY_NONE) echo_stream = EO_NONE; accumulate = false; phrq_io_only = false; + m_line_type = PHRQ_io::LT_EMPTY; } CParser::~CParser() @@ -326,7 +332,7 @@ PHRQ_io::LINE_TYPE CParser::get_logical_line() // remove '\\' for (; pos < m_line_save.size(); pos++) { - m_line_save[pos] = m_line_save[pos + 1]; + m_line_save[pos] = m_line_save[(size_t) pos + 1]; } m_line_save.erase(m_line_save.size() - 1, 1); break; diff --git a/global_structures.h b/global_structures.h index 6d824d5b..f90ec208 100644 --- a/global_structures.h +++ b/global_structures.h @@ -604,6 +604,7 @@ class cxxChemRxn public: cxxChemRxn(void) { + logk[0] = dz[0] = 0.0; for (size_t i = 0; i < MAX_LOG_K_INDICES; i++) { logk[i] = 0.0; @@ -615,6 +616,7 @@ public: } cxxChemRxn(struct reaction *rxn) { + logk[0] = dz[0] = 0.0; for (size_t i = 0; i < MAX_LOG_K_INDICES; i++) { logk[i] = rxn->logk[i]; diff --git a/kinetics.cpp b/kinetics.cpp index 6396a192..384a6b97 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -188,7 +188,11 @@ RESTART: // if limiting rates, jump to here { char * temp_name = string_duplicate(name.c_str()); char * ptr = temp_name; - get_elts_in_species(&ptr, coef * coef1); + if (get_elts_in_species(&ptr, coef * coef1) == ERROR) + { + error_string = sformatf("Error in -formula: %s", temp_name); + error_msg(error_string, CONTINUE); + } free_check_null(temp_name); } } @@ -208,7 +212,11 @@ RESTART: // if limiting rates, jump to here /* found kinetics component */ char * formula = string_duplicate(exchange_ptr->Get_exchange_comps()[j].Get_formula().c_str()); char * ptr = formula; - get_elts_in_species(&ptr, -coef*exchange_ptr->Get_exchange_comps()[j].Get_phase_proportion()); + if (get_elts_in_species(&ptr, -coef*exchange_ptr->Get_exchange_comps()[j].Get_phase_proportion()) == ERROR) + { + error_string = sformatf("Error in -formula: %s", formula); + error_msg(error_string, CONTINUE); + } free_check_null(formula); } } @@ -243,7 +251,11 @@ RESTART: // if limiting rates, jump to here } else { - get_elts_in_species(&ptr, -coef * surface_comp_ptr->Get_phase_proportion()); + if (get_elts_in_species(&ptr, -coef * surface_comp_ptr->Get_phase_proportion()) == ERROR) + { + error_string = sformatf("Error in -formula: %s", temp_formula); + error_msg(error_string, CONTINUE); + } } free_check_null(temp_formula); } diff --git a/model.cpp b/model.cpp index e823bb4a..8faf89a6 100644 --- a/model.cpp +++ b/model.cpp @@ -1207,7 +1207,7 @@ ineq(int in_kode) /* Copy in saturation index equation (has mass or supersaturated) */ memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(my_array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; //if (it->second.Get_add_formula().size() == 0 if (comp_ptr->Get_add_formula().size() == 0 @@ -1241,7 +1241,7 @@ ineq(int in_kode) */ memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(my_array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; l_count_rows++; /* @@ -1252,7 +1252,7 @@ ineq(int in_kode) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(my_array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; res[l_count_rows] = 1.0; @@ -1269,7 +1269,7 @@ ineq(int in_kode) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(my_array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; res[l_count_rows] = 1.0; if (in_kode != 1) @@ -1351,7 +1351,7 @@ ineq(int in_kode) } memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(my_array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; if (mass_water_switch == TRUE && x[i] == mass_hydrogen_unknown) { @@ -1368,7 +1368,7 @@ ineq(int in_kode) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(my_array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; l_count_rows++; } @@ -1412,7 +1412,7 @@ ineq(int in_kode) memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(zero[0]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); ineq_array[l_count_rows * max_column_count + i] = 1.0; ineq_array[l_count_rows * max_column_count + count_unknowns] = x[i]->moles; @@ -1425,7 +1425,7 @@ ineq(int in_kode) memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(zero[0]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); ineq_array[l_count_rows * max_column_count + i] = -1.0; ineq_array[l_count_rows * max_column_count + count_unknowns] = @@ -1447,7 +1447,7 @@ ineq(int in_kode) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(my_array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; for (j = 0; j < count_unknowns; j++) { @@ -1609,7 +1609,7 @@ ineq(int in_kode) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(zero[0]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); ineq_array[l_count_rows * max_column_count + i] = -1.0; ineq_array[l_count_rows * max_column_count + count_unknowns] = x[i]->moles; @@ -1647,7 +1647,7 @@ ineq(int in_kode) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(zero[0]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); ineq_array[l_count_rows * max_column_count + i] = 1.0; ineq_array[l_count_rows * max_column_count + count_unknowns] = 0.99 * x[i]->moles - MIN_TOTAL_SS; @@ -1674,7 +1674,7 @@ ineq(int in_kode) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(my_array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; for (j = 0; j < count_unknowns; j++) { diff --git a/parse.cpp b/parse.cpp index cf149a4d..4bd6a255 100644 --- a/parse.cpp +++ b/parse.cpp @@ -580,7 +580,7 @@ get_elts_in_species(char **t_ptr, LDBLE coef) char c, c1; LDBLE d; char element[MAX_LENGTH]; - + char** t_ptr_save = t_ptr; while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0')) { /* close parenthesis */ @@ -689,7 +689,7 @@ get_elts_in_species(char **t_ptr, LDBLE coef) } if (paren_count != 0) { - error_string = sformatf( "Unbalanced parentheses."); + error_string = sformatf( "Unbalanced parentheses: %s", *t_ptr_save); error_msg(error_string, CONTINUE); input_error++; return (ERROR); @@ -837,7 +837,7 @@ get_secondary_in_species(char **t_ptr, LDBLE coef) char c, c1; LDBLE d; char element[MAX_LENGTH]; - + char** t_ptr_save = t_ptr; while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0')) { /* close parenthesis */ @@ -941,7 +941,7 @@ get_secondary_in_species(char **t_ptr, LDBLE coef) } if (paren_count != 0) { - error_string = sformatf( "Unbalanced parentheses."); + error_string = sformatf("Unbalanced parentheses: %s", *t_ptr_save); error_msg(error_string, CONTINUE); return (ERROR); }