From 03171b2d91a8383671f4c4fa13d15ea44de687cf Mon Sep 17 00:00:00 2001 From: Darth Vader Date: Mon, 29 Nov 2021 15:20:08 +0000 Subject: [PATCH] Squashed 'src/' changes from a826eecc..6beb009a 6beb009a Merge commit '8f2558798f15927fa58343a43c7c14295986ae45' 8f255879 Squashed 'phreeqcpp/' changes from 40f9a93..7cda4a7 git-subtree-dir: src git-subtree-split: 6beb009a167da83c26f4660ac5ade440bc3dd6fa --- phreeqcpp/Phreeqc.h | 2 + phreeqcpp/model.cpp | 1 - phreeqcpp/read.cpp | 100 ++++++++++++++++++++++++++++++++++------ phreeqcpp/sit.cpp | 2 - phreeqcpp/transport.cpp | 2 +- 5 files changed, 88 insertions(+), 19 deletions(-) diff --git a/phreeqcpp/Phreeqc.h b/phreeqcpp/Phreeqc.h index 605f72f7..dd414fb2 100644 --- a/phreeqcpp/Phreeqc.h +++ b/phreeqcpp/Phreeqc.h @@ -646,6 +646,8 @@ public: int read_input(void); int* read_list_ints_range(const char** ptr, int* count_ints, int positive, int* int_list); + int read_list_ints_range(const char** cptr, bool positive, std::vector& int_list); + int read_log_k_only(const char* cptr, LDBLE* log_k); int read_t_c_only(const char* cptr, LDBLE* t_c); int read_p_c_only(const char* cptr, LDBLE* p_c); diff --git a/phreeqcpp/model.cpp b/phreeqcpp/model.cpp index 35a98ff2..9bebfc87 100644 --- a/phreeqcpp/model.cpp +++ b/phreeqcpp/model.cpp @@ -5558,7 +5558,6 @@ numerical_jacobian(void) cxxGasPhase* gas_phase_ptr = use.Get_gas_phase_ptr(); std::vector phase_ptrs; std::vector base_phases; - double base_mass_water_bulk_x = 0, base_moles_h2o = 0; cxxGasPhase base_gas_phase; cxxSurface base_surface; diff --git a/phreeqcpp/read.cpp b/phreeqcpp/read.cpp index 4ade4fe4..ba2a0b1c 100644 --- a/phreeqcpp/read.cpp +++ b/phreeqcpp/read.cpp @@ -2506,6 +2506,86 @@ read_list_ints_range(const char **cptr, int *count_ints, int positive, int *int_ } return (int_list); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_list_ints_range(const char** cptr, bool positive, std::vector &int_list) +/* ---------------------------------------------------------------------- */ +{ + /* + * Reads a list of int numbers until end of line is reached or + * an int cannot be read from a token. + * + * Arguments: + * cptr entry: points to line to read from + * exit: points to next non-int token or end of line + * + * count_ints entry: number of ints already in list + * + * positive entry: if TRUE, expects to read only positive integers + * + * Returns: + * pointer to a list of count_ints ints + */ + char token[MAX_LENGTH]; + int value, value1, value2; + int i, l; + const char* cptr_save; + int count_start = (int)int_list.size(); + + cptr_save = *cptr; + while (copy_token(token, cptr, &l) != EMPTY) + { + if (sscanf(token, "%d", &value) == 1) + { + /* Read an integer */ + int_list.push_back(value); + if (value <= 0 && positive) + { + error_msg("Expected an integer greater than zero.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + /* Read range of integers */ + if (replace("-", " ", token) == TRUE) + { + if (sscanf(token, "%d %d", &value1, &value2) != 2) + { + error_msg("Expected an integer range n-m.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else if (value2 < value1) + { + error_msg("Expected an integer range n-m, with n <= m.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else if (value2 <= 0 && positive == TRUE) + { + error_msg("Expected an integer greater than zero.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else + { + for (i = value1 + 1; i <= value2; i++) + { + int_list.push_back(i); + } + } + } + cptr_save = *cptr; + } + else + { + *cptr = cptr_save; + break; + } + } + return ((int )int_list.size() - count_start); +} /* ---------------------------------------------------------------------- */ bool Phreeqc:: @@ -7131,18 +7211,13 @@ read_advection(void) case 2: /* print */ case 5: /* print_cells */ { - std::istringstream iss(next_char); - int idummy; - while (iss >> idummy) - { - print_temp.push_back(idummy); - } + (void)read_list_ints_range(&next_char, false, print_temp); opt_save = 2; } break; case 3: /* selected_output */ - case 11: /* selected_output_frequency */ - case 12: /* punch_frequency */ + case 11: /* selected_output_frequency */ + case 12: /* punch_frequency */ (void)sscanf(next_char, "%d", &punch_ad_modulus); opt_save = OPTION_DEFAULT; if (punch_ad_modulus <= 0) @@ -7154,15 +7229,10 @@ read_advection(void) } break; case 4: /* punch */ - case 14: /* punch_cells */ + case 14: /* punch_cells */ case 6: /* selected_cells */ { - std::istringstream iss(next_char); - int idummy; - while (iss >> idummy) - { - punch_temp.push_back(idummy); - } + (void) read_list_ints_range(&next_char, false, punch_temp); opt_save = 4; break; } diff --git a/phreeqcpp/sit.cpp b/phreeqcpp/sit.cpp index 8f213e98..8e9c4e8c 100644 --- a/phreeqcpp/sit.cpp +++ b/phreeqcpp/sit.cpp @@ -962,10 +962,8 @@ jacobian_sit(void) std::vector base; LDBLE d, d1, d2; int i, j; - cxxGasPhase* gas_phase_ptr = use.Get_gas_phase_ptr(); std::vector phase_ptrs; std::vector base_phases; - double base_mass_water_bulk_x = 0, base_moles_h2o = 0; cxxGasPhase base_gas_phase; cxxSurface base_surface; Restart: diff --git a/phreeqcpp/transport.cpp b/phreeqcpp/transport.cpp index 88f33a29..19ffe8a5 100644 --- a/phreeqcpp/transport.cpp +++ b/phreeqcpp/transport.cpp @@ -6152,7 +6152,7 @@ flux_mcd(const char* species_name, int option) /* ---------------------------------------------------------------------- */ { class species* s_ptr; - double f = 0.0, dum = 0.0; + double f = 0.0; if (state == TRANSPORT && multi_Dflag) { s_ptr = s_search(species_name);