Have done preliminary testing with all MODIFY keywords.

Added brief documentation in revisions.

Fixed dump feature of TRANSPORT to work with
dump_raw of C++.

ppdump now has testing for DUMP, DELETE, and MODIFY.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3727 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2009-10-29 19:53:35 +00:00
parent d54c04039a
commit cd38a8036d
7 changed files with 223 additions and 146 deletions

View File

@ -166,29 +166,29 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
s_oss << indent0 << "-rate_name " << this->
rate_name << std::endl;
s_oss << indent0 << "-tol " << this->tol << std::endl;
s_oss << indent0 << "-m " << this->m << std::endl;
s_oss << indent0 << "-m0 " << this->m0 << std::endl;
s_oss << indent0 << "-moles " << this->moles << std::endl;
s_oss << indent1 << "-tol " << this->tol << std::endl;
s_oss << indent1 << "-m " << this->m << std::endl;
s_oss << indent1 << "-m0 " << this->m0 << std::endl;
s_oss << indent1 << "-moles " << this->moles << std::endl;
// namecoef
s_oss << indent0;
s_oss << indent1;
s_oss << "-namecoef" << std::endl;
this->namecoef.dump_raw(s_oss, indent + 1);
this->namecoef.dump_raw(s_oss, indent + 2);
// d_params
s_oss << indent0;
s_oss << indent1;
s_oss << "-d_params" << std::endl;
{
int i = 0;
s_oss << indent1;
s_oss << indent2;
for (std::vector < double >::const_iterator it = d_params.begin();
it != d_params.end(); it++)
{
if (i++ == 5)
{
s_oss << std::endl;
s_oss << indent1;
s_oss << indent2;
i = 0;
}
s_oss << *it << " ";
@ -198,7 +198,7 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
}
void
cxxKineticsComp::read_raw(CParser & parser)
cxxKineticsComp::read_raw(CParser & parser, bool check)
{
std::string str;
double d;
@ -221,12 +221,14 @@ cxxKineticsComp::read_raw(CParser & parser)
std::string token;
int opt_save;
std::vector < double > temp_d_params;
opt_save = CParser::OPT_ERROR;
bool rate_name_defined(false);
bool tol_defined(false);
bool m_defined(false);
bool m0_defined(false);
bool moles_defined(false);
bool d_params_defined(false);
for (;;)
{
@ -328,13 +330,19 @@ cxxKineticsComp::read_raw(CParser & parser)
while (parser.copy_token(token, next_char) == CParser::TT_DIGIT)
{
sscanf(token.c_str(), "%lf", &d);
this->d_params.push_back(d);
temp_d_params.push_back(d);
d_params_defined = true;
}
opt_save = 6;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
if (d_params_defined)
{
this->d_params = temp_d_params;
}
// members that must be defined
if (rate_name_defined == false)
{

View File

@ -26,7 +26,7 @@ public:
void dump_raw(std::ostream & s_oss, unsigned int indent) const;
void read_raw(CParser & parser);
void read_raw(CParser & parser, bool check = true);
char *get_rate_name() const
{

View File

@ -1425,7 +1425,10 @@ read_surface_modify(void)
struct surface *entity_ptr = entity.cxxSurface2surface();
surface_free(&(surface[n]));
surface_copy(entity_ptr, &(surface[n]), entity_ptr->n_user);
free_check_null(surface[n].description);
surface[n].description = string_duplicate(entity_ptr->description);
surface_free(entity_ptr);
free_check_null(entity_ptr);
// Need to output the next keyword
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
@ -1450,6 +1453,24 @@ read_solid_solutions_modify(void)
*
*/
int return_value;
// 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);
}
/*
* Make parser
*/
@ -1475,23 +1496,6 @@ read_solid_solutions_modify(void)
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++;
@ -1508,7 +1512,10 @@ read_solid_solutions_modify(void)
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);
free_check_null(s_s_assemblage[n].description);
s_s_assemblage[n].description = string_duplicate(entity_ptr->description);
s_s_assemblage_free(entity_ptr);
free_check_null(entity_ptr);
// Need to output the next keyword
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
@ -1533,6 +1540,23 @@ read_gas_phase_modify(void)
*
*/
int return_value;
// 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);
}
/*
* Make parser
*/
@ -1558,23 +1582,6 @@ read_gas_phase_modify(void)
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++;
@ -1590,7 +1597,10 @@ read_gas_phase_modify(void)
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);
free_check_null(gas_phase[n].description);
gas_phase[n].description = string_duplicate(entity_ptr->description);
gas_phase_free(entity_ptr);
free_check_null(entity_ptr);
// Need to output the next keyword
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
@ -1615,6 +1625,24 @@ read_kinetics_modify(void)
*
*/
int return_value;
// 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);
}
/*
* Make parser
*/
@ -1640,23 +1668,6 @@ read_kinetics_modify(void)
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++;
@ -1673,7 +1684,10 @@ read_kinetics_modify(void)
struct kinetics *entity_ptr = entity.cxxKinetics2kinetics();
kinetics_free(&(kinetics[n]));
kinetics_copy(entity_ptr, &(kinetics[n]), entity_ptr->n_user);
free_check_null(kinetics[n].description);
kinetics[n].description = string_duplicate(entity_ptr->description);
kinetics_free(entity_ptr);
free_check_null(entity_ptr);
// Need to output the next keyword
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);

View File

@ -205,10 +205,33 @@ cxxSSassemblage::read_raw(CParser & parser, bool check)
case 0: // solid_solution
{
cxxSSassemblageSS ssSS;
ssSS.read_raw(parser);
std::string str(ssSS.get_name());
this->ssAssemblageSSs[str] = ssSS;
cxxSSassemblageSS ec;
// preliminary read
std::istream::pos_type pos = parser.tellg();
CParser::ECHO_OPTION eo = parser.get_echo_file();
parser.set_echo_file(CParser::EO_NONE);
CParser::ECHO_OPTION eo_s = parser.get_echo_stream();
parser.set_echo_stream(CParser::EO_NONE);
ec.read_raw(parser, false);
parser.set_echo_file(eo);
parser.set_echo_file(eo_s);
parser.seekg(pos).clear();
parser.seekg(pos);
if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end())
{
cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.get_name())->second;
ec1.read_raw(parser, false);
}
else
{
cxxSSassemblageSS ec1;
ec1.read_raw(parser, false);
std::string str(ec1.get_name());
this->ssAssemblageSSs[str] = ec1;
}
}
useLastLine = true;
break;

View File

@ -189,30 +189,30 @@ cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const
//const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n";
unsigned int i;
s_oss.precision(DBL_DIG - 1);
std::string indent0("");
std::string indent0(""), indent1("");
for (i = 0; i < indent; ++i)
indent0.append(Utilities::INDENT);
for (i = 0; i < indent + 1; ++i)
indent1.append(Utilities::INDENT);
// S_S element and attributes
s_oss << indent0 << "-name " << this->name << std::endl;
//s_oss << indent0 << "-total_moles " << this->total_moles << std::endl;
s_oss << indent0 << "-a0 " << this->a0 << std::endl;
s_oss << indent0 << "-a1 " << this->a1 << std::endl;
s_oss << indent0 << "-ag0 " << this->ag0 << std::endl;
s_oss << indent0 << "-ag1 " << this->ag1 << std::endl;
s_oss << indent0 << "-miscibility " << this->
miscibility << std::endl;
s_oss << indent1 << "-a0 " << this->a0 << std::endl;
s_oss << indent1 << "-a1 " << this->a1 << std::endl;
s_oss << indent1 << "-ag0 " << this->ag0 << std::endl;
s_oss << indent1 << "-ag1 " << this->ag1 << std::endl;
s_oss << indent1 << "-miscibility " << this->miscibility << std::endl;
//s_oss << indent0 << "-spinodal " << this->spinodal << std::endl;
//s_oss << indent0 << "-tk " << this->tk << std::endl;
s_oss << indent0 << "-xb1 " << this->xb1 << std::endl;
s_oss << indent0 << "-xb2 " << this->xb2 << std::endl;
s_oss << indent0 << "-component " << std::endl;
this->comps.dump_raw(s_oss, indent + 1);
s_oss << indent1 << "-xb1 " << this->xb1 << std::endl;
s_oss << indent1 << "-xb2 " << this->xb2 << std::endl;
s_oss << indent1 << "-component " << std::endl;
this->comps.dump_raw(s_oss, indent + 2);
}
void
cxxSSassemblageSS::read_raw(CParser & parser)
cxxSSassemblageSS::read_raw(CParser & parser, bool check)
{
std::string str;
@ -428,70 +428,73 @@ cxxSSassemblageSS::read_raw(CParser & parser)
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
// members that must be defined
if (name_defined == false)
if (check)
{
// members that must be defined
if (name_defined == false)
{
parser.incr_input_error();
parser.error_msg("Name not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
/*
if (total_moles_defined == false) {
parser.incr_input_error();
parser.error_msg("Name not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
/*
if (total_moles_defined == false) {
parser.incr_input_error();
parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
}
*/
if (a0_defined == false)
{
parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
}
*/
if (a0_defined == false)
{
parser.incr_input_error();
parser.error_msg("A0 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (a1_defined == false)
{
parser.incr_input_error();
parser.error_msg("A1 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (ag0_defined == false)
{
parser.incr_input_error();
parser.error_msg("Ag0 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (ag1_defined == false)
{
parser.incr_input_error();
parser.error_msg("Ag1 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (miscibility_defined == false)
{
parser.incr_input_error();
parser.error_msg("Miscibility not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
/*
if (spinodal_defined == false) {
parser.incr_input_error();
parser.error_msg("A0 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (a1_defined == false)
{
parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
}
if (tk_defined == false) {
parser.incr_input_error();
parser.error_msg("A1 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (ag0_defined == false)
{
parser.incr_input_error();
parser.error_msg("Ag0 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (ag1_defined == false)
{
parser.incr_input_error();
parser.error_msg("Ag1 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (miscibility_defined == false)
{
parser.incr_input_error();
parser.error_msg("Miscibility not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
/*
if (spinodal_defined == false) {
parser.incr_input_error();
parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
}
if (tk_defined == false) {
parser.incr_input_error();
parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
}
*/
if (xb1_defined == false)
{
parser.incr_input_error();
parser.error_msg("Xb1 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (xb2_defined == false)
{
parser.incr_input_error();
parser.error_msg("Xb2 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE);
}
*/
if (xb1_defined == false)
{
parser.incr_input_error();
parser.error_msg("Xb1 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
if (xb2_defined == false)
{
parser.incr_input_error();
parser.error_msg("Xb2 not defined for SSassemblageSS input.",
CParser::OT_CONTINUE);
}
}
}

View File

@ -42,7 +42,7 @@ class cxxSSassemblageSS
void dump_raw(std::ostream & s_oss, unsigned int indent) const;
void read_raw(CParser & parser);
void read_raw(CParser & parser, bool check = true);
char *get_name() const
{

View File

@ -284,6 +284,7 @@ cxxKinetics::read_raw(CParser & parser, bool check)
std::string token;
int opt_save;
bool useLastLine(false);
std::vector < double > temp_steps;
// Read kinetics number and description
this->read_number_description(parser);
@ -295,6 +296,7 @@ cxxKinetics::read_raw(CParser & parser, bool check)
bool use_cvode_defined(false);
bool cvode_steps_defined(false);
bool cvode_order_defined(false);
bool steps_defined(false);
for (;;)
{
@ -376,10 +378,32 @@ cxxKinetics::read_raw(CParser & parser, bool check)
case 4: // component
{
cxxKineticsComp kc;
kc.read_raw(parser);
std::string str(kc.get_rate_name());
this->kineticsComps[str] = kc;
cxxKineticsComp ec;
// preliminary read
std::istream::pos_type pos = parser.tellg();
CParser::ECHO_OPTION eo = parser.get_echo_file();
parser.set_echo_file(CParser::EO_NONE);
CParser::ECHO_OPTION eo_s = parser.get_echo_stream();
parser.set_echo_stream(CParser::EO_NONE);
ec.read_raw(parser, false);
parser.set_echo_file(eo);
parser.set_echo_file(eo_s);
parser.seekg(pos).clear();
parser.seekg(pos);
if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end())
{
cxxKineticsComp & comp = this->kineticsComps.find(ec.get_rate_name())->second;
comp.read_raw(parser, false);
}
else
{
cxxKineticsComp ec1;
ec1.read_raw(parser, false);
std::string str(ec1.get_rate_name());
this->kineticsComps[str] = ec1;
}
}
useLastLine = true;
break;
@ -412,7 +436,8 @@ cxxKinetics::read_raw(CParser & parser, bool check)
}
else
{
this->steps.push_back(d);
temp_steps.push_back(d);
steps_defined = true;
}
}
opt_save = 6;
@ -447,6 +472,10 @@ cxxKinetics::read_raw(CParser & parser, bool check)
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
if (steps_defined)
{
this->steps = temp_steps;
}
if (check)
{
// members that must be defined