merged MULTICHART branch back to trunk

git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5365 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2011-05-04 00:24:40 +00:00
parent 8060c0654d
commit 2a491b71a4
17 changed files with 1866 additions and 1393 deletions

167
ChartHandler.cpp Normal file
View File

@ -0,0 +1,167 @@
// ChartHandler.cpp: implementation of the ChartHandler class.
//
//////////////////////////////////////////////////////////////////////
#if defined MULTICHART
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include "ChartHandler.h"
#include "phreeqc_class.h"
#if defined PHREEQC_CLASS
#include "phreeqc.h"
#else
extern int punch_user_graph(void);
extern int error_msg(const char *err_str, const int stop, ...);
#endif
#include <iostream>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ChartHandler::ChartHandler()
//
// default constructor for ChartHandler
//
{
current_chart = NULL;
current_chart_n_user = -1000;
u_g_defined = false;
timer = true;
}
ChartHandler::~ChartHandler()
{
std::map<int, ChartObject *>::iterator it;
for (it = this->chart_map.begin(); it != chart_map.end(); it++)
{
it->second->Rate_free();
delete it->second;
}
}
void
ChartHandler::Punch_user_graph(PHREEQC_PTR_ARG)
{
std::map<int, ChartObject *>::iterator it = this->chart_map.begin();
for ( ; it != chart_map.end(); it++)
{
if (it->second->Get_active())
{
while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1))
System::Threading::Thread::Sleep(1);
this->current_chart = it->second;
P_INSTANCE_POINTER punch_user_graph();
System::Threading::Interlocked::Exchange(it->second->usingResource, 0);
}
}
}
bool
ChartHandler::Read(PHREEQC_PTR_ARG_COMMA CParser &parser)
{
int n_user;
std::string token;
// reads line, next character is after keyword
parser.check_line("ChartHandler", true, false, true, false);
std::istringstream iss(parser.line());
// keyword
iss >> token;
// number
if (!(iss >> n_user))
{
n_user = 1;
}
// makes new ChartObject if necessary
std::map<int, ChartObject *>::iterator it = this->chart_map.find(n_user);
if (it == this->chart_map.end())
{
chart_map[n_user] = new ChartObject();
it = this->chart_map.find(n_user);
#ifdef PHREEQC_CLASS
it->second->Set_phreeqc(P_INSTANCE);
#endif
}
// Read/update ChartObject
while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1))
System::Threading::Thread::Sleep(1);
{
it->second->Read(parser);
current_chart_n_user = n_user;
current_chart = it->second;
u_g_defined = true;
}
// if detached, set timer_end and free
if (it->second->Get_detach() && it->second->Get_form_started())
{
it->second->Set_end_timer(true);
it->second->Rate_free();
}
// Release lock
System::Threading::Interlocked::Exchange(it->second->usingResource, 0);
// if detached, wait for thread to acknowledge and then erase chart
if (it->second->Get_detach())
{
while (it->second->Get_form_started() && it->second->Get_done() != true)
{
System::Threading::Thread::Sleep(1);
}
delete it->second;
this->chart_map.erase(it);
}
return true;
}
bool
ChartHandler::End_timer(PHREEQC_PTR_ARG)
{
size_t max_tries = 1000;
std::map<int, ChartObject *>::iterator it = this->chart_map.begin();
for ( ; it != chart_map.end(); it++)
{
//{
// std::vector<CurveObject *>::iterator cit = it->second->Get_Curves().begin();
// size_t i;
// for (i = 0; i < it->second->Get_Curves().size(); i ++)
// {
// std::cerr << "Curve " << i << ", number of points " << it->second->Get_Curves()[i]->Get_x().size() << std::endl;
// }
//}
size_t i = 0;
if (it->second->Get_form_started())
{
while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1) && i < max_tries)
{
i++;
System::Threading::Thread::Sleep(1);
}
it->second->Set_end_timer(true);
it->second->Rate_free();
System::Threading::Interlocked::Exchange(it->second->usingResource, 0);
size_t i2 = 0;
while (it->second->Get_done() != true && i2 < max_tries)
{
i2++;
System::Threading::Thread::Sleep(1);
}
if (i >= max_tries || i2 >= max_tries)
{
P_INSTANCE_POINTER error_msg("Chart did not respond.", CONTINUE);
}
}
}
this->timer = false;
return true;
}
#endif

44
ChartHandler.h Normal file
View File

@ -0,0 +1,44 @@
#if !defined(CHARTHANDLER_H_INCLUDED)
#define CHARTHANDLER_H_INCLUDED
#if defined MULTICHART
#include <vector>
#include <map>
#include <string>
#include "Parser.h"
#include "ChartObject.h"
class ChartHandler
{
public:
ChartHandler();
~ChartHandler();
size_t Get_chart_count()
{
return this->chart_map.size();
}
ChartObject * Get_current_chart()
{
return this->current_chart;
}
bool Get_timer()
{
return timer;
}
bool Read(PHREEQC_PTR_ARG_COMMA CParser &parser);
void Punch_user_graph(PHREEQC_PTR_ARG);
bool End_timer(PHREEQC_PTR_ARG);
protected:
std::map<int, ChartObject *> chart_map;
int current_chart_n_user;
ChartObject * current_chart;
bool u_g_defined;
bool timer;
public:
};
#endif // MULTICHART
#endif // !defined(CHARTHANDLER_H_INCLUDED)

968
ChartObject.cpp Normal file
View File

@ -0,0 +1,968 @@
// ChartObject.cpp: implementation of the ChartObject class.
//
//////////////////////////////////////////////////////////////////////
#ifdef MULTICHART
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include "Utils.h"
#include <iostream>
#include "ChartObject.h"
#include "Parser.h"
#include <fstream>
#include <math.h>
#include <iomanip>
#ifdef PHREEQC_CLASS
#include "Phreeqc_class.h"
#include "Phreeqc.h"
#else
#include "phqalloc.h"
extern int error_msg(const char *err_str, const int stop, ...);
extern int warning_msg(const char *err_str, ...);
extern int rate_free(struct rate *rate_ptr);
extern int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase);
extern void * free_check_null(void *);
#endif
#include "phqalloc.h"
#include "phrqproto.h"
#include "output.h"
#include "Form2.h"
using namespace zdg_ui2;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ChartObject::ChartObject()
//
// default constructor for cxxExchComp
//
{
new_ug = false;
FirstCallToUSER_GRAPH = true;
update_time_chart = 150;
PanelHeight = 510;
PanelWidth = 640;
Symbol_map["Square"] = 0;
Symbol_map["Diamond"] = 1;
Symbol_map["Triangle"] = 2;
Symbol_map["Circle"] = 3;
Symbol_map["XCross"] = 4;
Symbol_map["Plus"] = 5;
Symbol_map["Star"] = 6;
Symbol_map["TriangleDown"] = 7;
Symbol_map["HDash"] = 8;
Symbol_map["VDash"] = 9;
Symbol_map["None"] = 10;
Color_vector.push_back("Red");
Color_vector.push_back("Green");
Color_vector.push_back("Blue");
Color_vector.push_back("Orange");
Color_vector.push_back("Magenta");
Color_vector.push_back("Yellow");
Color_vector.push_back("Black");
chart_title.clear();
axis_titles.clear();
int i;
for (i = 0; i < 5; i++)
{
axis_scale_x[i] = NA;
axis_scale_y[i] = NA;
axis_scale_y2[i] = NA;
}
chart_type = 0;
graph_initial_solutions = false;
shifts_as_points = false;
connect_simulations = true;
colnr = 0;
RowOffset = 0;
ColumnOffset = 0;
prev_advection_step = 0;
prev_transport_step = 0;
prev_sim_no = 0;
end_timer = false;
done = false;
curve_added = false;
point_added = false;
user_graph = new rate;
user_graph->commands = NULL;
user_graph->name = NULL;
user_graph->new_def = 0;
user_graph->linebase = user_graph->loopbase = user_graph->varbase = NULL;
default_symbol = 0;
graph_x = NA;
graph_y.clear();
secondary_y.clear();
usingResource = 0;
form_started = false;
active = true;
detach = false;
}
ChartObject::~ChartObject()
{
delete this->user_graph;
std::vector<CurveObject *>::iterator it;
for (it = this->CurvesCSV.begin(); it != CurvesCSV.end(); it++)
{
delete *it;
}
for (it = this->Curves.begin(); it != Curves.end(); it++)
{
delete *it;
}
}
bool
ChartObject::Set_axis_scale(CParser & parser)
{
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
double *scale_ptr = NULL;
std::vector<std::string> string_vector;
size_t j = 0;
// rereads option
parser.copy_token(token, next_char);
// reads parameters
while ((j < 6) && (parser.copy_token(token, next_char)) != CParser::TT_EMPTY)
{
string_vector.push_back(token);
j++;
}
if (string_vector.size() == 0)
{
P_INSTANCE_POINTER error_msg("No axis defined for scales", CParser::OT_CONTINUE);
return false;
}
std::string str = string_vector[0];
std::string type;
Utilities::str_tolower(str);
if (str.substr(0,2) == "y2" || str.substr(0,1) == "s")
{
type = "sy";
scale_ptr = this->axis_scale_y2;
}
else if (str.substr(0,1) == "y")
{
type = "y";
scale_ptr = this->axis_scale_y;
}
else if (str.substr(0,1) == "x")
{
type = "x";
scale_ptr = this->axis_scale_x;
}
else
{
std::ostringstream estream;
estream << "Found " << str;
estream << ", but expect axis type \'x\', \'y\', \'y2\'or \'sy\'.";
estream << std::endl;
P_INSTANCE_POINTER error_msg(estream.str().c_str(), CParser::OT_CONTINUE);
return false;
}
for (j = 1; j < string_vector.size() && j < 5; j++)
{
std::string s = string_vector[j];
if (s[0] == 'a' || s[0] == 'A')
{
scale_ptr[j - 1] = NA;
}
else if (CParser::token_type(s) == CParser::TT_DIGIT)
{
scale_ptr[j - 1] = atof(s.c_str());
}
else
{
std::ostringstream estream;
estream << "Found " << s;
estream << ", but expect number or 'a(uto)'.";
estream << std::endl;
P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE);
return false;
}
}
if (string_vector.size() == 6)
{
std::string s = string_vector[5];
if (s[0] != 't' || s[0] != 'T' || s[0] != 'l' || s[0] != 'L')
{
scale_ptr[4] = 10.0;
if (((fabs(scale_ptr[0] - NA) > 1e-3) && scale_ptr[0] <=0) ||
((fabs(scale_ptr[1] - NA) > 1e-3) && scale_ptr[1] <=0))
{
std::ostringstream estream;
estream << "MIN and MAX must be > 0 for log " << type << "-scale.";
estream << std::endl;
P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE);
return false;
}
}
}
if ((fabs(scale_ptr[0] - NA) > 1e-3) && (fabs(scale_ptr[1] - NA) > 1e-3))
{
if (scale_ptr[0] > scale_ptr[1])
{
std::ostringstream estream;
estream << "Maximum must be larger than minimum of axis_scale " << type << "-scale." << std::endl;
estream << "Switching values for MIN and MAX. " << std::endl;
P_INSTANCE_POINTER warning_msg(estream.str().c_str());
double t;
t = scale_ptr[0];
scale_ptr[0] = scale_ptr[1];
scale_ptr[1] = scale_ptr[0];
return false;
}
}
return true;
}
bool
ChartObject::Read(CParser & parser)
{
static std::vector < std::string > vopts;
if (vopts.empty())
{
vopts.reserve(15);
vopts.push_back("start"); // 0
vopts.push_back("end"); // 1
vopts.push_back("heading"); // 2
vopts.push_back("headings"); // 3
vopts.push_back("chart_title"); // 4
vopts.push_back("axis_titles"); // 5
vopts.push_back("axis_scale"); // 6
vopts.push_back("initial_solutions"); // 7
vopts.push_back("plot_concentration_vs"); // 8
vopts.push_back("shifts_as_points"); // 9
vopts.push_back("grid_offset"); // 10
vopts.push_back("connect_simulations"); // 11
vopts.push_back("plot_csv_file"); // 12
vopts.push_back("clear"); // 13
vopts.push_back("detach"); // 14
}
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
bool useLastLine(false);
bool new_command_lines(true);
if (this->FirstCallToUSER_GRAPH)
{
}
else
{
this->ColumnOffset = this->Curves.size();
this->new_ug = true;
}
this->new_plotxy_curves.clear();
//this->new_headings.clear();
// Read number and description
{
this->read_number_description(parser);
}
opt_save = CParser::OPT_DEFAULT;
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_ERROR:
opt = CParser::OPT_EOF;
P_INSTANCE_POINTER error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE);
P_INSTANCE_POINTER error_msg(parser.line().c_str(), CONTINUE);
useLastLine = false;
break;
case 0: /* start */
opt_save = CParser::OPT_DEFAULT;
break;
case 1: /* end */
opt_save = CParser::OPT_DEFAULT;
break;
case 2: /* headings */
case 3: /* heading */
while (parser.copy_token(token, next_char) != CParser::TT_EMPTY)
{
this->new_headings.push_back(token);
}
break;
case 4: /* chart title */
{
std::string tok;
parser.get_rest_of_line(tok);
CParser::copy_title(this->chart_title, tok.begin(), tok.end());
}
break;
case 5: /* axis titles */
{
this->axis_titles.clear();
std::string l;
parser.get_rest_of_line(l);
std::string tok;
std::string::iterator b = l.begin();
std::string::iterator e = l.end();
this->axis_titles.clear();
while(parser.copy_title(tok, b, e) != CParser::TT_EMPTY)
{
this->axis_titles.push_back(tok);
}
}
while (this->axis_titles.size() < 3) this->axis_titles.push_back("");
break;
case 6: /* axis scales */
{
this->Set_axis_scale(parser);
}
break;
case 7: /* initial_solutions */
this->graph_initial_solutions = parser.get_true_false(next_char, FALSE);
break;
case 8: /* plot_concentration_vs */
parser.copy_token(token, next_char);
Utilities::str_tolower(token);
if (token[0] == 'x' || token[0] == 'd')
chart_type = 0;
else if (token[0] == 't')
chart_type = 1;
else
{
std::ostringstream estream;
estream << "Found " << token << ", but expect plot type: (\'x\' or \'dist\') for distance, (\'t\') for time.";
P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE);
}
break;
case 9: /* shifts_as_points */
this->shifts_as_points = parser.get_true_false(next_char, true);
if (this->shifts_as_points)
this->chart_type = 0;
else
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);
break;
case 12: /* plot_csv_file */
{
std::string file_name;
parser.get_rest_of_line(file_name);
file_name = trim(file_name);
this->OpenCSVFile(file_name);
}
break;
case 13: /* clear */
case 14: /* detach */
this->detach = true;
break;
/* End of modifications */
case CParser::OPT_DEFAULT: // Read Basic commands
{
if (new_command_lines)
{
this->rate_command_list.clear();
new_command_lines = false;
}
this->rate_new_def = true;
/* read command */
std::string cmd(parser.line());
std::string cmd_lower = cmd;
Utilities::str_tolower(cmd_lower);
if ((cmd_lower.find("graph_y") != std::string::npos) ||
(cmd_lower.find("graph_sy") != std::string::npos))
{
//Number of curves not known here
//Curves are created in Basic cmds
}
if (cmd_lower.find("plot_xy") != std::string::npos)
{
//Curves are created in Basic cmds
ExtractCurveInfo(cmd); // truncates cmd
}
this->rate_command_list.push_back(cmd);
}
opt_save = CParser::OPT_DEFAULT;
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
// install new plotxy commands
this->Set_rate_struct();
return true;
}
bool
ChartObject::OpenCSVFile(std::string file_name)
{
std::string token;
std::ifstream f_csv(file_name.c_str(), std::ifstream::in);
if (!f_csv.is_open())
{
std::ostringstream estream;
estream << "Could not open csv file for USER_GRAPH " << file_name;
P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE);
return false;
}
std::ostringstream oss_out;
std::ostringstream oss_err;
CParser parser(P_INSTANCE_COMMA f_csv, oss_out, oss_err);
parser.set_echo_file(CParser::EO_NONE);
/* Get lines */
int linenr = 0;
// temporary storage for new CSV curves
std::vector<std::string> headings;
std::vector<CurveObject *> csv_curves;
// Read file line by line into temporary curves
while (parser.check_line("cvs file", false, true, true, false) != CParser::LT_EOF)
{
// Headings line
if (linenr == 0)
{
// Skip x in 1st column
parser.get_iss() >> token;
// Read rest of headings
while (parser.get_iss() >> token)
{
headings.push_back(token);
}
// add curves to temporary csv_curves
size_t i;
for (i = 0; i < headings.size(); i++)
{
CurveObject *c = new CurveObject;
c->Set_id(headings[i]);
c->Set_line_w(0);
std::string sym = "";
this->Get_legal_symbol(sym);
c->Set_symbol(sym);
csv_curves.push_back(c);
}
linenr++;
continue;
}
token = parser.line();
std::string tok1;
CParser::TOKEN_TYPE tt = CParser::parse_delimited(token, tok1, "\t");
// Curve properties lines
if (linenr < 6 && tt != CParser::TT_DIGIT)
{
Utilities::str_tolower(tok1);
std::string tok2;
size_t i=0;
while (token.size() != 0 && i < csv_curves.size())
{
CParser::parse_delimited(token, tok2, "\t");
tok2 = trim(tok2);
if (!strncmp(tok1.c_str(), "color", 5))
{
csv_curves[i]->Set_color(tok2);
}
else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL)
&& (strstr(tok1.c_str(), "-si") == NULL))
{
csv_curves[i]->Set_symbol(tok2);
}
else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8))
{
csv_curves[i]->Set_symbol_size(atof(tok2.c_str()));
}
else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5))
{
csv_curves[i]->Set_line_w(atof(tok2.c_str()));
}
else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5))
{
csv_curves[i]->Set_y_axis(atoi(tok2.c_str()));
}
i++;
}
linenr++;
continue;
}
// Curve data
if (linenr < 6) linenr = 6;
if (tt != CParser::TT_DIGIT)
{
linenr++;
continue;
}
// x value for all curves
double x_value = atof(tok1.c_str());
// y values for curves
std::string tok2;
size_t i=0;
while (token.size() != 0 && i < csv_curves.size())
{
CParser::parse_delimited(token, tok2, "\t");
Utilities::squeeze_white(tok2);
if (tok2.size() == 0)
{
//csv_curves[i].Get_x().push_back(NA);
//csv_curves[i].Get_y().push_back(NA);
}
else
{
csv_curves[i]->Get_x().push_back(x_value);
csv_curves[i]->Get_y().push_back(atof(tok2.c_str()));
}
i++;
}
linenr++;
}
// Append new curves
std::vector<CurveObject *>::iterator it = csv_curves.begin();
for (; it != csv_curves.end(); it++)
{
if ((*it)->Get_x().size() > 0)
{
this->CurvesCSV.push_back(*it);
this->Set_curve_added(true);
}
}
return true;
}
void
ChartObject::ExtractCurveInfo(std::string & cmd_line)
{
/* plot_xy x, tot("Cl"), color = Red, symbol = Circle, symbol_size = 0.0, line_w = 1.0, y_axis = 2 */
// Make copy of cmd_line
int curvenr = (int) this->Curves.size();
std::string str_line = cmd_line;
// find command part of cmd_line
Utilities::replace(",","#",cmd_line);
size_t pos = cmd_line.find(",");
if (pos != std::string::npos)
{
cmd_line = cmd_line.substr(0, pos);
Utilities::replace("#",",",cmd_line);
str_line.erase(0, pos + 1);
}
else
{
P_INSTANCE_POINTER error_msg("Did not find x and y expressions for plot_xy command in USER_GRAPH", STOP);
}
// new curve
CurveObject new_curve;
while (Utilities::replace(","," ",str_line));
while (Utilities::replace("="," ",str_line));
std::string::iterator b = str_line.begin();
std::string::iterator e = str_line.end();
//while (CParser::copy_title(tok, b, e) != CParser::TT_EMPTY)
for(;;)
{
std::string tok1, tok2;
if ((CParser::copy_token(tok1, b, e) == CParser::TT_EMPTY) ||
(CParser::copy_token(tok2, b, e) == CParser::TT_EMPTY))
break;
Utilities::str_tolower(tok1);
if (!strncmp(tok1.c_str(), "color", 5))
{
new_curve.Set_color(tok2);
continue;
}
else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL)
&& (strstr(tok1.c_str(), "-si") == NULL))
{
new_curve.Set_symbol(tok2);
continue;
}
else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8))
{
new_curve.Set_symbol_size(atof(tok2.c_str()));
continue;
}
else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5))
{
new_curve.Set_line_w(atof(tok2.c_str()));
continue;
}
else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5))
{
new_curve.Set_y_axis(atoi(tok2.c_str()));
continue;
}
else
{
std::ostringstream estream;
estream << "Unknown input for plot_xy in USER_GRAPH " << str_line << std::endl;
P_INSTANCE_POINTER warning_msg(estream.str().c_str());
continue;
}
}
// Add to list of new plotxy curves
this->new_plotxy_curves.push_back(new_curve);
}
void
ChartObject::Set_rate_struct(void)
{
if (rate_command_list.size() == 0) return;
std::list<std::string>::iterator it = rate_command_list.begin();
std::ostringstream oss;
for (; it != rate_command_list.end(); it++)
{
oss << *it << std::endl;
}
this->Rate_free();
this->user_graph->commands = (char *) P_INSTANCE_POINTER PHRQ_malloc((oss.str().size()) + 100 * sizeof(char));
::strcpy(this->user_graph->commands, oss.str().c_str());
this->user_graph->new_def = this->rate_new_def;
this->user_graph->loopbase = NULL;
this->user_graph->varbase = NULL;
this->user_graph->linebase = NULL;
this->user_graph->name = NULL;
}
void
ChartObject::Get_legal_symbol(std::string &sym)
{
std::map<std::string, int>::iterator it;
if ((it = this->Symbol_map.find(sym)) == this->Symbol_map.end())
{
sym = "Default";
for (it = this->Symbol_map.begin(); it != this->Symbol_map.end(); it++)
{
if (default_symbol == it->second)
{
sym = it->first;
break;
}
}
default_symbol++;
default_symbol = default_symbol % this->Symbol_map.size();
}
return;
}
ZedGraph::SymbolType
ChartObject::Return_SymbolType(const std::string sym)
{
int i;
std::map<std::string, int>::iterator it;
if ((it = this->Symbol_map.find(sym)) != this->Symbol_map.end())
{
i = it->second;
}
else
{
i = default_symbol++;
default_symbol = default_symbol % this->Symbol_map.size();
}
switch (i)
{
case 0:
return SymbolType::Square;
break;
case 1:
return SymbolType::Diamond;
break;
case 2:
return SymbolType::Triangle;
break;
case 3:
return SymbolType::Circle;
break;
case 4:
return SymbolType::XCross;
break;
case 5:
return SymbolType::Plus;
break;
case 6:
return SymbolType::Star;
break;
case 7:
return SymbolType::TriangleDown;
break;
case 8:
return SymbolType::HDash;
break;
case 9:
return SymbolType::VDash;
break;
case 10:
return SymbolType::None;
break;
default:
return SymbolType::Default;
break;
}
}
void
ChartObject::SaveCurvesToFile(std::string &file_name)
{
// reimplemented in Form
// This version not currently used
std::ofstream f_out(file_name.c_str(), std::ifstream::out);
if (!f_out.is_open())
{
std::ostringstream estream;
estream << "Could not open csv file for USER_GRAPH " << file_name;
P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE);
return;
}
// list of curves
std::vector<CurveObject *> all_curves;
size_t i;
for (i = 0; i < this->CurvesCSV.size(); i++)
{
all_curves.push_back(this->CurvesCSV[i]);
}
for (i = 0; i < this->Curves.size(); i++)
{
all_curves.push_back(Curves[i]);
}
// write headings
size_t max_points = 0;
std::vector<CurveObject *>::iterator it = all_curves.begin();
f_out.precision(4);
i = 0;
for ( ; it != all_curves.end(); it++)
{
f_out.width(12);
f_out << "x" << "\t";
f_out.width(12);
if ((*it)->Get_id().size() > 0)
{
f_out << (*it)->Get_id() << "\t";
}
else
{
f_out << "y" << "\t";;
}
if ((*it)->Get_x().size() > max_points)
max_points = (*it)->Get_x().size();
}
f_out << std::endl;
// write data
size_t i2 = 0;
f_out << std::scientific;
f_out.precision(4);
while (i2 < max_points)
{
for (it = all_curves.begin(); it != all_curves.end(); it++)
{
if (i2 < (*it)->Get_x().size())
{
f_out.width(12);
f_out << (*it)->Get_x()[i2] << "\t";
f_out.width(12);
f_out << (*it)->Get_y()[i2] << "\t";
}
else if (i2 < max_points)
{
f_out.width(13);
f_out << "\t";
f_out.width(13);
f_out << "\t";
}
}
f_out << std::endl;
i2++;
}
f_out.close();
return;
}
// file only used with MULTICHART
#if !defined PHREEQC_CLASS
bool
ChartObject::start_chart(void)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(true);
// needed to send ChartObject pointer to thread
Thread ^t = gcnew Thread(
gcnew ParameterizedThreadStart(Form1::ThreadForm));
t->SetApartmentState(ApartmentState::STA);
t->IsBackground = false;
t->Priority = ThreadPriority::Normal;
ChartObj ^p = gcnew ChartObj(this);
t->Start(p);
//Thread::Sleep( 1 ); /* this when debugging... */
//_beginthread(void (Form1::ThreadForm), 0, NULL);
return true;
}
#else
bool
ChartObject::start_chart(void)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(true);
// needed to send ChartObject pointer to thread
Thread ^t = gcnew Thread(
gcnew ParameterizedThreadStart(Form1::ThreadForm));
t->SetApartmentState(ApartmentState::STA);
t->IsBackground = false;
t->Priority = ThreadPriority::Normal;
ChartObj ^p = gcnew ChartObj(this);
t->Start(p);
this->form_started = true;
//Thread::Sleep( 1 ); /* this when debugging... */
//_beginthread(void (Form1::ThreadForm), 0, NULL);
return true;
}
#endif
void
ChartObject::Rate_free(void)
{
user_graph->commands = (char *) P_INSTANCE_POINTER free_check_null(user_graph->commands);
if (user_graph->linebase != NULL)
{
char cmd[] = "new; quit";
P_INSTANCE_POINTER basic_run(cmd, user_graph->linebase, user_graph->varbase, user_graph->loopbase);
user_graph->linebase = NULL;
user_graph->varbase = NULL;
user_graph->loopbase = NULL;
}
}
void ChartObject::Initialize_graph_pts(void)
{
graph_x = NA;
graph_y.clear();
secondary_y.clear();
}
void
ChartObject::Finalize_graph_pts(void)
{
if (graph_x != NA)
{
std::map<int, double>::iterator it;
for (it = graph_y.begin(); it != graph_y.end(); it++)
{
Curves[it->first]->Get_x().push_back(graph_x);
Curves[it->first]->Get_y().push_back(it->second);
}
}
if (graph_x != NA)
{
std::map<int, bool>::iterator it;
for (it = secondary_y.begin(); it != secondary_y.end(); it++)
{
Curves[it->first]->Set_y_axis(2);
}
}
}
void
ChartObject::Add_curve(std::string id,
double line_width,
std::string symbol,
double symbol_size,
int y_axis,
std::string color)
{
CurveObject *c = new CurveObject;
c->Set_id(id);
c->Set_line_w(line_width);
this->Get_legal_symbol(symbol);
c->Set_symbol(symbol);
c->Set_symbol_size(symbol_size);
c->Set_y_axis(y_axis);
c->Set_color(color);
this->Curves.push_back(c);
}
void
ChartObject::Set_rate_new_def(bool tf)
{
this->rate_new_def = tf;
if (this->user_graph != NULL)
{
if (tf)
{
this->user_graph->new_def = 1;
}
else
{
this->user_graph->new_def = 0;
}
}
}
#endif // MULTICHART

380
ChartObject.h Normal file
View File

@ -0,0 +1,380 @@
#if !defined(CHARTOBJECT_H_INCLUDED)
#define CHARTOBJECT_H_INCLUDED
#if defined MULTICHART
#include <vector>
#include <list>
#include <string>
#include <sstream>
#include "CurveObject.h"
#if defined PHREEQC_CLASS
#else
#include "global_structures.h"
#endif
#include "NumKeyword.h"
#include <float.h>
class Phreeqc;
class ChartObject:public cxxNumKeyword
{
public:
ChartObject();
ChartObject(int i);
~ChartObject();
// new_ug
bool Get_new_ug()
{
return this->new_ug;
}
void Set_new_ug(bool b)
{
this->new_ug = b;
}
// bool FirstCallToUSER_GRAPH;
void Set_FirstCallToUSER_GRAPH(bool b)
{
this->FirstCallToUSER_GRAPH = b;
}
bool Get_FirstCallToUSER_GRAPH()
{
return this->FirstCallToUSER_GRAPH;
}
// int update_time_chart;
int Get_update_time_chart()
{
return (this->update_time_chart);
}
// PanelHeight
int Get_PanelHeight()
{
return (this->PanelHeight);
}
// PanelWidth
int Get_PanelWidth()
{
return (this->PanelWidth);
}
// Symbol_map
// std::vector<std::string> Color_vector;
// std::string chart_title;
std::string &Get_chart_title()
{
return this->chart_title;
}
// std::vector<std::string> axis_titles;
std::vector<std::string> &Get_axis_titles()
{
return this->axis_titles;
}
// double axis_scale_x[5];
double *Get_axis_scale_x()
{
return this->axis_scale_x;
}
// double axis_scale_y[5];
double *Get_axis_scale_y()
{
return this->axis_scale_y;
}
// double axis_scale_y2[5];
double *Get_axis_scale_y2()
{
return this->axis_scale_y2;
}
// int chart_type;
int Get_chart_type()
{
return this->chart_type;
}
// bool graph_initial_solutions;
bool Get_graph_initial_solutions()
{
return this->graph_initial_solutions;
}
// bool connect_simulations;
bool Get_connect_simulations()
{
return this->connect_simulations;
}
// int shifts_as_points;
// int colnr;
void Set_colnr(int i)
{
this->colnr = i;
}
int Get_colnr()
{
return (this->colnr);
}
// int RowOffset;
void Set_RowOffset(int i)
{
this->RowOffset = i;
}
int Get_RowOffset()
{
return (this->RowOffset);
}
// int ColumnOffset;
void Set_ColumnOffset(int i)
{
this->ColumnOffset = i;
}
int Get_ColumnOffset()
{
return (this->ColumnOffset);
}
// int prev_advection_step;
void Set_prev_advection_step(int i)
{
this->prev_advection_step = i;
}
int Get_prev_advection_step()
{
return (this->prev_advection_step);
}
// int prev_transport_step;
void Set_prev_transport_step(int i)
{
this->prev_transport_step = i;
}
int Get_prev_transport_step()
{
return (this->prev_transport_step);
}
// int prev_sim_no;
void Set_prev_sim_no(int i)
{
this->prev_sim_no = i;
}
int Get_prev_sim_no(void)
{
return this->prev_sim_no;
}
// bool end_timer;
void Set_end_timer(bool b)
{
this->end_timer = b;
}
bool Get_end_timer()
{
return this->end_timer;
}
// bool end_timer;
void Set_done(bool b)
{
this->done = b;
}
bool Get_done()
{
return this->done;
}
// std::vector<CurveObject *> CurvesCSV;
std::vector<CurveObject *> &Get_CurvesCSV()
{
return this->CurvesCSV;
}
// std::vector<CurveObject *> Curves;
std::vector<CurveObject *> &Get_Curves()
{
return this->Curves;
}
// bool curve_added;
void Set_curve_added(bool tf)
{
this->curve_added = tf;
}
bool Get_curve_added()
{
return this->curve_added;
}
// bool point_added;
void Set_point_added(bool tf)
{
this->point_added = tf;
}
bool Get_point_added()
{
return this->point_added;
}
// struct rate user_graph;
struct rate *Get_user_graph()
{
return this->user_graph;
}
// C++ for rate struct
// std::string rate_name;
// std::list<std::string> rate_command_list;
std::list<std::string> &Get_rate_command_list()
{
return this->rate_command_list;
}
// bool rate_new_def;
void Set_rate_new_def(bool tf);
bool Get_rate_new_def()
{
return this->rate_new_def;
}
// int default_symbol;
//double graph_x;
void Set_graph_x(double d)
{
this->graph_x = d;
}
double Get_graph_x()
{
return this->graph_x;
}
//std::map<int, double> graph_y;
std::map<int, double> &Get_graph_y()
{
return this->graph_y;
}
//std::map<int, bool> secondary_y;
std::map<int, bool> &Get_secondary_y()
{
return this->secondary_y;
}
//std::vector<CurveObject> new_plotxy_curves;
std::vector<CurveObject> &Get_new_plotxy_curves()
{
return this->new_plotxy_curves;
}
//std::vector<std::string> new_headings;
std::vector<std::string> &Get_new_headings()
{
return this->new_headings;
}
// bool active;
void Set_active(bool tf)
{
this->active = tf;
}
bool Get_active()
{
return this->active;
}
// bool detach;
void Set_detach(bool tf)
{
this->detach = tf;
}
bool Get_detach()
{
return this->detach;
}
// bool chart_started;
bool Get_form_started()
{
return this->form_started;
}
#if defined PHREEQC_CLASS
void Set_phreeqc(Phreeqc * ptr)
{
this->p_instance1 = ptr;
}
Phreeqc * Get_phreeqc()
{
return this->p_instance1;
}
#endif
bool Set_axis_scale(std::vector<std::string>, std::vector<int> types, std::ostringstream &);
bool Set_axis_scale(CParser & parser);
bool Read(CParser & parser);
bool OpenCSVFile(std::string fn);
void ExtractCurveInfo(std::string & str_line);
void Set_rate_struct(void);
void PlotXY(std::string x, std::string y);
bool start_chart(void);
ZedGraph::SymbolType Return_SymbolType(std::string);
void SaveCurvesToFile(std::string &);
void Rate_free(void);
void Initialize_graph_pts(void);
void Finalize_graph_pts(void);
void Get_legal_symbol(std::string &sym);
//void Add_new_series(void);
void Add_curve(std::string id = "",
double line_width = 1.0,
std::string symbol = "",
double symbol_size = 6.0,
int y_axis = 1,
std::string color = "");
protected:
bool new_ug;
bool FirstCallToUSER_GRAPH;
int update_time_chart; /* milliseconds, maybe read */
int PanelHeight;
int PanelWidth;
std::map<std::string, int> Symbol_map;
std::vector<std::string> Color_vector;
std::string chart_title;
std::vector<std::string> axis_titles;
double axis_scale_x[5];
double axis_scale_y[5];
double axis_scale_y2[5];
int chart_type;
bool graph_initial_solutions;
bool connect_simulations;
int shifts_as_points;
int colnr;
int RowOffset;
int ColumnOffset;
int prev_advection_step;
int prev_transport_step;
int prev_sim_no;
bool end_timer;
bool done;
std::vector<CurveObject *> CurvesCSV;
std::vector<CurveObject *> Curves;
bool curve_added;
bool point_added;
struct rate *user_graph;
// C++ for rate struct
std::string rate_name;
std::list<std::string> rate_command_list;
bool rate_new_def;
int default_symbol;
// temporary storage before stored graph_x/y/sy data are stored in curves
// Initialize_graph_pts and Finalize_graph_pts use this storage.
double graph_x;
std::map<int, double> graph_y;
std::map<int, bool> secondary_y;
// temporary plotxy curve definitions before stored in curves
// a plotxy curve is copied to Curves when cmdplotxy is encountered
// this keeps order correct between plotxy and graph_x/y/sy
std::vector<CurveObject> new_plotxy_curves;
// temporary headings until stored during basic_run
std::vector<std::string> new_headings;
bool active;
bool detach;
bool form_started;
#if defined PHREEQC_CLASS
class Phreeqc * p_instance1;
#endif
public:
int usingResource;
};
#endif // MULTICHART
#endif // !defined(CHARTOBJECT_H_INCLUDED)

37
CurveObject.cpp Normal file
View File

@ -0,0 +1,37 @@
// CurveObject.cpp: implementation of the CurveObject class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include "CurveObject.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CurveObject::CurveObject()
//
// default constructor for cxxExchComp
//
{
x.clear();
y.clear();
//this->npoints_plot = 0;
//this->npoints = 0;
//this->nxy = 0;
//this->prev_npoints = 0;
this->id = "";
this->symbol = "";
this->color = "";
this->y_axis = 1;
this->line_w = 1.0;
this->symbol_size = 6.0;
}
CurveObject::~CurveObject()
{
}

90
CurveObject.h Normal file
View File

@ -0,0 +1,90 @@
#if !defined(CURVEOBJECT_H_INCLUDED)
#define CURVEOBJECT_H_INCLUDED
#include <vector>
#include <string>
class CurveObject
{
public:
CurveObject();
~CurveObject();
void Set_id(std::string s)
{
this->id = s;
}
std::string &Get_id(void)
{
return this->id;
}
void Set_color(std::string s)
{
this->color = s;
}
std::string &Get_color(void)
{
return this->color;
}
void Set_symbol(std::string s)
{
this->symbol = s;
}
std::string &Get_symbol(void)
{
return this->symbol;
}
void Set_symbol_size(double f)
{
this->symbol_size = f;
}
double Get_symbol_size(void)
{
return this->symbol_size;
}
void Set_line_w(double f)
{
this->line_w = f;
}
double Get_line_w(void)
{
return this->line_w;
}
void Set_y_axis(int f)
{
this->y_axis = f;
}
std::vector<double> & Get_x()
{
return this->x;
}
std::vector<double> & Get_y()
{
return this->y;
}
int Get_y_axis()
{
return this->y_axis;
}
//void Set_npoints_plot(int f)
//{
// this->npoints_plot = f;
//}
//int Get_npoints_plot(void)
//{
// return this->npoints_plot;
//}
protected:
//float *x, *y;
std::vector<double> x, y;
//int nxy, npoints, npoints_plot, prev_npoints;
std::string id, color, symbol;
int y_axis;
double line_w, symbol_size;
public:
};
#endif // !defined(CURVEOBJECT_H_INCLUDED)

View File

@ -372,6 +372,11 @@ CParser::check_key(std::string::iterator begin, std::string::iterator end)
s_keyword_map.insert(std::map < std::string,
KEY_TYPE >::value_type("reaction_raw",
KT_REACTION_RAW));
#if defined MULTICHART
s_keyword_map.insert(std::map < std::string,
KEY_TYPE >::value_type("user_graph",
KT_USER_GRAPH));
#endif
}
std::string lowercase;
@ -1349,3 +1354,91 @@ incr_input_error()
++ ERROR_MESSAGE_QUALIFIER input_error;
return ++m_input_error;
}
CParser::TOKEN_TYPE CParser::copy_title(std::string & token,
std::string::iterator & begin,
std::string::iterator & end)
{
if (begin != end)
{
std::string::iterator b = begin;
std::string::iterator e = end;
for (; b < end && (::isspace(*b) || (*b == ',')); ++b);
begin = b;
if (*begin == '"')
{
begin = ++b;
for (; begin != end && !(*begin == '"'); ++begin);
e = begin;
if (begin != end && *begin == '"')
{
e = begin++;
}
}
else
{
for (; begin < end && !(*begin == ',') && !(::isspace(*begin)); ++begin);
e = begin;
}
token.assign(b, e);
}
else
{
token.resize(0);
}
token = trim(token);
return token_type(token);
}
bool CParser::get_true_false(std::istream::pos_type & pos, bool def)
{
std::string token;
this->copy_token(token, pos);
std::string::iterator b = token.begin();
for (; b != token.end() && (::isspace(*b)); ++b);
if (b != token.end())
{
if (*b == 'f' || *b == 'F')
{
return false;
}
else if (*b == 't' || *b == 'T')
{
return true;
}
}
return def;
}
CParser::TOKEN_TYPE CParser::get_rest_of_line(std::string &token)
{
token.clear();
std::istringstream::pos_type pos = m_line_iss.tellg();
int j;
while ((j = m_line_iss.get()) != std::char_traits < char >::eof())
{
char c = (char) j;
token += c;
}
token = trim(token);
return token_type(token);
}
CParser::TOKEN_TYPE CParser::parse_delimited(std::string & source, std::string & result,
const std::string& t = " \t")
{
size_t pos = source.find_first_of(t);
std::string temp;
if (pos != std::string::npos)
{
result = source.substr(0, pos);
temp = source.substr(pos+1);
source = temp;
}
else
{
result = source;
source.clear();
}
std::string str = result;
return token_type(trim_left(str));
}

View File

@ -68,6 +68,9 @@ class CParser
KT_SURFACE_RAW = 11,
KT_TEMPERATURE_RAW = 12,
KT_REACTION_RAW = 13
#if defined MULTICHART
, KT_USER_GRAPH = 14
#endif
};
enum OPT_TYPE
@ -159,7 +162,7 @@ class CParser
std::istream::pos_type & next_pos);
std::string & line()
std::string & line()
{
return m_line;
}
@ -219,9 +222,15 @@ class CParser
static TOKEN_TYPE copy_token(std::string & token,
std::string::iterator & begin,
std::string::iterator & end);
static CParser::TOKEN_TYPE copy_title(std::string & token,
std::string::iterator & begin,
std::string::iterator & end);
static TOKEN_TYPE token_type(const std::string & token);
static TOKEN_TYPE copy_token(std::string & token, std::istream & is);
TOKEN_TYPE copy_token(std::string & token, std::istream::pos_type & pos);
bool get_true_false(std::istream::pos_type & pos, bool def);
TOKEN_TYPE get_rest_of_line(std::string &token);
static TOKEN_TYPE parse_delimited(std::string & source, std::string & result, const std::string& t);
CParser::TOKEN_TYPE peek_token();
/**

View File

@ -220,12 +220,12 @@ Phreeqc::Phreeqc(void)
{"let", toklet},
{"print", tokprint},
{"punch", tokpunch},
#if defined PHREEQ98 || defined CHART
#if defined PHREEQ98 || defined CHART || defined MULTICHART
{"graph_x", tokgraph_x},
{"graph_y", tokgraph_y},
{"graph_sy", tokgraph_sy},
#endif
#ifdef CHART
#if defined CHART || defined MULTICHART
{"plot_xy", tokplot_xy},
#endif
{"input", tokinput},

View File

@ -28,7 +28,7 @@
#include "runner.h"
#include "dumper.h"
#include "StorageBinList.h"
#include "ChartHandler.h"
#define STATIC
#define EXTERNAL
#define CLASS_QUALIFIER Phreeqc::
@ -44,7 +44,6 @@ public:
Phreeqc(void);
~Phreeqc(void);
//private:
//
//struct _generic_N_Vector;
@ -182,12 +181,12 @@ void cmddel(struct LOC_exec *LINK);
void cmdrenum(struct LOC_exec *LINK);
void cmdprint(struct LOC_exec *LINK);
void cmdpunch(struct LOC_exec *LINK);
#if defined PHREEQ98 || defined CHART
#if defined PHREEQ98 || defined CHART || defined MULTICHART
void cmdgraph_x(struct LOC_exec *LINK);
void cmdgraph_y(struct LOC_exec *LINK);
void cmdgraph_sy(struct LOC_exec *LINK);
#endif
#ifdef CHART
#if defined CHART || defined MULTICHART
void cmdplot_xy(struct LOC_exec *LINK);
#endif
void cmdlet(boolean implied, struct LOC_exec *LINK);
@ -778,7 +777,7 @@ int punch_s_s_assemblage(void);
int punch_saturation_indices(void);
int punch_totals(void);
int punch_user_punch(void);
#if defined PHREEQ98 || defined CHART
#if defined PHREEQ98 || defined CHART || defined MULTICHART
int punch_user_graph(void);
#endif
@ -855,6 +854,9 @@ int read_user_punch(void);
#if defined PHREEQ98 || defined CHART
int read_user_graph(void);
#endif
#if defined MULTICHART
int read_user_graph_handler();
#endif
int next_keyword_or_option(const char **opt_list, int count_opt_list);
// ReadClass.cxx

View File

@ -20,4 +20,4 @@
#define PHREEQC_NAME_SPACE Phreeqc::
#endif
#endif /* _INC_PHREEQC_CLASS_H */
//#include "Phreeqc_class.h"

View File

@ -1854,8 +1854,8 @@ read_kinetics_modify(void)
*/
std::istringstream iss_in;
return_value = streamify_to_next_keyword(iss_in);
std::ostringstream oss_out;
std::ostringstream oss_err;
std::ostringstream oss_out; // ??
std::ostringstream oss_err; // ??
CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err);
assert(!reading_database());
@ -2731,3 +2731,56 @@ dump_ostream(std::ostream& os)
// Turn off dump until next read
dump_info.SetAll(false);
}
#if defined MULTICHART
/* ---------------------------------------------------------------------- */
int CLASS_QUALIFIER
read_user_graph_handler(void)
/* ---------------------------------------------------------------------- */
{
/*
* Reads USER_GRAPH_DATA_BLOCK 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(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err);
//For testing, need to read line to get started
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);
}
assert(!reading_database());
bool success = chart_handler.Read(PHREEQC_THIS_COMMA parser);
// Need to output the next keyword
if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);
return (return_value);
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +0,0 @@
#ifndef _INC_SAXPHREEQC_H
#define _INC_SAXPHREEQC_H
#if defined(__cplusplus) | defined(_CPP)
extern "C"
{
#endif
void SAX_StartSystem();
int SAX_AddSolution(struct solution *solution_ptr);
void SAX_EndSystem();
int SAX_GetXMLLength();
const char *SAX_GetXMLStr();
int SAX_UnpackSolutions(void *pvBuffer, int buf_size);
#if defined(__cplusplus) | defined(_CPP)
}
#endif
#endif

View File

@ -1,206 +0,0 @@
// SaxPhreeqcHandlers.h: interface for the SaxPhreeqcHandlers class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_)
#define AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <wchar.h> // iswspace sprintf
#include <xercesc/sax2/DefaultHandler.hpp> // SAX2XMLReader
/**
#include <hash_map>
**/
#include <vector>
#include <map>
#define xns XERCES_CPP_NAMESPACE
#ifdef USE_LONG_DOUBLE
#define LDBLE long double
#else
#define LDBLE double
#endif
struct XMLCH_LESS:
std::binary_function < const XMLCh *, const XMLCh *,
bool >
{
bool
operator() (const XMLCh * _X, const XMLCh * _Y) const
{
return
xns::XMLString::compareString(_X, _Y) <
0;
}
};
#include <math.h>
//extern "C" {
#define EXTERNAL extern
//#include "phqalloc.h"
#include "global.h"
#include "phrqproto.h"
// int conc_init(struct conc *conc_ptr);
//}
class
Cconc:
public
conc
{
public:
Cconc()
{
conc_init(this);
}
~
Cconc()
{;
}
};
class
SaxPhreeqcHandlers:
public
xns::DefaultHandler
{
public:
SaxPhreeqcHandlers();
virtual ~
SaxPhreeqcHandlers();
// -----------------------------------------------------------------------
// Implementations of the SAX DocumentHandler interface
// -----------------------------------------------------------------------
void
endDocument();
void
endElement(const XMLCh * const uri, const XMLCh * const name,
const XMLCh * const qname);
void
characters(const XMLCh * const chars, const unsigned int length);
void
ignorableWhitespace(const XMLCh * const chars, const unsigned int length);
void
processingInstruction(const XMLCh * const target,
const XMLCh * const data);
void
startDocument();
void
startElement(const XMLCh * const uri, const XMLCh * const name,
const XMLCh * const qname,
const xns::Attributes & attributes);
// element types
enum elementType
{
typeNULL,
typePHAST_STATE,
typeSYSTEM,
typeSOLUTION,
typeSOLN_PE,
typeSOLN_TOTAL,
typeSOLN_MASTER_ACTIVITY,
typeSOLN_ISOTOPE,
typeSOLN_SPECIES_GAMMA
} eltType;
// attribute types
enum attributeType
{
attNULL,
attSOLN_new_def,
attSOLN_n_user,
attSOLN_n_user_end,
attSOLN_description,
attSOLN_tc,
attSOLN_ph,
attSOLN_solution_pe,
attSOLN_mu,
attSOLN_ah2o,
attSOLN_density,
attSOLN_total_h,
attSOLN_total_o,
attSOLN_cb,
attSOLN_mass_water,
attSOLN_total_alkalinity,
attSOLN_total_co2,
attSOLN_units,
attSOLN_default_pe,
attSOLN_count_master_activity,
attSOLN_count_isotopes,
attSOLN_count_species_gamma,
attSOLN_PE_name,
attM_A_description,
attM_A_la,
attM_A_list,
attISO_isotope_number,
attISO_elt_name,
attISO_isotope_name,
attISO_total,
attISO_ratio,
attISO_ratio_uncertainty,
attISO_x_ratio_uncertainty,
attISO_coef,
attCONC_description,
attCONC_moles,
attCONC_input_conc,
attCONC_units,
attCONC_equation_name,
attCONC_phase_si,
attCONC_n_pe,
attCONC_as,
attCONC_gfw,
} attType;
int
processSolutionAttributes(const xns::Attributes & attributes);
int
processSolutionTotalAttributes(const xns::Attributes & attributes,
struct conc *c);
int
processMasterActivityAttributes(const xns::Attributes & attributes,
struct master_activity *ma);
//int processMasterActivityAttributes(const xns::Attributes& attributes, std::vector<struct master_activity> *v);
int
processIsotopeAttributes(const xns::Attributes & attributes,
struct isotope *iso);
protected:
std::vector <
conc >
totals;
std::vector <
master_activity >
acts,
s_gammas;
std::vector <
isotope >
isotopes;
std::map < const XMLCh *,
elementType,
XMLCH_LESS >
mapXMLCh2Type;
std::map < const XMLCh *,
attributeType,
XMLCH_LESS >
mapXMLCh2AttType;
/**
std::hash_map<const XMLCh*, ElementType, hash<const XMLCh*>, XMLCH_EQUALS> m_hashmapXMLCh2Type;
**/
struct solution *
solution_ptr;
};
#endif // !defined(AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_)

View File

@ -79,7 +79,16 @@ Utilities::squeeze_white(std::string & s_l)
std::string str;
std::string::iterator beg = s_l.begin();
std::string::iterator end = s_l.end();
CParser::copy_token(str, beg, end);
//CParser::copy_token(str, beg, end);
std::string::iterator pos;
for (pos = beg; pos != end; pos++)
{
int c = *pos;
if (!::isspace(c))
{
str += c;
}
}
s_l = str;
}
@ -96,7 +105,7 @@ Utilities::error_msg(const std::string & err_str, const int stop)
//+NAN double: 7ff8000000000000
//-NAN double: fff8000000000000
/*
double Utilities::get_nan(void)
{
unsigned long long raw = 0x7ff0000000000000;
@ -104,5 +113,5 @@ double Utilities::get_nan(void)
return(d);
}
*/

View File

@ -1,16 +0,0 @@
#if !defined(CHARSTAR_H_INCLUDED)
#define CHARSTAR_H_INCLUDED
struct CHARSTAR_LESS:
std::binary_function < const char *, const char *,
bool >
{
bool
operator() (const char *_X, const char *_Y) const
{
return::strcmp(_X, _Y) <
0;
}
};
#endif