From 6ca3a6d3b24357c50cbc964bc1e7aa2bc72b70bd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 21 Oct 2009 19:40:43 +0000 Subject: [PATCH] Added the suite of modify keywords: SOLUTION_MODIFY EQUILIBRIUM_PHASES_MODIFY EXCHANGE_MODIFY SURFACE_MODIFY SOLID_SOLUTIONS_MODIFY GAS_PHASE_MODIFY KINETICS_MODIFY May now revisit dump to add a delete capability. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3714 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 17 +- Exchange.h | 2 +- GasPhase.cxx | 39 +-- GasPhase.h | 2 +- PPassemblage.cxx | 2 +- PPassemblage.h | 2 +- ReadClass.cxx | 636 +++++++++++++++++++++++++++++++++++++++++++---- SSassemblage.cxx | 2 +- SSassemblage.h | 2 +- Solution.cxx | 127 +++++----- Solution.h | 2 +- Surface.cxx | 139 ++++++----- Surface.h | 2 +- Utils.cxx | 10 + Utils.h | 2 + cxxKinetics.cxx | 75 +++--- cxxKinetics.h | 2 +- dumper.cpp | 72 +++--- dumper.h | 28 +-- 19 files changed, 863 insertions(+), 300 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 0ada85d1..c16043a7 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -289,7 +289,7 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxExchange::read_raw(CParser & parser) +cxxExchange::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -363,13 +363,16 @@ cxxExchange::read_raw(CParser & parser) break; } // members that must be defined - if (pitzer_exchange_gammas_defined == false) + if (check) { - parser.incr_input_error(); - parser. - error_msg - ("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", - CParser::OT_CONTINUE); + if (pitzer_exchange_gammas_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", + CParser::OT_CONTINUE); + } } } void diff --git a/Exchange.h b/Exchange.h index 9a234578..af23f7af 100644 --- a/Exchange.h +++ b/Exchange.h @@ -28,7 +28,7 @@ class cxxExchange:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/GasPhase.cxx b/GasPhase.cxx index 2036bc67..1cc1e184 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -253,7 +253,7 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxGasPhase::read_raw(CParser & parser) +cxxGasPhase::read_raw(CParser & parser, bool check) { int i; @@ -369,24 +369,27 @@ cxxGasPhase::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (type_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Type not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); - } - if (total_p_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); - } - if (volume_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); + // members that must be defined + if (type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Type not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } + if (total_p_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } + if (volume_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } } } diff --git a/GasPhase.h b/GasPhase.h index 4b6a86ce..8b40b860 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -38,7 +38,7 @@ class cxxGasPhase:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 776b36ab..02ef3ead 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -163,7 +163,7 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxPPassemblage::read_raw(CParser & parser) +cxxPPassemblage::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) diff --git a/PPassemblage.h b/PPassemblage.h index b47d5654..096edadb 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -30,7 +30,7 @@ class cxxPPassemblage:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); const cxxNameDouble & get_totals() const { diff --git a/ReadClass.cxx b/ReadClass.cxx index cdc760fd..541b3648 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1032,55 +1032,589 @@ read_dump(void) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } -#ifdef SKIP +/* /* ---------------------------------------------------------------------- */ int -streamify_to_next_keyword(std::istringstream & lines) +read_solution_modify(void) /* ---------------------------------------------------------------------- */ { /* - * Reads to next keyword or eof + * Reads solution_modify data block + * + * 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 * - * Returns: - * KEYWORD - * OPTION - * EOF */ - const char *opt_list[] = { - "none" - }; - int count_opt_list = 0; - int opt; - char *next_char; + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); - // Handle echo - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); - std::string accumulate(line); - accumulate.append("\n"); - for (;;) + if (pr.echo_input == FALSE) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_EOF) - { /* end of file */ - break; - } - else if (opt == OPTION_KEYWORD) - { /* keyword */ - break; - } - else - { - accumulate.append(line); - accumulate.append("\n"); - } + parser.set_echo_file(CParser::EO_NONE); } - pr.echo_input = save_echo_input; - lines.str(accumulate); - return (opt); + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find solution number + char token[MAX_LENGTH]; + char *next; + int l, n_user, n; + next = line; + copy_token(token, &next, &l); + if (copy_token(token, &next, &l) != DIGIT) + { + input_error++; + sprintf(error_string, "Expected solution number following SOLUTION_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (solution_bsearch(n_user, &n, FALSE) == NULL) + { + input_error++; + sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + cxxSolution sol(solution[n]); + sol.read_raw(parser, false); + + struct solution *soln_ptr = sol.cxxSolution2solution(); + + /* + * This is not quite right, may not produce sort order, forced sort + */ + + solution_free(solution[n]); + solution[n] = soln_ptr; + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_equilibrium_phases_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads equilibrium_phases_modify data block + * + * 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 return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find equilibrium_phases number + char token[MAX_LENGTH]; + char *next; + int l, n_user, n; + next = line; + copy_token(token, &next, &l); + if (copy_token(token, &next, &l) != DIGIT) + { + input_error++; + sprintf(error_string, "Expected equilibrium_phases number following EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (pp_assemblage_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxPPassemblage entity(&(pp_assemblage[n])); + entity.read_raw(parser, false); + + // save entity + struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(); + pp_assemblage_free(&(pp_assemblage[n])); + pp_assemblage_copy(entity_ptr, &(pp_assemblage[n]), entity_ptr->n_user); + pp_assemblage_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_exchange_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads EXCHANGE_MODIFY data block + * + * 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 return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find exchange number + char token[MAX_LENGTH]; + char *next; + int l, n_user, n; + next = line; + copy_token(token, &next, &l); + if (copy_token(token, &next, &l) != DIGIT) + { + input_error++; + sprintf(error_string, "Expected exchange number following EXCHANGE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (exchange_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Exchange %d not found for EXCHANGE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxExchange entity(&(exchange[n])); + entity.read_raw(parser, false); + + // save entity + struct exchange *entity_ptr = entity.cxxExchange2exchange(); + exchange_free(&(exchange[n])); + exchange_copy(entity_ptr, &(exchange[n]), entity_ptr->n_user); + exchange_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_surface_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads SURFACE_MODIFY data block + * + * 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 return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find surface number + char token[MAX_LENGTH]; + char *next; + int l, n_user, n; + next = line; + copy_token(token, &next, &l); + if (copy_token(token, &next, &l) != DIGIT) + { + input_error++; + sprintf(error_string, "Expected surface number following SURFACE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (surface_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Surface %d not found for SURFACE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxSurface entity(&(surface[n])); + entity.read_raw(parser, false); + + // save entity + struct surface *entity_ptr = entity.cxxSurface2surface(); + surface_free(&(surface[n])); + surface_copy(entity_ptr, &(surface[n]), entity_ptr->n_user); + surface_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_solid_solutions_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads SOLID_SOLUTIONS_MODIFY data block + * + * 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 return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find solid_solutions number + char token[MAX_LENGTH]; + char *next; + int l, n_user, n; + next = line; + copy_token(token, &next, &l); + if (copy_token(token, &next, &l) != DIGIT) + { + input_error++; + sprintf(error_string, "Expected solid_solutions number following SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (s_s_assemblage_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxSSassemblage entity(&(s_s_assemblage[n])); + entity.read_raw(parser, false); + + // save entity + struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(); + s_s_assemblage_free(&(s_s_assemblage[n])); + s_s_assemblage_copy(entity_ptr, &(s_s_assemblage[n]), entity_ptr->n_user); + s_s_assemblage_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_gas_phase_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads GAS_PHASE_MODIFY data block + * + * 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 return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find gas_phase number + char token[MAX_LENGTH]; + char *next; + int l, n_user, n; + next = line; + copy_token(token, &next, &l); + if (copy_token(token, &next, &l) != DIGIT) + { + input_error++; + sprintf(error_string, "Expected gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (gas_phase_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Gas_phase %d not found for GAS_PHASE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxGasPhase entity(&(gas_phase[n])); + entity.read_raw(parser, false); + // save entity + struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(); + gas_phase_free(&(gas_phase[n])); + gas_phase_copy(entity_ptr, &(gas_phase[n]), entity_ptr->n_user); + gas_phase_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_kinetics_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads KINETICS_MODIFY data block + * + * 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 return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find kinetics number + char token[MAX_LENGTH]; + char *next; + int l, n_user, n; + next = line; + copy_token(token, &next, &l); + if (copy_token(token, &next, &l) != DIGIT) + { + input_error++; + sprintf(error_string, "Expected kinetics number following KINETICS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (kinetics_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Kinetics %d not found for KINETICS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxKinetics entity(&(kinetics[n])); + entity.read_raw(parser, false); + + // save entity + struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(); + kinetics_free(&(kinetics[n])); + kinetics_copy(entity_ptr, &(kinetics[n]), entity_ptr->n_user); + kinetics_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } -#endif /* ---------------------------------------------------------------------- */ int streamify_to_next_keyword(std::istringstream & lines) @@ -1135,13 +1669,13 @@ dump_entities(void) { int i, n, return_value; return_value = OK; - if (!dump_info.get_dump_solution() && - !dump_info.get_dump_pp_assemblage() && - !dump_info.get_dump_exchange() && - !dump_info.get_dump_surface() && - !dump_info.get_dump_s_s_assemblage() && - !dump_info.get_dump_gas_phase() && - !dump_info.get_dump_kinetics()) + if (!dump_info.get_bool_solution() && + !dump_info.get_bool_pp_assemblage() && + !dump_info.get_bool_exchange() && + !dump_info.get_bool_surface() && + !dump_info.get_bool_s_s_assemblage() && + !dump_info.get_bool_gas_phase() && + !dump_info.get_bool_kinetics()) { return(OK); } @@ -1158,7 +1692,7 @@ dump_entities(void) dump_stream.open(dump_info.get_file_name().c_str()); } // solutions - if (dump_info.get_dump_solution()) + if (dump_info.get_bool_solution()) { if (dump_info.get_solution().size() == 0) { @@ -1183,7 +1717,7 @@ dump_entities(void) } // pp_assemblages - if (dump_info.get_dump_pp_assemblage()) + if (dump_info.get_bool_pp_assemblage()) { if (dump_info.get_pp_assemblage().size() == 0) { @@ -1209,7 +1743,7 @@ dump_entities(void) } // exchanges - if (dump_info.get_dump_exchange()) + if (dump_info.get_bool_exchange()) { if (dump_info.get_exchange().size() == 0) { @@ -1235,7 +1769,7 @@ dump_entities(void) } // surfaces - if (dump_info.get_dump_surface()) + if (dump_info.get_bool_surface()) { if (dump_info.get_surface().size() == 0) { @@ -1261,7 +1795,7 @@ dump_entities(void) } // s_s_assemblages - if (dump_info.get_dump_s_s_assemblage()) + if (dump_info.get_bool_s_s_assemblage()) { if (dump_info.get_s_s_assemblage().size() == 0) { @@ -1287,7 +1821,7 @@ dump_entities(void) } // gas_phases - if (dump_info.get_dump_gas_phase()) + if (dump_info.get_bool_gas_phase()) { if (dump_info.get_gas_phase().size() == 0) { @@ -1313,7 +1847,7 @@ dump_entities(void) } // kineticss - if (dump_info.get_dump_kinetics()) + if (dump_info.get_bool_kinetics()) { if (dump_info.get_kinetics().size() == 0) { diff --git a/SSassemblage.cxx b/SSassemblage.cxx index a5dd5251..724426f3 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -151,7 +151,7 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSSassemblage::read_raw(CParser & parser) +cxxSSassemblage::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) diff --git a/SSassemblage.h b/SSassemblage.h index c3255ec3..d3784752 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -32,7 +32,7 @@ class cxxSSassemblage:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/Solution.cxx b/Solution.cxx index 68774f7a..1a5fe63f 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -543,7 +543,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSolution::read_raw(CParser & parser) +cxxSolution::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -806,68 +806,71 @@ cxxSolution::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // all members must be defined - if (tc_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Temp not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (ph_defined == false) - { - parser.incr_input_error(); - parser.error_msg("pH not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (pe_defined == false) - { - parser.incr_input_error(); - parser.error_msg("pe not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (mu_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (ah2o_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Activity of water not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (total_h_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (total_o_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (cb_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (mass_water_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Temp not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (total_alkalinity_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Total alkalinity not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + // all members must be defined + if (tc_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (ph_defined == false) + { + parser.incr_input_error(); + parser.error_msg("pH not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (pe_defined == false) + { + parser.incr_input_error(); + parser.error_msg("pe not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (mu_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (ah2o_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Activity of water not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_h_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_o_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (cb_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (mass_water_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_alkalinity_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Total alkalinity not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } } return; } diff --git a/Solution.h b/Solution.h index 8804d8d5..2f45095b 100644 --- a/Solution.h +++ b/Solution.h @@ -156,7 +156,7 @@ class cxxSolution:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); void multiply(double extensive); #ifdef ORCHESTRA void ORCH_write(std::ostream & headings, std::ostream & input_data) const; diff --git a/Surface.cxx b/Surface.cxx index b4eb8150..4023d439 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -359,7 +359,7 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSurface::read_raw(CParser & parser) +cxxSurface::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; int i = 0; @@ -613,77 +613,80 @@ cxxSurface::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - /* - if (diffuse_layer_defined == false) { - parser.incr_input_error(); - parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (edl_defined == false) { - parser.incr_input_error(); - parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - */ - if (only_counter_ions_defined == false) + if (check) { + // members that must be defined + /* + if (diffuse_layer_defined == false) { parser.incr_input_error(); - parser. - error_msg("Only_counter_ions not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - /* - if (donnan_defined == false) { - parser.incr_input_error(); - parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - */ - if (thickness_defined == false) - { + parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (edl_defined == false) { parser.incr_input_error(); - parser.error_msg("Thickness not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (type_defined == false) - { + parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + */ + if (only_counter_ions_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Only_counter_ions not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + /* + if (donnan_defined == false) { parser.incr_input_error(); - parser.error_msg("Surface type not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (dl_type_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Dl_type not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (sites_units_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Sites_units not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (debye_lengths_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (DDL_viscosity_defined == false) - { - parser.incr_input_error(); - parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (DDL_limit_defined == false) - { - parser.incr_input_error(); - parser.error_msg("DDL_limit not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (transport_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Transport not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + */ + if (thickness_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Thickness not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Surface type not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (dl_type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Dl_type not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (sites_units_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Sites_units not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (debye_lengths_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (DDL_viscosity_defined == false) + { + parser.incr_input_error(); + parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (DDL_limit_defined == false) + { + parser.incr_input_error(); + parser.error_msg("DDL_limit not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (transport_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Transport not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } } } diff --git a/Surface.h b/Surface.h index b9d94fba..9ad68f5a 100644 --- a/Surface.h +++ b/Surface.h @@ -37,7 +37,7 @@ class cxxSurface:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/Utils.cxx b/Utils.cxx index 1a3f6ff7..f11f3416 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -92,3 +92,13 @@ Utilities::error_msg(const std::string & err_str, const int stop) output_message(OUTPUT_ERROR, err_str, stop, "", args); } #endif + +//+NAN double: 7ff8000000000000 +//-NAN double: fff8000000000000 +double Utilities::get_nan(void) +{ + unsigned long long raw = 0x7ff0000000000000; + double d = *( double* )&raw; + return(d); + +} diff --git a/Utils.h b/Utils.h index 2bed81de..4696d4e2 100644 --- a/Utils.h +++ b/Utils.h @@ -31,6 +31,8 @@ namespace Utilities void squeeze_white(std::string & s_l); + double get_nan(void); + //void error_msg(const std::string&, const int stopflag); // operations on maps of entities (Solution, Exchange, ...) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 49392e43..3fb83d62 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -259,7 +259,7 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxKinetics::read_raw(CParser & parser) +cxxKinetics::read_raw(CParser & parser, bool check) { double d; @@ -445,42 +445,45 @@ cxxKinetics::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (step_divide_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Step_divide not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (rk_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Rk not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (bad_step_max_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (use_cvode_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (cvode_steps_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (cvode_order_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); + // members that must be defined + if (step_divide_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Step_divide not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (rk_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Rk not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (bad_step_max_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (use_cvode_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (cvode_steps_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (cvode_order_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } } } diff --git a/cxxKinetics.h b/cxxKinetics.h index aa5f3edc..8f42b3e7 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -32,7 +32,7 @@ class cxxKinetics:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/dumper.cpp b/dumper.cpp index 923ad49f..0b9738f4 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -5,26 +5,26 @@ dumper::dumper(void) { this->file_name = "dump.out"; this->append = false; - this->dump_solution = false; - this->dump_pp_assemblage = false; - this->dump_exchange = false; - this->dump_surface = false; - this->dump_s_s_assemblage = false; - this->dump_gas_phase = false; - this->dump_kinetics = false; + this->bool_solution = false; + this->bool_pp_assemblage = false; + this->bool_exchange = false; + this->bool_surface = false; + this->bool_s_s_assemblage = false; + this->bool_gas_phase = false; + this->bool_kinetics = false; } dumper::dumper(CParser & parser) { this->file_name = "dump.out"; this->append = false; - this->dump_solution = false; - this->dump_pp_assemblage = false; - this->dump_exchange = false; - this->dump_surface = false; - this->dump_s_s_assemblage = false; - this->dump_gas_phase = false; - this->dump_kinetics = false; + this->bool_solution = false; + this->bool_pp_assemblage = false; + this->bool_exchange = false; + this->bool_surface = false; + this->bool_s_s_assemblage = false; + this->bool_gas_phase = false; + this->bool_kinetics = false; this->Read(parser); } @@ -44,23 +44,23 @@ void dumper::DumpAll(bool tf) if (tf) { - this->dump_solution = true; - this->dump_pp_assemblage = true; - this->dump_exchange = true; - this->dump_surface = true; - this->dump_s_s_assemblage = true; - this->dump_gas_phase = true; - this->dump_kinetics = true; + this->bool_solution = true; + this->bool_pp_assemblage = true; + this->bool_exchange = true; + this->bool_surface = true; + this->bool_s_s_assemblage = true; + this->bool_gas_phase = true; + this->bool_kinetics = true; } else { - this->dump_solution = false; - this->dump_pp_assemblage = false; - this->dump_exchange = false; - this->dump_surface = false; - this->dump_s_s_assemblage = false; - this->dump_gas_phase = false; - this->dump_kinetics = false; + this->bool_solution = false; + this->bool_pp_assemblage = false; + this->bool_exchange = false; + this->bool_surface = false; + this->bool_s_s_assemblage = false; + this->bool_gas_phase = false; + this->bool_kinetics = false; } } bool dumper::Read(CParser & parser) @@ -198,7 +198,7 @@ bool dumper::Read(CParser & parser) { this->solution.insert(*it); } - this->dump_solution = true; + this->bool_solution = true; break; case 1: case 2: @@ -206,40 +206,42 @@ bool dumper::Read(CParser & parser) { this->pp_assemblage.insert(*it); } - this->dump_pp_assemblage = true; + this->bool_pp_assemblage = true; break; case 3: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->exchange.insert(*it); } - this->dump_exchange = true; + this->bool_exchange = true; break; case 4: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->surface.insert(*it); } - this->dump_surface = true; + this->bool_surface = true; break; case 5: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->s_s_assemblage.insert(*it); - } this->dump_s_s_assemblage = true; + } + this->bool_s_s_assemblage = true; break; case 6: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->gas_phase.insert(*it); - } this->dump_gas_phase = true; + } + this->bool_gas_phase = true; break; case 7: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->kinetics.insert(*it); } - this->dump_kinetics = true; + this->bool_kinetics = true; break; case 8: //file std::getline(parser.get_iss(), this->file_name); diff --git a/dumper.h b/dumper.h index e68426aa..50247795 100644 --- a/dumper.h +++ b/dumper.h @@ -15,13 +15,13 @@ public: void DumpAll(bool tf); std::string get_file_name(void) { return(this->file_name); }; bool get_append(void) { return(this->append); }; - bool get_dump_solution(void) { return(this->dump_solution); }; - bool get_dump_pp_assemblage(void) { return(this->dump_pp_assemblage); }; - bool get_dump_exchange(void) { return(this->dump_exchange); }; - bool get_dump_surface(void) { return(this->dump_surface); }; - bool get_dump_s_s_assemblage(void) { return(this->dump_s_s_assemblage); }; - bool get_dump_gas_phase(void) { return(this->dump_gas_phase); }; - bool get_dump_kinetics(void) { return(this->dump_kinetics); }; + bool get_bool_solution(void) { return(this->bool_solution); }; + bool get_bool_pp_assemblage(void) { return(this->bool_pp_assemblage); }; + bool get_bool_exchange(void) { return(this->bool_exchange); }; + bool get_bool_surface(void) { return(this->bool_surface); }; + bool get_bool_s_s_assemblage(void) { return(this->bool_s_s_assemblage); }; + bool get_bool_gas_phase(void) { return(this->bool_gas_phase); }; + bool get_bool_kinetics(void) { return(this->bool_kinetics); }; std::set < int > & get_solution(void) { return(this->solution); }; std::set < int > & get_pp_assemblage(void) { return(this->pp_assemblage); }; @@ -33,13 +33,13 @@ public: protected: std::string file_name; bool append; - bool dump_solution; - bool dump_pp_assemblage; - bool dump_exchange; - bool dump_surface; - bool dump_s_s_assemblage; - bool dump_gas_phase; - bool dump_kinetics; + bool bool_solution; + bool bool_pp_assemblage; + bool bool_exchange; + bool bool_surface; + bool bool_s_s_assemblage; + bool bool_gas_phase; + bool bool_kinetics; std::set < int > solution; std::set < int > pp_assemblage;