mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 16:44:49 +01:00
Got reader for reaction_pressure working.
git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5840 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
90f308452a
commit
ae868f0a20
4
Parser.h
4
Parser.h
@ -162,6 +162,10 @@ class CParser: public PHRQ_base
|
||||
{
|
||||
return m_line;
|
||||
}
|
||||
std::string & line_save()
|
||||
{
|
||||
return m_line_save;
|
||||
}
|
||||
std::string & get_accumulated()
|
||||
{
|
||||
return accumulated;
|
||||
|
||||
@ -642,7 +642,7 @@ public:
|
||||
//int read_delta_v_only(char *ptr, LDBLE * delta_v);
|
||||
int read_number_description(char *ptr, int *n_user, int *n_user_end,
|
||||
char **description, int allow_negative=FALSE);
|
||||
int check_key(char *str);
|
||||
int check_key(const char *str);
|
||||
int check_units(char *tot_units, int alkalinity, int check_compatibility,
|
||||
const char *default_units, int print);
|
||||
int find_option(char *item, int *n, const char **list, int count_list,
|
||||
|
||||
194
Pressure.cxx
194
Pressure.cxx
@ -25,129 +25,127 @@ cxxPressure::cxxPressure(PHRQ_io *io)
|
||||
{
|
||||
count = 0;
|
||||
equalIncrements = false;
|
||||
pressures.push_back(1.0);
|
||||
}
|
||||
|
||||
cxxPressure::~cxxPressure()
|
||||
{
|
||||
}
|
||||
void
|
||||
int
|
||||
cxxPressure::read(CParser & parser)
|
||||
{
|
||||
double d;
|
||||
CParser::TOKEN_TYPE k;
|
||||
static std::vector < std::string > vopts;
|
||||
if (vopts.empty())
|
||||
{
|
||||
vopts.reserve(5);
|
||||
vopts.push_back("pressures"); //0
|
||||
vopts.push_back("equal_increments"); //1
|
||||
vopts.push_back("count"); //2
|
||||
}
|
||||
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token;
|
||||
int opt_save;
|
||||
bool useLastLine(false);
|
||||
|
||||
// Read reaction_pressure number and description
|
||||
/*
|
||||
* Reads pressure data for reaction steps
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
// number and description
|
||||
this->read_number_description(parser);
|
||||
|
||||
opt_save = CParser::OPT_ERROR;
|
||||
bool equalIncrements_defined(false);
|
||||
bool count_defined(false);
|
||||
|
||||
CParser::LINE_TYPE lt;
|
||||
bool done = false;
|
||||
for (;;)
|
||||
{
|
||||
int opt;
|
||||
if (useLastLine == false)
|
||||
{
|
||||
opt = parser.get_option(vopts, next_char);
|
||||
}
|
||||
else
|
||||
{
|
||||
opt = parser.getOptionFromLastLine(vopts, next_char);
|
||||
}
|
||||
if (opt == CParser::OPT_DEFAULT)
|
||||
{
|
||||
opt = opt_save;
|
||||
}
|
||||
switch (opt)
|
||||
{
|
||||
case CParser::OPT_EOF:
|
||||
break;
|
||||
case CParser::OPT_KEYWORD:
|
||||
break;
|
||||
case CParser::OPT_DEFAULT:
|
||||
case CParser::OPT_ERROR:
|
||||
opt = CParser::OPT_EOF;
|
||||
parser.error_msg("Unknown input in REACTION_PRESSURE_RAW keyword.",
|
||||
CParser::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE);
|
||||
useLastLine = false;
|
||||
break;
|
||||
// new line
|
||||
//LINE_TYPE check_line(const std::string & str, bool allow_empty,
|
||||
// bool allow_eof, bool allow_keyword, bool print);
|
||||
std::istream::pos_type ptr;
|
||||
std::istream::pos_type next_char;
|
||||
std::string token, str;
|
||||
lt = parser.check_line(str, false, true, true, true);
|
||||
|
||||
case 0: // pressures
|
||||
while ((k =
|
||||
parser.copy_token(token, next_char)) == CParser::TT_DIGIT)
|
||||
if (lt == CParser::LT_EMPTY ||
|
||||
lt == CParser::LT_KEYWORD ||
|
||||
lt == CParser::LT_EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (lt == CParser::LT_OPTION)
|
||||
{
|
||||
this->error_msg("Expected numeric value for pressures.", CParser::OT_CONTINUE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (done)
|
||||
{
|
||||
this->error_msg("Unknown input following equal increment definition.", CParser::OT_CONTINUE);
|
||||
continue;
|
||||
}
|
||||
|
||||
// LT_OK
|
||||
|
||||
for (;;)
|
||||
{
|
||||
// new token
|
||||
std::string token;
|
||||
CParser::TOKEN_TYPE k = parser.copy_token(token, next_char);
|
||||
|
||||
// need new line
|
||||
if (k == CParser::TT_EMPTY)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// read a pressure
|
||||
if (k == CParser::TT_DIGIT)
|
||||
{
|
||||
std::istringstream iss(token);
|
||||
LDBLE d;
|
||||
if (!(iss >> d))
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected numeric value for pressures.",
|
||||
this->error_msg("Expected numeric value for pressures.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->pressures.push_back(d);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
opt_save = 0;
|
||||
useLastLine = false;
|
||||
break;
|
||||
|
||||
case 1: // equal_increments
|
||||
if (!(parser.get_iss() >> this->equalIncrements))
|
||||
// non digit, must be "in"
|
||||
if (k == CParser::TT_UPPER || k == CParser::TT_LOWER)
|
||||
{
|
||||
this->equalIncrements = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE);
|
||||
if (this->pressures.size() != 2)
|
||||
{
|
||||
this->error_msg("To define equal increments, exactly two pressures should be defined.", CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = parser.copy_token(token, next_char);
|
||||
if (i == EMPTY)
|
||||
{
|
||||
error_msg("To define equal increments, define 'in n steps'.", CONTINUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::istringstream iss(token);
|
||||
if ((iss >> i) && i > 0)
|
||||
{
|
||||
this->equalIncrements = true;
|
||||
this->count = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_msg("Unknown input for pressure steps.", CONTINUE);
|
||||
}
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
if (k == CParser::TT_UNKNOWN)
|
||||
{
|
||||
error_msg("Unknown input for pressure steps.", CONTINUE);
|
||||
}
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
equalIncrements_defined = true;
|
||||
break;
|
||||
|
||||
case 2: // count
|
||||
if (!(parser.get_iss() >> this->count))
|
||||
{
|
||||
this->count = 0;
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Expected integer value for count.", CParser::OT_CONTINUE);
|
||||
}
|
||||
opt_save = CParser::OPT_DEFAULT;
|
||||
useLastLine = false;
|
||||
count_defined = true;
|
||||
break;
|
||||
}
|
||||
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
|
||||
break;
|
||||
}
|
||||
// members that must be defined
|
||||
if (equalIncrements_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Equal_increments not defined for REACTION_PRESSURE_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
if (count_defined == false)
|
||||
{
|
||||
parser.incr_input_error();
|
||||
parser.error_msg("Count_temps not defined for REACTION_PRESSURE_RAW input.",
|
||||
CParser::OT_CONTINUE);
|
||||
}
|
||||
} // tokens
|
||||
} // lines
|
||||
return lt;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@ -14,14 +14,13 @@ class cxxPressure:public cxxNumKeyword
|
||||
|
||||
public:
|
||||
cxxPressure(PHRQ_io *io=NULL);
|
||||
cxxPressure(struct temperature *, PHRQ_io *io=NULL);
|
||||
~cxxPressure();
|
||||
|
||||
//void dump_xml(std::ostream& os, unsigned int indent = 0)const;
|
||||
|
||||
void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const;
|
||||
|
||||
void read(CParser & parser);
|
||||
int read(CParser & parser);
|
||||
void read_raw(CParser & parser);
|
||||
|
||||
std::vector<double> & Get_pressures(void) {return pressures;};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user