From a99253764f14b882a3adf7bc5f6fb4e748cd5797 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Fri, 12 Mar 2021 18:11:29 -0700 Subject: [PATCH 01/34] (void)sscanf, removed SKIP, removed PHREEQ98 --- ChartObject.cpp | 12 - ExchComp.cxx | 62 --- Exchange.cxx | 34 -- GasPhase.cxx | 174 ------ ISolution.cxx | 176 ------ ISolutionComp.cxx | 255 +-------- KineticsComp.cxx | 47 +- NameDouble.cxx | 76 --- PBasic.cpp | 65 --- PBasic.h | 3 - PPassemblage.cxx | 23 - Phreeqc.cpp | 271 ---------- Phreeqc.h | 90 ---- Pressure.cxx | 34 -- Reaction.cxx | 35 -- SS.cxx | 29 - SSassemblage.cxx | 31 -- SScomp.cxx | 43 -- Solution.cxx | 63 --- StorageBin.cxx | 287 ---------- Surface.cxx | 68 --- Temperature.cxx | 35 -- basicsubs.cpp | 414 -------------- class_main.cpp | 8 - cxxKinetics.cxx | 35 -- cxxMix.cxx | 35 -- global_structures.h | 46 +- inverse.cpp | 96 +--- isotopes.cpp | 143 +---- kinetics.cpp | 523 +----------------- mainsubs.cpp | 171 ------ model.cpp | 236 +------- prep.cpp | 31 -- read.cpp | 1243 ++----------------------------------------- readtr.cpp | 36 +- sit.cpp | 210 -------- spread.cpp | 28 +- step.cpp | 6 - structures.cpp | 27 +- tally.cpp | 129 ----- tidy.cpp | 485 ----------------- utilities.cpp | 39 -- 42 files changed, 97 insertions(+), 5757 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 510a667d..4932fcdd 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -368,18 +368,6 @@ ChartObject::Read(CParser & parser) this->chart_type = 1; break; case 10: /* grid_offset */ -#ifdef PHREEQ98 - /* - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) - sscanf(token, "%d", &RowOffset); - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) - sscanf(token, "%d", &ColumnOffset); - */ -#endif break; case 11: /* connect_simulations */ this->connect_simulations = parser.get_true_false(next_char, true); diff --git a/ExchComp.cxx b/ExchComp.cxx index 48d89dde..d38bbd3e 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -31,68 +31,6 @@ cxxExchComp::cxxExchComp(PHRQ_io *io) phase_proportion = 0.0; formula_z = 0.0; } -#ifdef SKIP -cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, - std::vector < LDBLE >&f_vector) - // - // constructor for cxxExchComp from mixing - // -{ - if (ec_vector.size() <= 0) - return; - // - // check consistency - // - std::vector < LDBLE >::iterator it_f; - std::vector < cxxExchComp >::iterator it_ec; - // set fixed variables - it_ec = ec_vector.begin(); - this->formula = it_ec->formula; - this->formula_totals = it_ec->formula_totals; - this->formula_z = it_ec->formula_z; - this->phase_name = it_ec->phase_name; - this->rate_name = it_ec->rate_name; - it_ec++; - for (; it_ec != ec_vector.end(); it_ec++) - { - if (it_ec->formula != this->formula || - it_ec->formula_z != this->formula_z || - it_ec->phase_name != this->phase_name || - this->rate_name != this->rate_name) - { - error_msg - ("Mixing exchange components. Formula, z, phase_name, or rate_name did not match", - STOP); - } - } - // calculate sum of extensive factors - LDBLE sum_extensive = 0; - for (it_f = f_vector.begin(); it_f != f_vector.end(); it_f++) - { - sum_extensive += *it_f; - } - this->moles = 0; - this->la = 0; - this->charge_balance = 0; - this->phase_proportion = 0; - this->totals.clear(); - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - it_ec = ec_vector.begin(); - it_f = f_vector.begin(); - for (; it_ec != ec_vector.end();) - { - LDBLE extensive = *it_f; - LDBLE intensive = extensive / sum_extensive; - this->moles += it_ec->moles * extensive; - this->la += it_ec->la * intensive; - this->charge_balance += it_ec->charge_balance * extensive; - this->phase_proportion += it_ec->phase_proportion * intensive; - this->totals.add_extensive(it_ec->totals, extensive); - it_ec++; - it_f++; - } -} -#endif cxxExchComp::~cxxExchComp() { } diff --git a/Exchange.cxx b/Exchange.cxx index c1192df9..2f2dc11f 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -117,40 +117,6 @@ cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const return; } -#ifdef SKIP -void -cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // Exchange element and attributes - s_oss << indent0; - s_oss << " - pitzer_exchange_gammas << "\"" << "\n"; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = exchComps.begin(); - it != exchComps.end(); ++it) - { - (*it).second.dump_xml(s_oss, indent + 2); - } - - return; -} -#endif void cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { diff --git a/GasPhase.cxx b/GasPhase.cxx index 7a538593..61fba4b1 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -36,88 +36,6 @@ cxxGasPhase::cxxGasPhase(PHRQ_io * io) pr_in = false; temperature = 298.15; } -#ifdef SKIP -cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, - cxxMix & mx, int l_n_user, PHRQ_io * io) -: cxxNumKeyword(io) -{ - this->n_user = this->n_user_end = l_n_user; - total_p = 0; - volume = 0; - v_m = 0; - pr_in = false; - bool first = true; -// -// Mix -// - // accumulate in map - std::map comp_map; - std::map::iterator comp_it; - - const std::map < int, LDBLE > & mixcomps = mx.Get_mixComps(); - std::map < int, LDBLE >::const_iterator it; - for (it = mixcomps.begin(); it != mixcomps.end(); it++) - { - const cxxGasPhase *entity_ptr = &(entity_map.find(it->first)->second); - if (first) - { - this->new_def = entity_ptr->new_def; - this->solution_equilibria = entity_ptr->solution_equilibria; - this->n_solution = entity_ptr->n_solution; - this->type = entity_ptr->type; - this->total_p = entity_ptr->total_p * it->second; - this->total_moles = entity_ptr->total_moles * it->second; - this->volume = entity_ptr->volume * it->second; - this->v_m = entity_ptr->v_m * it->second; - this->pr_in = entity_ptr->pr_in; - this->temperature = entity_ptr->temperature; - first = false; - } - else - { - if (this->type != entity_ptr->type) - { - std::ostringstream oss; - oss << "Cannot mix two gas_phases with differing types."; - error_msg(oss.str().c_str(), CONTINUE); - return; - } - - this->total_p += entity_ptr->total_p * it->second; - this->volume += entity_ptr->volume * it->second; - this->v_m += entity_ptr->v_m * it->second; - } - cxxGasPhase *gas_phase_ptr = Utilities::Rxn_find(entity_map, it->first); - if (gas_phase_ptr) - { - std::vector add_comps = gas_phase_ptr->Get_gas_comps(); - for (size_t i = 0; i < add_comps.size(); i++) - { - comp_it = comp_map.find(add_comps[i].Get_phase_name()); - if (comp_it != comp_map.end()) - { - comp_it->second.add(add_comps[i], it->second); - } - else - { - cxxGasComp gc(add_comps[i]); - gc.multiply(it->second); - comp_map[add_comps[i].Get_phase_name()] = gc; - } - } - - } - } - - // put map into vector - this->gas_comps.clear(); - std::vector gc; - for (comp_it = comp_map.begin(); comp_it != comp_map.end(); comp_it++) - { - this->gas_comps.push_back(comp_it->second); - } -} -#endif cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, cxxMix & mx, int l_n_user, PHRQ_io * io) : cxxNumKeyword(io) @@ -219,102 +137,10 @@ cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, this->gas_comps.push_back(comp_it->second); } } -#ifdef SKIP -cxxGasPhase::cxxGasPhase(const std::map < int, cxxGasPhase > &entities, - cxxMix & mix, int l_n_user, PHRQ_io * io): -cxxNumKeyword(io) -{ - this->n_user = this->n_user_end = l_n_user; - gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; - total_p = 0; - volume = 0; - v_m = 0; - pr_in = false; - bool first = true; -// -// Mix -// - //cxxNameDouble gasPhaseComps; - const std::map < int, LDBLE > & mixcomps = mix.Get_mixComps(); - std::map < int, LDBLE >::const_iterator it; - for (it = mixcomps.begin(); it != mixcomps.end(); it++) - { - if (entities.find(it->first) != entities.end()) - { - const cxxGasPhase *entity_ptr = - &(entities.find(it->first)->second); - this->gasPhaseComps.add_extensive(entity_ptr->gasPhaseComps, - it->second); - //GP_TYPE type; - //LDBLE total_p; - //LDBLE volume; - if (first) - { - this->type = entity_ptr->type; - this->total_p = entity_ptr->total_p * it->second; - this->volume = entity_ptr->volume * it->second; - this->v_m = entity_ptr->v_m * it->second; - this->pr_in = entity_ptr->pr_in; - first = false; - } - else - { - if (this->type != entity_ptr->type) - { - std::ostringstream oss; - oss << "Cannot mix two gas_phases with differing types."; - error_msg(oss.str().c_str(), CONTINUE); - //input_error++; - return; - } - - this->total_p += entity_ptr->total_p * it->second; - this->volume += entity_ptr->volume * it->second; - this->v_m += entity_ptr->v_m * it->second; - } - } - } -} -#endif cxxGasPhase::~cxxGasPhase() { } -#ifdef SKIP -void -cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // GasPhase element and attributes - s_oss << indent0; - s_oss << " - pitzer_gas_phase_gammas << "\"" << "\n"; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = - gas_phaseComps.begin(); it != gas_phaseComps.end(); ++it) - { - it->dump_xml(s_oss, indent + 2); - } - - return; -} -#endif - void cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { diff --git a/ISolution.cxx b/ISolution.cxx index 29afa583..6e771005 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -31,179 +31,3 @@ units("mMol/kgw") cxxISolution::~cxxISolution() { } - -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -void -cxxISolution::ConvertUnits(Phreeqc * phreeqc_ptr) - // - // Converts from input units to moles per kilogram water - // -{ - LDBLE sum_solutes = 0; - // foreach conc - std::map < std::string, cxxISolutionComp >::iterator iter = - this->comps.begin(); - for (; iter != this->comps.end(); ++iter) - { - struct master *master_ptr = phreeqc_ptr-> master_bsearch(iter->first.c_str()); - if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) - continue; - //if (iter->second.Get_description() == "H(1)" || iter->second.Get_description() == "E") continue; - if (strcmp(iter->second.Get_description().c_str(), "H(1)") == 0 - || strcmp(iter->second.Get_description().c_str(), "E")) - continue; - if (iter->second.get_input_conc() <= 0.0) - continue; -/* -* Convert liters to kg solution -*/ - LDBLE moles = iter->second.get_input_conc(); - if (this->units.find("/l") != std::string::npos) - { - moles /= this->density; - } -/* -* Convert to moles -*/ - //set gfw for element - iter->second.set_gfw(phreeqc_ptr); - // convert to moles - if (iter->second.get_units().find("g/") != std::string::npos) - { - if (iter->second.get_gfw() != 0) - { - moles /= iter->second.get_gfw(); - } - else - { - std::ostringstream oss; - oss << "Could not find gfw, " << iter->second. - Get_description(); - error_msg(oss.str().c_str(), CONTINUE); - } - } -/* -* Convert milli or micro -*/ - char c = iter->second.get_units().c_str()[0]; - if (c == 'm') - { - moles *= 1e-3; - } - else if (c == 'u') - { - moles *= 1e-6; - } - iter->second.set_moles(moles); -/* -* Sum grams of solute, convert from moles necessary -*/ - sum_solutes += moles * (iter->second.get_gfw()); - } -/* - * Convert /kgs to /kgw - */ - LDBLE l_mass_water; - if ((this->units.find("kgs") != std::string::npos) || - (this->units.find("/l") != std::string::npos)) - { - l_mass_water = 1.0 - 1e-3 * sum_solutes; - for (; iter != this->comps.end(); ++iter) - { - iter->second.set_moles(iter->second.get_moles() / l_mass_water); - } - } -/* - * Scale by mass of water in solution - */ - l_mass_water = this->mass_water; - for (; iter != this->comps.end(); ++iter) - { - iter->second.set_moles(iter->second.get_moles() * l_mass_water); - } -} -#endif - -#ifdef SKIP -void -cxxISolution::dump_xml(std::ostream & os, unsigned int indent) const const -{ - unsigned int i; - - for (i = 0; i < indent; ++i) - os << Utilities::INDENT; - os << "\n"; - - cxxNumKeyword::dump_xml(os, indent); - - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "" << this->get_tc() << "" << "\n"; - - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "" << this->get_ph() << "" << "\n"; - - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "" << this->get_solution_pe() << "" << "\n"; - - assert(this->pe.size() > 0); - assert(this->default_pe >= 0); - assert(this->pe.size() > (unsigned int) this->default_pe); - - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "" << this->get_units() << "" << "\n"; - - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "" << this->get_density() << "" << "\n"; - - // foreach conc - if (!this->totals.empty()) - { - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "\n"; - - std::vector < cxxISolutionComp >::const_iterator iter = - this->totals.begin(); - for (; iter != this->totals.end(); ++iter) - { - (*iter).dump_xml(*this, os, indent + 2); - } - - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "\n"; - } - - // foreach isotope - if (!this->isotopes.empty()) - { - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "\n"; - - std::list < cxxIsotope >::const_iterator iter = - this->isotopes.begin(); - for (; iter != this->isotopes.end(); ++iter) - { - (*iter).dump_xml(os, indent + 2); - } - - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "\n"; - } - - for (i = 0; i < indent + 1; ++i) - os << Utilities::INDENT; - os << "" << this->get_mass_water() << "" << "\n"; - - for (i = 0; i < indent; ++i) - os << Utilities::INDENT; - os << "" << "\n"; -} -#endif diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 7e0ca016..58dfa083 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -21,259 +21,6 @@ cxxISolutionComp::~cxxISolutionComp(void) { } -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -struct conc * -cxxISolutionComp::cxxISolutionComp2conc(Phreeqc * phreeqc_ptr, const std::map < std::string, - cxxISolutionComp > &totals) - // for ISolutions - // takes a std::vector cxxISolutionComp structures - // returns list of conc structures -{ - struct conc *c; - c = (struct conc *) - phreeqc_ptr-> PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); - if (c == NULL) - phreeqc_ptr-> malloc_error(); - int i = 0; - for (std::map < std::string, cxxISolutionComp >::const_iterator it = totals.begin(); - it != totals.end(); ++it) - { - c[i].description = phreeqc_ptr-> string_duplicate(it->second.description.c_str()); - c[i].moles = it->second.moles; - c[i].input_conc = it->second.input_conc; - if (it->second.units.size() == 0) - c[i].units = NULL; - else - c[i].units = phreeqc_ptr-> string_hsave(it->second.units.c_str()); - if (it->second.equation_name.size() == 0) - c[i].equation_name = NULL; - else - c[i].equation_name = phreeqc_ptr-> string_hsave(it->second.equation_name.c_str()); - c[i].phase_si = it->second.phase_si; - c[i].n_pe = it->second.n_pe; - c[i].as = phreeqc_ptr-> string_hsave(it->second.as.c_str()); - c[i].gfw = it->second.gfw; - //c[i].skip = 0; - c[i].phase = NULL; - i++; - } - c[i].description = NULL; - return (c); -} -#endif - -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -void -cxxISolutionComp::set_gfw(Phreeqc * phreeqc_ptr) -{ -// return gfw - if (this->gfw > 0.0) - return; -// calculate gfw from as or from master species gfw - if (this->as.size() != 0) - { - /* use given chemical formula to calculate gfw */ - LDBLE l_gfw; - if (phreeqc_ptr-> compute_gfw(this->as.c_str(), &l_gfw) == ERROR) - { - std::ostringstream oss; - oss << "Could not compute gfw, " << this->as; - error_msg(oss.str().c_str(), CONTINUE); - return; - } - //if (this->description == "Alkalinity" && this->as == "CaCO3") - if (strcmp(this->description.c_str(), "Alkalinity") == 0 - && strcmp(this->as.c_str(), "CaCO3")) - { - l_gfw /= 2.; - } - this->gfw = l_gfw; - return; - } - /* use gfw of master species */ - std::string str(this->description); - struct master *master_ptr = phreeqc_ptr-> master_bsearch(str.c_str()); - if (master_ptr != NULL) - { - /* use gfw for element redox state */ - this->gfw = master_ptr->gfw; - return; - } - std::ostringstream oss; - oss << "Could not find gfw, " << this->description; - error_msg(oss.str().c_str(), CONTINUE); - return; -} -#endif -#ifdef SKIP -cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser, - cxxISolution & solution) -{ - // std::string& str = parser.line(); - std::string str = parser.line(); - - // defaults set in ctor - - // Remove space between "kg" and "solution" or "water" in units - Utilities::replace("Kg", "kg", str); - Utilities::replace("KG", "kg", str); - while (Utilities::replace("kg ", "kg", str)); - - std::istream::pos_type ptr = 0; - - // - // Read master species list for mass balance equation - // - std::string token; - std::string token1; - int - count_redox_states = 0; - CParser::TOKEN_TYPE j; - while (((j = parser.copy_token(token, ptr)) == CParser::TT_UPPER) || - (token[0] == '[') || - (Utilities::strcmp_nocase_arg1(token.c_str(), "ph") == 0) || - (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0)) - { - ++count_redox_states; - Utilities::replace("(+", "(", token); - if (count_redox_states > 1) - token1 += " "; - token1 += token; - } - if (count_redox_states == 0) - { - parser.incr_input_error(); - parser. - error_msg - ("No element or master species given for concentration input.", - PHRQ_io::OT_CONTINUE); - return cxxISolutionComp::ERROR; - } - description = token1; - - // Determine if reading alkalinity, allow equivalents for units - Utilities::str_tolower(token1); - bool - alk = false; - if (token1.find("alk") == 0) - { - alk = true; - } - - // Read concentration - if (!(std::istringstream(token) >> this->input_conc)) - { - std::ostringstream err; - err << "Concentration data error for " << token1 << - " in solution input."; - parser.error_msg(err, PHRQ_io::OT_CONTINUE); - return cxxISolutionComp::ERROR; - } - if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) - return cxxISolutionComp::OK; - - // Read optional data - token1 = token; - - // Check for units info - if (parser.check_units(token1, alk, false, solution.get_units(), false) == - CParser::OK) - { - if (parser. - check_units(token1, alk, false, solution.get_units(), - true) == CParser::OK) - { - this->units = token1; - if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) - return cxxISolutionComp::OK; - } - else - { - return cxxISolutionComp::ERROR; - } - } - - // Check for "as" followed by formula to be used for gfw - token1 = token; - Utilities::str_tolower(token1); - if (token1.compare("as") == 0) - { - parser.copy_token(token, ptr); - this->as = token; - if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) - return cxxISolutionComp::OK; - } - // Check for "gfw" followed by gram formula weight - else if (token1.compare("gfw") == 0) - { - if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) - { - parser.error_msg("Expecting gram formula weight.", - PHRQ_io::OT_CONTINUE); - return cxxISolutionComp::ERROR; - } - else - { - parser.get_iss() >> this->gfw; - if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) - return cxxISolutionComp::OK; - } - } - - // Check for redox couple for pe - if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) - { - this->n_pe = cxxPe_Data::store(solution.pe, token); - if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) - return cxxISolutionComp::OK; - } - else if (token.find("/") != std::string::npos) - { - if (parser.parse_couple(token) == CParser::OK) - { - this->n_pe = cxxPe_Data::store(solution.pe, token); - if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) - return cxxISolutionComp::OK; - } - else - { - return cxxISolutionComp::ERROR; - } - } - - // Must have phase - this->equation_name = token; - if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) - return cxxISolutionComp::OK; - - // Check for saturation index - if (!(std::istringstream(token) >> this->phase_si)) - { - parser.error_msg("Expected saturation index.", PHRQ_io::OT_CONTINUE); - return cxxISolutionComp::ERROR; - } - return cxxISolutionComp::OK; -} -#endif -#ifdef SKIP -void -cxxISolutionComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - std::string indent0(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - - s_oss << indent0; - s_oss << "description << "\""; - - s_oss << " conc_moles=\"" << this->moles << "\""; - - s_oss << "\">" << "\n"; -} -#endif /* ---------------------------------------------------------------------- */ CParser::STATUS_TYPE cxxISolutionComp:: read(const char *line_in, cxxSolution *solution_ptr) @@ -397,7 +144,7 @@ read(const char *line_in, cxxSolution *solution_ptr) } else { - sscanf(token.c_str(), SCANFORMAT, &this->gfw); + (void)sscanf(token.c_str(), SCANFORMAT, &this->gfw); if ((CParser::copy_token(token, b, e)) == CParser::TT_EMPTY) return (CParser::PARSER_OK); } diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 3c9cd177..db21cedc 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -36,51 +36,6 @@ cxxKineticsComp::~cxxKineticsComp() { } -#ifdef SKIP -void -cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // Kinetics_Comp element and attributes - - s_oss << indent0 << "formula=\"" << this->formula << "\"" << "\n"; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; - s_oss << indent0 << "la=\"" << this->la << "\"" << "\n"; - s_oss << indent0 << "charge_balance=\"" << this-> - charge_balance << "\"" << "\n"; - if (this->phase_name != NULL) - { - s_oss << indent0 << "phase_name=\"" << this-> - phase_name << "\"" << "\n"; - } - if (this->rate_name != NULL) - { - s_oss << indent0 << "rate_name=\"" << this-> - rate_name << "\"" << "\n"; - } - s_oss << indent0 << "phase_proportion=\"" << this-> - phase_proportion << "\"" << "\n"; - - // totals - s_oss << indent0; - s_oss << "totals.dump_xml(s_oss, indent + 1); - - // formula_totals - s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); -} -#endif void cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { @@ -233,7 +188,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { double dd; - sscanf(token.c_str(), "%lf", &dd); + (void)sscanf(token.c_str(), "%lf", &dd); temp_d_params.push_back((LDBLE) dd); d_params_defined = true; } diff --git a/NameDouble.cxx b/NameDouble.cxx index 5780cfc8..e8b64ef4 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -96,23 +96,6 @@ cxxNameDouble::cxxNameDouble(std::map < std::string, cxxISolutionComp > &comps) } this->type = ND_ELT_MOLES; } -#ifdef SKIP -cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, - cxxNameDouble::ND_TYPE l_type) - // - // constructor for cxxNameDouble from list of elt_list - // -{ - int i; - for (i = 0; i < count; i++) - { - if (ma[i].description == NULL) - continue; - (*this)[ma[i].description] = ma[i].la; - } - this->type = l_type; -} -#endif cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) // // constructor for cxxNameDouble from list of elt_list @@ -379,38 +362,7 @@ cxxNameDouble::Simplify_redox(void) const } return new_totals; } -#ifdef SKIP -cxxNameDouble -cxxNameDouble::Simplify_redox(void) -{ - // remove individual redox states from totals - cxxNameDouble &nd = *this; - std::set list_of_elements; - cxxNameDouble::const_iterator it; - for (it = nd.begin(); it != nd.end(); ++it) - { - std::string current_ename(it->first); - std::basic_string < char >::size_type indexCh; - indexCh = current_ename.find("("); - if (indexCh != std::string::npos) - { - current_ename = current_ename.substr(0, indexCh); - } - if (current_ename == "H" || current_ename == "O" || current_ename == "Charge") - continue; - list_of_elements.insert(current_ename); - } - cxxNameDouble new_totals; - new_totals.type = cxxNameDouble::ND_ELT_MOLES; - std::set::iterator nt_it = list_of_elements.begin(); - for( ; nt_it != list_of_elements.end(); nt_it++) - { - new_totals[(*nt_it).c_str()] = nd.Get_total_element((*nt_it).c_str()); - } - return new_totals; -} -#endif void cxxNameDouble::Multiply_activities_redox(std::string str, LDBLE f) { @@ -439,34 +391,6 @@ cxxNameDouble::Multiply_activities_redox(std::string str, LDBLE f) if (str[0] < it->first[0]) break; } } -#ifdef SKIP -void -cxxNameDouble::Multiply_activities_redox(std::string str, LDBLE f) -{ - // update original master_activities using just computed factors - cxxNameDouble::iterator it; - LDBLE lg_f = log10(f); - std::string redox_name = str; - redox_name.append("("); - - for (it = this->begin(); it != this->end(); it++) - { - if (it->first == str) - { - // Found exact match - it->second += lg_f; - } - else - { - // no exact match, current is element name, need to find all valences - if (strstr(it->first.c_str(), redox_name.c_str()) == it->first.c_str()) - { - it->second += lg_f; - } - } - } -} -#endif LDBLE cxxNameDouble::Get_total_element(const char *string) const { diff --git a/PBasic.cpp b/PBasic.cpp index 73e3e281..3d5a6be1 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3482,35 +3482,6 @@ factor(struct LOC_exec * LINK) break; } n.UU.val = PhreeqcPtr->solution_number(); -#ifdef SKIP - if (PhreeqcPtr->state == TRANSPORT) - { - n.UU.val = PhreeqcPtr->cell_no; - } - else if (PhreeqcPtr->state == PHAST) - { - n.UU.val = PhreeqcPtr->cell_no; - } - else if (PhreeqcPtr->state == ADVECTION) - { - n.UU.val = PhreeqcPtr->cell_no; - } - else if (PhreeqcPtr->state < REACTION) - { - n.UU.val = PhreeqcPtr->use.Get_solution_ptr()->Get_n_user(); - } - else - { - if (PhreeqcPtr->use.Get_mix_in()) - { - n.UU.val = PhreeqcPtr->use.Get_n_mix_user(); - } - else - { - n.UU.val = PhreeqcPtr->use.Get_n_solution_user(); - } - } -#endif break; case toksim_no: @@ -4560,21 +4531,6 @@ findline(long n) l = l->next; return l; } -#ifdef SKIP -linerec * PBasic:: -mustfindline(long n) -{ - linerec *l; - - l = findline(n); - if (l == NULL) - { - char * error_string = PhreeqcPtr->sformatf( "Undefined line %ld", n); - errormsg(error_string); - } - return l; -} -#endif linerec * PBasic:: mustfindline(long n) { @@ -7316,27 +7272,6 @@ _Escape(int code) throw PBasicStop(); // following not used -#ifdef SKIP - char l_buf[100]; - char token[200], empty[2] = { "\0" }; - if (code == 0) - /* exit(EXIT_SUCCESS); */ - error_msg("Exit success in Basic", STOP); - if (code == -1) - { - error_msg("Fatal error in Basic interpreter.", CONTINUE); - sprintf(token, "%s", - _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); - error_msg(token, STOP); - exit(EXIT_FAILURE); - } - /* fprintf(stderr, "%s\n", _ShowEscape(l_buf, P_escapecode, P_ioresult, "")); */ - /* exit(EXIT_FAILURE); */ - error_msg("Fatal error in Basic interpreter.", CONTINUE); - sprintf(token, "%s", _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); - error_msg(token, STOP); - return (1); -#endif } int PBasic:: diff --git a/PBasic.h b/PBasic.h index 6ab2b489..7318bdf3 100644 --- a/PBasic.h +++ b/PBasic.h @@ -479,9 +479,6 @@ public: int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); int basic_init(void); -#ifdef PHREEQ98 - void GridChar(char *s, char *a); -#endif int sget_logical_line(char **ptr, int *l, char *return_line); long my_labs(long x); void * my_memmove(void * d, Const void * s, size_t n); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 3536dc51..8da71945 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -299,29 +299,6 @@ cxxPPassemblage::add(const cxxPPassemblage & addee, LDBLE extensive) //cxxNameDouble eltList; this->eltList.add_extensive(addee.eltList, extensive); } -#ifdef SKIP -cxxPPassemblageComp * cxxPPassemblage:: -Find(const std::string name_in) -{ - std::string name(name_in); - Utilities::str_tolower(name); - - cxxPPassemblageComp * comp = NULL; - std::map::iterator it; - it = this->pp_assemblage_comps.begin(); - for ( ; it != this->pp_assemblage_comps.end(); it++) - { - std::string pname(it->first); - Utilities::str_tolower(pname); - if (name == pname) - { - comp = &it->second; - break; - } - } - return comp; -} -#endif cxxPPassemblageComp * cxxPPassemblage:: Find(const std::string name_in) { diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 77a16e0b..a4c19186 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -473,52 +473,6 @@ void Phreeqc::init(void) current_selected_output = NULL; current_user_punch = NULL; high_precision = false; -#ifdef SKIP - //struct punch punch; -/* - * Initialize punch - */ - punch.in = FALSE; - punch.count_totals = 0; - punch.totals = 0; - punch.count_molalities = 0; - punch.molalities = 0; - punch.count_activities = 0; - punch.activities = 0; - punch.count_pure_phases = 0; - punch.pure_phases = 0; - punch.count_si = 0; - punch.si = 0; - punch.count_gases = 0; - punch.gases = 0; - punch.count_s_s = 0; - punch.s_s = 0; - punch.count_kinetics = 0; - punch.kinetics = 0; - punch.count_isotopes = 0; - punch.isotopes = 0; - punch.count_calculate_values = 0; - punch.calculate_values = 0; - punch.inverse = TRUE; - punch.sim = TRUE; - punch.state = TRUE; - punch.soln = TRUE; - punch.dist = TRUE; - punch.time = TRUE; - punch.step = TRUE; - punch.rxn = FALSE; - punch.temp = FALSE; - punch.ph = TRUE; - punch.pe = TRUE; - punch.alk = FALSE; - punch.mu = FALSE; - punch.water = FALSE; - punch.high_precision = FALSE; - punch.user_punch = TRUE; - punch.charge_balance = FALSE; - punch.percent_error = FALSE; -#endif - MIN_LM = -30.0; /* minimum log molality allowed before molality set to zero */ LOG_ZERO_MOLALITY = -30; /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ MIN_RELATED_LOG_ACTIVITY = -30; @@ -908,11 +862,6 @@ void Phreeqc::init(void) * USER PRINT COMMANDS * ---------------------------------------------------------------------- */ user_print = NULL; -#ifdef SKIP - user_punch = NULL; - user_punch_headings = NULL; - user_punch_count_headings = 0; -#endif n_user_punch_index = 0; fpunchf_user_s_warning = 0; fpunchf_user_buffer[0] = 0; @@ -1254,11 +1203,6 @@ void Phreeqc::init(void) default_data_base = string_duplicate("c:\\phreeqc\\database\\phreeqc.dat"); #else default_data_base = string_duplicate("phreeqc.dat"); -#endif -#ifdef PHREEQ98 - int outputlinenr; - char *LogFileNameC; - char progress_str[512]; #endif /* Pitzer */ pitzer_model = FALSE; @@ -1305,28 +1249,12 @@ void Phreeqc::init(void) BK[i] = 0.0; DK[i] = 0.0; } -#ifdef PHREEQ98 - int connect_simulations, graph_initial_solutions; - int shifts_as_points; - int chart_type; - int ShowChart; - int RowOffset, ColumnOffset; -#endif dummy = 0; /* print.cpp ------------------------------- */ sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char)); if (sformatf_buffer == NULL) malloc_error(); sformatf_buffer_size = 256; -#ifdef PHREEQ98 - int colnr, rownr; - int graph_initial_solutions; - int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ - /* int shifts_as_points; */ - int chart_type; - int AddSeries; - int FirstCallToUSER_GRAPH; -#endif /* read.cpp */ prev_next_char = NULL; #if defined PHREEQ98 @@ -1390,13 +1318,6 @@ void Phreeqc::init(void) heat_mix_f_m = 0; warn_MCD_X = 0; warn_fixed_Surf = 0; -#ifdef PHREEQ98 - int AutoLoadOutputFile, CreateToC; - int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; - int outputlinenr; - int stop_calculations; - char err_str98[80]; -#endif /* utilities.cpp ------------------------------- */ spinner = 0; // keycount; @@ -2192,38 +2113,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } // For now, User Punch is not copied -#ifdef SKIP - /* - user_punch = NULL; - */ - { - user_punch->name = NULL; - user_punch->commands = NULL; - if (pSrc->user_punch->commands != NULL) - { - user_punch->commands = string_duplicate(pSrc->user_punch->commands); - } - user_punch->new_def = TRUE; - user_punch->linebase = NULL; - user_punch->varbase = NULL; - user_punch->loopbase = NULL; - } - /* - user_punch_headings = NULL; - user_punch_count_headings = 0; - */ - user_punch_count_headings = pSrc->user_punch_count_headings; - if (user_punch_count_headings > 0) - { - user_punch_headings = (const char **) free_check_null(user_punch_headings); - user_punch_headings = (const char **) PHRQ_malloc((size_t) user_punch_count_headings * sizeof(char *)); - if (user_punch_headings == NULL) malloc_error(); - for (int i = 0; i < user_punch_count_headings; i++) - { - user_punch_headings[i] = string_hsave(pSrc->user_punch_headings[i]); - } - } -#endif n_user_punch_index = pSrc->n_user_punch_index; fpunchf_user_s_warning = pSrc->fpunchf_user_s_warning; //fpunchf_user_buffer[0] = 0; @@ -2498,145 +2387,9 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) //have_punch_name = pSrc->have_punch_name; print_density = pSrc->print_density; print_viscosity = pSrc->print_viscosity; -#ifdef SKIP - LDBLE *zeros; - int zeros_max; -#endif viscos = pSrc->viscos; viscos_0 = pSrc->viscos_0; viscos_0_25 = pSrc->viscos_0_25; // viscosity of the solution, of pure water, of pure water at 25 C -#ifdef SKIP - LDBLE cell_pore_volume; - LDBLE cell_porosity; - LDBLE cell_volume; - LDBLE cell_saturation; - struct system_species *sys; - int count_sys, max_sys; - LDBLE sys_tot; - - LDBLE V_solutes, rho_0, rho_0_sat, kappa_0, p_sat/*, ah2o_x0*/; - LDBLE SC; // specific conductance mS/cm - LDBLE eps_r; // relative dielectric permittivity - LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av - LDBLE QBrn; // Born function d(ln(eps_r))/dP / eps_r * 41.84004, for supcrt calc'n of molal volume - LDBLE ZBrn; // Born function (-1/eps_r + 1) * 41.84004, for supcrt calc'n of molal volume - LDBLE dgdP; // dg / dP, pressure derivative of g-function, for supcrt calc'n of molal volume - - int need_temp_msg; - LDBLE solution_mass, solution_volume; - - /* phqalloc.cpp ------------------------------- */ - PHRQMemHeader *s_pTail; - - /* Basic */ - PBasic * basic_interpreter; - double(*basic_callback_ptr) (double x1, double x2, const char *str, void *cookie); - void *basic_callback_cookie; -#ifdef IPHREEQC_NO_FORTRAN_MODULE - double(*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, size_t l); -#else - double(*basic_fortran_callback_ptr) (double *x1, double *x2, const char *str, int l); -#endif -#if defined(SWIG) || defined(SWIG_IPHREEQC) - class BasicCallback *basicCallback; - void SetCallback(BasicCallback *cb) { basicCallback = cb; } -#endif - - /* cl1.cpp ------------------------------- */ - LDBLE *x_arg, *res_arg, *scratch; - int x_arg_max, res_arg_max, scratch_max; -#ifdef SKIP - /* dw.cpp ------------------------------- */ - /* COMMON /QQQQ/ */ - LDBLE Q0, Q5; - LDBLE GASCON, TZ, AA; - LDBLE Z, DZ, Y; - LDBLE G1, G2, GF; - LDBLE B1, B2, B1T, B2T, B1TT, B2TT; -#endif - /* gases.cpp ------------------------------- */ - LDBLE a_aa_sum, b2, b_sum, R_TK; - - /* input.cpp ------------------------------- */ - int check_line_return; - int reading_db; - - /* integrate.cpp ------------------------------- */ - LDBLE midpoint_sv; - LDBLE z_global, xd_global, alpha_global; - - /* inverse.cpp ------------------------------- */ - int max_row_count, max_column_count; - int carbon; - const char **col_name, **row_name; - int count_rows, count_optimize; - int col_phases, col_redox, col_epsilon, col_ph, col_water, - col_isotopes, col_phase_isotopes; - int row_mb, row_fract, row_charge, row_carbon, row_isotopes, - row_epsilon, row_isotope_epsilon, row_water; - LDBLE *inv_zero, *array1, *inv_res, *inv_delta1, *delta2, *delta3, *inv_cu, - *delta_save; - LDBLE *min_delta, *max_delta; - int *inv_iu, *inv_is; - int klmd, nklmd, n2d, kode, iter; - LDBLE toler, error, max_pct, scaled_error; - struct master *master_alk; - int *row_back, *col_back; - unsigned long *good, *bad, *minimal; - int max_good, max_bad, max_minimal; - int count_good, count_bad, count_minimal, count_calls; - unsigned long soln_bits, phase_bits, current_bits, temp_bits; - FILE *netpath_file; - int count_inverse_models, count_pat_solutions; - int min_position[32], max_position[32], now[32]; - std::vector inverse_heading_names; - - /* kinetics.cpp ------------------------------- */ -public: - int count_pp, count_pg, count_ss; - void *cvode_kinetics_ptr; - int cvode_test; - int cvode_error; - int cvode_n_user; - int cvode_n_reactions; - realtype cvode_step_fraction; - realtype cvode_rate_sim_time; - realtype cvode_rate_sim_time_start; - realtype cvode_last_good_time; - realtype cvode_prev_good_time; - N_Vector cvode_last_good_y; - N_Vector cvode_prev_good_y; - M_Env kinetics_machEnv; - N_Vector kinetics_y, kinetics_abstol; - void *kinetics_cvode_mem; - cxxSSassemblage *cvode_ss_assemblage_save; - cxxPPassemblage *cvode_pp_assemblage_save; -protected: - LDBLE *m_original; - LDBLE *m_temp; - LDBLE *rk_moles; - int set_and_run_attempt; - LDBLE *x0_moles; - - /* model.cpp ------------------------------- */ - int gas_in; - LDBLE min_value; - LDBLE *normal, *ineq_array, *res, *cu, *zero, *delta1; - int *iu, *is, *back_eq; - int normal_max, ineq_array_max, res_max, cu_max, zero_max, - delta1_max, iu_max, is_max, back_eq_max; - - /* phrq_io_output.cpp ------------------------------- */ - int forward_output_to_log; - - /* phreeqc_files.cpp ------------------------------- */ - char *default_data_base; -#ifdef PHREEQ98 - int outputlinenr; - char *LogFileNameC; - char progress_str[512]; -#endif -#endif /* Pitzer */ pitzer_model = pSrc->pitzer_model; sit_model = pSrc->sit_model; @@ -2720,14 +2473,6 @@ protected: DK[i] = 0.0; } */ - -#ifdef PHREEQ98 - int connect_simulations, graph_initial_solutions; - int shifts_as_points; - int chart_type; - int ShowChart; - int RowOffset, ColumnOffset; -#endif dummy = 0; /* print.cpp ------------------------------- */ /* @@ -2736,15 +2481,6 @@ protected: malloc_error(); sformatf_buffer_size = 256; */ -#ifdef PHREEQ98 - int colnr, rownr; - int graph_initial_solutions; - int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ - /* int shifts_as_points; */ - int chart_type; - int AddSeries; - int FirstCallToUSER_GRAPH; -#endif /* read.cpp */ prev_next_char = NULL; #if defined PHREEQ98 @@ -2825,13 +2561,6 @@ protected: current_A = pSrc->current_A; fix_current = pSrc->fix_current; -#ifdef PHREEQ98 - int AutoLoadOutputFile, CreateToC; - int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; - int outputlinenr; - int stop_calculations; - char err_str98[80]; -#endif /* utilities.cpp ------------------------------- */ //spinner = 0; //// keycount; diff --git a/Phreeqc.h b/Phreeqc.h index cb14bb2d..d4b9755b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -275,15 +275,6 @@ public: void fpunchf_user(int user_index, const char *format, double d); void fpunchf_user(int user_index, const char *format, char * d); int fpunchf_end_row(const char *format); -#ifdef SKIP - // dw.cpp ------------------------------- - int BB(LDBLE T); - LDBLE PS(LDBLE T); - LDBLE VLEST(LDBLE T); - int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); - int QQ(LDBLE T, LDBLE D); - LDBLE BASE(LDBLE D); -#endif // input.cpp ------------------------------- int reading_database(void); void set_reading_database(int reading_database); @@ -552,10 +543,6 @@ public: int set_pz(int initial); int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); int check_gammas_pz(void); -#ifdef SKIP - LDBLE DC(LDBLE T); - int DW(LDBLE T); -#endif int ISPEC(const char *name); LDBLE G(LDBLE Y); LDBLE GP(LDBLE Y); @@ -1159,12 +1146,6 @@ protected: static LDBLE under(LDBLE xval); void zero_double(LDBLE * target, int n); int get_input_errors(void); -#ifdef PHREEQ98 - void AddToCEntry(char *a, int l, int i); - void ApplicationProcessMessages(void); - int copy_title(char *token_ptr, char **ptr, int *length); - extern int clean_up_null(void); -#endif int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, const char *Key); void ExpandTable_multi(HashTable * Table); @@ -1816,15 +1797,6 @@ protected: /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; int x_arg_max, res_arg_max, scratch_max; -#ifdef SKIP - /* dw.cpp ------------------------------- */ - /* COMMON /QQQQ/ */ - LDBLE Q0, Q5; - LDBLE GASCON, TZ, AA; - LDBLE Z, DZ, Y; - LDBLE G1, G2, GF; - LDBLE B1, B2, B1T, B2T, B1TT, B2TT; -#endif /* gases.cpp ------------------------------- */ LDBLE a_aa_sum, b2, b_sum, R_TK; @@ -1902,12 +1874,6 @@ protected: /* phreeqc_files.cpp ------------------------------- */ char *default_data_base; -#ifdef PHREEQ98 - int outputlinenr; - char *LogFileNameC; - char progress_str[512]; -#endif - /* Pitzer */ int pitzer_model, sit_model, pitzer_pe; int full_pitzer, always_full_pitzer, ICON, IC; @@ -1931,25 +1897,9 @@ protected: LDBLE *M, *LGAMMA; LDBLE BK[23], DK[23]; -#ifdef PHREEQ98 - int connect_simulations, graph_initial_solutions; - int shifts_as_points; - int chart_type; - int ShowChart; - int RowOffset, ColumnOffset; -#endif LDBLE dummy; /* print.cpp ------------------------------- */ -#ifdef PHREEQ98 - int colnr, rownr; - int graph_initial_solutions; - int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ - /* int shifts_as_points; */ - int chart_type; - int AddSeries; - int FirstCallToUSER_GRAPH; -#endif /* read.cpp */ char *prev_next_char; @@ -2006,13 +1956,6 @@ protected: int warn_MCD_X, warn_fixed_Surf; LDBLE current_x, current_A, fix_current; // current: coulomb / s, Ampere, fixed current (Ampere) -#ifdef PHREEQ98 - int AutoLoadOutputFile, CreateToC; - int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; - int outputlinenr; - int stop_calculations; - char err_str98[80]; -#endif /* utilities.cpp ------------------------------- */ int spinner; std::map gfw_map; @@ -2194,39 +2137,6 @@ namespace Utilities return phreeqc_cookie->cleanup_after_parser(parser); } -#ifdef SKIP - template < typename T > - int Rxn_read_modify(std::map < int, T > &m, std::set < int > &s, Phreeqc * phreeqc_cookie) - { - typename std::map < int, T >::iterator it; - - CParser parser(phreeqc_cookie->Get_phrq_io()); - - std::string key_name; - std::string::iterator b = parser.line().begin(); - std::string::iterator e = parser.line().end(); - CParser::copy_token(key_name, b, e); - - cxxNumKeyword nk; - nk.read_number_description(parser); - T * entity_ptr = Utilities::Rxn_find(m, nk.Get_n_user()); - if (!entity_ptr) - { - std::ostringstream errstr; - errstr << "Could not find " << key_name << " " << nk.Get_n_user() << " to modify.\n"; - phreeqc_cookie->error_msg(errstr.str().c_str(), PHRQ_io::OT_STOP); - } - - entity_ptr->read_raw(parser, false); - entity_ptr->Set_n_user(nk.Get_n_user()); - entity_ptr->Set_n_user_end(nk.Get_n_user_end()); - entity_ptr->Set_description(nk.Get_description()); - s.insert(entity_ptr->Get_n_user()); - - return phreeqc_cookie->cleanup_after_parser(parser); - } -#endif - template < typename T > int Rxn_read_modify(std::map < int, T > &m, std::set < int > &s, Phreeqc * phreeqc_cookie) { diff --git a/Pressure.cxx b/Pressure.cxx index 03bd30ca..cb21173c 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -310,40 +310,6 @@ cxxPressure::read_raw(CParser & parser, bool check) } } } -#ifdef SKIP -void -cxxPressure::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // Temperature element and attributes - s_oss << indent0; - s_oss << " - pitzer_temperature_gammas << "\"" << "\n"; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = - temperatureComps.begin(); it != temperatureComps.end(); ++it) - { - it->dump_xml(s_oss, indent + 2); - } - - return; -} -#endif /* ---------------------------------------------------------------------- */ LDBLE cxxPressure:: Pressure_for_step(int step_number) diff --git a/Reaction.cxx b/Reaction.cxx index 44252814..4eb19741 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -33,41 +33,6 @@ cxxReaction::~cxxReaction() { } -#ifdef SKIP -void -cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // Reaction element and attributes - s_oss << indent0; - s_oss << " - pitzer_irrev_gammas << "\"" << "\n"; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = - irrevComps.begin(); it != irrevComps.end(); ++it) - { - it->dump_xml(s_oss, indent + 2); - } - - return; -} -#endif - void cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { diff --git a/SS.cxx b/SS.cxx index a40e577f..6274f2e2 100644 --- a/SS.cxx +++ b/SS.cxx @@ -49,35 +49,6 @@ cxxSS::~cxxSS() { } -#ifdef SKIP -void -cxxSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // S_S element and attributes - - s_oss << indent0 << "name=\"" << this->name << "\"" << "\n"; - s_oss << indent0 << "add_formula=\"" << this-> - add_formula << "\"" << "\n"; - s_oss << indent0 << "si=\"" << this->si << "\"" << "\n"; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; - s_oss << indent0 << "delta=\"" << this->delta << "\"" << "\n"; - s_oss << indent0 << "initial_moles=\"" << this-> - initial_moles << "\"" << "\n"; - s_oss << indent0 << "dissolve_only=\"" << this-> - dissolve_only << "\"" << "\n"; - -} -#endif void cxxSS::dump_raw(std::ostream & s_oss, unsigned int indent) const { diff --git a/SSassemblage.cxx b/SSassemblage.cxx index ef945efa..8868f71d 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -57,37 +57,6 @@ cxxSSassemblage::~cxxSSassemblage() { } -#ifdef SKIP -void -cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // SSassemblage element and attributes - s_oss << indent0; - s_oss << "eltList.dump_xml(s_oss, indent + 1); - - // SSs - s_oss << indent1; - s_oss << "::const_iterator it = - SSs.begin(); it != SSs.end(); ++it) - { - it->dump_xml(s_oss, indent + 2); - } -} -#endif void cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { diff --git a/SScomp.cxx b/SScomp.cxx index a750a627..fbc52914 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -36,26 +36,6 @@ PHRQ_base(io) dnc = 0; dnb = 0; } -#ifdef SKIP -cxxSScomp::cxxSScomp(struct pure_phase * pure_phase_ptr, PHRQ_io *io) -: -PHRQ_base(io) - // - // constructor for cxxSScomp from struct pure_phase - // -{ - this->Set_name(pure_phase_ptr->name); - this->Set_add_formula(pure_phase_ptr->add_formula); - si = pure_phase_ptr->si; - si_org = pure_phase_ptr->si_org; - moles = pure_phase_ptr->moles; - delta = pure_phase_ptr->delta; - initial_moles = pure_phase_ptr->initial_moles; - force_equality = (pure_phase_ptr->force_equality == TRUE); - dissolve_only = (pure_phase_ptr->dissolve_only == TRUE); - precipitate_only = (pure_phase_ptr->precipitate_only == TRUE); -} -#endif cxxSScomp::~cxxSScomp() { } @@ -248,29 +228,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) } } -#ifdef SKIP -void -cxxSScomp::totalize(Phreeqc * phreeqc_ptr) -{ - this->totals.clear(); - // component structures - if (this->add_formula.size() != 0) - return; - struct phase *phase_ptr; - int l; - phase_ptr = phreeqc_ptr-> phase_bsearch(this->name.c_str(), &l, FALSE); - if (phase_ptr != NULL) - { - cxxNameDouble phase_formula(phase_ptr->next_elt); - this->totals.add_extensive(phase_formula, this->moles); - } - else - { - assert(false); - } - return; -} -#endif void cxxSScomp::multiply(LDBLE extensive) { diff --git a/Solution.cxx b/Solution.cxx index 28e11fdf..fe41e230 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1297,44 +1297,6 @@ cxxSolution::Update(const cxxNameDouble &const_nd) // update totals this->totals = simple_new; } -#ifdef SKIP -void -cxxSolution::Update(const cxxNameDouble &const_nd) -{ - // const_nd is updated totals - cxxNameDouble simple_original_totals = this->totals.Simplify_redox(); - cxxNameDouble original_activities(this->master_activity); - - this->master_activity.clear(); - - // Update activities - if (original_activities.size() > 0) - { - cxxNameDouble nd = const_nd; - cxxNameDouble simple_this_totals = nd.Simplify_redox(); - cxxNameDouble::iterator it = simple_original_totals.begin(); - for ( ; it != simple_original_totals.end(); it++) - { - cxxNameDouble::iterator jit = simple_this_totals.find(it->first); - if (jit != simple_this_totals.end()) - { - if (it->second != 0) - { - LDBLE f = jit->second / it->second; - if (f != 1) - { - original_activities.Multiply_activities_redox(it->first, f); - } - } - } - } - original_activities.merge_redox(this->master_activity); - this->master_activity = original_activities; - } - - return; -} -#endif void cxxSolution::zero() { @@ -1449,31 +1411,6 @@ cxxSolution::Get_total(const char *string) const return (it->second); } } -#ifdef SKIP -LDBLE -cxxSolution::Get_total_element(const char *string) const -{ - cxxNameDouble::const_iterator it; - LDBLE d = 0.0; - for (it = this->totals.begin(); it != this->totals.end(); ++it) - { - // C++ way to do it - std::string ename(string); - std::string current_ename(it->first); - std::basic_string < char >::size_type indexCh; - indexCh = current_ename.find("("); - if (indexCh != std::string::npos) - { - current_ename = current_ename.substr(0, indexCh); - } - if (current_ename == ename) - { - d += it->second; - } - } - return (d); -} -#endif void cxxSolution::Set_total(char *string, LDBLE d) diff --git a/StorageBin.cxx b/StorageBin.cxx index cf4d5c56..b533c599 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -802,41 +802,6 @@ cxxStorageBin::Get_Pressures() { return this->Pressures; } -#ifdef SKIP -void -cxxStorageBin::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // StorageBin element and attributes - s_oss << indent0; - s_oss << " - pitzer_mix_gammas << "\"" << "\n"; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = - mixComps.begin(); it != mixComps.end(); ++it) - { - it->dump_xml(s_oss, indent + 2); - } - - return; -} -#endif - void cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const { @@ -1318,258 +1283,6 @@ cxxStorageBin::Clear(void) // Pressure this->Pressures.clear(); } -#ifdef SKIP -cxxSolution * -cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) -{ -/* - * mixes solutions based on cxxMix structure, returns new solution - * return solution must be freed by calling method - */ - LDBLE intensive, extensive; - cxxSolution *cxxsoln_ptr, *cxxsoln_ptr1; -/* - * Zero out global solution data - */ - cxxsoln_ptr = new cxxSolution(0.0); -/* - * Determine sum of mixing fractions - */ - extensive = 0.0; - - std::map < int, LDBLE >*mixcomps = mixmap.comps(); - - std::map < int, LDBLE >::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - extensive += it->second; - } -/* - * Add solutions - */ - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - cxxsoln_ptr1 = &((this->Solutions.find(it->first))->second); - if (cxxsoln_ptr1 == NULL) - { - error_string = sformatf( - "Solution %d not found in mix_cxxSolutions.", it->first); - error_msg(error_string, CONTINUE); - phreeqc_ptr-> input_error++; - return (NULL); - } - intensive = it->second / extensive; - cxxsoln_ptr->add(*cxxsoln_ptr1, intensive, it->second); - } - return (cxxsoln_ptr); -} -#endif - -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -struct system * -cxxStorageBin::cxxStorageBin2system(Phreeqc * phreeqc_ptr, int n) - // - // make a system from storagebin - // -{ - struct system *system_ptr = - (struct system *) phreeqc_ptr-> PHRQ_malloc(sizeof(struct system)); - if (system_ptr == NULL) - phreeqc_ptr-> malloc_error(); - - // Solutions - - if (this->getSolution(n) != NULL) - { - //system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(phreeqc_ptr); - system_ptr->solution = phreeqc_ptr-> cxxSolution2solution(this->getSolution(n)); - } - else - { - system_ptr->solution = NULL; - } - - // Exchangers - if (this->getExchange(n) != NULL) - { - //system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(phreeqc_ptr); - system_ptr->exchange = phreeqc_ptr-> cxxExchange2exchange(this->getExchange(n)); - } - else - { - system_ptr->exchange = NULL; - } - - // GasPhases - if (this->getGasPhase(n) != NULL) - { - //system_ptr->gas_phase = (this->getGasPhase(n))->cxxGasPhase2gas_phase(phreeqc_ptr); - system_ptr->gas_phase = phreeqc_ptr-> cxxGasPhase2gas_phase(this->getGasPhase(n)); - } - else - { - system_ptr->gas_phase = NULL; - } - - // Kinetics - if (this->getKinetics(n) != NULL) - { - //system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(phreeqc_ptr); - system_ptr->kinetics = phreeqc_ptr-> cxxKinetics2kinetics(this->getKinetics(n)); - - } - else - { - system_ptr->kinetics = NULL; - } - - // PPassemblages - if (this->getPPassemblage(n) != NULL) - { - //system_ptr->pp_assemblage = - // (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(phreeqc_ptr); - system_ptr->pp_assemblage = - phreeqc_ptr-> cxxPPassemblage2pp_assemblage(this->getPPassemblage(n)); - } - else - { - system_ptr->pp_assemblage = NULL; - } - - // SSassemblages - if (this->getSSassemblage(n) != NULL) - { - //system_ptr->ss_assemblage = - // (this->getSSassemblage(n))->cxxSSassemblage2ss_assemblage(phreeqc_ptr); - system_ptr->ss_assemblage = - phreeqc_ptr-> cxxSSassemblage2ss_assemblage((this->getSSassemblage(n))); - } - else - { - system_ptr->ss_assemblage = NULL; - } - - // Surfaces - if (this->getSurface(n) != NULL) - { - //system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(phreeqc_ptr); - system_ptr->surface = phreeqc_ptr-> cxxSurface2surface((this->getSurface(n))); - } - else - { - system_ptr->surface = NULL; - } - return system_ptr; -} -#endif - -#ifdef SKIP -cxxExchange * -cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) -{ -/* - * mixes exchangers based on cxxMix structure, returns new exchanger - * return exchanger must be freed by calling method - */ - cxxExchange *new_exch_ptr, *old_exch_ptr; -/* - * Zero out global solution data - */ - new_exch_ptr = new cxxExchange(); - - std::map < int, LDBLE >::const_iterator it_mix; - std::map < int, LDBLE >*mixcomps = mixmap.comps(); - - // Pitzer_exchange_gammas - it_mix = mixcomps->begin(); - old_exch_ptr = &((this->Exchangers.find(it_mix->first))->second); - if (old_exch_ptr == NULL) - { - error_string = sformatf( "Exchange %d not found in mix_cxxExchange.", - it_mix->first); - error_msg(error_string, CONTINUE); - phreeqc_ptr-> input_error++; - return (NULL); - } - new_exch_ptr->set_pitzer_exchange_gammas(old_exch_ptr-> - get_pitzer_exchange_gammas()); -/* - * Make list of ExchComps - */ - std::vector < cxxExchComp > ec_vector; - std::vector < LDBLE >f_vector; - // - // make list of all exchange components and their mix fractions - // - for (it_mix = mixcomps->begin(); it_mix != mixcomps->end(); it_mix++) - { - old_exch_ptr = &((this->Exchangers.find(it_mix->first))->second); - if (old_exch_ptr == NULL) - { - error_string = sformatf( "Exchange %d not found in mix_cxxExchange.", - it_mix->first); - error_msg(error_string, CONTINUE); - phreeqc_ptr-> input_error++; - return (NULL); - } - // Add exchange components to vector ec_vector - std::list < cxxExchComp >::const_iterator it_ec; - std::list < cxxExchComp > &eclist = old_exch_ptr->get_exchComps(); - for (it_ec = eclist.begin(); it_ec != eclist.end(); it_ec++) - { - f_vector.push_back(it_mix->second); - //cxxExchComp ec = *it_ec; - //ec_vector.push_back(ec); - ec_vector.push_back(*it_ec); - } - } - // - // Process list to make mixture - // - char *current_formula = ec_vector.begin()->get_formula(); - while (current_formula != NULL) - { - - std::vector < cxxExchComp > ec_subvector; - std::vector < LDBLE >f_subvector; - std::vector < cxxExchComp >::iterator it_ec = ec_vector.begin(); - std::vector < LDBLE >::iterator it_f = f_vector.begin(); - current_formula = NULL; - for (; it_ec != ec_vector.end(); it_ec++) - { - if (*it_f != 0) - { - if (current_formula == NULL) - current_formula = it_ec->get_formula(); - if (it_ec->get_formula() == current_formula) - { - ec_subvector.push_back(*it_ec); - f_subvector.push_back(*it_f); - *it_f = 0; - //ec_vector.erase(it_ec); - //f_vector.erase(it_f); - } - } - it_f++; - } - // - // mix ec_subvector to make - // one exchange component - // - if (current_formula != NULL) - { - cxxExchComp new_comp(ec_subvector, f_subvector); - new_exch_ptr->get_exchComps().push_back(new_comp); - } - } - /* - std::ostringstream oss; - new_exch_ptr->dump_raw(oss, 0); - std::cerr << oss.str(); - */ - return (new_exch_ptr); -} -#endif cxxSystem & cxxStorageBin::Get_System(void) diff --git a/Surface.cxx b/Surface.cxx index fdbc122a..459a2ab9 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -96,74 +96,6 @@ cxxSurface::Get_related_rate() const } return (false); } -#ifdef SKIP -void -cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // Surface element and attributes - s_oss << indent0; - s_oss << "type << "\"" << "\n"; - - s_oss << indent1; - s_oss << "dl_type=\"" << this->dl_type << "\"" << "\n"; - - s_oss << indent1; - s_oss << "sites_units=\"" << this->sites_units << "\"" << "\n"; - - s_oss << indent1; - s_oss << "only_counter_ions=\"" << this-> - only_counter_ions << "\"" << "\n"; - - s_oss << indent1; - s_oss << "thickness=\"" << this->thickness << "\"" << "\n"; - - s_oss << indent1; - s_oss << "debye_lengths=\"" << this->debye_lengths << "\"" << "\n"; - - s_oss << indent1; - s_oss << "DDL_viscosity=\"" << this->DDL_viscosity << "\"" << "\n"; - - s_oss << indent1; - s_oss << "DDL_limit=\"" << this->DDL_limit << "\"" << "\n"; - - s_oss << indent1; - s_oss << "transport=\"" << this->transport << "\"" << "\n"; - - // surface component structures - s_oss << indent1; - s_oss << "::const_iterator it = - this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) - { - (*it).second.dump_xml(s_oss, indent + 2); - } - } - // surface charge structures - s_oss << indent1; - s_oss << "::const_iterator it = - surface_charges.begin(); it != surface_charges.end(); ++it) - { - (*it).second.dump_xml(s_oss, indent + 2); - } - - return; -} -#endif void cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { diff --git a/Temperature.cxx b/Temperature.cxx index a1df2da2..1af917b4 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -32,41 +32,6 @@ cxxTemperature::~cxxTemperature() { } -#ifdef SKIP -void -cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // Temperature element and attributes - s_oss << indent0; - s_oss << " - pitzer_temperature_gammas << "\"" << "\n"; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = - temperatureComps.begin(); it != temperatureComps.end(); ++it) - { - it->dump_xml(s_oss, indent + 2); - } - - return; -} -#endif - int cxxTemperature::read(CParser & parser) { diff --git a/basicsubs.cpp b/basicsubs.cpp index e7988f35..f66ef510 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -665,39 +665,7 @@ calc_logk_p(const char *name) } return (lk); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -calc_logk_s(const char *name) -/* ---------------------------------------------------------------------- */ -{ - int i; - char token[MAX_LENGTH]; - struct species *s_ptr; - LDBLE lk, l_logk[MAX_LOG_K_INDICES]; - strcpy(token, name); - s_ptr = s_search(token); - if (s_ptr != NULL) - { - for (i = 0; i < MAX_LOG_K_INDICES; i++) - { - l_logk[i] = 0.0; - } - //if (s_ptr->moles) - //select_log_k_expression(s_ptr->rxn_x->logk, l_logk); - select_log_k_expression(s_ptr->rxn->logk, l_logk); - //{ - // perhaps calculate species' delta_v if absent? - // select_log_k_expression(s_ptr->rxn_s->logk, l_logk); - //} - add_other_logk(l_logk, s_ptr->count_add_logk, s_ptr->add_logk); - lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM); - return (lk); - } - return (-999.99); -} -#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_logk_s(const char *name) @@ -2218,238 +2186,7 @@ match_elts_in_species(const char *name, const char *mytemplate) } return (match); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -match_elts_in_species(const char *name, const char *mytemplate) -/* ---------------------------------------------------------------------- */ -{ -/* - * Makes a list of elements with their coefficients, stores elements - * in elt_list at position count_elts. Global variable count_elts is - * updated with each stored element. Also uses static global variable - * paren_count. - * - * Arguments: - * **t_ptr input, point in token string to start looking - * output, is next position to start looking - * coef input, coefficient to multiply subscripts by - */ - int i, i1, l, case_no, match; - char c, c1; - char *ptr, *ptr1; - const char *replace_name, *name_ptr; - LDBLE d; - char element[MAX_LENGTH]; - char token[MAX_LENGTH], equal_list[MAX_LENGTH], elt_name[MAX_LENGTH]; - char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH]; - char str[2]; - strcpy(token, name); - squeeze_white(token); - while (replace("(+", "(", token)); - while (replace("++++++", "+6", token)); - while (replace("+++++", "+5", token)); - while (replace("++++", "+4", token)); - while (replace("+++", "+3", token)); - while (replace("++", "+2", token)); - while (replace("------", "-6", token)); - while (replace("-----", "-5", token)); - while (replace("----", "-4", token)); - while (replace("---", "-3", token)); - while (replace("--", "-2", token)); - - ptr = token; - count_match_tokens = 0; - while ((c = *ptr) != '\0') - { - c1 = *(ptr + 1); - str[0] = c; - str[1] = '\0'; -/* - * New element - */ - if (isupper((int) c) || (c == 'e' && c1 == '-') || (c == '[')) - { - /* - * Get new element and subscript - */ - if (get_elt(&ptr, element, &l) == ERROR) - { - return (ERROR); - } - match_tokens[count_match_tokens].name = string_hsave(element); - if (get_num(&ptr, &d) == ERROR) - { - return (ERROR); - } - match_tokens[count_match_tokens++].coef = d; - } - else - { - match_tokens[count_match_tokens].name = string_hsave(str); - match_tokens[count_match_tokens++].coef = 1.0; - ptr += 1; - } - } - /* - * Replace elements with first of equivalent elements - */ - strcpy(template1, mytemplate); - squeeze_white(template1); - ptr = template1; - while (extract_bracket(&ptr, equal_list) == TRUE) - { - replace("{", "", equal_list); - replace("}", "", equal_list); - while (replace(",", " ", equal_list) == TRUE); - ptr1 = equal_list; - /* - * Get first name in a list from template - */ - if (copy_token(elt_name, &ptr1, &l) == EMPTY) - { - error_string = sformatf( - "Expecting a nonempty list of element names in isotope sum. %s", - mytemplate); - error_msg(error_string, CONTINUE); - return (ERROR); - } - replace_name = string_hsave(elt_name); - /* - * Replace in species all equivalent names from template - */ - while (copy_token(elt_name, &ptr1, &l) != EMPTY) - { - name_ptr = string_hsave(elt_name); - for (i = 0; i < count_match_tokens; i++) - { - if (name_ptr == match_tokens[i].name) - { - match_tokens[i].name = replace_name; - } - } - } - } - /* - * Combine contiguous elements - */ - i1 = 0; - for (i = 1; i < count_match_tokens; i++) - { - if ((isupper((int) (match_tokens[i].name[0])) != FALSE) - && (match_tokens[i].name == match_tokens[i1].name)) - { - match_tokens[i1].coef += match_tokens[i].coef; - } - else - { - i1++; - match_tokens[i1].name = match_tokens[i].name; - match_tokens[i1].coef = match_tokens[i].coef; - } - } - count_match_tokens = i1 + 1; - /* - * write out string - */ - token[0] = '\0'; - for (i = 0; i < count_match_tokens; i++) - { - strcat(token, match_tokens[i].name); - if (match_tokens[i].coef != 1.0) - { - sprintf(token1, "%g", (double) match_tokens[i].coef); - strcat(token, token1); - } - } - /* - * Write a template name using first of equivalent elements - */ - strcpy(template1, mytemplate); - squeeze_white(template1); - ptr = template1; - while (extract_bracket(&ptr, equal_list) == TRUE) - { - strcpy(equal_list1, equal_list); - replace("{", "", equal_list); - replace("}", "", equal_list); - while (replace(",", " ", equal_list) == TRUE); - ptr1 = equal_list; - /* - * Get first name in a list - */ - if (copy_token(elt_name, &ptr1, &l) == EMPTY) - { - error_string = sformatf( - "Expecting a nonempty list of element names in isotope sum. %s", - mytemplate); - error_msg(error_string, CONTINUE); - return (ERROR); - } - replace_name = string_hsave(elt_name); - replace(equal_list1, replace_name, template1); - squeeze_white(template1); - ptr = template1; - } - /* - * Compare string - */ - /* Cases: 0 exact match - * 1 leading wild card - * 2 trailing wild card - * 3 leading and trailing wild card - */ - case_no = 0; - if (template1[0] == '*') - case_no = 1; - l = (int) strlen(template1); - if (template1[l - 1] == '*') - { - if (case_no != 1) - { - case_no = 2; - } - else - { - case_no = 3; - } - } - while (replace("*", "", template1)); - match = FALSE; - switch (case_no) - { - case 0: - /* exact match */ - if (strcmp(token, template1) == 0) - match = TRUE; - break; - case 1: - /* leading wild card */ - if ((ptr = strstr(token, template1)) == NULL) - { - match = FALSE; - } - else - { - if (strcmp(ptr, template1) == 0) - match = TRUE; - } - break; - case 2: - /* trailing wild card */ - if (strstr(token, template1) == token) - match = TRUE; - break; - case 3: - /* trailing wild card */ - if (strstr(token, template1) != NULL) - match = TRUE; - break; - } - return (match); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: extract_bracket(char **string, char *bracket_string) @@ -2614,126 +2351,7 @@ surf_total(const char *total_name, const char *surface_name) } return t; } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -surf_total(const char *total_name, const char *surface_name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in LDBLE layer - */ - int j; - if (use.Get_surface_ptr() == NULL || surface_name == NULL) - return (0); - -/* - * Find surface... - */ - for (j = 0; j < count_unknowns; j++) - { - if (x[j]->type != SURFACE) - continue; - - std::string token; - token = x[j]->master[0]->elt->name; - replace("_", " ", token); - std::string::iterator b = token.begin(); - std::string::iterator e = token.end(); - std::string name; - CParser::copy_token(name, b, e); - if (strcmp(name.c_str(), surface_name) == 0) - break; - } - if (j >= count_unknowns) - return (0); -/* - * find total moles for redox state - */ - LDBLE t = 0; - bool redox = false; - if (strstr(total_name, "(") != NULL) - { - redox = true; - } - for (j = 0; j < count_s_x; j++) - { - if (s_x[j]->type != SURF) - continue; - - std::string token; - bool match = false; - - // find if surface matches - for (int i = 0; s_x[j]->next_elt[i].elt != NULL; i++) - { - if (s_x[j]->next_elt[i].elt->master->type != SURF) continue; - - //strcpy(token, s_x[j]->next_elt[i].elt->name); - //replace("_", " ", token); - //ptr = token; - //copy_token(name, &ptr, &k); - token = s_x[j]->next_elt[i].elt->name; - replace("_", " ", token); - std::string::iterator b = token.begin(); - std::string::iterator e = token.end(); - std::string name; - CParser::copy_token(name, b, e); - if (strcmp(name.c_str(), surface_name) == 0) - { - match = true; - break; - } - } - if (!match) continue; - - // surface matches, now match element or redox state - struct rxn_token *rxn_ptr; - for (rxn_ptr = s_x[j]->rxn_s->token + 1; rxn_ptr->s != NULL; rxn_ptr++) - { - if (redox && rxn_ptr->s->secondary) - { - token = rxn_ptr->s->secondary->elt->name; - } - else if (!redox && rxn_ptr->s->secondary) - { - token = rxn_ptr->s->secondary->elt->primary->elt->name; - } - else if (!redox && rxn_ptr->s->primary) - { - token = rxn_ptr->s->primary->elt->name; - } - else - { - continue; - } - if (strcmp(token.c_str(), total_name) == 0) - { - t += rxn_ptr->coef * s_x[j]->moles; - break; - } - else - // sum all sites in case total_name is a surface name without underscore surf ("Hfo_w", "Hfo") - { - if (rxn_ptr->s->type == SURF) - { - if (token.find("_") != std::string::npos) - { - token = token.substr(0, token.find("_")); - } - if (strcmp(token.c_str(), total_name) == 0) - { - t += rxn_ptr->coef * s_x[j]->moles; - break; - } - } - } - } - } - return t; -} -#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: surf_total_no_redox(const char *total_name, const char *surface_name) @@ -2988,44 +2606,12 @@ get_edl_species(cxxSurfaceCharge & charge_ref) sys[count_sys].moles = moles_surface; sys_tot += sys[count_sys].moles; count_sys++; -#ifdef SKIP - double g = charge_ref.Get_g_map()[s_x[j]->z].Get_g(); - double moles_excess = mass_water_aq_x * molality * (g * s_x[j]->erm_ddl + - mass_water_surface / - mass_water_aq_x * (s_x[j]->erm_ddl - 1)); - double c = (mass_water_surface * molality + moles_excess) / mass_water_surface; - charge_ref.Get_dl_species_map()[s_x[j]->number] = c; -#endif } else { continue; } } -#ifdef SKIP -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i; -/* - * find total moles in aq, surface, and exchange - */ - - for (i = 0; i < count_s_x; i++) - { - //if (s_x[i]->type != AQ) - if (s_x[i]->type > HPLUS) - continue; - sys[count_sys].name = string_duplicate(s_x[i]->name); - sys[count_sys].moles = s_x[i]->moles; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("aq"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); - } - -#endif return (OK); } /* ---------------------------------------------------------------------- */ diff --git a/class_main.cpp b/class_main.cpp index 897052e5..78f3d148 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -427,11 +427,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, if (strcmp_nocase(token, "database") == 0) { user_database = (char *) free_check_null(user_database); -#ifdef PHREEQ98 - user_database = string_duplicate(prefix_database_dir(ptr)); -#else user_database = string_duplicate(ptr); -#endif if (string_trim(user_database) == EMPTY) { warning_msg("DATABASE file name is missing; default database will be used."); @@ -627,11 +623,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, if (strcmp_nocase(token, "database") == 0) { user_database = (char *) free_check_null(user_database); -#ifdef PHREEQ98 - user_database = string_duplicate(prefix_database_dir(ptr)); -#else user_database = string_duplicate(ptr); -#endif if (string_trim(user_database) == EMPTY) { warning_msg("DATABASE file name is missing; default database will be used."); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index be640cae..2cc4b67f 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -69,41 +69,6 @@ cxxKinetics::~cxxKinetics() { } -#ifdef SKIP -void -cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // Kinetics element and attributes - s_oss << indent0; - s_oss << " - pitzer_kinetics_gammas << "\"" << "\n"; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = - kineticsComps.begin(); it != kineticsComps.end(); ++it) - { - it->dump_xml(s_oss, indent + 2); - } - - return; -} -#endif - void cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) const { diff --git a/cxxMix.cxx b/cxxMix.cxx index a9161c36..763c31fc 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -29,41 +29,6 @@ cxxMix::~cxxMix() { } -#ifdef SKIP -void -cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const -{ - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for (i = 0; i < indent; ++i) - indent0.append(Utilities::INDENT); - for (i = 0; i < indent + 1; ++i) - indent1.append(Utilities::INDENT); - for (i = 0; i < indent + 2; ++i) - indent2.append(Utilities::INDENT); - - // Mix element and attributes - s_oss << indent0; - s_oss << " - pitzer_mix_gammas << "\"" << "\n"; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = mixComps.begin(); - it != mixComps.end(); ++it) - { - it->dump_xml(s_oss, indent + 2); - } - - return; -} -#endif - void cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { diff --git a/global_structures.h b/global_structures.h index f90ec208..d0604682 100644 --- a/global_structures.h +++ b/global_structures.h @@ -289,51 +289,7 @@ struct name_phase const char *name; struct phase *phase; }; -#ifdef SKIP -struct punch -{ - int in; - int new_def; - struct name_master *totals; - int count_totals; - struct name_species *molalities; - int count_molalities; - struct name_species *activities; - int count_activities; - struct name_phase *pure_phases; - int count_pure_phases; - struct name_phase *si; - int count_si; - struct name_phase *gases; - int count_gases; - struct name_phase *s_s; - int count_s_s; - struct name_phase *kinetics; - int count_kinetics; - struct name_master *isotopes; - int count_isotopes; - struct name_master *calculate_values; - int count_calculate_values; - int inverse; - int sim; - int state; - int soln; - int dist; - int time; - int step; - int rxn; - int temp; - int ph; - int pe; - int alk; - int mu; - int water; - int high_precision; - int user_punch; - int charge_balance; - int percent_error; -}; -#endif + struct Change_Surf { const char *comp_name; diff --git a/inverse.cpp b/inverse.cpp index f31bda65..13ccc69f 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -2223,100 +2223,6 @@ punch_model_heading(struct inverse *inv_ptr) punch_flush(); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -punch_model_heading(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints model headings to selected output file - */ - int i; - char token[MAX_LENGTH]; - //if (/*punch.in == FALSE ||*/ pr.punch == FALSE || punch.inverse == FALSE) - // return (OK); - std::vector heading_names; - std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); - for ( ; so_it != SelectedOutput_map.end(); so_it++) - { - // set punch file - current_selected_output = &(so_it->second); - if (pr.punch == FALSE || - current_selected_output == NULL || - current_selected_output->punch_ostream == NULL || - !current_selected_output->Get_inverse() || - !current_selected_output->Get_active()) - continue; - phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); - - int l = (!current_selected_output->Get_high_precision()) ? 15 : 20; - heading_names.clear(); - /* - * Print sum of residuals and maximum fractional error - */ - heading_names.push_back(sformatf("%*s\t", l, "Sum_resid")); - heading_names.push_back(sformatf("%*s\t", l, "Sum_Delta/U")); - heading_names.push_back(sformatf("%*s\t", l, "MaxFracErr")); - - /* - * Print solution numbers - */ - for (i = 0; i < inv_ptr->count_solns; i++) - { - sprintf(token, "Soln_%d", inv_ptr->solns[i]); - std::string tok1(token); - tok1.append("_min"); - std::string tok2(token); - tok2.append("_max"); - - heading_names.push_back(sformatf("%*s\t", l, token)); - heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); - heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); - } - /* - * Print phase names - */ - for (i = col_phases; i < col_redox; i++) - { - - std::string tok1(col_name[i]); - tok1.append("_max"); - std::string tok2(col_name[i]); - tok2.append("_max"); - - heading_names.push_back(sformatf("%*s\t", l, col_name[i])); - heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); - heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); - - } - - size_t j; - - // punch headings - //user_punch_count_headings = (int) heading_names.size(); - //user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, - // (size_t) (user_punch_count_headings + 1) * sizeof(char *)); - //if (user_punch_headings == NULL) - // malloc_error(); - - for (j = 0; j < heading_names.size(); j++) - { - fpunchf_heading(heading_names[j].c_str()); - //user_punch_headings[j] = string_hsave(heading_names[j].c_str()); - } - fpunchf_heading("\n"); - } - current_selected_output = NULL; - phrq_io->Set_punch_ostream(NULL); - inverse_heading_names = heading_names; -/* - * Flush buffer after each model - */ - punch_flush(); - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: punch_model(struct inverse *inv_ptr) @@ -5204,7 +5110,7 @@ dump_netpath_pat(struct inverse *inv_ptr) std::string::iterator e = string.end(); CParser::copy_token(token, b, e); CParser::copy_token(string1, b, e); - sscanf(string1.c_str(), SCANFORMAT, &f); + (void)sscanf(string1.c_str(), SCANFORMAT, &f); sum += f * rxn_ptr->coef; } } diff --git a/isotopes.cpp b/isotopes.cpp index 9ed21205..1fada086 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -106,7 +106,7 @@ read_isotopes(void) input_error++; break; } - sscanf(token, SCANFORMAT, &(master_isotope_ptr->standard)); + (void)sscanf(token, SCANFORMAT, &(master_isotope_ptr->standard)); opt_save = OPTION_DEFAULT; break; case 1: /* total_is_major_isotope */ @@ -1137,46 +1137,6 @@ calculate_values(void) calculate_value[j]->calculated = FALSE; calculate_value[j]->value = MISSING; } -#ifdef SKIP - for (j = 0; j < count_calculate_value; j++) - { - calculate_value_ptr = calculate_value[j]; - rate_moles = NAN; - if (calculate_value_ptr->new_def == TRUE) - { - if (basic_compile - (calculate_value[j]->commands, &calculate_value[j]->linebase, - &calculate_value[j]->varbase, - &calculate_value[j]->loopbase) != 0) - { - error_string = sformatf( - "Fatal Basic error in CALCULATE_VALUES %s.", - calculate_value[j]->name); - error_msg(error_string, STOP); - } - calculate_value_ptr->new_def = FALSE; - } - if (basic_run - (l_command, calculate_value[j]->linebase, - calculate_value[j]->varbase, calculate_value[j]->loopbase) != 0) - { - error_string = sformatf( "Fatal Basic error in calculate_value %s.", - calculate_value[j]->name); - error_msg(error_string, STOP); - } - if (rate_moles == NAN) - { - error_string = sformatf( "Calculated value not SAVEed for %s.", - calculate_value[j]->name); - error_msg(error_string, STOP); - } - else - { - calculate_value[j]->calculated = TRUE; - calculate_value[j]->value = rate_moles; - } - } -#endif if (pr.isotope_ratios == TRUE) { for (j = 0; j < count_isotope_ratio; j++) @@ -1306,107 +1266,6 @@ calculate_values(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -calculate_values(void) -/* ---------------------------------------------------------------------- */ -{ - int j; - struct calculate_value *calculate_value_ptr; - struct isotope_ratio *isotope_ratio_ptr; - struct isotope_alpha *isotope_alpha_ptr; - struct master_isotope *master_isotope_ptr; - char l_command[] = "run"; - - - /* - * initialize ratios as missing - */ - for (j = 0; j < count_calculate_value; j++) - { - calculate_value[j]->calculated = FALSE; - calculate_value[j]->value = MISSING; - } - for (j = 0; j < count_calculate_value; j++) - { - calculate_value_ptr = calculate_value[j]; - rate_moles = NAN; - if (calculate_value_ptr->new_def == TRUE) - { - if (basic_compile - (calculate_value[j]->commands, &calculate_value[j]->linebase, - &calculate_value[j]->varbase, - &calculate_value[j]->loopbase) != 0) - { - error_string = sformatf( - "Fatal Basic error in CALCULATE_VALUES %s.", - calculate_value[j]->name); - error_msg(error_string, STOP); - } - calculate_value_ptr->new_def = FALSE; - } - if (basic_run - (l_command, calculate_value[j]->linebase, - calculate_value[j]->varbase, calculate_value[j]->loopbase) != 0) - { - error_string = sformatf( "Fatal Basic error in calculate_value %s.", - calculate_value[j]->name); - error_msg(error_string, STOP); - } - if (rate_moles == NAN) - { - error_string = sformatf( "Calculated value not SAVEed for %s.", - calculate_value[j]->name); - error_msg(error_string, STOP); - } - else - { - calculate_value[j]->calculated = TRUE; - calculate_value[j]->value = rate_moles; - } - } - for (j = 0; j < count_isotope_ratio; j++) - { - isotope_ratio_ptr = isotope_ratio[j]; - master_isotope_ptr = - master_isotope_search(isotope_ratio_ptr->isotope_name); - calculate_value_ptr = calculate_value_search(isotope_ratio_ptr->name); - /* - * Calculate converted isotope ratio - */ - if (calculate_value_ptr->value == MISSING) - { - isotope_ratio_ptr->ratio = MISSING; - isotope_ratio_ptr->converted_ratio = MISSING; - } - else - { - isotope_ratio_ptr->ratio = calculate_value_ptr->value; - isotope_ratio_ptr->converted_ratio = - convert_isotope(master_isotope_ptr, - calculate_value_ptr->value); - } - } - for (j = 0; j < count_isotope_alpha; j++) - { - isotope_alpha_ptr = isotope_alpha[j]; - calculate_value_ptr = calculate_value_search(isotope_alpha_ptr->name); - /* - * Calculate converted isotope ratio - */ - if (calculate_value_ptr->value == MISSING) - { - isotope_alpha_ptr->value = MISSING; - } - else - { - isotope_alpha_ptr->value = calculate_value_ptr->value; - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: convert_isotope(struct master_isotope * master_isotope_ptr, LDBLE ratio) diff --git a/kinetics.cpp b/kinetics.cpp index 177077aa..e18f3dd7 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -288,121 +288,7 @@ RESTART: // if limiting rates, jump to here } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through kinetic components to - * using extrapolated values, which were - * stored in moles in run_kinetics - */ - LDBLE coef; - struct phase *phase_ptr; - struct master *master_ptr; -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - kinetics_ptr->Get_totals().clear(); - count_elts = 0; - paren_count = 0; - for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) - { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); - if (kinetics_comp_ptr->Get_moles() > m_temp[i]) - { - kinetics_comp_ptr->Set_moles(m_temp[i]); - kinetics_comp_ptr->Set_m(0); - } - coef = kinetics_comp_ptr->Get_moles(); - if (coef == 0.0) - continue; -/* - * Reactant is a pure phase, copy formula into token - */ - cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin(); - for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++) - { - std::string name = it->first; - LDBLE coef1 = it->second; - phase_ptr = NULL; - int k; - phase_ptr = phase_bsearch(name.c_str(), &k, FALSE); - if (phase_ptr != NULL) - { - add_elt_list(phase_ptr->next_elt, - coef *coef1); - } - else - { - char * temp_name = string_duplicate(name.c_str()); - char * ptr = temp_name; - get_elts_in_species(&ptr, coef * coef1); - free_check_null(temp_name); - } - } - if (use.Get_exchange_ptr() != NULL - && use.Get_exchange_ptr()->Get_related_rate()) - { - cxxExchange * exchange_ptr = use.Get_exchange_ptr(); - for(size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) - { - std::string name(exchange_ptr->Get_exchange_comps()[j].Get_rate_name()); - if (name.size() > 0) - { - if (strcmp_nocase - (kinetics_comp_ptr->Get_rate_name().c_str(), - name.c_str()) == 0) - { - /* 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()); - free_check_null(formula); - } - } - } - } - if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_related_rate()) - { - for (size_t j = 0; j < use.Get_surface_ptr()->Get_surface_comps().size(); j++) - { - cxxSurfaceComp *surface_comp_ptr = &(use.Get_surface_ptr()->Get_surface_comps()[j]); - if (surface_comp_ptr->Get_rate_name().size() > 0) - { - if (strcmp_nocase - (kinetics_comp_ptr->Get_rate_name().c_str(), - surface_comp_ptr->Get_rate_name().c_str()) == 0) - { - /* found kinetics component */ - char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str()); - char *ptr = temp_formula; -/* Surface = 0 when m becomes low ... - */ - if (0.9 * surface_comp_ptr->Get_phase_proportion() * - (kinetics_comp_ptr->Get_m()) < MIN_RELATED_SURFACE) - { - master_ptr = master_bsearch(ptr); - master_ptr->total = 0.0; - } - else - { - get_elts_in_species(&ptr, -coef * surface_comp_ptr->Get_phase_proportion()); - } - free_check_null(temp_formula); - } - } - } - } - } - kinetics_ptr->Set_totals(elt_list_NameDouble()); - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, @@ -1189,21 +1075,6 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, step_ok, (int) (100 * h_sum / kin_time)); status(0, str, true); } -#ifdef SKIP -#if !defined(PHREEQCI_GUI) -#ifndef PHREEQ98 - if (pr.status == TRUE && status_on == TRUE - && (int) (1e3 / CLOCKS_PER_SEC * ((float) clock() - status_timer)) > status_interval) - { - char str[MAX_LENGTH]; - backspace_screen(37); - sprintf(str, "RK-steps: Bad%4d. OK%5d. Time %3d%%", step_bad, - step_ok, (int) (100 * h_sum / kin_time)); - screen_msg(sformatf("%-37s", str)); - } -#endif -#endif -#endif } EQUAL_RATE_OUT: @@ -2094,398 +1965,6 @@ set_reaction(int i, int use_mix, int use_kinetics) */ return (OK); } -//#define REVISED_CVODE -#ifdef REVISED_CVODE -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ -/* - * Kinetics calculations - * Rates and moles of each reaction are calculated in calc_kinetic_reaction - * Total number of moles in reaction is stored in kinetics[i].totals - */ - - int converge, m_iter; - int pr_all_save; - int nsaver; - cxxKinetics *kinetics_ptr; - cxxPPassemblage *pp_assemblage_ptr; - cxxSSassemblage *ss_assemblage_ptr; - cxxUse use_save; - int save_old, n_reactions /*, nok, nbad */ ; - - /* CVODE definitions */ - realtype ropt[OPT_SIZE], reltol, t, tout, tout1, sum_t; - long int iopt[OPT_SIZE]; - int flag; -/* - * Set nsaver - */ - run_reactions_iterations = 0; - kin_time_x = kin_time; - rate_kin_time = kin_time; - nsaver = i; - if (state == TRANSPORT || state == PHAST) - { - if (use_mix == DISP) - { - nsaver = -2; - } - else if (use_mix == STAG) - { - nsaver = -2 - i; - } - } - if (state == ADVECTION) - { - nsaver = -2; - } -/* - * Check that reaction exists for this cell .. - */ - kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); - if (kin_time <= 0 || - (state == REACTION && use.Get_kinetics_in() == FALSE) || - (state == TRANSPORT && kinetics_ptr == NULL) || - (state == PHAST && kinetics_ptr == NULL) || - (state == ADVECTION && kinetics_ptr == NULL)) - { - converge = set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); - if (converge == MASS_BALANCE) - { - error_msg("Negative concentration in system. Stopping calculation.", STOP); - } - run_reactions_iterations += iterations; - } - else - { -/* - * Save moles of kinetic reactants for printout... - */ - size_t count_comps = kinetics_ptr->Get_kinetics_comps().size(); - m_temp = (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); - if (m_temp == NULL) - malloc_error(); - - m_original = (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); - if (m_original == NULL) - malloc_error(); - - for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) - { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); - m_original[j] = kinetics_comp_ptr->Get_m(); - m_temp[j] = kinetics_comp_ptr->Get_m(); - } -/* -* Start the loop for timestepping ... - * Use either Runge-Kutta-Fehlberg, or final result extrapolation - */ - pr_all_save = pr.all; - pr.all = FALSE; -/* - * This condition makes output equal for incremental_reactions TRUE/FALSE... - * (if (incremental_reactions == FALSE || reaction_step == 1) - */ - store_get_equi_reactants(i, FALSE); - if (!kinetics_ptr->Get_use_cvode()) - { - rk_kinetics(i, kin_time, use_mix, nsaver, step_fraction); - - // finish up - rate_sim_time = rate_sim_time_start + kin_time; - store_get_equi_reactants(i, TRUE); - pr.all = pr_all_save; - - kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); - for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) - { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); - kinetics_comp_ptr->Set_moles(m_original[j] - kinetics_comp_ptr->Get_m()); - } - m_temp = (LDBLE *) free_check_null(m_temp); - m_original = (LDBLE *) free_check_null(m_original); - } - else - { - // save initial reactants - // cxxStorageBin save_bin(use); // if needed - - save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); - if (nsaver != i) - { - Utilities::Rxn_copy(Rxn_solution_map, i, save_old); - } - for (int j = 0; j < OPT_SIZE; j++) - { - iopt[j] = 0; - ropt[j] = 0; - } - -/* - * Do mix first - */ - kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); - n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size(); - cvode_n_user = i; - cvode_kinetics_ptr = (void *) kinetics_ptr; - cvode_n_reactions = n_reactions; - cvode_rate_sim_time_start = rate_sim_time_start; - cvode_rate_sim_time = rate_sim_time; - - if (multi_Dflag) - converge = set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - else - converge = set_and_run_wrapper(i, use_mix, FALSE, i, 0.0); - if (converge == MASS_BALANCE) - error_msg - ("Negative concentration in system. Stopping calculation.", - STOP); - saver(); - pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, i); - ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, i); - if (pp_assemblage_ptr != NULL) - { - cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); - } - if (ss_assemblage_ptr != NULL) - { - cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); - } - - /* allocate space for CVODE */ - kinetics_machEnv = M_EnvInit_Serial(n_reactions); - kinetics_machEnv->phreeqc_ptr = this; - kinetics_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (kinetics_y == NULL) - malloc_error(); - cvode_last_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (cvode_last_good_y == NULL) - malloc_error(); - cvode_prev_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (cvode_prev_good_y == NULL) - malloc_error(); - kinetics_abstol = N_VNew(n_reactions, kinetics_machEnv); - if (kinetics_abstol == NULL) - malloc_error(); - for (int j = 0; j < n_reactions; j++) - { - Ith(cvode_last_good_y, j + 1) = 0.0; - Ith(cvode_prev_good_y, j + 1) = 0.0; - Ith(kinetics_abstol, j + 1) = 0.0; - } -/* - * Set y to 0.0 - */ - for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) - { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); - kinetics_comp_ptr->Set_moles(0.0); - Ith(kinetics_y, j + 1) = 0.0; - Ith(kinetics_abstol, j + 1) = kinetics_comp_ptr->Get_tol(); - } - reltol = 0.0; - - /* Call CVodeMalloc to initialize CVODE: - - NEQ is the problem size = number of equations - f is the user's right hand side function in y'=f(t,y) - T0 is the initial time - y is the initial dependent variable vector - BDF specifies the Backward Differentiation Formula - NEWTON specifies a Newton iteration - SV specifies scalar relative and vector absolute tolerances - &reltol is a pointer to the scalar relative tolerance - abstol is the absolute tolerance vector - FALSE indicates there are no optional inputs in iopt and ropt - iopt is an array used to communicate optional integer input and output - ropt is an array used to communicate optional real input and output - - A pointer to CVODE problem memory is returned and stored in cvode_mem. */ - /* Don`t know what this does */ - /* - iopt[SLDET] = TRUE; - cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); - cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, ADAMS, FUNCTIONAL, SV, &reltol, abstol, NULL, NULL, FALSE, iopt, ropt, machEnv); - iopt[MXSTEP] is maximum number of steps that CVODE tries. - */ - iopt[MXSTEP] = kinetics_ptr->Get_cvode_steps(); - iopt[MAXORD] = kinetics_ptr->Get_cvode_order(); - kinetics_cvode_mem = - CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, - &reltol, kinetics_abstol, this, NULL, TRUE, iopt, - ropt, kinetics_machEnv); - if (kinetics_cvode_mem == NULL) - malloc_error(); - - /* Call CVDense to specify the CVODE dense linear solver with the - user-supplied Jacobian routine Jac. */ - flag = CVDense(kinetics_cvode_mem, Jac, this); - if (flag != SUCCESS) - { - error_msg("CVDense failed.", STOP); - } - t = 0; - tout = kin_time; - /*ropt[HMAX] = tout/10.; */ - /*ropt[HMIN] = 1e-17; */ - use_save = use; - flag = CVode(kinetics_cvode_mem, tout, kinetics_y, &t, NORMAL); - rate_sim_time = rate_sim_time_start + t; - /* - printf("At t = %0.4e y =%14.6e %14.6e %14.6e\n", - t, Ith(y,1), Ith(y,2), Ith(y,3)); - */ - m_iter = 0; - sum_t = 0; -RESTART: - while (flag != SUCCESS) - { - sum_t += cvode_last_good_time; - error_string = sformatf( - "CVode incomplete at cvode_steps %d. Cell: %d\tTime: %e\tCvode calls: %d, continuing...\n", - (int) iopt[NST], cell_no, (double) sum_t, m_iter + 1); - warning_msg(error_string); - - // run with last good y, update reactants - cvode_update_reactants(i, nsaver, true); - - cvode_last_good_time = 0; - if (++m_iter >= kinetics_ptr->Get_bad_step_max()) - { - m_temp = (LDBLE *) free_check_null(m_temp); - m_original = (LDBLE *) free_check_null(m_original); - error_msg("Repeated restart of integration.", STOP); - } - tout1 = tout - sum_t; - t = 0; - N_VScale(1.0, cvode_last_good_y, kinetics_y); - for (int j = 0; j < OPT_SIZE; j++) - { - iopt[j] = 0; - ropt[j] = 0; - } - CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ - iopt[MXSTEP] = kinetics_ptr->Get_cvode_steps(); - iopt[MAXORD] = kinetics_ptr->Get_cvode_order(); - kinetics_cvode_mem = - CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, - SV, &reltol, kinetics_abstol, this, NULL, - TRUE, iopt, ropt, kinetics_machEnv); - if (kinetics_cvode_mem == NULL) - malloc_error(); - - /* Call CVDense to specify the CVODE dense linear solver with the - user-supplied Jacobian routine Jac. */ - flag = CVDense(kinetics_cvode_mem, Jac, this); - if (flag != SUCCESS) - { - error_msg("CVDense failed.", STOP); - } - flag = CVode(kinetics_cvode_mem, tout1, kinetics_y, &t, NORMAL); - } - // end cvode integration - - // update -#ifdef SKIP - for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) - { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); - kinetics_comp_ptr->Set_moles(Ith(kinetics_y, j + 1)); - kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); - if (kinetics_comp_ptr->Get_m() < 0) - { - kinetics_comp_ptr->Set_moles(m_original[j]); - kinetics_comp_ptr->Set_m(0.0); - } - } - if (use.Get_pp_assemblage_ptr() != NULL) - { - Rxn_pp_assemblage_map[cvode_pp_assemblage_save->Get_n_user()] = *cvode_pp_assemblage_save; - use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, cvode_pp_assemblage_save->Get_n_user())); - } - if (use.Get_ss_assemblage_ptr() != NULL) - { - Rxn_ss_assemblage_map[cvode_ss_assemblage_save->Get_n_user()] = *cvode_ss_assemblage_save; - use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); - } -#endif - - // put remaining kinetic reaction in last_good_y for update - N_VScale(1.0, kinetics_y, cvode_last_good_y); - if (!cvode_update_reactants(i, nsaver, false)) - { - warning_msg("FAIL 2 after successful integration in CVode"); - flag = -1; - goto RESTART; - } -#ifdef SKIP - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == MASS_BALANCE) - { - warning_msg("FAIL 2 after successful integration in CVode"); - flag = -1; - goto RESTART; - } - for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) - { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); - kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); - } -#endif -/* - * Restore solution i, if necessary - */ - if (nsaver != i) - { - Utilities::Rxn_copy(Rxn_solution_map, save_old, i); - } - free_cvode(); - use.Set_mix_in(use_save.Get_mix_in()); - use.Set_mix_ptr(use_save.Get_mix_ptr()); - - // finish up - rate_sim_time = rate_sim_time_start + kin_time; - store_get_equi_reactants(i, TRUE); - pr.all = pr_all_save; - -#ifdef SKIP - kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); - for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) - { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); - kinetics_comp_ptr->Set_moles(m_original[j] - kinetics_comp_ptr->Get_m()); - } -#else - kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); - cxxKinetics *kinetics_original_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); - for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) - { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); - cxxKineticsComp * kinetics_original_comp_ptr = &(kinetics_original_ptr->Get_kinetics_comps()[j]); - kinetics_comp_ptr->Set_moles(kinetics_original_comp_ptr->Get_m() - kinetics_comp_ptr->Get_m()); - } -#endif - m_temp = (LDBLE *) free_check_null(m_temp); - m_original = (LDBLE *) free_check_null(m_original); - } // end cvode - } - iterations = run_reactions_iterations; - if (cvode_pp_assemblage_save != NULL) - { - delete cvode_pp_assemblage_save; - cvode_pp_assemblage_save = NULL; - } - if (cvode_ss_assemblage_save != NULL) - { - delete cvode_ss_assemblage_save; - cvode_ss_assemblage_save = NULL; - } - return (OK); -} -#else /* ---------------------------------------------------------------------- */ int Phreeqc:: run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) @@ -2884,7 +2363,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) } return (OK); } -#endif + /* ---------------------------------------------------------------------- */ int Phreeqc:: free_cvode(void) diff --git a/mainsubs.cpp b/mainsubs.cpp index 27e34981..d5343258 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -109,81 +109,6 @@ initialize(void) hcreate_multi((unsigned) max_elements, &elements_hash_table); hcreate_multi((unsigned) max_s, &species_hash_table); hcreate_multi((unsigned) max_phases, &phases_hash_table); -#ifdef SKIP_OLD_SELECTED_OUTPUT -/* - * Initialize punch - */ - punch.in = FALSE; - punch.new_def = FALSE; - - // one punch.totals - punch.count_totals = 0; - punch.totals = - (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.totals == NULL) - malloc_error(); - - // one punch.molalities - punch.count_molalities = 0; - punch.molalities = - (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); - if (punch.molalities == NULL) - malloc_error(); - - // one punch.activities - punch.count_activities = 0; - punch.activities = - (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); - if (punch.activities == NULL) - malloc_error(); - - // one punch.pure_phases - punch.count_pure_phases = 0; - punch.pure_phases = - (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.pure_phases == NULL) - malloc_error(); - - // one punch.si - punch.count_si = 0; - punch.si = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.si == NULL) - malloc_error(); - - // one punch.gases - punch.count_gases = 0; - punch.gases = - (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.gases == NULL) - malloc_error(); - - // one punch.s_s - punch.count_s_s = 0; - punch.s_s = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.s_s == NULL) - malloc_error(); - - // one punch.kinetics - punch.count_kinetics = 0; - punch.kinetics = - (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.kinetics == NULL) - malloc_error(); - - // one punch.isotopes - punch.count_isotopes = 0; - punch.isotopes = - (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.isotopes == NULL) - malloc_error(); - - // one punch.calculate_values - punch.count_calculate_values = 0; - punch.calculate_values = - (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.calculate_values == NULL) - malloc_error(); -#endif // one save_values save_values = (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); @@ -203,37 +128,6 @@ initialize(void) user_print->linebase = NULL; user_print->varbase = NULL; user_print->loopbase = NULL; - -#ifdef SKIP - // user_punch - user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); - if (user_punch == NULL) - malloc_error(); - user_punch->commands = NULL; - user_punch->linebase = NULL; - user_punch->varbase = NULL; - user_punch->loopbase = NULL; - user_punch_headings = (const char **) PHRQ_malloc(sizeof(char *)); - if (user_punch_headings == NULL) - malloc_error(); - user_punch_count_headings = 0; -#endif -#if defined PHREEQ98 -/* - * user_graph - */ - user_graph = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); - if (user_graph == NULL) - malloc_error(); - user_graph->commands = NULL; - user_graph->linebase = NULL; - user_graph->varbase = NULL; - user_graph->loopbase = NULL; - user_graph_headings = (char **) PHRQ_malloc(sizeof(char *)); - if (user_graph_headings == NULL) - malloc_error(); - user_graph_count_headings = 0; -#endif /* Initialize llnl aqueous model parameters */ @@ -710,26 +604,6 @@ initial_solutions(int print) initial_solution_isotopes = FALSE; return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_mix() -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through list of solution_mix, mix, save solutions - */ - std::map::iterator it; - for (it = Rxn_solution_mix_map.begin(); it != Rxn_solution_mix_map.end(); it++) - { - cxxSolution sol(Rxn_solution_map, it->second, it->second.Get_n_user(), this->phrq_io); - Rxn_solution_map[it->second.Get_n_user()] = sol; - Utilities::Rxn_copies(Rxn_solution_map, it->second.Get_n_user(), it->second.Get_n_user_end()); - } - Rxn_solution_mix_map.clear(); - return OK; -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: initial_exchangers(int print) @@ -1620,37 +1494,6 @@ xsolution_save(int n_user) warning_msg(error_string); } } -#ifdef SKIP -/* - * Bug-fix - * Create and initialize intial data (this object should always be present even if it is left empty) - */ - - temp_solution.Create_initial_data(); - cxxISolution* initialData = temp_solution.Get_initial_data(); - - initialData->Set_units( "Mol/kgw" ); - - // Copy totals to initialdata when present - if ( !temp_solution.Get_totals().empty() ) - { - cxxNameDouble& totals = temp_solution.Get_totals(); - - for (cxxNameDouble::iterator jit = totals.begin(); jit != totals.end(); jit++) - { - std::string compName( jit->first ); - double compConc = jit->second; - - SolutionCompMap& comps = initialData->Get_comps(); - - cxxISolutionComp& tempComp = comps[ compName ]; - - tempComp.Set_description( compName.c_str() ); - tempComp.Set_input_conc( compConc / temp_solution.Get_mass_water()); - tempComp.Set_units( initialData->Get_units().c_str() ); - } - } -#endif if (this->save_species) { // saves mol/L @@ -1817,7 +1660,6 @@ xsurface_save(int n_user) double moles_excess = mass_water_aq_x * molality * charge_ref.Get_g_map()[s_x[j]->z].Get_g(); double moles_surface = mass_water_surface * molality + moles_excess; charge_ref.Get_dl_species_map()[s_x[j]->number] = moles_surface/mass_water_surface; -//#ifdef SKIP double g = charge_ref.Get_g_map()[s_x[j]->z].Get_g(); //double moles_excess = mass_water_aq_x * molality * (g * s_x[j]->erm_ddl + // mass_water_surface / @@ -1833,9 +1675,6 @@ xsurface_save(int n_user) moles_excess = mass_water_aq_x * molality * g; double c = (mass_water_surface * molality + moles_excess) / mass_water_surface; charge_ref.Get_dl_species_map()[s_x[j]->number] = c; - - -//#endif } //charge_ref.Get_dl_species_map()[s_h2o->number] = 0.0; charge_ref.Get_dl_species_map()[s_h2o->number] = 1.0/gfw_water; @@ -2434,12 +2273,10 @@ run_simulations(void) /* ---------------------------------------------------------------------- */ { char token[MAX_LENGTH]; -//#ifdef SKIP_KEEP #if defined(_MSC_VER) && (_MSC_VER < 1900) // removed in vs2015 unsigned int old_exponent_format; old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); #endif -//#endif /* * Prepare error handling */ @@ -2504,11 +2341,6 @@ run_simulations(void) output_msg(sformatf( "%s\n\n", title_x)); } tidy_model(); -#ifdef PHREEQ98 - if (!phreeq98_debug) - { -#endif - /* * Calculate distribution of species for initial solutions */ @@ -2583,9 +2415,6 @@ run_simulations(void) dup_print("End of simulation.", TRUE); output_flush(); error_flush(); -#ifdef PHREEQ98 - } /* if (!phreeq98_debug) */ -#endif } } catch (const PhreeqcStop&) diff --git a/model.cpp b/model.cpp index bd64386f..b81439f0 100644 --- a/model.cpp +++ b/model.cpp @@ -259,26 +259,6 @@ model(void) return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -adjust_step_size(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Step sizes are cut down if overflow occurs in molalities - */ - pe_step_size_now -= (pe_step_size_now - 1.0) / 2.0; - step_size_now -= (step_size_now - 1.) / 2.0; - if (pe_step_size_now < 1.5) - pe_step_size_now = 1.5; - if (step_size_now < 1.5) - step_size_now = 1.5; - log_msg(sformatf( "\tNew step sizes: %f\t%f\t%d\n", - step_size_now, pe_step_size_now, iterations)); - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: check_residuals(void) @@ -2573,217 +2553,7 @@ molalities(int allow_overflow) return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -molalities(int allow_overflow) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates la for master species - * Calculates lm and moles from lk, lg, and la's of master species - * Adjusts lm of h2 and o2. - */ - int i, j; - LDBLE total_g; - struct rxn_token *rxn_ptr; -/* - * la for master species - */ - for (i = 0; i < count_master; i++) - { - if (master[i]->in == REWRITE) - { - master[i]->s->la = master[i]->s->lm + master[i]->s->lg; - } - } - if (dl_type_x != cxxSurface::NO_DL) - { - s_h2o->tot_g_moles = s_h2o->moles; - s_h2o->tot_dh2o_moles = 0.0; - } - for (i = 0; i < count_s_x; i++) - { - if (s_x[i]->type > HPLUS && s_x[i]->type != EX - && s_x[i]->type != SURF) - continue; -/* - * lm and moles for all aqueous species - */ - s_x[i]->lm = s_x[i]->lk - s_x[i]->lg; - for (rxn_ptr = s_x[i]->rxn_x->token + 1; rxn_ptr->s != NULL; - rxn_ptr++) - { - s_x[i]->lm += rxn_ptr->s->la * rxn_ptr->coef; - /* - if (isnan(rxn_ptr->s->la)) - { - fprintf(stderr,"molalities la %s %e\n", rxn_ptr->s->name, rxn_ptr->s->la); - } - */ - } - if (s_x[i]->type == EX) - { - s_x[i]->moles = Utilities::safe_exp(s_x[i]->lm * LOG_10); - } - else if (s_x[i]->type == SURF) - { - s_x[i]->moles = Utilities::safe_exp(s_x[i]->lm * LOG_10); - - } - else - { - s_x[i]->moles = under(s_x[i]->lm) * mass_water_aq_x; - if (s_x[i]->moles / mass_water_aq_x > 100) - { - log_msg(sformatf( "Overflow: %s\t%e\t%e\t%d\n", - s_x[i]->name, - (double) (s_x[i]->moles / mass_water_aq_x), - (double) s_x[i]->lm, iterations)); - - if (iterations >= 0 && allow_overflow == FALSE) - { - return (ERROR); - } - } - - } - } -/* - * other terms for diffuse layer model - */ - if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC - && dl_type_x != cxxSurface::NO_DL) - calc_all_donnan(); - - for (i = 0; i < count_s_x; i++) - { - if (s_x[i]->type > HPLUS && s_x[i]->type != EX - && s_x[i]->type != SURF) - continue; - if (use.Get_surface_ptr() != NULL && dl_type_x != cxxSurface::NO_DL - && s_x[i]->type <= HPLUS) - { - total_g = 0.0; - s_x[i]->tot_dh2o_moles = 0.0; - for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) - { - int is = s_x[i]->number; - cxxSurfaceCharge & charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; -/* - * partially corrected formulation assumes mass of water in diffuse layer - * is insignificant. Excess is calculated on the basis of moles_water_aq_x - * instead of moles_water_bulk. - */ - /* revised eq. 61 */ - s_diff_layer[is][charge_ref.Get_name()].Set_g_moles(s_x[i]->moles * s_x[i]->erm_ddl * - (charge_ref.Get_g_map()[s_x[i]->z].Get_g() + - charge_ref.Get_mass_water() / - mass_water_aq_x)); - if (s_x[i]->moles > 1e-30) - { - s_diff_layer[is][charge_ref.Get_name()].Set_dg_g_moles(s_x[i]->dg * s_diff_layer[is][charge_ref.Get_name()].Get_g_moles() / - s_x[i]->moles); - } - - /* - * first term of 63 is summed for all surfaces in - * s_x[i]->tot_g_moles. This sum is then used in - * the jacobian for species i - */ - total_g += - charge_ref.Get_g_map()[s_x[i]->z].Get_g() + - charge_ref.Get_mass_water() / - mass_water_aq_x; - /* revised eq. 63, second term */ - /* g.dg is dg/dx(-2y**2) or dg/d(ln y) */ - s_diff_layer[is][charge_ref.Get_name()].Set_dx_moles( - s_x[i]->moles * s_x[i]->erm_ddl * - charge_ref.Get_g_map()[s_x[i]->z].Get_dg()); - /* revised eq. 63, third term */ - s_diff_layer[is][charge_ref.Get_name()].Set_dh2o_moles( - -s_x[i]->moles * s_x[i]->erm_ddl * - charge_ref.Get_mass_water() / - mass_water_aq_x); - s_x[i]->tot_dh2o_moles += s_diff_layer[is][charge_ref.Get_name()].Get_dh2o_moles(); - - /* surface related to phase */ - s_diff_layer[is][charge_ref.Get_name()].Set_drelated_moles( - s_x[i]->moles * s_x[i]->erm_ddl * - charge_ref.Get_specific_area() * - use.Get_surface_ptr()->Get_thickness() / mass_water_aq_x); - } - s_x[i]->tot_g_moles = - s_x[i]->moles * (1 + total_g /* s_x[i]->erm_ddl */ ); - - /* note that dg is for cb, act water, mu eqns */ - /* dg_total_g for mole balance eqns */ - /* dg_g_moles for surface cb */ - - if (s_x[i]->moles > 1e-30) - { - s_x[i]->dg_total_g = - s_x[i]->dg * s_x[i]->tot_g_moles / s_x[i]->moles; - } - else - { - s_x[i]->dg_total_g = 0.0; - } - if (debug_diffuse_layer == TRUE) - { - output_msg(sformatf( "%s\t%e\t%e\n", s_x[i]->name, - (double) s_x[i]->moles, - (double) s_x[i]->tot_g_moles)); - output_msg(sformatf( "\tg\n")); - for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) - { - cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; - output_msg(sformatf( "\t%e", - (double) charge_ref.Get_g_map()[s_x[i]->z].Get_g())); - } - output_msg(sformatf( "\n\tg_moles\n")); - for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) - { - cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; - int is = s_x[i]->number; - output_msg(sformatf( "\t%e", - (double) s_diff_layer[is][charge_ref.Get_name()].Get_g_moles())); - } - output_msg(sformatf( "\n\tdg\n")); - for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) - { - cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; - output_msg(sformatf( "\t%e", - (double) charge_ref.Get_g_map()[s_x[i]->z].Get_dg())); - } - output_msg(sformatf( "\n\tdx_moles\n")); - for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) - { - int is = s_x[i]->number; - cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; - output_msg(sformatf( "\t%e", - (double) s_diff_layer[is][charge_ref.Get_name()].Get_dx_moles())); - } - output_msg(sformatf( "\n\tdh2o_moles\t%e\n", - (double) s_x[i]->tot_dh2o_moles)); - for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) - { - cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; - int is = s_x[i]->number; - output_msg(sformatf( "\t%e", - s_diff_layer[is][charge_ref.Get_name()].Get_dh2o_moles())); - } - output_msg(sformatf( "\n")); - } - } - } - calc_gas_pressures(); - calc_ss_fractions(); - - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_gas_pressures(void) @@ -5030,10 +4800,7 @@ revise_guesses(void) { repeat = TRUE; d = 0; -#ifdef SKIP - d = weight * log10(fabs(x[i]->moles / x[i]->sum)); - double d1 = d; -#else + // avoid underflows and overflows if (x[i]->moles > 1e101 || x[i]->moles < 1e-101 || x[i]->sum > 1e101 || x[i]->sum < 1e-101) @@ -5072,7 +4839,6 @@ revise_guesses(void) { x[i]->master[0]->s->la += 5.0; } -#endif } if (debug_set == TRUE) { diff --git a/prep.cpp b/prep.cpp index f4e2f3a6..a081e720 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1888,37 +1888,6 @@ clear(void) * Free arrays used in model */ free_model_allocs(); -#ifdef SKIP - // Bug-fix - // The standard implementation of clear() sets the unknown pointer of some of the - // masters to NULL. However, the function quick_setup presumes that a master pointer - // is valid when the masters total is larger than zero. This results in a crash - // when the unknown pointer is dereferenced. The same goes for the secondary master - // species. - // - // Perhaps this should be part of the 'Clear master species solution-dependent data'-loop above?! - for ( int i = 0; i < count_master; i++ ) - { - if (master[i]->s->type == SURF_PSI) - continue; - - if ( master[i]->s == s_eminus || - master[i]->s == s_hplus || - master[i]->s == s_h2o || - master[i]->s == s_h2 || - master[i]->s == s_o2 ) - continue; - - if (master[i]->total > 0 ) - { - // Make sure masters total is set to zero when unknown pointer for master species is not set - if ( ( master[i]->s->secondary && !master[i]->s->secondary->unknown ) || !master[i]->unknown ) - { - master[i]->total = 0.0; - } - } - } -#endif return (OK); } /* ---------------------------------------------------------------------- */ diff --git a/read.cpp b/read.cpp index 6b7843b3..6e2bd653 100644 --- a/read.cpp +++ b/read.cpp @@ -802,22 +802,6 @@ read_exchange_species(void) trxn.token[0].s->o = next_elt->coef; } } -#ifdef SKIP - // Need to do this in tidy species in case X- is not first species read. -/* - * Find valence of cation from coefficients of reaction components - * Changed to be coefficient of exchanger - */ - exchange_coef = 0.0; - for (i = 1; i < count_trxn; i++) - { - if (trxn.token[i].s->type == EX) - { - exchange_coef = trxn.token[i].coef; - } - } - trxn.token[0].s->equiv = exchange_coef; -#endif /* * Malloc space for species reaction */ @@ -967,7 +951,7 @@ read_exchange(void) if (i == DIGIT) { int n_solution; - sscanf(token.c_str(), "%d", &n_solution); + (void)sscanf(token.c_str(), "%d", &n_solution); temp_exchange.Set_n_solution(n_solution); temp_exchange.Set_new_def(true); temp_exchange.Set_solution_equilibria(true); @@ -1045,7 +1029,7 @@ read_exchange(void) break; } LDBLE p; - sscanf(token1.c_str(), SCANFORMAT, &p); + (void)sscanf(token1.c_str(), SCANFORMAT, &p); comp_ptr->Set_phase_proportion(p); } /* @@ -1090,7 +1074,7 @@ read_exchange(void) break; } LDBLE p; - sscanf(token1.c_str(), SCANFORMAT, &p); + (void)sscanf(token1.c_str(), SCANFORMAT, &p); comp_ptr->Set_phase_proportion(p); /* real conc must be defined in tidy_model */ conc = 1.0; @@ -1323,11 +1307,11 @@ read_gas_phase(void) error_msg(line_save, CONTINUE); break; case 0: /* pressure */ - sscanf(next_char, SCANFORMAT, &dummy); + (void)sscanf(next_char, SCANFORMAT, &dummy); temp_gas_phase.Set_total_p(dummy); break; case 1: /* Volume */ - sscanf(next_char, SCANFORMAT, &dummy); + (void)sscanf(next_char, SCANFORMAT, &dummy); temp_gas_phase.Set_volume(dummy); break; case 2: /* Temperature */ @@ -1355,7 +1339,7 @@ read_gas_phase(void) i = copy_token(token, &next_char, &l); if (i == DIGIT) { - sscanf(token, "%d", &l); + (void)sscanf(token, "%d", &l); temp_gas_phase.Set_n_solution(l); temp_gas_phase.Set_new_def(true); temp_gas_phase.Set_solution_equilibria(true); @@ -1946,7 +1930,7 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) input_error++; break; } - sscanf(token, SCANFORMAT, &dummy); + (void)sscanf(token, SCANFORMAT, &dummy); temp_isotope.Set_ratio(dummy); /* read and store isotope ratio uncertainty */ @@ -1960,7 +1944,7 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) error_msg(error_string, CONTINUE); continue; } - sscanf(token, SCANFORMAT, &dummy); + (void)sscanf(token, SCANFORMAT, &dummy); temp_isotope.Set_ratio_uncertainty(dummy); temp_isotope.Set_ratio_uncertainty_defined(true); isotopes.push_back(temp_isotope); @@ -2354,7 +2338,7 @@ read_kinetics(void) case 6: /* step_divide */ if (copy_token(token, &next_char) == DIGIT) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_kinetics.Set_step_divide(dummy); } else @@ -3146,8 +3130,7 @@ read_millero_abcdef (char *ptr, LDBLE * abcdef) { abcdef[j] = 0.0; } - j = - sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + j = sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, &(abcdef[0]), &(abcdef[1]), &(abcdef[2]), &(abcdef[3]), &(abcdef[4]), &(abcdef[5]), &(abcdef[6])); if (j < 1) { @@ -3173,8 +3156,7 @@ read_viscosity_parms(char *ptr, LDBLE * Jones_Dole) { Jones_Dole[j] = 0.0; } - j = - sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + j = sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, &(Jones_Dole[0]), &(Jones_Dole[1]), &(Jones_Dole[2]), &(Jones_Dole[3]), &(Jones_Dole[4]), &(Jones_Dole[5]), &(Jones_Dole[6]), &(Jones_Dole[7]), &(Jones_Dole[8]), &(Jones_Dole[9])); if (j < 1) { @@ -3363,7 +3345,7 @@ read_master_species(void) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - sscanf(token, SCANFORMAT, &master[count_master-1]->gfw); + (void)sscanf(token, SCANFORMAT, &master[count_master-1]->gfw); } else if (i == UPPER) { @@ -3399,7 +3381,7 @@ read_master_species(void) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - sscanf(token, SCANFORMAT, &elts_ptr->gfw); + (void)sscanf(token, SCANFORMAT, &elts_ptr->gfw); } else { @@ -3490,7 +3472,7 @@ read_mix(void) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - sscanf(token, "%d ", &n_solution); + (void)sscanf(token, "%d ", &n_solution); } else { @@ -3577,7 +3559,7 @@ read_entity_mix(std::map &mix_map) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - sscanf(token, "%d ", &n_solution); + (void)sscanf(token, "%d ", &n_solution); } else { @@ -3613,112 +3595,6 @@ read_entity_mix(std::map &mix_map) mix_map[temp_mix.Get_n_user()] = temp_mix; return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_solution_mix(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads mixing fractions - */ - int n_user, n_user_end; - int return_value; - int n_solution; - LDBLE fraction; - int j, i, l; - char *ptr; - char token[MAX_LENGTH]; - char *description; - cxxMix temp_mix; - -/* - * Read mix number - */ - ptr = line; - read_number_description(ptr, &n_user, &n_user_end, &description); - - temp_mix.Set_n_user(n_user); - temp_mix.Set_n_user_end(n_user_end); - temp_mix.Set_description(description); - free_check_null(description); -#ifdef SKIP -/* - * Set use data to first read - */ - if (use.Get_mix_in() == FALSE) - { - use.Set_mix_in(true); - use.Set_n_mix_user(n_user); - } -#endif -/* - * Read mixture data - */ - for (;;) - { - return_value = check_line("Mix raw data", FALSE, TRUE, TRUE, TRUE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - { - break; - } - ptr = line; -/* - * Read n_user - */ - i = copy_token(token, &ptr, &l); - if (i == DIGIT) - { - sscanf(token, "%d ", &n_solution); - } - else - { - input_error++; - error_msg("Expected a solution number in mix_raw input.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } -/* - * Read fraction for solution - */ - copy_token(token, &ptr, &l); - j = sscanf(token, SCANFORMAT, &fraction); - if (j != 1) - { - input_error++; - error_msg("Expected a mixing fraction.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } - -/* - * Save data - */ - temp_mix.Add(n_solution ,fraction); - } - if (temp_mix.Get_mixComps().size() == 0) - { - input_error++; - error_msg - ("Must define at least one solution number and mixing fraction for MIX_RAW input.", - CONTINUE); - } - Rxn_solution_mix_map[n_user] = temp_mix; -#ifdef SKIP - // copy if needed - if (n_user_end > n_user) - { - int i; - for (i = n_user + 1; i <= n_user_end; i++) - { - Utilities::Rxn_copy(Rxn_mix_map, n_user, i); - } - } -#endif - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_number_description(char *ptr, int *n_user, @@ -5190,465 +5066,6 @@ read_selected_output(void) return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_selected_output(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read data for to output to flat file - */ - int value; - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "file", /* 0 */ - "totals", /* 1 */ - "molalities", /* 2 */ - "activities", /* 3 */ - "pure_phases", /* 4 */ - "si", /* 5 */ - "saturation_indices", /* 6 */ - "gases", /* 7 */ - "equilibrium_phases", /* 8 */ - "equilibria", /* 9 */ - "equilibrium", /* 10 */ - "pure", /* 11 */ - "inverse", /* 12 */ - "kinetic_reactants", /* 13 */ - "kinetics", /* 14 */ - "solid_solutions", /* 15 */ - "inverse_modeling", /* 16 */ - "reset", /* 17 */ - "simulation", /* 18 */ - "sim", /* 19 */ - "state", /* 20 */ - "solution", /* 21 */ - "soln", /* 22 */ - "distance", /* 23 */ - "dist", /* 24 */ - "time", /* 25 */ - "step", /* 26 */ - "reaction", /* 27 */ - "rxn", /* 28 */ - "temperature", /* 29 */ - "temp", /* 30 */ - "ph", /* 31 */ - "pe", /* 32 */ - "alkalinity", /* 33 */ - "alk", /* 34 */ - "ionic_strength", /* 35 */ - "mu", /* 36 */ - "water", /* 37 */ - "high_precision", /* 38 */ - "user_punch", /* 39 */ - "mol", /* 40 */ - "kin", /* 41 */ - "charge_balance", /* 42 */ - "percent_error", /* 43 */ - "selected_out", /* 44 */ - "selected_output", /* 45 */ - "isotopes", /* 46 */ - "calculate_values", /* 47 */ - "equilibrium_phase" /* 48 */ - }; - int count_opt_list = 49; - - int i, l; - char file_name[MAX_LENGTH], token[MAX_LENGTH]; - - punch.in = TRUE; - punch.new_def = TRUE; - punch.count_totals = 0; - punch.count_molalities = 0; - punch.count_activities = 0; - punch.count_pure_phases = 0; - punch.count_si = 0; - punch.count_gases = 0; - punch.count_kinetics = 0; - punch.count_s_s = 0; -/* - * Read eqn from file and call parser - */ - opt_save = OPTION_ERROR; - return_value = UNKNOWN; - for (;;) - { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) - { - opt = opt_save; - } - opt_save = opt; - switch (opt) - { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_DEFAULT: - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SELECTED_OUTPUT keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* file name */ - /* copy_token(file_name, &next_char, &l); */ - if (string_trim(next_char) != EMPTY) - { - strcpy(file_name, next_char); - have_punch_name = TRUE; - punch_close(); - if (!punch_open(file_name)) - { - error_string = sformatf( "Can`t open file, %s.", file_name); - input_error++; - error_msg(error_string, CONTINUE); - } - selected_output_file_name = (char*)free_check_null(selected_output_file_name); - selected_output_file_name = string_duplicate(file_name); - } - opt_save = OPTION_ERROR; - break; - case 1: /* totals */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - if (i != UPPER && token[0] != '[') - { - error_string = sformatf( "Expected element name to" - " begin with upper case letter."); - warning_msg(error_string); - } - else - { - punch.count_totals++; - punch.totals = - (struct name_master *) PHRQ_realloc(punch.totals, - (size_t) punch. - count_totals * - sizeof(struct - name_master)); - if (punch.totals == NULL) - malloc_error(); - punch.totals[punch.count_totals - 1].name = - string_hsave(token); - } - } - break; - case 2: /* molalities */ - case 40: /* mol */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - if (i != UPPER && token[0] != '(' && (token[0] != '[')) - { - error_string = sformatf( "Expected species name to" - " begin with upper case letter."); - warning_msg(error_string); - } - else - { - punch.count_molalities++; - punch.molalities = - (struct name_species *) PHRQ_realloc(punch. - molalities, - (size_t) punch. - count_molalities - * - sizeof(struct - name_species)); - if (punch.molalities == NULL) - malloc_error(); - punch.molalities[punch.count_molalities - 1].name = - string_hsave(token); - } - } - break; - case 3: /* activities */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - if (i != UPPER && token[0] != '(' && (token[0] != '[')) - { - error_string = sformatf( "Expected species name to" - " begin with upper case letter."); - warning_msg(error_string); - } - else - { - punch.count_activities++; - punch.activities = - (struct name_species *) PHRQ_realloc(punch. - activities, - (size_t) punch. - count_activities - * - sizeof(struct - name_species)); - if (punch.activities == NULL) - malloc_error(); - punch.activities[punch.count_activities - 1].name = - string_hsave(token); - } - } - break; - case 4: /* pure_phases */ - case 8: /* equilibrium_phases */ - case 9: /* equilibria */ - case 10: /* equilibrium */ - case 11: /* pure */ - case 48: /* equilibrium_phase */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - punch.count_pure_phases++; - punch.pure_phases = - (struct name_phase *) PHRQ_realloc(punch.pure_phases, - (size_t) punch. - count_pure_phases * - sizeof(struct - name_phase)); - if (punch.pure_phases == NULL) - malloc_error(); - punch.pure_phases[punch.count_pure_phases - 1].name = - string_hsave(token); - } - break; - case 5: /* si */ - case 6: /* saturation_index */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - punch.count_si++; - punch.si = - (struct name_phase *) PHRQ_realloc(punch.si, - (size_t) punch. - count_si * - sizeof(struct - name_phase)); - if (punch.si == NULL) - malloc_error(); - punch.si[punch.count_si - 1].name = string_hsave(token); - } - break; - case 7: /* gases */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - punch.count_gases++; - punch.gases = - (struct name_phase *) PHRQ_realloc(punch.gases, - (size_t) punch. - count_gases * - sizeof(struct - name_phase)); - if (punch.gases == NULL) - malloc_error(); - punch.gases[punch.count_gases - 1].name = string_hsave(token); - } - break; - case 12: /* inverse */ - case 16: /* inverse_modeling */ - punch.inverse = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 13: /* kinetic_reactants */ - case 14: /* kinetics */ - case 41: /* kin */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - punch.count_kinetics++; - punch.kinetics = - (struct name_phase *) PHRQ_realloc(punch.kinetics, - (size_t) punch. - count_kinetics * - sizeof(struct - name_phase)); - if (punch.kinetics == NULL) - malloc_error(); - punch.kinetics[punch.count_kinetics - 1].name = - string_hsave(token); - } - break; - case 15: /* solid_solutions */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - punch.count_s_s++; - punch.s_s = - (struct name_phase *) PHRQ_realloc(punch.s_s, - (size_t) punch. - count_s_s * - sizeof(struct - name_phase)); - if (punch.s_s == NULL) - malloc_error(); - punch.s_s[punch.count_s_s - 1].name = string_hsave(token); - } - break; - case 46: /* isotopes */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - if (i != UPPER && token[0] != '[') - { - error_string = sformatf( "Expected element name to" - " begin with upper case letter."); - warning_msg(error_string); - } - else - { - punch.count_isotopes++; - punch.isotopes = - (struct name_master *) PHRQ_realloc(punch.isotopes, - (size_t) punch. - count_isotopes * - sizeof(struct - name_master)); - if (punch.isotopes == NULL) - malloc_error(); - punch.isotopes[punch.count_isotopes - 1].name = - string_hsave(token); - } - } - break; - case 47: /* calculate_values */ - while ((i = copy_token(token, &next_char, &l)) != EMPTY) - { - punch.count_calculate_values++; - punch.calculate_values = - (struct name_master *) PHRQ_realloc(punch. - calculate_values, - (size_t) punch. - count_calculate_values - * - sizeof(struct - name_master)); - if (punch.calculate_values == NULL) - malloc_error(); - punch.calculate_values[punch.count_calculate_values - - 1].name = string_hsave(token); - } - break; - case 17: /* reset */ - value = get_true_false(next_char, TRUE); - /* matches print order */ - punch.sim = value; - punch.state = value; - punch.soln = value; - punch.dist = value; - punch.time = value; - punch.step = value; - punch.ph = value; - punch.pe = value; - punch.rxn = value; - punch.temp = value; - punch.alk = value; - punch.mu = value; - punch.water = value; - punch.charge_balance = value; - punch.percent_error = value; - opt_save = OPTION_ERROR; - break; - case 18: /* simulation */ - case 19: /* sim */ - punch.sim = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 20: /* state */ - punch.state = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 21: /* solution */ - case 22: /* soln */ - punch.soln = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 23: /* distance */ - case 24: /* dist */ - punch.dist = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 25: /* time */ - punch.time = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 26: /* step */ - punch.step = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 27: /* reaction */ - case 28: /* rxn */ - punch.rxn = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 29: /* temperature */ - case 30: /* temp */ - punch.temp = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 31: /* ph */ - punch.ph = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 32: /* pe */ - punch.pe = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 33: /* alkalinity */ - case 34: /* alk */ - punch.alk = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 35: /* ionic strength */ - case 36: /* mu */ - punch.mu = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 37: /* water */ - punch.water = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 38: /* high_precision */ - punch.high_precision = get_true_false(next_char, TRUE); - if (punch.high_precision == TRUE /*&& convergence_tolerance > 1e-12*/) - { - convergence_tolerance = 1e-12; - } - opt_save = OPTION_ERROR; - break; - case 39: /* user_punch */ - punch.user_punch = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 42: /* charge_balance */ - punch.charge_balance = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 43: /* percent_error */ - punch.percent_error = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - case 44: /* selected_out */ - case 45: /* selected_output */ - warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output"); - pr.punch = get_true_false(next_char, TRUE); - opt_save = OPTION_ERROR; - break; - } - if (return_value == EOF || return_value == KEYWORD) - break; - } - if (!have_punch_name) - { - punch_close(); - if (!punch_open("selected.out")) - { - error_string = sformatf( "Can`t open file, %s.", "selected.out"); - input_error++; - error_msg(error_string, CONTINUE); - } - } - - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_solution(void) @@ -5893,7 +5310,7 @@ read_solution(void) error_msg(error_string, CONTINUE); continue; } - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_isotope.Set_ratio(dummy); temp_isotope.Set_ratio_uncertainty(NAN); @@ -5909,7 +5326,7 @@ read_solution(void) error_msg(error_string, PHRQ_io::OT_CONTINUE); continue; } - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_isotope.Set_ratio_uncertainty(dummy); temp_isotope.Set_ratio_uncertainty_defined(true); } @@ -5932,7 +5349,7 @@ read_solution(void) } else { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_solution.Set_mass_water(dummy); } } @@ -6615,7 +6032,7 @@ read_use(void) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - sscanf(token, "%d", &n_user); + (void)sscanf(token, "%d", &n_user); if (n_user < 0) { error_msg("Number must be a positive integer.", CONTINUE); @@ -7159,22 +6576,6 @@ read_surface_species(void) trxn.token[0].s->o = next_elt->coef; } } -#ifdef SKIP - // need to do this in tidy in case surface master species not yet defined - /* - * Find coefficient of surface in rxn, store in equiv - */ - trxn.token[0].s->equiv = 0.0; - for (i = 1; i < count_trxn; i++) - { - if (trxn.token[i].s->type == SURF) - { - trxn.token[0].s->equiv = trxn.token[i].coef; - } - } - if (trxn.token[0].s->equiv == 0.0) - trxn.token[0].s->equiv = 1.0; -#endif /* * Malloc space for species reaction */ @@ -7308,7 +6709,7 @@ read_surface(void) if (i == DIGIT) { int j; - sscanf(token.c_str(), "%d", &j); + (void)sscanf(token.c_str(), "%d", &j); temp_surface.Set_solution_equilibria(true); temp_surface.Set_n_solution(j); break; @@ -7352,7 +6753,7 @@ read_surface(void) int i = copy_token(token, &next_char); if (i == DIGIT) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_surface.Set_thickness(dummy); thickness = 1; continue; @@ -7373,7 +6774,7 @@ read_surface(void) int j = copy_token(token1, &next_char); if (j == DIGIT) { - sscanf(token1.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token1.c_str(), SCANFORMAT, &dummy); temp_surface.Set_debye_lengths(dummy); continue; } @@ -7392,7 +6793,7 @@ read_surface(void) int j = copy_token(token1, &next_char); if (j == DIGIT) { - sscanf(token1.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token1.c_str(), SCANFORMAT, &dummy); temp_surface.Set_DDL_viscosity(dummy); continue; } @@ -7411,7 +6812,7 @@ read_surface(void) int j = copy_token(token1, &next_char); if (j == DIGIT) { - sscanf(token1.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token1.c_str(), SCANFORMAT, &dummy); temp_surface.Set_DDL_limit(dummy); continue; } @@ -7603,7 +7004,7 @@ read_surface(void) input_error++; break; } - sscanf(token1.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token1.c_str(), SCANFORMAT, &dummy); comp_ptr->Set_phase_proportion(dummy); /* real conc must be defined in tidy_model */ conc = 1.0; @@ -7703,7 +7104,7 @@ read_surface(void) } else { - sscanf(token1.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token1.c_str(), SCANFORMAT, &dummy); comp_ptr->Set_Dw(dummy); if (dummy > 0) { @@ -8189,11 +7590,11 @@ read_advection(void) error_msg(line_save, CONTINUE); break; case 0: /* cells */ - sscanf(next_char, "%d", &count_ad_cells); + (void)sscanf(next_char, "%d", &count_ad_cells); opt_save = OPTION_DEFAULT; break; case 1: /* shifts */ - sscanf(next_char, "%d", &count_ad_shifts); + (void)sscanf(next_char, "%d", &count_ad_shifts); opt_save = OPTION_DEFAULT; break; case 2: /* print */ @@ -8206,7 +7607,7 @@ read_advection(void) case 3: /* selected_output */ case 11: /* selected_output_frequency */ case 12: /* punch_frequency */ - sscanf(next_char, "%d", &punch_ad_modulus); + (void)sscanf(next_char, "%d", &punch_ad_modulus); opt_save = OPTION_DEFAULT; if (punch_ad_modulus <= 0) { @@ -8226,7 +7627,7 @@ read_advection(void) break; case 7: /* time_step */ case 8: /* timest */ - sscanf(next_char, SCANFORMAT, &advection_kin_time); + (void)sscanf(next_char, SCANFORMAT, &advection_kin_time); { std::string token; int j = copy_token(token, &next_char); @@ -8242,7 +7643,7 @@ read_advection(void) case 9: /* output */ case 10: /* output_frequency */ case 13: /* print_frequency */ - sscanf(next_char, "%d", &print_ad_modulus); + (void)sscanf(next_char, "%d", &print_ad_modulus); opt_save = OPTION_DEFAULT; if (print_ad_modulus <= 0) { @@ -8256,7 +7657,7 @@ read_advection(void) char token[MAX_LENGTH]; int j; if (copy_token(token, &next_char, &j) == DIGIT) - sscanf(token, SCANFORMAT, &initial_total_time); + (void)sscanf(token, SCANFORMAT, &initial_total_time); { std::string stdtoken; j = copy_token(stdtoken, &next_char); @@ -8419,19 +7820,19 @@ read_debug(void) error_msg(line_save, CONTINUE); break; case 0: /* iterations */ - sscanf(next_char, "%d", &itmax); + (void)sscanf(next_char, "%d", &itmax); break; case 1: /* tolerance */ - sscanf(next_char, SCANFORMAT, &ineq_tol); + (void)sscanf(next_char, SCANFORMAT, &ineq_tol); break; case 2: /* step_size */ - sscanf(next_char, SCANFORMAT, &step_size); + (void)sscanf(next_char, SCANFORMAT, &step_size); break; case 3: /* pe_step_size */ - sscanf(next_char, SCANFORMAT, &pe_step_size); + (void)sscanf(next_char, SCANFORMAT, &pe_step_size); break; case 4: /* pp_scale */ - sscanf(next_char, SCANFORMAT, &pp_scale); + (void)sscanf(next_char, SCANFORMAT, &pp_scale); break; case 5: /* diagonal_scale */ diagonal_scale = get_true_false(next_char, TRUE); @@ -8467,7 +7868,7 @@ read_debug(void) case 14: /* convergence_tolerance */ { LDBLE ct; - sscanf(next_char, SCANFORMAT, &ct); + (void)sscanf(next_char, SCANFORMAT, &ct); convergence_tolerance = ct; } break; @@ -8476,7 +7877,7 @@ read_debug(void) break; case 16: /* tries */ case 17: /* try */ - sscanf(next_char, "%d", &max_tries); + (void)sscanf(next_char, "%d", &max_tries); break; case 18: /* debug_inverse */ numerical_fixed_volume = (get_true_false(next_char, TRUE) == TRUE); @@ -8485,11 +7886,11 @@ read_debug(void) force_numerical_fixed_volume = (get_true_false(next_char, TRUE) == TRUE); break; case 20: /* equi_delay */ - sscanf(next_char, "%d", &equi_delay); + (void)sscanf(next_char, "%d", &equi_delay); break; case 21: /* minimum_total */ case 22: /* min_total */ - sscanf(next_char, SCANFORMAT, &MIN_TOTAL); + (void)sscanf(next_char, SCANFORMAT, &MIN_TOTAL); MIN_TOTAL_SS = MIN_TOTAL/100; MIN_RELATED_SURFACE = MIN_TOTAL*100; break; @@ -8720,7 +8121,7 @@ read_print(void) break; case 32: /* warning */ case 33: /* warnings */ - sscanf(next_char, "%d", &pr.warnings); + (void)sscanf(next_char, "%d", &pr.warnings); break; case 34: /* initial_isotopes */ pr.initial_isotopes = get_true_false(next_char, TRUE); @@ -8734,7 +8135,7 @@ read_print(void) case 37: /* censor_species */ if (copy_token(token, &next_char, &l) != EMPTY) { - sscanf(token, SCANFORMAT, &censor); + (void)sscanf(token, SCANFORMAT, &censor); } else { @@ -8957,166 +8358,6 @@ check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, } return (ERROR); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -check_units(char *tot_units, int alkalinity, int check_compatibility, - const char *default_units, int print) -/* ---------------------------------------------------------------------- */ -{ -#define NUNITS (sizeof(units) / sizeof(char *)) -/* - * Check if legitimate units - * Input: - * tot_units character string to check, - * alkalinity TRUE if alkalinity, FALSE if any other total, - * check_compatibility TRUE check alk and default units, FALSE otherwise - * default_units character string of default units (check /L, /kg, etc) - * print TRUE print warning messages - * Output: - * tot_units standard form for unit - */ - int i, found; - char *end; - char string[MAX_LENGTH]; - const char *units[] = { - "Mol/l", /* 0 */ - "mMol/l", /* 1 */ - "uMol/l", /* 2 */ - "g/l", /* 3 */ - "mg/l", /* 4 */ - "ug/l", /* 5 */ - "Mol/kgs", /* 6 */ - "mMol/kgs", /* 7 */ - "uMol/kgs", /* 8 */ - "g/kgs", /* 9 = ppt */ - "mg/kgs", /* 10 = ppm */ - "ug/kgs", /* 11 = ppb */ - "Mol/kgw", /* 12 = mol/kg H2O */ - "mMol/kgw", /* 13 = mmol/kg H2O */ - "uMol/kgw", /* 14 = umol/kg H2O */ - "g/kgw", /* 15 = mol/kg H2O */ - "mg/kgw", /* 16 = mmol/kg H2O */ - "ug/kgw", /* 17 = umol/kg H2O */ - "eq/l", /* 18 */ - "meq/l", /* 19 */ - "ueq/l", /* 20 */ - "eq/kgs", /* 21 */ - "meq/kgs", /* 22 */ - "ueq/kgs", /* 23 */ - "eq/kgw", /* 24 */ - "meq/kgw", /* 25 */ - "ueq/kgw", /* 26 */ - }; - - squeeze_white(tot_units); - str_tolower(tot_units); - replace("milli", "m", tot_units); - replace("micro", "u", tot_units); - replace("grams", "g", tot_units); - replace("gram", "g", tot_units); - replace("moles", "Mol", tot_units); - replace("mole", "Mol", tot_units); - replace("mol", "Mol", tot_units); - replace("liter", "l", tot_units); - replace("kgh", "kgw", tot_units); - replace("ppt", "g/kgs", tot_units); - replace("ppm", "mg/kgs", tot_units); - replace("ppb", "ug/kgs", tot_units); - replace("equivalents", "eq", tot_units); - replace("equivalent", "eq", tot_units); - replace("equiv", "eq", tot_units); - - if ((end = strstr(tot_units, "/l")) != NULL) - { - *(end + 2) = '\0'; - } - if ((end = strstr(tot_units, "/kgs")) != NULL) - { - *(end + 4) = '\0'; - } - if ((end = strstr(tot_units, "/kgw")) != NULL) - { - *(end + 4) = '\0'; - } -/* - * Check if unit in list - */ - found = FALSE; - for (i = 0; i < (int) NUNITS; i++) - { - if (strcmp(tot_units, units[i]) == 0) - { - found = TRUE; - break; - } - } - if (found == FALSE) - { - if (print == TRUE) - { - error_string = sformatf( "Unknown unit, %s.", tot_units); - error_msg(error_string, CONTINUE); - } - return (ERROR); - } - -/* - * Check if units are compatible with default_units - */ - if (check_compatibility == FALSE) - return (OK); -/* - * Special cases for alkalinity - */ - if (alkalinity == TRUE && strstr(tot_units, "Mol") != NULL) - { - if (print == TRUE) - { - error_string = sformatf( - "Alkalinity given in moles, assumed to be equivalents."); - warning_msg(error_string); - } - replace("Mol", "eq", tot_units); - } - if (alkalinity == FALSE && strstr(tot_units, "eq") != NULL) - { - if (print == TRUE) - { - error_msg("Only alkalinity can be entered in equivalents.", - CONTINUE); - } - return (ERROR); - } -/* - * See if default_units are compatible with tot_units - */ - if (strstr(default_units, "/l") && strstr(tot_units, "/l")) - return (OK); - if (strstr(default_units, "/kgs") && strstr(tot_units, "/kgs")) - return (OK); - if (strstr(default_units, "/kgw") && strstr(tot_units, "/kgw")) - return (OK); - - strcpy(string, default_units); - replace("kgs", "kg solution", string); - replace("kgs", "kg solution", tot_units); - replace("kgw", "kg water", string); - replace("kgw", "kg water", tot_units); - replace("/l", "/L", string); - replace("Mol", "mol", string); - replace("/l", "/L", tot_units); - replace("Mol", "mol", tot_units); - if (print == TRUE) - { - error_string = sformatf( - "Units for master species, %s, are not compatible with default units, %s.", - tot_units, string); - error_msg(error_string, CONTINUE); - } - return (ERROR); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: find_option(const char *item, int *n, const char **list, int count_list, int exact) @@ -9660,376 +8901,6 @@ read_user_punch(void) return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_user_punch(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads basic code with which to calculate rates - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int length, line_length; - int return_value, opt, opt_save; - std::string stdtoken; - char *next_char; - const char *opt_list[] = { - "start", /* 0 */ - "end", /* 1 */ - "heading", /* 2 */ - "headings" /* 3 */ - }; - int count_opt_list = 4; - - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ - user_punch_count_headings = 0; - return_value = UNKNOWN; - for (;;) - { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) - { - opt = opt_save; - } - opt_save = OPTION_DEFAULT; - switch (opt) - { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in USER_PUNCH keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* start */ - opt_save = OPTION_DEFAULT; - break; - case 1: /* end */ - opt_save = OPTION_DEFAULT; - break; - case 2: /* headings */ - case 3: /* heading */ - while (copy_token(stdtoken, &next_char) != EMPTY) - { - user_punch_headings = - (const char **) PHRQ_realloc(user_punch_headings, - (size_t) - (user_punch_count_headings + - 1) * sizeof(char *)); - if (user_punch_headings == NULL) - malloc_error(); - user_punch_headings[user_punch_count_headings] = - string_hsave(stdtoken.c_str()); - user_punch_count_headings++; - } - break; - case OPTION_DEFAULT: /* read first command */ - rate_free(user_punch); - user_punch->new_def = TRUE; - user_punch->commands = (char *) PHRQ_malloc(sizeof(char)); - if (user_punch->commands == NULL) - malloc_error(); - user_punch->commands[0] = '\0'; - user_punch->linebase = NULL; - user_punch->varbase = NULL; - user_punch->loopbase = NULL; - user_punch->name = - string_hsave("user defined Basic punch routine"); - case OPT_1: /* read command */ - length = (int) strlen(user_punch->commands); - line_length = (int) strlen(line); - user_punch->commands = - (char *) PHRQ_realloc(user_punch->commands, - (size_t) (length + line_length + - 2) * sizeof(char)); - if (user_punch->commands == NULL) - malloc_error(); - user_punch->commands[length] = ';'; - user_punch->commands[length + 1] = '\0'; - strcat((user_punch->commands), line); - opt_save = OPT_1; - break; - } - if (return_value == EOF || return_value == KEYWORD) - break; - } - return (return_value); -} -#endif -#if defined PHREEQ98 -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_user_graph(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads basic code with which to calculate rates - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int l, length, line_length, CurveInfonr = 0; - int return_value, opt, opt_save; - char file_name[MAX_LENGTH]; - char token[MAX_LENGTH]; - char *next_char; - const char *opt_list[] = { - "start", /* 0 */ - "end", /* 1 */ - "heading", /* 2 */ - "headings", /* 3 */ - "chart_title", /* 4 */ - "axis_titles", /* 5 */ - "axis_scale", /* 6 */ - "initial_solutions", /* 7 */ - "plot_concentration_vs", /* 8 */ - "shifts_as_points", /* 9 */ - "grid_offset", /* 10 */ - "connect_simulations", /* 11 */ - "plot_csv_file" /* 12 */ - "plot_tsv_file" /* 13 */ - }; - int count_opt_list = 14; - int i; - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ -#ifdef PHREEQ98 - user_graph_count_headings = 0; -#endif - return_value = UNKNOWN; - for (;;) - { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) opt = opt_save; - - switch (opt) - { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* start */ - opt_save = OPTION_DEFAULT; - break; - case 1: /* end */ - opt_save = OPTION_DEFAULT; - break; - case 2: /* headings */ - case 3: /* heading */ - while (copy_token(token, &next_char, &l) != EMPTY) - { - user_graph_headings = - (char **) PHRQ_realloc(user_graph_headings, - (size_t) (user_graph_count_headings + - 1) * sizeof(char *)); - if (user_graph_headings == NULL) - malloc_error(); - user_graph_headings[user_graph_count_headings] = - string_hsave(token); - user_graph_count_headings++; - } - break; -/*Modifications of read_user_punch to change the chart's appearance */ - case 4: /* chart title */ - copy_title(token, &next_char, &l); - SetChartTitle(token); - break; - case 5: /* axis titles */ - i = 0; - while (copy_title(token, &next_char, &l) != EMPTY) - { - SetAxisTitles(token, i); - i++; - } - break; - case 6: { /* axis scales */ - char *axis = ""; - int j = 0; - float f_min, f_max; f_min = (float) -9.999; - prev_next_char = next_char; - copy_token(token, &next_char, &l); - str_tolower(token); - if (strstr(token, "x") == token) - axis = "x"; - else if ((strstr(token, "y") == token) && (strstr(token, "y2") != token)) - axis = "y"; - else if ((strstr(token, "s") == token) || (strstr(token, "y2") == token)) - axis = "s"; - else - { - input_error++; - copy_token(token, &prev_next_char, &l); - error_string = sformatf( - "Found '%s', but expect axis type \'x\', \'y\', or \'sy\'.", token); - error_msg(error_string, CONTINUE); - } - while ((j < 4) - && (i = copy_token(token, &next_char, &l)) != EMPTY) - { - str_tolower(token); - if ((i == DIGIT) || (strstr(token, "a") == token)) - SetAxisScale(axis, j, token, FALSE); - else - { - input_error++; - copy_token(token, &prev_next_char, &l); - error_string = sformatf( - "Found '%s', but expect number or 'a(uto)'.", token); - error_msg(error_string, CONTINUE); - } - if (i == DIGIT) - { - if (j == 0) - f_min = (float) atof(token); - else if (j == 1 && fabs(f_min + 9.999) > 1e-3) - { - f_max = (float) atof(token); - if (f_min > f_max) - { - error_string = sformatf( - "Maximum must be larger than minimum of axis_scale, interchanging both for %s axis", axis); - warning_msg(error_string); - SetAxisScale(axis, 0, token, FALSE); - sprintf(token, "%e", f_min); - SetAxisScale(axis, 1, token, FALSE); - } - } - } - j++; /* counter for categories */ - prev_next_char = next_char; - } - if (j == 4) - SetAxisScale(axis, j, 0, - get_true_false(next_char, FALSE)); /* anything else than false turns on log scale */ - } - break; - case 7: - graph_initial_solutions = get_true_false(next_char, FALSE); - break; - case 8: - prev_next_char = next_char; - copy_token(token, &next_char, &l); - str_tolower(token); - if (strstr(token, "x") == token || strstr(token, "d") == token) - chart_type = 0; - else if (strstr(token, "t") == token) - chart_type = 1; - else - { - input_error++; - copy_token(token, &prev_next_char, &l); - error_string = sformatf( - "Found '%s', but expect plot type: (\'x\' or \'dist\') for distance, (\'t\') for time.", - token); - error_msg(error_string, CONTINUE); - } - break; - case 9: - shifts_as_points = get_true_false(next_char, TRUE); - if (shifts_as_points == TRUE) - chart_type = 0; - else - chart_type = 1; - break; - case 10: -#ifdef PHREEQ98 - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) - sscanf(token, "%d", &RowOffset); - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) - sscanf(token, "%d", &ColumnOffset); -#endif - break; - case 11: - connect_simulations = get_true_false(next_char, TRUE); - break; - case 12: - string_trim(next_char); - strcpy(file_name, next_char); - if (!OpenCSVFile(file_name)) - { - error_string = sformatf( "Can`t open file, %s. Give the full path + name, or copy the file to the working directory.", file_name); - input_error++; - error_msg(error_string, CONTINUE); - } - break; - /* End of modifications */ - case OPTION_DEFAULT: /* read first command */ - rate_free(user_graph); - user_graph->new_def = TRUE; - user_graph->commands = (char *) PHRQ_malloc(sizeof(char)); - if (user_graph->commands == NULL) - malloc_error(); - user_graph->commands[0] = '\0'; - user_graph->linebase = NULL; - user_graph->varbase = NULL; - user_graph->loopbase = NULL; - user_graph->name = - string_hsave("user defined Basic graph routine"); - case OPT_1: /* read command */ - length = strlen(user_graph->commands); - line_length = strlen(line); - user_graph->commands = - (char *) PHRQ_realloc(user_graph->commands, - (size_t) (length + line_length + - 2) * sizeof(char)); - if (user_graph->commands == NULL) - malloc_error(); - user_graph->commands[length] = ';'; - user_graph->commands[length + 1] = '\0'; - strcat((user_graph->commands), line); - opt_save = OPT_1; - break; - } - - if (return_value == EOF || return_value == KEYWORD) - break; - } -#ifdef PHREEQ98 - for (i = 0; i < user_graph_count_headings; i++) - { - GridHeadings(user_graph_headings[i], i); - } -#endif - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_solid_solutions(void) @@ -10168,12 +9039,12 @@ read_solid_solutions(void) ptr = next_char; if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p()[0] = dummy; } if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p()[1] = dummy; } ss_ptr->Set_input_case(cxxSS::SS_PARM_A0_A1); @@ -10187,12 +9058,12 @@ read_solid_solutions(void) ptr = next_char; if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p()[0] = dummy; } if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p()[1] = dummy; } ss_ptr->Set_input_case(cxxSS::SS_PARM_DIM_GUGG); @@ -10209,7 +9080,7 @@ read_solid_solutions(void) { if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p().push_back(dummy); } } @@ -10236,7 +9107,7 @@ read_solid_solutions(void) { if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p().push_back(dummy); } } @@ -10263,7 +9134,7 @@ read_solid_solutions(void) { if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p().push_back(dummy); } } @@ -10290,7 +9161,7 @@ read_solid_solutions(void) { if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p().push_back(dummy); } } @@ -10317,7 +9188,7 @@ read_solid_solutions(void) { if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p().push_back(dummy); } } @@ -10344,7 +9215,7 @@ read_solid_solutions(void) { if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p().push_back(dummy); } } @@ -10422,7 +9293,7 @@ read_solid_solutions(void) { if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p().push_back(dummy); } } @@ -10449,7 +9320,7 @@ read_solid_solutions(void) { if (copy_token(token, &ptr) != EMPTY) { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); ss_ptr->Get_p().push_back(dummy); } } @@ -10865,7 +9736,7 @@ read_line_doubles(char *next_char, LDBLE ** d, int *count_d, int *count_alloc) } else { - sscanf(token, SCANFORMAT, &value); + (void)sscanf(token, SCANFORMAT, &value); n = 1; } for (;;) @@ -11237,7 +10108,7 @@ read_copy(void) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - sscanf(token, "%d", &n_user); + (void)sscanf(token, "%d", &n_user); //if (n_user < 0) //{ // error_msg("Source index number must be a positive integer.", diff --git a/readtr.cpp b/readtr.cpp index e45f7a37..5a682fd1 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -177,12 +177,12 @@ read_transport(void) error_msg(line_save, CONTINUE); break; case 0: /* cells */ - sscanf(next_char, "%d", &count_cells); + (void)sscanf(next_char, "%d", &count_cells); opt_save = OPTION_DEFAULT; break; case 1: /* shifts */ if (copy_token(token, &next_char, &l) == DIGIT) - sscanf(token, "%d", &count_shifts); + (void)sscanf(token, "%d", &count_shifts); else { warning_msg @@ -193,7 +193,7 @@ read_transport(void) if (j != EMPTY) { if (j == DIGIT) - sscanf(token, "%d", &ishift); + (void)sscanf(token, "%d", &ishift); else { input_error++; @@ -215,7 +215,7 @@ read_transport(void) case 3: /* selected_output */ case 29: /* selected_output_frequency */ case 33: /* punch_frequency */ - sscanf(next_char, "%d", &punch_modulus); + (void)sscanf(next_char, "%d", &punch_modulus); opt_save = OPTION_DEFAULT; if (punch_modulus <= 0) { @@ -234,7 +234,7 @@ read_transport(void) str_tolower(token); if (i == DIGIT) { - sscanf(token, "%d", &bcon_first); + (void)sscanf(token, "%d", &bcon_first); if (bcon_first < 1 || bcon_first > 3) { input_error++; @@ -264,7 +264,7 @@ read_transport(void) str_tolower(token); if (i == DIGIT) { - sscanf(token, "%d", &bcon_last); + (void)sscanf(token, "%d", &bcon_last); if (bcon_last < 1 || bcon_last > 3) { input_error++; @@ -293,7 +293,7 @@ read_transport(void) case 5: /* timest */ case 14: /* time_step */ if (copy_token(token, &next_char, &l) == DIGIT) - sscanf(token, SCANFORMAT, ×t); + (void)sscanf(token, SCANFORMAT, ×t); { std::string stdtoken; j = copy_token(stdtoken, &next_char); @@ -304,7 +304,7 @@ read_transport(void) } if (j == DIGIT) { - sscanf(stdtoken.c_str(), SCANFORMAT, &mcd_substeps); + (void)sscanf(stdtoken.c_str(), SCANFORMAT, &mcd_substeps); } } //if (copy_token(token, &next_char, &l) == DIGIT) @@ -319,7 +319,7 @@ read_transport(void) break; case 6: /* diffc */ case 16: /* diffusion_coefficient */ - sscanf(next_char, SCANFORMAT, &diffc); + (void)sscanf(next_char, SCANFORMAT, &diffc); opt_save = OPTION_DEFAULT; break; case 7: /* tempr */ @@ -327,7 +327,7 @@ read_transport(void) case 19: /* temperature_retardation_factor */ case 39: /* thermal_diffusion */ if (copy_token(token, &next_char, &l) == DIGIT) - sscanf(token, SCANFORMAT, &tempr); + (void)sscanf(token, SCANFORMAT, &tempr); if (tempr < 1) { tempr = 1; @@ -337,7 +337,7 @@ read_transport(void) } j = copy_token(token, &next_char, &l); if (j == DIGIT) - sscanf(token, SCANFORMAT, &heat_diffc); + (void)sscanf(token, SCANFORMAT, &heat_diffc); opt_save = OPTION_DEFAULT; break; case 8: /* length */ @@ -456,7 +456,7 @@ read_transport(void) case 27: /* output */ case 28: /* output_frequency */ case 34: /* print_frequency */ - sscanf(next_char, "%d", &print_modulus); + (void)sscanf(next_char, "%d", &print_modulus); opt_save = OPTION_DEFAULT; if (print_modulus <= 0) { @@ -469,7 +469,7 @@ read_transport(void) case 31: /* dump_frequency */ dump_in = TRUE; if (copy_token(token, &next_char, &l) == DIGIT) - sscanf(token, "%d", &dump_modulus); + (void)sscanf(token, "%d", &dump_modulus); else { warning_msg("Expected integer value for dump_frequency."); @@ -480,7 +480,7 @@ read_transport(void) case 32: /* dump_restart */ dump_in = TRUE; if (copy_token(token, &next_char, &l) == DIGIT) - sscanf(token, "%d", &transport_start); + (void)sscanf(token, "%d", &transport_start); else { warning_msg @@ -495,7 +495,7 @@ read_transport(void) break; case 36: /* initial_time */ if (copy_token(token, &next_char, &l) == DIGIT) - sscanf(token, SCANFORMAT, &initial_total_time); + (void)sscanf(token, SCANFORMAT, &initial_total_time); { std::string stdtoken; j = copy_token(stdtoken, &next_char); @@ -678,7 +678,7 @@ read_transport(void) case 45: /* current */ if (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, SCANFORMAT, &fix_current); + (void)sscanf(token, SCANFORMAT, &fix_current); // fix_current = fabs(fix_current); } else @@ -704,7 +704,7 @@ read_transport(void) } if (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, SCANFORMAT, &max_mixf); + (void)sscanf(token, SCANFORMAT, &max_mixf); } else { @@ -1171,7 +1171,7 @@ read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, int *count_alloc) } else { - sscanf(token, SCANFORMAT, &value); + (void)sscanf(token, SCANFORMAT, &value); n = 1; } for (;;) diff --git a/sit.cpp b/sit.cpp index 1123e149..e636e423 100644 --- a/sit.cpp +++ b/sit.cpp @@ -287,185 +287,6 @@ calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) } return OK; } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -sit(void) -/* ---------------------------------------------------------------------- */ -{ - int i, i0, i1; - LDBLE param, z0, z1; - LDBLE A, AGAMMA, T; - /* - LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, - CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, - BMXPHI, PHIPHI, AW, A, B; - */ -/* - LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, - B; -*/ - LDBLE XI, XX, OSUM, DI, F, OSMOT, B; - LDBLE I, TK; - /* - C - C INITIALIZE - C - */ - //CONV = 1.0 / LOG_10; - XI = 0.0e0; - XX = 0.0e0; - OSUM = 0.0e0; - /*n - I = *I_X; - TK = *TK_X; - */ - I = mu_x; - TK = tk_x; - /* DH_AB(TK, &A, &B); */ - /* - C - C TRANSFER DATA FROM TO sit_M - C - */ - for (i = 0; i < 3 * count_s; i++) - { - sit_IPRSNT[i] = FALSE; - sit_M[i] = 0.0; - if (spec[i] != NULL && spec[i]->in == TRUE) - { - if (spec[i]->type == EX || - spec[i]->type == SURF || spec[i]->type == SURF_PSI) - continue; - sit_M[i] = under(spec[i]->lm); - if (sit_M[i] > MIN_TOTAL) - sit_IPRSNT[i] = TRUE; - } - } - /* - C - C COMPUTE SIT COEFFICIENTS' TEMPERATURE DEPENDENCE - C - */ - PTEMP_SIT(TK); - for (i = 0; i < 2 * count_s + sit_count_anions; i++) - { - sit_LGAMMA[i] = 0.0; - if (sit_IPRSNT[i] == TRUE) - { - XX = XX + sit_M[i] * fabs(spec[i]->z); - XI = XI + sit_M[i] * spec[i]->z * spec[i]->z; - OSUM = OSUM + sit_M[i]; - } - } - I = XI / 2.0e0; - I = mu_x; // Added equation for MU - DI = sqrt(I); - /* - C - C CALCULATE F & GAMCLM - C - */ - AGAMMA = 3*sit_A0; /* Grenthe p 379 */ - A = AGAMMA / LOG_10; - /* - * F is now for log10 gamma - */ - - B = 1.5; - F = -A * (DI / (1.0e0 + B * DI)); - - - /*OSMOT = -(sit_A0) * pow(I, 1.5e0) / (1.0e0 + B * DI);*/ - T = 1.0 + B*DI; - OSMOT = -2.0*A/(B*B*B)*(T - 2.0*log(T) - 1.0/T); - /* - * Sums for sit_LGAMMA, and OSMOT - * epsilons are tabulated for log10 gamma (not ln gamma) - */ - for (i = 0; i < count_sit_param; i++) - { - i0 = sit_params[i]->ispec[0]; - i1 = sit_params[i]->ispec[1]; - if (sit_IPRSNT[i0] == FALSE || sit_IPRSNT[i1] == FALSE) continue; - z0 = spec[i0]->z; - z1 = spec[i1]->z; - param = sit_params[i]->p; - switch (sit_params[i]->type) - { - case TYPE_SIT_EPSILON: - sit_LGAMMA[i0] += sit_M[i1] * param; - sit_LGAMMA[i1] += sit_M[i0] * param; - if (z0 == 0.0 && z1 == 0.0) - { - OSMOT += sit_M[i0] * sit_M[i1] * param / 2.0; - } - else - { - OSMOT += sit_M[i0] * sit_M[i1] * param; - } - break; - case TYPE_SIT_EPSILON_MU: - sit_LGAMMA[i0] += sit_M[i1] * I * param; - sit_LGAMMA[i1] += sit_M[i0] * I * param; - OSMOT += sit_M[i0] * sit_M[i1] * param; - if (z0 == 0.0 && z1 == 0.0) - { - OSMOT += sit_M[i0] * sit_M[i1] * param * I / 2.0; - } - else - { - OSMOT += sit_M[i0] * sit_M[i1] * param * I; - } - break; - default: - case TYPE_Other: - error_msg("TYPE_Other in pitz_param list.", STOP); - break; - } - } - - /* - * Add F and CSUM terms to sit_LGAMMA - */ - - for (i = 0; i < sit_count_cations; i++) - { - z0 = spec[i]->z; - sit_LGAMMA[i] += z0 * z0 * F; - } - for (i = 2 * count_s; i < 2 * count_s + sit_count_anions; i++) - { - z0 = spec[i]->z; - sit_LGAMMA[i] += z0 * z0 * F; - } - /* - C - C CONVERT TO MACINNES CONVENTION - C - */ - /*COSMOT = 1.0e0 + 2.0e0 * OSMOT / OSUM;*/ - COSMOT = 1.0e0 + OSMOT*LOG_10 / OSUM; - /* - C - C CALCULATE THE ACTIVITY OF WATER - C - */ - AW = exp(-OSUM * COSMOT / 55.50837e0); - /*if (AW > 1.0) AW = 1.0;*/ - /*s_h2o->la=log10(AW); */ - mu_x = I; - for (i = 0; i < 2 * count_s + sit_count_anions; i++) - { - if (sit_IPRSNT[i] == FALSE) continue; - spec[i]->lg_pitzer = sit_LGAMMA[i]; -/* - output_msg(sformatf( "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, sit_M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg)); -*/ - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: sit(void) @@ -1573,37 +1394,6 @@ gammas_sit() return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -PTEMP_SIT(LDBLE TK) -/* ---------------------------------------------------------------------- */ -{ -/* -C -C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER -C -*/ - int i; - LDBLE TR = 298.15; - - if (fabs(TK - OTEMP) < 0.001 && fabs(patm_x - OPRESS) < 0.1) return OK; -/* -C Set DW0 -*/ - DW0 = rho_0 = calc_rho_0(TK - 273.15, patm_x); - VP = patm_x; - for (i = 0; i < count_sit_param; i++) - { - calc_sit_param(sit_params[i], TK, TR); - } - calc_dielectrics(TK - 273.15, patm_x); - sit_A0 = A0; - OTEMP = TK; - OPRESS = patm_x; - return OK; -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: PTEMP_SIT(LDBLE TK) diff --git a/spread.cpp b/spread.cpp index c9e33274..ca13926c 100644 --- a/spread.cpp +++ b/spread.cpp @@ -210,7 +210,7 @@ read_solution_spread(void) break; case 14: /* pressure */ case 15: /* press */ - sscanf(next_char, SCANFORMAT, &(soln_defaults.pressure)); + (void)sscanf(next_char, SCANFORMAT, &(soln_defaults.pressure)); break; } } @@ -269,7 +269,7 @@ read_solution_spread(void) break; case 0: /* temperature */ case 1: - sscanf(next_char, SCANFORMAT, &(soln_defaults.temp)); + (void)sscanf(next_char, SCANFORMAT, &(soln_defaults.temp)); break; case 2: /* density */ case 3: @@ -331,7 +331,7 @@ read_solution_spread(void) break; case 6: /* ph */ copy_token(token, &next_char); - sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.ph)); + (void)sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.ph)); if (copy_token(token, &next_char) != EMPTY) { warning_msg @@ -340,7 +340,7 @@ read_solution_spread(void) break; case 7: /* pe */ copy_token(token, &next_char); - sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.pe)); + (void)sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.pe)); if (copy_token(token, &next_char) != EMPTY) { warning_msg @@ -409,7 +409,7 @@ read_solution_spread(void) } else { - sscanf(token.c_str(), SCANFORMAT, + (void)sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.iso[i].uncertainty)); } } @@ -431,7 +431,7 @@ read_solution_spread(void) } else { - sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.water)); + (void)sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.water)); } } break; @@ -489,7 +489,7 @@ read_solution_spread(void) error_msg(error_string, CONTINUE); break; } - sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.iso[i].value)); + (void)sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.iso[i].value)); /* read and store isotope ratio uncertainty */ int j; if ((j = copy_token(token, &next_char)) != EMPTY) @@ -504,14 +504,14 @@ read_solution_spread(void) } else { - sscanf(token.c_str(), SCANFORMAT, + (void)sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.iso[i].uncertainty)); } } } break; case 14: /* pressure */ - sscanf(next_char, SCANFORMAT, &(soln_defaults.pressure)); + (void)sscanf(next_char, SCANFORMAT, &(soln_defaults.pressure)); break; case 100: /* read headings */ heading = string_to_spread_row(line); @@ -720,14 +720,14 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, break; case 0: /* temperature */ case 1: - sscanf(next_char, SCANFORMAT, &dummy); + (void)sscanf(next_char, SCANFORMAT, &dummy); temp_solution.Set_tc(dummy); break; case 2: /* density */ case 3: { int j = copy_token(token, &next_char); - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_solution.Set_density(dummy); j = copy_token(token, &next_char); if (j != EMPTY) @@ -915,7 +915,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, free_check_null(char_string); continue; } - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_isotope.Set_ratio(dummy); temp_isotope.Set_ratio_uncertainty(NAN); @@ -932,7 +932,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, free_check_null(char_string); continue; } - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_isotope.Set_ratio_uncertainty(dummy); } temp_solution.Get_isotopes()[temp_isotope.Get_isotope_name()] = temp_isotope; @@ -956,7 +956,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, } else { - sscanf(token.c_str(), SCANFORMAT, &dummy); + (void)sscanf(token.c_str(), SCANFORMAT, &dummy); temp_solution.Set_mass_water(dummy); } } diff --git a/step.cpp b/step.cpp index fc5bb95d..e4d83ac6 100644 --- a/step.cpp +++ b/step.cpp @@ -516,12 +516,6 @@ add_surface(cxxSurface *surface_ptr) { cb_x += comp_ptr->Get_charge_balance(); } -#ifdef SKIP_MUSIC - if (surface_ptr->type == CD_MUSIC) - { - cb_x += surface_ptr->comps[i].cb; - } -#endif if (!surface_ptr->Get_new_def()) { master_i_ptr->s->la = comp_ptr->Get_la(); diff --git a/structures.cpp b/structures.cpp index 01648c36..d4e26436 100644 --- a/structures.cpp +++ b/structures.cpp @@ -187,40 +187,15 @@ clean_up(void) cell_data = (struct cell_data *) free_check_null(cell_data); /* punch */ -#ifdef SKIP - punch.totals = (struct name_master *) free_check_null(punch.totals); - punch.molalities = - (struct name_species *) free_check_null(punch.molalities); - punch.activities = - (struct name_species *) free_check_null(punch.activities); - punch.pure_phases = - (struct name_phase *) free_check_null(punch.pure_phases); - punch.si = (struct name_phase *) free_check_null(punch.si); - punch.gases = (struct name_phase *) free_check_null(punch.gases); - punch.s_s = (struct name_phase *) free_check_null(punch.s_s); - punch.kinetics = (struct name_phase *) free_check_null(punch.kinetics); -#endif advection_punch = (int *) free_check_null(advection_punch); advection_print = (int *) free_check_null(advection_print); -#ifdef SKIP - punch.isotopes = (struct name_master *) free_check_null(punch.isotopes); - punch.calculate_values = - (struct name_master *) free_check_null(punch.calculate_values); -#endif + SelectedOutput_map.clear(); UserPunch_map.clear(); /* user_print and user_punch */ rate_free(user_print); user_print = (struct rate *) free_check_null(user_print); -#ifdef SKIP - rate_free(user_punch); - user_print = (struct rate *) free_check_null(user_print); - - user_punch = (struct rate *) free_check_null(user_punch); - user_punch_headings = (const char **) free_check_null(user_punch_headings); -#endif - /* Free llnl aqueous model parameters */ diff --git a/tally.cpp b/tally.cpp index 994c6af2..4b18d54b 100644 --- a/tally.cpp +++ b/tally.cpp @@ -157,63 +157,6 @@ get_all_components(void) count_tally_table_rows = tally_count_component; return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -get_all_components(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Counts components in any defined solution, gas_phase, exchanger, - * surface, or pure_phase_assemblage - * - * Returns n_comp, which is total, including H, O, elements, and Charge - * names contains character strings with names of components - */ - int i, j; -/* - * Accumulate all aqueous components - */ - add_all_components_tally(); -/* - * Count components, 2 for hydrogen, oxygen, + others, - */ - tally_count_component = 0; - for (i = 0; i < count_master; i++) - { - if (master[i]->total > 0.0 && master[i]->s->type == AQ) - { - tally_count_component++; - } - } -/* - * Put information in buffer. - * Buffer contains an entry for every primary master - * species that can be used in the transport problem. - * Each entry in buffer is sent to HST for transort. - */ - t_buffer = - (struct tally_buffer *) PHRQ_malloc((size_t) tally_count_component * - sizeof(struct tally_buffer)); - j = 0; - for (i = 0; i < count_master; i++) - { - if (master[i]->total > 0.0 && master[i]->s->type == AQ) - { - t_buffer[j].name = master[i]->elt->name; - t_buffer[j].master = master[i]; - t_buffer[j].gfw = master[i]->elt->gfw; - j++; - } - } - /* - * Return value - */ - /**n_comp = count_component;*/ - count_tally_table_rows = tally_count_component; - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: store_tally_table(LDBLE * l_array, int row_dim_in, int col_dim, LDBLE fill_factor) @@ -535,53 +478,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) tally_table[i].total[n_buffer][2].moles = solution_ptr->Get_total_o(); } break; -#ifdef SKIP - case Solution: -/* - * fill solution - */ - if (n_user[Solution] < 0 || n_buffer == 0) - break; - { - cxxSolution *solution_ptr; - if (i == 0) - { - solution_ptr = Utilities::Rxn_find(Rxn_solution_map, index_conservative); - } - else if (i == 1) - { - solution_ptr = Utilities::Rxn_find(Rxn_solution_map, n_user[Solution]); - } - else - { - solution_ptr = NULL; - error_msg - ("Solution is not in first two columns of tally_table", - STOP); - } - if (solution_ptr == NULL) - break; - xsolution_zero(); - add_solution(solution_ptr, 1.0, 1.0); - count_elts = 0; - paren_count = 0; - for (int j = 0; j < count_master; j++) - { - if (master[j]->total > 0.0) - { - char * temp_name = string_duplicate(master[j]->elt->primary->elt->name); - ptr = temp_name; - get_elts_in_species(&ptr, master[j]->total); - free_check_null(temp_name); - } - } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - } - break; -#endif case Reaction: /* * fill reaction @@ -1153,31 +1049,6 @@ build_tally_table(void) } } -#ifdef SKIP - /* - * Debug print for table definition - */ - output_msg(sformatf( "List of rows for tally table\n")); - for (i = 0; i < count_tally_table_rows; i++) - { - output_msg(sformatf( "\t%-s\n", buffer[i].name)); - } - output_msg(sformatf( "\nList of columns for tally table\n")); - for (i = 0; i < count_tally_table_columns; i++) - { - output_msg(sformatf( "\t%-20s\tType: %d\n", - tally_table[i].name, tally_table[i].type)); - if (tally_table[i].formula != NULL) - { - for (j = 0; tally_table[i].formula[j].elt != NULL; j++) - { - output_msg(sformatf( "\t\t%-10s\t%f\n", - tally_table[i].formula[j].elt->name, - (double) tally_table[i].formula[j].coef)); - } - } - } -#endif pr.use = save_print_use; return (OK); } diff --git a/tidy.cpp b/tidy.cpp index 95d12e21..453aaaa5 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1079,173 +1079,7 @@ tidy_gas_phase(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -tidy_gas_phase(void) -/* ---------------------------------------------------------------------- */ -{ - int n_user, last; - LDBLE P, V_m; - bool PR; -/* - * Find all gases for each gas_phase in phase list - */ - for (std::set::const_iterator nit = Rxn_new_gas_phase.begin(); nit != Rxn_new_gas_phase.end(); nit++) - { - std::map::iterator it = Rxn_gas_phase_map.find(*nit); - if (it == Rxn_gas_phase_map.end()) - { - assert(false); - } - cxxGasPhase *gas_phase_ptr = &(it->second); - PR = false; - P = 0.0; - std::vector gc = gas_phase_ptr->Get_gas_comps(); - for (size_t j = 0; j < gc.size(); j++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); - if (phase_ptr == NULL) - { - input_error++; - error_string = sformatf( - "Gas not found in PHASES database, %s.", - gc[j].Get_phase_name().c_str()); - error_msg(error_string, CONTINUE); - continue; - } - else - { - if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0) - PR = true; - } - gas_phase_ptr->Set_pr_in(PR); - if (gas_phase_ptr->Get_new_def()) - { - if (j == gc.size() - 1) - gas_phase_ptr->Set_new_def(false); - /* - * Fixed pressure - */ - if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) - { - if (gas_phase_ptr->Get_solution_equilibria()) - { - input_error++; - error_string = sformatf( - "Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.", - gas_phase_ptr->Get_n_user()); - error_msg(error_string, CONTINUE); - } - /* calculate moles */ - if (gc[j].Get_p_read() != NAN) - { - P += gc[j].Get_p_read(); - if (!PR) - gc[j].Set_moles( - gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / - R_LITER_ATM / gas_phase_ptr->Get_temperature()); - } - else - { - input_error++; - error_string = sformatf( - "Gas phase %d: partial pressure of gas component %s not defined.", - gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str()); - error_msg(error_string, CONTINUE); - } - } - else - { - /* - * Fixed volume - */ - if (!gas_phase_ptr->Get_solution_equilibria()) - { - if (gc[j].Get_p_read() != NAN) - { - P += gc[j].Get_p_read(); - if (!PR) - gc[j].Set_moles ( - gc[j].Get_p_read() * - gas_phase_ptr->Get_volume() / R_LITER_ATM / - gas_phase_ptr->Get_temperature()); - } - else - { - input_error++; - error_string = sformatf( - "Gas phase %d: moles of gas component %s not defined.", - gas_phase_ptr->Get_n_user(), - gc[j].Get_phase_name().c_str()); - error_msg(error_string, CONTINUE); - } - } - } - - gas_phase_ptr->Set_gas_comps(gc); - - if (PR && P > 0 && j == gc.size() - 1) - { - std::vector phase_ptrs; - size_t j_PR; - for (j_PR = 0; j_PR < gas_phase_ptr->Get_gas_comps().size(); j_PR++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j_PR].Get_phase_name().c_str(), &k, FALSE); - if (gc[j_PR].Get_p_read() == 0) - continue; - phase_ptr->moles_x = gc[j_PR].Get_p_read() / P; - phase_ptrs.push_back(phase_ptr); - } - V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); - gas_phase_ptr->Set_v_m(V_m); - if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) - { - gas_phase_ptr->Set_total_p(P); - } - std::vector gc = gas_phase_ptr->Get_gas_comps(); - for (j_PR = 0; j_PR < gas_phase_ptr->Get_gas_comps().size(); j_PR++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gc[j_PR].Get_phase_name().c_str(), &k, FALSE); - if (gc[j_PR].Get_p_read() == 0) - { - gc[j_PR].Set_moles(0.0); - } else - { - gc[j_PR].Set_moles(phase_ptr->moles_x * - gas_phase_ptr->Get_volume() / V_m); - gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j_PR].Get_moles()); - } - } - gas_phase_ptr->Set_gas_comps(gc); - } - /* - * Duplicate gas phase, only if not solution equilibria - */ - if (!gas_phase_ptr->Get_solution_equilibria()) - { - n_user = gas_phase_ptr->Get_n_user(); - last = gas_phase_ptr->Get_n_user_end(); - gas_phase_ptr->Set_n_user_end(n_user); - for (int j1 = n_user + 1; j1 <= last; j1++) - { - Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j1); - } - } - else - { - gas_phase_ptr->Set_new_def(true); - } - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_inverse(void) @@ -2453,312 +2287,7 @@ tidy_punch(void) phrq_io->Set_punch_ostream(NULL); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -tidy_punch(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, l; - int punch_save; - char token[MAX_LENGTH]; -/* - * tidy punch information - */ - if (punch.high_precision == FALSE) - { - l = 12; - } - else - { - l = 20; - } - if (punch.in == TRUE) - { - /* totals */ - for (i = 0; i < punch.count_totals; i++) - { - punch.totals[i].master = master_bsearch(punch.totals[i].name); - } - - /* molalities */ - - for (i = 0; i < punch.count_molalities; i++) - { - punch.molalities[i].s = s_search(punch.molalities[i].name); - } - - /* log activities */ - - for (i = 0; i < punch.count_activities; i++) - { - punch.activities[i].s = s_search(punch.activities[i].name); - } - - /* equilibrium phases */ - - for (i = 0; i < punch.count_pure_phases; i++) - { - punch.pure_phases[i].phase = - phase_bsearch(punch.pure_phases[i].name, &j, FALSE); - } - - /* saturation indices */ - - for (i = 0; i < punch.count_si; i++) - { - punch.si[i].phase = phase_bsearch(punch.si[i].name, &j, FALSE); - } - - /* gases */ - - for (i = 0; i < punch.count_gases; i++) - { - punch.gases[i].phase = - phase_bsearch(punch.gases[i].name, &j, FALSE); - } - } - /* - * Always write new headings when SELECTED_OUTPUT is read - */ - if (punch.new_def == TRUE && punch.in == TRUE) - { - punch_save = pr.punch; - pr.punch = TRUE; - phrq_io->Set_punch_on(true); - - /* constant stuff, sim, pH, etc. */ - - if (punch.sim == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "sim")); - } - if (punch.state == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "state")); - } - if (punch.soln == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "soln")); - } - if (punch.dist == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "dist_x")); - } - if (punch.time == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "time")); - } - if (punch.step == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "step")); - } - if (punch.ph == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "pH")); - } - if (punch.pe == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "pe")); - } - if (punch.rxn == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "reaction")); - } - if (punch.temp == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "temp")); - } - if (punch.alk == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "Alk")); - } - if (punch.mu == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "mu")); - } - if (punch.water == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "mass_H2O")); - } - if (punch.charge_balance == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "charge")); - } - if (punch.percent_error == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "pct_err")); - } - /* totals */ - - for (i = 0; i < punch.count_totals; i++) - { - fpunchf_heading(sformatf("%*s\t", l, punch.totals[i].name)); - if (punch.totals[i].master == NULL) - { - error_string = sformatf( "Did not find master species," - " %s.", punch.totals[i].name); - warning_msg(error_string); - } - } - - /* molalities */ - - for (i = 0; i < punch.count_molalities; i++) - { - strcpy(token, "m_"); - strcat(token, punch.molalities[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - if (punch.molalities[i].s == NULL) - { - error_string = sformatf( "Did not find species," - " %s.", punch.molalities[i].name); - warning_msg(error_string); - } - } - - /* log activities */ - - for (i = 0; i < punch.count_activities; i++) - { - strcpy(token, "la_"); - strcat(token, punch.activities[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - if (punch.activities[i].s == NULL) - { - error_string = sformatf( "Did not find species, " - "%s.", punch.activities[i].name); - warning_msg(error_string); - } - } - - /* equilibrium phases */ - - for (i = 0; i < punch.count_pure_phases; i++) - { - strcpy(token, "d_"); - strcat(token, punch.pure_phases[i].name); - fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name)); - fpunchf_heading(sformatf("%*s\t", l, token)); - if (punch.pure_phases[i].phase == NULL) - { - error_string = sformatf( "Did not find phase, " - "%s.", punch.pure_phases[i].name); - warning_msg(error_string); - } - } - - /* saturation indices */ - - for (i = 0; i < punch.count_si; i++) - { - strcpy(token, "si_"); - strcat(token, punch.si[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - if (punch.si[i].phase == NULL) - { - error_string = sformatf( "Did not find phase, " - "%s.", punch.si[i].name); - warning_msg(error_string); - } - } - - /* gases */ - - if (punch.count_gases > 0) - { - fpunchf_heading(sformatf("%*s\t", l, "pressure")); - fpunchf_heading(sformatf("%*s\t", l, "total mol")); - fpunchf_heading(sformatf("%*s\t", l, "volume")); - } - for (i = 0; i < punch.count_gases; i++) - { - strcpy(token, "g_"); - strcat(token, punch.gases[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - if (punch.gases[i].phase == NULL) - { - error_string = sformatf( "Did not find phase, " - "%s.", punch.gases[i].name); - warning_msg(error_string); - } - } - - /* kinetics */ - - for (i = 0; i < punch.count_kinetics; i++) - { - strcpy(token, "k_"); - strcat(token, punch.kinetics[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - strcpy(token, "dk_"); - strcat(token, punch.kinetics[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - } - - /* solid solutions */ - - for (i = 0; i < punch.count_s_s; i++) - { - strcpy(token, "s_"); - strcat(token, punch.s_s[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - } - - /* isotopes */ - - for (i = 0; i < punch.count_isotopes; i++) - { - if (isotope_ratio_search(punch.isotopes[i].name) == NULL) - { - error_string = sformatf( - "Did not find isotope_ratio definition for " - "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", - punch.isotopes[i].name, punch.isotopes[i].name); - warning_msg(error_string); - } - strcpy(token, "I_"); - strcat(token, punch.isotopes[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - } - - /* calculate_values */ - - for (i = 0; i < punch.count_calculate_values; i++) - { - if (calculate_value_search(punch.calculate_values[i].name) == NULL) - { - error_string = sformatf( - "Did not find calculate_values definition for " - "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", - punch.calculate_values[i].name, - punch.calculate_values[i].name); - warning_msg(error_string); - } - strcpy(token, "V_"); - strcat(token, punch.calculate_values[i].name); - fpunchf_heading(sformatf("%*s\t", l, token)); - } - - /* user_punch */ - if (punch.user_punch == TRUE) - { - for (i = 0; i < user_punch_count_headings; i++) - { - fpunchf_heading(sformatf("%*s\t", l, user_punch_headings[i])); - } - } - fpunchf_heading("\n"); - - punch.new_def = FALSE; - pr.punch = punch_save; - phrq_io->Set_punch_on(pr.punch == TRUE); - } - punch_flush(); - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_species(void) @@ -3199,17 +2728,6 @@ tidy_surface(void) } break; } -#ifdef SKIP_MUSIC - /* - * If charge of formula is non zero - */ - if (surface_ptr->type == CD_MUSIC) - { - surface_ptr->comps[i].cb = - surface_ptr->comps[i].formula_z * - surface_ptr->comps[i].moles; - } -#endif } /* * Check that all surface comps have a corresponding master @@ -4295,9 +3813,6 @@ tidy_min_surface(void) surface_comp_ptr->Set_phase_name(phase_ptr->name); /* make surface concentration proportional to mineral ... */ LDBLE conc = jit->second.Get_moles() * surface_comp_ptr->Get_phase_proportion(); -#ifdef SKIP_MUSIC - comp_ptr->cb = conc * comp_ptr->formula_z; -#endif /* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ { char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str()); diff --git a/utilities.cpp b/utilities.cpp index 8ffc8c0b..6b0bcae2 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -407,15 +407,6 @@ copy_token(char *token_ptr, char **ptr, int *length) } token_ptr[i] = '\0'; *length = i; -#ifdef PHREEQ98 - if ((return_value == DIGIT) && (strstr(token_ptr, ",") != NULL)) - { - error_string = sformatf( - "Commas are not allowed as decimal separator: %s.", - token_ptr); - error_msg(error_string, CONTINUE); - } -#endif return (return_value); } /* ---------------------------------------------------------------------- */ @@ -484,15 +475,6 @@ copy_token(std::string &token, char **ptr) token.append(c_char); (*ptr)++; } -#ifdef PHREEQ98 - if ((return_value == DIGIT) && (strstr(token_ptr, ",") != NULL)) - { - error_string = sformatf( - "Commas are not allowed as decimal separator: %s.", - token_ptr); - error_msg(error_string, CONTINUE); - } -#endif return (return_value); } #if defined PHREEQ98 @@ -599,17 +581,6 @@ dup_print(const char *ptr, int emphasis) if (pr.headings == FALSE) return (OK); -#ifdef PHREEQ98 - if ((CreateToC == TRUE) && (AutoLoadOutputFile == TRUE)) - { - if (strstr(ptr, "Reading") == ptr) - AddToCEntry((char *) ptr, 1, outputlinenr); - else if (strstr(ptr, "Beginning") == ptr) - AddToCEntry((char *) ptr, 2, outputlinenr); - else if ((strstr(ptr, "TITLE") != ptr) && (strstr(ptr, "End") != ptr)) - AddToCEntry((char *) ptr, 3, outputlinenr); - } -#endif std::string save_in(ptr); l = (int) strlen(ptr); dash = (char *) PHRQ_malloc((size_t) (l + 2) * sizeof(char)); @@ -1001,10 +972,6 @@ print_centered(const char *string) int i, l, l1, l2; char token[MAX_LENGTH]; -#ifdef PHREEQ98 - if ((CreateToC == TRUE) && (AutoLoadOutputFile == TRUE)) - AddToCEntry((char *) string, 4, outputlinenr); -#endif l = (int) strlen(string); l1 = (79 - l) / 2; l2 = 79 - l - l1; @@ -1397,12 +1364,6 @@ status(int count, const char *str, bool rk_string) char spin_str[2]; clock_t t2; -#ifdef PHREEQ98 - if (ProcessMessages) - ApplicationProcessMessages(); - if (stop_calculations == TRUE) - error_msg("Execution canceled by user.", STOP); -#endif if (pr.status == FALSE || phast == TRUE) return (OK); From 54b0d4d1332f8c6e0d53ca8b9cb15a47c652c64a Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Sun, 14 Mar 2021 08:37:40 -0600 Subject: [PATCH 02/34] starting on space --- Phreeqc.cpp | 34 +++---- Phreeqc.h | 9 +- cl1.cpp | 52 ++++++++--- model.cpp | 235 ++++++++++++++++++++++++++++--------------------- structures.cpp | 22 ++--- utilities.cpp | 4 +- 6 files changed, 209 insertions(+), 147 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index a4c19186..9c1e7f62 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1178,24 +1178,24 @@ void Phreeqc::init(void) /* model.cpp ------------------------------- */ gas_in = FALSE; min_value = 1e-10; - normal = NULL; - ineq_array = NULL; - res = NULL; - cu = NULL; + //normal = NULL; + //ineq_array = NULL; + //res = NULL; + //cu = NULL; zero = NULL; - delta1 = NULL; - iu = NULL; - is = NULL; - back_eq = NULL; - normal_max = 0; - ineq_array_max = 0; - res_max = 0; - cu_max = 0; - zero_max = 0; - delta1_max = 0; - iu_max = 0; - is_max = 0; - back_eq_max = 0; + //delta1 = NULL; + //iu = NULL; + //is = NULL; + //back_eq = NULL; + //normal_max = 0; + ////ineq_array_max = 0; + //res_max = 0; + //cu_max = 0; + //zero_max = 0; + //delta1_max = 0; + //iu_max = 0; + //is_max = 0; + //back_eq_max = 0; /* phrq_io_output.cpp ------------------------------- */ forward_output_to_log = 0; /* phreeqc_files.cpp ------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index d4b9755b..1fe31a3d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1144,7 +1144,9 @@ protected: int string_trim_right(char *str); int string_trim_left(char *str); static LDBLE under(LDBLE xval); +#ifdef SKIP void zero_double(LDBLE * target, int n); +#endif int get_input_errors(void); int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, const char *Key); @@ -1796,6 +1798,7 @@ protected: /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; + std::vector x_arg_v, res_arg_v, scratch_v; int x_arg_max, res_arg_max, scratch_max; /* gases.cpp ------------------------------- */ LDBLE a_aa_sum, b2, b_sum, R_TK; @@ -1865,9 +1868,11 @@ protected: int gas_in; LDBLE min_value; LDBLE *normal, *ineq_array, *res, *cu, *zero, *delta1; + std::vector normal_v, ineq_array_v, res_v, cu_v, zero_v, delta1_v; int *iu, *is, *back_eq; - int normal_max, ineq_array_max, res_max, cu_max, zero_max, - delta1_max, iu_max, is_max, back_eq_max; + std::vector iu_v, is_v, back_eq_v; + //int normal_max, ineq_array_max, res_max, cu_max, zero_max, + // delta1_max, iu_max, is_max, back_eq_max; /* phrq_io_output.cpp ------------------------------- */ int forward_output_to_log; diff --git a/cl1.cpp b/cl1.cpp index 2e7bc82a..a386c622 100644 --- a/cl1.cpp +++ b/cl1.cpp @@ -188,12 +188,14 @@ cl1(int k, int l, int m, int n, output_msg(sformatf( "Set up phase 1 costs\n")); #endif /* Zero first row of cu and iu */ - memcpy((void *) &(l_cu[0]), (void *) &(scratch[0]), - (size_t) nklm * sizeof(LDBLE)); - for (j = 0; j < nklm; ++j) - { - l_iu[j] = 0; - } + //memcpy((void *) &(l_cu[0]), (void *) &(scratch[0]), + // (size_t) nklm * sizeof(LDBLE)); + memset(&l_cu[0], 0, (size_t)nklm * sizeof(LDBLE)); + //for (j = 0; j < nklm; ++j) + //{ + // l_iu[j] = 0; + //} + memset(&l_iu[0], 0, (size_t)nklm * sizeof(int)); /* L40: */ #ifdef DEBUG_CL1 output_msg(sformatf( "L40\n")); @@ -847,16 +849,17 @@ cl1(int k, int l, int m, int n, void Phreeqc:: cl1_space(int check, int l_n2d, int klm, int l_nklmd) { +#ifdef SKIP if (check == 1) { if (x_arg == NULL) { - x_arg = (LDBLE *) PHRQ_malloc((size_t) (l_n2d * sizeof(LDBLE))); + x_arg = (LDBLE*)PHRQ_malloc((size_t)(l_n2d * sizeof(LDBLE))); } else if (l_n2d > x_arg_max) { x_arg = - (LDBLE *) PHRQ_realloc(x_arg, (size_t) (l_n2d * sizeof(LDBLE))); + (LDBLE*)PHRQ_realloc(x_arg, (size_t)(l_n2d * sizeof(LDBLE))); x_arg_max = l_n2d; } if (x_arg == NULL) @@ -865,13 +868,13 @@ cl1_space(int check, int l_n2d, int klm, int l_nklmd) if (res_arg == NULL) { - res_arg = (LDBLE *) PHRQ_malloc((size_t) ((klm) * sizeof(LDBLE))); + res_arg = (LDBLE*)PHRQ_malloc((size_t)((klm) * sizeof(LDBLE))); } else if (klm > res_arg_max) { res_arg = - (LDBLE *) PHRQ_realloc(res_arg, - (size_t) ((klm) * sizeof(LDBLE))); + (LDBLE*)PHRQ_realloc(res_arg, + (size_t)((klm) * sizeof(LDBLE))); res_arg_max = klm; } if (res_arg == NULL) @@ -879,18 +882,39 @@ cl1_space(int check, int l_n2d, int klm, int l_nklmd) zero_double(res_arg, klm); } -/* Make scratch space */ + /* Make scratch space */ if (scratch == NULL) { - scratch = (LDBLE *) PHRQ_malloc((size_t) l_nklmd * sizeof(LDBLE)); + scratch = (LDBLE*)PHRQ_malloc((size_t)l_nklmd * sizeof(LDBLE)); } else if (l_nklmd > scratch_max) { scratch = - (LDBLE *) PHRQ_realloc(scratch, (size_t) l_nklmd * sizeof(LDBLE)); + (LDBLE*)PHRQ_realloc(scratch, (size_t)l_nklmd * sizeof(LDBLE)); scratch_max = l_nklmd; } if (scratch == NULL) malloc_error(); zero_double(scratch, l_nklmd); +#endif + if (l_n2d > x_arg_v.size()) + { + x_arg_v.resize(l_n2d); + x_arg = &x_arg_v[0]; + } + memset(x_arg_v.data(), 0, sizeof(double) * (size_t)l_n2d); + + if (klm > res_arg_v.size()) + { + res_arg_v.resize(klm); + res_arg = &res_arg_v[0]; + } + memset(res_arg_v.data(), 0, sizeof(double) * (size_t)klm); + + if (l_nklmd > scratch_v.size()) + { + scratch_v.resize(l_nklmd); + scratch = &scratch_v[0]; + } + memset(scratch_v.data(), 0, sizeof(double) * (size_t)l_nklmd); } diff --git a/model.cpp b/model.cpp index b81439f0..a017d43f 100644 --- a/model.cpp +++ b/model.cpp @@ -1023,8 +1023,10 @@ ineq(int in_kode) /* * Normalize column */ - space((void **) ((void *) &normal), count_unknowns, &normal_max, - sizeof(LDBLE)); + //space((void **) ((void *) &normal), count_unknowns, &normal_max, + // sizeof(LDBLE)); + normal_v.resize((size_t)count_unknowns); + normal = normal_v.data(); for (i = 0; i < count_unknowns; i++) normal[i] = 1.0; @@ -1124,22 +1126,36 @@ ineq(int in_kode) */ max_row_count = 2 * count_unknowns + 2; max_column_count = count_unknowns + 2; - space((void **) ((void *) &ineq_array), max_row_count * max_column_count, - &ineq_array_max, sizeof(LDBLE)); + //space((void **) ((void *) &ineq_array), max_row_count * max_column_count, + // &ineq_array_max, sizeof(LDBLE)); + ineq_array_v.resize((size_t)max_row_count * (size_t)max_column_count); + ineq_array = ineq_array_v.data(); - space((void **) ((void *) &back_eq), max_row_count, &back_eq_max, - sizeof(int)); + //space((void **) ((void *) &back_eq), max_row_count, &back_eq_max, + // sizeof(int)); + back_eq_v.resize((size_t)max_row_count); + back_eq = back_eq_v.data(); - space((void **) ((void *) &zero), max_row_count, &zero_max, - sizeof(LDBLE)); - zero_double(zero, max_row_count); + //space((void **) ((void *) &zero), max_row_count, &zero_max, + // sizeof(LDBLE)); + //zero_double(zero, max_row_count); + zero_v.resize((size_t)max_row_count); + zero = zero_v.data(); + memset(zero, 0, (size_t)max_row_count * sizeof(double)); - space((void **) ((void *) &res), max_row_count, &res_max, sizeof(LDBLE)); - zero_double(res, max_row_count); - space((void **) ((void *) &delta1), max_column_count, &delta1_max, - sizeof(LDBLE)); - zero_double(delta1, max_column_count); + //space((void **) ((void *) &res), max_row_count, &res_max, sizeof(LDBLE)); + //zero_double(res, max_row_count); + res_v.resize((size_t)max_row_count); + res = res_v.data(); + memset(res, 0, (size_t)max_row_count * sizeof(double)); + + //space((void **) ((void *) &delta1), max_column_count, &delta1_max, + // sizeof(LDBLE)); + //zero_double(delta1, max_column_count); + delta1_v.resize((size_t)max_column_count); + delta1 = delta1_v.data(); + memset(delta1, 0,(size_t)max_column_count * sizeof(double)); /* * Copy equations to optimize into ineq_array @@ -1389,10 +1405,11 @@ ineq(int in_kode) { /* Pure phase is present, force Mass transfer to be <= amount of mineral remaining */ - memcpy((void *) - &(ineq_array[l_count_rows * max_column_count]), - (void *) &(zero[0]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + //memcpy((void *) + // &(ineq_array[l_count_rows * max_column_count]), + // (void *) &(zero[0]), + // ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memset(&ineq_array[l_count_rows * max_column_count], 0, ((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; @@ -1402,10 +1419,11 @@ ineq(int in_kode) /* Pure phase is present and dissolve_only, force ppt to be <= amount of dissolved so far */ if (x[i]->dissolve_only == TRUE) { - memcpy((void *) - &(ineq_array[l_count_rows * max_column_count]), - (void *) &(zero[0]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + //memcpy((void *) + // &(ineq_array[l_count_rows * max_column_count]), + // (void *) &(zero[0]), + // ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memset(&(ineq_array[l_count_rows * max_column_count]), 0, ((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] = @@ -1587,9 +1605,14 @@ ineq(int in_kode) { if (x[i]->type == GAS_MOLES) { - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(zero[0]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + //memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + // (void *) &(zero[0]), + // ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + //std::fill(&(ineq_array[l_count_rows * max_column_count]), + // &(ineq_array[l_count_rows * max_column_count + count_unknowns]), + // 0.0e0); + memset(&(ineq_array[l_count_rows * max_column_count]), 0, + ((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; @@ -1625,9 +1648,11 @@ ineq(int in_kode) break; if (x[i]->phase->in == TRUE && x[i]->ss_in == TRUE) { - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(zero[0]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + //memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + // (void *) &(zero[0]), + // ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memset(&(ineq_array[l_count_rows * max_column_count]), 0, + ((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; @@ -1755,11 +1780,17 @@ ineq(int in_kode) /* * Allocate space for arrays */ - space((void **) ((void *) &cu), 2 * l_nklmd, &cu_max, sizeof(LDBLE)); + //space((void **) ((void *) &cu), 2 * l_nklmd, &cu_max, sizeof(LDBLE)); + cu_v.resize(2 * (size_t)l_nklmd); + cu = cu_v.data(); - space((void **) ((void *) &iu), 2 * l_nklmd, &iu_max, sizeof(int)); + //space((void **) ((void *) &iu), 2 * l_nklmd, &iu_max, sizeof(int)); + iu_v.resize(2 * (size_t)l_nklmd); + iu = iu_v.data(); - space((void **) ((void *) &is), l_klmd, &is_max, sizeof(int)); + //space((void **) ((void *) &is), l_klmd, &is_max, sizeof(int)); + is_v.resize(l_klmd); + is = is_v.data(); #ifdef SLNQ slnq_array = @@ -1852,8 +1883,10 @@ ineq(int in_kode) #endif /* Copy delta1 into delta and scale */ #ifdef SHRINK_ARRAY - memcpy((void *) &(delta[0]), (void *) &(zero[0]), - (size_t) count_unknowns * sizeof(LDBLE)); + //memcpy((void *) &(delta[0]), (void *) &(zero[0]), + // (size_t) count_unknowns * sizeof(LDBLE)); + memset(&(delta[0]), 0, + (size_t)count_unknowns * sizeof(LDBLE)); #endif memcpy((void *) &(delta[0]), (void *) &(delta1[0]), (size_t) n * sizeof(LDBLE)); @@ -5583,74 +5616,74 @@ void Phreeqc:: ineq_init(int l_max_row_count, int l_max_column_count) /* ---------------------------------------------------------------------- */ { - if (normal == NULL) - { - normal = - (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); - normal_max = count_unknowns; - if (normal == NULL) - malloc_error(); - } - if (ineq_array == NULL) - { - ineq_array = - (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * l_max_column_count * - sizeof(LDBLE)); - if (ineq_array == NULL) - malloc_error(); - ineq_array_max = l_max_row_count * l_max_column_count; - } - if (back_eq == NULL) - { - back_eq = (int *) PHRQ_malloc((size_t) l_max_row_count * sizeof(int)); - if (back_eq == NULL) - malloc_error(); - back_eq_max = l_max_row_count; - } - if (zero == NULL) - { - zero = (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * sizeof(LDBLE)); - if (zero == NULL) - malloc_error(); - zero_max = l_max_row_count; - } - if (res == NULL) - { - res = (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * sizeof(LDBLE)); - if (res == NULL) - malloc_error(); - res_max = l_max_row_count; - } - if (delta1 == NULL) - { - delta1 = - (LDBLE *) PHRQ_malloc((size_t) l_max_column_count * sizeof(LDBLE)); - if (delta1 == NULL) - malloc_error(); - delta1_max = l_max_column_count; - } - if (cu == NULL) - { - cu = (LDBLE *) PHRQ_malloc((size_t) 3 * l_max_row_count * - sizeof(LDBLE)); - if (cu == NULL) - malloc_error(); - cu_max = 3 * l_max_row_count; - } - if (iu == NULL) - { - iu = (int *) PHRQ_malloc((size_t) 3 * l_max_row_count * sizeof(int)); - if (iu == NULL) - malloc_error(); - iu_max = 3 * l_max_row_count; - } - if (is == NULL) - { - is = (int *) PHRQ_malloc((size_t) 3 * l_max_row_count * sizeof(int)); - if (is == NULL) - malloc_error(); - is_max = 3 * l_max_row_count; - } + //if (normal == NULL) + //{ + // normal = + // (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); + // normal_max = count_unknowns; + // if (normal == NULL) + // malloc_error(); + //} + ////if (ineq_array == NULL) + ////{ + //// ineq_array = + //// (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * l_max_column_count * + //// sizeof(LDBLE)); + //// if (ineq_array == NULL) + //// malloc_error(); + //// ineq_array_max = l_max_row_count * l_max_column_count; + ////} + //if (back_eq == NULL) + //{ + // back_eq = (int *) PHRQ_malloc((size_t) l_max_row_count * sizeof(int)); + // if (back_eq == NULL) + // malloc_error(); + // back_eq_max = l_max_row_count; + //} + //if (zero == NULL) + //{ + // zero = (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * sizeof(LDBLE)); + // if (zero == NULL) + // malloc_error(); + // zero_max = l_max_row_count; + //} + //if (res == NULL) + //{ + // res = (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * sizeof(LDBLE)); + // if (res == NULL) + // malloc_error(); + // res_max = l_max_row_count; + //} + //if (delta1 == NULL) + //{ + // delta1 = + // (LDBLE *) PHRQ_malloc((size_t) l_max_column_count * sizeof(LDBLE)); + // if (delta1 == NULL) + // malloc_error(); + // delta1_max = l_max_column_count; + //} + //if (cu == NULL) + //{ + // cu = (LDBLE *) PHRQ_malloc((size_t) 3 * l_max_row_count * + // sizeof(LDBLE)); + // if (cu == NULL) + // malloc_error(); + // cu_max = 3 * l_max_row_count; + //} + //if (iu == NULL) + //{ + // iu = (int *) PHRQ_malloc((size_t) 3 * l_max_row_count * sizeof(int)); + // if (iu == NULL) + // malloc_error(); + // iu_max = 3 * l_max_row_count; + //} + //if (is == NULL) + //{ + // is = (int *) PHRQ_malloc((size_t) 3 * l_max_row_count * sizeof(int)); + // if (is == NULL) + // malloc_error(); + // is_max = 3 * l_max_row_count; + //} } /* ---------------------------------------------------------------------- */ void Phreeqc:: diff --git a/structures.cpp b/structures.cpp index d4e26436..e35089b7 100644 --- a/structures.cpp +++ b/structures.cpp @@ -309,19 +309,19 @@ clean_up(void) line_save = (char *) free_check_null(line_save); zeros = (LDBLE *) free_check_null(zeros); - scratch = (LDBLE *) free_check_null(scratch); - x_arg = (LDBLE *) free_check_null(x_arg); - res_arg = (LDBLE *) free_check_null(res_arg); + //scratch = (LDBLE *) free_check_null(scratch); + //x_arg = (LDBLE *) free_check_null(x_arg); + //res_arg = (LDBLE *) free_check_null(res_arg); - normal = (LDBLE *) free_check_null(normal); - ineq_array = (LDBLE *) free_check_null(ineq_array); - back_eq = (int *) free_check_null(back_eq); + //normal = (LDBLE *) free_check_null(normal); + //ineq_array = (LDBLE *) free_check_null(ineq_array); + //back_eq = (int *) free_check_null(back_eq); zero = (LDBLE *) free_check_null(zero); - res = (LDBLE *) free_check_null(res); - delta1 = (LDBLE *) free_check_null(delta1); - cu = (LDBLE *) free_check_null(cu); - iu = (int *) free_check_null(iu); - is = (int *) free_check_null(is); + //res = (LDBLE *) free_check_null(res); + //delta1 = (LDBLE *) free_check_null(delta1); + //cu = (LDBLE *) free_check_null(cu); + //iu = (int *) free_check_null(iu); + //is = (int *) free_check_null(is); /* x_arg = res_arg = scratch = NULL; */ x_arg_max = res_arg_max = scratch_max = 0; diff --git a/utilities.cpp b/utilities.cpp index 6b0bcae2..07792d95 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1991,7 +1991,7 @@ string_pad(const char *str, int i) } return (str_ptr); } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ void Phreeqc:: zero_double(LDBLE * target, int n) @@ -2013,7 +2013,7 @@ zero_double(LDBLE * target, int n) memcpy((void *) target, (void *) zeros, (size_t) (n * sizeof(LDBLE))); return; } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: get_input_errors() From 1e0d410577f7d926f19b8d0b405bf5a1a13ce42e Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Sun, 14 Mar 2021 10:12:47 -0600 Subject: [PATCH 03/34] using memset --- Phreeqc.h | 2 -- cl1.cpp | 3 +++ model.cpp | 5 +++-- utilities.cpp | 2 -- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 1fe31a3d..7c395e54 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1144,9 +1144,7 @@ protected: int string_trim_right(char *str); int string_trim_left(char *str); static LDBLE under(LDBLE xval); -#ifdef SKIP void zero_double(LDBLE * target, int n); -#endif int get_input_errors(void); int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, const char *Key); diff --git a/cl1.cpp b/cl1.cpp index a386c622..362f1651 100644 --- a/cl1.cpp +++ b/cl1.cpp @@ -903,6 +903,7 @@ cl1_space(int check, int l_n2d, int klm, int l_nklmd) x_arg = &x_arg_v[0]; } memset(x_arg_v.data(), 0, sizeof(double) * (size_t)l_n2d); + //zero_double(x_arg, l_n2d); if (klm > res_arg_v.size()) { @@ -910,6 +911,7 @@ cl1_space(int check, int l_n2d, int klm, int l_nklmd) res_arg = &res_arg_v[0]; } memset(res_arg_v.data(), 0, sizeof(double) * (size_t)klm); + //zero_double(res_arg, klm); if (l_nklmd > scratch_v.size()) { @@ -917,4 +919,5 @@ cl1_space(int check, int l_n2d, int klm, int l_nklmd) scratch = &scratch_v[0]; } memset(scratch_v.data(), 0, sizeof(double) * (size_t)l_nklmd); + //zero_double(scratch, l_nklmd); } diff --git a/model.cpp b/model.cpp index a017d43f..9498508e 100644 --- a/model.cpp +++ b/model.cpp @@ -1142,20 +1142,21 @@ ineq(int in_kode) zero_v.resize((size_t)max_row_count); zero = zero_v.data(); memset(zero, 0, (size_t)max_row_count * sizeof(double)); + //zero_double(zero, max_row_count); //space((void **) ((void *) &res), max_row_count, &res_max, sizeof(LDBLE)); - //zero_double(res, max_row_count); res_v.resize((size_t)max_row_count); res = res_v.data(); memset(res, 0, (size_t)max_row_count * sizeof(double)); + //zero_double(res, max_row_count); //space((void **) ((void *) &delta1), max_column_count, &delta1_max, // sizeof(LDBLE)); - //zero_double(delta1, max_column_count); delta1_v.resize((size_t)max_column_count); delta1 = delta1_v.data(); memset(delta1, 0,(size_t)max_column_count * sizeof(double)); + //zero_double(delta1, max_column_count); /* * Copy equations to optimize into ineq_array diff --git a/utilities.cpp b/utilities.cpp index 07792d95..c0bb7e19 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1991,7 +1991,6 @@ string_pad(const char *str, int i) } return (str_ptr); } -#ifdef SKIP /* ---------------------------------------------------------------------- */ void Phreeqc:: zero_double(LDBLE * target, int n) @@ -2013,7 +2012,6 @@ zero_double(LDBLE * target, int n) memcpy((void *) target, (void *) zeros, (size_t) (n * sizeof(LDBLE))); return; } -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: get_input_errors() From 9d9fbfb85ef283e37614b93d40eb162a52d03789 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Sun, 14 Mar 2021 11:45:48 -0600 Subject: [PATCH 04/34] cl1 variables converted to std::vector --- Phreeqc.cpp | 25 +----------------- Phreeqc.h | 12 ++------- cl1.cpp | 51 ----------------------------------- mainsubs.cpp | 6 ----- model.cpp | 72 ++++++++++++-------------------------------------- structures.cpp | 19 ------------- utilities.cpp | 21 --------------- 7 files changed, 20 insertions(+), 186 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 9c1e7f62..e561642e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1002,8 +1002,6 @@ void Phreeqc::init(void) //have_punch_name = FALSE; print_density = 0; print_viscosity = 0; - zeros = NULL; - zeros_max = 1; cell_pore_volume = 0; cell_volume = 0; cell_porosity = 0; @@ -1178,24 +1176,7 @@ void Phreeqc::init(void) /* model.cpp ------------------------------- */ gas_in = FALSE; min_value = 1e-10; - //normal = NULL; - //ineq_array = NULL; - //res = NULL; - //cu = NULL; - zero = NULL; - //delta1 = NULL; - //iu = NULL; - //is = NULL; - //back_eq = NULL; - //normal_max = 0; - ////ineq_array_max = 0; - //res_max = 0; - //cu_max = 0; - //zero_max = 0; - //delta1_max = 0; - //iu_max = 0; - //is_max = 0; - //back_eq_max = 0; + /* phrq_io_output.cpp ------------------------------- */ forward_output_to_log = 0; /* phreeqc_files.cpp ------------------------------- */ @@ -1859,10 +1840,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) count_phases = 0; max_phases = MAX_PHASES; */ - //max_phases = pSrc->max_phases; - //phases = (struct phase **) PHRQ_malloc((size_t)max_phases * sizeof(struct phase)); - //space((void **)((void *)&phases), INIT, &max_phases, - // sizeof(struct phase *)); count_phases = 0; for (int i = 0; i < pSrc->count_phases; i++) { diff --git a/Phreeqc.h b/Phreeqc.h index 7c395e54..530af68a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1144,7 +1144,6 @@ protected: int string_trim_right(char *str); int string_trim_left(char *str); static LDBLE under(LDBLE xval); - void zero_double(LDBLE * target, int n); int get_input_errors(void); int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, const char *Key); @@ -1754,9 +1753,6 @@ protected: /* VP: Density End */ int print_viscosity; - LDBLE *zeros; - int zeros_max; - LDBLE viscos, viscos_0, viscos_0_25; // viscosity of the solution, of pure water, of pure water at 25 C LDBLE cell_pore_volume; LDBLE cell_porosity; @@ -1865,12 +1861,8 @@ protected: /* model.cpp ------------------------------- */ int gas_in; LDBLE min_value; - LDBLE *normal, *ineq_array, *res, *cu, *zero, *delta1; - std::vector normal_v, ineq_array_v, res_v, cu_v, zero_v, delta1_v; - int *iu, *is, *back_eq; - std::vector iu_v, is_v, back_eq_v; - //int normal_max, ineq_array_max, res_max, cu_max, zero_max, - // delta1_max, iu_max, is_max, back_eq_max; + std::vector normal, ineq_array, res, cu, zero, delta1; + std::vector iu, is, back_eq; /* phrq_io_output.cpp ------------------------------- */ int forward_output_to_log; diff --git a/cl1.cpp b/cl1.cpp index 362f1651..fa558fca 100644 --- a/cl1.cpp +++ b/cl1.cpp @@ -849,61 +849,12 @@ cl1(int k, int l, int m, int n, void Phreeqc:: cl1_space(int check, int l_n2d, int klm, int l_nklmd) { -#ifdef SKIP - if (check == 1) - { - if (x_arg == NULL) - { - x_arg = (LDBLE*)PHRQ_malloc((size_t)(l_n2d * sizeof(LDBLE))); - } - else if (l_n2d > x_arg_max) - { - x_arg = - (LDBLE*)PHRQ_realloc(x_arg, (size_t)(l_n2d * sizeof(LDBLE))); - x_arg_max = l_n2d; - } - if (x_arg == NULL) - malloc_error(); - zero_double(x_arg, l_n2d); - - if (res_arg == NULL) - { - res_arg = (LDBLE*)PHRQ_malloc((size_t)((klm) * sizeof(LDBLE))); - } - else if (klm > res_arg_max) - { - res_arg = - (LDBLE*)PHRQ_realloc(res_arg, - (size_t)((klm) * sizeof(LDBLE))); - res_arg_max = klm; - } - if (res_arg == NULL) - malloc_error(); - zero_double(res_arg, klm); - } - - /* Make scratch space */ - if (scratch == NULL) - { - scratch = (LDBLE*)PHRQ_malloc((size_t)l_nklmd * sizeof(LDBLE)); - } - else if (l_nklmd > scratch_max) - { - scratch = - (LDBLE*)PHRQ_realloc(scratch, (size_t)l_nklmd * sizeof(LDBLE)); - scratch_max = l_nklmd; - } - if (scratch == NULL) - malloc_error(); - zero_double(scratch, l_nklmd); -#endif if (l_n2d > x_arg_v.size()) { x_arg_v.resize(l_n2d); x_arg = &x_arg_v[0]; } memset(x_arg_v.data(), 0, sizeof(double) * (size_t)l_n2d); - //zero_double(x_arg, l_n2d); if (klm > res_arg_v.size()) { @@ -911,7 +862,6 @@ cl1_space(int check, int l_n2d, int klm, int l_nklmd) res_arg = &res_arg_v[0]; } memset(res_arg_v.data(), 0, sizeof(double) * (size_t)klm); - //zero_double(res_arg, klm); if (l_nklmd > scratch_v.size()) { @@ -919,5 +869,4 @@ cl1_space(int check, int l_n2d, int klm, int l_nklmd) scratch = &scratch_v[0]; } memset(scratch_v.data(), 0, sizeof(double) * (size_t)l_nklmd); - //zero_double(scratch, l_nklmd); } diff --git a/mainsubs.cpp b/mainsubs.cpp index d5343258..877a3984 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -228,12 +228,6 @@ initialize(void) // Allocate space for sit sit_init(); - // Allocate zeros - zeros = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (zeros == NULL) - malloc_error(); - zeros[0] = 0.0; - zeros_max = 1; use_kinetics_limiter = false; return; diff --git a/model.cpp b/model.cpp index 9498508e..dcb5736f 100644 --- a/model.cpp +++ b/model.cpp @@ -1023,14 +1023,8 @@ ineq(int in_kode) /* * Normalize column */ - //space((void **) ((void *) &normal), count_unknowns, &normal_max, - // sizeof(LDBLE)); - normal_v.resize((size_t)count_unknowns); - normal = normal_v.data(); - - for (i = 0; i < count_unknowns; i++) - normal[i] = 1.0; - + normal.resize((size_t)count_unknowns); + std::fill(normal.begin(), normal.end(), 1.0); for (i = 0; i < count_unknowns; i++) { @@ -1126,38 +1120,14 @@ ineq(int in_kode) */ max_row_count = 2 * count_unknowns + 2; max_column_count = count_unknowns + 2; - //space((void **) ((void *) &ineq_array), max_row_count * max_column_count, - // &ineq_array_max, sizeof(LDBLE)); - ineq_array_v.resize((size_t)max_row_count * (size_t)max_column_count); - ineq_array = ineq_array_v.data(); - - //space((void **) ((void *) &back_eq), max_row_count, &back_eq_max, - // sizeof(int)); - back_eq_v.resize((size_t)max_row_count); - back_eq = back_eq_v.data(); - - //space((void **) ((void *) &zero), max_row_count, &zero_max, - // sizeof(LDBLE)); - //zero_double(zero, max_row_count); - zero_v.resize((size_t)max_row_count); - zero = zero_v.data(); - memset(zero, 0, (size_t)max_row_count * sizeof(double)); - //zero_double(zero, max_row_count); - - - //space((void **) ((void *) &res), max_row_count, &res_max, sizeof(LDBLE)); - res_v.resize((size_t)max_row_count); - res = res_v.data(); - memset(res, 0, (size_t)max_row_count * sizeof(double)); - //zero_double(res, max_row_count); - - //space((void **) ((void *) &delta1), max_column_count, &delta1_max, - // sizeof(LDBLE)); - delta1_v.resize((size_t)max_column_count); - delta1 = delta1_v.data(); - memset(delta1, 0,(size_t)max_column_count * sizeof(double)); - //zero_double(delta1, max_column_count); - + ineq_array.resize((size_t)max_row_count * (size_t)max_column_count); + back_eq.resize((size_t)max_row_count); + zero.resize((size_t)max_row_count); + memset(zero.data(), 0, (size_t)max_row_count * sizeof(double)); + res.resize((size_t)max_row_count); + memset(res.data(), 0, (size_t)max_row_count * sizeof(double)); + delta1.resize((size_t)max_column_count); + memset(delta1.data(), 0,(size_t)max_column_count * sizeof(double)); /* * Copy equations to optimize into ineq_array */ @@ -1723,7 +1693,7 @@ ineq(int in_kode) if (debug_model == TRUE) { output_msg(sformatf( "\nA and B arrays:\n\n")); - array_print(ineq_array, l_count_rows, count_unknowns + 1, + array_print(ineq_array.data(), l_count_rows, count_unknowns + 1, max_column_count); } /* @@ -1781,17 +1751,9 @@ ineq(int in_kode) /* * Allocate space for arrays */ - //space((void **) ((void *) &cu), 2 * l_nklmd, &cu_max, sizeof(LDBLE)); - cu_v.resize(2 * (size_t)l_nklmd); - cu = cu_v.data(); - - //space((void **) ((void *) &iu), 2 * l_nklmd, &iu_max, sizeof(int)); - iu_v.resize(2 * (size_t)l_nklmd); - iu = iu_v.data(); - - //space((void **) ((void *) &is), l_klmd, &is_max, sizeof(int)); - is_v.resize(l_klmd); - is = is_v.data(); + cu.resize(2 * (size_t)l_nklmd); + iu.resize(2 * (size_t)l_nklmd); + is.resize(l_klmd); #ifdef SLNQ slnq_array = @@ -1817,9 +1779,9 @@ ineq(int in_kode) /* * Call CL1 */ - cl1(k, l, m, n, - l_nklmd, l_n2d, ineq_array, - &l_kode, ineq_tol, &l_iter, delta1, res, &l_error, cu, iu, is, FALSE); + cl1(k, l, m, n, l_nklmd, l_n2d, ineq_array.data(), + &l_kode, ineq_tol, &l_iter, delta1.data(), res.data(), + &l_error, cu.data(), iu.data(), is.data(), FALSE); /* Set return_kode */ if (l_kode == 1) { diff --git a/structures.cpp b/structures.cpp index e35089b7..6ffe4445 100644 --- a/structures.cpp +++ b/structures.cpp @@ -308,25 +308,6 @@ clean_up(void) line = (char *) free_check_null(line); line_save = (char *) free_check_null(line_save); - zeros = (LDBLE *) free_check_null(zeros); - //scratch = (LDBLE *) free_check_null(scratch); - //x_arg = (LDBLE *) free_check_null(x_arg); - //res_arg = (LDBLE *) free_check_null(res_arg); - - //normal = (LDBLE *) free_check_null(normal); - //ineq_array = (LDBLE *) free_check_null(ineq_array); - //back_eq = (int *) free_check_null(back_eq); - zero = (LDBLE *) free_check_null(zero); - //res = (LDBLE *) free_check_null(res); - //delta1 = (LDBLE *) free_check_null(delta1); - //cu = (LDBLE *) free_check_null(cu); - //iu = (int *) free_check_null(iu); - //is = (int *) free_check_null(is); - -/* x_arg = res_arg = scratch = NULL; */ - x_arg_max = res_arg_max = scratch_max = 0; - - /* free user database name if defined */ user_database = (char *) free_check_null(user_database); //selected_output_file_name = diff --git a/utilities.cpp b/utilities.cpp index c0bb7e19..49870995 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1992,27 +1992,6 @@ string_pad(const char *str, int i) return (str_ptr); } /* ---------------------------------------------------------------------- */ -void Phreeqc:: -zero_double(LDBLE * target, int n) -/* ---------------------------------------------------------------------- */ -{ - int i; - - if (n > zeros_max) - { - zeros = (LDBLE *) PHRQ_realloc(zeros, (size_t) (n * sizeof(LDBLE))); - if (zeros == NULL) - malloc_error(); - for (i = zeros_max; i < n; i++) - { - zeros[i] = 0.0; - } - zeros_max = n; - } - memcpy((void *) target, (void *) zeros, (size_t) (n * sizeof(LDBLE))); - return; -} -/* ---------------------------------------------------------------------- */ int Phreeqc:: get_input_errors() /* ---------------------------------------------------------------------- */ From 97e574d25992594f3b8ab0f0e56e8a1be12fe910 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 10:00:15 -0600 Subject: [PATCH 05/34] vector calculate_value** --- Phreeqc.cpp | 28 ++++------------------------ Phreeqc.h | 4 +--- isotopes.cpp | 18 ++++-------------- mainsubs.cpp | 6 +----- structures.cpp | 8 ++------ tidy.cpp | 1 - 6 files changed, 12 insertions(+), 53 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e561642e..54bf7f4b 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -982,9 +982,6 @@ void Phreeqc::init(void) master_isotope = NULL; max_master_isotope = MAX_ELTS; initial_solution_isotopes = FALSE; - count_calculate_value = 0; - calculate_value = NULL; - max_calculate_value = MAX_ELTS; calculate_value_hash_table = NULL; count_isotope_ratio = 0; isotope_ratio = 0; @@ -2309,34 +2306,17 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } } initial_solution_isotopes = pSrc->initial_solution_isotopes; - /* - count_calculate_value = 0; - calculate_value = NULL; - max_calculate_value = MAX_ELTS; - calculate_value_hash_table = NULL; - */ - for (int i = 0; i < pSrc->count_calculate_value; i++) + + for (int i = 0; i < pSrc->calculate_value.size(); i++) { - struct calculate_value *calculate_value_ptr = calculate_value_store(pSrc->calculate_value[i]->name, FALSE); - //memcpy(calculate_value_ptr, pSrc->calculate_value[i], sizeof(struct calculate_value)); + struct calculate_value* calculate_value_ptr = calculate_value_store(pSrc->calculate_value[i]->name, FALSE); calculate_value_ptr->value = pSrc->calculate_value[i]->value; - //calculate_value_ptr->commands = NULL; if (pSrc->calculate_value[i]->commands) { calculate_value_ptr->commands = string_duplicate(pSrc->calculate_value[i]->commands); } - //calculate_value_ptr->new_def = TRUE; - //calculate_value_ptr->calculated = FALSE; - //calculate_value_ptr->linebase = NULL; - //calculate_value_ptr->varbase = NULL; - //calculate_value_ptr->loopbase = NULL; } - /* - count_isotope_ratio = 0; - isotope_ratio = 0; - max_isotope_ratio = MAX_ELTS; - isotope_ratio_hash_table = 0; - */ + for (int i = 0; i < pSrc->count_isotope_ratio; i++) { struct isotope_ratio *isotope_ratio_ptr = isotope_ratio_store(pSrc->isotope_ratio[i]->name, FALSE); diff --git a/Phreeqc.h b/Phreeqc.h index 530af68a..6562717e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1731,9 +1731,7 @@ protected: struct master_isotope **master_isotope; int max_master_isotope; int initial_solution_isotopes; - int count_calculate_value; - struct calculate_value **calculate_value; - int max_calculate_value; + std::vector calculate_value; HashTable *calculate_value_hash_table; int count_isotope_ratio; struct isotope_ratio **isotope_ratio; diff --git a/isotopes.cpp b/isotopes.cpp index 1fada086..9e4f28ac 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -892,11 +892,7 @@ punch_calculate_values(void) if (current_selected_output->Get_calculate_values().size() == 0) return OK; - //if (punch.in == FALSE || punch.calculate_values == FALSE) - // return (OK); - //if (punch.count_calculate_values == 0) - // return (OK); - //for (i = 0; i < punch.count_calculate_values; i++) + for (size_t i = 0; i < current_selected_output->Get_calculate_values().size(); i++) { result = MISSING; @@ -1132,7 +1128,7 @@ calculate_values(void) /* * initialize ratios as missing */ - for (j = 0; j < count_calculate_value; j++) + for (j = 0; j < calculate_value.size(); j++) { calculate_value[j]->calculated = FALSE; calculate_value[j]->value = MISSING; @@ -1522,14 +1518,8 @@ calculate_value_store(const char *name, int replace_if_found) } else { - n = count_calculate_value++; - /* make sure there is space in s */ - if (count_calculate_value >= max_calculate_value) - { - space((void **) ((void *) &calculate_value), - count_calculate_value, &max_calculate_value, - sizeof(struct calculate_value *)); - } + n = (int)calculate_value.size(); + calculate_value.resize((size_t)n+1); /* Make new calculate_value structure */ calculate_value[n] = calculate_value_alloc(); calculate_value_ptr = calculate_value[n]; diff --git a/mainsubs.cpp b/mainsubs.cpp index 877a3984..9df03df9 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -177,11 +177,7 @@ initialize(void) #endif /* calculate_value */ - max_calculate_value = MAX_ELTS; - count_calculate_value = 0; - space((void **) ((void *) &calculate_value), INIT, &max_calculate_value, - sizeof(struct calculate_value *)); - hcreate_multi((unsigned) max_calculate_value, + hcreate_multi((unsigned) MAX_ELTS, &calculate_value_hash_table); /* isotope_ratio */ diff --git a/structures.cpp b/structures.cpp index 6ffe4445..bef9008e 100644 --- a/structures.cpp +++ b/structures.cpp @@ -236,14 +236,11 @@ clean_up(void) master_isotope_hash_table = NULL; /* calculate_value */ - for (i = 0; i < count_calculate_value; i++) + for (i = 0; i < (int) calculate_value.size(); i++) { calculate_value_free(calculate_value[i]); - calculate_value[i] = - (struct calculate_value *) free_check_null(calculate_value[i]); + calculate_value[i] = (struct calculate_value*)free_check_null(calculate_value[i]); } - calculate_value = - (struct calculate_value **) free_check_null(calculate_value); hdestroy_multi(calculate_value_hash_table); calculate_value_hash_table = NULL; @@ -334,7 +331,6 @@ clean_up(void) llnl_count_bdot = 0; llnl_count_co2_coefs = 0; - count_calculate_value = 0; count_isotope_ratio = 0; count_isotope_alpha = 0; diff --git a/tidy.cpp b/tidy.cpp index 453aaaa5..665e8a5f 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -2227,7 +2227,6 @@ tidy_punch(void) /* calculate_values */ - //for (i = 0; i < punch.count_calculate_values; i++) for (size_t i = 0; i < current_selected_output->Get_calculate_values().size(); i++) { std::pair< std::string, void *> &pair_ref = current_selected_output->Get_calculate_values()[i]; From 4bb1c8006c0c3db2800a3dec0c7a034996492020 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 10:12:21 -0600 Subject: [PATCH 06/34] vector master_isotope --- Phreeqc.cpp | 8 ++++---- Phreeqc.h | 7 ++++--- isotopes.cpp | 33 ++++++++++++++++++--------------- mainsubs.cpp | 8 ++++---- structures.cpp | 10 ++++------ tidy.cpp | 2 +- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 54bf7f4b..4236a163 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -978,9 +978,9 @@ void Phreeqc::init(void) /* ---------------------------------------------------------------------- * ISOTOPES * ---------------------------------------------------------------------- */ - count_master_isotope = 0; - master_isotope = NULL; - max_master_isotope = MAX_ELTS; + //count_master_isotope = 0; + //master_isotope = NULL; + //max_master_isotope = MAX_ELTS; initial_solution_isotopes = FALSE; calculate_value_hash_table = NULL; count_isotope_ratio = 0; @@ -2277,7 +2277,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) max_master_isotope = MAX_ELTS; */ - for (int i = 0; i < pSrc->count_master_isotope; i++) + for (int i = 0; i < (int)pSrc->master_isotope.size(); i++) { struct master_isotope *master_isotope_ptr = master_isotope_store(pSrc->master_isotope[i]->name, FALSE); memcpy(master_isotope_ptr, pSrc->master_isotope[i], sizeof(struct master_isotope)); diff --git a/Phreeqc.h b/Phreeqc.h index 6562717e..a261d851 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1727,9 +1727,10 @@ protected: * ---------------------------------------------------------------------- */ //struct name_coef match_tokens[50]; //int count_match_tokens; - int count_master_isotope; - struct master_isotope **master_isotope; - int max_master_isotope; + //int count_master_isotope; + //struct master_isotope **master_isotope; + //int max_master_isotope; + std::vector master_isotope; int initial_solution_isotopes; std::vector calculate_value; HashTable *calculate_value_hash_table; diff --git a/isotopes.cpp b/isotopes.cpp index 9e4f28ac..d6f30cba 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -478,7 +478,8 @@ add_isotopes(cxxSolution &solution_ref) /* * zero out isotopes */ - for (i = 0; i < count_master_isotope; i++) + //for (i = 0; i < count_master_isotope; i++) + for (i = 0; i < (int)master_isotope.size(); i++) { master_isotope[i]->moles = 0; } @@ -513,7 +514,7 @@ add_isotopes(cxxSolution &solution_ref) * Set isotopes flag */ initial_solution_isotopes = FALSE; - for (i = 0; i < count_master_isotope; i++) + for (i = 0; i < (int)master_isotope.size(); i++) { if (master_isotope[i]->minor_isotope == TRUE && master_isotope[i]->moles > 0) @@ -662,7 +663,7 @@ calculate_isotope_moles(struct element *elt_ptr, /* * Update master_isotope */ - for (j = 0; j < count_master_isotope; j++) + for (j = 0; j < (int)master_isotope.size(); j++) { for (i = 0; i < count_isotopes; i++) { @@ -770,12 +771,12 @@ print_initial_solution_isotopes(void) print_centered("Isotopes"); output_msg(sformatf( "%10s\t%12s\t%12s\t%12s\t%12s\n\n", "Isotope", "Molality", "Moles", "Ratio", "Units")); - for (i = 0; i < count_master_isotope; i++) + for (i = 0; i < (int)master_isotope.size(); i++) { if (master_isotope[i]->minor_isotope == FALSE) { print_isotope = FALSE; - for (j = 0; j < count_master_isotope; j++) + for (j = 0; j < (int)master_isotope.size(); j++) { if ((master_isotope[j]->elt == master_isotope[i]->elt) && (master_isotope[j]->minor_isotope == TRUE) && @@ -794,7 +795,7 @@ print_initial_solution_isotopes(void) master_isotope[i]->name, (double) (master_isotope[i]->moles / mass_water_aq_x), (double) master_isotope[i]->moles)); - for (j = 0; j < count_master_isotope; j++) + for (j = 0; j < (int)master_isotope.size(); j++) { if (i == j) continue; @@ -991,7 +992,7 @@ print_isotope_ratios(void) * Print heading */ print_isotope = FALSE; - for (i = 0; i < count_master_isotope; i++) + for (i = 0; i < (int)master_isotope.size(); i++) { if (master_isotope[i]->minor_isotope == FALSE) continue; @@ -1053,7 +1054,7 @@ print_isotope_alphas(void) * Print heading */ print_isotope = FALSE; - for (i = 0; i < count_master_isotope; i++) + for (i = 0; i < (int)master_isotope.size(); i++) { if (master_isotope[i]->minor_isotope == FALSE) continue; @@ -1350,13 +1351,15 @@ master_isotope_store(const char *name, int replace_if_found) } else { - n = count_master_isotope++; - /* make sure there is space in s */ - if (count_master_isotope >= max_master_isotope) - { - space((void **) ((void *) &master_isotope), count_master_isotope, - &max_master_isotope, sizeof(struct master_isotope *)); - } + //n = count_master_isotope++; + ///* make sure there is space in s */ + //if (count_master_isotope >= max_master_isotope) + //{ + // space((void **) ((void *) &master_isotope), count_master_isotope, + // &max_master_isotope, sizeof(struct master_isotope *)); + //} + n = (int)master_isotope.size(); + master_isotope.resize((size_t)n + 1); /* Make new master_isotope structure */ master_isotope[n] = master_isotope_alloc(); master_isotope_ptr = master_isotope[n]; diff --git a/mainsubs.cpp b/mainsubs.cpp index 9df03df9..6e49dddd 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -98,14 +98,14 @@ initialize(void) space((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); - space((void **) ((void *) &master_isotope), INIT, &max_master_isotope, - sizeof(struct master_isotope *)); + //space((void **) ((void *) &master_isotope), INIT, &max_master_isotope, + // sizeof(struct master_isotope *)); /* * Create hash tables */ hcreate_multi((unsigned) max_logk, &logk_hash_table); - hcreate_multi((unsigned) max_master_isotope, &master_isotope_hash_table); + hcreate_multi((unsigned) MAX_ELTS, &master_isotope_hash_table); hcreate_multi((unsigned) max_elements, &elements_hash_table); hcreate_multi((unsigned) max_s, &species_hash_table); hcreate_multi((unsigned) max_phases, &phases_hash_table); @@ -1379,7 +1379,7 @@ xsolution_save(int n_user) */ if (initial_solution_isotopes == TRUE) { - for (int i = 0; i < count_master_isotope; i++) + for (int i = 0; i < (int)master_isotope.size(); i++) { if (master_isotope[i]->moles > 0) { diff --git a/structures.cpp b/structures.cpp index bef9008e..79d43539 100644 --- a/structures.cpp +++ b/structures.cpp @@ -225,13 +225,11 @@ clean_up(void) user_graph_headings = (char **) free_check_null(user_graph_headings); #endif /* master_isotope */ - for (i = 0; i < count_master_isotope; i++) + for (i = 0; i < (int)master_isotope.size(); i++) { - master_isotope[i] = - (struct master_isotope *) free_check_null(master_isotope[i]); + master_isotope[i] = (struct master_isotope *) free_check_null(master_isotope[i]); } - master_isotope = - (struct master_isotope **) free_check_null(master_isotope); + //master_isotope = (struct master_isotope **) free_check_null(master_isotope); hdestroy_multi(master_isotope_hash_table); master_isotope_hash_table = NULL; @@ -320,7 +318,7 @@ clean_up(void) count_phases = 0; count_s = 0; count_logk = 0; - count_master_isotope = 0; + //count_master_isotope = 0; count_rates = 0; count_inverse = 0; count_save_values = 0; diff --git a/tidy.cpp b/tidy.cpp index 665e8a5f..be3f71b3 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -5505,7 +5505,7 @@ tidy_master_isotope(void) int i; struct master *master_ptr; - for (i = 0; i < count_master_isotope; i++) + for (i = 0; i < (int)master_isotope.size(); i++) { /* * Mark master species list as minor isotope From 76da4f89bc0265351bd293d29bb66800d8cf01c1 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 10:21:07 -0600 Subject: [PATCH 07/34] finished master_isotope --- Phreeqc.cpp | 9 --------- Phreeqc.h | 5 ----- isotopes.cpp | 8 -------- mainsubs.cpp | 3 --- structures.cpp | 1 - 5 files changed, 26 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 4236a163..766a0ba2 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -978,9 +978,6 @@ void Phreeqc::init(void) /* ---------------------------------------------------------------------- * ISOTOPES * ---------------------------------------------------------------------- */ - //count_master_isotope = 0; - //master_isotope = NULL; - //max_master_isotope = MAX_ELTS; initial_solution_isotopes = FALSE; calculate_value_hash_table = NULL; count_isotope_ratio = 0; @@ -2271,12 +2268,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) /* ---------------------------------------------------------------------- * ISOTOPES * ---------------------------------------------------------------------- */ - /* - count_master_isotope = 0; - master_isotope = NULL; - max_master_isotope = MAX_ELTS; - */ - for (int i = 0; i < (int)pSrc->master_isotope.size(); i++) { struct master_isotope *master_isotope_ptr = master_isotope_store(pSrc->master_isotope[i]->name, FALSE); diff --git a/Phreeqc.h b/Phreeqc.h index a261d851..03698287 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1725,11 +1725,6 @@ protected: /* ---------------------------------------------------------------------- * ISOTOPES * ---------------------------------------------------------------------- */ - //struct name_coef match_tokens[50]; - //int count_match_tokens; - //int count_master_isotope; - //struct master_isotope **master_isotope; - //int max_master_isotope; std::vector master_isotope; int initial_solution_isotopes; std::vector calculate_value; diff --git a/isotopes.cpp b/isotopes.cpp index d6f30cba..d5585d03 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -478,7 +478,6 @@ add_isotopes(cxxSolution &solution_ref) /* * zero out isotopes */ - //for (i = 0; i < count_master_isotope; i++) for (i = 0; i < (int)master_isotope.size(); i++) { master_isotope[i]->moles = 0; @@ -1351,13 +1350,6 @@ master_isotope_store(const char *name, int replace_if_found) } else { - //n = count_master_isotope++; - ///* make sure there is space in s */ - //if (count_master_isotope >= max_master_isotope) - //{ - // space((void **) ((void *) &master_isotope), count_master_isotope, - // &max_master_isotope, sizeof(struct master_isotope *)); - //} n = (int)master_isotope.size(); master_isotope.resize((size_t)n + 1); /* Make new master_isotope structure */ diff --git a/mainsubs.cpp b/mainsubs.cpp index 6e49dddd..d069c736 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -98,9 +98,6 @@ initialize(void) space((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); - //space((void **) ((void *) &master_isotope), INIT, &max_master_isotope, - // sizeof(struct master_isotope *)); - /* * Create hash tables */ diff --git a/structures.cpp b/structures.cpp index 79d43539..de7c1e50 100644 --- a/structures.cpp +++ b/structures.cpp @@ -318,7 +318,6 @@ clean_up(void) count_phases = 0; count_s = 0; count_logk = 0; - //count_master_isotope = 0; count_rates = 0; count_inverse = 0; count_save_values = 0; From ba2601a32fd1d236da21972025e902e89dccc715 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 10:36:07 -0600 Subject: [PATCH 08/34] vector isotope_ratio --- Phreeqc.cpp | 5 +---- Phreeqc.h | 4 +--- basicsubs.cpp | 8 ++++---- isotopes.cpp | 13 ++++--------- mainsubs.cpp | 6 +----- structures.cpp | 5 ++--- tidy.cpp | 2 +- 7 files changed, 14 insertions(+), 29 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 766a0ba2..235d0ac9 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -980,9 +980,6 @@ void Phreeqc::init(void) * ---------------------------------------------------------------------- */ initial_solution_isotopes = FALSE; calculate_value_hash_table = NULL; - count_isotope_ratio = 0; - isotope_ratio = 0; - max_isotope_ratio = MAX_ELTS; isotope_ratio_hash_table = 0; count_isotope_alpha = 0; isotope_alpha = 0; @@ -2308,7 +2305,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } } - for (int i = 0; i < pSrc->count_isotope_ratio; i++) + for (int i = 0; i < (int)pSrc->isotope_ratio.size(); i++) { struct isotope_ratio *isotope_ratio_ptr = isotope_ratio_store(pSrc->isotope_ratio[i]->name, FALSE); isotope_ratio_ptr->name = string_hsave(pSrc->isotope_ratio[i]->name); diff --git a/Phreeqc.h b/Phreeqc.h index 03698287..00d2ed9a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1729,9 +1729,7 @@ protected: int initial_solution_isotopes; std::vector calculate_value; HashTable *calculate_value_hash_table; - int count_isotope_ratio; - struct isotope_ratio **isotope_ratio; - int max_isotope_ratio; + std::vector isotope_ratio; HashTable *isotope_ratio_hash_table; int count_isotope_alpha; struct isotope_alpha **isotope_alpha; diff --git a/basicsubs.cpp b/basicsubs.cpp index f66ef510..20ed0e80 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -4011,7 +4011,7 @@ iso_value(const char *total_name) strcpy(token, ""); strcpy(my_total_name, total_name); while (replace(" ","_",my_total_name)); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; @@ -4025,7 +4025,7 @@ iso_value(const char *total_name) strcat(token,"R("); strcat(token,my_total_name); strcat(token,")"); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; @@ -4047,7 +4047,7 @@ iso_unit(const char *total_name) strcpy(my_total_name, total_name); while (replace(" ","_",my_total_name)); strcpy(unit, "unknown"); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; @@ -4066,7 +4066,7 @@ iso_unit(const char *total_name) strcat(token,"R("); strcat(token,my_total_name); strcat(token,")"); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; diff --git a/isotopes.cpp b/isotopes.cpp index d5585d03..8e0db9b2 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -1011,7 +1011,7 @@ print_isotope_ratios(void) output_msg(sformatf( "%25s\t%12s\t%15s\n\n", "Isotope Ratio", "Ratio", "Input Units")); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; @@ -1135,7 +1135,7 @@ calculate_values(void) } if (pr.isotope_ratios == TRUE) { - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { isotope_ratio_ptr = isotope_ratio[j]; master_isotope_ptr = @@ -1699,13 +1699,8 @@ isotope_ratio_store(const char *name, int replace_if_found) } else { - n = count_isotope_ratio++; - /* make sure there is space in s */ - if (count_isotope_ratio >= max_isotope_ratio) - { - space((void **) ((void *) &isotope_ratio), count_isotope_ratio, - &max_isotope_ratio, sizeof(struct isotope_ratio *)); - } + n = (int)isotope_ratio.size(); + isotope_ratio.resize((size_t)n + 1); /* Make new isotope_ratio structure */ isotope_ratio[n] = isotope_ratio_alloc(); isotope_ratio_ptr = isotope_ratio[n]; diff --git a/mainsubs.cpp b/mainsubs.cpp index d069c736..6afdfdd8 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -178,11 +178,7 @@ initialize(void) &calculate_value_hash_table); /* isotope_ratio */ - max_isotope_ratio = MAX_ELTS; - count_isotope_ratio = 0; - space((void **) ((void *) &isotope_ratio), INIT, &max_isotope_ratio, - sizeof(struct isotope_ratio *)); - hcreate_multi((unsigned) max_isotope_ratio, &isotope_ratio_hash_table); + hcreate_multi((unsigned) MAX_ELTS, &isotope_ratio_hash_table); /* isotope_value */ max_isotope_alpha = MAX_ELTS; diff --git a/structures.cpp b/structures.cpp index de7c1e50..1ba32193 100644 --- a/structures.cpp +++ b/structures.cpp @@ -243,12 +243,12 @@ clean_up(void) calculate_value_hash_table = NULL; /* isotope_ratio */ - for (i = 0; i < count_isotope_ratio; i++) + for (i = 0; i < (int)isotope_ratio.size(); i++) { isotope_ratio[i] = (struct isotope_ratio *) free_check_null(isotope_ratio[i]); } - isotope_ratio = (struct isotope_ratio **) free_check_null(isotope_ratio); + //isotope_ratio = (struct isotope_ratio **) free_check_null(isotope_ratio); hdestroy_multi(isotope_ratio_hash_table); isotope_ratio_hash_table = NULL; @@ -328,7 +328,6 @@ clean_up(void) llnl_count_bdot = 0; llnl_count_co2_coefs = 0; - count_isotope_ratio = 0; count_isotope_alpha = 0; default_data_base = (char *) free_check_null(default_data_base); diff --git a/tidy.cpp b/tidy.cpp index be3f71b3..603f8f2c 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -5543,7 +5543,7 @@ tidy_isotope_ratios(void) struct master_isotope *master_isotope_ptr; struct calculate_value *calculate_value_ptr; - for (i = 0; i < count_isotope_ratio; i++) + for (i = 0; i < (int)isotope_ratio.size(); i++) { /* * Mark master species list as minor isotope From e8af689a39e441a569dc40109d873608a5a2efb2 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 10:46:23 -0600 Subject: [PATCH 09/34] vector isotope_alpha --- Phreeqc.cpp | 12 ++---------- Phreeqc.h | 4 +--- isotopes.cpp | 13 ++++--------- mainsubs.cpp | 8 ++------ structures.cpp | 5 +---- tidy.cpp | 2 +- 6 files changed, 11 insertions(+), 33 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 235d0ac9..69b43378 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -981,9 +981,6 @@ void Phreeqc::init(void) initial_solution_isotopes = FALSE; calculate_value_hash_table = NULL; isotope_ratio_hash_table = 0; - count_isotope_alpha = 0; - isotope_alpha = 0; - max_isotope_alpha = MAX_ELTS; isotope_alpha_hash_table = 0; @@ -2313,13 +2310,8 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) isotope_ratio_ptr->ratio = pSrc->isotope_ratio[i]->ratio; isotope_ratio_ptr->converted_ratio = pSrc->isotope_ratio[i]->converted_ratio; } - /* - count_isotope_alpha = 0; - isotope_alpha = 0; - max_isotope_alpha = MAX_ELTS; - isotope_alpha_hash_table = 0; - */ - for (int i = 0; i < pSrc->count_isotope_alpha; i++) + + for (int i = 0; i < (int)pSrc->isotope_alpha.size(); i++) { struct isotope_alpha *isotope_alpha_ptr = isotope_alpha_store(pSrc->isotope_alpha[i]->name, FALSE); isotope_alpha_ptr->named_logk = string_hsave(pSrc->isotope_alpha[i]->named_logk); diff --git a/Phreeqc.h b/Phreeqc.h index 00d2ed9a..ee8cd26e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1731,9 +1731,7 @@ protected: HashTable *calculate_value_hash_table; std::vector isotope_ratio; HashTable *isotope_ratio_hash_table; - int count_isotope_alpha; - struct isotope_alpha **isotope_alpha; - int max_isotope_alpha; + std::vector isotope_alpha; HashTable *isotope_alpha_hash_table; int phreeqc_mpi_myself; int first_read_input; diff --git a/isotopes.cpp b/isotopes.cpp index 8e0db9b2..dcc3ed88 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -1076,7 +1076,7 @@ print_isotope_alphas(void) " Isotope Ratio", "Solution alpha", "Solution", (double) tc_x)); - for (j = 0; j < count_isotope_alpha; j++) + for (j = 0; j < (int)isotope_alpha.size(); j++) { if (isotope_alpha[j]->value == MISSING) continue; @@ -1202,7 +1202,7 @@ calculate_values(void) } if (pr.isotope_alphas == TRUE) { - for (j = 0; j < count_isotope_alpha; j++) + for (j = 0; j < (int)isotope_alpha.size(); j++) { isotope_alpha_ptr = isotope_alpha[j]; calculate_value_ptr = calculate_value_search(isotope_alpha_ptr->name); @@ -1856,13 +1856,8 @@ isotope_alpha_store(const char *name, int replace_if_found) } else { - n = count_isotope_alpha++; - /* make sure there is space in s */ - if (count_isotope_alpha >= max_isotope_alpha) - { - space((void **) ((void *) &isotope_alpha), count_isotope_alpha, - &max_isotope_alpha, sizeof(struct isotope_alpha *)); - } + n = (int)isotope_alpha.size(); + isotope_alpha.resize((size_t)n + 1); /* Make new isotope_alpha structure */ isotope_alpha[n] = isotope_alpha_alloc(); isotope_alpha_ptr = isotope_alpha[n]; diff --git a/mainsubs.cpp b/mainsubs.cpp index 6afdfdd8..eb86b22d 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -180,12 +180,8 @@ initialize(void) /* isotope_ratio */ hcreate_multi((unsigned) MAX_ELTS, &isotope_ratio_hash_table); - /* isotope_value */ - max_isotope_alpha = MAX_ELTS; - count_isotope_alpha = 0; - space((void **) ((void *) &isotope_alpha), INIT, &max_isotope_alpha, - sizeof(struct isotope_alpha *)); - hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table); + /* isotope_alpha */ + hcreate_multi((unsigned) MAX_ELTS, &isotope_alpha_hash_table); /* * define constant named log_k diff --git a/structures.cpp b/structures.cpp index 1ba32193..988b05a6 100644 --- a/structures.cpp +++ b/structures.cpp @@ -253,12 +253,11 @@ clean_up(void) isotope_ratio_hash_table = NULL; /* isotope_alpha */ - for (i = 0; i < count_isotope_alpha; i++) + for (i = 0; i < (int)isotope_alpha.size(); i++) { isotope_alpha[i] = (struct isotope_alpha *) free_check_null(isotope_alpha[i]); } - isotope_alpha = (struct isotope_alpha **) free_check_null(isotope_alpha); hdestroy_multi(isotope_alpha_hash_table); isotope_alpha_hash_table = NULL; @@ -328,8 +327,6 @@ clean_up(void) llnl_count_bdot = 0; llnl_count_co2_coefs = 0; - count_isotope_alpha = 0; - default_data_base = (char *) free_check_null(default_data_base); sformatf_buffer = (char *) free_check_null(sformatf_buffer); return (OK); diff --git a/tidy.cpp b/tidy.cpp index 603f8f2c..83af5b16 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -5589,7 +5589,7 @@ tidy_isotope_alphas(void) struct calculate_value *calculate_value_ptr; struct logk *logk_ptr; - for (i = 0; i < count_isotope_alpha; i++) + for (i = 0; i < (int)isotope_alpha.size(); i++) { /* * Mark master species list as minor isotope From f2c64fef86308193dfda3468e33ed4bdd64a3dd0 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 12:12:46 -0600 Subject: [PATCH 10/34] vector elements --- Phreeqc.cpp | 23 +++++------------------ Phreeqc.h | 5 +---- mainsubs.cpp | 5 +---- structures.cpp | 22 +++++++--------------- tidy.cpp | 7 +++---- transport.cpp | 2 +- 6 files changed, 18 insertions(+), 46 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 69b43378..b6ac835c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -711,9 +711,6 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Elements *---------------------------------------------------------------------- */ - elements = NULL; - count_elements = 0; - max_elements = MAX_ELEMENTS; element_h_one = NULL; /*---------------------------------------------------------------------- * Element List @@ -1644,25 +1641,15 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) /*---------------------------------------------------------------------- * Elements *---------------------------------------------------------------------- */ - //max_elements = pSrc->max_elements; - //elements = (struct element **) free_check_null(elements); - //elements = (struct element **) PHRQ_malloc((size_t)max_elements * sizeof(struct element)); - space((void **)((void *)&elements), pSrc->max_elements, &max_elements, - sizeof(struct element *)); - count_elements = 0; - for (int i = 0; i < pSrc->count_elements; i++) + for (int i = 0; i < (int)pSrc->elements.size(); i++) { - string_hsave(pSrc->elements[i]->name); - struct element *elt_ptr = element_store(pSrc->elements[i]->name); + + const char * ptr = string_hsave(pSrc->elements[i]->name); + struct element *elt_ptr = element_store(ptr); elt_ptr->gfw = pSrc->elements[i]->gfw; } element_h_one = element_store("H(1)"); - /* - elements = NULL; - count_elements = 0; - max_elements = MAX_ELEMENTS; - element_h_one = NULL; - */ + /*---------------------------------------------------------------------- * Element List *---------------------------------------------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index ee8cd26e..8f85741e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1457,10 +1457,7 @@ protected: /*---------------------------------------------------------------------- * Elements *---------------------------------------------------------------------- */ - - struct element **elements; - int count_elements; - int max_elements; + std::vector elements; struct element *element_h_one; /*---------------------------------------------------------------------- diff --git a/mainsubs.cpp b/mainsubs.cpp index eb86b22d..80acd672 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -60,9 +60,6 @@ initialize(void) cell_data[i].print = FALSE; } - space((void **) ((void *) &elements), INIT, &max_elements, - sizeof(struct element *)); - space((void **) ((void *) &elt_list), INIT, &max_elts, sizeof(struct elt_list)); @@ -103,7 +100,7 @@ initialize(void) */ hcreate_multi((unsigned) max_logk, &logk_hash_table); hcreate_multi((unsigned) MAX_ELTS, &master_isotope_hash_table); - hcreate_multi((unsigned) max_elements, &elements_hash_table); + hcreate_multi((unsigned) MAX_ELTS, &elements_hash_table); hcreate_multi((unsigned) max_s, &species_hash_table); hcreate_multi((unsigned) max_phases, &phases_hash_table); // one save_values diff --git a/structures.cpp b/structures.cpp index 988b05a6..8a008813 100644 --- a/structures.cpp +++ b/structures.cpp @@ -81,11 +81,10 @@ clean_up(void) /* elements */ - for (j = 0; j < count_elements; j++) + for (j = 0; j < (int)elements.size(); j++) { elements[j] = (struct element *) free_check_null(elements[j]); } - elements = (struct element **) free_check_null(elements); /* solutions */ Rxn_solution_map.clear(); @@ -312,7 +311,6 @@ clean_up(void) #endif title_x = (char *) free_check_null(title_x); last_title_x.clear(); - count_elements = 0; count_master = 0; count_phases = 0; count_s = 0; @@ -407,7 +405,6 @@ element_store(const char *element) * Returns: * The address of an elt structure that contains the element data. */ - int n; struct element *elts_ptr; ENTRY item, *found_item; char token[MAX_LENGTH]; @@ -428,8 +425,9 @@ element_store(const char *element) * Save new elt structure and return pointer to it */ /* make sure there is space in elements */ - elements[count_elements] = - (struct element *) PHRQ_malloc((size_t) sizeof(struct element)); + size_t count_elements = elements.size(); + elements.resize(count_elements + 1); + elements[count_elements] = (struct element *) PHRQ_malloc((size_t) sizeof(struct element)); if (elements[count_elements] == NULL) malloc_error(); /* set name pointer in elements structure */ @@ -438,24 +436,18 @@ element_store(const char *element) elements[count_elements]->master = NULL; elements[count_elements]->primary = NULL; elements[count_elements]->gfw = 0.0; - n = count_elements++; - if (count_elements >= max_elements) - { - space((void **) ((void *) &elements), count_elements, &max_elements, - sizeof(struct element *)); - } /* * Update hash table */ - item.key = elements[n]->name; - item.data = (void *) elements[n]; + item.key = elements[count_elements]->name; + item.data = (void *) elements[count_elements]; found_item = hsearch_multi(elements_hash_table, item, ENTER); if (found_item == NULL) { error_string = sformatf( "Hash table error in element_store."); error_msg(error_string, CONTINUE); } - return (elements[n]); + return (elements[count_elements]); } /* ********************************************************************** diff --git a/tidy.cpp b/tidy.cpp index 83af5b16..44e19e2b 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -154,11 +154,10 @@ tidy_model(void) /* master species */ qsort(master, (unsigned) count_master, sizeof(struct master *), master_compare); - /* elements */ - qsort(elements, (size_t) count_elements, (size_t) sizeof(struct element *), element_compare); + qsort(elements.data(), elements.size(), sizeof(struct element *), element_compare); /* phases */ - qsort(phases, (size_t) count_phases, (size_t) sizeof(struct phase *), phase_compare); + qsort(phases, (size_t) count_phases, sizeof(struct phase *), phase_compare); } @@ -2429,7 +2428,7 @@ tidy_species(void) /* * Set pointer in element to master species */ - for (i = 0; i < count_elements; i++) + for (i = 0; i < (int)elements.size(); i++) { elements[i]->master = master_bsearch(elements[i]->name); if (elements[i]->master == NULL) diff --git a/transport.cpp b/transport.cpp index 0bacb84b..c2e84bc0 100644 --- a/transport.cpp +++ b/transport.cpp @@ -135,7 +135,7 @@ transport(void) ct[i].m_s = NULL; ct[i].v_m_size = ct[i].J_ij_size = ct[i].m_s_size = 0; } - count_moles_added = count_elements; + count_moles_added = (int)elements.size(); moles_added = (struct MOLES_ADDED *) PHRQ_malloc((size_t) (count_moles_added)* sizeof(struct MOLES_ADDED)); if (moles_added == NULL) malloc_error(); From e7c78a88ad279402f04fb65fb80ad442e74128f6 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 12:33:49 -0600 Subject: [PATCH 11/34] vector phases --- Phreeqc.cpp | 12 ++---------- Phreeqc.h | 4 +--- basicsubs.cpp | 2 +- inverse.cpp | 2 +- mainsubs.cpp | 5 +---- prep.cpp | 4 ++-- print.cpp | 2 +- structures.cpp | 33 +++++++++------------------------ tidy.cpp | 6 +++--- 9 files changed, 21 insertions(+), 49 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index b6ac835c..f364038e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -743,9 +743,7 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Phases *---------------------------------------------------------------------- */ - phases = NULL; - count_phases = 0; - max_phases = MAX_PHASES; + /*---------------------------------------------------------------------- * Master species *---------------------------------------------------------------------- */ @@ -1810,13 +1808,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) /*---------------------------------------------------------------------- * Phases *---------------------------------------------------------------------- */ - /* - phases = NULL; - count_phases = 0; - max_phases = MAX_PHASES; - */ - count_phases = 0; - for (int i = 0; i < pSrc->count_phases; i++) + for (int i = 0; i < (int)pSrc->phases.size(); i++) { struct phase *phase_ptr = phase_store(pSrc->phases[i]->name); memcpy(phase_ptr, pSrc->phases[i], sizeof(struct phase)); diff --git a/Phreeqc.h b/Phreeqc.h index 8f85741e..d54d2a6a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1503,9 +1503,7 @@ protected: /*---------------------------------------------------------------------- * Phases *---------------------------------------------------------------------- */ - struct phase **phases; - int count_phases; - int max_phases; + std::vector phases; /*---------------------------------------------------------------------- * Master species diff --git a/basicsubs.cpp b/basicsubs.cpp index 20ed0e80..5fd5d8d1 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3038,7 +3038,7 @@ system_total_si(void) char name[MAX_LENGTH]; sys_tot = -999.9; - for (i = 0; i < count_phases; i++) + for (i = 0; i < (int)phases.size(); i++) { if (phases[i]->in == FALSE || phases[i]->type != SOLID) continue; diff --git a/inverse.cpp b/inverse.cpp index 13ccc69f..ed8b8629 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -2068,7 +2068,7 @@ print_model(struct inverse *inv_ptr) (double)d1, (double)d2, (double)d3, inv_ptr->phases[i - col_phases].phase->formula)); i1 = 0; - for (; i1 < count_phases; i1++) + for (; i1 < (int)phases.size(); i1++) { if (Utilities::strcmp_nocase(phases[i1]->name, col_name[i])) continue; diff --git a/mainsubs.cpp b/mainsubs.cpp index 80acd672..9c8d98b9 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -85,9 +85,6 @@ initialize(void) stag_data->th_m = 0; stag_data->th_im = 0; - space((void **) ((void *) &phases), INIT, &max_phases, - sizeof(struct phase *)); - space((void **) ((void *) &trxn.token), INIT, &max_trxn, sizeof(struct rxn_token_temp)); @@ -102,7 +99,7 @@ initialize(void) hcreate_multi((unsigned) MAX_ELTS, &master_isotope_hash_table); hcreate_multi((unsigned) MAX_ELTS, &elements_hash_table); hcreate_multi((unsigned) max_s, &species_hash_table); - hcreate_multi((unsigned) max_phases, &phases_hash_table); + hcreate_multi((unsigned) MAX_PHASES, &phases_hash_table); // one save_values save_values = (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); diff --git a/prep.cpp b/prep.cpp index a081e720..63c6e822 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1383,7 +1383,7 @@ build_model(void) /* * Rewrite phases to current master species */ - for (i = 0; i < count_phases; i++) + for (i = 0; i < (int)phases.size(); i++) { count_trxn = 0; trxn_add_phase(phases[i]->rxn_s, 1.0, FALSE); @@ -5732,7 +5732,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ /* * Calculate log k for all pure phases */ - for (i = 0; i < count_phases; i++) + for (i = 0; i < (int)phases.size(); i++) { if (phases[i]->in == TRUE) { diff --git a/print.cpp b/print.cpp index ffdb8376..1cc8f4ea 100644 --- a/print.cpp +++ b/print.cpp @@ -1253,7 +1253,7 @@ print_saturation_indices(void) output_msg(sformatf(" %-15s%9s%8s%9s%3d%4s%3d%4s\n\n", "Phase", "SI**", "log IAP", "log K(", int(tk_x), " K, ", int(floor(patm_x + 0.5)), " atm)")); - for (i = 0; i < count_phases; i++) + for (i = 0; i < (int)phases.size(); i++) { if (phases[i]->in == FALSE || phases[i]->type != SOLID) continue; diff --git a/structures.cpp b/structures.cpp index 8a008813..ee8ba3fb 100644 --- a/structures.cpp +++ b/structures.cpp @@ -123,12 +123,11 @@ clean_up(void) /* phases */ - for (j = 0; j < count_phases; j++) + for (j = 0; j < (int)phases.size(); j++) { phase_free(phases[j]); phases[j] = (struct phase *) free_check_null(phases[j]); } - phases = (struct phase **) free_check_null(phases); /* inverse */ for (j = 0; j < count_inverse; j++) @@ -312,7 +311,6 @@ clean_up(void) title_x = (char *) free_check_null(title_x); last_title_x.clear(); count_master = 0; - count_phases = 0; count_s = 0; count_logk = 0; count_rates = 0; @@ -1300,15 +1298,8 @@ phase_delete(int i) * Input: i, number of phase * Return: OK */ - int j; - phase_free(phases[i]); - phases[i] = (struct phase *) free_check_null(phases[i]); - for (j = i; j < (count_phases - 1); j++) - { - phases[j] = phases[j + 1]; - } - count_phases--; + phases.erase(phases.begin() + (size_t)i); return (OK); } @@ -1356,13 +1347,13 @@ phase_bsearch(const char *ptr, int *j, int print) void *void_ptr; void_ptr = NULL; - if (count_phases > 0) + if ((int)phases.size() > 0) { void_ptr = (void *) bsearch((char *) ptr, - (char *) phases, - (size_t) count_phases, - (size_t) sizeof(struct phase *), phase_compare_string); + (char *) phases.data(), + phases.size(), + sizeof(struct phase *), phase_compare_string); } if (void_ptr == NULL && print == TRUE) { @@ -1376,7 +1367,7 @@ phase_bsearch(const char *ptr, int *j, int print) return (NULL); } - *j = (int) ((struct phase **) void_ptr - phases); + *j = (int) ((struct phase **) void_ptr - phases.data()); return (*(struct phase **) void_ptr); } @@ -1460,7 +1451,6 @@ phase_store(const char *name) * If phase existed, it is reinitialized. The structure returned * contains only the name of the phase. */ - int n; struct phase *phase_ptr; ENTRY item, *found_item; char token[MAX_LENGTH]; @@ -1487,13 +1477,8 @@ phase_store(const char *name) /* * Make new phase structure and return pointer to it */ - /* make sure there is space in phases */ - n = count_phases++; - if (count_phases >= max_phases) - { - space((void **) ((void *) &phases), count_phases, &max_phases, - sizeof(struct phase *)); - } + size_t n = (int)phases.size(); + phases.resize(n + 1); phases[n] = phase_alloc(); /* set name in phase structure */ phases[n]->name = string_hsave(name); diff --git a/tidy.cpp b/tidy.cpp index 44e19e2b..0625df42 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -157,7 +157,7 @@ tidy_model(void) /* elements */ qsort(elements.data(), elements.size(), sizeof(struct element *), element_compare); /* phases */ - qsort(phases, (size_t) count_phases, sizeof(struct phase *), phase_compare); + qsort(phases.data(), phases.size(), sizeof(struct phase *), phase_compare); } @@ -1487,7 +1487,7 @@ tidy_phases(void) /* * Fix log Ks first, so they can possibly be added to other phase equations */ - for (i = 0; i < count_phases; i++) + for (i = 0; i < (int)phases.size(); i++) { select_log_k_expression(phases[i]->logk, phases[i]->rxn->logk); add_other_logk(phases[i]->rxn->logk, phases[i]->count_add_logk, @@ -1498,7 +1498,7 @@ tidy_phases(void) /* * Rewrite all phases to secondary species */ - for (i = 0; i < count_phases; i++) + for (i = 0; i < (int)phases.size(); i++) { /* * Rewrite equation From de1ba62395e62c05a2ea225b782dd321538539e2 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 13:21:14 -0600 Subject: [PATCH 12/34] vector s --- Phreeqc.cpp | 12 +---------- Phreeqc.h | 4 +--- mainsubs.cpp | 4 +--- model.cpp | 2 +- pitzer.cpp | 57 +++++++++++++++++++++++++------------------------- prep.cpp | 6 +++--- sit.cpp | 48 +++++++++++++++++++++--------------------- step.cpp | 2 +- structures.cpp | 19 ++++------------- tidy.cpp | 10 ++++----- 10 files changed, 69 insertions(+), 95 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index f364038e..19e24943 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -726,9 +726,6 @@ void Phreeqc::init(void) max_logk = MAX_S; moles_per_kilogram_string= NULL; pe_string = NULL; - s = NULL; - count_s = 0; - max_s = MAX_S; // auto s_diff_layer; s_x = NULL; count_s_x = 0; @@ -1717,14 +1714,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } count_logk = pSrc->count_logk; // s, species - count_s = 0; - //max_s = pSrc->max_s; - - //s = (struct species **) free_check_null(s); - //s = (struct species **) PHRQ_malloc(sizeof(struct species *)*size_t(max_s)); - - space((void **)((void *)&s), pSrc->max_s, &max_s, sizeof(struct species *)); - for (int i = 0; i < pSrc->count_s; i++) + for (int i = 0; i < (int)pSrc->s.size(); i++) { struct species *s_ptr = s_store(pSrc->s[i]->name, pSrc->s[i]->z, FALSE); memcpy(s_ptr, pSrc->s[i], sizeof(struct species)); diff --git a/Phreeqc.h b/Phreeqc.h index d54d2a6a..fb793c03 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1483,9 +1483,7 @@ protected: char *moles_per_kilogram_string; char *pe_string; - struct species **s; - int count_s; - int max_s; + std::vector s; std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; struct species **s_x; diff --git a/mainsubs.cpp b/mainsubs.cpp index 9c8d98b9..690b2573 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -88,8 +88,6 @@ initialize(void) space((void **) ((void *) &trxn.token), INIT, &max_trxn, sizeof(struct rxn_token_temp)); - space((void **) ((void *) &s), INIT, &max_s, sizeof(struct species *)); - space((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); /* @@ -98,7 +96,7 @@ initialize(void) hcreate_multi((unsigned) max_logk, &logk_hash_table); hcreate_multi((unsigned) MAX_ELTS, &master_isotope_hash_table); hcreate_multi((unsigned) MAX_ELTS, &elements_hash_table); - hcreate_multi((unsigned) max_s, &species_hash_table); + hcreate_multi((unsigned) MAX_S, &species_hash_table); hcreate_multi((unsigned) MAX_PHASES, &phases_hash_table); // one save_values save_values = diff --git a/model.cpp b/model.cpp index dcb5736f..cda8234d 100644 --- a/model.cpp +++ b/model.cpp @@ -5028,7 +5028,7 @@ surface_model(void) if (dl_type_x != cxxSurface::NO_DL && same_model == FALSE) { s_diff_layer.clear(); - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { std::map < std::string, cxxSpeciesDL > dl; s_diff_layer.push_back(dl); diff --git a/pitzer.cpp b/pitzer.cpp index c911633e..d6209f3b 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -65,19 +65,18 @@ pitzer_tidy(void) */ if (spec != NULL) spec = (struct species **) free_check_null(spec); - spec = - (struct species **) - PHRQ_malloc((size_t) (3 * count_s * sizeof(struct species *))); + spec = (struct species **) + PHRQ_malloc((size_t) (3 * s.size() * sizeof(struct species *))); if (spec == NULL) malloc_error(); - for (i = 0; i < 3 * count_s; i++) + for (i = 0; i < 3 * (int)s.size(); i++) spec[i] = NULL; cations = spec; - neutrals = &(spec[count_s]); - anions = &(spec[2 * count_s]); - MAXCATIONS = count_s; - FIRSTANION = 2 * count_s; - MAXNEUTRAL = count_s; + neutrals = &(spec[s.size()]); + anions = &(spec[2 * s.size()]); + MAXCATIONS = (int)s.size(); + FIRSTANION = 2 * (int)s.size(); + MAXNEUTRAL = (int)s.size(); count_cations = 0; count_anions = 0; count_neutrals = 0; @@ -88,22 +87,22 @@ pitzer_tidy(void) */ if (IPRSNT != NULL) IPRSNT = (int *) free_check_null(IPRSNT); - IPRSNT = (int *) PHRQ_malloc((size_t) (3 * count_s * sizeof(int))); + IPRSNT = (int *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(int))); if (IPRSNT == NULL) malloc_error(); if (M != NULL) M = (LDBLE *) free_check_null(M); - M = (LDBLE *) PHRQ_malloc((size_t) (3 * count_s * sizeof(LDBLE))); + M = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE))); if (M == NULL) malloc_error(); if (LGAMMA != NULL) LGAMMA = (LDBLE *) free_check_null(LGAMMA); - LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * count_s * sizeof(LDBLE))); + LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE))); if (LGAMMA == NULL) malloc_error(); - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { if (s[i] == s_eminus) continue; @@ -159,9 +158,9 @@ pitzer_tidy(void) } } - for (i = 2 * count_s; i < 2 * count_s + count_anions - 1; i++) + for (i = 2 * (int)s.size(); i < 2 * (int)s.size() + count_anions - 1; i++) { - for (j = i + 1; j < 2 * count_s + count_anions; j++) + for (j = i + 1; j < 2 * (int)s.size() + count_anions; j++) { sprintf(line, "%s %s 1", spec[i]->name, spec[j]->name); pzp_ptr = pitz_param_read(line, 2); @@ -574,7 +573,7 @@ ISPEC(const char *name) */ { int i; - for (i = 0; i < 3 * count_s; i++) + for (i = 0; i < 3 * (int)s.size(); i++) { if (spec[i] == NULL) continue; @@ -923,7 +922,7 @@ pitzer(void) C TRANSFER DATA FROM TO M C */ - for (i = 0; i < 3 * count_s; i++) + for (i = 0; i < 3 * (int)s.size(); i++) { IPRSNT[i] = FALSE; M[i] = 0.0; @@ -954,7 +953,7 @@ pitzer(void) C */ PTEMP(TK); - for (i = 0; i < 2 * count_s + count_anions; i++) + for (i = 0; i < 2 * (int)s.size() + count_anions; i++) { LGAMMA[i] = 0.0; if (IPRSNT[i] == TRUE) @@ -1155,7 +1154,7 @@ pitzer(void) F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; } - for (i = 2 * count_s; i < 2 * count_s + count_anions; i++) + for (i = 2 * (int)s.size(); i < 2 * (int)s.size() + count_anions; i++) { if (!IPRSNT[i]) continue; @@ -1176,7 +1175,7 @@ pitzer(void) C CORRECTED ERROR IN PHIMAC, NOVEMBER, 1989 C */ - for (i = 0; i < 2 * count_s + count_anions; i++) + for (i = 0; i < 2 * (int)s.size() + count_anions; i++) { if (IPRSNT[i] == TRUE) { @@ -1198,7 +1197,7 @@ pitzer(void) */ /*s_h2o->la=log10(AW); */ mu_x = I; - for (i = 0; i < 2 * count_s + count_anions; i++) + for (i = 0; i < 2 * (int)s.size() + count_anions; i++) { if (IPRSNT[i] == FALSE) continue; @@ -2627,12 +2626,12 @@ pitzer_make_lists(void) max = count_cations; break; case 1: - min = count_s; - max = count_s + count_neutrals; + min = (int)s.size(); + max = (int)s.size() + count_neutrals; break; case 2: - min = 2*count_s; - max = 2*count_s + count_anions; + min = 2* (int)s.size(); + max = 2* (int)s.size() + count_anions; break; } for (int i = min; i < max; i++) @@ -2647,19 +2646,19 @@ pitzer_make_lists(void) continue; IPRSNT[i] = TRUE; s_list.push_back(i); - if (i < count_s) + if (i < (int)s.size()) { cation_list.push_back(i); } - if (i >= count_s && i < 2*count_s) + if (i >= (int)s.size() && i < 2* (int)s.size()) { neutral_list.push_back(i); } - if (i >= 2*count_s) + if (i >= 2* (int)s.size()) { anion_list.push_back(i); } - if (i < count_s || i >= 2*count_s) + if (i < (int)s.size() || i >= 2* (int)s.size()) { ion_list.push_back(i); } diff --git a/prep.cpp b/prep.cpp index 63c6e822..e966eed8 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1205,7 +1205,7 @@ build_model(void) count_s_x = 0; compute_gfw("H2O", &gfw_water); gfw_water *= 0.001; - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { if (s[i]->type > H2O && s[i]->type != EX && s[i]->type != SURF) continue; @@ -1810,7 +1810,7 @@ clear(void) */ solution_ptr = use.Get_solution_ptr(); - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { s[i]->in = FALSE; } @@ -4832,7 +4832,7 @@ setup_unknowns(void) max_unknowns++; if (pitzer_model == TRUE || sit_model == TRUE) { - max_unknowns += count_s; + max_unknowns += (int)s.size(); } /* diff --git a/sit.cpp b/sit.cpp index e636e423..22fbdd42 100644 --- a/sit.cpp +++ b/sit.cpp @@ -39,16 +39,16 @@ sit_tidy(void) * allocate pointers to species structures */ if (spec != NULL) spec = (struct species **) free_check_null(spec); - spec = (struct species **) PHRQ_malloc((size_t) (3 * count_s * sizeof(struct species *))); + spec = (struct species **) PHRQ_malloc((size_t) (3 * s.size() * sizeof(struct species *))); if (spec == NULL) malloc_error(); - for (i = 0; i < 3 * count_s; i++) spec[i] = NULL; + for (i = 0; i < 3 * (int)s.size(); i++) spec[i] = NULL; cations = spec; - neutrals = &(spec[count_s]); - anions = &(spec[2 * count_s]); - sit_MAXCATIONS = count_s; - sit_FIRSTANION = 2 * count_s; - sit_MAXNEUTRAL = count_s; + neutrals = &(spec[s.size()]); + anions = &(spec[2 * s.size()]); + sit_MAXCATIONS = (int)s.size(); + sit_FIRSTANION = 2 * (int)s.size(); + sit_MAXNEUTRAL = (int)s.size(); sit_count_cations = 0; sit_count_anions = 0; sit_count_neutrals = 0; @@ -57,17 +57,17 @@ sit_tidy(void) * allocate other arrays for SIT */ if (sit_IPRSNT != NULL) sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); - sit_IPRSNT = (int *) PHRQ_malloc((size_t) (3 * count_s * sizeof(int))); + sit_IPRSNT = (int *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(int))); if (sit_IPRSNT == NULL) malloc_error(); if (sit_M != NULL) sit_M = (LDBLE *) free_check_null(sit_M); - sit_M = (LDBLE *) PHRQ_malloc((size_t) (3 * count_s * sizeof(LDBLE))); + sit_M = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE))); if (sit_M == NULL) malloc_error(); if (sit_LGAMMA != NULL) sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); - sit_LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * count_s * sizeof(LDBLE))); + sit_LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE))); if (sit_LGAMMA == NULL) malloc_error(); - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { if (s[i] == s_eminus) continue; @@ -149,7 +149,7 @@ sit_ISPEC(const char *name) */ { int i; - for (i = 0; i < 3 * count_s; i++) + for (i = 0; i < 3 * (int)s.size(); i++) { if (spec[i] == NULL) continue; @@ -340,7 +340,7 @@ sit(void) sit_M[i] = 0.0; } } - //for (i = 0; i < 3 * count_s; i++) + //for (i = 0; i < 3 * (int)s.size(); i++) //{ // sit_IPRSNT[i] = FALSE; // sit_M[i] = 0.0; @@ -368,7 +368,7 @@ sit(void) XI = XI + sit_M[i] * spec[i]->z * spec[i]->z; OSUM = OSUM + sit_M[i]; } - //for (i = 0; i < 2 * count_s + sit_count_anions; i++) + //for (i = 0; i < 2 * (int)s.size() + sit_count_anions; i++) //{ // sit_LGAMMA[i] = 0.0; // if (sit_IPRSNT[i] == TRUE) @@ -462,7 +462,7 @@ sit(void) // z0 = spec[i]->z; // sit_LGAMMA[i] += z0 * z0 * F; //} - //for (i = 2 * count_s; i < 2 * count_s + sit_count_anions; i++) + //for (i = 2 * (int)s.size(); i < 2 * (int)s.size() + sit_count_anions; i++) //{ // z0 = spec[i]->z; // sit_LGAMMA[i] += z0 * z0 * F; @@ -488,7 +488,7 @@ sit(void) int i = s_list[j]; spec[i]->lg_pitzer = sit_LGAMMA[i]; } -// for (i = 0; i < 2 * count_s + sit_count_anions; i++) +// for (i = 0; i < 2 * (int)s.size() + sit_count_anions; i++) // { // if (sit_IPRSNT[i] == FALSE) continue; // spec[i]->lg_pitzer = sit_LGAMMA[i]; @@ -1447,12 +1447,12 @@ sit_make_lists(void) max = sit_count_cations; break; case 1: - min = count_s; - max = count_s + sit_count_neutrals; + min = (int)s.size(); + max = (int)s.size() + sit_count_neutrals; break; case 2: - min = 2*count_s; - max = 2*count_s + sit_count_anions; + min = 2*(int)s.size(); + max = 2*(int)s.size() + sit_count_anions; break; } for (int i = min; i < max; i++) @@ -1466,19 +1466,19 @@ sit_make_lists(void) continue; sit_IPRSNT[i] = TRUE; s_list.push_back(i); - if (i < count_s) + if (i < (int)s.size()) { cation_list.push_back(i); } - if (i >= count_s && i < 2*count_s) + if (i >= (int)s.size() && i < 2*(int)s.size()) { neutral_list.push_back(i); } - if (i >= 2*count_s) + if (i >= 2*(int)s.size()) { anion_list.push_back(i); } - if (i < count_s || i >= 2*count_s) + if (i < (int)s.size() || i >= 2*(int)s.size()) { ion_list.push_back(i); } diff --git a/step.cpp b/step.cpp index e4d83ac6..19094bcf 100644 --- a/step.cpp +++ b/step.cpp @@ -326,7 +326,7 @@ xsolution_zero(void) } if (pitzer_model == TRUE || sit_model == TRUE) { - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { s[i]->lg = 0.0; } diff --git a/structures.cpp b/structures.cpp index ee8ba3fb..41e83140 100644 --- a/structures.cpp +++ b/structures.cpp @@ -64,12 +64,11 @@ clean_up(void) /* species */ - for (j = 0; j < count_s; j++) + for (j = 0; j < (int)s.size(); j++) { s_free(s[j]); s[j] = (struct species *) free_check_null(s[j]); } - s = (struct species **) free_check_null(s); /* master species */ @@ -311,7 +310,6 @@ clean_up(void) title_x = (char *) free_check_null(title_x); last_title_x.clear(); count_master = 0; - count_s = 0; count_logk = 0; count_rates = 0; count_inverse = 0; @@ -1962,11 +1960,7 @@ s_delete(int i) s_free(s[i]); s[i] = (struct species *) free_check_null(s[i]); - for (j = i; j < (count_s - 1); j++) - { - s[j] = s[j + 1]; - } - count_s--; + s.erase(s.begin() + i); return (OK); } @@ -2158,13 +2152,8 @@ s_store(const char *name, LDBLE l_z, int replace_if_found) } else { - n = count_s++; - /* make sure there is space in s */ - if (count_s >= max_s) - { - space((void **) ((void *) &s), count_s, &max_s, - sizeof(struct species *)); - } + n = (int)s.size(); + s.resize((size_t)n + 1); /* Make new species structure */ s[n] = s_alloc(); s_ptr = s[n]; diff --git a/tidy.cpp b/tidy.cpp index 0625df42..1d9219e8 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -150,7 +150,7 @@ tidy_model(void) /* species */ if (new_model == TRUE) { - qsort(s, (size_t) count_s, (size_t) sizeof(struct species *), s_compare); + qsort(s.data(), s.size(), sizeof(struct species *), s_compare); /* master species */ qsort(master, (unsigned) count_master, sizeof(struct master *), master_compare); @@ -453,7 +453,7 @@ check_species_input(void) int return_value; return_value = OK; - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { if (s[i]->next_elt == NULL) { @@ -2304,7 +2304,7 @@ tidy_species(void) /* * Set secondary and primary pointers in species structures */ - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { s[i]->number = i; s[i]->primary = NULL; @@ -2396,7 +2396,7 @@ tidy_species(void) /* * Rewrite all species to secondary species */ - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { count_trxn = 0; if (s[i]->primary != NULL || s[i]->secondary != NULL) @@ -2487,7 +2487,7 @@ tidy_species(void) /* * Calculate H and O if alternate mass balance is given */ - for (i = 0; i < count_s; i++) + for (i = 0; i < (int)s.size(); i++) { if (s[i]->next_secondary != NULL) { From 3c9f5946efbc042ead8f5e655567e4c55dd5bc8a Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 14:27:30 -0600 Subject: [PATCH 13/34] vector master --- Phreeqc.cpp | 17 ++++--------- Phreeqc.h | 5 +--- basicsubs.cpp | 8 +++---- inverse.cpp | 14 +++++------ mainsubs.cpp | 9 +++---- model.cpp | 6 ++--- prep.cpp | 20 ++++++++-------- print.cpp | 6 ++--- read.cpp | 65 ++++++++++++++++---------------------------------- step.cpp | 10 ++++---- structures.cpp | 32 ++++++++++--------------- tally.cpp | 10 ++++---- tidy.cpp | 26 ++++++++++---------- 13 files changed, 91 insertions(+), 137 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 19e24943..8235ad51 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -744,10 +744,7 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Master species *---------------------------------------------------------------------- */ - master = NULL; - dbg_master = NULL; - count_master = 0; - max_master = MAX_MASTER; + /*---------------------------------------------------------------------- * Unknowns *---------------------------------------------------------------------- */ @@ -1862,16 +1859,10 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) count_master = 0; max_master = MAX_MASTER; */ - count_master = pSrc->count_master; - //max_master = pSrc->max_master; - //master = (struct master **) free_check_null(master); - //master = (struct master **) PHRQ_malloc((size_t) max_master * sizeof(struct master *)); - space((void **)((void *)&master), pSrc->max_master, &max_master, - sizeof(struct master *)); - if (master == NULL) malloc_error(); - dbg_master = master; - for (int i = 0; i < count_master; i++) + int count_master = (int)pSrc->master.size(); + for (int i = 0; i < (int)master.size(); i++) { + master.resize((size_t)i + 1); master[i] = (struct master *) PHRQ_malloc( sizeof(struct master)); if (master[i] == NULL) malloc_error(); memcpy(master[i], pSrc->master[i], sizeof(struct master)); diff --git a/Phreeqc.h b/Phreeqc.h index fb793c03..95e98671 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1506,10 +1506,7 @@ protected: /*---------------------------------------------------------------------- * Master species *---------------------------------------------------------------------- */ - struct master **master; /* structure array of master species */ - struct master **dbg_master; - int count_master; - int max_master; + std::vector master; /*---------------------------------------------------------------------- * Unknowns diff --git a/basicsubs.cpp b/basicsubs.cpp index 5fd5d8d1..e16f6c42 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -583,7 +583,7 @@ calc_solution_volume(void) gfw = s_h2o->primary->gfw; total_mass += total_o_x * gfw; - for (int i = 0; i < count_master; i++) + for (int i = 0; i < (int)master.size(); i++) { if (master[i]->s->type != AQ) continue; struct master *master_ptr = master[i]; @@ -2492,7 +2492,7 @@ total(const char *total_name) { t = 0; for (i = master_ptr->number + 1; - (i < count_master && master[i]->elt->primary == master_ptr); + (i < (int)master.size() && master[i]->elt->primary == master_ptr); i++) { t += master[i]->total / mass_water_aq_x; @@ -2562,7 +2562,7 @@ total_mole(const char *total_name) { t = 0; for (i = master_ptr->number + 1; - (i < count_master && master[i]->elt->primary == master_ptr); + (i < (int)master.size() && master[i]->elt->primary == master_ptr); i++) { t += master[i]->total; @@ -2950,7 +2950,7 @@ system_total_elements(void) space((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { master_ptr = master[i]; if (master_ptr->primary == TRUE && master_ptr->total_primary <= 0) diff --git a/inverse.cpp b/inverse.cpp index ed8b8629..50830c63 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -380,7 +380,7 @@ setup_inverse(struct inverse *inv_ptr) */ /* initialize master species */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { master[i]->in = -1; if (strstr(master[i]->elt->name, "Alk") == master[i]->elt->name) @@ -439,7 +439,7 @@ setup_inverse(struct inverse *inv_ptr) column = i; sprintf(token, "soln %d", i); col_name[column] = string_hsave(token); - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { if (master[j]->in >= 0) { @@ -453,7 +453,7 @@ setup_inverse(struct inverse *inv_ptr) } /* calculate charge balance for elements in model */ cb = 0; - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { if (master[j]->in >= 0) { @@ -3614,7 +3614,7 @@ count_isotope_unknowns(struct inverse *inv_ptr, { /* find master */ - for (k = 0; k < count_master; k++) + for (k = 0; k < (int)master.size(); k++) { if (master[k] == primary_ptr) break; @@ -3622,7 +3622,7 @@ count_isotope_unknowns(struct inverse *inv_ptr, /* sum all secondary for master */ k++; - for (; k < count_master; k++) + for (; k < (int)master.size(); k++) { if (master[k]->elt->primary != primary_ptr) break; @@ -4922,7 +4922,7 @@ dump_netpath_pat(struct inverse *inv_ptr) * Write elements */ xsolution_zero(); - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { master[j]->in = FALSE; } @@ -4942,7 +4942,7 @@ dump_netpath_pat(struct inverse *inv_ptr) continue; master_ptr->in = TRUE; } - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { if (master[j]->in == TRUE) { diff --git a/mainsubs.cpp b/mainsubs.cpp index 690b2573..d58b428f 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -70,9 +70,6 @@ initialize(void) space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); - space((void **) ((void *) &master), INIT, &max_master, - sizeof(struct master *)); - space((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns, sizeof(struct unknown_list)); @@ -1401,7 +1398,7 @@ xsolution_save(int n_user) /* * Copy totals data */ - for (int i = 0; i < count_master; i++) + for (int i = 0; i < (int)master.size(); i++) { if (master[i]->s->type == EX || master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) @@ -1826,7 +1823,7 @@ step_save_exch(int n_user) } // Set exchange total in one component - for (int i = 0; i < count_master; i++) + for (int i = 0; i < (int)master.size(); i++) { if (master[i]->s->type != EX) continue; @@ -1871,7 +1868,7 @@ step_save_surf(int n_user) return (OK); Utilities::Rxn_copy(Rxn_surface_map, use.Get_surface_ptr()->Get_n_user(), n_user); cxxSurface *surface_ptr = Utilities::Rxn_find(Rxn_surface_map, n_user); - for (int i = 0; i < count_master; i++) + for (int i = 0; i < (int)master.size(); i++) { if (master[i]->s->type != SURF) continue; diff --git a/model.cpp b/model.cpp index cda8234d..011745da 100644 --- a/model.cpp +++ b/model.cpp @@ -2356,7 +2356,7 @@ molalities(int allow_overflow) /* * la for master species */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->in == REWRITE) { @@ -4949,7 +4949,7 @@ sum_species(void) /* * Sum valence states, put in master->total */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { master[i]->total = 0.0; master[i]->total_primary = 0.0; @@ -4991,7 +4991,7 @@ sum_species(void) /* * Calculate total element concentrations */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { master[i]->elt->primary->total_primary += master[i]->total; } diff --git a/prep.cpp b/prep.cpp index e966eed8..9471368b 100644 --- a/prep.cpp +++ b/prep.cpp @@ -155,7 +155,7 @@ quick_setup(void) * Updates essential information for the model. */ int i; - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->s->type == SURF_PSI) continue; @@ -1835,7 +1835,7 @@ clear(void) * Clear master species solution-dependent data */ const char * pe_str = string_hsave("pe"); - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { master[i]->in = FALSE; master[i]->unknown = NULL; @@ -2091,7 +2091,7 @@ get_list_master_ptrs(char *ptr, struct master *master_ptr) /* * First in list is primary species */ - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { if (master[j] == master_ptr0) break; @@ -2100,7 +2100,7 @@ get_list_master_ptrs(char *ptr, struct master *master_ptr) /* * Element has only one valence */ - if (j >= count_master || master[j]->elt->primary != master_ptr0) + if (j >= (int)master.size() || master[j]->elt->primary != master_ptr0) { master_ptr_list[count_list++] = master_ptr0; /* @@ -2118,7 +2118,7 @@ get_list_master_ptrs(char *ptr, struct master *master_ptr) input_error++; } master_ptr_list[count_list++] = master_ptr0->s->secondary; - while (j < count_master && master[j]->elt->primary == master_ptr0) + while (j < (int)master.size() && master[j]->elt->primary == master_ptr0) { if (master[j]->s->primary == NULL) { @@ -2646,7 +2646,7 @@ reprep(void) /* * Initialize s, master, and unknown pointers */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->in == FALSE) continue; @@ -5128,13 +5128,13 @@ tidy_redox(void) /* * Keep valences of oxygen and hydrogen in model, if not already in */ - for (int i = 0; i < count_master; i++) + for (int i = 0; i < (int)master.size(); i++) { if (master[i]->primary == TRUE && (master[i]->s == s_hplus || master[i]->s == s_h2o)) { int j = i + 1; - while (j < count_master && master[j]->elt->primary == master[i]) + while (j < (int)master.size() && master[j]->elt->primary == master[i]) { if (master[j]->in == FALSE && master[j]->s != master[i]->s) { @@ -5818,7 +5818,7 @@ save_model(void) /* * mark master species */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { master[i]->last_model = FALSE; if (master[i]->total > 0) @@ -6009,7 +6009,7 @@ check_same_model(void) /* * Check master species */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { /* output_msg(sformatf("%s\t%e\t%d\n", master[i]->elt->name, diff --git a/print.cpp b/print.cpp index 1cc8f4ea..0c5be864 100644 --- a/print.cpp +++ b/print.cpp @@ -371,7 +371,7 @@ print_eh(void) tk_x = tc_x + 273.15; first = TRUE; - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->in != TRUE) continue; @@ -381,7 +381,7 @@ print_eh(void) * Secondary master species has mass balance equation */ master_ptr0 = master[i]->elt->primary; - for (k = i + 1; k < count_master; k++) + for (k = i + 1; k < (int)master.size(); k++) { if (master[k]->in != TRUE) continue; @@ -1074,7 +1074,7 @@ print_master_reactions(void) int i; struct rxn_token *next_token; - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { output_msg(sformatf("%s\t%s\n\tPrimary reaction\n", master[i]->elt->name, master[i]->s->name)); diff --git a/read.cpp b/read.cpp index 6e2bd653..86180790 100644 --- a/read.cpp +++ b/read.cpp @@ -1174,11 +1174,8 @@ read_exchange_master_species(void) /* * Increase pointer array, if necessary, and malloc space */ - if (count_master >= max_master) - { - space((void **) ((void *) &master), count_master + 1, - &max_master, sizeof(struct master *)); - } + size_t count_master = master.size(); + master.resize(count_master + 1); master[count_master] = master_alloc(); /* * Set type to EX @@ -1219,13 +1216,6 @@ read_exchange_master_species(void) elts_ptr = element_store(master[count_master]->elt->name); elts_ptr->gfw = 0.0; } - - count_master++; - if (count_master >= max_master) - { - space((void **) ((void *) &master), count_master, &max_master, - sizeof(struct master *)); - } } return (j); } @@ -3265,20 +3255,17 @@ read_master_species(void) /* * Increase pointer array, if necessary, and malloc space */ - if (count_master >= max_master) - { - space((void **) ((void *) &master), count_master + 1, - &max_master, sizeof(struct master *)); - } - master[count_master++] = master_alloc(); + size_t count_master = master.size(); + master.resize(count_master + 1); + master[count_master] = master_alloc(); /* * Set type to AQ */ - master[count_master-1]->type = AQ; + master[count_master]->type = AQ; /* * Save element name */ - master[count_master-1]->elt = element_store(token); + master[count_master]->elt = element_store(token); std::string ename = token; /* * Save pointer to species data for master species @@ -3295,13 +3282,13 @@ read_master_species(void) s_ptr = s_search(token); if (s_ptr != NULL) { - master[count_master-1]->s = s_ptr; + master[count_master]->s = s_ptr; } else { ptr1 = token; get_token(&ptr1, token1, &l_z, &l); - master[count_master-1]->s = s_store(token1, l_z, FALSE); + master[count_master]->s = s_store(token1, l_z, FALSE); } std::string sname = token; @@ -3321,7 +3308,7 @@ read_master_species(void) * Read alkalinity for species */ copy_token(token, &ptr, &l); - i = sscanf(token, SCANFORMAT, &master[count_master-1]->alk); + i = sscanf(token, SCANFORMAT, &master[count_master]->alk); if (i != 1) { input_error++; @@ -3345,11 +3332,11 @@ read_master_species(void) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - (void)sscanf(token, SCANFORMAT, &master[count_master-1]->gfw); + (void)sscanf(token, SCANFORMAT, &master[count_master]->gfw); } else if (i == UPPER) { - master[count_master-1]->gfw_formula = string_hsave(token); + master[count_master]->gfw_formula = string_hsave(token); } else { @@ -3371,13 +3358,13 @@ read_master_species(void) /* * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES */ - if (strchr(master[count_master-1]->elt->name, '(') == NULL) + if (strchr(master[count_master]->elt->name, '(') == NULL) { - master[count_master-1]->primary = TRUE; + master[count_master]->primary = TRUE; /* Read gram formula weight for primary */ - if (strcmp(master[count_master-1]->elt->name, "E") != 0) + if (strcmp(master[count_master]->elt->name, "E") != 0) { - elts_ptr = master[count_master-1]->elt; + elts_ptr = master[count_master]->elt; i = copy_token(token, &ptr, &l); if (i == DIGIT) { @@ -3405,14 +3392,8 @@ read_master_species(void) } else { - master[count_master-1]->primary = FALSE; + master[count_master]->primary = FALSE; } - if (count_master >= max_master) - { - space((void **) ((void *) &master), count_master, &max_master, - sizeof(struct master *)); - } - } gfw_map.clear(); return (j); @@ -7294,17 +7275,11 @@ read_surface_master_species(void) * Delete master if it exists */ master_delete(token); - /* - * Increase pointer array, if necessary, and malloc space - */ - if (count_master + 4 >= max_master) - { - space((void **) ((void *) &master), count_master + 4, - &max_master, sizeof(struct master *)); - } /* * Save values in master and species structure for surface sites */ + size_t count_master = master.size(); + master.resize(count_master + 1); master[count_master] = master_alloc(); master[count_master]->type = SURF; master[count_master]->elt = element_store(token); @@ -7376,6 +7351,8 @@ add_psi_master_species(char *token) master_ptr = master_search(token, &n); if (master_ptr == NULL) { + size_t count_master = master.size(); + master.resize(count_master + 1); master[count_master] = master_alloc(); master[count_master]->type = plane; master[count_master]->elt = element_store(token); diff --git a/step.cpp b/step.cpp index 19094bcf..a785b367 100644 --- a/step.cpp +++ b/step.cpp @@ -318,7 +318,7 @@ xsolution_zero(void) mass_water_aq_x = 0.0; units_x = moles_per_kilogram_string; - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { master[i]->total = 0.0; master[i]->total_primary = 0.0; @@ -459,7 +459,7 @@ add_exchange(cxxExchange *exchange_ptr) } if (exchange_ptr->Get_new_def()) { - for (int i = 0; i < count_master; i++) + for (int i = 0; i < (int)master.size(); i++) { if (master[i]->type == EX && master[i]->total > 0) { @@ -1337,7 +1337,7 @@ pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr) * Make la's of all master species for the element small, so SI will be small * and no mass transfer will be calculated */ - for (int k = 0; k < count_master; k++) + for (int k = 0; k < (int)master.size(); k++) { if (master[k]->elt->primary == master_ptr) { @@ -1412,7 +1412,7 @@ ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr) * so SI will be small * and no mass transfer will be calculated */ - for (k = 0; k < count_master; k++) + for (k = 0; k < (int)master.size(); k++) { if (master[k]->elt->primary == master_ptr) { @@ -1439,7 +1439,7 @@ solution_check(void) /* * Check that all elements are in solution for phases with zero mass */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { master_ptr = master[i]; if (master_ptr->total <= MIN_TOTAL && master_ptr->total >= -MIN_TOTAL) diff --git a/structures.cpp b/structures.cpp index 41e83140..a5f06e47 100644 --- a/structures.cpp +++ b/structures.cpp @@ -72,11 +72,10 @@ clean_up(void) /* master species */ - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { master_free(master[j]); } - master = (struct master **) free_check_null(master); /* elements */ @@ -309,7 +308,6 @@ clean_up(void) #endif title_x = (char *) free_check_null(title_x); last_title_x.clear(); - count_master = 0; count_logk = 0; count_rates = 0; count_inverse = 0; @@ -1004,16 +1002,12 @@ master_delete(char *ptr) * TRUE if master species was deleted. * FALSE if master species was not found. */ - int j, n; + int n; if (master_search(ptr, &n) == NULL) return (FALSE); master_free(master[n]); - for (j = n; j < (count_master - 1); j++) - { - master[j] = master[j + 1]; - } - count_master--; + master.erase(master.begin() + n); return (TRUE); } @@ -1048,22 +1042,22 @@ master_bsearch(const char *ptr) * Return: pointer to master structure containing name ptr or NULL. */ void *void_ptr; - if (count_master == 0) + if (master.size() == 0) { return (NULL); } void_ptr = bsearch((const char *) ptr, - (char *) master, - (unsigned) count_master, + (char *) master.data(), + master.size(), sizeof(struct master *), master_compare_string); if (void_ptr == NULL) { char * dup = string_duplicate(ptr); replace("(+","(", dup); void_ptr = bsearch((const char *) dup, - (char *) master, - (unsigned) count_master, - sizeof(struct master *), master_compare_string); + (char*)master.data(), + master.size(), + sizeof(struct master*), master_compare_string); dup = (char *) free_check_null(dup); } if (void_ptr == NULL) @@ -1168,7 +1162,7 @@ master_bsearch_secondary(char *ptr) */ if (master_ptr_primary) { - if ((master_ptr_primary->number >= count_master - 1) || + if ((master_ptr_primary->number >= (int)master.size() - 1) || (master[master_ptr_primary->number + 1]->elt->primary != master_ptr_primary)) { return(master_ptr_primary); @@ -1177,7 +1171,7 @@ master_bsearch_secondary(char *ptr) * Find secondary master with same species as primary */ master_ptr = NULL; - for (j = master_ptr_primary->number + 1; j < count_master; j++) + for (j = master_ptr_primary->number + 1; j < (int)master.size(); j++) { if (master[j]->s == master_ptr_primary->s) { @@ -1219,7 +1213,7 @@ master_search(char *ptr, int *n) * Search master species list */ *n = -999; - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (strcmp(ptr, master[i]->elt->name) == 0) { @@ -1956,8 +1950,6 @@ s_delete(int i) /* * Delete species i: free memory and renumber array of pointers, s. */ - int j; - s_free(s[i]); s[i] = (struct species *) free_check_null(s[i]); s.erase(s.begin() + i); diff --git a/tally.cpp b/tally.cpp index 4b18d54b..56a0c83b 100644 --- a/tally.cpp +++ b/tally.cpp @@ -82,11 +82,11 @@ get_all_components(void) add_all_components_tally(); // add secondary master species - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->total > 0.0 && master[i]->s->type == AQ && master[i]->primary == TRUE) { - for (int j = i + 1; j < count_master; j++) + for (int j = i + 1; j < (int)master.size(); j++) { if (master[j]->elt->primary == master[i]) { @@ -105,7 +105,7 @@ get_all_components(void) * Count components + Alkalinity + total_h + total_o */ tally_count_component = 3; - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->total > 0.0 && master[i]->s->type == AQ) { @@ -140,7 +140,7 @@ get_all_components(void) compute_gfw("O", &(t_buffer[j].gfw)); j++; - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->total > 0.0 && master[i]->s->type == AQ) { @@ -756,7 +756,7 @@ master_to_tally_table(struct tally_buffer *buffer_ptr) * copy element list amounts to buffer in tally table * for column number */ - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { if (master[j]->total <= 0) continue; diff --git a/tidy.cpp b/tidy.cpp index 1d9219e8..353b7207 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -153,7 +153,7 @@ tidy_model(void) qsort(s.data(), s.size(), sizeof(struct species *), s_compare); /* master species */ - qsort(master, (unsigned) count_master, sizeof(struct master *), master_compare); + qsort(master.data(), master.size(), sizeof(struct master *), master_compare); /* elements */ qsort(elements.data(), elements.size(), sizeof(struct element *), element_compare); /* phases */ @@ -1294,7 +1294,7 @@ tidy_inverse(void) /* * Mark master species list */ - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) master[j]->in = FALSE; for (j = 0; j < count_elts; j++) { @@ -1322,13 +1322,13 @@ tidy_inverse(void) */ count_in = 0; inverse[i].count_redox_rxns = 0; - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { /* skip all secondary master species in this loop */ if (master[j]->primary == FALSE || master[j]->in == FALSE) continue; count_in++; - if (j + 1 == count_master) + if (j + 1 == (int)master.size()) continue; /* if next master species is secondary, mark all secondary master species until a primary is found */ @@ -1336,7 +1336,7 @@ tidy_inverse(void) { master[j]->in = FALSE; count_in--; - for (k = j + 1; k < count_master; k++) + for (k = j + 1; k < (int)master.size(); k++) { if (master[k]->primary == FALSE) { @@ -1363,7 +1363,7 @@ tidy_inverse(void) if (inv_elts == NULL) malloc_error(); count_in = 0; - for (j = 0; j < count_master; j++) + for (j = 0; j < (int)master.size(); j++) { /* skip H(1) and O(-2) */ if (master[j]->s == s_hplus || master[j]->s == s_h2o) @@ -2322,7 +2322,7 @@ tidy_species(void) } } } - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { char * temp_name = string_duplicate(master[i]->elt->name); ptr = temp_name; @@ -2375,7 +2375,7 @@ tidy_species(void) * Write equations for all master species in terms of primary * master species, set coefficient of element in master species */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { count_trxn = 0; if (master[i]->s->primary != NULL) @@ -2451,7 +2451,7 @@ tidy_species(void) * Make sure all primary master species for redox elements * are also secondary master species */ - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->primary == FALSE) { @@ -2595,7 +2595,7 @@ tidy_species(void) } } - for (i = 0; i < count_master; i++) + for (i = 0; i < (int)master.size(); i++) { if (master[i]->gfw <= 0.0) { @@ -2995,7 +2995,7 @@ tidy_isotopes(void) /* find index number of master species, set flag to FALSE */ master_ptr = master_bsearch(kit->second.Get_elt_name().c_str()); isotope_number = kit->second.Get_isotope_number(); - for (int k = 0; k < count_master; k++) + for (int k = 0; k < (int)master.size(); k++) { master[k]->isotope = FALSE; } @@ -3026,7 +3026,7 @@ tidy_isotopes(void) /* for primary, fill in ratio for all secondary species */ if (master_ptr->primary == TRUE && master_ptr->s->secondary != NULL) { - for (int k = primary_number + 1; k < count_master; k++) + for (int k = primary_number + 1; k < (int)master.size(); k++) { if (master[k]->elt->primary != primary_ptr) break; @@ -3060,7 +3060,7 @@ tidy_isotopes(void) /* * Write new isotope structure */ - for (int k = 0; k < count_master; k++) + for (int k = 0; k < (int)master.size(); k++) { /* skip primary master species of redox elements */ if (master[k]->primary == TRUE && master[k]->s->secondary != NULL) From e8dd208374d82e6ec892ac07df26635b932d055f Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 16:22:43 -0600 Subject: [PATCH 14/34] vector sys --- PBasic.cpp | 10 +-- Phreeqc.cpp | 3 - Phreeqc.h | 3 +- basicsubs.cpp | 173 +++++++++++++++++++++----------------------------- 4 files changed, 80 insertions(+), 109 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 3d5a6be1..fb568145 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -2786,8 +2786,9 @@ factor(struct LOC_exec * LINK) if (parse_all) { PhreeqcPtr->sys_tot = 0; - PhreeqcPtr->count_sys = 1000; - int count_sys = PhreeqcPtr->count_sys; + //PhreeqcPtr->count_sys = 1000; + //int count_sys = PhreeqcPtr->count_sys; + size_t count_sys = 1000; names_arg = (char**)PhreeqcPtr->PHRQ_calloc((size_t)(count_sys + 1), sizeof(char*)); if (names_arg == NULL) { @@ -2916,8 +2917,9 @@ factor(struct LOC_exec * LINK) if (parse_all) { PhreeqcPtr->sys_tot = 0; - PhreeqcPtr->count_sys = 1000; - int count_sys = PhreeqcPtr->count_sys; + //PhreeqcPtr->count_sys = 1000; + //int count_sys = PhreeqcPtr->count_sys; + int count_sys = 1000; names_arg = (char **) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); if (names_arg == NULL) { diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 8235ad51..27d7197c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -983,9 +983,6 @@ void Phreeqc::init(void) cell_volume = 0; cell_porosity = 0; cell_saturation = 0; - sys = NULL; - count_sys = 0; - max_sys = 0; sys_tot = 0; V_solutes = 0.0; diff --git a/Phreeqc.h b/Phreeqc.h index 95e98671..1d6070d0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1738,8 +1738,7 @@ protected: LDBLE cell_porosity; LDBLE cell_volume; LDBLE cell_saturation; - struct system_species *sys; - int count_sys, max_sys; + std::vector sys; LDBLE sys_tot; LDBLE V_solutes, rho_0, rho_0_sat, kappa_0, p_sat/*, ah2o_x0*/; diff --git a/basicsubs.cpp b/basicsubs.cpp index e16f6c42..076a5d7f 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2586,12 +2586,13 @@ get_edl_species(cxxSurfaceCharge & charge_ref) { double mass_water_surface = charge_ref.Get_mass_water(); - space((void **) ((void *) &sys), count_s_x, &max_sys, sizeof(struct system_species)); - count_sys = 0; + sys.clear(); for (int j = 0; j < count_s_x; j++) { if (s_x[j]->type == H2O) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(s_x[j]->name); sys[count_sys].moles = mass_water_surface / gfw_water; sys_tot += sys[count_sys].moles; @@ -2599,6 +2600,8 @@ get_edl_species(cxxSurfaceCharge & charge_ref) } else if (s_x[j]->type < H2O) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); double molality = under(s_x[j]->lm); double moles_excess = mass_water_aq_x * molality * charge_ref.Get_g_map()[s_x[j]->z].Get_g(); double moles_surface = mass_water_surface * molality + moles_excess; @@ -2624,10 +2627,7 @@ edl_species(const char *surf_name, LDBLE * count, char ***names, LDBLE ** moles, */ int i; sys_tot = 0; - count_sys = 0; - max_sys = 100; - space((void **) ((void *) &sys), INIT, &max_sys, - sizeof(struct system_species)); + sys.clear(); if (!(dl_type_x == cxxSurface::NO_DL)) { cxxSurface *surface_ptr = use.Get_surface_ptr(); @@ -2646,31 +2646,32 @@ edl_species(const char *surf_name, LDBLE * count, char ***names, LDBLE ** moles, /* * Sort system species */ - if (count_sys > 1) + if (sys.size() > 1) { - qsort(sys, (size_t) count_sys, - (size_t) sizeof(struct system_species), system_species_compare); + qsort(sys.data(), sys.size(), + sizeof(struct system_species), system_species_compare); } /* * malloc space */ - *names = (char **) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(char *)); + *names = (char **) PHRQ_malloc((sys.size() + 1) * sizeof(char *)); if (names == NULL) malloc_error(); - *moles = (LDBLE *) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(LDBLE)); + *moles = (LDBLE *) PHRQ_malloc((sys.size() + 1) * sizeof(LDBLE)); if (moles == NULL) malloc_error(); (*names)[0] = NULL; (*moles)[0] = 0; - for (i = 0; i < count_sys; i++) + for (i = 0; i < (int)sys.size(); i++) { (*names)[i + 1] = sys[i].name; (*moles)[i + 1] = sys[i].moles; } - *count = (LDBLE) count_sys; + *count = (LDBLE)sys.size(); - PHRQ_free(sys); + //PHRQ_free(sys); + sys.clear(); return (sys_tot); } /* ---------------------------------------------------------------------- */ @@ -2685,10 +2686,7 @@ system_total(const char *total_name, LDBLE * count, char ***names, int i; sys_tot = 0; - count_sys = 0; - max_sys = 100; - space((void **) ((void *) &sys), INIT, &max_sys, - sizeof(struct system_species)); + sys.clear(); if (strcmp_nocase(total_name, "elements") == 0) { system_total_elements(); @@ -2739,33 +2737,34 @@ system_total(const char *total_name, LDBLE * count, char ***names, /* * Sort system species */ - if (count_sys > 1 && isort == 0) + if (sys.size() > 1 && isort == 0) { - qsort(sys, (size_t) count_sys, - (size_t) sizeof(struct system_species), system_species_compare); + qsort(sys.data(), sys.size(), + sizeof(struct system_species), system_species_compare); } else { - qsort(sys, (size_t)count_sys, + qsort(sys.data(), sys.size(), (size_t)sizeof(struct system_species), system_species_compare_name); } /* * malloc space */ - *names = (char **) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(char *)); + size_t count_sys = sys.size(); + *names = (char **) PHRQ_malloc((count_sys + 1) * sizeof(char *)); if (names == NULL) malloc_error(); - *types = (char **) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(char *)); + *types = (char **) PHRQ_malloc((count_sys + 1) * sizeof(char *)); if (types == NULL) malloc_error(); - *moles = (LDBLE *) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(LDBLE)); + *moles = (LDBLE *) PHRQ_malloc((count_sys + 1) * sizeof(LDBLE)); if (moles == NULL) malloc_error(); (*names)[0] = NULL; (*types)[0] = NULL; (*moles)[0] = 0; - for (i = 0; i < count_sys; i++) + for (i = 0; i < (int)count_sys; i++) { (*names)[i + 1] = sys[i].name; (*types)[i + 1] = sys[i].type; @@ -2775,7 +2774,7 @@ system_total(const char *total_name, LDBLE * count, char ***names, if (strcmp_nocase(total_name, "elements") == 0) { sys_tot = 0;; - for (i = 0; i < count_sys; i++) + for (i = 0; i < (int)count_sys; i++) { if (strcmp(sys[i].type, "dis") == 0 && strstr(sys[i].name, "(") == NULL && @@ -2786,7 +2785,8 @@ system_total(const char *total_name, LDBLE * count, char ***names, } } } - PHRQ_free(sys); + //PHRQ_free(sys); + sys.clear(); return (sys_tot); } @@ -2918,38 +2918,35 @@ system_total_elements(void) /* * Include H and O */ + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate("H"); sys[count_sys].moles = total_h_x; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("dis"); count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate("O"); sys[count_sys].moles = total_o_x; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("dis"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); + count_sys++;; /* * Include H(1) and O(-2) */ + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate("H(1)"); sys[count_sys].moles = solution_sum_secondary("H(1)"); sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("dis"); count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate("O(-2)"); sys[count_sys].moles = solution_sum_secondary("O(-2)"); sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("dis"); count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); - + sys.resize(count_sys + 1); for (i = 0; i < (int)master.size(); i++) { master_ptr = master[i]; @@ -3019,10 +3016,6 @@ system_total_elements(void) { sys[count_sys].type = string_duplicate("surf"); } - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); - } return (OK); } @@ -3053,14 +3046,13 @@ system_total_si(void) } si = -phases[i]->lk + iap; strcpy(name, phases[i]->name); + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(name); sys[count_sys].moles = si; if (si > sys_tot) sys_tot = si; sys[count_sys].type = string_duplicate("phase"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); } return (OK); } @@ -3082,13 +3074,12 @@ system_total_aq(void) //if (s_x[i]->type != AQ) if (s_x[i]->type > HPLUS) continue; + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(s_x[i]->name); sys[count_sys].moles = s_x[i]->moles; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("aq"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); } return (OK); } @@ -3111,13 +3102,12 @@ system_total_ex(void) continue; if (s_x[i]->primary != NULL) continue; + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(s_x[i]->name); sys[count_sys].moles = s_x[i]->moles; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("ex"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); } return (OK); } @@ -3138,13 +3128,12 @@ system_total_surf(void) { if (s_x[i]->type != SURF) continue; + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(s_x[i]->name); sys[count_sys].moles = s_x[i]->moles; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("surf"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); } return (OK); } @@ -3169,13 +3158,12 @@ system_total_gas(void) struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &i, FALSE); assert(phase_ptr); + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(phase_ptr->name); sys[count_sys].moles = phase_ptr->moles_x; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("gas"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); } return (OK); } @@ -3196,14 +3184,12 @@ system_total_equi(void) cxxPPassemblageComp *comp_ptr = &(it->second); int l; struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(phase_ptr->name); - //sys[count_sys].moles = comp_ptr->Get_moles(); sys[count_sys].moles = equi_phase(sys[count_sys].name); sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("equi"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); } return (OK); } @@ -3220,14 +3206,13 @@ system_total_kin(void) std::vector comps = use.Get_kinetics_ptr()->Get_kinetics_comps(); for (size_t i=0 ; i < comps.size(); i++) { - cxxKineticsComp *comp_ptr = &comps[i]; + cxxKineticsComp *comp_ptr = &comps[i]; + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(comp_ptr->Get_rate_name().c_str()); sys[count_sys].moles = comp_ptr->Get_m(); sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("kin"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); } return (OK); } @@ -3254,13 +3239,12 @@ system_total_ss(void) cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); int l; struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(phase_ptr->name); sys[count_sys].moles = comp_ptr->Get_moles(); sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); } } return (OK); @@ -3299,6 +3283,8 @@ system_total_elt(const char *total_name) { if (strcmp(elt_list[j].elt->name, total_name) == 0) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(s_x[i]->name); sys[count_sys].moles = elt_list[j].coef; sys_tot += sys[count_sys].moles; @@ -3333,9 +3319,6 @@ system_total_elt(const char *total_name) { error_msg("System_total", STOP); } - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); break; } } @@ -3388,15 +3371,14 @@ system_total_elt(const char *total_name) { if (strcmp(elt_list[j].elt->name, total_name) == 0) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); strcpy(name, x[k]->master[0]->elt->name); replace("_psi", "", name); sys[count_sys].name = string_duplicate(name); sys[count_sys].moles = elt_list[j].coef; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("diff"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); break; } } @@ -3433,14 +3415,12 @@ system_total_elt(const char *total_name) { if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = - string_duplicate(phase_ptr->name); + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); + sys[count_sys].name = string_duplicate(phase_ptr->name); sys[count_sys].moles = elt_list[j].coef; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("equi"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); break; } } @@ -3477,14 +3457,13 @@ system_total_elt(const char *total_name) { if (strcmp(elt_list[j].elt->name, total_name) == 0) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(phase_ptr->name); sys[count_sys].moles = elt_list[j].coef; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space((void **) ((void *) &sys), count_sys, - &max_sys, sizeof(struct system_species)); break; } } @@ -3521,13 +3500,12 @@ system_total_elt(const char *total_name) { if (strcmp(elt_list[j].elt->name, total_name) == 0) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(phase_ptr->name); sys[count_sys].moles = elt_list[j].coef; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("gas"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); break; } } @@ -3577,6 +3555,8 @@ system_total_elt_secondary(const char *total_name) { if (strcmp(elt_list[j].elt->name, total_name) == 0) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(s_x[i]->name); sys[count_sys].moles = elt_list[j].coef; sys_tot += sys[count_sys].moles; @@ -3606,9 +3586,6 @@ system_total_elt_secondary(const char *total_name) { error_msg("System_total", STOP); } - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); break; } } @@ -3664,13 +3641,12 @@ system_total_elt_secondary(const char *total_name) continue; strcpy(name, x[k]->master[0]->elt->name); replace("_psi", "", name); + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(name); sys[count_sys].moles = sum; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("diff"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); break; } } @@ -3706,14 +3682,13 @@ system_total_elt_secondary(const char *total_name) { if (strcmp(elt_list[j].elt->name, total_name) == 0) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(phase_ptr->name); sys[count_sys].moles = elt_list[j].coef; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("equi"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); break; } } @@ -3750,14 +3725,13 @@ system_total_elt_secondary(const char *total_name) { if (strcmp(elt_list[j].elt->name, total_name) == 0) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(phase_ptr->name); sys[count_sys].moles = elt_list[j].coef; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space((void **) ((void *) &sys), count_sys, - &max_sys, sizeof(struct system_species)); break; } } @@ -3796,14 +3770,13 @@ system_total_elt_secondary(const char *total_name) { if (strcmp(elt_list[j1].elt->name, total_name) == 0) { + size_t count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(phase_ptr->name); sys[count_sys].moles = elt_list[j1].coef; sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("gas"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); break; } } From 3d41ef8287047e51e5955af967d4363b7f82edb9 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 17:04:29 -0600 Subject: [PATCH 15/34] vector logk --- Phreeqc.cpp | 15 ++------------- Phreeqc.h | 5 +---- mainsubs.cpp | 4 +--- structures.cpp | 15 ++++----------- tidy.cpp | 4 ++-- 5 files changed, 10 insertions(+), 33 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 27d7197c..68239da3 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -721,9 +721,6 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Species *---------------------------------------------------------------------- */ - logk = NULL; - count_logk = 0; - max_logk = MAX_S; moles_per_kilogram_string= NULL; pe_string = NULL; // auto s_diff_layer; @@ -1678,15 +1675,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) */ // logk - space((void **)((void *)&logk), pSrc->max_logk, &max_logk, sizeof(struct logk *)); - //for (int i = 0; i < count_logk; i++) - //{ - // logk[i] = (struct logk *) free_check_null(logk[i]); - //} - //logk = (struct logk **) free_check_null(logk); - //max_logk = pSrc->max_logk; - //logk = (struct logk **) PHRQ_malloc((size_t) max_logk * sizeof(struct logk *)); - for (int i = 0; i < pSrc->count_logk; i++) + for (int i = 0; i < (int)pSrc->logk.size(); i++) { char * name = string_duplicate(pSrc->logk[i]->name); struct logk *logk_ptr = logk_store(name, FALSE); @@ -1706,7 +1695,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } } } - count_logk = pSrc->count_logk; + // s, species for (int i = 0; i < (int)pSrc->s.size(); i++) { diff --git a/Phreeqc.h b/Phreeqc.h index 1d6070d0..570a06be 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1475,10 +1475,7 @@ protected: /*---------------------------------------------------------------------- * Species *---------------------------------------------------------------------- */ - - struct logk **logk; - int count_logk; - int max_logk; + std::vector logk; char *moles_per_kilogram_string; char *pe_string; diff --git a/mainsubs.cpp b/mainsubs.cpp index d58b428f..ef406ab9 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -85,12 +85,10 @@ initialize(void) space((void **) ((void *) &trxn.token), INIT, &max_trxn, sizeof(struct rxn_token_temp)); - space((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); - /* * Create hash tables */ - hcreate_multi((unsigned) max_logk, &logk_hash_table); + hcreate_multi((unsigned) MAX_S, &logk_hash_table); hcreate_multi((unsigned) MAX_ELTS, &master_isotope_hash_table); hcreate_multi((unsigned) MAX_ELTS, &elements_hash_table); hcreate_multi((unsigned) MAX_S, &species_hash_table); diff --git a/structures.cpp b/structures.cpp index a5f06e47..30863ade 100644 --- a/structures.cpp +++ b/structures.cpp @@ -152,12 +152,12 @@ clean_up(void) rates = (struct rate *) free_check_null(rates); /* logk hash table */ - for (j = 0; j < count_logk; j++) + for (j = 0; j < (int)logk.size(); j++) { free_check_null(logk[j]->add_logk); logk[j] = (struct logk *) free_check_null(logk[j]); } - logk = (struct logk **) free_check_null(logk); + logk.clear(); /* save_values */ for (j = 0; j < count_save_values; j++) @@ -308,7 +308,6 @@ clean_up(void) #endif title_x = (char *) free_check_null(title_x); last_title_x.clear(); - count_logk = 0; count_rates = 0; count_inverse = 0; count_save_values = 0; @@ -3232,7 +3231,6 @@ logk_store(char *name, int replace_if_found) * Returns: * pointer to logk structure "logk" where "name" can be found. */ - int n; struct logk *logk_ptr; ENTRY item, *found_item; /* @@ -3255,14 +3253,9 @@ logk_store(char *name, int replace_if_found) } else { - n = count_logk++; - /* make sure there is space in s */ - if (count_logk >= max_logk) - { - space((void **) ((void *) &logk), count_logk, &max_logk, - sizeof(struct logk *)); - } /* Make new logk structure */ + size_t n = logk.size(); + logk.resize(n + 1); logk[n] = logk_alloc(); logk_ptr = logk[n]; } diff --git a/tidy.cpp b/tidy.cpp index 353b7207..72404df6 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -533,12 +533,12 @@ tidy_logk(void) */ { int i; - for (i = 0; i < count_logk; i++) + for (i = 0; i < (int)logk.size(); i++) { select_log_k_expression(logk[i]->log_k_original, logk[i]->log_k); logk[i]->done = FALSE; } - for (i = 0; i < count_logk; i++) + for (i = 0; i < (int)logk.size(); i++) { if (logk[i]->done == FALSE) { From 622d3618a521d457c0296d231deefed58b2d8980 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 18:21:12 -0600 Subject: [PATCH 16/34] vector s_x --- Phreeqc.h | 5 +---- basicsubs.cpp | 40 ++++++++++++++++++++-------------------- integrate.cpp | 16 ++++++++-------- mainsubs.cpp | 8 ++++---- model.cpp | 19 +++++++++---------- pitzer.cpp | 10 +++++----- prep.cpp | 27 ++++++++++----------------- print.cpp | 9 ++++----- sit.cpp | 10 +++++----- transport.cpp | 2 +- 10 files changed, 67 insertions(+), 79 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 570a06be..d51d0330 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1482,10 +1482,7 @@ protected: std::vector s; std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; - - struct species **s_x; - int count_s_x; - int max_s_x; + std::vector s_x; struct species *s_h2o; struct species *s_hplus; diff --git a/basicsubs.cpp b/basicsubs.cpp index 076a5d7f..f3d97f24 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -267,7 +267,7 @@ calc_SC(void) return (SC); //# endif - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) continue; @@ -305,7 +305,7 @@ calc_SC(void) SC = 0; //LDBLE ta1, ta2, ta3, ta4; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { // ** for optimizing, get numbers from -analyt for H+ = H+... //if (!strcmp(s_x[i]->name, "H+")) @@ -318,7 +318,7 @@ calc_SC(void) //} // } - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) continue; @@ -378,7 +378,7 @@ calc_SC(void) m_plus = m_min = eq_plus = eq_min = eq_dw_plus = eq_dw_min = Sum_m_dw = z_plus = z_min = 0; SC = 0; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) continue; @@ -418,7 +418,7 @@ calc_SC(void) B2 = t1 * AVOGADRO / t2 * DH_B * 1e17; // DH_B per Angstrom (*1e10), viscos in mPa.s (*1e3), B2 in cm2 (*1e4) Dw_SC = viscos_0_25 / t2 * 1e4 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0); - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) continue; @@ -520,7 +520,7 @@ calc_dens(void) /* 2nd option, use species_x, vm = 0 for complexes with undefined volume... */ V_solutes = M_T = 0.0; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) continue; @@ -821,7 +821,7 @@ calc_surface_charge(const char *surface_name) * Go through species, sum charge */ charge = 0; - for (k = 0; k < count_s_x; k++) + for (k = 0; k < (int)this->s_x.size(); k++) { if (s_x[k]->type != SURF) continue; @@ -1106,7 +1106,7 @@ diff_layer_total(const char *total_name, const char *surface_name) mass_water_surface = surface_charge_ptr1->Get_mass_water(); count_elts = 0; paren_count = 0; - for (j = 0; j < count_s_x; j++) + for (j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type > HPLUS) continue; @@ -1838,7 +1838,7 @@ sum_match_species(const char *mytemplate, const char *name) if (sum_species_map.find(mytemplate) == sum_species_map.end()) { std::vector species_list; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { struct species *s_ptr = s_x[i]; if (match_elts_in_species(s_ptr->name, mytemplate) == TRUE) @@ -2260,7 +2260,7 @@ surf_total(const char *total_name, const char *surface_name) * find total moles for redox state */ LDBLE t = 0; - for (j = 0; j < count_s_x; j++) + for (j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type != SURF) continue; @@ -2397,7 +2397,7 @@ surf_total_no_redox(const char *total_name, const char *surface_name) */ count_elts = 0; paren_count = 0; - for (j = 0; j < count_s_x; j++) + for (j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type != SURF) continue; @@ -2587,7 +2587,7 @@ get_edl_species(cxxSurfaceCharge & charge_ref) double mass_water_surface = charge_ref.Get_mass_water(); sys.clear(); - for (int j = 0; j < count_s_x; j++) + for (int j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type == H2O) { @@ -3069,7 +3069,7 @@ system_total_aq(void) /* * find total moles in aq, surface, and exchange */ - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { //if (s_x[i]->type != AQ) if (s_x[i]->type > HPLUS) @@ -3096,7 +3096,7 @@ system_total_ex(void) /* * find total moles in aq, surface, and exchange */ - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type != EX) continue; @@ -3124,7 +3124,7 @@ system_total_surf(void) /* * find total moles in aq, surface, and exchange */ - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type != SURF) continue; @@ -3264,7 +3264,7 @@ system_total_elt(const char *total_name) /* * find total moles in aq, surface, and exchange */ - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { count_elts = 0; paren_count = 0; @@ -3342,7 +3342,7 @@ system_total_elt(const char *total_name) mass_water_surface = charge_ptr->Get_mass_water(); count_elts = 0; paren_count = 0; - for (j = 0; j < count_s_x; j++) + for (j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type > HPLUS) continue; @@ -3530,7 +3530,7 @@ system_total_elt_secondary(const char *total_name) /* * find total moles in aq, surface, and exchange */ - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { count_elts = 0; paren_count = 0; @@ -3608,7 +3608,7 @@ system_total_elt_secondary(const char *total_name) */ mass_water_surface = charge_ptr->Get_mass_water(); sum = 0; - for (j = 0; j < count_s_x; j++) + for (j = 0; j < (int)this->s_x.size(); j++) { count_elts = 0; paren_count = 0; @@ -3835,7 +3835,7 @@ solution_sum_secondary(const char *total_name) * find total moles in aq, surface, and exchange */ sum = 0; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type > H2O) continue; diff --git a/integrate.cpp b/integrate.cpp index 3636b1ed..1dbd5200 100644 --- a/integrate.cpp +++ b/integrate.cpp @@ -53,7 +53,7 @@ calc_all_g(void) /* * calculate g for given surface for each species */ - for (int i = 0; i < count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type > HPLUS) continue; @@ -252,7 +252,7 @@ g_function(LDBLE x_value) { it->second.Set_psi_to_z(exp(ln_x_value * it->first) - 1.0); } - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type < H2O && s_x[i]->z != 0.0) { @@ -265,7 +265,7 @@ g_function(LDBLE x_value) sum1 = 0.0; output_msg(sformatf( "Species\tmoles\tX**z-1\tsum\tsum charge\n")); - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type < H2O && s_x[i]->z != 0.0) { @@ -479,7 +479,7 @@ calc_init_g(void) /* * calculate g for given surface for each species */ - for (int i = 0; i < count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type > HPLUS) continue; @@ -703,7 +703,7 @@ sum_diffuse_layer(cxxSurfaceCharge *charge_ptr) count_elts = 0; paren_count = 0; mass_water_surface = charge_ptr->Get_mass_water(); - for (int j = 0; j < count_s_x; j++) + for (int j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type > HPLUS) continue; @@ -771,7 +771,7 @@ calc_all_donnan(void) it->second = 0.0; } charge_group_map.clear(); - for (int i = 0; i < count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type > HPLUS) continue; @@ -925,7 +925,7 @@ calc_init_donnan(void) charge_group_map.clear(); charge_group_map[0.0] = 0.0; - for (int i = 0; i < count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type > HPLUS) continue; @@ -989,7 +989,7 @@ calc_init_donnan(void) charge_ptr->Get_g_map()[z].Set_dg(-z); } /* save g for species */ - for (int i = 0; i < count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { int is = s_x[i]->number; assert (is < (int) s_diff_layer.size()); diff --git a/mainsubs.cpp b/mainsubs.cpp index ef406ab9..50c6085c 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1425,7 +1425,7 @@ xsolution_save(int n_user) } if (pitzer_model == TRUE || sit_model == TRUE) { - for (int j = 0; j < count_s_x; j++) + for (int j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->lg != 0.0) { @@ -1464,7 +1464,7 @@ xsolution_save(int n_user) { // saves mol/L temp_solution.Get_species_map().clear(); - for (int i = 0; i < this->count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type <= H2O) { @@ -1473,7 +1473,7 @@ xsolution_save(int n_user) } // saves gamma temp_solution.Get_log_gamma_map().clear(); - for (int i = 0; i < this->count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type <= H2O) { @@ -1618,7 +1618,7 @@ xsurface_save(int n_user) { cxxSurfaceCharge & charge_ref = surface_ptr->Get_surface_charges()[i]; double mass_water_surface = charge_ref.Get_mass_water(); - for (int j = 0; j < count_s_x; j++) + for (int j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type > H2O) continue; diff --git a/model.cpp b/model.cpp index 011745da..ae7520aa 100644 --- a/model.cpp +++ b/model.cpp @@ -637,7 +637,7 @@ gammas(LDBLE mu) /* * Calculate activity coefficients */ - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { switch (s_x[i]->gflag) { @@ -881,7 +881,7 @@ int Phreeqc::gammas_a_f(int i1) } } - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->gflag != 4 || s_x[i]->primary) continue; @@ -2374,7 +2374,7 @@ molalities(int allow_overflow) s_h2o->tot_g_moles = s_h2o->moles; s_h2o->tot_dh2o_moles = 0.0; } - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type > HPLUS && s_x[i]->type != EX && s_x[i]->type != SURF) @@ -2434,7 +2434,7 @@ molalities(int allow_overflow) } struct species *s_ptr = NULL; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { s_ptr = s_x[i]; if (s_ptr->type > HPLUS && s_ptr->type != EX && s_ptr->type != SURF) @@ -4376,7 +4376,7 @@ residuals(void) { sum = 0; sum1 = 0; - for (j = 0; j < count_s_x; j++) + for (j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type == SURF) { @@ -4422,7 +4422,7 @@ residuals(void) negfpsirt = master_ptr2->s->la * LOG_10; sum = 0; sum1 = 0; - for (j = 0; j < count_s_x; j++) + for (j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type < H2O) { @@ -4577,7 +4577,7 @@ set(int initial) return (set_sit(initial)); iterations = -1; solution_ptr = use.Get_solution_ptr(); - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { s_x[i]->lm = LOG_ZERO_MOLALITY; s_x[i]->lg = 0.0; @@ -4921,7 +4921,7 @@ sum_species(void) total_ions_x = 0.0; total_o_x = 0.0; total_h_x = 0.0; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type == EX) continue; @@ -5177,8 +5177,7 @@ free_model_allocs(void) my_array = (LDBLE *) free_check_null(my_array); delta = (LDBLE *) free_check_null(delta); residual = (LDBLE *) free_check_null(residual); - s_x = (struct species **) free_check_null(s_x); - count_s_x = 0; + s_x.clear(); sum_mb1 = (struct list1 *) free_check_null(sum_mb1); count_sum_mb1 = 0; sum_mb2 = (struct list2 *) free_check_null(sum_mb2); diff --git a/pitzer.cpp b/pitzer.cpp index d6209f3b..a964fdae 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1710,14 +1710,14 @@ set_pz(int initial) */ iterations = -1; solution_ptr = use.Get_solution_ptr(); - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { s_x[i]->lm = LOG_ZERO_MOLALITY; s_x[i]->lg_pitzer = 0.0; } if (initial == TRUE || set_and_run_attempt > 0) { - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { s_x[i]->lg = 0.0; } @@ -2342,7 +2342,7 @@ model_pz(void) { count_basis_change++; - count_unknowns -= count_s_x; + count_unknowns -= (int)this->s_x.size(); reprep(); full_pitzer = false; } @@ -2467,7 +2467,7 @@ gammas_pz(bool exch_a_f) /* * Calculate activity coefficients */ - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { switch (s_x[i]->gflag) { @@ -2539,7 +2539,7 @@ gammas_pz(bool exch_a_f) if (use.Get_exchange_ptr() != NULL && exch_a_f) // appt for gammas_a_f { - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { switch (s_x[i]->gflag) { diff --git a/prep.cpp b/prep.cpp index 9471368b..62a08dbd 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1152,15 +1152,10 @@ build_model(void) /* * Make space for lists of pointers to species in the model */ - - max_s_x = MAX_S; - // clear sum_species_map, which is built from s_x sum_species_map_db.clear(); sum_species_map.clear(); - - space((void **) ((void *) &s_x), INIT, &max_s_x, - sizeof(struct species *)); + s_x.clear(); max_sum_mb1 = MAX_SUM_MB; count_sum_mb1 = 0; @@ -1202,7 +1197,7 @@ build_model(void) /* * Pick species in the model, determine reaction for model, build jacobian */ - count_s_x = 0; + s_x.clear(); compute_gfw("H2O", &gfw_water); gfw_water *= 0.001; for (i = 0; i < (int)s.size(); i++) @@ -1225,13 +1220,10 @@ build_model(void) } if (pitzer_model == FALSE && sit_model == FALSE) s[i]->lg = 0.0; - if (count_s_x + 1 >= max_s_x) - { - space((void **) ((void *) &s_x), count_s_x + 1, - &max_s_x, sizeof(struct species *)); - } compute_gfw(s[i]->name, &s[i]->gfw); - s_x[count_s_x++] = s[i]; + size_t count_s_x = s_x.size(); + s_x.resize(count_s_x + 1); + s_x[count_s_x] = s[i]; /* * Write mass action equation for current model @@ -1364,7 +1356,7 @@ build_model(void) if (pitzer_model == TRUE || sit_model == TRUE) { j0 = count_unknowns; - j = count_unknowns + count_s_x; + j = count_unknowns + (int)this->s_x.size(); k = j0; for (i = j0; i < j; i++) { @@ -2665,7 +2657,8 @@ reprep(void) /* * Free arrays built in build_model */ - s_x = (struct species **) free_check_null(s_x); + //s_x = (struct species **) free_check_null(s_x); + s_x.clear(); sum_mb1 = (struct list1 *) free_check_null(sum_mb1); sum_mb2 = (struct list2 *) free_check_null(sum_mb2); sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); @@ -5624,7 +5617,7 @@ calc_vm(LDBLE tc, LDBLE pa) */ if (llnl_count_temp > 0) return OK; LDBLE pb_s = 2600. + pa * 1.01325, TK_s = tc + 45.15, sqrt_mu = sqrt(mu_x); - for (int i = 0; i < count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { //if (!strcmp(s_x[i]->name, "H2O")) if (s_x[i] == s_h2o) @@ -5719,7 +5712,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ calc_vm(tc, pa); mu_terms_in_logk = false; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { //if (s_x[i]->rxn_x->logk[vm_tc]) /* calculate delta_v for the reaction... */ diff --git a/print.cpp b/print.cpp index 0c5be864..b006afc4 100644 --- a/print.cpp +++ b/print.cpp @@ -290,7 +290,7 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) { count_elts = 0; paren_count = 0; - for (j = 0; j < count_s_x; j++) + for (j = 0; j < (int)this->s_x.size(); j++) { if (s_x[j]->type > HPLUS) continue; @@ -3620,16 +3620,15 @@ print_alkalinity(void) if (pr.alkalinity == FALSE || pr.all == FALSE) return (OK); print_centered("Distribution of alkalinity"); - alk_list = - (struct species_list *) - PHRQ_malloc((size_t) (count_s_x * sizeof(struct species_list))); + alk_list = (struct species_list *) + PHRQ_malloc((s_x.size() * sizeof(struct species_list))); if (alk_list == NULL) { malloc_error(); return (OK); } j = 0; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->alk == 0.0) continue; diff --git a/sit.cpp b/sit.cpp index 22fbdd42..ab4e9c95 100644 --- a/sit.cpp +++ b/sit.cpp @@ -540,14 +540,14 @@ set_sit(int initial) */ iterations = -1; solution_ptr = use.Get_solution_ptr(); - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { s_x[i]->lm = LOG_ZERO_MOLALITY; s_x[i]->lg_pitzer = 0.0; } if (initial == TRUE || set_and_run_attempt > 0) { - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { s_x[i]->lg = 0.0; } @@ -1135,7 +1135,7 @@ model_sit(void) { count_basis_change++; - count_unknowns -= count_s_x; + count_unknowns -= (int)this->s_x.size(); reprep(); full_pitzer = false; } @@ -1263,7 +1263,7 @@ gammas_sit() /* * Calculate activity coefficients */ - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { switch (s_x[i]->gflag) { @@ -1326,7 +1326,7 @@ gammas_sit() if (use.Get_exchange_ptr() != NULL) { - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { switch (s_x[i]->gflag) { diff --git a/transport.cpp b/transport.cpp index c2e84bc0..696cf4a2 100644 --- a/transport.cpp +++ b/transport.cpp @@ -5891,7 +5891,7 @@ viscosity(void) tc = (tc_x > 200) ? 200 : tc_x; - for (i = 0; i < count_s_x; i++) + for (i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type != AQ && s_x[i]->type > HPLUS) continue; From e43471a738af044c950538718a6c51945d6f70f4 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 18:21:40 -0600 Subject: [PATCH 17/34] vector s_x --- Phreeqc.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 68239da3..7d3e4c05 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -723,10 +723,6 @@ void Phreeqc::init(void) *---------------------------------------------------------------------- */ moles_per_kilogram_string= NULL; pe_string = NULL; - // auto s_diff_layer; - s_x = NULL; - count_s_x = 0; - max_s_x = 0; s_h2o = NULL; s_hplus = NULL; s_h3oplus = NULL; From b87d0cdd040429fb093120556d1247c95ee9a830 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 20:23:11 -0600 Subject: [PATCH 18/34] vector my_array, residual, delta --- Phreeqc.cpp | 3 --- Phreeqc.h | 4 +--- inverse.cpp | 28 +++++++--------------------- model.cpp | 6 +++--- prep.cpp | 28 ++++------------------------ 5 files changed, 15 insertions(+), 54 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 7d3e4c05..ce736909 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -870,9 +870,6 @@ void Phreeqc::init(void) stop_program = FALSE; incremental_reactions = FALSE; count_strings = 0; - my_array = NULL; - delta = NULL; - residual = NULL; input_error = 0; next_keyword = Keywords::KEY_NONE; parse_error = 0; diff --git a/Phreeqc.h b/Phreeqc.h index d51d0330..e1702fc1 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1614,9 +1614,7 @@ protected: int count_strings; int max_strings; - LDBLE *my_array; - LDBLE *delta; - LDBLE *residual; + std::vector my_array, delta, residual; int input_error; diff --git a/inverse.cpp b/inverse.cpp index 50830c63..8298778e 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -266,15 +266,9 @@ setup_inverse(struct inverse *inv_ptr) /* * Malloc space for arrays */ - my_array = (LDBLE *) free_check_null(my_array); - my_array = - (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * - sizeof(LDBLE)); - if (my_array == NULL) - malloc_error(); + my_array.resize((size_t)max_column_count * (size_t)max_row_count); - array1 = - (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * + array1 = (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * sizeof(LDBLE)); if (array1 == NULL) malloc_error(); @@ -288,10 +282,7 @@ setup_inverse(struct inverse *inv_ptr) if (row_name == NULL) malloc_error(); - delta = (LDBLE *) free_check_null(delta); - delta = (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); - if (delta == NULL) - malloc_error(); + delta.resize((size_t)max_column_count); inv_delta1 = (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); if (inv_delta1 == NULL) @@ -1332,8 +1323,8 @@ solve_inverse(struct inverse *inv_ptr) output_msg(sformatf( "\tNumber of calls to cl1: %d\n", count_calls)); } - my_array = (LDBLE *) free_check_null(my_array); - delta = (LDBLE *) free_check_null(delta); + my_array.clear(); + delta.clear(); array1 = (LDBLE *) free_check_null(array1); inv_zero = (LDBLE *) free_check_null(inv_zero); inv_res = (LDBLE *) free_check_null(inv_res); @@ -1462,7 +1453,7 @@ solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits) memcpy((void *) &(delta_save[0]), (void *) &(inv_zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - shrink(inv_ptr, my_array, array1, + shrink(inv_ptr, my_array.data(), array1, &k, &l, &m, &n, cur_bits, delta2, col_back, row_back); /* * Save delta constraints @@ -4418,7 +4409,7 @@ dump_netpath_pat(struct inverse *inv_ptr) LDBLE d1, d2, d3; char *ptr; LDBLE sum, sum1, sum_iso, d; - LDBLE *array_save, *l_delta_save; + std::vector array_save, l_delta_save; int count_unknowns_save, max_row_count_save, max_column_count_save, temp, count_current_solutions, temp_punch; int solnmap[10][2]; @@ -4440,8 +4431,6 @@ dump_netpath_pat(struct inverse *inv_ptr) max_row_count_save = max_row_count; max_column_count_save = max_column_count; - my_array = NULL; - delta = NULL; count_unknowns = 0; max_row_count = 0; max_column_count = 0; @@ -4879,9 +4868,6 @@ dump_netpath_pat(struct inverse *inv_ptr) fprintf(netpath_file, "%14d # Well number\n", count_pat_solutions); } - //free_model_allocs(); - my_array = (LDBLE *) free_check_null(my_array); - delta = (LDBLE *) free_check_null(delta); my_array = array_save; delta = l_delta_save; count_unknowns = count_unknowns_save; diff --git a/model.cpp b/model.cpp index ae7520aa..f31be925 100644 --- a/model.cpp +++ b/model.cpp @@ -5174,9 +5174,9 @@ free_model_allocs(void) } x = (struct unknown **) free_check_null(x); max_unknowns = 0; - my_array = (LDBLE *) free_check_null(my_array); - delta = (LDBLE *) free_check_null(delta); - residual = (LDBLE *) free_check_null(residual); + my_array.clear(); + delta.clear(); + residual.clear(); s_x.clear(); sum_mb1 = (struct list1 *) free_check_null(sum_mb1); count_sum_mb1 = 0; diff --git a/prep.cpp b/prep.cpp index 62a08dbd..1a657395 100644 --- a/prep.cpp +++ b/prep.cpp @@ -54,10 +54,7 @@ prep(void) * Must allocate all necessary space before pointers to * X are set. */ - - //if (!same_model && !switch_numerical) - // numerical_fixed_volume = false; - if (same_model == FALSE || !my_array/*|| switch_numerical*/) + if (same_model == FALSE || my_array.size() == 0) { clear(); setup_unknowns(); @@ -81,26 +78,9 @@ prep(void) /* * Allocate space for array */ -/* - array = (LDBLE *) PHRQ_malloc( (size_t) (count_unknowns+1) * count_unknowns * sizeof( LDBLE )); - if (array == NULL) malloc_error(); - delta = (LDBLE *) PHRQ_malloc( (size_t) count_unknowns * sizeof( LDBLE )); - if (delta == NULL) malloc_error(); - residual = (LDBLE *) PHRQ_malloc( (size_t) count_unknowns * sizeof( LDBLE )); - if (residual == NULL) malloc_error(); -*/ - my_array = - (LDBLE *) PHRQ_malloc((size_t) (max_unknowns + 1) * - max_unknowns * sizeof(LDBLE)); - if (my_array == NULL) - malloc_error(); - delta = (LDBLE *) PHRQ_malloc((size_t) max_unknowns * sizeof(LDBLE)); - if (delta == NULL) - malloc_error(); - residual = - (LDBLE *) PHRQ_malloc((size_t) max_unknowns * sizeof(LDBLE)); - if (residual == NULL) - malloc_error(); + my_array.resize(((size_t)max_unknowns + 1) * (size_t)max_unknowns); + delta.resize((size_t)max_unknowns); + residual.resize((size_t)max_unknowns); for (int j = 0; j < max_unknowns; j++) { residual[j] = 0; From e3ea0100c260641547af532b726f5d0301403372 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 21:10:35 -0600 Subject: [PATCH 19/34] vector sit_params --- Phreeqc.cpp | 12 ++---------- Phreeqc.h | 3 +-- pitzer_structures.cpp | 14 ++++++-------- sit.cpp | 20 +++++++------------- 4 files changed, 16 insertions(+), 33 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index ce736909..c140efa3 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1213,10 +1213,7 @@ void Phreeqc::init(void) /* readtr.cpp */ // auto dump_file_name_cpp; /* sit.cpp ------------------------------- */ - sit_params = NULL; - count_sit_param = 0; - max_sit_param = 100; - // auto sit_param_map + sit_A0 = 0; sit_count_cations = 0; sit_count_anions = 0; @@ -2388,12 +2385,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) sit_M = NULL; sit_LGAMMA = NULL; */ - count_sit_param = 0; //pSrc->count_sit_param; - max_sit_param = 1; // count_sit_param; - for (int i = 0; i < pSrc->count_sit_param; i++) - { - sit_param_store(pSrc->sit_params[i], true); - } + sit_params.clear(); sit_param_map = pSrc->sit_param_map; /* tidy.cpp ------------------------------- */ //a0 = 0; diff --git a/Phreeqc.h b/Phreeqc.h index e1702fc1..596f1320 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1884,8 +1884,7 @@ protected: std::string dump_file_name_cpp; /* sit.cpp ------------------------------- */ - struct pitz_param **sit_params; - int count_sit_param, max_sit_param; + std::vector sit_params; std::map< std::string, size_t > sit_param_map; LDBLE sit_A0; int sit_count_cations, sit_count_anions, sit_count_neutrals; diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index 061eb715..339f5af7 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -274,14 +274,10 @@ sit_param_store(struct pitz_param *pzp_ptr, bool force_copy) } else { - if (count_sit_param >= max_sit_param) - { - space((void **) ((void *) &sit_params), - count_sit_param, &max_sit_param, - sizeof(struct pitz_param *)); - } if (force_copy) { + size_t count_sit_param = sit_params.size(); + sit_params.resize(count_sit_param + 1); sit_params[count_sit_param] = pitz_param_duplicate(pzp_ptr); // clean up pointers // species @@ -294,13 +290,15 @@ sit_param_store(struct pitz_param *pzp_ptr, bool force_copy) } // thetas sit_params[count_sit_param]->thetas = NULL; + sit_param_map[key] = count_sit_param; } else { + size_t count_sit_param = sit_params.size(); + sit_params.resize(count_sit_param + 1); sit_params[count_sit_param] = pzp_ptr; + sit_param_map[key] = count_sit_param; } - sit_param_map[key] = count_sit_param; - count_sit_param++; } } diff --git a/sit.cpp b/sit.cpp index ab4e9c95..a39c42a7 100644 --- a/sit.cpp +++ b/sit.cpp @@ -12,10 +12,7 @@ sit_init(void) * Initialization for SIT */ sit_model = FALSE; - max_sit_param = 100; - count_sit_param = 0; - space((void **) ((void *) &sit_params), INIT, &max_sit_param, - sizeof(struct pitz_param *)); + sit_params.clear(); OTEMP = -100.; OPRESS = -100.; return OK; @@ -94,7 +91,7 @@ sit_tidy(void) /* * put species numbers in sit_params */ - for (i = 0; i < count_sit_param; i++) + for (i = 0; i < (int)sit_params.size(); i++) { for (j = 0; j < 3; j++) { @@ -117,7 +114,7 @@ sit_tidy(void) } /* remake map */ { sit_param_map.clear(); - for (int j = 0; j < count_sit_param; j++) + for (int j = 0; j < (int)sit_params.size(); j++) { std::set< std::string > header; for (int i = 0; i < 3; i++) @@ -134,7 +131,7 @@ sit_tidy(void) std::string key = key_str.str().c_str(); sit_param_map[key] = j; } - assert ((int) sit_param_map.size() == count_sit_param); + assert ((int) sit_param_map.size() == (int)sit_params.size()); } if (get_input_errors() > 0) return (ERROR); return OK; @@ -403,8 +400,6 @@ sit(void) * Sums for sit_LGAMMA, and OSMOT * epsilons are tabulated for log10 gamma (not ln gamma) */ - //for (i = 0; i < count_sit_param; i++) - //{ for (size_t j = 0; j < param_list.size(); j++) { int i = param_list[j]; @@ -508,12 +503,11 @@ sit_clean_up(void) */ int i; - for (i = 0; i < count_sit_param; i++) + for (i = 0; i < (int)sit_params.size(); i++) { sit_params[i] = (struct pitz_param *) free_check_null(sit_params[i]); } - count_sit_param = 0; - sit_params = (struct pitz_param **) free_check_null(sit_params); + sit_params.clear(); sit_param_map.clear(); sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); @@ -1489,7 +1483,7 @@ sit_make_lists(void) } } } - for (int i = 0; i < count_sit_param; i++) + for (int i = 0; i < (int)sit_params.size(); i++) { int i0 = sit_params[i]->ispec[0]; int i1 = sit_params[i]->ispec[1]; From b1af156bcb6dfad16776bd57687475d8d421faab Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 23:00:38 -0600 Subject: [PATCH 20/34] vector pitz_params --- Phreeqc.cpp | 10 +----- Phreeqc.h | 3 +- pitzer.cpp | 77 +++++++++++++++++++------------------------ pitzer_structures.cpp | 14 ++++---- 4 files changed, 41 insertions(+), 63 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index c140efa3..e404794f 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1161,9 +1161,6 @@ void Phreeqc::init(void) AW = 0; VP = 0; DW0 = 0; - pitz_params = NULL; - count_pitz_param = 0; - max_pitz_param = 100; // auto pitz_param_map theta_params = 0; count_theta_param = 0; @@ -2280,13 +2277,8 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) always_full_pitzer = pSrc->always_full_pitzer; ICON = pSrc->ICON; IC = pSrc->IC; - /* - pitz_params = NULL; - count_pitz_param = 0; - max_pitz_param = 100; - */ - for (int i = 0; i < pSrc->count_pitz_param; i++) + for (int i = 0; i < (int)pSrc->pitz_params.size(); i++) { pitz_param_store(pSrc->pitz_params[i], true); } diff --git a/Phreeqc.h b/Phreeqc.h index 596f1320..a9b7bbd0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1846,8 +1846,7 @@ protected: LDBLE COSMOT; LDBLE AW; LDBLE VP, DW0; - struct pitz_param **pitz_params; - int count_pitz_param, max_pitz_param; + std::vector pitz_params; std::map< std::string, size_t > pitz_param_map; struct theta_param **theta_params; int count_theta_param, max_theta_param; diff --git a/pitzer.cpp b/pitzer.cpp index a964fdae..10875b6a 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -15,11 +15,8 @@ pitzer_init(void) * Initialization for pitzer */ pitzer_model = FALSE; - max_pitz_param = 100; - count_pitz_param = 0; use_etheta = TRUE; - space((void **) ((void *) &pitz_params), INIT, &max_pitz_param, - sizeof(struct pitz_param *)); + pitz_params.clear(); max_theta_param = 100; count_theta_param = 0; @@ -128,20 +125,21 @@ pitzer_tidy(void) * cation-cation or anion-anion pair * Remove old TYPE_ETHETA definitions */ - j = 0; - for (i = 0; i < count_pitz_param; i++) + + std::vector pitz_params_temp = pitz_params; + pitz_params.clear(); + + for (i = 0; i < (int)pitz_params_temp.size(); i++) { - if (pitz_params[i]->type == TYPE_ETHETA) + if (pitz_params_temp[i]->type == TYPE_ETHETA) { - pitz_params[i] = - (struct pitz_param *) free_check_null(pitz_params[i]); + pitz_params_temp[i] = (struct pitz_param*)free_check_null(pitz_params_temp[i]); } else { - pitz_params[j++] = pitz_params[i]; + pitz_params.push_back(pitz_params_temp[i]); } } - count_pitz_param = j; for (i = 0; i < count_cations - 1; i++) { for (j = i + 1; j < count_cations; j++) @@ -149,13 +147,9 @@ pitzer_tidy(void) sprintf(line, "%s %s 1", spec[i]->name, spec[j]->name); pzp_ptr = pitz_param_read(line, 2); pzp_ptr->type = TYPE_ETHETA; - if (count_pitz_param >= max_pitz_param) - { - space((void **) ((void *) &pitz_params), count_pitz_param, - &max_pitz_param, sizeof(struct pitz_param *)); - } - pitz_params[count_pitz_param++] = pzp_ptr; - + size_t count_pitz_param = pitz_params.size(); + pitz_params.resize(count_pitz_param + 1); + pitz_params[count_pitz_param] = pzp_ptr; } } for (i = 2 * (int)s.size(); i < 2 * (int)s.size() + count_anions - 1; i++) @@ -165,19 +159,15 @@ pitzer_tidy(void) sprintf(line, "%s %s 1", spec[i]->name, spec[j]->name); pzp_ptr = pitz_param_read(line, 2); pzp_ptr->type = TYPE_ETHETA; - if (count_pitz_param >= max_pitz_param) - { - space((void **) ((void *) &pitz_params), count_pitz_param, - &max_pitz_param, sizeof(struct pitz_param *)); - } + size_t count_pitz_param = pitz_params.size(); + pitz_params.resize(count_pitz_param + 1); pitz_params[count_pitz_param] = pzp_ptr; - count_pitz_param++; } } /* * put species numbers in pitz_params */ - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { for (j = 0; j < 3; j++) { @@ -205,7 +195,7 @@ pitzer_tidy(void) string1 = string_hsave("K+"); string2 = string_hsave("Cl-"); IC = ISPEC(string2); - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { if ((pitz_params[i]->species[0] == string1 && pitz_params[i]->species[1] == string2) || @@ -248,7 +238,7 @@ pitzer_tidy(void) /* * Set alpha values */ - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { z0 = fabs(spec[pitz_params[i]->ispec[0]]->z); z1 = fabs(spec[pitz_params[i]->ispec[1]]->z); @@ -296,11 +286,11 @@ pitzer_tidy(void) /* * Add specific alphas */ - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { if (pitz_params[i]->type == TYPE_ALPHAS) { - for (j = 0; j < count_pitz_param; j++) + for (j = 0; j < (int)pitz_params.size(); j++) { if (pitz_params[j]->type != TYPE_B1) continue; @@ -311,7 +301,7 @@ pitzer_tidy(void) pitz_params[j]->alpha = pitz_params[i]->a[0]; break; } - for (j = 0; j < count_pitz_param; j++) + for (j = 0; j < (int)pitz_params.size(); j++) { if (pitz_params[j]->type != TYPE_B2) continue; @@ -338,7 +328,7 @@ pitzer_tidy(void) } } count_theta_param = 0; - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { if (pitz_params[i]->type == TYPE_ETHETA) { @@ -369,7 +359,7 @@ pitzer_tidy(void) /* Coef for Osmotic coefficient for TYPE_MU */ - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { if (pitz_params[i]->type == TYPE_MU) { @@ -432,7 +422,7 @@ pitzer_tidy(void) /* Coef for gammas for TYPE_MU */ - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { if (pitz_params[i]->type == TYPE_MU) { @@ -488,7 +478,7 @@ pitzer_tidy(void) } /* Debug TYPE_MU coefficients */ /* - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { if (pitz_params[i]->type == TYPE_MU) { @@ -504,7 +494,7 @@ pitzer_tidy(void) /* Coef for Osmotic coefficient for TYPE_LAMDA */ - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { if (pitz_params[i]->type == TYPE_LAMDA) { @@ -529,7 +519,7 @@ pitzer_tidy(void) } /* Debug TYPE_LAMDA coefficients */ /* - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { if (pitz_params[i]->type == TYPE_LAMDA) { @@ -542,7 +532,7 @@ pitzer_tidy(void) /* remake map */ { pitz_param_map.clear(); - for (int j = 0; j < count_pitz_param; j++) + for (int j = 0; j < (int)pitz_params.size(); j++) { std::set< std::string > header; for (int i = 0; i < 3; i++) @@ -559,7 +549,7 @@ pitzer_tidy(void) std::string key = key_str.str().c_str(); pitz_param_map[key] = j; } - assert ((int) pitz_param_map.size() == count_pitz_param); + assert ((int) pitz_param_map.size() == (int)pitz_params.size()); } return OK; } @@ -783,7 +773,7 @@ C VP = patm_x; #if !defined(PITZER_LISTS) int i; - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { calc_pitz_param(pitz_params[i], TK, TR); } @@ -1018,7 +1008,7 @@ pitzer(void) /* * Sums for F, LGAMMA, and OSMOT */ - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { i0 = pitz_params[i]->ispec[0]; i1 = pitz_params[i]->ispec[1]; @@ -1670,14 +1660,13 @@ pitzer_clean_up(void) * Free all allocated memory, except strings */ int i; - for (i = 0; i < count_pitz_param; i++) + for (i = 0; i < (int)pitz_params.size(); i++) { pitz_params[i] = (struct pitz_param *) free_check_null(pitz_params[i]); } - count_pitz_param = 0; pitz_param_map.clear(); - pitz_params = (struct pitz_param **) free_check_null(pitz_params); + pitz_params.clear(); for (i = 0; i < count_theta_param; i++) { theta_params[i] = @@ -2673,7 +2662,7 @@ pitzer_make_lists(void) { IPRSNT[IC] = TRUE; } - for (int i = 0; i < count_pitz_param; i++) + for (int i = 0; i < (int)pitz_params.size(); i++) { /* TYPE_B0, TYPE_B1, TYPE_B2, TYPE_C0, TYPE_THETA, TYPE_LAMDA, TYPE_ZETA, diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index 339f5af7..e1c14938 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -195,14 +195,10 @@ pitz_param_store(struct pitz_param *pzp_ptr, bool force_copy) } else { - if (count_pitz_param >= max_pitz_param) - { - space((void **) ((void *) &pitz_params), - count_pitz_param, &max_pitz_param, - sizeof(struct pitz_param *)); - } if (force_copy) { + size_t count_pitz_param = pitz_params.size(); + pitz_params.resize(count_pitz_param + 1); pitz_params[count_pitz_param] = pitz_param_duplicate(pzp_ptr); // clean up pointers // species @@ -215,13 +211,15 @@ pitz_param_store(struct pitz_param *pzp_ptr, bool force_copy) } // thetas pitz_params[count_pitz_param]->thetas = NULL; + pitz_param_map[key] = count_pitz_param; } else { + size_t count_pitz_param = pitz_params.size(); + pitz_params.resize(count_pitz_param + 1); pitz_params[count_pitz_param] = pzp_ptr; + pitz_param_map[key] = count_pitz_param; } - pitz_param_map[key] = count_pitz_param; - count_pitz_param++; } } From 0957a528df95cbf75308b8812e32ec556eaf0674 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 23:19:42 -0600 Subject: [PATCH 21/34] vector theta_params --- Phreeqc.cpp | 25 +++++-------------------- Phreeqc.h | 3 +-- pitzer.cpp | 34 ++++++++++------------------------ pitzer_structures.cpp | 2 +- 4 files changed, 17 insertions(+), 47 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e404794f..1ba97b95 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1162,9 +1162,6 @@ void Phreeqc::init(void) VP = 0; DW0 = 0; // auto pitz_param_map - theta_params = 0; - count_theta_param = 0; - max_theta_param = 100; use_etheta = TRUE; OTEMP = -100.; OPRESS = -100.; @@ -2284,24 +2281,12 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } pitz_param_map = pSrc->pitz_param_map; // auto pitz_param_map - /* - theta_params = 0; - count_theta_param = 0; - max_theta_param = 100; - use_etheta = TRUE; - */ - count_theta_param = pSrc->count_theta_param; - max_theta_param = count_theta_param; - space((void **)((void *)&theta_params), count_theta_param, &max_theta_param, - sizeof(struct theta_param *)); - if (pSrc->theta_params != NULL) + for (int i = 0; i < (int)pSrc->theta_params.size(); i++) { - //theta_params = (struct theta_param **) malloc((size_t)count_theta_param * sizeof(struct theta_param *)); - for (int i = 0; i < count_theta_param; i++) - { - theta_params[i] = theta_param_alloc(); - memcpy(theta_params[i], pSrc->theta_params[i], sizeof(struct theta_param)); - } + size_t count_theta_params = theta_params.size(); + theta_params.resize(count_theta_params + 1); + theta_params[count_theta_params] = theta_param_alloc(); + memcpy(theta_params[count_theta_params], pSrc->theta_params[i], sizeof(struct theta_param)); } use_etheta = pSrc->use_etheta; /* diff --git a/Phreeqc.h b/Phreeqc.h index a9b7bbd0..8979be00 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1848,8 +1848,7 @@ protected: LDBLE VP, DW0; std::vector pitz_params; std::map< std::string, size_t > pitz_param_map; - struct theta_param **theta_params; - int count_theta_param, max_theta_param; + std::vector theta_params; int use_etheta; LDBLE OTEMP, OPRESS; LDBLE A0; diff --git a/pitzer.cpp b/pitzer.cpp index 10875b6a..e13443ea 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -17,11 +17,7 @@ pitzer_init(void) pitzer_model = FALSE; use_etheta = TRUE; pitz_params.clear(); - - max_theta_param = 100; - count_theta_param = 0; - space((void **) ((void *) &theta_params), INIT, &max_theta_param, - sizeof(struct theta_param *)); + theta_params.clear(); ICON = TRUE; OTEMP = -100.; @@ -319,15 +315,11 @@ pitzer_tidy(void) * Add thetas pointer to etheta pitzer parameters */ - if (count_theta_param > 0) + for (i = 0; i < (int)theta_params.size(); i++) { - for (i = 0; i < count_theta_param; i++) - { - theta_params[i] = - (struct theta_param *) free_check_null(theta_params[i]); - } + theta_params[i] = (struct theta_param *) free_check_null(theta_params[i]); } - count_theta_param = 0; + theta_params.clear(); for (i = 0; i < (int)pitz_params.size(); i++) { if (pitz_params[i]->type == TYPE_ETHETA) @@ -337,18 +329,13 @@ pitzer_tidy(void) theta_param_ptr = theta_param_search(z0, z1); if (theta_param_ptr == NULL) { - if (count_theta_param >= max_theta_param) - { - space((void **) ((void *) &theta_params), - count_theta_param, &max_theta_param, - sizeof(struct theta_param *)); - } + size_t count_theta_param = theta_params.size(); + theta_params.resize(count_theta_param + 1); theta_params[count_theta_param] = theta_param_alloc(); theta_param_init(theta_params[count_theta_param]); theta_params[count_theta_param]->zj = z0; theta_params[count_theta_param]->zk = z1; theta_param_ptr = theta_params[count_theta_param]; - count_theta_param++; } pitz_params[i]->thetas = theta_param_ptr; } @@ -997,7 +984,7 @@ pitzer(void) /* * Calculate ethetas */ - for (i = 0; i < count_theta_param; i++) + for (i = 0; i < (int)theta_params.size(); i++) { z0 = theta_params[i]->zj; z1 = theta_params[i]->zk; @@ -1321,7 +1308,7 @@ pitzer(void) */ if (use_etheta == TRUE) { - for (i = 0; i < count_theta_param; i++) + for (i = 0; i < (int)theta_params.size(); i++) { z0 = theta_params[i]->zj; z1 = theta_params[i]->zk; @@ -1667,13 +1654,12 @@ pitzer_clean_up(void) } pitz_param_map.clear(); pitz_params.clear(); - for (i = 0; i < count_theta_param; i++) + for (i = 0; i < (int)theta_params.size(); i++) { theta_params[i] = (struct theta_param *) free_check_null(theta_params[i]); } - count_theta_param = 0; - theta_params = (struct theta_param **) free_check_null(theta_params); + theta_params.clear(); LGAMMA = (LDBLE *) free_check_null(LGAMMA); IPRSNT = (int *) free_check_null(IPRSNT); spec = (struct species **) free_check_null(spec); diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index e1c14938..93d8ccd3 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -346,7 +346,7 @@ theta_param_search(LDBLE zj, LDBLE zk) * Returns NULL if not found, index number in theta_params if found */ int i; - for (i = 0; i < count_theta_param; i++) + for (i = 0; i < (int)theta_params.size(); i++) { if ((theta_params[i]->zj == zj && theta_params[i]->zk == zk) || (theta_params[i]->zj == zk && theta_params[i]->zk == zj)) From e8c90279e6c9e6cffad9477717ac77397ddc6f0a Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 00:23:56 -0600 Subject: [PATCH 22/34] vector elt_list --- Phreeqc.cpp | 4 ---- Phreeqc.h | 5 +---- basicsubs.cpp | 58 ++++++++++++++++++++++++-------------------------- integrate.cpp | 4 ++-- mainsubs.cpp | 3 --- parse.cpp | 19 +++++++---------- prep.cpp | 30 ++++++++++++-------------- print.cpp | 4 ++-- step.cpp | 4 ++-- structures.cpp | 7 +++--- tally.cpp | 24 ++++++++++----------- tidy.cpp | 24 ++++++++++----------- utilities.cpp | 20 +++++++---------- 13 files changed, 93 insertions(+), 113 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 1ba97b95..47122dcf 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -715,9 +715,7 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Element List *---------------------------------------------------------------------- */ - elt_list = NULL; count_elts = 0; - max_elts = MAX_ELTS; /*---------------------------------------------------------------------- * Species *---------------------------------------------------------------------- */ @@ -1624,9 +1622,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) * Element List *---------------------------------------------------------------------- */ /* - elt_list = NULL; count_elts = 0; - max_elts = MAX_ELTS; */ /*---------------------------------------------------------------------- * Reaction diff --git a/Phreeqc.h b/Phreeqc.h index 8979be00..4dcc12d6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1463,11 +1463,8 @@ protected: /*---------------------------------------------------------------------- * Element List *---------------------------------------------------------------------- */ - - struct elt_list *elt_list; /* structure array of working space while reading equations - names are in "strings", initially in input order */ + std::vector elt_list; int count_elts; /* number of elements in elt_list = position of next */ - int max_elts; /*---------------------------------------------------------------------- * Reaction *---------------------------------------------------------------------- */ diff --git a/basicsubs.cpp b/basicsubs.cpp index f3d97f24..a54440cc 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -1124,8 +1124,8 @@ diff_layer_total(const char *total_name, const char *surface_name) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), Phreeqc:: elt_list_compare); + qsort(elt_list.data(), (size_t) count_elts, + sizeof(struct elt_list), Phreeqc:: elt_list_compare); elt_list_combine(); } /* @@ -2422,8 +2422,8 @@ surf_total_no_redox(const char *total_name, const char *surface_name) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* @@ -2838,8 +2838,8 @@ kinetics_formula(std::string kin_name, cxxNameDouble &stoichiometry) //elt_list[count_elts].elt = NULL; if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } stoichiometry = elt_list_NameDouble(); @@ -3272,8 +3272,8 @@ system_total_elt(const char *total_name) if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* @@ -3360,8 +3360,8 @@ system_total_elt(const char *total_name) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* @@ -3407,8 +3407,8 @@ system_total_elt(const char *total_name) add_elt_list(phase_ptr->next_elt, x[i]->moles); if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } for (j = 0; j < count_elts; j++) @@ -3448,9 +3448,8 @@ system_total_elt(const char *total_name) comp_ptr->Get_moles()); if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), - elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } for (j = 0; j < count_elts; j++) @@ -3489,8 +3488,8 @@ system_total_elt(const char *total_name) add_elt_list(phase_ptr->next_elt, phase_ptr->moles_x); if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* @@ -3544,8 +3543,8 @@ system_total_elt_secondary(const char *total_name) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* @@ -3674,8 +3673,8 @@ system_total_elt_secondary(const char *total_name) add_elt_list(phase_ptr->next_sys_total, x[i]->moles); if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } for (j = 0; j < count_elts; j++) @@ -3716,9 +3715,8 @@ system_total_elt_secondary(const char *total_name) comp_ptr->Get_moles()); if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), - elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } for (j = 0; j < count_elts; j++) @@ -3759,8 +3757,8 @@ system_total_elt_secondary(const char *total_name) if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* @@ -3851,8 +3849,8 @@ solution_sum_secondary(const char *total_name) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* @@ -3968,8 +3966,8 @@ system_total_solids(cxxExchange *exchange_ptr, if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } return (OK); diff --git a/integrate.cpp b/integrate.cpp index 1dbd5200..c4488a65 100644 --- a/integrate.cpp +++ b/integrate.cpp @@ -726,8 +726,8 @@ sum_diffuse_layer(cxxSurfaceCharge *charge_ptr) if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t) count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } return (OK); diff --git a/mainsubs.cpp b/mainsubs.cpp index 50c6085c..10654610 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -60,9 +60,6 @@ initialize(void) cell_data[i].print = FALSE; } - space((void **) ((void *) &elt_list), INIT, &max_elts, - sizeof(struct elt_list)); - inverse = (struct inverse *) PHRQ_malloc((size_t) sizeof(struct inverse)); if (inverse == NULL) malloc_error(); count_inverse = 0; diff --git a/parse.cpp b/parse.cpp index 4bd6a255..22e00495 100644 --- a/parse.cpp +++ b/parse.cpp @@ -140,7 +140,7 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association) /* * Sort elements in reaction and combine */ - qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), + qsort(elt_list.data(), (size_t) count_elts, sizeof(struct elt_list), elt_list_compare); if (elt_list_combine() == ERROR) return (ERROR); @@ -228,7 +228,7 @@ check_eqn(int association) /* * Sort elements in reaction and combine */ - qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), + qsort(elt_list.data(), (size_t) count_elts, sizeof(struct elt_list), elt_list_compare); if (elt_list_combine() == ERROR) return (ERROR); @@ -607,10 +607,9 @@ get_elts_in_species(char **t_ptr, LDBLE coef) { return (ERROR); } - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } elt_list[count_elts].elt = element_store(element); if (get_num(t_ptr, &d) == ERROR) @@ -622,10 +621,9 @@ get_elts_in_species(char **t_ptr, LDBLE coef) /* * Expand working space for elements if necessary */ - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } continue; } @@ -875,10 +873,9 @@ get_secondary_in_species(char **t_ptr, LDBLE coef) /* * Expand working space for elements if necessary */ - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } continue; } diff --git a/prep.cpp b/prep.cpp index 1a657395..131cbb62 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5303,8 +5303,8 @@ write_mb_eqn_x(void) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } return (OK); @@ -5356,10 +5356,9 @@ write_mb_for_species_list(int n) { if (strcmp(elt_list[i].elt->name, "O(-2)") == 0) { - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } elt_list[count_elts].elt = element_h_one; elt_list[count_elts].coef = elt_list[i].coef * 2; @@ -5368,8 +5367,8 @@ write_mb_for_species_list(int n) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } s[n]->next_sys_total = @@ -5419,10 +5418,9 @@ write_phase_sys_total(int n) { if (strcmp(elt_list[i].elt->name, "O(-2)") == 0) { - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } elt_list[count_elts].elt = element_h_one; elt_list[count_elts].coef = elt_list[i].coef * 2; @@ -5431,8 +5429,8 @@ write_phase_sys_total(int n) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } phases[n]->next_sys_total = @@ -6545,8 +6543,8 @@ change_hydrogen_in_elt_list(LDBLE charge) found_o = -1; coef_h = 0.0; coef_o = 0.0; - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); for (j = 0; j < count_elts; j++) { @@ -6571,8 +6569,8 @@ change_hydrogen_in_elt_list(LDBLE charge) elt_list[count_elts].elt = s_hplus->primary->elt; elt_list[count_elts].coef = coef; count_elts++; - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); return (OK); } diff --git a/print.cpp b/print.cpp index b006afc4..4cd48a86 100644 --- a/print.cpp +++ b/print.cpp @@ -318,8 +318,8 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) */ if (count_elts > 0) { - qsort(elt_list, (size_t)count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* diff --git a/step.cpp b/step.cpp index a785b367..d9cf2715 100644 --- a/step.cpp +++ b/step.cpp @@ -1028,8 +1028,8 @@ add_gas_phase(cxxGasPhase *gas_phase_ptr) */ if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t) count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* diff --git a/structures.cpp b/structures.cpp index 30863ade..57011da8 100644 --- a/structures.cpp +++ b/structures.cpp @@ -292,7 +292,8 @@ clean_up(void) /* miscellaneous work space */ - elt_list = (struct elt_list *) free_check_null(elt_list); + //elt_list = (struct elt_list *) free_check_null(elt_list); + elt_list.clear(); trxn.token = (struct rxn_token_temp *) free_check_null(trxn.token); mb_unknowns = (struct unknown_list *) free_check_null(mb_unknowns); line = (char *) free_check_null(line); @@ -586,8 +587,8 @@ elt_list_save(void) */ if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* diff --git a/tally.cpp b/tally.cpp index 56a0c83b..ea45226f 100644 --- a/tally.cpp +++ b/tally.cpp @@ -550,8 +550,8 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) { add_elt_list(exchange_ptr->Get_exchange_comps()[j].Get_totals(), 1.0); } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t) count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); elt_list_to_tally_table(tally_table[i].total[n_buffer]); } @@ -572,8 +572,8 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) { add_elt_list(surface_ptr->Get_surface_comps()[j].Get_totals(), 1.0); } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t) count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); elt_list_to_tally_table(tally_table[i].total[n_buffer]); } @@ -643,8 +643,8 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) add_elt_list(phase_ptr->next_elt, (*gc)[l].Get_moles()); } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t) count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); elt_list_to_tally_table(tally_table[i].total[n_buffer]); break; @@ -921,8 +921,8 @@ build_tally_table(void) strcpy(token, phase_ptr->formula); add_elt_list(phase_ptr->next_elt, 1.0); } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t) count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); tally_table[n].formula = elt_list_save(); } @@ -973,8 +973,8 @@ build_tally_table(void) paren_count = 0; strcpy(token, phase_ptr->formula); add_elt_list(phase_ptr->next_elt, 1.0); - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); tally_table[n].formula = elt_list_save(); } @@ -1041,8 +1041,8 @@ build_tally_table(void) free_check_null(temp_name); } } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); tally_table[n].formula = elt_list_save(); } diff --git a/tidy.cpp b/tidy.cpp index 72404df6..38e90ffc 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1287,8 +1287,8 @@ tidy_inverse(void) */ if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t) count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } /* @@ -3495,8 +3495,8 @@ tidy_min_exchange(void) error_msg(error_string, CONTINUE); continue; } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); for (jj = 0; jj < count_elts; jj++) { @@ -3675,8 +3675,8 @@ update_min_exchange(void) error_msg(error_string, CONTINUE); continue; } - qsort(elt_list, (size_t)count_elts, - (size_t)sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); for (jj = 0; jj < count_elts; jj++) { @@ -3900,8 +3900,8 @@ tidy_min_surface(void) free_check_null(temp_formula); } } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); /* Makes no sense: sorbed species need not be in mineral structure... */ /* But elements that can desorb into solution must be in mineral */ @@ -4273,8 +4273,8 @@ tidy_kin_surface(void) /* save kinetics formula */ if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } elt_list_kinetics = elt_list_save(); @@ -4302,8 +4302,8 @@ tidy_kin_surface(void) } if (count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } for (int j = 0; j < count_elts; j++) diff --git a/utilities.cpp b/utilities.cpp index 49870995..86992a8b 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -19,10 +19,9 @@ add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef) for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; elt_list_ptr1++) { - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } elt_list[count_elts].elt = elt_list_ptr1->elt; elt_list[count_elts].coef = elt_list_ptr1->coef * coef; @@ -65,10 +64,9 @@ add_elt_list_multi_surf(struct elt_list *elt_list_ptr, LDBLE coef, struct elemen for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; elt_list_ptr1++) { - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } if (elt_list_ptr1->elt == surf_elt_ptr) { @@ -93,10 +91,9 @@ add_elt_list_multi_surf(struct elt_list *elt_list_ptr, LDBLE coef, struct elemen for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; elt_list_ptr1++) { - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } if (elt_list_ptr1->elt == surf_elt_ptr) { @@ -115,10 +112,9 @@ add_elt_list(const cxxNameDouble & nd, LDBLE coef) cxxNameDouble::const_iterator cit = nd.begin(); for ( ; cit != nd.end(); cit++) { - if (count_elts >= max_elts) + if (count_elts >= (int)elt_list.size()) { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); + elt_list.resize((size_t)count_elts + 1); } elt_list[count_elts].elt = element_store(cit->first.c_str()); elt_list[count_elts].coef = cit->second * coef; From 83cfb298d6ea3142c8dea295a57fe8a338e9a0e1 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 08:41:20 -0600 Subject: [PATCH 23/34] elt_list, moved qsort to elt_list_combine --- basicsubs.cpp | 99 +++++++------------------------------------------- integrate.cpp | 8 +--- parse.cpp | 8 ++-- prep.cpp | 25 ++----------- print.cpp | 7 +--- step.cpp | 7 +--- structures.cpp | 26 ++++++------- tally.cpp | 12 ------ tidy.cpp | 22 +---------- 9 files changed, 37 insertions(+), 177 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index a54440cc..dc10e530 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -1122,12 +1122,7 @@ diff_layer_total(const char *total_name, const char *surface_name) */ add_elt_list(s_x[j]->next_elt, moles_surface); } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t) count_elts, - sizeof(struct elt_list), Phreeqc:: elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Return totals */ @@ -2420,12 +2415,7 @@ surf_total_no_redox(const char *total_name, const char *surface_name) } } } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Return totals */ @@ -2836,12 +2826,7 @@ kinetics_formula(std::string kin_name, cxxNameDouble &stoichiometry) } formula.append(kin_name); //elt_list[count_elts].elt = NULL; - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); stoichiometry = elt_list_NameDouble(); break; } @@ -3270,12 +3255,7 @@ system_total_elt(const char *total_name) paren_count = 0; add_elt_list(s_x[i]->next_elt, s_x[i]->moles); - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Look for element */ @@ -3358,12 +3338,7 @@ system_total_elt(const char *total_name) */ add_elt_list(s_x[j]->next_elt, moles_surface); } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Print totals */ @@ -3405,12 +3380,7 @@ system_total_elt(const char *total_name) //struct phase * phase_ptr = phase_bsearch(x[i]->pp_assemblage_comp_name, &j, FALSE); struct phase * phase_ptr = x[i]->phase; add_elt_list(phase_ptr->next_elt, x[i]->moles); - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); for (j = 0; j < count_elts; j++) { if (strcmp(elt_list[j].elt->name, total_name) == 0) @@ -3446,12 +3416,7 @@ system_total_elt(const char *total_name) paren_count = 0; add_elt_list(phase_ptr->next_elt, comp_ptr->Get_moles()); - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); for (j = 0; j < count_elts; j++) { if (strcmp(elt_list[j].elt->name, total_name) == 0) @@ -3486,12 +3451,7 @@ system_total_elt(const char *total_name) count_elts = 0; paren_count = 0; add_elt_list(phase_ptr->next_elt, phase_ptr->moles_x); - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Look for element */ @@ -3541,12 +3501,7 @@ system_total_elt_secondary(const char *total_name) { add_elt_list(s_x[i]->next_sys_total, s_x[i]->moles); } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Look for element */ @@ -3671,12 +3626,7 @@ system_total_elt_secondary(const char *total_name) //struct phase * phase_ptr = phase_bsearch(x[i]->pp_assemblage_comp_name, &j, FALSE); struct phase * phase_ptr = x[i]->phase; add_elt_list(phase_ptr->next_sys_total, x[i]->moles); - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); for (j = 0; j < count_elts; j++) { if (strcmp(elt_list[j].elt->name, total_name) == 0) @@ -3713,12 +3663,7 @@ system_total_elt_secondary(const char *total_name) paren_count = 0; add_elt_list(phase_ptr->next_sys_total, comp_ptr->Get_moles()); - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); for (j = 0; j < count_elts; j++) { if (strcmp(elt_list[j].elt->name, total_name) == 0) @@ -3755,12 +3700,7 @@ system_total_elt_secondary(const char *total_name) add_elt_list(phase_ptr->next_sys_total, phase_ptr->moles_x); - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Look for element */ @@ -3847,12 +3787,7 @@ solution_sum_secondary(const char *total_name) { add_elt_list(s_x[i]->next_sys_total, s_x[i]->moles); } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Look for element */ @@ -3963,13 +3898,7 @@ system_total_solids(cxxExchange *exchange_ptr, it->second.Get_moles()); } } - - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); return (OK); } diff --git a/integrate.cpp b/integrate.cpp index c4488a65..ce6fa6b1 100644 --- a/integrate.cpp +++ b/integrate.cpp @@ -723,13 +723,7 @@ sum_diffuse_layer(cxxSurfaceCharge *charge_ptr) add_elt_list(s_x[j]->next_elt, moles_surface); } add_elt_list(s_h2o->next_elt, mass_water_surface / gfw_water); - - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t) count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); return (OK); } /* ---------------------------------------------------------------------- */ diff --git a/parse.cpp b/parse.cpp index 22e00495..8931f432 100644 --- a/parse.cpp +++ b/parse.cpp @@ -140,8 +140,8 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association) /* * Sort elements in reaction and combine */ - qsort(elt_list.data(), (size_t) count_elts, sizeof(struct elt_list), - elt_list_compare); + //qsort(elt_list.data(), (size_t) count_elts, sizeof(struct elt_list), + // elt_list_compare); if (elt_list_combine() == ERROR) return (ERROR); /* @@ -228,8 +228,8 @@ check_eqn(int association) /* * Sort elements in reaction and combine */ - qsort(elt_list.data(), (size_t) count_elts, sizeof(struct elt_list), - elt_list_compare); + //qsort(elt_list.data(), (size_t) count_elts, sizeof(struct elt_list), + // elt_list_compare); if (elt_list_combine() == ERROR) return (ERROR); /* diff --git a/prep.cpp b/prep.cpp index 131cbb62..b837e060 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5301,12 +5301,7 @@ write_mb_eqn_x(void) free_check_null(temp_name); } } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); return (OK); } @@ -5365,12 +5360,7 @@ write_mb_for_species_list(int n) count_elts++; } } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); s[n]->next_sys_total = (struct elt_list *) free_check_null(s[n]->next_sys_total); s[n]->next_sys_total = elt_list_save(); @@ -5427,12 +5417,7 @@ write_phase_sys_total(int n) count_elts++; } } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); phases[n]->next_sys_total = (struct elt_list *) free_check_null(phases[n]->next_sys_total); phases[n]->next_sys_total = elt_list_save(); @@ -6543,8 +6528,6 @@ change_hydrogen_in_elt_list(LDBLE charge) found_o = -1; coef_h = 0.0; coef_o = 0.0; - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); for (j = 0; j < count_elts; j++) { @@ -6569,8 +6552,6 @@ change_hydrogen_in_elt_list(LDBLE charge) elt_list[count_elts].elt = s_hplus->primary->elt; elt_list[count_elts].coef = coef; count_elts++; - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); return (OK); } diff --git a/print.cpp b/print.cpp index 4cd48a86..df04e616 100644 --- a/print.cpp +++ b/print.cpp @@ -316,12 +316,7 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) ptr = &(token[0]); get_elts_in_species (&ptr, mass_water_surface / gfw_water); */ - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Print totals */ diff --git a/step.cpp b/step.cpp index d9cf2715..c0eb9a4f 100644 --- a/step.cpp +++ b/step.cpp @@ -1026,12 +1026,7 @@ add_gas_phase(cxxGasPhase *gas_phase_ptr) /* * Sort elements in reaction and combine */ - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t) count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Add gas elements to totals */ diff --git a/structures.cpp b/structures.cpp index 57011da8..fb94a438 100644 --- a/structures.cpp +++ b/structures.cpp @@ -461,15 +461,17 @@ elt_list_combine(void) { int i, j; - if (count_elts < 1) - { - output_msg("elt_list_combine: How did this happen?\n"); - return (ERROR); - } - if (count_elts == 1) + //if (count_elts < 1) + //{ + // output_msg("elt_list_combine: How did this happen?\n"); + // return (ERROR); + //} + if (count_elts <= 1) { return (OK); } + qsort(elt_list.data(), (size_t)count_elts, + sizeof(struct elt_list), Phreeqc::elt_list_compare); j = 0; for (i = 1; i < count_elts; i++) { @@ -585,18 +587,12 @@ elt_list_save(void) /* * Sort elements in reaction and combine */ - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Malloc space and store element data */ - elt_list_ptr = - (struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1) * - sizeof(struct elt_list)); + elt_list_ptr = (struct elt_list*)PHRQ_malloc((size_t)(count_elts + 1) * + sizeof(struct elt_list)); if (elt_list_ptr == NULL) { malloc_error(); diff --git a/tally.cpp b/tally.cpp index ea45226f..a6ccbb08 100644 --- a/tally.cpp +++ b/tally.cpp @@ -550,8 +550,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) { add_elt_list(exchange_ptr->Get_exchange_comps()[j].Get_totals(), 1.0); } - qsort(elt_list.data(), (size_t) count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); elt_list_to_tally_table(tally_table[i].total[n_buffer]); } @@ -572,8 +570,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) { add_elt_list(surface_ptr->Get_surface_comps()[j].Get_totals(), 1.0); } - qsort(elt_list.data(), (size_t) count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); elt_list_to_tally_table(tally_table[i].total[n_buffer]); } @@ -643,8 +639,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) add_elt_list(phase_ptr->next_elt, (*gc)[l].Get_moles()); } - qsort(elt_list.data(), (size_t) count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); elt_list_to_tally_table(tally_table[i].total[n_buffer]); break; @@ -921,8 +915,6 @@ build_tally_table(void) strcpy(token, phase_ptr->formula); add_elt_list(phase_ptr->next_elt, 1.0); } - qsort(elt_list.data(), (size_t) count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); tally_table[n].formula = elt_list_save(); } @@ -973,8 +965,6 @@ build_tally_table(void) paren_count = 0; strcpy(token, phase_ptr->formula); add_elt_list(phase_ptr->next_elt, 1.0); - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); tally_table[n].formula = elt_list_save(); } @@ -1041,8 +1031,6 @@ build_tally_table(void) free_check_null(temp_name); } } - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); tally_table[n].formula = elt_list_save(); } diff --git a/tidy.cpp b/tidy.cpp index 38e90ffc..0ba1ec98 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1285,12 +1285,7 @@ tidy_inverse(void) /* * Sort elements in reaction and combine */ - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t) count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); /* * Mark master species list */ @@ -3495,8 +3490,6 @@ tidy_min_exchange(void) error_msg(error_string, CONTINUE); continue; } - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); for (jj = 0; jj < count_elts; jj++) { @@ -3675,8 +3668,6 @@ update_min_exchange(void) error_msg(error_string, CONTINUE); continue; } - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); for (jj = 0; jj < count_elts; jj++) { @@ -3900,8 +3891,6 @@ tidy_min_surface(void) free_check_null(temp_formula); } } - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); /* Makes no sense: sorbed species need not be in mineral structure... */ /* But elements that can desorb into solution must be in mineral */ @@ -4273,8 +4262,6 @@ tidy_kin_surface(void) /* save kinetics formula */ if (count_elts > 0) { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } elt_list_kinetics = elt_list_save(); @@ -4300,12 +4287,7 @@ tidy_kin_surface(void) free_check_null(temp_formula); } } - if (count_elts > 0) - { - qsort(elt_list.data(), (size_t)count_elts, - sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } + elt_list_combine(); for (int j = 0; j < count_elts; j++) { if (elt_list[j].elt == NULL) From 7d303de1b49c0f6b51f992b9b8422e24972302c0 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 13:19:51 -0600 Subject: [PATCH 24/34] vector trxn.token --- Phreeqc.cpp | 3 --- Phreeqc.h | 3 +-- global_structures.h | 2 +- mainsubs.cpp | 4 ---- parse.cpp | 7 ++----- prep.cpp | 14 ++++---------- structures.cpp | 25 +++++++------------------ tidy.cpp | 14 ++++---------- 8 files changed, 19 insertions(+), 53 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 47122dcf..bece82d1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -763,7 +763,6 @@ void Phreeqc::init(void) * Reaction work space *---------------------------------------------------------------------- */ // struct trxn; - trxn.token = 0; for (int i = 0; i < MAX_LOG_K_INDICES; i++) { trxn.logk[i] = 0; @@ -773,7 +772,6 @@ void Phreeqc::init(void) trxn.dz[i] = 0; } count_trxn = 0; - max_trxn = MAX_TRXN; mb_unknowns = NULL; count_mb_unknowns = 0; @@ -1896,7 +1894,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) trxn.dz[i] = 0; } count_trxn = 0; - max_trxn = MAX_TRXN; */ /* mb_unknowns = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 4dcc12d6..0f9555d0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1530,8 +1530,7 @@ protected: *---------------------------------------------------------------------- */ struct reaction_temp trxn; /* structure array of working space while reading equations species names are in "temp_strings" */ - int count_trxn; /* number of reactants in trxn = position of next */ - int max_trxn; + int count_trxn; /* number of reactants in trxn = position of next */ struct unknown_list *mb_unknowns; int count_mb_unknowns; diff --git a/global_structures.h b/global_structures.h index d0604682..b6e833bb 100644 --- a/global_structures.h +++ b/global_structures.h @@ -813,7 +813,7 @@ struct reaction_temp { LDBLE logk[MAX_LOG_K_INDICES]; LDBLE dz[3]; - struct rxn_token_temp *token; + std::vector token; }; struct rxn_token_temp { /* data for equations, aq. species or minerals */ diff --git a/mainsubs.cpp b/mainsubs.cpp index 10654610..d5bbe610 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -78,10 +78,6 @@ initialize(void) stag_data->exch_f = 0; stag_data->th_m = 0; stag_data->th_im = 0; - - space((void **) ((void *) &trxn.token), INIT, &max_trxn, - sizeof(struct rxn_token_temp)); - /* * Create hash tables */ diff --git a/parse.cpp b/parse.cpp index 8931f432..11cc4e26 100644 --- a/parse.cpp +++ b/parse.cpp @@ -1025,11 +1025,8 @@ get_species(char **ptr) char string[MAX_LENGTH]; int l; - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, &max_trxn, - sizeof(struct rxn_token_temp)); - } + if ((size_t) count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); /* coefficient */ if (get_coef(&(trxn.token[count_trxn].coef), ptr) == ERROR) { diff --git a/prep.cpp b/prep.cpp index b837e060..6bb87951 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2861,11 +2861,8 @@ add_potential_factor(void) /* * Make sure there is space */ - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, &max_trxn, - sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); /* * Include psi in mass action equation */ @@ -2958,11 +2955,8 @@ add_cd_music_factors(int n) /* * Make sure there is space */ - if (count_trxn + 3 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 3, &max_trxn, - sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 3 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 3); /* * Include psi in mass action equation */ diff --git a/structures.cpp b/structures.cpp index fb94a438..44f96472 100644 --- a/structures.cpp +++ b/structures.cpp @@ -291,10 +291,8 @@ clean_up(void) change_surf = (struct Change_Surf *) free_check_null(change_surf); /* miscellaneous work space */ - - //elt_list = (struct elt_list *) free_check_null(elt_list); elt_list.clear(); - trxn.token = (struct rxn_token_temp *) free_check_null(trxn.token); + trxn.token.clear(); mb_unknowns = (struct unknown_list *) free_check_null(mb_unknowns); line = (char *) free_check_null(line); line_save = (char *) free_check_null(line_save); @@ -2620,11 +2618,8 @@ trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine) */ for (size_t j = 0; j < r_ptr.Get_tokens().size(); j++) { - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); trxn.token[count_trxn].name = r_ptr.Get_tokens()[j].name; trxn.token[count_trxn].s = r_ptr.Get_tokens()[j].s; trxn.token[count_trxn].coef = coef * r_ptr.Get_tokens()[j].coef; @@ -2685,11 +2680,8 @@ trxn_add(struct reaction *r_ptr, LDBLE coef, int combine) next_token = r_ptr->token; while (next_token->s != NULL) { - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); trxn.token[count_trxn].name = next_token->s->name; trxn.token[count_trxn].s = next_token->s; trxn.token[count_trxn].coef = coef * next_token->coef; @@ -2743,11 +2735,8 @@ trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine) next_token = r_ptr->token; while (next_token->s != NULL || next_token->name != NULL) { - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); if (next_token->s != NULL) { trxn.token[count_trxn].name = next_token->s->name; diff --git a/tidy.cpp b/tidy.cpp index 0ba1ec98..ce623bfa 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -2873,11 +2873,8 @@ species_rxn_to_trxn(struct species *s_ptr) trxn.token[i].unknown = NULL; trxn.token[i].coef = s_ptr->rxn->token[i].coef; count_trxn = i + 1; - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); } return (OK); } @@ -2916,11 +2913,8 @@ phase_rxn_to_trxn(struct phase *phase_ptr, struct reaction *rxn_ptr) trxn.token[i].unknown = NULL; trxn.token[i].coef = rxn_ptr->token[i].coef; count_trxn = i + 1; - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); } return (OK); } From f0707aa0b327bc1f603decbcbd2fc0ccbabfb3a5 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 14:50:43 -0600 Subject: [PATCH 25/34] vector sum_mb1, sum_mb2 --- Phreeqc.cpp | 6 ----- Phreeqc.h | 13 ++++------- model.cpp | 10 ++++---- prep.cpp | 66 ++++++++++++++++++++++++----------------------------- 4 files changed, 39 insertions(+), 56 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index bece82d1..039903a0 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -579,15 +579,9 @@ void Phreeqc::init(void) count_sum_jacob0 = 0; max_sum_jacob0 = 0; sum_jacob0 = NULL; - count_sum_mb1 = 0; - max_sum_mb1 = 0; - sum_mb1 = NULL; count_sum_jacob1 = 0; max_sum_jacob1 = 0; sum_jacob1 = NULL; - count_sum_mb2 = 0; - max_sum_mb2 = 0; - sum_mb2 = NULL; count_sum_jacob2 = 0; max_sum_jacob2 = 0; sum_jacob2 = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 0f9555d0..a49b3319 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1326,18 +1326,15 @@ protected: int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ - int count_sum_mb1; /* number of elements in sum_mb1 */ - int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ - struct list1 *sum_mb1; /* array of pointers to sources and targets for mass - balance summations with coef = 1.0 */ + std::vector sum_mb1; /* array of pointers to sources and targets for mass + balance summations with coef = 1.0 */ int count_sum_jacob1; /* number of elements in sum_jacob1 */ int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ struct list1 *sum_jacob1; /* array of pointers to sources and targets for array equations with coef = 1.0 */ - int count_sum_mb2; /* number of elements in sum_mb2 */ - int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ - struct list2 *sum_mb2; /* array of coefficients and pointers to sources and - targets for mass balance summations with coef != 1.0 */ + + std::vector sum_mb2; /* array of coefficients and pointers to sources and + targets for mass balance summations with coef != 1.0 */ int count_sum_jacob2; /* number of elements in sum_jacob2 */ int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and diff --git a/model.cpp b/model.cpp index f31be925..fc7d1a16 100644 --- a/model.cpp +++ b/model.cpp @@ -2132,7 +2132,7 @@ mb_sums(void) /* * Add terms with coefficients of 1.0 */ - for (k = 0; k < count_sum_mb1; k++) + for (k = 0; k < (int)sum_mb1.size(); k++) { *sum_mb1[k].target += *sum_mb1[k].source; /* { k += 1; k -= 1;} */ @@ -2140,7 +2140,7 @@ mb_sums(void) /* * Add terms with coefficients != 1.0 */ - for (k = 0; k < count_sum_mb2; k++) + for (k = 0; k < (int)sum_mb2.size(); k++) { *sum_mb2[k].target += *sum_mb2[k].source * sum_mb2[k].coef; /* { k += 1; k -= 1;} */ @@ -5178,10 +5178,8 @@ free_model_allocs(void) delta.clear(); residual.clear(); s_x.clear(); - sum_mb1 = (struct list1 *) free_check_null(sum_mb1); - count_sum_mb1 = 0; - sum_mb2 = (struct list2 *) free_check_null(sum_mb2); - count_sum_mb2 = 0; + sum_mb1.clear(); + sum_mb2.clear(); sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); count_sum_jacob0 = 0; sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); diff --git a/prep.cpp b/prep.cpp index 6bb87951..d9576fbd 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1081,18 +1081,18 @@ build_mb_sums(void) /* * Make space for lists */ - if (count_sum_mb1 + count_mb_unknowns >= max_sum_mb1) - { - space((void **) ((void *) &sum_mb1), - count_sum_mb1 + count_mb_unknowns, &max_sum_mb1, - sizeof(struct list1)); - } - if (count_sum_mb2 + count_mb_unknowns >= max_sum_mb2) - { - space((void **) ((void *) &sum_mb2), - count_sum_mb2 + count_mb_unknowns, &max_sum_mb2, - sizeof(struct list2)); - } + //if (count_sum_mb1 + count_mb_unknowns >= max_sum_mb1) + //{ + // space((void **) ((void *) &sum_mb1), + // count_sum_mb1 + count_mb_unknowns, &max_sum_mb1, + // sizeof(struct list1)); + //} + //if (count_sum_mb2 + count_mb_unknowns >= max_sum_mb2) + //{ + // space((void **) ((void *) &sum_mb2), + // count_sum_mb2 + count_mb_unknowns, &max_sum_mb2, + // sizeof(struct list2)); + //} if (debug_prep == TRUE) { @@ -1137,15 +1137,17 @@ build_model(void) sum_species_map.clear(); s_x.clear(); - max_sum_mb1 = MAX_SUM_MB; - count_sum_mb1 = 0; - space((void **) ((void *) &sum_mb1), INIT, &max_sum_mb1, - sizeof(struct list1)); + //max_sum_mb1 = MAX_SUM_MB; + //count_sum_mb1 = 0; + //space((void **) ((void *) &sum_mb1), INIT, &max_sum_mb1, + // sizeof(struct list1)); + sum_mb1.clear(); - max_sum_mb2 = MAX_SUM_MB; - count_sum_mb2 = 0; - space((void **) ((void *) &sum_mb2), INIT, &max_sum_mb2, - sizeof(struct list2)); + //max_sum_mb2 = MAX_SUM_MB; + //count_sum_mb2 = 0; + //space((void **) ((void *) &sum_mb2), INIT, &max_sum_mb2, + // sizeof(struct list2 + sum_mb2.clear(); max_sum_jacob0 = MAX_SUM_JACOB0; count_sum_jacob0 = 0; @@ -2637,10 +2639,9 @@ reprep(void) /* * Free arrays built in build_model */ - //s_x = (struct species **) free_check_null(s_x); s_x.clear(); - sum_mb1 = (struct list1 *) free_check_null(sum_mb1); - sum_mb2 = (struct list2 *) free_check_null(sum_mb2); + sum_mb1.clear(); + sum_mb2.clear(); sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); @@ -4976,25 +4977,18 @@ store_mb(LDBLE * source, LDBLE * target, LDBLE coef) */ if (equal(coef, 1.0, TOL) == TRUE) { + size_t count_sum_mb1 = sum_mb1.size(); + sum_mb1.resize(count_sum_mb1 + 1); sum_mb1[count_sum_mb1].source = source; - sum_mb1[count_sum_mb1++].target = target; - if (count_sum_mb1 >= max_sum_mb1) - { - space((void **) ((void *) &sum_mb1), - count_sum_mb1 + count_trxn + 4, &max_sum_mb1, - sizeof(struct list1)); - } + sum_mb1[count_sum_mb1].target = target; } else { + size_t count_sum_mb2 = sum_mb2.size(); + sum_mb2.resize(count_sum_mb2 + 1); sum_mb2[count_sum_mb2].source = source; sum_mb2[count_sum_mb2].coef = coef; - sum_mb2[count_sum_mb2++].target = target; - if (count_sum_mb2 >= max_sum_mb2) - { - space((void **) ((void *) &sum_mb2), count_sum_mb2, - &max_sum_mb2, sizeof(struct list2)); - } + sum_mb2[count_sum_mb2].target = target; } return (OK); } From 51514eb125f407a0da49054129274e683b81aec7 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 15:50:20 -0600 Subject: [PATCH 26/34] vector delta, sum_jacobx --- Phreeqc.cpp | 13 +------- Phreeqc.h | 24 +++++---------- model.cpp | 22 +++++-------- prep.cpp | 89 ++++++++++++++--------------------------------------- 4 files changed, 39 insertions(+), 109 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 039903a0..be9c7236 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -576,18 +576,7 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Jacobian and Mass balance lists *---------------------------------------------------------------------- */ - count_sum_jacob0 = 0; - max_sum_jacob0 = 0; - sum_jacob0 = NULL; - count_sum_jacob1 = 0; - max_sum_jacob1 = 0; - sum_jacob1 = NULL; - count_sum_jacob2 = 0; - max_sum_jacob2 = 0; - sum_jacob2 = NULL; - count_sum_delta = 0; - max_sum_delta = 0; - sum_delta = NULL; + /*---------------------------------------------------------------------- * Solution *---------------------------------------------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index a49b3319..61404c90 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1321,28 +1321,18 @@ protected: /*---------------------------------------------------------------------- * Jacobian and Mass balance lists *---------------------------------------------------------------------- */ - - int count_sum_jacob0; /* number of elements in sum_jacob0 */ - int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ - struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ + std::vector sum_jacob0; /* array of pointers to targets and coefficients for array */ std::vector sum_mb1; /* array of pointers to sources and targets for mass balance summations with coef = 1.0 */ - int count_sum_jacob1; /* number of elements in sum_jacob1 */ - int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ - struct list1 *sum_jacob1; /* array of pointers to sources and targets for array - equations with coef = 1.0 */ - + std::vector sum_jacob1; /* array of pointers to sources and targets for array + equations with coef = 1.0 */ std::vector sum_mb2; /* array of coefficients and pointers to sources and targets for mass balance summations with coef != 1.0 */ - int count_sum_jacob2; /* number of elements in sum_jacob2 */ - int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ - struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and - targets, coef != 1.0 */ - int count_sum_delta; /* number of elements in sum_delta */ - int max_sum_delta; /* calculated maximum number of elements in sum_delta */ - struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for - summing deltas for mass balance equations */ + std::vector sum_jacob2; /* array of coefficients and pointers to sources and + targets, coef != 1.0 */ + std::vector sum_delta; /* array of pointers to sources, targets and coefficients for + summing deltas for mass balance equations */ /*---------------------------------------------------------------------- * Solution *---------------------------------------------------------------------- */ diff --git a/model.cpp b/model.cpp index fc7d1a16..26ab9995 100644 --- a/model.cpp +++ b/model.cpp @@ -1951,21 +1951,21 @@ jacobian_sums(void) /* * Add constant terms */ - for (k = 0; k < count_sum_jacob0; k++) + for (k = 0; k < (int)sum_jacob0.size(); k++) { *sum_jacob0[k].target += sum_jacob0[k].coef; } /* * Add terms with coefficients of 1.0 */ - for (k = 0; k < count_sum_jacob1; k++) + for (k = 0; k < (int)sum_jacob1.size(); k++) { *sum_jacob1[k].target += *sum_jacob1[k].source; } /* * Add terms with coefficients != 1.0 */ - for (k = 0; k < count_sum_jacob2; k++) + for (k = 0; k < (int)sum_jacob2.size(); k++) { *sum_jacob2[k].target += *sum_jacob2[k].source * sum_jacob2[k].coef; } @@ -2135,7 +2135,6 @@ mb_sums(void) for (k = 0; k < (int)sum_mb1.size(); k++) { *sum_mb1[k].target += *sum_mb1[k].source; -/* { k += 1; k -= 1;} */ } /* * Add terms with coefficients != 1.0 @@ -2143,7 +2142,6 @@ mb_sums(void) for (k = 0; k < (int)sum_mb2.size(); k++) { *sum_mb2[k].target += *sum_mb2[k].source * sum_mb2[k].coef; -/* { k += 1; k -= 1;} */ } return (OK); } @@ -3155,7 +3153,7 @@ reset(void) x[i]->delta = 0.0; } - for (i = 0; i < count_sum_delta; i++) + for (i = 0; i < (int)sum_delta.size(); i++) { *sum_delta[i].target += *sum_delta[i].source * sum_delta[i].coef; } @@ -5180,14 +5178,10 @@ free_model_allocs(void) s_x.clear(); sum_mb1.clear(); sum_mb2.clear(); - sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); - count_sum_jacob0 = 0; - sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); - count_sum_jacob1 = 0; - sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); - count_sum_jacob2 = 0; - sum_delta = (struct list2 *) free_check_null(sum_delta); - count_sum_delta = 0; + sum_jacob0.clear(); + sum_jacob1.clear(); + sum_jacob2.clear(); + sum_delta.clear(); return (OK); } diff --git a/prep.cpp b/prep.cpp index d9576fbd..b3280e3d 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1136,39 +1136,12 @@ build_model(void) sum_species_map_db.clear(); sum_species_map.clear(); s_x.clear(); - - //max_sum_mb1 = MAX_SUM_MB; - //count_sum_mb1 = 0; - //space((void **) ((void *) &sum_mb1), INIT, &max_sum_mb1, - // sizeof(struct list1)); sum_mb1.clear(); - - //max_sum_mb2 = MAX_SUM_MB; - //count_sum_mb2 = 0; - //space((void **) ((void *) &sum_mb2), INIT, &max_sum_mb2, - // sizeof(struct list2 sum_mb2.clear(); - - max_sum_jacob0 = MAX_SUM_JACOB0; - count_sum_jacob0 = 0; - space((void **) ((void *) &sum_jacob0), INIT, &max_sum_jacob0, - sizeof(struct list0)); - - max_sum_jacob1 = MAX_SUM_JACOB1; - count_sum_jacob1 = 0; - space((void **) ((void *) &sum_jacob1), INIT, &max_sum_jacob1, - sizeof(struct list1)); - - max_sum_jacob2 = MAX_SUM_JACOB2; - count_sum_jacob2 = 0; - space((void **) ((void *) &sum_jacob2), INIT, &max_sum_jacob2, - sizeof(struct list2)); - - - max_sum_delta = MAX_SUM_JACOB0; - count_sum_delta = 0; - space((void **) ((void *) &sum_delta), INIT, &max_sum_delta, - sizeof(struct list2)); + sum_jacob0.clear(); + sum_jacob1.clear(); + sum_jacob2.clear(); + sum_delta.clear(); max_species_list = 5 * MAX_S; count_species_list = 0; @@ -2642,10 +2615,10 @@ reprep(void) s_x.clear(); sum_mb1.clear(); sum_mb2.clear(); - sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); - sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); - sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); - sum_delta = (struct list2 *) free_check_null(sum_delta); + sum_jacob0.clear(); + sum_jacob1.clear(); + sum_jacob2.clear(); + sum_delta.clear(); /* * Build model again */ @@ -4913,34 +4886,26 @@ store_jacob(LDBLE * source, LDBLE * target, LDBLE coef) */ if (equal(coef, 1.0, TOL) == TRUE) { + size_t count_sum_jacob1 = sum_jacob1.size(); + sum_jacob1.resize(count_sum_jacob1 + 1); if (debug_prep == TRUE) { - output_msg(sformatf( "\tjacob1 %d\n", count_sum_jacob1)); + output_msg(sformatf( "\tjacob1 %d\n", (int)count_sum_jacob1)); } sum_jacob1[count_sum_jacob1].source = source; - sum_jacob1[count_sum_jacob1++].target = target; - /* Check space */ - if (count_sum_jacob1 >= max_sum_jacob1) - { - space((void **) ((void *) &sum_jacob1), count_sum_jacob1, - &max_sum_jacob1, sizeof(struct list1)); - } + sum_jacob1[count_sum_jacob1].target = target; } else { + size_t count_sum_jacob2 = sum_jacob2.size(); + sum_jacob2.resize(count_sum_jacob2 + 1); if (debug_prep == TRUE) { - output_msg(sformatf( "\tjacob2 %d\n", count_sum_jacob2)); + output_msg(sformatf("\tjacob2 %d\n", count_sum_jacob2)); } sum_jacob2[count_sum_jacob2].source = source; sum_jacob2[count_sum_jacob2].target = target; - sum_jacob2[count_sum_jacob2++].coef = coef; - /* Check space */ - if (count_sum_jacob2 >= max_sum_jacob2) - { - space((void **) ((void *) &sum_jacob2), count_sum_jacob2, - &max_sum_jacob2, sizeof(struct list2)); - } + sum_jacob2[count_sum_jacob2].coef = coef; } return (OK); } @@ -4953,15 +4918,11 @@ store_jacob0(int row, int column, LDBLE coef) /* * Stores in list a constant coef which will be added into jacobian array */ + size_t count_sum_jacob0 = sum_jacob0.size(); + sum_jacob0.resize(count_sum_jacob0 + 1); sum_jacob0[count_sum_jacob0].target = - &(my_array[row * (count_unknowns + 1) + column]); - sum_jacob0[count_sum_jacob0++].coef = coef; - /* Check space */ - if (count_sum_jacob0 >= max_sum_jacob0) - { - space((void **) ((void *) &sum_jacob0), count_sum_jacob0, - &max_sum_jacob0, sizeof(struct list0)); - } + &(my_array[(size_t)row * ((size_t)count_unknowns + 1) + (size_t)column]); + sum_jacob0[count_sum_jacob0].coef = coef; return (OK); } @@ -5004,15 +4965,11 @@ store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef) * in x[i]->delta. These may be multiplied by a factor under some * situations where the entire calculated step is not taken */ + size_t count_sum_delta = sum_delta.size(); + sum_delta.resize(count_sum_delta + 1); sum_delta[count_sum_delta].source = source; sum_delta[count_sum_delta].target = target; - sum_delta[count_sum_delta++].coef = coef; - /* Check space */ - if (count_sum_delta >= max_sum_delta) - { - space((void **) ((void *) &sum_delta), count_sum_delta, - &max_sum_delta, sizeof(struct list2)); - } + sum_delta[count_sum_delta].coef = coef; return (OK); } From 449a54f61e1d0bd93c3beb303098e9048139f22a Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 16:36:02 -0600 Subject: [PATCH 27/34] vector mb_unknowns --- Phreeqc.cpp | 8 -------- Phreeqc.h | 4 +--- mainsubs.cpp | 3 --- prep.cpp | 32 ++++++++------------------------ structures.cpp | 2 +- 5 files changed, 10 insertions(+), 39 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index be9c7236..842699c9 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -756,9 +756,6 @@ void Phreeqc::init(void) } count_trxn = 0; - mb_unknowns = NULL; - count_mb_unknowns = 0; - max_mb_unknowns = MAX_TRXN; /* ---------------------------------------------------------------------- * Print * ---------------------------------------------------------------------- */ @@ -1878,11 +1875,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } count_trxn = 0; */ - /* - mb_unknowns = NULL; - count_mb_unknowns = 0; - max_mb_unknowns = MAX_TRXN; - */ /* ---------------------------------------------------------------------- * Print * ---------------------------------------------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index 61404c90..3991c5c8 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1519,9 +1519,7 @@ protected: species names are in "temp_strings" */ int count_trxn; /* number of reactants in trxn = position of next */ - struct unknown_list *mb_unknowns; - int count_mb_unknowns; - int max_mb_unknowns; + std::vector mb_unknowns; /* ---------------------------------------------------------------------- * Print diff --git a/mainsubs.cpp b/mainsubs.cpp index d5bbe610..5190e988 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -67,9 +67,6 @@ initialize(void) space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); - space((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns, - sizeof(struct unknown_list)); - // one stag_data stag_data = (struct stag_data *) PHRQ_calloc(1, sizeof(struct stag_data)); if (stag_data == NULL) diff --git a/prep.cpp b/prep.cpp index b3280e3d..6d178178 100644 --- a/prep.cpp +++ b/prep.cpp @@ -874,7 +874,7 @@ build_jacobian_sums(int k) /* * Calculate jacobian coefficients for each mass balance equation */ - for (i = 0; i < count_mb_unknowns; i++) + for (i = 0; i < (int)mb_unknowns.size(); i++) { /* * Store d(moles) for a mass balance equation @@ -1081,24 +1081,11 @@ build_mb_sums(void) /* * Make space for lists */ - //if (count_sum_mb1 + count_mb_unknowns >= max_sum_mb1) - //{ - // space((void **) ((void *) &sum_mb1), - // count_sum_mb1 + count_mb_unknowns, &max_sum_mb1, - // sizeof(struct list1)); - //} - //if (count_sum_mb2 + count_mb_unknowns >= max_sum_mb2) - //{ - // space((void **) ((void *) &sum_mb2), - // count_sum_mb2 + count_mb_unknowns, &max_sum_mb2, - // sizeof(struct list2)); - //} - if (debug_prep == TRUE) { output_msg(sformatf( "\n\tMass balance summations.\n")); } - for (i = 0; i < count_mb_unknowns; i++) + for (i = 0; i < (int)mb_unknowns.size(); i++) { target = &(mb_unknowns[i].unknown->f); store_mb(mb_unknowns[i].source, target, mb_unknowns[i].coef); @@ -2184,16 +2171,12 @@ store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, LDBLE coef, { if (equal(coef, 0.0, TOL) == TRUE) return (OK); - if ((count_mb_unknowns + 1) >= max_mb_unknowns) - { - space((void **) ((void *) &mb_unknowns), count_mb_unknowns + 1, - &max_mb_unknowns, sizeof(struct unknown_list)); - } + size_t count_mb_unknowns = mb_unknowns.size(); + mb_unknowns.resize(count_mb_unknowns + 1); mb_unknowns[count_mb_unknowns].unknown = unknown_ptr; mb_unknowns[count_mb_unknowns].source = LDBLE_ptr; mb_unknowns[count_mb_unknowns].gamma_source = gamma_ptr; mb_unknowns[count_mb_unknowns].coef = coef; - count_mb_unknowns++; return (OK); } @@ -2216,7 +2199,7 @@ mb_for_species_aq(int n) struct master *master_ptr; struct unknown *unknown_ptr; - count_mb_unknowns = 0; + mb_unknowns.clear(); /* * e- does not appear in any mass balances */ @@ -2379,7 +2362,8 @@ mb_for_species_ex(int n) */ int i; struct master *master_ptr; - count_mb_unknowns = 0; + + mb_unknowns.clear(); /* * Master species for exchange do not appear in any mass balances */ @@ -2469,7 +2453,7 @@ mb_for_species_surf(int n) int i; struct master *master_ptr; - count_mb_unknowns = 0; + mb_unknowns.clear(); /* * Include in charge balance, if diffuse_layer_x == FALSE */ diff --git a/structures.cpp b/structures.cpp index 44f96472..feb43058 100644 --- a/structures.cpp +++ b/structures.cpp @@ -293,7 +293,7 @@ clean_up(void) /* miscellaneous work space */ elt_list.clear(); trxn.token.clear(); - mb_unknowns = (struct unknown_list *) free_check_null(mb_unknowns); + mb_unknowns.clear(); line = (char *) free_check_null(line); line_save = (char *) free_check_null(line_save); From 41b9965576337e6c4466482a655397548baed014 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 17:12:41 -0600 Subject: [PATCH 28/34] vector species_list --- Phreeqc.cpp | 3 - Phreeqc.h | 4 +- mainsubs.cpp | 4 +- model.cpp | 2 +- prep.cpp | 33 +++---- print.cpp | 10 +- structures.cpp | 245 ++++++++++++++++++++----------------------------- transport.cpp | 20 ++-- 8 files changed, 128 insertions(+), 193 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 842699c9..251d6714 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -570,9 +570,6 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Species_list *---------------------------------------------------------------------- */ - count_species_list = 0; - max_species_list = 0; - species_list = NULL; /*---------------------------------------------------------------------- * Jacobian and Mass balance lists *---------------------------------------------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index 3991c5c8..f221b18d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1314,9 +1314,7 @@ protected: /*---------------------------------------------------------------------- * Species_list *---------------------------------------------------------------------- */ - int count_species_list; - int max_species_list; - struct species_list *species_list; + std::vector species_list; /*---------------------------------------------------------------------- * Jacobian and Mass balance lists diff --git a/mainsubs.cpp b/mainsubs.cpp index 5190e988..d04ec04b 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1140,7 +1140,7 @@ xexchange_save(int n_user) count_elts = 0; paren_count = 0; charge = 0.0; - for (j = 0; j < count_species_list; j++) + for (j = 0; j < (int)species_list.size(); j++) { if (species_list[j].master_s == x[i]->master[0]->s) { @@ -1530,7 +1530,7 @@ xsurface_save(int n_user) count_elts = 0; paren_count = 0; charge = 0.0; - for (int j = 0; j < count_species_list; j++) + for (int j = 0; j < (int)species_list.size(); j++) { if (species_list[j].master_s == x[i]->master[0]->s) { diff --git a/model.cpp b/model.cpp index 26ab9995..2855ee10 100644 --- a/model.cpp +++ b/model.cpp @@ -4952,7 +4952,7 @@ sum_species(void) master[i]->total = 0.0; master[i]->total_primary = 0.0; } - for (i = 0; i < count_species_list; i++) + for (i = 0; i < (int)species_list.size(); i++) { if (species_list[i].master_s->secondary != NULL) { diff --git a/prep.cpp b/prep.cpp index 6d178178..efcd5ec1 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1129,13 +1129,7 @@ build_model(void) sum_jacob1.clear(); sum_jacob2.clear(); sum_delta.clear(); - - max_species_list = 5 * MAX_S; - count_species_list = 0; - species_list = (struct species_list *) free_check_null(species_list); - space((void **) ((void *) &species_list), INIT, &max_species_list, - sizeof(struct species_list)); - + species_list.clear(); /* * Pick species in the model, determine reaction for model, build jacobian */ @@ -1358,8 +1352,8 @@ build_model(void) /* * Sort species list, by master only */ - qsort(&species_list[0], (size_t) count_species_list, - (size_t) sizeof(struct species_list), species_list_compare_master); + qsort(&species_list[0], (int)species_list.size(), + sizeof(struct species_list), species_list_compare_master); /* * Save model description */ @@ -1640,24 +1634,16 @@ build_species_list(int n) */ int j; struct master *master_ptr; -/* - * Check space and store reaction token name and pointer to species - */ - if (count_species_list + count_elts >= max_species_list) - { - space((void **) ((void *) &species_list), - count_species_list + count_elts, &max_species_list, - sizeof(struct species_list)); - } /* * Treat species made only with H+, e-, and H2O specially */ if (is_special(s[n]) == TRUE) { + size_t count_species_list = species_list.size(); + species_list.resize(count_species_list + 1); species_list[count_species_list].master_s = s_hplus; species_list[count_species_list].s = s[n]; species_list[count_species_list].coef = 0.0; - count_species_list++; return (OK); } /* @@ -1672,12 +1658,13 @@ build_species_list(int n) if (elt_list[j].elt->master->s->type != EX) continue; master_ptr = elt_list[j].elt->master; + size_t count_species_list = species_list.size(); + species_list.resize(count_species_list + 1); species_list[count_species_list].master_s = elt_list[j].elt->master->s; species_list[count_species_list].s = s[n]; species_list[count_species_list].coef = master_ptr->coef * elt_list[j].coef; - count_species_list++; } return (OK); } @@ -1693,12 +1680,13 @@ build_species_list(int n) if (elt_list[j].elt->master->s->type != SURF) continue; master_ptr = elt_list[j].elt->master; + size_t count_species_list = species_list.size(); + species_list.resize(count_species_list + 1); species_list[count_species_list].master_s = elt_list[j].elt->master->s; species_list[count_species_list].s = s[n]; species_list[count_species_list].coef = master_ptr->coef * elt_list[j].coef; - count_species_list++; } return (OK); } @@ -1717,6 +1705,8 @@ build_species_list(int n) { master_ptr = elt_list[j].elt->master->s->primary; } + size_t count_species_list = species_list.size(); + species_list.resize(count_species_list + 1); species_list[count_species_list].master_s = master_ptr->s; species_list[count_species_list].s = s[n]; /* @@ -1724,7 +1714,6 @@ build_species_list(int n) */ species_list[count_species_list].coef = master_ptr->coef * elt_list[j].coef; - count_species_list++; } return (OK); } diff --git a/print.cpp b/print.cpp index df04e616..07b69f3a 100644 --- a/print.cpp +++ b/print.cpp @@ -455,7 +455,7 @@ print_exchange(void) s_h2o->lm = s_h2o->la; name = s_hplus->secondary->elt->name; - for (i = 0; i < count_species_list; i++) + for (i = 0; i < (int)species_list.size(); i++) { /* * Get name of master species @@ -1486,7 +1486,7 @@ print_species(void) */ s_h2o->lm = s_h2o->la; name = s_hplus->secondary->elt->name; - for (i = 0; i < count_species_list; i++) + for (i = 0; i < (int)species_list.size(); i++) { /* * Get name of master species @@ -1774,7 +1774,7 @@ print_surface(void) output_msg(sformatf("\t%-15s%12s%12s%12s%12s\n\n", "Species", "Moles", "Fraction", "Molality", "Molality")); - for (int i = 0; i < count_species_list; i++) + for (int i = 0; i < (int)species_list.size(); i++) { if (species_list[i].master_s != master_ptr->s) continue; @@ -1816,7 +1816,7 @@ print_surface(void) output_msg(sformatf("\t%-15s%12s%12s%12s%12s\n\n", "Species", "Moles", "Fraction", "Molality", "Molality")); - for (int i = 0; i < count_species_list; i++) + for (int i = 0; i < (int)species_list.size(); i++) { if (species_list[i].master_s != master_ptr->s) continue; @@ -2072,7 +2072,7 @@ print_surface_cd_music(void) output_msg(sformatf("\t%-20s%12s%12s%12s%12s\n\n", "Species", "Moles", "Fraction", "Molality", "Molality")); - for (int i = 0; i < count_species_list; i++) + for (int i = 0; i < (int)species_list.size(); i++) { if (species_list[i].master_s != master_ptr->s) continue; diff --git a/structures.cpp b/structures.cpp index feb43058..7db3e24b 100644 --- a/structures.cpp +++ b/structures.cpp @@ -21,9 +21,9 @@ int Phreeqc:: clean_up(void) /* ---------------------------------------------------------------------- */ { -/* - * Free all allocated memory, except strings - */ + /* + * Free all allocated memory, except strings + */ int i, j; #if defined MULTICHART chart_handler.End_timer(); @@ -37,169 +37,144 @@ clean_up(void) #endif #endif - description_x = (char *) free_check_null(description_x); + description_x = (char*)free_check_null(description_x); isotopes_x.clear(); moles_per_kilogram_string = - (char *) free_check_null(moles_per_kilogram_string); - pe_string = (char *) free_check_null(pe_string); -/* model */ + (char*)free_check_null(moles_per_kilogram_string); + pe_string = (char*)free_check_null(pe_string); + /* model */ last_model.exchange = - (struct master **) free_check_null(last_model.exchange); + (struct master**)free_check_null(last_model.exchange); last_model.gas_phase = - (struct phase **) free_check_null(last_model.gas_phase); + (struct phase**)free_check_null(last_model.gas_phase); last_model.pp_assemblage = - (struct phase **) free_check_null(last_model.pp_assemblage); + (struct phase**)free_check_null(last_model.pp_assemblage); last_model.ss_assemblage = - (const char **) free_check_null(last_model.ss_assemblage); + (const char**)free_check_null(last_model.ss_assemblage); last_model.add_formula = - (const char **) free_check_null(last_model.add_formula); - last_model.si = (LDBLE *) free_check_null(last_model.si); + (const char**)free_check_null(last_model.add_formula); + last_model.si = (LDBLE*)free_check_null(last_model.si); last_model.surface_comp = - (const char **) free_check_null(last_model.surface_comp); + (const char**)free_check_null(last_model.surface_comp); last_model.surface_charge = - (const char **) free_check_null(last_model.surface_charge); + (const char**)free_check_null(last_model.surface_charge); /* model */ free_model_allocs(); -/* species */ + /* species */ for (j = 0; j < (int)s.size(); j++) { s_free(s[j]); - s[j] = (struct species *) free_check_null(s[j]); + s[j] = (struct species*)free_check_null(s[j]); } + s.clear(); -/* master species */ + /* master species */ for (j = 0; j < (int)master.size(); j++) { master_free(master[j]); } + master.clear(); -/* elements */ + /* elements */ for (j = 0; j < (int)elements.size(); j++) { - elements[j] = (struct element *) free_check_null(elements[j]); + elements[j] = (struct element*)free_check_null(elements[j]); } - -/* solutions */ + elements.clear(); + /* solutions */ Rxn_solution_map.clear(); - -/* surfaces */ + /* surfaces */ Rxn_surface_map.clear(); - -/* exchange */ + /* exchange */ Rxn_exchange_map.clear(); - -/* pp assemblages */ + /* pp assemblages */ Rxn_pp_assemblage_map.clear(); - -/* s_s assemblages */ + /* s_s assemblages */ Rxn_ss_assemblage_map.clear(); - -/* irreversible reactions */ + /* irreversible reactions */ Rxn_reaction_map.clear(); - -/* temperature */ + /* temperature */ Rxn_temperature_map.clear(); - -/* pressure */ + /* pressure */ Rxn_pressure_map.clear(); - -/* unknowns */ - + /* unknowns */ for (j = 0; j < max_unknowns; j++) { unknown_free(x[j]); } - x = (struct unknown **) free_check_null(x); - -/* mixtures */ + x = (struct unknown**)free_check_null(x); + /* mixtures */ Rxn_mix_map.clear(); - -/* phases */ - + /* phases */ for (j = 0; j < (int)phases.size(); j++) { phase_free(phases[j]); - phases[j] = (struct phase *) free_check_null(phases[j]); + phases[j] = (struct phase*)free_check_null(phases[j]); } - -/* inverse */ + phases.clear(); + /* inverse */ for (j = 0; j < count_inverse; j++) { inverse_free(&(inverse[j])); } - inverse = (struct inverse *) free_check_null(inverse); - -/* gases */ + inverse = (struct inverse*)free_check_null(inverse); + /* gases */ Rxn_gas_phase_map.clear(); - -/* kinetics */ + /* kinetics */ Rxn_kinetics_map.clear(); - x0_moles = (LDBLE *) free_check_null(x0_moles); - m_temp = (LDBLE *) free_check_null(m_temp); - m_original = (LDBLE *) free_check_null(m_original); - rk_moles = (LDBLE *) free_check_null(rk_moles); - -/* rates */ + x0_moles = (LDBLE*)free_check_null(x0_moles); + m_temp = (LDBLE*)free_check_null(m_temp); + m_original = (LDBLE*)free_check_null(m_original); + rk_moles = (LDBLE*)free_check_null(rk_moles); + /* rates */ for (j = 0; j < count_rates; j++) { rate_free(&rates[j]); } - rates = (struct rate *) free_check_null(rates); - -/* logk hash table */ + rates = (struct rate*)free_check_null(rates); + /* logk hash table */ for (j = 0; j < (int)logk.size(); j++) { free_check_null(logk[j]->add_logk); - logk[j] = (struct logk *) free_check_null(logk[j]); + logk[j] = (struct logk*)free_check_null(logk[j]); } logk.clear(); - -/* save_values */ + /* save_values */ for (j = 0; j < count_save_values; j++) { save_values[j].subscripts = - (int *) free_check_null(save_values[j].subscripts); + (int*)free_check_null(save_values[j].subscripts); } - save_values = (struct save_values *) free_check_null(save_values); - -/* model */ - -/* global solution */ - + save_values = (struct save_values*)free_check_null(save_values); + /* working pe*/ pe_x.clear(); - -/* species_list */ - - species_list = (struct species_list *) free_check_null(species_list); - -/* transport data */ - - stag_data = (struct stag_data *) free_check_null(stag_data); - cell_data = (struct cell_data *) free_check_null(cell_data); - -/* punch */ - advection_punch = (int *) free_check_null(advection_punch); - advection_print = (int *) free_check_null(advection_print); - + /*species_list*/ + species_list.clear(); + /* transport data */ + stag_data = (struct stag_data*)free_check_null(stag_data); + cell_data = (struct cell_data*)free_check_null(cell_data); + /* advection */ + advection_punch = (int*)free_check_null(advection_punch); + advection_print = (int*)free_check_null(advection_print); + /* selected_output */ SelectedOutput_map.clear(); + /* user_print and user_punch */ UserPunch_map.clear(); - -/* user_print and user_punch */ rate_free(user_print); - user_print = (struct rate *) free_check_null(user_print); + user_print = (struct rate*)free_check_null(user_print); /* Free llnl aqueous model parameters */ - llnl_temp = (LDBLE *) free_check_null(llnl_temp); - llnl_adh = (LDBLE *) free_check_null(llnl_adh); - llnl_bdh = (LDBLE *) free_check_null(llnl_bdh); - llnl_bdot = (LDBLE *) free_check_null(llnl_bdot); - llnl_co2_coefs = (LDBLE *) free_check_null(llnl_co2_coefs); + llnl_temp = (LDBLE*)free_check_null(llnl_temp); + llnl_adh = (LDBLE*)free_check_null(llnl_adh); + llnl_bdh = (LDBLE*)free_check_null(llnl_bdh); + llnl_bdot = (LDBLE*)free_check_null(llnl_bdot); + llnl_co2_coefs = (LDBLE*)free_check_null(llnl_co2_coefs); /* * Copier space */ @@ -214,93 +189,76 @@ clean_up(void) copier_free(©_reaction); copier_free(©_temperature); copier_free(©_pressure); - -#if defined PHREEQ98 - rate_free(user_graph); - user_graph = (struct rate *) free_check_null(user_graph); - user_graph_headings = (char **) free_check_null(user_graph_headings); -#endif /* master_isotope */ for (i = 0; i < (int)master_isotope.size(); i++) { - master_isotope[i] = (struct master_isotope *) free_check_null(master_isotope[i]); + master_isotope[i] = (struct master_isotope*)free_check_null(master_isotope[i]); } - //master_isotope = (struct master_isotope **) free_check_null(master_isotope); + master_isotope.clear(); hdestroy_multi(master_isotope_hash_table); master_isotope_hash_table = NULL; - /* calculate_value */ - for (i = 0; i < (int) calculate_value.size(); i++) + for (i = 0; i < (int)calculate_value.size(); i++) { calculate_value_free(calculate_value[i]); calculate_value[i] = (struct calculate_value*)free_check_null(calculate_value[i]); } + calculate_value.clear(); hdestroy_multi(calculate_value_hash_table); calculate_value_hash_table = NULL; - /* isotope_ratio */ for (i = 0; i < (int)isotope_ratio.size(); i++) { isotope_ratio[i] = - (struct isotope_ratio *) free_check_null(isotope_ratio[i]); + (struct isotope_ratio*)free_check_null(isotope_ratio[i]); } - //isotope_ratio = (struct isotope_ratio **) free_check_null(isotope_ratio); + isotope_ratio.clear(); hdestroy_multi(isotope_ratio_hash_table); isotope_ratio_hash_table = NULL; - /* isotope_alpha */ for (i = 0; i < (int)isotope_alpha.size(); i++) { isotope_alpha[i] = - (struct isotope_alpha *) free_check_null(isotope_alpha[i]); + (struct isotope_alpha*)free_check_null(isotope_alpha[i]); } + isotope_alpha.clear(); hdestroy_multi(isotope_alpha_hash_table); isotope_alpha_hash_table = NULL; - + /* tally table */ free_tally_table(); - /* CVODE memory */ free_cvode(); - + /* pitzer */ pitzer_clean_up(); - + /* sit */ sit_clean_up(); - - -/* hash tables */ - + /* hash tables */ hdestroy_multi(elements_hash_table); hdestroy_multi(species_hash_table); hdestroy_multi(logk_hash_table); hdestroy_multi(phases_hash_table); - elements_hash_table = NULL; species_hash_table = NULL; logk_hash_table = NULL; phases_hash_table = NULL; - -/* strings */ + /* strings */ #ifdef HASH strings_hash_clear(); #else strings_map_clear(); #endif - -/* delete basic interpreter */ + /* delete basic interpreter */ basic_free(); + /* change_surf */ change_surf = (struct Change_Surf *) free_check_null(change_surf); - -/* miscellaneous work space */ + /* miscellaneous work space */ elt_list.clear(); trxn.token.clear(); mb_unknowns.clear(); line = (char *) free_check_null(line); line_save = (char *) free_check_null(line_save); - -/* free user database name if defined */ + /* free user database name if defined */ user_database = (char *) free_check_null(user_database); - //selected_output_file_name = - // (char *) free_check_null(selected_output_file_name); dump_file_name = (char *) free_check_null(dump_file_name); #ifdef PHREEQCI_GUI free_spread(); @@ -326,33 +284,24 @@ int Phreeqc:: reinitialize(void) /* ---------------------------------------------------------------------- */ { -/* solutions */ + /* solutions */ Rxn_solution_map.clear(); - -/* surfaces */ + /* surfaces */ Rxn_surface_map.clear(); - -/* exchange */ + /* exchange */ Rxn_exchange_map.clear(); - -/* pp assemblages */ + /* pp assemblages */ Rxn_pp_assemblage_map.clear(); - -/* s_s assemblages */ + /* s_s assemblages */ Rxn_ss_assemblage_map.clear(); - -/* gases */ + /* gases */ Rxn_gas_phase_map.clear(); - -/* kinetics */ + /* kinetics */ Rxn_kinetics_map.clear(); - -/* irreversible reactions */ + /* irreversible reactions */ Rxn_reaction_map.clear(); - // Temperature Rxn_temperature_map.clear(); - // Pressure Rxn_pressure_map.clear(); return (OK); @@ -2494,10 +2443,10 @@ species_list_sort(void) /* * Sort list using rules in species_list_compare */ - if (count_species_list > 0) + if (species_list.size() > 0) { - qsort(&species_list[0], (size_t) count_species_list, - (size_t) sizeof(struct species_list), species_list_compare); + qsort(&species_list[0], species_list.size(), + sizeof(struct species_list), species_list_compare); } return (OK); } diff --git a/transport.cpp b/transport.cpp index 696cf4a2..91b7e7db 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1812,13 +1812,13 @@ fill_spec(int l_cell_no, int ref_cell) //sol_D[l_cell_no].spec = (struct spec *) free_check_null(sol_D[l_cell_no].spec); if (sol_D[l_cell_no].spec == NULL) { - sol_D[l_cell_no].spec = (struct spec *) PHRQ_malloc((size_t)(count_species_list + size_xt) * sizeof(struct spec)); - sol_D[l_cell_no].spec_size = count_species_list + size_xt; + sol_D[l_cell_no].spec = (struct spec *) PHRQ_malloc((species_list.size() + (size_t)size_xt) * sizeof(struct spec)); + sol_D[l_cell_no].spec_size = (int)species_list.size() + size_xt; } - else if (count_species_list + size_xt > sol_D[l_cell_no].spec_size) + else if ((int)species_list.size() + size_xt > sol_D[l_cell_no].spec_size) { - sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, (size_t)(count_species_list + size_xt) * sizeof(struct spec)); - sol_D[l_cell_no].spec_size = count_species_list + size_xt; + sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, (species_list.size() + (size_t)size_xt) * sizeof(struct spec)); + sol_D[l_cell_no].spec_size = (int)species_list.size() + size_xt; } if (sol_D[l_cell_no].spec == NULL) malloc_error(); @@ -1878,11 +1878,13 @@ fill_spec(int l_cell_no, int ref_cell) /* * sort species by name... */ - if (count_species_list > 0) - qsort(&species_list[0], (size_t) count_species_list, - (size_t) sizeof(struct species_list), sort_species_name); + if (species_list.size() > 1) + { + qsort(&species_list[0], species_list.size(), + sizeof(struct species_list), sort_species_name); + } - for (i = 0; i < count_species_list; i++) + for (i = 0; i < (int)species_list.size(); i++) { /* * copy species data From e3cc46ad7bf793a40fa12119cb0e031fe1b66c90 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 17:46:22 -0600 Subject: [PATCH 29/34] vector save_values --- Phreeqc.cpp | 14 -------------- Phreeqc.h | 3 +-- mainsubs.cpp | 5 ----- structures.cpp | 35 ++++++++++++++--------------------- 4 files changed, 15 insertions(+), 42 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 251d6714..e2354ccf 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -504,12 +504,8 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Save *---------------------------------------------------------------------- */ - count_save_values = 0; - save_values = NULL; save_init(-1); // set initial save values - // auto use - // copier structures copy_solution.n_user = copy_solution.start = copy_solution.end = 0; copy_solution.count = copy_solution.max = 0; @@ -1329,16 +1325,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) /*---------------------------------------------------------------------- * Save *---------------------------------------------------------------------- */ - count_save_values = 0; - /* - save_values = NULL; - save_init(-1); // set initial save values - */ - - // auto use - - // copier structures - //-- skip copier, accept init /*---------------------------------------------------------------------- * Inverse diff --git a/Phreeqc.h b/Phreeqc.h index f221b18d..ad16617a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1234,8 +1234,7 @@ protected: /*---------------------------------------------------------------------- * Save *---------------------------------------------------------------------- */ - int count_save_values; - struct save_values *save_values; + std::vector save_values; struct save save; /*---------------------------------------------------------------------- diff --git a/mainsubs.cpp b/mainsubs.cpp index d04ec04b..b59d2fb0 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -83,11 +83,6 @@ initialize(void) hcreate_multi((unsigned) MAX_ELTS, &elements_hash_table); hcreate_multi((unsigned) MAX_S, &species_hash_table); hcreate_multi((unsigned) MAX_PHASES, &phases_hash_table); - // one save_values - save_values = - (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); - if (save_values == NULL) - malloc_error(); // one rate rates = (struct rate *) PHRQ_malloc(sizeof(struct rate)); diff --git a/structures.cpp b/structures.cpp index 7db3e24b..fdf58638 100644 --- a/structures.cpp +++ b/structures.cpp @@ -145,12 +145,12 @@ clean_up(void) } logk.clear(); /* save_values */ - for (j = 0; j < count_save_values; j++) + for (j = 0; j < (int)save_values.size(); j++) { save_values[j].subscripts = (int*)free_check_null(save_values[j].subscripts); } - save_values = (struct save_values*)free_check_null(save_values); + save_values.clear(); /* working pe*/ pe_x.clear(); /*species_list*/ @@ -267,7 +267,6 @@ clean_up(void) last_title_x.clear(); count_rates = 0; count_inverse = 0; - count_save_values = 0; llnl_count_temp = 0; llnl_count_adh = 0; @@ -2126,22 +2125,22 @@ save_values_bsearch(struct save_values *k, int *n) * values of subscripts */ void *void_ptr; - if (count_save_values == 0) + if (save_values.size() == 0) { *n = -999; return (NULL); } void_ptr = (void *) bsearch((char *) k, - (char *) save_values, - (size_t) count_save_values, + (char *) save_values.data(), + save_values.size(), (size_t) sizeof(struct save_values), save_values_compare); if (void_ptr == NULL) { *n = -999; return (NULL); } - *n = (int) ((struct save_values *) void_ptr - save_values); + *n = (int) ((struct save_values *) void_ptr - save_values.data()); return ((struct save_values *) void_ptr); } @@ -2191,10 +2190,10 @@ save_values_sort(void) /* * Sort array of save_values structures */ - if (count_save_values > 0) + if (save_values.size() > 0) { - qsort(save_values, (size_t) count_save_values, - (size_t) sizeof(struct save_values), save_values_compare); + qsort(save_values.data(), save_values.size(), + sizeof(struct save_values), save_values_compare); } return (OK); } @@ -2217,13 +2216,8 @@ save_values_store(struct save_values *s_v) } else { - save_values = - (struct save_values *) PHRQ_realloc(save_values, - (size_t) (count_save_values + - 1) * - sizeof(struct save_values)); - if (save_values == NULL) - malloc_error(); + size_t count_save_values = save_values.size(); + save_values.resize(count_save_values + 1); save_values[count_save_values].value = s_v->value; save_values[count_save_values].count_subscripts = s_v->count_subscripts; @@ -2237,14 +2231,13 @@ save_values_store(struct save_values *s_v) save_values[count_save_values].subscripts = (int *) memcpy(save_values[count_save_values].subscripts, s_v->subscripts, (size_t) i * sizeof(int)); - count_save_values++; save_values_sort(); } - if (count_save_values > 0) + if (save_values.size() > 0) { - qsort(save_values, (size_t) count_save_values, - (size_t) sizeof(struct save_values), save_values_compare); + qsort(save_values.data(), save_values.size(), + sizeof(struct save_values), save_values_compare); } return (OK); } From 6c0edef05154ef6d881550260312cb595471852c Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 18:08:29 -0600 Subject: [PATCH 30/34] vector rates --- Phreeqc.cpp | 25 +++++++++---------------- Phreeqc.h | 3 +-- mainsubs.cpp | 5 ----- read.cpp | 10 ++-------- structures.cpp | 21 ++++++++++----------- 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e2354ccf..130e6b3a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -796,8 +796,6 @@ void Phreeqc::init(void) /* ---------------------------------------------------------------------- * RATES * ---------------------------------------------------------------------- */ - rates = NULL; - count_rates = 0; rate_m = 0; rate_m0 = 0; rate_time = 0; @@ -1922,21 +1920,16 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) // auto rate_p count_rate_p = 0; */ - rates = (struct rate *) free_check_null(rates); - count_rates = pSrc->count_rates; - if (count_rates > 0) + for (int i = 0; i < (int)pSrc->rates.size(); i++) { - rates = (struct rate *) PHRQ_malloc((size_t) count_rates * sizeof(struct rate)); - if (rates == NULL) malloc_error(); - for (int i = 0; i < count_rates; i++) - { - rates[i].name = string_hsave(pSrc->rates[i].name); - rates[i].commands = string_duplicate(pSrc->rates[i].commands); - rates[i].new_def = TRUE; - rates[i].linebase = NULL; - rates[i].varbase = NULL; - rates[i].loopbase = NULL; - } + size_t count_rates = rates.size(); + rates.resize(count_rates + 1); + rates[i].name = string_hsave(pSrc->rates[i].name); + rates[i].commands = string_duplicate(pSrc->rates[i].commands); + rates[i].new_def = TRUE; + rates[i].linebase = NULL; + rates[i].varbase = NULL; + rates[i].loopbase = NULL; } /* ---------------------------------------------------------------------- * USER PRINT COMMANDS diff --git a/Phreeqc.h b/Phreeqc.h index ad16617a..4b7347e6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1531,8 +1531,7 @@ protected: /* ---------------------------------------------------------------------- * RATES * ---------------------------------------------------------------------- */ - struct rate *rates; - int count_rates; + std::vector rates; LDBLE rate_m, rate_m0, rate_time, rate_kin_time, rate_sim_time_start, rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; std::vector rate_p; diff --git a/mainsubs.cpp b/mainsubs.cpp index b59d2fb0..52240695 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -84,11 +84,6 @@ initialize(void) hcreate_multi((unsigned) MAX_S, &species_hash_table); hcreate_multi((unsigned) MAX_PHASES, &phases_hash_table); - // one rate - rates = (struct rate *) PHRQ_malloc(sizeof(struct rate)); - if (rates == NULL) - malloc_error(); - // user_print user_print = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); if (user_print == NULL) diff --git a/read.cpp b/read.cpp index 86180790..276fc1ad 100644 --- a/read.cpp +++ b/read.cpp @@ -8567,15 +8567,9 @@ read_rates(void) } if (rate_ptr == NULL) { - rates = - (struct rate *) PHRQ_realloc(rates, - (size_t) (count_rates + - 1) * - sizeof(struct rate)); - if (rates == NULL) - malloc_error(); + size_t count_rates = rates.size(); + rates.resize(count_rates + 1); rate_ptr = &rates[count_rates]; - count_rates++; } else { diff --git a/structures.cpp b/structures.cpp index fdf58638..ce2e5a31 100644 --- a/structures.cpp +++ b/structures.cpp @@ -132,11 +132,11 @@ clean_up(void) m_original = (LDBLE*)free_check_null(m_original); rk_moles = (LDBLE*)free_check_null(rk_moles); /* rates */ - for (j = 0; j < count_rates; j++) + for (j = 0; j < (int)rates.size(); j++) { rate_free(&rates[j]); } - rates = (struct rate*)free_check_null(rates); + rates.clear(); /* logk hash table */ for (j = 0; j < (int)logk.size(); j++) { @@ -265,7 +265,6 @@ clean_up(void) #endif title_x = (char *) free_check_null(title_x); last_title_x.clear(); - count_rates = 0; count_inverse = 0; llnl_count_temp = 0; @@ -1454,16 +1453,16 @@ rate_bsearch(char *ptr, int *j) */ void *void_ptr; - if (count_rates == 0) + if (rates.size() == 0) { *j = -1; return (NULL); } void_ptr = (void *) bsearch((char *) ptr, - (char *) rates, - (size_t) count_rates, - (size_t) sizeof(struct rate *), rate_compare_string); + (char *) rates.data(), + rates.size(), + sizeof(struct rate *), rate_compare_string); if (void_ptr == NULL) { @@ -1471,7 +1470,7 @@ rate_bsearch(char *ptr, int *j) return (NULL); } - *j = (int) ((struct rate *) void_ptr - rates); + *j = (int) ((struct rate *) void_ptr - rates.data()); return ((struct rate *) void_ptr); } @@ -1580,7 +1579,7 @@ rate_search(const char *name_in, int *n) int i; *n = -1; - for (i = 0; i < count_rates; i++) + for (i = 0; i < (int)rates.size(); i++) { if (strcmp_nocase(rates[i].name, name) == 0) { @@ -1604,9 +1603,9 @@ rate_sort(void) /* * Sort array of rate structures */ - if (count_rates > 0) + if (rates.size() > 1) { - qsort(rates, (size_t) count_rates, (size_t) sizeof(struct rate), + qsort(rates.data(), rates.size(), sizeof(struct rate), rate_compare); } return (OK); From d4cc14ef43986bf7295eda8c695a5f37a50b9627 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 19:03:54 -0600 Subject: [PATCH 31/34] vector x --- Phreeqc.cpp | 1 - Phreeqc.h | 3 +-- model.cpp | 10 ++++------ prep.cpp | 4 +--- print.cpp | 2 +- structures.cpp | 4 ++-- 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 130e6b3a..204240d3 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -715,7 +715,6 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Unknowns *---------------------------------------------------------------------- */ - x = NULL; count_unknowns = 0; max_unknowns = 0; ah2o_unknown = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 4b7347e6..57cbb3fc 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1486,8 +1486,7 @@ protected: /*---------------------------------------------------------------------- * Unknowns *---------------------------------------------------------------------- */ - - struct unknown **x; + std::vector x; int count_unknowns; int max_unknowns; diff --git a/model.cpp b/model.cpp index 2855ee10..8e19c617 100644 --- a/model.cpp +++ b/model.cpp @@ -5163,14 +5163,12 @@ free_model_allocs(void) * free space allocated in model */ int i; - if (x != NULL) + for (i = 0; i < (int)x.size(); i++) { - for (i = 0; i < max_unknowns; i++) - { - unknown_free(x[i]); - } + unknown_free(x[i]); } - x = (struct unknown **) free_check_null(x); + x.clear(); + count_unknowns = 0; max_unknowns = 0; my_array.clear(); delta.clear(); diff --git a/prep.cpp b/prep.cpp index efcd5ec1..b69fb185 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4752,9 +4752,7 @@ setup_unknowns(void) /* * Allocate space for pointer array and structures */ - - space((void **) ((void *) &x), INIT, &max_unknowns, - sizeof(struct unknown *)); + x.resize((size_t)max_unknowns); for (i = 0; i < max_unknowns; i++) { x[i] = (struct unknown *) unknown_alloc(); diff --git a/print.cpp b/print.cpp index 07b69f3a..84bcbc47 100644 --- a/print.cpp +++ b/print.cpp @@ -2829,7 +2829,7 @@ punch_pp_assemblage(void) { for (int j = 0; j < count_unknowns; j++) { - if (x == NULL || x[j]->type != PP) + if (x.size() == 0 || x[j]->type != PP) continue; //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp * ) x[j]->pp_assemblage_comp_ptr; diff --git a/structures.cpp b/structures.cpp index ce2e5a31..20e3ef82 100644 --- a/structures.cpp +++ b/structures.cpp @@ -103,11 +103,11 @@ clean_up(void) /* pressure */ Rxn_pressure_map.clear(); /* unknowns */ - for (j = 0; j < max_unknowns; j++) + for (j = 0; j < (int)x.size(); j++) { unknown_free(x[j]); } - x = (struct unknown**)free_check_null(x); + x.clear(); /* mixtures */ Rxn_mix_map.clear(); /* phases */ From e43550cdbc614d89e567df96f5d0512c88be78a3 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Tue, 16 Mar 2021 22:51:02 -0600 Subject: [PATCH 32/34] vector inverse --- Phreeqc.cpp | 1 - Phreeqc.h | 3 +-- mainsubs.cpp | 3 --- structures.cpp | 62 +++++++++++++------------------------------------- 4 files changed, 17 insertions(+), 52 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 204240d3..440f3284 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -532,7 +532,6 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Inverse *---------------------------------------------------------------------- */ - inverse = NULL; count_inverse = 0; /*---------------------------------------------------------------------- * Mix diff --git a/Phreeqc.h b/Phreeqc.h index 57cbb3fc..1c76a0ff 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1260,8 +1260,7 @@ protected: /*---------------------------------------------------------------------- * Inverse *---------------------------------------------------------------------- */ - - struct inverse *inverse; + std::vector inverse; int count_inverse; /*---------------------------------------------------------------------- diff --git a/mainsubs.cpp b/mainsubs.cpp index 52240695..4096c11a 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -59,9 +59,6 @@ initialize(void) cell_data[i].punch = FALSE; cell_data[i].print = FALSE; } - - inverse = (struct inverse *) PHRQ_malloc((size_t) sizeof(struct inverse)); - if (inverse == NULL) malloc_error(); count_inverse = 0; space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); diff --git a/structures.cpp b/structures.cpp index 20e3ef82..ce4e5169 100644 --- a/structures.cpp +++ b/structures.cpp @@ -122,7 +122,7 @@ clean_up(void) { inverse_free(&(inverse[j])); } - inverse = (struct inverse*)free_check_null(inverse); + inverse.clear(); /* gases */ Rxn_gas_phase_map.clear(); /* kinetics */ @@ -600,18 +600,8 @@ inverse_alloc(void) */ { struct inverse *inverse_ptr = NULL; - - count_inverse++; - inverse = - (struct inverse *) PHRQ_realloc(inverse, - (size_t) count_inverse * - sizeof(struct inverse)); - if (inverse == NULL) - { - malloc_error(); - return inverse_ptr; - } - inverse_ptr = &(inverse[count_inverse - 1]); + inverse.resize((size_t)count_inverse + 1); + inverse_ptr = &(inverse[count_inverse++]); /* * Initialize variables */ @@ -627,36 +617,30 @@ inverse_alloc(void) * allocate space for pointers in structure to NULL */ - inverse_ptr->uncertainties = - (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + inverse_ptr->uncertainties = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); if (inverse_ptr->uncertainties == NULL) { malloc_error(); return inverse_ptr; } - - inverse_ptr->ph_uncertainties = - (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + inverse_ptr->ph_uncertainties = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); if (inverse_ptr->ph_uncertainties == NULL) { malloc_error(); return inverse_ptr; } - inverse_ptr->force_solns = (int *) PHRQ_malloc((size_t) sizeof(int)); if (inverse_ptr->force_solns == NULL) { malloc_error(); return inverse_ptr; } - inverse_ptr->dalk_dph = NULL; inverse_ptr->dalk_dc = NULL; inverse_ptr->solns = NULL; - inverse_ptr->elts = - (struct inv_elts *) PHRQ_malloc((size_t) sizeof(struct inv_elts)); + inverse_ptr->elts = (struct inv_elts *) PHRQ_malloc((size_t) sizeof(struct inv_elts)); if (inverse_ptr->elts == NULL) { malloc_error(); @@ -665,9 +649,8 @@ inverse_alloc(void) inverse_ptr->elts[0].name = NULL; inverse_ptr->elts[0].uncertainties = NULL; - inverse_ptr->isotopes = - (struct inv_isotope *) PHRQ_malloc((size_t) - sizeof(struct inv_isotope)); + inverse_ptr->isotopes = (struct inv_isotope *) PHRQ_malloc((size_t) + sizeof(struct inv_isotope)); if (inverse_ptr->isotopes == NULL) { malloc_error(); @@ -677,9 +660,8 @@ inverse_alloc(void) inverse_ptr->isotopes[0].isotope_number = 0; inverse_ptr->isotopes[0].elt_name = NULL; - inverse_ptr->i_u = - (struct inv_isotope *) PHRQ_malloc((size_t) - sizeof(struct inv_isotope)); + inverse_ptr->i_u = (struct inv_isotope *) PHRQ_malloc((size_t) + sizeof(struct inv_isotope)); if (inverse_ptr->i_u == NULL) { malloc_error(); @@ -689,14 +671,12 @@ inverse_alloc(void) inverse_ptr->i_u[0].isotope_number = 0; inverse_ptr->i_u[0].elt_name = NULL; - inverse_ptr->phases = - (struct inv_phases *) PHRQ_malloc((size_t) sizeof(struct inv_phases)); + inverse_ptr->phases = (struct inv_phases *) PHRQ_malloc((size_t) sizeof(struct inv_phases)); if (inverse_ptr->phases == NULL) { malloc_error(); return inverse_ptr; } - return (inverse_ptr); } @@ -731,14 +711,8 @@ inverse_delete(int i) * Input: i, number of inverse struct to delete * Return: OK */ - int j; - inverse_free(&(inverse[i])); - for (j = i; j < (count_inverse - 1); j++) - { - memcpy((void *) &(inverse[j]), (void *) &(inverse[j + 1]), - (size_t) sizeof(struct inverse)); - } + inverse.erase(inverse.begin() + (size_t)i); count_inverse--; return (OK); } @@ -876,8 +850,8 @@ inverse_sort(void) */ if (count_inverse > 0) { - qsort(inverse, (size_t) count_inverse, - (size_t) sizeof(struct inverse), inverse_compare); + qsort(inverse.data(), (size_t) count_inverse, + sizeof(struct inverse), inverse_compare); } return (OK); } @@ -3076,13 +3050,9 @@ unknown_delete(int i) /* * Delete unknow from list x */ - int j; - unknown_free(x[i]); - for (j = i; j < (count_unknowns); j++) - { - x[j] = x[j + 1]; - } + x.erase(x.begin() + (size_t)i); + count_unknowns--; return (OK); } From 71aa5b9fcfd80a73ac36f70bbb1f152bc05a77bb Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Wed, 17 Mar 2021 14:42:06 -0600 Subject: [PATCH 33/34] bug count_sys not incremented --- basicsubs.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index dc10e530..dd971337 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2931,7 +2931,6 @@ system_total_elements(void) sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("dis"); count_sys++; - sys.resize(count_sys + 1); for (i = 0; i < (int)master.size(); i++) { master_ptr = master[i]; @@ -2985,7 +2984,9 @@ system_total_elements(void) { t = master_ptr->total; } - strcpy(name, master[i]->elt->name); + strcpy(name, master[i]->elt->name); + count_sys = sys.size(); + sys.resize(count_sys + 1); sys[count_sys].name = string_duplicate(name); sys[count_sys].moles = t; sys_tot += sys[count_sys].moles; From 0feb20dead731b8dedf3e86d5ef664bc24733127 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Wed, 17 Mar 2021 15:08:50 -0600 Subject: [PATCH 34/34] after merging origin/master, one fix needed --- mainsubs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainsubs.cpp b/mainsubs.cpp index aee4aafb..fe5ef63d 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1475,7 +1475,7 @@ xsolution_save(int n_user) } // saves molalities temp_solution.Get_log_molalities_map().clear(); - for (int i = 0; i < this->count_s_x; i++) + for (int i = 0; i < (int)this->s_x.size(); i++) { if (s_x[i]->type <= H2O) {