From 4b793aa95fe63c82409ee6d375261353326fe0cd Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 5 Mar 2010 21:20:09 +0000 Subject: [PATCH 01/32] Updated for IPhreeqc to use PHREEQC_CPP and PHREEQC_CLASS. Currently doesn't include gmp. MemDebug project still needs work. Needs to be tested on linux. git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4145 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ErrorReporter.hxx | 3 +- IPhreeqc.cpp | 1869 +++++++++++++++++++++++++++++--------------- IPhreeqc.hpp | 87 +++ PhreeqcParser.hxx | 35 - SelectedOutput.cpp | 441 ++++++----- SelectedOutput.hxx | 7 +- Var.c | 4 +- fwrap.c | 7 +- global.c | 5 - module_files.c | 57 +- module_files.h | 4 +- module_output.c | 11 +- phreeqcns.hxx | 2 + 13 files changed, 1592 insertions(+), 940 deletions(-) create mode 100644 IPhreeqc.hpp delete mode 100644 PhreeqcParser.hxx delete mode 100644 global.c diff --git a/ErrorReporter.hxx b/ErrorReporter.hxx index a1eb67c3..e2f554b2 100644 --- a/ErrorReporter.hxx +++ b/ErrorReporter.hxx @@ -6,7 +6,8 @@ #include // std::fprintf #include "phreeqcns.hxx" -class IErrorReporter { +class IErrorReporter +{ public: virtual size_t AddError(const char* error_msg) = 0; virtual void Clear(void) = 0; diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index 05209cab..639bfa9d 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -1,214 +1,216 @@ -#if defined(_DEBUG) -#pragma warning(disable : 4786) // disable truncation warning -#endif -#include // std::cout -#include // std::ifstream -#include // std::auto_ptr -#include // std::istringstream -#include - -#if defined(_WIN32) -#include // ::OutputDebugString -#endif - -#include "phreeqcns.hxx" -#include "ErrorReporter.hxx" -#include "SelectedOutput.hxx" -#include "Var.h" #include "IPhreeqc.h" -#include "module_files.h" - -#ifdef PHREEQC_CPP -extern int dump_entities(void); -extern int delete_entities(void); -extern int run_as_cells(void); -#endif +#include "IPhreeqc.hpp" +#include "ErrorReporter.hxx" +int istream_getc(void *cookie); const char OUTPUT_FILENAME[] = "phreeqc.out"; const char ERROR_FILENAME[] = "phreeqc.err"; const char LOG_FILENAME[] = "phreeqc.log"; const char PUNCH_FILENAME[] = "selected.out"; - -const std::string& GetAccumulatedLines(void); -void ClearAccumulatedLines(void); - -void EndRow(void); -void AddSelectedOutput(const char* name, const char* format, va_list argptr); - - -struct PhreeqcStop{}; - -struct IPhreeqc -{ - // ctor - IPhreeqc(void) - : m_pIErrorReporter(0) - , m_bDatabaseLoaded(false) - , m_bSelectedOutputOn(false) - , m_sPunchFileName(NULL) - { - // initialize - UnLoadDatabase(); - }; - IPhreeqc(IErrorReporter *pIErrorReporter) - : m_pIErrorReporter(0) - , m_bDatabaseLoaded(false) - , m_bSelectedOutputOn(false) - , m_sPunchFileName(NULL) - { - // initialize - UnLoadDatabase(); - }; - ~IPhreeqc(void) - { - UnLoadDatabase(); - delete[] m_sPunchFileName; - }; - IErrorReporter *m_pIErrorReporter; - bool m_bDatabaseLoaded; - bool m_bSelectedOutputOn; - char *m_sPunchFileName; -}; - -static std::string s_string_input; -static std::ostringstream s_oss; -static CErrorReporter s_errorReporter; -static IPhreeqc s_IPhreeqc(&s_errorReporter); - -static void check_database(const char *sz_routine); - -static void do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int error_on, int log_on, int selected_output_on, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie); - - -int istream_getc(void *cookie); -int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); -int open_handler(const int type, const char *file_name); -int handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); - - -int -istream_getc(void *cookie) -{ - if (cookie) - { - std::istream* is = (std::istream*)cookie; - return is->get(); - } - return EOF; -} - -int -handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) -{ - int n = OK; - switch (action) - { - case ACTION_OPEN: - n = open_handler(type, err_str); - break; - - case ACTION_OUTPUT: - n = output_handler(type, err_str, stop, cookie, format, args); - break; - - default: - n = module_handler(action, type, err_str, stop, cookie, format, args); - break; - } - - if (stop == STOP) - { - throw PhreeqcStop(); - } - return n; -} - -int -output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) -{ - IPhreeqc* pIPhreeqc = (IPhreeqc*) cookie; - - switch (type) - { - case OUTPUT_ERROR: - if (pIPhreeqc && pIPhreeqc->m_pIErrorReporter) - { - std::ostringstream oss; - oss << "ERROR: " << err_str << "\n"; - if (stop == STOP) { - oss << "Stopping.\n"; - } - pIPhreeqc->m_pIErrorReporter->AddError(oss.str().c_str()); - } - break; - - case OUTPUT_PUNCH: - AddSelectedOutput(err_str, format, args); - break; - - } - return module_handler(ACTION_OUTPUT, type, err_str, stop, cookie, format, args); -} - -int -open_handler(const int type, const char *file_name) -{ - int n = OK; - switch (type) - { - case OUTPUT_PUNCH: - if (file_name) - { - ASSERT(s_IPhreeqc.m_sPunchFileName != file_name); - if (s_IPhreeqc.m_sPunchFileName != file_name) - { - delete[] s_IPhreeqc.m_sPunchFileName; - s_IPhreeqc.m_sPunchFileName = NULL; - s_IPhreeqc.m_sPunchFileName = new char[::strlen(file_name) + 1]; - ::strcpy(s_IPhreeqc.m_sPunchFileName, file_name); - } - } - if (s_IPhreeqc.m_bSelectedOutputOn) - { - n = module_handler(ACTION_OPEN, type, file_name, CONTINUE, NULL, NULL, NULL); - } - break; - default: - n = module_handler(ACTION_OPEN, type, file_name, CONTINUE, NULL, NULL, NULL); - break; - } - return n; -} - int LoadDatabase(const char* filename) +{ + return IPhreeqc::LibraryInstance()->LoadDatabase(filename); +} + +int +LoadDatabaseString(const char* input) +{ + return IPhreeqc::LibraryInstance()->LoadDatabaseString(input); +} + +void +UnLoadDatabase(void) +{ + IPhreeqc::LibraryInstance()->UnLoadDatabase(); +} + +void +OutputLastError(void) +{ + IPhreeqc::LibraryInstance()->OutputLastError(); +} + +const char* +GetLastErrorString(void) +{ + return IPhreeqc::LibraryInstance()->GetLastErrorString(); +} + +VRESULT +AccumulateLine(const char *line) +{ + return IPhreeqc::LibraryInstance()->AccumulateLine(line); +} + +int +Run(int output_on, int error_on, int log_on, int selected_output_on) +{ + return IPhreeqc::LibraryInstance()->Run(output_on, error_on, log_on, selected_output_on); +} + +int +RunFile(const char* filename, int output_on, int error_on, int log_on, int selected_output_on) +{ + return IPhreeqc::LibraryInstance()->RunFile(filename, output_on, error_on, log_on, selected_output_on); +} + +int +RunString(const char* input, int output_on, int error_on, int log_on, int selected_output_on) +{ + return IPhreeqc::LibraryInstance()->RunString(input, output_on, error_on, log_on, selected_output_on); +} + +int +GetSelectedOutputRowCount(void) +{ + return (int)IPhreeqc::LibraryInstance()->GetSelectedOutputRowCount(); +} + +int +GetSelectedOutputColumnCount(void) +{ + return (int)IPhreeqc::LibraryInstance()->GetSelectedOutputColumnCount(); +} + +VRESULT +GetSelectedOutputValue(int row, int col, VAR* pVAR) +{ + return IPhreeqc::LibraryInstance()->GetSelectedOutputValue(row, col, pVAR); +} + +size_t +AddError(const char* error_msg) +{ + return IPhreeqc::LibraryInstance()->AddError(error_msg); +} + + +void +OutputLines(void) +{ + IPhreeqc::LibraryInstance()->OutputLines(); +} + +const std::string& +GetAccumulatedLines(void) +{ + return IPhreeqc::LibraryInstance()->GetAccumulatedLines(); +} + +void +ClearAccumulatedLines(void) +{ + IPhreeqc::LibraryInstance()->ClearAccumulatedLines(); +} + + +IPhreeqc::IPhreeqc(void) +: Phreeqc() +, ErrorReporter(0) +, SelectedOutput(0) +, DatabaseLoaded(false) +, SelectedOutputOn(false) +{ + ASSERT(this->phast == 0); + this->ErrorReporter = new CErrorReporter; + this->SelectedOutput = new CSelectedOutput(); + this->Init(); + this->UnLoadDatabase(); +} + +IPhreeqc::~IPhreeqc(void) +{ + delete this->ErrorReporter; + delete this->SelectedOutput; +} + +// the library singleton +IPhreeqc* IPhreeqc::Instance = 0; + +IPhreeqc* IPhreeqc::LibraryInstance() +{ + if (IPhreeqc::Instance == 0) + { + IPhreeqc::Instance = new IPhreeqc; + } + return IPhreeqc::Instance; +} + +int Phreeqc::EndRow(void) +{ + return OK; +} + +int IPhreeqc::EndRow(void) +{ + if (this->SelectedOutput->GetRowCount() <= 1) + { + // ensure all user_punch headings are included + for (int i = this->n_user_punch_index; i < this->user_punch_count_headings; ++i) + { + this->SelectedOutput->PushBackEmpty(this->user_punch_headings[i]); + } + } + return this->SelectedOutput->EndRow(); +} + +void IPhreeqc::ClearAccumulatedLines(void) +{ + this->StringInput.erase(); +} + +size_t IPhreeqc::AddError(const char* error_msg) +{ + return this->ErrorReporter->AddError(error_msg); +} + +const std::string& IPhreeqc::GetAccumulatedLines(void) +{ + return this->StringInput; +} + +void IPhreeqc::OutputLines(void) +{ + std::cout << this->StringInput.c_str() << std::endl; +} + +void IPhreeqc::UnLoadDatabase(void) +{ + // init IPhreeqc + // + this->DatabaseLoaded = false; + this->SelectedOutputOn = false; + + // clear error state + // + ASSERT(this->ErrorReporter); + this->ErrorReporter->Clear(); + + // clear selectedoutput + // + ASSERT(this->ErrorReporter); + this->SelectedOutput->Clear(); + + // initialize phreeqc + // + this->clean_up(); + this->add_output_callback(IPhreeqc::handler, this); + this->do_initialize(); + this->input_error = 0; +} + +int IPhreeqc::LoadDatabase(const char* filename) { try { // cleanup // - UnLoadDatabase(); + this->UnLoadDatabase(); + this->SelectedOutput->Clear(); - CSelectedOutput::Instance()->Clear(); - -#if 0 - // open stream - // - std::ifstream ifs; - ifs.open(filename); - if (!ifs.is_open()) - { - std::ostringstream oss; - oss << "LoadDatabase: Unable to open:" << "\"" << filename << "\"."; - error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop - } - - // read input - // - read_database(istream_getc, &ifs); -#else // open file // FILE* f = fopen(filename, "r"); @@ -216,24 +218,24 @@ LoadDatabase(const char* filename) { std::ostringstream oss; oss << "LoadDatabase: Unable to open:" << "\"" << filename << "\"."; - error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop + this->error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop } // read input // - read_database(getc_callback, f); -#endif + this->read_database(getc_callback, f); + } catch (PhreeqcStop) { // do nothing } - catch(...) + catch (...) { const char *errmsg = "LoadDatabase: An unhandled exception occured.\n"; try { - error_msg(errmsg, STOP); // throws PhreeqcStop + this->error_msg(errmsg, STOP); // throws PhreeqcStop } catch (PhreeqcStop) { @@ -241,27 +243,26 @@ LoadDatabase(const char* filename) } } - s_IPhreeqc.m_bDatabaseLoaded = (input_error == 0); - return input_error; + this->DatabaseLoaded = (this->input_error == 0); + return this->input_error; } -int -LoadDatabaseString(const char* input) +int IPhreeqc::LoadDatabaseString(const char* input) { try { // cleanup // - UnLoadDatabase(); + this->UnLoadDatabase(); - CSelectedOutput::Instance()->Clear(); + this->SelectedOutput->Clear(); std::string s(input); std::istringstream iss(s); // read input // - read_database(istream_getc, &iss); + this->read_database(istream_getc, &iss); } catch (PhreeqcStop) { @@ -272,7 +273,7 @@ LoadDatabaseString(const char* input) const char *errmsg = "LoadDatabaseString: An unhandled exception occured.\n"; try { - error_msg(errmsg, STOP); // throws PhreeqcStop + this->error_msg(errmsg, STOP); // throws PhreeqcStop } catch (PhreeqcStop) { @@ -280,423 +281,70 @@ LoadDatabaseString(const char* input) } } - s_IPhreeqc.m_bDatabaseLoaded = (input_error == 0); - return input_error; + this->DatabaseLoaded = (this->input_error == 0); + return this->input_error; } -void -UnLoadDatabase(void) +void IPhreeqc::OutputLastError(void) { - // init IPhreeqc - // - s_IPhreeqc.m_pIErrorReporter = &s_errorReporter; - s_IPhreeqc.m_bDatabaseLoaded = false; - s_IPhreeqc.m_bSelectedOutputOn = false; - - // clear error state - // - s_errorReporter.Clear(); - - // free selectedoutput - // - CSelectedOutput::Release(); - - // initialize phreeqc - // - clean_up(); - add_output_callback(handler, &s_IPhreeqc); - do_initialize(); - input_error = 0; + std::cout << ((CErrorReporter*)this->ErrorReporter)->GetOS()->str().c_str() << std::endl; } - -void -OutputLastError(void) -{ - std::cout << s_errorReporter.GetOS()->str().c_str() << std::endl; -} - -const char* -GetLastErrorString(void) +const char* IPhreeqc::GetLastErrorString(void) { static std::string str; - str = s_errorReporter.GetOS()->str(); + str = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); return str.c_str(); } -// COMMENT: {11/27/2006 7:00:49 PM}#if defined(_WIN32) -// COMMENT: {11/27/2006 7:00:49 PM}void -// COMMENT: {11/27/2006 7:00:49 PM}DebugOutputLastError(void) -// COMMENT: {11/27/2006 7:00:49 PM}{ -// COMMENT: {11/27/2006 7:00:49 PM} std::istringstream iss(s_errorReporter.GetOS()->str()); -// COMMENT: {11/27/2006 7:00:49 PM} std::string line; -// COMMENT: {11/27/2006 7:00:49 PM} while (std::getline(iss, line)) { -// COMMENT: {11/27/2006 7:00:49 PM} ::OutputDebugString(line.c_str()); -// COMMENT: {11/27/2006 7:00:49 PM} ::OutputDebugString("\n"); -// COMMENT: {11/27/2006 7:00:49 PM} } -// COMMENT: {11/27/2006 7:00:49 PM}} -// COMMENT: {11/27/2006 7:00:49 PM}#endif - - -VRESULT -AccumulateLine(const char *line) +void IPhreeqc::check_database(const char* sz_routine) { - try - { - s_errorReporter.Clear(); - s_string_input.append(line); - s_string_input.append("\n"); - return VR_OK; - } - catch (...) - { - s_errorReporter.AddError("AccumulateLine: An unhandled exception occured.\n"); - } - return VR_OUTOFMEMORY; -} + this->ErrorReporter->Clear(); + this->SelectedOutput->Clear(); -int -Run(int output_on, int error_on, int log_on, int selected_output_on) -{ - static const char *sz_routine = "Run"; - try - { - // this may throw - check_database(sz_routine); - - input_error = 0; - - // create input stream - std::istringstream iss(GetAccumulatedLines()); - - // this may throw - do_run(sz_routine, &iss, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); - } - catch (PhreeqcStop) - { - // do nothing - } - catch(...) - { - const char *errmsg = "Run: An unhandled exception occured.\n"; - try - { - error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - // do nothing - } - } - - ::ClearAccumulatedLines(); - close_output_files(); - return input_error; -} - -int -RunFile(const char* filename, int output_on, int error_on, int log_on, int selected_output_on) -{ - static const char *sz_routine = "RunFile"; - try - { - // this may throw - check_database(sz_routine); - - input_error = 0; - -#if 0 - // create input stream - std::ifstream ifs; - ifs.open(filename); - if (!ifs.is_open()) - { - std::ostringstream oss; - oss << "RunFile: Unable to open:" << "\"" << filename << "\"."; - input_error = 1; - error_msg(oss.str().c_str(), STOP); // throws - } - - // this may throw - do_run(sz_routine, &ifs, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); -#else - // open file - // - FILE* f = fopen(filename, "r"); - if (!f) - { - std::ostringstream oss; - oss << "RunFile: Unable to open:" << "\"" << filename << "\"."; - error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop - } - - // this may throw - do_run(sz_routine, NULL, f, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); -#endif - } - catch (PhreeqcStop) - { - // do nothing - } - catch(...) - { - const char *errmsg = "RunFile: An unhandled exception occured.\n"; - try - { - error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - // do nothing - } - } - - close_output_files(); - return input_error; -} - -int -RunString(const char* input, int output_on, int error_on, int log_on, int selected_output_on) -{ - static const char *sz_routine = "RunString"; - try - { - // this may throw - check_database(sz_routine); - - input_error = 0; - - // create input stream - std::string s(input); - std::istringstream iss(s); - - // this may throw - do_run(sz_routine, &iss, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); - } - catch (PhreeqcStop) - { - // do nothing - } - catch(...) - { - const char *errmsg = "RunString: An unhandled exception occured.\n"; - try - { - error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - // do nothing - } - } - - close_output_files(); - return input_error; -} - - -int -GetSelectedOutputRowCount(void) -{ - return (int)CSelectedOutput::Instance()->GetRowCount(); -} - -int -GetSelectedOutputColumnCount(void) -{ - return (int)CSelectedOutput::Instance()->GetColCount(); -} - -VRESULT -GetSelectedOutputValue(int row, int col, VAR* pVAR) -{ - s_errorReporter.Clear(); - if (!pVAR) { - s_errorReporter.AddError("GetSelectedOutputValue: VR_INVALIDARG pVar is NULL.\n"); - return VR_INVALIDARG; - } - - VRESULT v = CSelectedOutput::Instance()->Get(row, col, pVAR); - switch (v) { - case VR_OK: - break; - case VR_OUTOFMEMORY: - s_errorReporter.AddError("GetSelectedOutputValue: VR_OUTOFMEMORY Out of memory.\n"); - break; - case VR_BADVARTYPE: - s_errorReporter.AddError("GetSelectedOutputValue: VR_BADVARTYPE pVar must be initialized(VarInit) and/or cleared(VarClear).\n"); - break; - case VR_INVALIDARG: - // not possible - break; - case VR_INVALIDROW: - s_errorReporter.AddError("GetSelectedOutputValue: VR_INVALIDROW Row index out of range.\n"); - break; - case VR_INVALIDCOL: - s_errorReporter.AddError("GetSelectedOutputValue: VR_INVALIDCOL Column index out of range.\n"); - break; - } - return v; -} - -size_t -AddError(const char* error_msg) -{ - return s_errorReporter.AddError(error_msg); -} - -void -OutputLines(void) -{ - std::cout << s_string_input.c_str() << std::endl; -} - -// COMMENT: {11/27/2006 7:01:16 PM}#if defined(WIN32) -// COMMENT: {11/27/2006 7:01:16 PM}void -// COMMENT: {11/27/2006 7:01:16 PM}DebugOutputLines(void) -// COMMENT: {11/27/2006 7:01:16 PM}{ -// COMMENT: {11/27/2006 7:01:16 PM} std::istringstream iss(s_string_input); -// COMMENT: {11/27/2006 7:01:16 PM} std::string line; -// COMMENT: {11/27/2006 7:01:16 PM} while (std::getline(iss, line)) { -// COMMENT: {11/27/2006 7:01:16 PM} ::OutputDebugString(line.c_str()); -// COMMENT: {11/27/2006 7:01:16 PM} ::OutputDebugString("\n"); -// COMMENT: {11/27/2006 7:01:16 PM} } -// COMMENT: {11/27/2006 7:01:16 PM}} -// COMMENT: {11/27/2006 7:01:16 PM}#endif - -const std::string& -GetAccumulatedLines(void) -{ - return s_string_input; -} - -void -ClearAccumulatedLines(void) -{ - s_string_input.erase(); -} - -int -RunWithCallback(PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie, int output_on, int error_on, int log_on, int selected_output_on) -{ - static const char *sz_routine = "RunWithCallback"; - try - { - // this may throw - check_database(sz_routine); - - input_error = 0; - - // this may throw - do_run(sz_routine, NULL, NULL, output_on, error_on, log_on, selected_output_on, pfn_pre, pfn_post, cookie); - } - catch (PhreeqcStop) - { - // do nothing - } - catch(...) - { - const char *errmsg = "RunWithCallback: An unhandled exception occured.\n"; - try - { - error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - // do nothing - } - } - - ClearAccumulatedLines(); - close_output_files(); - output_close(OUTPUT_DUMP); // this should be closed in close_output_files - return input_error; -} - - -int -CatchErrors(PFN_CATCH_CALLBACK pfn, void *cookie) -{ - int rvalue = OK; - try - { - input_error = 0; - - if (pfn) - { - rvalue = pfn(cookie); - } - - } - catch (PhreeqcStop) - { - // do nothing - } - catch (...) - { - const char errmsg[] = "CatchErrors: Unhandled exception occured.\n"; - try - { - error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - // do nothing - } - } - return rvalue; -} - -static void -check_database(const char* sz_routine) -{ - s_errorReporter.Clear(); - CSelectedOutput::Instance()->Clear(); - - if (!s_IPhreeqc.m_bDatabaseLoaded) + if (!this->DatabaseLoaded) { std::ostringstream oss; oss << sz_routine << ": No database is loaded"; - input_error = 1; - error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop + this->input_error = 1; + this->error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop } } -static void -do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int error_on, int log_on, int selected_output_on, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie) +void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int error_on, int log_on, int selected_output_on, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie) { std::auto_ptr auto_iss(NULL); char token[MAX_LENGTH]; if (output_on) { - if (output_open(OUTPUT_MESSAGE, OUTPUT_FILENAME) != OK) + if (this->output_open(OUTPUT_MESSAGE, OUTPUT_FILENAME) != OK) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << OUTPUT_FILENAME << "\".\n"; - warning_msg(oss.str().c_str()); + this->warning_msg(oss.str().c_str()); } } if (error_on) { - if (output_open(OUTPUT_ERROR, ERROR_FILENAME) != OK) + if (this->output_open(OUTPUT_ERROR, ERROR_FILENAME) != OK) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << ERROR_FILENAME << "\".\n"; - warning_msg(oss.str().c_str()); + this->warning_msg(oss.str().c_str()); } } if (log_on) { - if (output_open(OUTPUT_LOG, LOG_FILENAME) != OK) + if (this->output_open(OUTPUT_LOG, LOG_FILENAME) != OK) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << LOG_FILENAME << "\".\n"; - warning_msg(oss.str().c_str()); + this->warning_msg(oss.str().c_str()); } } - s_IPhreeqc.m_bSelectedOutputOn = (selected_output_on != 0); + this->SelectedOutputOn = (selected_output_on != 0); /* * call pre-run callback @@ -713,63 +361,63 @@ do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int e { if (fp) { - set_read_callback(getc_callback, fp, FALSE); + this->set_read_callback(getc_callback, fp, FALSE); } else { - std::auto_ptr a_iss(new std::istringstream(GetAccumulatedLines())); + std::auto_ptr a_iss(new std::istringstream(this->GetAccumulatedLines())); auto_iss = a_iss; - set_read_callback(istream_getc, auto_iss.get(), FALSE); + this->set_read_callback(istream_getc, auto_iss.get(), FALSE); } } else { - set_read_callback(istream_getc, pis, FALSE); + this->set_read_callback(istream_getc, pis, FALSE); } /* * Read input data for simulation */ - for (simulation = 1; ; simulation++) { + for (this->simulation = 1; ; this->simulation++) { #ifdef PHREEQ98 AddSeries = !connect_simulations; #endif - sprintf(token, "Reading input data for simulation %d.", simulation); + ::sprintf(token, "Reading input data for simulation %d.", simulation); - output_msg(OUTPUT_GUI_ERROR, "\nSimulation %d\n", simulation); + this->output_msg(OUTPUT_GUI_ERROR, "\nSimulation %d\n", simulation); #ifdef SWIG_SHARED_OBJ - int save_punch_in = punch.in; + int save_punch_in = this->punch.in; #endif // SWIG_SHARED_OBJ - dup_print(token, TRUE); - if (read_input() == EOF) break; +// COMMENT: {3/3/2010 10:46:12 PM} dup_print(token, TRUE); + if (this->read_input() == EOF) break; #ifdef SWIG_SHARED_OBJ - if (simulation > 1 && save_punch_in == TRUE && punch.new_def == TRUE) + if (this->simulation > 1 && save_punch_in == TRUE && this->punch.new_def == TRUE) { std::ostringstream oss; oss << sz_routine << ": Warning SELECTED_OUTPUT has been redefined.\n"; - warning_msg(oss.str().c_str()); + this->warning_msg(oss.str().c_str()); } - if (simulation > 1 && keyword[39].keycount > 0) + if (this->simulation > 1 && this->keyword[39].keycount > 0) { std::ostringstream oss; oss << sz_routine << ": Warning USER_PUNCH has been redefined.\n"; - warning_msg(oss.str().c_str()); + this->warning_msg(oss.str().c_str()); } #endif // SWIG_SHARED_OBJ - if (title_x != NULL) { - sprintf(token, "TITLE"); - dup_print(token, TRUE); - if (pr.headings == TRUE) output_msg(OUTPUT_MESSAGE,"%s\n\n", title_x); + if (this->title_x != NULL) { + ::sprintf(token, "TITLE"); + this->dup_print(token, TRUE); + if (this->pr.headings == TRUE) this->output_msg(OUTPUT_MESSAGE, "%s\n\n", this->title_x); } #ifdef SWIG_SHARED_OBJ - if (punch.in == TRUE) + if (this->punch.in == TRUE) { // // (punch.in == TRUE) when any "RUN" has contained @@ -787,9 +435,9 @@ do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int e // TRUE ??? // // - if (!selected_output_on) ASSERT(!::output_isopen(OUTPUT_PUNCH)); + if (!selected_output_on) ASSERT(!this->output_isopen(OUTPUT_PUNCH)); - if (pr.punch == FALSE) + if (this->pr.punch == FALSE) { // No selected_output for this simulation // this happens when @@ -799,34 +447,34 @@ do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int e } else { - if (punch.new_def == FALSE) + if (this->punch.new_def == FALSE) { - if (selected_output_on && !::output_isopen(OUTPUT_PUNCH)) + if (selected_output_on && !this->output_isopen(OUTPUT_PUNCH)) { // // LoadDatabase // do_run -- containing SELECTED_OUTPUT ****TODO**** check -file option // another do_run without SELECTED_OUTPUT // - std::string filename = s_IPhreeqc.m_sPunchFileName; - output_open(OUTPUT_PUNCH, filename.c_str()); - if (!::output_isopen(OUTPUT_PUNCH)) + std::string filename = this->PunchFileName; + this->output_open(OUTPUT_PUNCH, filename.c_str()); + if (!this->output_isopen(OUTPUT_PUNCH)) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n"; - warning_msg(oss.str().c_str()); + this->warning_msg(oss.str().c_str()); } else { // output selected_output headings - punch.new_def = TRUE; - tidy_punch(); + this->punch.new_def = TRUE; + this->tidy_punch(); } } } else { - if (selected_output_on && !::output_isopen(OUTPUT_PUNCH)) + if (selected_output_on && !this->output_isopen(OUTPUT_PUNCH)) { // This is a special case which could not occur in // phreeqc @@ -836,34 +484,34 @@ do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int e // another do_run with SELECTED_OUTPUT // std::string filename = PUNCH_FILENAME; - if (s_IPhreeqc.m_sPunchFileName && ::strlen(s_IPhreeqc.m_sPunchFileName)) + if (this->PunchFileName.size()) { - filename = s_IPhreeqc.m_sPunchFileName; + filename = this->PunchFileName; } - output_open(OUTPUT_PUNCH, filename.c_str()); - if (!::output_isopen(OUTPUT_PUNCH)) + this->output_open(OUTPUT_PUNCH, filename.c_str()); + if (!this->output_isopen(OUTPUT_PUNCH)) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n"; - warning_msg(oss.str().c_str()); + this->warning_msg(oss.str().c_str()); } else { // output selected_output headings ASSERT(punch.new_def == TRUE); - tidy_punch(); + this->tidy_punch(); } } } } } - if (!selected_output_on) ASSERT(!::output_isopen(OUTPUT_PUNCH)); + if (!selected_output_on) ASSERT(!this->output_isopen(OUTPUT_PUNCH)); /* the converse is not necessarily true */ - n_user_punch_index = -1; + this->n_user_punch_index = -1; #endif // SWIG_SHARED_OBJ - tidy_model(); + this->tidy_model(); #ifdef PHREEQC_CPP //test_classes(); #endif @@ -875,69 +523,69 @@ do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int e /* * Calculate distribution of species for initial solutions */ - if (new_solution) initial_solutions(TRUE); + if (this->new_solution) this->initial_solutions(TRUE); /* * Calculate distribution for exchangers */ - if (new_exchange) initial_exchangers(TRUE); + if (this->new_exchange) this->initial_exchangers(TRUE); /* * Calculate distribution for surfaces */ - if (new_surface) initial_surfaces(TRUE); + if (this->new_surface) this->initial_surfaces(TRUE); /* * Calculate initial gas composition */ - if (new_gas_phase) initial_gas_phases(TRUE); + if (this->new_gas_phase) this->initial_gas_phases(TRUE); /* * Calculate reactions */ - reactions(); + this->reactions(); /* * Calculate inverse models */ - inverse_models(); + this->inverse_models(); /* * Calculate advection */ - if (use.advect_in == TRUE) { - dup_print ("Beginning of advection calculations.", TRUE); - advection(); + if (this->use.advect_in == TRUE) { + this->dup_print ("Beginning of advection calculations.", TRUE); + this->advection(); } /* * Calculate transport */ - if (use.trans_in == TRUE) { - dup_print ("Beginning of transport calculations.", TRUE); - transport(); + if (this->use.trans_in == TRUE) { + this->dup_print ("Beginning of transport calculations.", TRUE); + this->transport(); } #ifdef PHREEQC_CPP /* * run */ - run_as_cells(); + this->run_as_cells(); #endif /* * Copy */ - if (new_copy) copy_entities(); + if (this->new_copy) this->copy_entities(); #ifdef PHREEQC_CPP /* * dump */ - dump_entities(); + this->dump_entities(); /* * delete */ - delete_entities(); + this->delete_entities(); #endif /* * End of simulation */ - dup_print( "End of simulation.", TRUE); + this->dup_print( "End of simulation.", TRUE); #ifdef PHREEQ98 } /* if (!phreeq98_debug) */ #endif @@ -946,7 +594,7 @@ do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int e /* * Display successful status */ - do_status(); + this->do_status(); /* * call post-run callback @@ -956,12 +604,951 @@ do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int e pfn_post(cookie); } - if (input_error > 0) + if (this->input_error > 0) { std::ostringstream oss; oss << "\n"; - oss << s_string_input.c_str(); + oss << this->StringInput.c_str(); oss << "\n"; - error_msg(oss.str().c_str(), CONTINUE); + this->error_msg(oss.str().c_str(), CONTINUE); } } + + + +int istream_getc(void *cookie) +{ + if (cookie) + { + std::istream* is = (std::istream*)cookie; + return is->get(); + } + return EOF; +} + +int IPhreeqc::handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +{ + int n = OK; + IPhreeqc *pThis = (IPhreeqc*)cookie; + switch (action) + { + case ACTION_OPEN: + n = pThis->open_handler(type, err_str); + break; + + case ACTION_OUTPUT: + n = pThis->output_handler(type, err_str, stop, cookie, format, args); + break; + + default: + n = pThis->module_handler(action, type, err_str, stop, cookie, format, args); + break; + } + + if (stop == STOP) + { + throw PhreeqcStop(); + } + return n; +} + +int IPhreeqc::output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +{ + IPhreeqc* pIPhreeqc = (IPhreeqc*) cookie; + + switch (type) + { + case OUTPUT_ERROR: + if (pIPhreeqc && pIPhreeqc->ErrorReporter) + { + std::ostringstream oss; + oss << "ERROR: " << err_str << "\n"; + if (stop == STOP) + { + oss << "Stopping.\n"; + } + pIPhreeqc->AddError(oss.str().c_str()); + } + break; + + case OUTPUT_PUNCH: + this->AddSelectedOutput(err_str, format, args); + break; + + } + return module_handler(ACTION_OUTPUT, type, err_str, stop, cookie, format, args); +} + +int IPhreeqc::open_handler(const int type, const char *file_name) +{ + int n = OK; + switch (type) + { + case OUTPUT_PUNCH: + if (file_name) + { + if (this->PunchFileName.compare(file_name) != 0) + { + this->PunchFileName = file_name; + } + } + if (this->SelectedOutputOn) + { + n = module_handler(ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); + } + break; + default: + n = module_handler(ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); + break; + } + return n; +} + +void IPhreeqc::Init(void) +{ + int i; + + moles_per_kilogram_string = 0; + pe_string = 0; + + debug_model = FALSE; + debug_prep = FALSE; + debug_set = FALSE; + debug_diffuse_layer = FALSE; + debug_inverse = FALSE; + itmax = 100; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); +#else + ineq_tol = pow((double) 10, (double) -DBL_DIG); +#endif + convergence_tolerance = 1e-8; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); +#else + inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); +#endif + step_size = 100.; + pe_step_size = 10.; + pp_scale = 1.0; + pp_column_scale = 1.0; + diagonal_scale = FALSE; + censor = 0.0; + mass_water_switch = FALSE; + delay_mass_water = FALSE; + incremental_reactions = FALSE; + aqueous_only = 0; + negative_concentrations = FALSE; + + LOG_10 = log(10.0); + + max_solution = MAX_SOLUTION; + max_pp_assemblage = MAX_PP_ASSEMBLAGE; + max_exchange = MAX_PP_ASSEMBLAGE; + max_surface = MAX_PP_ASSEMBLAGE; + max_gas_phase = MAX_PP_ASSEMBLAGE; + max_kinetics = MAX_PP_ASSEMBLAGE; + max_s_s_assemblage = MAX_PP_ASSEMBLAGE; + + max_elements = MAX_ELEMENTS; + max_elts = MAX_ELTS; + max_line = MAX_LINE; + max_master = MAX_MASTER; + max_mb_unknowns = MAX_TRXN; + max_phases = MAX_PHASES; + max_s = MAX_S; + max_strings = MAX_STRINGS; + max_trxn = MAX_TRXN; + max_logk = MAX_S; + max_master_isotope = MAX_ELTS; + + count_solution = 0; + count_pp_assemblage = 0; + count_exchange = 0; + count_surface = 0; + count_gas_phase = 0; + count_kinetics = 0; + count_s_s_assemblage = 0; + + count_elements = 0; + count_irrev = 0; + count_master = 0; + count_mix = 0; + count_phases = 0; + count_s = 0; + count_temperature = 0; + count_logk = 0; + count_master_isotope = 0; +/* + * Initialize advection + */ + count_ad_cells = 1; + count_ad_shifts = 1; + print_ad_modulus = 1; + punch_ad_modulus = 1; + + advection_punch = 0; + advection_kin_time = 0.0; + advection_kin_time_defined = FALSE; + advection_print = 0; + advection_warnings = TRUE; +/* + * Initialize transport + */ + count_cells = 1; + count_shifts = 1; + ishift = 1; + bcon_first = bcon_last = 3; + diffc = 0.3e-9; + simul_tr = 0; + tempr = 2.0; + heat_diffc = -0.1; + timest = 0.0; + multi_Dflag = FALSE; + interlayer_Dflag = FALSE; + interlayer_tortf = 100.0; + interlayer_Dpor = 0.1; +/* !!!! count_stag = 0; */ + mcd_substeps = 1.0; + print_modulus = 1; + punch_modulus = 1; + dump_modulus = 0; + dump_in = FALSE; + transport_warnings = TRUE; + + pp_assemblage = 0; + exchange = 0; + surface = 0; + gas_phase = 0; + kinetics = 0; + s_s_assemblage = 0; + cell_data = 0; + elements = 0; + elt_list = 0; + + + inverse = 0; + count_inverse = 0; + + irrev = 0; + + line = 0; + line_save = 0; + + master = 0; + + mb_unknowns = 0; + + mix = 0; + count_mix = 0; +/* !!!! */ + stag_data = 0; + + phases = 0; + + trxn.token = 0; + + s = 0; + + logk = 0; + + master_isotope = 0; + + solution = 0; + + temperature = 0; + + title_x = NULL; + pe_x = NULL; + description_x = NULL; + units_x = NULL; + s_x = NULL; + + sum_mb1 = NULL; + sum_mb2 = NULL; + sum_jacob0 = NULL; + sum_jacob1 = NULL; + sum_jacob2 = NULL; + sum_delta = NULL; + + isotopes_x = 0; + + x = NULL; + max_unknowns = 0; + + array = NULL; + delta = NULL; + residual = NULL; + s_h2o = NULL; + s_hplus = NULL; + s_h3oplus = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; + + logk_hash_table = 0; + master_isotope_hash_table = 0; + strings_hash_table = 0; + elements_hash_table = 0; + species_hash_table = 0; + phases_hash_table = 0; + keyword_hash_table = 0; +/* + * Initialize use pointers + */ + use.solution_in = FALSE; + use.pp_assemblage_in = FALSE; + use.mix_in = FALSE; + use.irrev_in = FALSE; +/* + * Initialize punch + */ + punch.in = FALSE; + punch.count_totals = 0; + punch.totals = 0; + punch.count_molalities = 0; + + punch.molalities = 0; + punch.count_activities = 0; + + punch.activities = 0; + punch.count_pure_phases = 0; + + punch.pure_phases = 0; + punch.count_si = 0; + + punch.si = 0; + punch.count_gases = 0; + + punch.gases = 0; + punch.count_s_s = 0; + punch.s_s = 0; + + punch.count_kinetics = 0; + punch.kinetics = 0; + + punch.count_isotopes = 0; + punch.isotopes = 0; + + punch.count_calculate_values = 0; + punch.calculate_values = 0; + + count_save_values = 0; + save_values = 0; + + + punch.inverse = TRUE; + + punch.sim = TRUE; + punch.state = TRUE; + punch.soln = TRUE; + punch.dist = TRUE; + punch.time = TRUE; + punch.step = TRUE; + punch.rxn = FALSE; + punch.temp = FALSE; + punch.ph = TRUE; + punch.pe = TRUE; + punch.alk = FALSE; + punch.mu = FALSE; + punch.water = FALSE; + punch.high_precision = FALSE; + punch.user_punch = TRUE; + punch.charge_balance = FALSE; + punch.percent_error = FALSE; +/* + * last model + */ + last_model.exchange = NULL; + last_model.gas_phase = NULL; + last_model.s_s_assemblage = NULL; + last_model.kinetics = NULL; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + last_model.surface_comp = NULL; + last_model.surface_charge = NULL; +/* + * Update hash table + */ + keyword_hash = 0; +/* + * rates + */ + rates = 0; + count_rates = 0; + initial_total_time = 0; + rate_m = 0; + rate_m0 = 0; + rate_p = NULL; + rate_time = 0; + rate_sim_time_start = 0; + rate_sim_time_end = 0; + rate_sim_time = 0; + rate_moles = 0; + initial_total_time = 0; + +/* + * user_print, user_punch + */ + user_print = 0; + user_punch = 0; + user_punch_headings = 0; + user_punch_count_headings = 0; +#ifdef PHREEQ98 +/* + * user_graph + */ + user_graph = 0; + user_graph_headings = 0 + user_graph_count_headings = 0; +#endif + /* + Initialize llnl aqueous model parameters + */ + llnl_temp = 0; + llnl_count_temp = 0; + + llnl_adh = 0; + llnl_count_adh = 0; + + llnl_bdh = 0; + llnl_count_bdh = 0; + + llnl_bdot = 0; + llnl_count_bdot = 0; + + llnl_co2_coefs = 0; + llnl_count_co2_coefs = 0; +/* + * + */ + command_hash_table = 0; + + change_surf = 0; + change_surf_count = 0; + + +#if defined(WINDOWS) || defined(_WINDOWS) + /* SRC pr.status = FALSE; */ +#endif + /* Initialize print here, not in global.h */ + pr.all = TRUE; + pr.initial_solutions = TRUE; + pr.initial_exchangers = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.s_s_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; + if (phast == TRUE) + { + pr.status = FALSE; + } + else + { + pr.status = TRUE; + } + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; + count_warnings = 0; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; + + species_list = NULL; + + user_database = NULL; + first_read_input = TRUE; + have_punch_name = FALSE; + selected_output_file_name = NULL; + dump_file_name = NULL; + + /* calculate_value */ + max_calculate_value = MAX_ELTS; + count_calculate_value = 0; + + calculate_value = 0; + calculate_value_hash_table = 0; + + /* isotope_ratio */ + max_isotope_ratio = MAX_ELTS; + count_isotope_ratio = 0; + isotope_ratio = 0; + isotope_ratio_hash_table = 0; + + /* isotope_value */ + max_isotope_alpha = MAX_ELTS; + count_isotope_alpha = 0; + isotope_alpha = 0; + isotope_alpha_hash_table = 0; + + phreeqc_mpi_myself = 0; + + copy_solution.n_user = copy_solution.start = copy_solution.end = 0; + copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; + copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; + copy_surface.n_user = copy_surface.start = copy_surface.end = 0; + copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; + copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; + copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; + copy_mix.n_user = copy_mix.start = copy_mix.end = 0; + copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; + copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; + + set_forward_output_to_log(FALSE); + simulation = 0; + /* + * cvode + */ + + cvode_init(); + /* + * Pitzer + */ + pitzer_model = FALSE; + max_pitz_param = 100; + count_pitz_param = 0; + use_etheta = TRUE; + pitz_params = 0; + + max_theta_param = 100; + count_theta_param = 0; + theta_params = 0; + + ICON = TRUE; + OTEMP = 0.0; + for (i = 0; i < 23; i++) + { + BK[i] = 0.0; + DK[i] = 0.0; + } + pitzer_pe = FALSE; + + + /* + * SIT + */ + sit_model = FALSE; + max_sit_param = 100; + count_sit_param = 0; + sit_params = 0; + + /* + * to facilitate debuging + */ + dbg_use = &use; + dbg_solution = solution; + dbg_exchange = exchange; + dbg_surface = surface; + dbg_pp_assemblage = pp_assemblage; + dbg_kinetics = kinetics; + dbg_irrev = irrev; + dbg_mix = mix; + dbg_master = master; + calculating_deriv = FALSE; + numerical_deriv = FALSE; + + zeros = 0; + zeros_max = 1; + + cell_pore_volume = 0; + cell_volume = 0; + cell_porosity = 0; + cell_saturation = 0; + + charge_group = NULL; + print_density = 0; + + return; +} + +void IPhreeqc::AddSelectedOutput(const char* name, const char* format, va_list argptr) +{ + int bInt; + int bDouble; + int bString; + + int state; + int bLongDouble; + char ch; + + + /* state values + 0 Haven't found start(%) + 1 Just read start(%) + 2 Just read Flags(-0+ #) (zero or more) + 3 Just read Width + 4 Just read Precision start (.) + 5 Just read Size modifier + 6 Just read Type + */ + + if (name == NULL) { + return; + } + + bDouble = 0; + bInt = 0; + bString = 0; + + bLongDouble = 0; + + state = 0; + ch = *format++; + while (ch != '\0') + { + switch (state) + { + case 0: /* looking for Start specification (%) */ + switch (ch) + { + case '%': + state = 1; + break; + default: + break; + } + ch = *format++; + break; + case 1: /* reading Flags (zero or more(-,+,0,# or space)) */ + switch (ch) + { + case '-': case '0': case '+': case ' ': case '#': + ch = *format++; + break; + default: + state = 2; + break; + } + break; + case 2: /* reading Minimum field width (decimal integer constant) */ + switch (ch) + { + case '.': + state = 3; + ch = *format++; + break; + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + ch = *format++; + break; + default: + state = 4; + break; + } + break; + case 3: /* reading Precision specification (period already read) */ + switch (ch) + { + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + ch = *format++; + break; + default: + state = 4; + break; + } + break; + case 4: /* reading Size modifier */ + switch (ch) + { + case 'l': + ch = *format++; + break; + case 'L': + bLongDouble = 1; + ch = *format++; + break; + case 'h': + ch = *format++; + break; + } + state = 5; + break; + case 5: /* reading Conversion letter */ + switch (ch) + { + case 'c': + break; + case 'd': + case 'i': + bInt = 1; + break; + case 'n': + case 'o': + case 'p': + break; + case 's': + bString = 1; + break; + case 'u': + case 'x': + case 'X': + case '%': + break; + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + bDouble = 1; + break; + default: + ASSERT(false); + break; + } + ch = '\0'; /* done */ + break; + } + } + + if (bDouble) + { + double valDouble; + + if (bLongDouble) + { + valDouble = (double)va_arg(argptr, long double); + } + else + { + valDouble = va_arg(argptr, double); + } + + this->SelectedOutput->PushBackDouble(name, valDouble); + } + else if (bInt) + { + int valInt; + valInt = va_arg(argptr, int); + + this->SelectedOutput->PushBackLong(name, (long)valInt); + } + else if (bString) + { + char* valString; + valString = (char *)va_arg(argptr, char *); + + this->SelectedOutput->PushBackString(name, valString); + } + else + { + ASSERT(false); + this->SelectedOutput->PushBackEmpty(name); + } +} + +VRESULT IPhreeqc::AccumulateLine(const char *line) +{ + try + { + this->ErrorReporter->Clear(); + this->StringInput.append(line); + this->StringInput.append("\n"); + return VR_OK; + } + catch (...) + { + this->AddError("AccumulateLine: An unhandled exception occured.\n"); + } + return VR_OUTOFMEMORY; +} + +int IPhreeqc::Run(int output_on, int error_on, int log_on, int selected_output_on) +{ + static const char *sz_routine = "Run"; + try + { + // this may throw + this->check_database(sz_routine); + + this->input_error = 0; + + // create input stream + std::istringstream iss(this->GetAccumulatedLines()); + + // this may throw + this->do_run(sz_routine, &iss, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); + } + catch (PhreeqcStop) + { + // do nothing + } + catch(...) + { + const char *errmsg = "Run: An unhandled exception occured.\n"; + try + { + this->error_msg(errmsg, STOP); // throws PhreeqcStop + } + catch (PhreeqcStop) + { + // do nothing + } + } + + this->ClearAccumulatedLines(); + this->close_output_files(); + return this->input_error; +} + +int IPhreeqc::RunFile(const char* filename, int output_on, int error_on, int log_on, int selected_output_on) +{ + static const char *sz_routine = "RunFile"; + try + { + // this may throw + this->check_database(sz_routine); + + this->input_error = 0; + +#if 0 + // create input stream + std::ifstream ifs; + ifs.open(filename); + if (!ifs.is_open()) + { + std::ostringstream oss; + oss << "RunFile: Unable to open:" << "\"" << filename << "\"."; + this->error_msg(oss.str().c_str(), STOP); // throws + } + + // this may throw + this->do_run(sz_routine, &ifs, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); +#else + // open file + // + FILE* f = ::fopen(filename, "r"); + if (!f) + { + std::ostringstream oss; + oss << "RunFile: Unable to open:" << "\"" << filename << "\"."; + this->error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop + } + + // this may throw + this->do_run(sz_routine, NULL, f, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); +#endif + } + catch (PhreeqcStop) + { + // do nothing + } + catch(...) + { + const char *errmsg = "RunFile: An unhandled exception occured.\n"; + try + { + this->error_msg(errmsg, STOP); // throws PhreeqcStop + } + catch (PhreeqcStop) + { + // do nothing + } + } + + this->close_output_files(); + return this->input_error; +} + +int IPhreeqc::RunString(const char* input, int output_on, int error_on, int log_on, int selected_output_on) +{ + static const char *sz_routine = "RunString"; + try + { + // this may throw + this->check_database(sz_routine); + + this->input_error = 0; + + // create input stream + std::string s(input); + std::istringstream iss(s); + + // this may throw + this->do_run(sz_routine, &iss, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); + } + catch (PhreeqcStop) + { + // do nothing + } + catch(...) + { + const char *errmsg = "RunString: An unhandled exception occured.\n"; + try + { + this->error_msg(errmsg, STOP); // throws PhreeqcStop + } + catch (PhreeqcStop) + { + // do nothing + } + } + + this->close_output_files(); + return this->input_error; +} + +int IPhreeqc::GetSelectedOutputRowCount(void)const +{ + return (int)this->SelectedOutput->GetRowCount(); +} + +int IPhreeqc::GetSelectedOutputColumnCount(void)const +{ + return (int)this->SelectedOutput->GetColCount(); +} + +VRESULT IPhreeqc::GetSelectedOutputValue(int row, int col, VAR* pVAR) +{ + this->ErrorReporter->Clear(); + if (!pVAR) + { + this->AddError("GetSelectedOutputValue: VR_INVALIDARG pVar is NULL.\n"); + return VR_INVALIDARG; + } + + VRESULT v = this->SelectedOutput->Get(row, col, pVAR); + switch (v) + { + case VR_OK: + break; + case VR_OUTOFMEMORY: + this->AddError("GetSelectedOutputValue: VR_OUTOFMEMORY Out of memory.\n"); + break; + case VR_BADVARTYPE: + this->AddError("GetSelectedOutputValue: VR_BADVARTYPE pVar must be initialized(VarInit) and/or cleared(VarClear).\n"); + break; + case VR_INVALIDARG: + // not possible + break; + case VR_INVALIDROW: + this->AddError("GetSelectedOutputValue: VR_INVALIDROW Row index out of range.\n"); + break; + case VR_INVALIDCOL: + this->AddError("GetSelectedOutputValue: VR_INVALIDCOL Column index out of range.\n"); + break; + } + return v; +} diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp new file mode 100644 index 00000000..cda13c11 --- /dev/null +++ b/IPhreeqc.hpp @@ -0,0 +1,87 @@ +#ifndef _INC_IPHREEQC_HPP +#define _INC_IPHREEQC_HPP + +#include "Phreeqc.h" /* Phreeqc */ +#include "IPhreeqcCallbacks.h" /* PFN_PRERUN_CALLBACK, PFN_POSTRUN_CALLBACK, PFN_CATCH_CALLBACK */ +#include "Var.h" /* VRESULT */ +#include "SelectedOutput.hxx" + + +class IErrorReporter; + +struct PhreeqcStop{}; + +class IPhreeqc : public Phreeqc +{ +public: + IPhreeqc(void); + ~IPhreeqc(void); + +public: + int LoadDatabase(const char* filename); + int LoadDatabaseString(const char* input); + + void UnLoadDatabase(void); + + void OutputLastError(void); + const char* GetLastErrorString(void); + + VRESULT AccumulateLine(const char *line); + + int Run(int output_on, int error_on, int log_on, int selected_output_on); + int RunFile(const char* filename, int output_on, int error_on, int log_on, int selected_output_on); + int RunString(const char* input, int output_on, int error_on, int log_on, int selected_output_on); + + int GetSelectedOutputRowCount(void)const; + int GetSelectedOutputColumnCount(void)const; + VRESULT GetSelectedOutputValue(int row, int col, VAR* pVAR); + + void OutputLines(void); + + size_t AddError(const char* error_msg); + + const std::string& GetAccumulatedLines(void); + void ClearAccumulatedLines(void); + + // Singleton for library + static IPhreeqc* LibraryInstance(); + + // Callbacks + // + + // IPhreeqc.cpp + static int handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); + int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); + int open_handler(const int type, const char *file_name/*, void *cookie*/); + + // module_files.c + static int module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); + int module_isopen_handler(const int type); + int module_open_handler(const int type, const char *file_name); + + // module_output.c + int output_isopen(const int type); + + virtual int EndRow(void); + void AddSelectedOutput(const char* name, const char* format, va_list argptr); + + void check_database(const char* sz_routine); + void do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int error_on, int log_on, int selected_output_on, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie); + +protected: + void Init(void); + +protected: + // Data + IErrorReporter *ErrorReporter; + CSelectedOutput *SelectedOutput; + std::string PunchFileName; + bool DatabaseLoaded; + bool SelectedOutputOn; + std::string StringInput; + +private: + static IPhreeqc* Instance; +}; + +#endif /* _INC_IPHREEQC_HPP */ diff --git a/PhreeqcParser.hxx b/PhreeqcParser.hxx deleted file mode 100644 index 6984be5c..00000000 --- a/PhreeqcParser.hxx +++ /dev/null @@ -1,35 +0,0 @@ -#if !defined(__PHREEQC_PARSER_HXX_INC) -#define __PHREEQC_PARSER_HXX_INC - - -// COMMENT: {11/10/2004 10:35:56 PM}#include -// COMMENT: {11/10/2004 10:35:56 PM}//#include -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM}struct PhreeqcStop{}; -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM}class CPhreeqcParser -// COMMENT: {11/10/2004 10:35:56 PM}{ -// COMMENT: {11/10/2004 10:35:56 PM}public: -// COMMENT: {11/10/2004 10:35:56 PM} CPhreeqcParser(std::istream& input); -// COMMENT: {11/10/2004 10:35:56 PM} virtual ~CPhreeqcParser(void); -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM} // const char* GetErrorMsg(void); -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM} // overrides -// COMMENT: {11/10/2004 10:35:56 PM} int get_logical_line(int *l); -// COMMENT: {11/10/2004 10:35:56 PM} int get_line(void); -// COMMENT: {11/10/2004 10:35:56 PM} // int error_msg (const char *err_str, const int stop); -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM}protected: -// COMMENT: {11/10/2004 10:35:56 PM} std::istream& m_input_stream; -// COMMENT: {11/10/2004 10:35:56 PM} //std::ostream& m_output_stream; -// COMMENT: {11/10/2004 10:35:56 PM} //std::ostream& m_error_stream; -// COMMENT: {11/10/2004 10:35:56 PM} -// COMMENT: {11/10/2004 10:35:56 PM} //std::string m_errors; -// COMMENT: {11/10/2004 10:35:56 PM}}; - - -#endif // __PHREEQC_PARSER_HXX_INC diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index 966488f8..f4843588 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -5,236 +5,253 @@ #pragma warning(disable : 4786) // disable truncation warning #include // std::ostringstream #include // ::OutputDebugString +#else +#if defined(PHREEQC_CLASS) +#include // ::OutputDebugString +#endif #endif #include #include +#if defined(PHREEQC_CLASS) +#include "phrqtype.h" +#include "p2c.h" +#include "global_structures.h" +#include "basic.h" +#include "Phreeqc.h" + +// COMMENT: {2/24/2010 6:01:56 PM}extern int user_punch_count_headings; +// COMMENT: {2/24/2010 6:01:56 PM}extern char **user_punch_headings; +#endif + #include "SelectedOutput.hxx" #include "phreeqcns.hxx" const size_t RESERVE_ROWS = 80; const size_t RESERVE_COLS = 80; - -int EndRow(void); +// COMMENT: {3/3/2010 5:31:34 PM}int EndRow(void); void AddSelectedOutput(const char* name, const char* format, va_list argptr); int warning_msg (const char *err_str); -int EndRow(void) -{ - if (CSelectedOutput::Instance()->GetRowCount() <= 1) { - // ensure all user_punch headings are included - for (int i = n_user_punch_index; i < user_punch_count_headings; ++i) { - CSelectedOutput::Instance()->PushBackEmpty(user_punch_headings[i]); - } - } - return CSelectedOutput::Instance()->EndRow(); -} +// COMMENT: {3/3/2010 8:55:29 PM}int Phreeqc::EndRow(void) +// COMMENT: {3/3/2010 8:55:29 PM}{ +// COMMENT: {3/3/2010 8:55:29 PM}// COMMENT: {3/3/2010 7:29:42 PM} if (CSelectedOutput::Instance()->GetRowCount() <= 1) +// COMMENT: {3/3/2010 8:55:29 PM} if (this->SelectedOutput.GetRowCount() <= 1) +// COMMENT: {3/3/2010 8:55:29 PM} { +// COMMENT: {3/3/2010 8:55:29 PM} // ensure all user_punch headings are included +// COMMENT: {3/3/2010 8:55:29 PM} for (int i = n_user_punch_index; i < user_punch_count_headings; ++i) +// COMMENT: {3/3/2010 8:55:29 PM} { +// COMMENT: {3/3/2010 8:55:29 PM} CSelectedOutput::Instance()->PushBackEmpty(user_punch_headings[i]); +// COMMENT: {3/3/2010 8:55:29 PM} } +// COMMENT: {3/3/2010 8:55:29 PM} } +// COMMENT: {3/3/2010 8:55:29 PM} return CSelectedOutput::Instance()->EndRow(); +// COMMENT: {3/3/2010 8:55:29 PM}} -int PushBackDouble(const char* key, double dVal) -{ - return CSelectedOutput::Instance()->PushBackDouble(key, dVal); -} - -int PushBackLong(const char* key, long lVal) -{ - return CSelectedOutput::Instance()->PushBackLong(key, lVal); -} - -int PushBackString(const char* key, const char* sVal) -{ - return CSelectedOutput::Instance()->PushBackString(key, sVal); -} - -int PushBackEmpty(const char* key) -{ - return CSelectedOutput::Instance()->PushBackEmpty(key); -} +// COMMENT: {3/3/2010 8:55:40 PM}int PushBackDouble(const char* key, double dVal) +// COMMENT: {3/3/2010 8:55:40 PM}{ +// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackDouble(key, dVal); +// COMMENT: {3/3/2010 8:55:40 PM}} +// COMMENT: {3/3/2010 8:55:40 PM} +// COMMENT: {3/3/2010 8:55:40 PM}int PushBackLong(const char* key, long lVal) +// COMMENT: {3/3/2010 8:55:40 PM}{ +// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackLong(key, lVal); +// COMMENT: {3/3/2010 8:55:40 PM}} +// COMMENT: {3/3/2010 8:55:40 PM} +// COMMENT: {3/3/2010 8:55:40 PM}int PushBackString(const char* key, const char* sVal) +// COMMENT: {3/3/2010 8:55:40 PM}{ +// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackString(key, sVal); +// COMMENT: {3/3/2010 8:55:40 PM}} +// COMMENT: {3/3/2010 8:55:40 PM} +// COMMENT: {3/3/2010 8:55:40 PM}int PushBackEmpty(const char* key) +// COMMENT: {3/3/2010 8:55:40 PM}{ +// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackEmpty(key); +// COMMENT: {3/3/2010 8:55:40 PM}} -void AddSelectedOutput(const char* name, const char* format, va_list argptr) -{ - int bInt; - int bDouble; - int bString; +// COMMENT: {3/3/2010 8:58:25 PM}void AddSelectedOutput(const char* name, const char* format, va_list argptr) +// COMMENT: {3/3/2010 8:58:25 PM}{ +// COMMENT: {3/3/2010 8:58:25 PM} int bInt; +// COMMENT: {3/3/2010 8:58:25 PM} int bDouble; +// COMMENT: {3/3/2010 8:58:25 PM} int bString; +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} int state; +// COMMENT: {3/3/2010 8:58:25 PM} int bLongDouble; +// COMMENT: {3/3/2010 8:58:25 PM} char ch; +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} /* state values +// COMMENT: {3/3/2010 8:58:25 PM} 0 Haven't found start(%) +// COMMENT: {3/3/2010 8:58:25 PM} 1 Just read start(%) +// COMMENT: {3/3/2010 8:58:25 PM} 2 Just read Flags(-0+ #) (zero or more) +// COMMENT: {3/3/2010 8:58:25 PM} 3 Just read Width +// COMMENT: {3/3/2010 8:58:25 PM} 4 Just read Precision start (.) +// COMMENT: {3/3/2010 8:58:25 PM} 5 Just read Size modifier +// COMMENT: {3/3/2010 8:58:25 PM} 6 Just read Type +// COMMENT: {3/3/2010 8:58:25 PM} */ +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} if (name == NULL) { +// COMMENT: {3/3/2010 8:58:25 PM} return; +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} bDouble = 0; +// COMMENT: {3/3/2010 8:58:25 PM} bInt = 0; +// COMMENT: {3/3/2010 8:58:25 PM} bString = 0; +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} bLongDouble = 0; +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} state = 0; +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} while (ch != '\0') { +// COMMENT: {3/3/2010 8:58:25 PM} switch (state) { +// COMMENT: {3/3/2010 8:58:25 PM} case 0: /* looking for Start specification (%) */ +// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) { +// COMMENT: {3/3/2010 8:58:25 PM} case '%': +// COMMENT: {3/3/2010 8:58:25 PM} state = 1; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} default: +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 1: /* reading Flags (zero or more(-,+,0,# or space)) */ +// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) { +// COMMENT: {3/3/2010 8:58:25 PM} case '-': case '0': case '+': case ' ': case '#': +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} default: +// COMMENT: {3/3/2010 8:58:25 PM} state = 2; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 2: /* reading Minimum field width (decimal integer constant) */ +// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) { +// COMMENT: {3/3/2010 8:58:25 PM} case '.': +// COMMENT: {3/3/2010 8:58:25 PM} state = 3; +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} default: +// COMMENT: {3/3/2010 8:58:25 PM} state = 4; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 3: /* reading Precision specification (period already read) */ +// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) +// COMMENT: {3/3/2010 8:58:25 PM} { +// COMMENT: {3/3/2010 8:58:25 PM} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} default: +// COMMENT: {3/3/2010 8:58:25 PM} state = 4; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 4: /* reading Size modifier */ +// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) +// COMMENT: {3/3/2010 8:58:25 PM} { +// COMMENT: {3/3/2010 8:58:25 PM} case 'l': +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 'L': +// COMMENT: {3/3/2010 8:58:25 PM} bLongDouble = 1; +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 'h': +// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} state = 5; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 5: /* reading Conversion letter */ +// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) { +// COMMENT: {3/3/2010 8:58:25 PM} case 'c': +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 'd': +// COMMENT: {3/3/2010 8:58:25 PM} case 'i': +// COMMENT: {3/3/2010 8:58:25 PM} bInt = 1; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 'n': +// COMMENT: {3/3/2010 8:58:25 PM} case 'o': +// COMMENT: {3/3/2010 8:58:25 PM} case 'p': +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 's': +// COMMENT: {3/3/2010 8:58:25 PM} bString = 1; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 'u': +// COMMENT: {3/3/2010 8:58:25 PM} case 'x': +// COMMENT: {3/3/2010 8:58:25 PM} case 'X': +// COMMENT: {3/3/2010 8:58:25 PM} case '%': +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} case 'f': +// COMMENT: {3/3/2010 8:58:25 PM} case 'e': +// COMMENT: {3/3/2010 8:58:25 PM} case 'E': +// COMMENT: {3/3/2010 8:58:25 PM} case 'g': +// COMMENT: {3/3/2010 8:58:25 PM} case 'G': +// COMMENT: {3/3/2010 8:58:25 PM} bDouble = 1; +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} default: +// COMMENT: {3/3/2010 8:58:25 PM} ASSERT(false); +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} ch = '\0'; /* done */ +// COMMENT: {3/3/2010 8:58:25 PM} break; +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} if (bDouble) { +// COMMENT: {3/3/2010 8:58:25 PM} double valDouble; +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} if (bLongDouble) { +// COMMENT: {3/3/2010 8:58:25 PM} valDouble = (double)va_arg(argptr, long double); +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} else { +// COMMENT: {3/3/2010 8:58:25 PM} valDouble = va_arg(argptr, double); +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackDouble(name, valDouble); +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} else if (bInt) { +// COMMENT: {3/3/2010 8:58:25 PM} int valInt; +// COMMENT: {3/3/2010 8:58:25 PM} valInt = va_arg(argptr, int); +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackLong(name, (long)valInt); +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} else if (bString) { +// COMMENT: {3/3/2010 8:58:25 PM} char* valString; +// COMMENT: {3/3/2010 8:58:25 PM} valString = (char *)va_arg(argptr, char *); +// COMMENT: {3/3/2010 8:58:25 PM} +// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackString(name, valString); +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM} else { +// COMMENT: {3/3/2010 8:58:25 PM} ASSERT(false); +// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackEmpty(name); +// COMMENT: {3/3/2010 8:58:25 PM} } +// COMMENT: {3/3/2010 8:58:25 PM}} - int state; - int bLongDouble; - char ch; - - - /* state values - 0 Haven't found start(%) - 1 Just read start(%) - 2 Just read Flags(-0+ #) (zero or more) - 3 Just read Width - 4 Just read Precision start (.) - 5 Just read Size modifier - 6 Just read Type - */ - - if (name == NULL) { - return; - } - - bDouble = 0; - bInt = 0; - bString = 0; - - bLongDouble = 0; - - state = 0; - ch = *format++; - while (ch != '\0') { - switch (state) { - case 0: /* looking for Start specification (%) */ - switch (ch) { - case '%': - state = 1; - break; - default: - break; - } - ch = *format++; - break; - case 1: /* reading Flags (zero or more(-,+,0,# or space)) */ - switch (ch) { - case '-': case '0': case '+': case ' ': case '#': - ch = *format++; - break; - default: - state = 2; - break; - } - break; - case 2: /* reading Minimum field width (decimal integer constant) */ - switch (ch) { - case '.': - state = 3; - ch = *format++; - break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - ch = *format++; - break; - default: - state = 4; - break; - } - break; - case 3: /* reading Precision specification (period already read) */ - switch (ch) - { - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - ch = *format++; - break; - default: - state = 4; - break; - } - break; - case 4: /* reading Size modifier */ - switch (ch) - { - case 'l': - ch = *format++; - break; - case 'L': - bLongDouble = 1; - ch = *format++; - break; - case 'h': - ch = *format++; - break; - } - state = 5; - break; - case 5: /* reading Conversion letter */ - switch (ch) { - case 'c': - break; - case 'd': - case 'i': - bInt = 1; - break; - case 'n': - case 'o': - case 'p': - break; - case 's': - bString = 1; - break; - case 'u': - case 'x': - case 'X': - case '%': - break; - case 'f': - case 'e': - case 'E': - case 'g': - case 'G': - bDouble = 1; - break; - default: - ASSERT(false); - break; - } - ch = '\0'; /* done */ - break; - } - } - - if (bDouble) { - double valDouble; - - if (bLongDouble) { - valDouble = (double)va_arg(argptr, long double); - } - else { - valDouble = va_arg(argptr, double); - } - - CSelectedOutput::Instance()->PushBackDouble(name, valDouble); - } - else if (bInt) { - int valInt; - valInt = va_arg(argptr, int); - - CSelectedOutput::Instance()->PushBackLong(name, (long)valInt); - } - else if (bString) { - char* valString; - valString = (char *)va_arg(argptr, char *); - - CSelectedOutput::Instance()->PushBackString(name, valString); - } - else { - ASSERT(false); - CSelectedOutput::Instance()->PushBackEmpty(name); - } -} - -// COMMENT: {11/16/2004 10:18:22 PM}CSelectedOutput CSelectedOutput::singleton; -CSelectedOutput* CSelectedOutput::s_instance = 0; - -CSelectedOutput* CSelectedOutput::Instance() -{ - if (s_instance == 0) - { - s_instance = new CSelectedOutput; - } - return s_instance; -} - -void CSelectedOutput::Release() -{ - if (s_instance) - { - delete s_instance; - s_instance = 0; - } -} +// COMMENT: {3/3/2010 8:56:03 PM}// COMMENT: {11/16/2004 10:18:22 PM}CSelectedOutput CSelectedOutput::singleton; +// COMMENT: {3/3/2010 8:56:03 PM}CSelectedOutput* CSelectedOutput::s_instance = 0; +// COMMENT: {3/3/2010 8:56:03 PM} +// COMMENT: {3/3/2010 8:56:03 PM}CSelectedOutput* CSelectedOutput::Instance() +// COMMENT: {3/3/2010 8:56:03 PM}{ +// COMMENT: {3/3/2010 8:56:03 PM} if (s_instance == 0) +// COMMENT: {3/3/2010 8:56:03 PM} { +// COMMENT: {3/3/2010 8:56:03 PM} s_instance = new CSelectedOutput; +// COMMENT: {3/3/2010 8:56:03 PM} } +// COMMENT: {3/3/2010 8:56:03 PM} return s_instance; +// COMMENT: {3/3/2010 8:56:03 PM}} +// COMMENT: {3/3/2010 8:56:03 PM} +// COMMENT: {3/3/2010 8:56:03 PM}void CSelectedOutput::Release() +// COMMENT: {3/3/2010 8:56:03 PM}{ +// COMMENT: {3/3/2010 8:56:03 PM} if (s_instance) +// COMMENT: {3/3/2010 8:56:03 PM} { +// COMMENT: {3/3/2010 8:56:03 PM} delete s_instance; +// COMMENT: {3/3/2010 8:56:03 PM} s_instance = 0; +// COMMENT: {3/3/2010 8:56:03 PM} } +// COMMENT: {3/3/2010 8:56:03 PM}} CSelectedOutput::CSelectedOutput() : m_nRowCount(0) diff --git a/SelectedOutput.hxx b/SelectedOutput.hxx index accaf5e6..b5018f7f 100644 --- a/SelectedOutput.hxx +++ b/SelectedOutput.hxx @@ -18,15 +18,10 @@ // TODO: templatize class CSelectedOutput { -protected: - CSelectedOutput(void); public: - static CSelectedOutput* Instance(); - static void Release(); - + CSelectedOutput(void); virtual ~CSelectedOutput(void); - int EndRow(void); void Clear(void); diff --git a/Var.c b/Var.c index 1368ea7d..c3c0ba9f 100644 --- a/Var.c +++ b/Var.c @@ -8,7 +8,9 @@ // void VarInit(VAR* pvar) { - pvar->type = TT_EMPTY; + pvar->type = TT_EMPTY; + pvar->sVal = 0; + pvar->vresult = VR_OK; } VRESULT VarClear(VAR* pvar) diff --git a/fwrap.c b/fwrap.c index 7d152103..847e804b 100644 --- a/fwrap.c +++ b/fwrap.c @@ -4,9 +4,7 @@ #include /* assert */ #include /* printf */ -#define EXTERNAL extern -#include "phreeqcpp/phreeqc/global.h" -#undef EXTERNAL +#include "phrqtype.h" struct buffer { char *name; @@ -35,8 +33,7 @@ extern int store_tally_table(double *array, int row_dim, int col_dim); extern int warning_msg (const char *err_str); extern int zero_tally_table(void); - -#include "../include/IPhreeqc.h" +#include "IPhreeqc.h" /******************************* When using GNU gcc/g++/g77 diff --git a/global.c b/global.c deleted file mode 100644 index 62c87820..00000000 --- a/global.c +++ /dev/null @@ -1,5 +0,0 @@ -#define EXTERNAL -#define MAIN -// TEST RMWEBB WRITE ACCESS -#include "global.h" -#include "phqalloc.h" diff --git a/module_files.c b/module_files.c index f0d2c9f5..3c27973d 100644 --- a/module_files.c +++ b/module_files.c @@ -5,33 +5,35 @@ #include "phreeqcpp/phreeqc/phreeqc_files.c" #endif -static int module_isopen_handler(const int type); -static int module_open_handler(const int type, const char *file_name); +// COMMENT: {3/2/2010 4:06:35 PM}static int module_isopen_handler(const int type); +// COMMENT: {3/2/2010 4:06:35 PM}static int module_open_handler(const int type, const char *file_name); -int -module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +#include "IPhreeqc.hpp" + +int IPhreeqc::module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) { + IPhreeqc* pThis = (IPhreeqc*) cookie; + switch (action) { case ACTION_OPEN: - return module_open_handler(type, err_str); + return pThis->module_open_handler(type, err_str); break; case ACTION_ISOPEN: - return module_isopen_handler(type); + return pThis->module_isopen_handler(type); break; default: - return phreeqc_handler(action, type, err_str, stop, cookie, format, args); + return pThis->phreeqc_handler(action, type, err_str, stop, cookie, format, args); break; } return ERROR; } -static int -module_isopen_handler(const int type) +int IPhreeqc::module_isopen_handler(const int type) { switch (type) { case OUTPUT_PUNCH: - if (punch_file) return 1; + if (this->punch_file) return 1; break; default: assert(0); @@ -39,51 +41,52 @@ module_isopen_handler(const int type) return 0; } -static int -module_open_handler(const int type, const char *file_name) +int IPhreeqc::module_open_handler(const int type, const char *file_name) { - assert(file_name && strlen(file_name)); + assert(file_name && ::strlen(file_name)); switch (type) { case OUTPUT_MESSAGE: - if (output != NULL) + if (this->output != NULL) { - fclose(output); - output = NULL; + ::fclose(this->output); + this->output = NULL; } - if ( (output = fopen(file_name, "w")) == NULL) + if ( (this->output = ::fopen(file_name, "w")) == NULL) { return ERROR; } break; case OUTPUT_ERROR: - assert(error_file != stderr); - if (error_file != NULL) + assert(this->error_file != stderr); + if (this->error_file != NULL) { - fclose(error_file); - error_file = NULL; + ::fclose(this->error_file); + this->error_file = NULL; } - if ( (error_file = fopen(file_name, "w")) == NULL) + if ( (this->error_file = ::fopen(file_name, "w")) == NULL) { return ERROR; } break; case OUTPUT_LOG: - if (log_file != NULL) + if (this->log_file != NULL) { - fclose(log_file); - log_file = NULL; + ::fclose(this->log_file); + this->log_file = NULL; } - if ( (log_file = fopen(file_name, "w")) == NULL) + if ( (this->log_file = ::fopen(file_name, "w")) == NULL) { return ERROR; } break; + default: - return open_handler(type, file_name); + return this->Phreeqc::open_handler(type, file_name); break; + } return(OK); } diff --git a/module_files.h b/module_files.h index c279cb18..35436586 100644 --- a/module_files.h +++ b/module_files.h @@ -9,8 +9,8 @@ extern "C" { #endif -int module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); -int output_isopen(const int type); +// COMMENT: {3/2/2010 4:07:45 PM}int module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); +// COMMENT: {3/2/2010 4:07:45 PM}int output_isopen(const int type); typedef enum { diff --git a/module_output.c b/module_output.c index d4345f5f..51d2fc45 100644 --- a/module_output.c +++ b/module_output.c @@ -1,5 +1,7 @@ #include "module_files.h" +#include "IPhreeqc.hpp" + #if defined(R_SO) #include "output.inl" #else @@ -7,14 +9,13 @@ #endif -/* ---------------------------------------------------------------------- */ -int output_isopen(const int type) -/* ---------------------------------------------------------------------- */ +int IPhreeqc::output_isopen(const int type) { size_t i; int isopen; - for (i = 0; i < count_output_callback; ++i) { - isopen = (output_callbacks[i].callback)(ACTION_ISOPEN, type, NULL, CONTINUE, output_callbacks[i].cookie, NULL, NULL); + for (i = 0; i < this->count_output_callback; ++i) + { + isopen = (this->output_callbacks[i].callback)(ACTION_ISOPEN, type, NULL, CONTINUE, this->output_callbacks[i].cookie, NULL, NULL); if (isopen) return 1; } return 0; diff --git a/phreeqcns.hxx b/phreeqcns.hxx index 5fb7c886..5f059056 100644 --- a/phreeqcns.hxx +++ b/phreeqcns.hxx @@ -11,6 +11,7 @@ #include +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" @@ -21,6 +22,7 @@ EXTERNAL int n_user_punch_index; #undef EXTERNAL +#endif #endif /* _INC_GLOBALNS */ From ab21478cd7c9f556a2317313a3dfc387161e1d04 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 5 Mar 2010 23:27:10 +0000 Subject: [PATCH 02/32] updated windows.h git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4147 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SelectedOutput.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index f4843588..19ff8a51 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -1,14 +1,12 @@ // SelectedOutput.cpp: implementation of the CSelectedOutput class. // ////////////////////////////////////////////////////////////////////// -#if defined(_DEBUG) -#pragma warning(disable : 4786) // disable truncation warning -#include // std::ostringstream -#include // ::OutputDebugString -#else -#if defined(PHREEQC_CLASS) -#include // ::OutputDebugString +#if defined(WIN32) +#include // reqd to avoid namespace problems #endif + +#if defined(_DEBUG) +#include // std::ostringstream #endif #include From 4d34613b6ea85ec59bf078cb15351cb1320e3297 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 5 Mar 2010 23:29:40 +0000 Subject: [PATCH 03/32] added memory header file git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4148 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index 639bfa9d..e3b709e6 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -1,3 +1,4 @@ +#include #include "IPhreeqc.h" #include "IPhreeqc.hpp" #include "ErrorReporter.hxx" From 59e3083acdd66ef5adaaa622bd0c267011d22c2f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 6 Mar 2010 04:55:37 +0000 Subject: [PATCH 04/32] changes reqd to compile on linux git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4150 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- fwrap.c | 2 +- pp_sys.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fwrap.c b/fwrap.c index 847e804b..b4354e38 100644 --- a/fwrap.c +++ b/fwrap.c @@ -73,7 +73,7 @@ f2cstring(char* fstring, int len) } void -padfstring(char *dest, char *src, unsigned int len) +padfstring(char *dest, const char *src, unsigned int len) { unsigned int sofar; diff --git a/pp_sys.c b/pp_sys.c index abc426a8..76197ac4 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -6,7 +6,7 @@ #include /* strlen */ extern char *f2cstring(char* fstring, int len); -extern void padfstring(char *dest, char *src, unsigned int len); +extern void padfstring(char *dest, const char *src, unsigned int len); #define fullpathpp fullpathpp_ #define splitpathpp splitpathpp_ @@ -63,8 +63,8 @@ splitpathpp(char *path, char* drive, char* dir, char* name, char* ext, unsigned int ext_len) { int i; - int dot = 0; - int slash = 0; + size_t dot = 0; + size_t slash = 0; int slash_found = 0; char *cpath = NULL; size_t plen = 0; @@ -72,7 +72,7 @@ splitpathpp(char *path, char* drive, char* dir, char* name, char* ext, /* linux has no drives */ padfstring(drive, "", drive_len); - if (cpath = f2cstring(path, path_len)) { + if ((cpath = f2cstring(path, path_len))) { plen = strlen(cpath); } From 37359f2ec7dd8873d4b3a391c17f99f2684ef0ee Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 12 Mar 2010 04:05:27 +0000 Subject: [PATCH 05/32] checkin to test on linux git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4159 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 101 +++++++++++++++++++++++---- IPhreeqc.hpp | 26 +++++-- fwrap.c | 194 ++++++++++++++++++++++++++++++++++++--------------- fwrap.h | 15 +++- fwrap2.c | 28 ++++++-- fwrap3.c | 28 ++++++-- 6 files changed, 308 insertions(+), 84 deletions(-) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index e3b709e6..a8f17d44 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -46,22 +46,46 @@ AccumulateLine(const char *line) return IPhreeqc::LibraryInstance()->AccumulateLine(line); } -int -Run(int output_on, int error_on, int log_on, int selected_output_on) +void +SetSelectedOutputOn(int value) { - return IPhreeqc::LibraryInstance()->Run(output_on, error_on, log_on, selected_output_on); + return IPhreeqc::LibraryInstance()->SetSelectedOutputOn(value != 0); +} + +void +SetOutputOn(int value) +{ + return IPhreeqc::LibraryInstance()->SetOutputOn(value != 0); +} + +void +SetErrorOn(int value) +{ + return IPhreeqc::LibraryInstance()->SetErrorOn(value != 0); +} + +void +SetLogOn(int value) +{ + return IPhreeqc::LibraryInstance()->SetLogOn(value != 0); } int -RunFile(const char* filename, int output_on, int error_on, int log_on, int selected_output_on) +Run(void) { - return IPhreeqc::LibraryInstance()->RunFile(filename, output_on, error_on, log_on, selected_output_on); + return IPhreeqc::LibraryInstance()->Run(); } int -RunString(const char* input, int output_on, int error_on, int log_on, int selected_output_on) +RunFile(const char* filename) { - return IPhreeqc::LibraryInstance()->RunString(input, output_on, error_on, log_on, selected_output_on); + return IPhreeqc::LibraryInstance()->RunFile(filename); +} + +int +RunString(const char* input) +{ + return IPhreeqc::LibraryInstance()->RunString(input); } int @@ -114,11 +138,16 @@ IPhreeqc::IPhreeqc(void) , SelectedOutput(0) , DatabaseLoaded(false) , SelectedOutputOn(false) +, OutputOn(false) +, LogOn(false) +, ErrorOn(false) +, DumpOn(false) +, DumpStringOn(false) { ASSERT(this->phast == 0); this->ErrorReporter = new CErrorReporter; this->SelectedOutput = new CSelectedOutput(); - this->Init(); + this->init(); this->UnLoadDatabase(); } @@ -622,7 +651,12 @@ int istream_getc(void *cookie) if (cookie) { std::istream* is = (std::istream*)cookie; - return is->get(); + int n = is->get(); + if (n == 13 && is->peek() == 10) + { + n = is->get(); + } + return n; } return EOF; } @@ -705,7 +739,7 @@ int IPhreeqc::open_handler(const int type, const char *file_name) return n; } -void IPhreeqc::Init(void) +void IPhreeqc::init(void) { int i; @@ -1186,6 +1220,31 @@ void IPhreeqc::Init(void) return; } +void IPhreeqc::SetOutputOn(bool bValue) +{ + this->OutputOn = bValue; +} + +void IPhreeqc::SetSelectedOutputOn(bool bValue) +{ + this->SelectedOutputOn = bValue; +} + +void IPhreeqc::SetLogOn(bool bValue) +{ + this->LogOn = bValue; +} + +void IPhreeqc::SetDumpOn(bool bValue) +{ + this->DumpOn = bValue; +} + +void IPhreeqc::SetErrorOn(bool bValue) +{ + this->ErrorOn = bValue; +} + void IPhreeqc::AddSelectedOutput(const char* name, const char* format, va_list argptr) { int bInt; @@ -1376,7 +1435,7 @@ VRESULT IPhreeqc::AccumulateLine(const char *line) return VR_OUTOFMEMORY; } -int IPhreeqc::Run(int output_on, int error_on, int log_on, int selected_output_on) +int IPhreeqc::Run(void) { static const char *sz_routine = "Run"; try @@ -1390,6 +1449,10 @@ int IPhreeqc::Run(int output_on, int error_on, int log_on, int selected_output_o std::istringstream iss(this->GetAccumulatedLines()); // this may throw + int output_on = this->OutputOn ? 1 : 0; + int error_on = this->ErrorOn ? 1 : 0; + int log_on = this->LogOn ? 1 : 0; + int selected_output_on = this->SelectedOutputOn ? 1 : 0; this->do_run(sz_routine, &iss, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); } catch (PhreeqcStop) @@ -1414,7 +1477,7 @@ int IPhreeqc::Run(int output_on, int error_on, int log_on, int selected_output_o return this->input_error; } -int IPhreeqc::RunFile(const char* filename, int output_on, int error_on, int log_on, int selected_output_on) +int IPhreeqc::RunFile(const char* filename) { static const char *sz_routine = "RunFile"; try @@ -1436,6 +1499,10 @@ int IPhreeqc::RunFile(const char* filename, int output_on, int error_on, int log } // this may throw + int output_on = this->OutputOn ? 1 : 0; + int error_on = this->ErrorOn ? 1 : 0; + int log_on = this->LogOn ? 1 : 0; + int selected_output_on = this->SelectedOutputOn ? 1 : 0; this->do_run(sz_routine, &ifs, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); #else // open file @@ -1449,6 +1516,10 @@ int IPhreeqc::RunFile(const char* filename, int output_on, int error_on, int log } // this may throw + int output_on = this->OutputOn ? 1 : 0; + int error_on = this->ErrorOn ? 1 : 0; + int log_on = this->LogOn ? 1 : 0; + int selected_output_on = this->SelectedOutputOn ? 1 : 0; this->do_run(sz_routine, NULL, f, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); #endif } @@ -1473,7 +1544,7 @@ int IPhreeqc::RunFile(const char* filename, int output_on, int error_on, int log return this->input_error; } -int IPhreeqc::RunString(const char* input, int output_on, int error_on, int log_on, int selected_output_on) +int IPhreeqc::RunString(const char* input) { static const char *sz_routine = "RunString"; try @@ -1488,6 +1559,10 @@ int IPhreeqc::RunString(const char* input, int output_on, int error_on, int log_ std::istringstream iss(s); // this may throw + int output_on = this->OutputOn ? 1 : 0; + int error_on = this->ErrorOn ? 1 : 0; + int log_on = this->LogOn ? 1 : 0; + int selected_output_on = this->SelectedOutputOn ? 1 : 0; this->do_run(sz_routine, &iss, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); } catch (PhreeqcStop) diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp index cda13c11..d0baee42 100644 --- a/IPhreeqc.hpp +++ b/IPhreeqc.hpp @@ -28,9 +28,17 @@ public: VRESULT AccumulateLine(const char *line); - int Run(int output_on, int error_on, int log_on, int selected_output_on); - int RunFile(const char* filename, int output_on, int error_on, int log_on, int selected_output_on); - int RunString(const char* input, int output_on, int error_on, int log_on, int selected_output_on); + //{{ + void SetDumpOn(bool bValue); + void SetErrorOn(bool bValue); + void SetLogOn(bool bValue); + void SetOutputOn(bool bValue); + void SetSelectedOutputOn(bool bValue); + //}} + + int Run(void); + int RunFile(const char* filename); + int RunString(const char* input); int GetSelectedOutputRowCount(void)const; int GetSelectedOutputColumnCount(void)const; @@ -69,7 +77,7 @@ public: void do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int error_on, int log_on, int selected_output_on, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie); protected: - void Init(void); + void init(void); protected: // Data @@ -77,9 +85,17 @@ protected: CSelectedOutput *SelectedOutput; std::string PunchFileName; bool DatabaseLoaded; - bool SelectedOutputOn; std::string StringInput; + bool SelectedOutputOn; + //{{ + bool OutputOn; + bool LogOn; + bool ErrorOn; + bool DumpOn; + bool DumpStringOn; + //}} + private: static IPhreeqc* Instance; }; diff --git a/fwrap.c b/fwrap.c index b4354e38..3e9b9531 100644 --- a/fwrap.c +++ b/fwrap.c @@ -2,36 +2,36 @@ #include /* malloc */ #include /* memcpy */ #include /* assert */ -#include /* printf */ +// COMMENT: {3/11/2010 8:14:05 PM}#include /* printf */ #include "phrqtype.h" -struct buffer { - char *name; - struct master *master; - LDBLE moles; - LDBLE gfw; -}; +// COMMENT: {3/11/2010 8:13:47 PM}struct buffer { +// COMMENT: {3/11/2010 8:13:47 PM} char *name; +// COMMENT: {3/11/2010 8:13:47 PM} struct master *master; +// COMMENT: {3/11/2010 8:13:47 PM} LDBLE moles; +// COMMENT: {3/11/2010 8:13:47 PM} LDBLE gfw; +// COMMENT: {3/11/2010 8:13:47 PM}}; -/* - * Routines - */ -extern void add_all_components(void); -extern int build_tally_table(void); -extern int calc_dummy_kinetic_reaction(struct kinetics *kinetics_ptr); -extern int diff_tally_table(void); -extern int elt_list_to_tally_table(struct buffer *buffer_ptr); -extern int entity_exists (char *name, int n_user); -extern int extend_tally_table(void); -extern int free_tally_table(void); -extern int fill_tally_table(int *n_user, int n_buffer); -extern int get_tally_table_rows_columns(int *rows, int *columns); -extern int get_tally_table_column_heading(int column, int *type, char *string); -extern int get_tally_table_row_heading(int column, char *string); -extern int set_reaction_moles(int n_user, LDBLE moles); -extern int store_tally_table(double *array, int row_dim, int col_dim); -extern int warning_msg (const char *err_str); -extern int zero_tally_table(void); +// COMMENT: {3/11/2010 8:13:17 PM}/* +// COMMENT: {3/11/2010 8:13:17 PM} * Routines +// COMMENT: {3/11/2010 8:13:17 PM} */ +// COMMENT: {3/11/2010 8:13:17 PM}extern void add_all_components(void); +// COMMENT: {3/11/2010 8:13:17 PM}extern int build_tally_table(void); +// COMMENT: {3/11/2010 8:13:17 PM}extern int calc_dummy_kinetic_reaction(struct kinetics *kinetics_ptr); +// COMMENT: {3/11/2010 8:13:17 PM}extern int diff_tally_table(void); +// COMMENT: {3/11/2010 8:13:17 PM}extern int elt_list_to_tally_table(struct buffer *buffer_ptr); +// COMMENT: {3/11/2010 8:13:17 PM}extern int entity_exists (char *name, int n_user); +// COMMENT: {3/11/2010 8:13:17 PM}extern int extend_tally_table(void); +// COMMENT: {3/11/2010 8:13:17 PM}extern int free_tally_table(void); +// COMMENT: {3/11/2010 8:13:17 PM}extern int fill_tally_table(int *n_user, int n_buffer); +// COMMENT: {3/11/2010 8:13:17 PM}extern int get_tally_table_rows_columns(int *rows, int *columns); +// COMMENT: {3/11/2010 8:13:17 PM}extern int get_tally_table_column_heading(int column, int *type, char *string); +// COMMENT: {3/11/2010 8:13:17 PM}extern int get_tally_table_row_heading(int column, char *string); +// COMMENT: {3/11/2010 8:13:17 PM}extern int set_reaction_moles(int n_user, LDBLE moles); +// COMMENT: {3/11/2010 8:13:17 PM}extern int store_tally_table(double *array, int row_dim, int col_dim); +// COMMENT: {3/11/2010 8:13:17 PM}extern int warning_msg (const char *err_str); +// COMMENT: {3/11/2010 8:13:17 PM}extern int zero_tally_table(void); #include "IPhreeqc.h" @@ -87,22 +87,38 @@ padfstring(char *dest, const char *src, unsigned int len) int LoadDatabaseF(char* filename, unsigned int filename_length) { - int n; char* cfilename; cfilename = f2cstring(filename, filename_length); - if (!cfilename) { + if (!cfilename) + { AddError("LoadDatabase: Out of memory.\n"); return VR_OUTOFMEMORY; } - n = LoadDatabase(cfilename); - + int n = ::LoadDatabase(cfilename); free(cfilename); - return n; } +int +LoadDatabaseStringF(char* input, unsigned int input_length) +{ + char* cinput; + + cinput = f2cstring(input, input_length); + if (!cinput) + { + AddError("LoadDatabase: Out of memory.\n"); + return VR_OUTOFMEMORY; + } + + int n = ::LoadDatabaseString(cinput); + free(cinput); + return n; +} + + VRESULT AccumulateLineF(char *line, unsigned int line_length) { @@ -110,48 +126,91 @@ AccumulateLineF(char *line, unsigned int line_length) char* cline; cline = f2cstring(line, line_length); - if (!cline) { + if (!cline) + { AddError("AccumulateLine: Out of memory.\n"); return VR_OUTOFMEMORY; } n = AccumulateLine(cline); - free(cline); - return n; } -int -RunF(int* output_on, int* error_on, int* log_on, int* selected_output_on) +void +SetSelectedOutputOnF(int* sel_on) { - return Run(*output_on, *error_on, *log_on, *selected_output_on); + ::SetSelectedOutputOn(*sel_on); +} + +void +SetOutputOnF(int* output_on) +{ + ::SetOutputOn(*output_on); +} + +void +SetErrorOnF(int* error_on) +{ + ::SetErrorOn(*error_on); +} + +void +SetLogOnF(int* log_on) +{ + ::SetLogOn(*log_on); } int -RunFileF(int* output_on, int* error_on, int* log_on, int* selected_output_on, char* filename, unsigned int filename_length) +RunF(void) { - char* cline; + return ::Run(); +} - cline = f2cstring(filename, filename_length); - if (!cline) { +int +RunFileF(char* filename, unsigned int filename_length) +{ + char* cfilename; + + cfilename = f2cstring(filename, filename_length); + if (!cfilename) + { AddError("RunFile: Out of memory.\n"); return (int)VR_OUTOFMEMORY; } - return RunFile(cline, *output_on, *error_on, *log_on, *selected_output_on); + int n = ::RunFile(cfilename); + free(cfilename); + return n; +} + +int +RunStringF(char* input, unsigned int input_length) +{ + char* cinput; + + cinput = f2cstring(input, input_length); + if (!cinput) + { + AddError("RunString: Out of memory.\n"); + return (int)VR_OUTOFMEMORY; + } + + int n = ::RunString(cinput); + free(cinput); + return n; } int GetSelectedOutputRowCountF(void) { - return GetSelectedOutputRowCount(); + return ::GetSelectedOutputRowCount(); } int GetSelectedOutputColumnCountF(void) { - return GetSelectedOutputColumnCount(); + return ::GetSelectedOutputColumnCount(); } VRESULT @@ -160,7 +219,7 @@ GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* sv VRESULT result; VAR v; VarInit(&v); - result = GetSelectedOutputValue(*row, *col, &v); + result = ::GetSelectedOutputValue(*row, *col, &v); switch (v.type) { case TT_EMPTY: @@ -184,20 +243,20 @@ GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* sv default: assert(0); } - VarClear(&v); + ::VarClear(&v); return result; } void OutputLastErrorF(void) { - OutputLastError(); + ::OutputLastError(); } void OutputLinesF(void) { - OutputLines(); + ::OutputLines(); } #if defined(__cplusplus) @@ -207,15 +266,18 @@ extern "C" { int SystemF(char* command, unsigned int command_length) { - char* cline; + char* ccommand; - cline = f2cstring(command, command_length); - if (!cline) { + ccommand = f2cstring(command, command_length); + if (!ccommand) + { AddError("System: Out of memory.\n"); return (int)VR_OUTOFMEMORY; } - return system(cline); + int n = system(ccommand); + free(ccommand); + return n; } #if defined(__cplusplus) @@ -245,13 +307,33 @@ int __stdcall ACCUMULATELINE(char *line, unsigned int len) { return AccumulateLineF(line, len); } -int __stdcall RUN(int *output_on, int *error_on, int *log_on, int *selected_on) +void __stdcall SETSELECTEDOUTPUTON(int *selected_on) { - return RunF(output_on, error_on, log_on, selected_on); + SetSelectedOutputOnF(selected_on); } -int __stdcall RUNFILE(char *filename, unsigned int len, int *output_on, int *error_on, int *log_on, int *selected_on) +void __stdcall SETOUTPUTON(int *output_on) { - return RunFileF(output_on, error_on, log_on, selected_on, filename, len); + SetOutputOnF(output_on); +} +void __stdcall SETERRORON(int *error_on) +{ + SetErrorOnF(error_on); +} +void __stdcall SETLOGON(int *log_on) +{ + SetLogOnF(log_on); +} +int __stdcall RUN(void) +{ + return RunF(); +} +int __stdcall RUNFILE(char *filename, unsigned int len) +{ + return RunFileF(filename, len); +} +int __stdcall RUNSTRING(char *input, unsigned int len) +{ + return RunStringF(input, len); } void __stdcall OUTPUTLINES(void) { diff --git a/fwrap.h b/fwrap.h index b8ad0335..7c147cc2 100644 --- a/fwrap.h +++ b/fwrap.h @@ -11,15 +11,26 @@ extern "C" { VRESULT AccumulateLineF(char *line, unsigned int line_length); - int RunF(int* output_on, int* error_on, int* log_on, int* selected_output_on); + int RunF(void); + + int RunFileF(char* filename, unsigned int filename_length); + + int RunStringF(char* input, unsigned int input_length); - int RunFileF(int* output_on, int* error_on, int* log_on, int* selected_output_on, char* filename, unsigned int filename_length); int GetSelectedOutputRowCountF(void); int GetSelectedOutputColumnCountF(void); VRESULT GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length); + void SetSelectedOutputOnF(int* selected_output_on); + + void SetOutputOnF(int* output_on); + + void SetErrorOnF(int* error_on); + + void SetLogOnF(int* error_on); + void OutputLastErrorF(void); void OutputLinesF(void); diff --git a/fwrap2.c b/fwrap2.c index 5cc2642e..e5dd1205 100644 --- a/fwrap2.c +++ b/fwrap2.c @@ -22,13 +22,33 @@ int ACCUMULATELINE(char *line, unsigned int len) { return AccumulateLineF(line, len); } -int RUN(int *output_on, int *error_on, int *log_on, int *selected_on) +void SETSELECTEDOUTPUTON(int *selected_on) { - return RunF(output_on, error_on, log_on, selected_on); + SetSelectedOutputOnF(selected_on); } -int RUNFILE(char *filename, unsigned int len, int *output_on, int *error_on, int *log_on, int *selected_on) +void SETOUTPUTON(int *output_on) { - return RunFileF(output_on, error_on, log_on, selected_on, filename, len); + SetOutputOnF(output_on); +} +void SETERRORON(int *error_on) +{ + SetErrorOnF(error_on); +} +void SETLOGON(int *log_on) +{ + SetLogOnF(log_on); +} +int RUN(void) +{ + return RunF(); +} +int RUNFILE(char *filename, unsigned int len) +{ + return RunFileF(filename, len); +} +int RUNSTRING(char *input, unsigned int len) +{ + return RunFileF(input, len); } void OUTPUTLINES(void) { diff --git a/fwrap3.c b/fwrap3.c index 8049470a..a8a42e4a 100644 --- a/fwrap3.c +++ b/fwrap3.c @@ -22,13 +22,33 @@ int accumulateline_(char *line, unsigned int len) { return AccumulateLineF(line, len); } -int run_(int *output_on, int *error_on, int *log_on, int *selected_on) +void setselectedoutputon_(int *selected_on) { - return RunF(output_on, error_on, log_on, selected_on); + SetSelectedOutputOnF(selected_on); } -int runfile_(char *filename, unsigned int len, int *output_on, int *error_on, int *log_on, int *selected_on) +void setoutputon_(int *output_on) { - return RunFileF(output_on, error_on, log_on, selected_on, filename, len); + SetOutputOnF(output_on); +} +void seterroron_(int *error_on) +{ + SetErrorOnF(error_on); +} +void setlogon_(int *log_on) +{ + SetLogOnF(log_on); +} +int run_(void) +{ + return RunF(); +} +int runfile_(char *filename, unsigned int len) +{ + return RunFileF(filename, len); +} +int runstring_(char *input, unsigned int len) +{ + return RunFileF(input, len); } void outputlines_(void) { From 4a1f9aa3736f1578722dbad94d8c6fa206cc5656 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 12 Mar 2010 06:15:35 +0000 Subject: [PATCH 06/32] cleaned up fwrap.c git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4162 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- fwrap.c | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/fwrap.c b/fwrap.c index 3e9b9531..8d650c0f 100644 --- a/fwrap.c +++ b/fwrap.c @@ -2,37 +2,7 @@ #include /* malloc */ #include /* memcpy */ #include /* assert */ -// COMMENT: {3/11/2010 8:14:05 PM}#include /* printf */ - #include "phrqtype.h" - -// COMMENT: {3/11/2010 8:13:47 PM}struct buffer { -// COMMENT: {3/11/2010 8:13:47 PM} char *name; -// COMMENT: {3/11/2010 8:13:47 PM} struct master *master; -// COMMENT: {3/11/2010 8:13:47 PM} LDBLE moles; -// COMMENT: {3/11/2010 8:13:47 PM} LDBLE gfw; -// COMMENT: {3/11/2010 8:13:47 PM}}; - -// COMMENT: {3/11/2010 8:13:17 PM}/* -// COMMENT: {3/11/2010 8:13:17 PM} * Routines -// COMMENT: {3/11/2010 8:13:17 PM} */ -// COMMENT: {3/11/2010 8:13:17 PM}extern void add_all_components(void); -// COMMENT: {3/11/2010 8:13:17 PM}extern int build_tally_table(void); -// COMMENT: {3/11/2010 8:13:17 PM}extern int calc_dummy_kinetic_reaction(struct kinetics *kinetics_ptr); -// COMMENT: {3/11/2010 8:13:17 PM}extern int diff_tally_table(void); -// COMMENT: {3/11/2010 8:13:17 PM}extern int elt_list_to_tally_table(struct buffer *buffer_ptr); -// COMMENT: {3/11/2010 8:13:17 PM}extern int entity_exists (char *name, int n_user); -// COMMENT: {3/11/2010 8:13:17 PM}extern int extend_tally_table(void); -// COMMENT: {3/11/2010 8:13:17 PM}extern int free_tally_table(void); -// COMMENT: {3/11/2010 8:13:17 PM}extern int fill_tally_table(int *n_user, int n_buffer); -// COMMENT: {3/11/2010 8:13:17 PM}extern int get_tally_table_rows_columns(int *rows, int *columns); -// COMMENT: {3/11/2010 8:13:17 PM}extern int get_tally_table_column_heading(int column, int *type, char *string); -// COMMENT: {3/11/2010 8:13:17 PM}extern int get_tally_table_row_heading(int column, char *string); -// COMMENT: {3/11/2010 8:13:17 PM}extern int set_reaction_moles(int n_user, LDBLE moles); -// COMMENT: {3/11/2010 8:13:17 PM}extern int store_tally_table(double *array, int row_dim, int col_dim); -// COMMENT: {3/11/2010 8:13:17 PM}extern int warning_msg (const char *err_str); -// COMMENT: {3/11/2010 8:13:17 PM}extern int zero_tally_table(void); - #include "IPhreeqc.h" /******************************* From da893cd778fe132259ff07476c9ff47f3af720c8 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 18 Mar 2010 03:21:45 +0000 Subject: [PATCH 07/32] need to test on linux git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4165 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ErrorReporter.hxx | 1 - IPhreeqc.cpp | 237 +++++++++++++++++++++++++++++++++++++-------- IPhreeqc.hpp | 56 +++++++---- SelectedOutput.cpp | 236 -------------------------------------------- fwrap.c | 60 ++++++++++++ fwrap.h | 14 ++- fwrap2.c | 24 +++++ fwrap3.c | 24 +++++ phreeqcns.hxx | 29 ------ 9 files changed, 357 insertions(+), 324 deletions(-) delete mode 100644 phreeqcns.hxx diff --git a/ErrorReporter.hxx b/ErrorReporter.hxx index e2f554b2..77124f84 100644 --- a/ErrorReporter.hxx +++ b/ErrorReporter.hxx @@ -4,7 +4,6 @@ #include // std::ostream #include // std::fprintf -#include "phreeqcns.hxx" class IErrorReporter { diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index a8f17d44..c2a5ad58 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -40,6 +40,19 @@ GetLastErrorString(void) return IPhreeqc::LibraryInstance()->GetLastErrorString(); } +const char* +GetLastWarningString(void) +{ + return IPhreeqc::LibraryInstance()->GetLastWarningString(); +} + +const char* +GetDumpString(void) +{ + return IPhreeqc::LibraryInstance()->GetDumpString(); +} + + VRESULT AccumulateLine(const char *line) { @@ -70,6 +83,18 @@ SetLogOn(int value) return IPhreeqc::LibraryInstance()->SetLogOn(value != 0); } +void +SetDumpOn(int value) +{ + return IPhreeqc::LibraryInstance()->SetDumpOn(value != 0); +} + +void +SetDumpStringOn(int value) +{ + return IPhreeqc::LibraryInstance()->SetDumpStringOn(value != 0); +} + int Run(void) { @@ -131,10 +156,34 @@ ClearAccumulatedLines(void) IPhreeqc::LibraryInstance()->ClearAccumulatedLines(); } +int +GetDumpLineCount(void) +{ + return IPhreeqc::LibraryInstance()->GetDumpLineCount(); +} + +const char* +GetDumpLine(int n) +{ + return IPhreeqc::LibraryInstance()->GetDumpLine(n); +} + +int +GetErrorLineCount(void) +{ + return IPhreeqc::LibraryInstance()->GetErrorLineCount(); +} + +const char* +GetErrorLine(int n) +{ + return IPhreeqc::LibraryInstance()->GetErrorLine(n); +} IPhreeqc::IPhreeqc(void) : Phreeqc() , ErrorReporter(0) +, WarningReporter(0) , SelectedOutput(0) , DatabaseLoaded(false) , SelectedOutputOn(false) @@ -145,8 +194,9 @@ IPhreeqc::IPhreeqc(void) , DumpStringOn(false) { ASSERT(this->phast == 0); - this->ErrorReporter = new CErrorReporter; - this->SelectedOutput = new CSelectedOutput(); + this->ErrorReporter = new CErrorReporter; + this->WarningReporter = new CErrorReporter; + this->SelectedOutput = new CSelectedOutput(); this->init(); this->UnLoadDatabase(); } @@ -154,6 +204,7 @@ IPhreeqc::IPhreeqc(void) IPhreeqc::~IPhreeqc(void) { delete this->ErrorReporter; + delete this->WarningReporter; delete this->SelectedOutput; } @@ -197,6 +248,11 @@ size_t IPhreeqc::AddError(const char* error_msg) return this->ErrorReporter->AddError(error_msg); } +size_t IPhreeqc::AddWarning(const char* error_msg) +{ + return this->WarningReporter->AddError(error_msg); +} + const std::string& IPhreeqc::GetAccumulatedLines(void) { return this->StringInput; @@ -212,18 +268,29 @@ void IPhreeqc::UnLoadDatabase(void) // init IPhreeqc // this->DatabaseLoaded = false; - this->SelectedOutputOn = false; // clear error state // ASSERT(this->ErrorReporter); this->ErrorReporter->Clear(); + this->LastErrorString.clear(); + + // clear warning state + // + ASSERT(this->WarningReporter); + this->WarningReporter->Clear(); + this->LastWarningString.clear(); // clear selectedoutput // - ASSERT(this->ErrorReporter); + ASSERT(this->SelectedOutput); this->SelectedOutput->Clear(); + // clear dump string + // + this->DumpString.clear(); + this->DumpLines.clear(); + // initialize phreeqc // this->clean_up(); @@ -317,14 +384,25 @@ int IPhreeqc::LoadDatabaseString(const char* input) void IPhreeqc::OutputLastError(void) { - std::cout << ((CErrorReporter*)this->ErrorReporter)->GetOS()->str().c_str() << std::endl; + std::cout << this->GetLastErrorString() << std::endl; } const char* IPhreeqc::GetLastErrorString(void) { - static std::string str; - str = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); - return str.c_str(); + this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); + return this->LastErrorString.c_str(); +} + +const char* IPhreeqc::GetLastWarningString(void) +{ + this->LastWarningString = ((CErrorReporter*)this->WarningReporter)->GetOS()->str(); + return this->LastWarningString.c_str(); +} + + +const char* IPhreeqc::GetDumpString(void) +{ + return this->DumpString.c_str(); } void IPhreeqc::check_database(const char* sz_routine) @@ -341,12 +419,12 @@ void IPhreeqc::check_database(const char* sz_routine) } } -void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int error_on, int log_on, int selected_output_on, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie) +void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie) { std::auto_ptr auto_iss(NULL); char token[MAX_LENGTH]; - if (output_on) + if (this->OutputOn) { if (this->output_open(OUTPUT_MESSAGE, OUTPUT_FILENAME) != OK) { @@ -355,7 +433,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o this->warning_msg(oss.str().c_str()); } } - if (error_on) + if (this->ErrorOn) { if (this->output_open(OUTPUT_ERROR, ERROR_FILENAME) != OK) { @@ -364,7 +442,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o this->warning_msg(oss.str().c_str()); } } - if (log_on) + if (this->LogOn) { if (this->output_open(OUTPUT_LOG, LOG_FILENAME) != OK) { @@ -374,8 +452,6 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o } } - this->SelectedOutputOn = (selected_output_on != 0); - /* * call pre-run callback */ @@ -465,7 +541,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o // TRUE ??? // // - if (!selected_output_on) ASSERT(!this->output_isopen(OUTPUT_PUNCH)); + if (!this->SelectedOutputOn) ASSERT(!this->output_isopen(OUTPUT_PUNCH)); if (this->pr.punch == FALSE) { @@ -479,7 +555,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o { if (this->punch.new_def == FALSE) { - if (selected_output_on && !this->output_isopen(OUTPUT_PUNCH)) + if (this->SelectedOutputOn && !this->output_isopen(OUTPUT_PUNCH)) { // // LoadDatabase @@ -504,7 +580,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o } else { - if (selected_output_on && !this->output_isopen(OUTPUT_PUNCH)) + if (this->SelectedOutputOn && !this->output_isopen(OUTPUT_PUNCH)) { // This is a special case which could not occur in // phreeqc @@ -536,7 +612,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o } } - if (!selected_output_on) ASSERT(!this->output_isopen(OUTPUT_PUNCH)); + if (!this->SelectedOutputOn) ASSERT(!this->output_isopen(OUTPUT_PUNCH)); /* the converse is not necessarily true */ this->n_user_punch_index = -1; @@ -605,7 +681,37 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o /* * dump */ + dumper dump_info_save(dump_info); + if (this->DumpOn) + { this->dump_entities(); + } + if (this->DumpStringOn) + { + dump_info = dump_info_save; + if (dump_info.Get_bool_any()) + { + std::ostringstream oss; + this->dump_ostream(oss); + if (dump_info.get_append()) + { + this->DumpString += oss.str(); + } + else + { + this->DumpString = oss.str(); + } + + /* Fill dump lines */ + this->DumpLines.clear(); + std::istringstream iss(this->DumpString); + std::string line; + while (std::getline(iss, line)) + { + this->DumpLines.push_back(line); + } + } + } /* * delete */ @@ -642,6 +748,9 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, int o oss << "\n"; this->error_msg(oss.str().c_str(), CONTINUE); } + //{{ + this->update_errors(); + //}} } @@ -694,7 +803,7 @@ int IPhreeqc::output_handler(const int type, const char *err_str, const int stop switch (type) { case OUTPUT_ERROR: - if (pIPhreeqc && pIPhreeqc->ErrorReporter) + if (pIPhreeqc) { std::ostringstream oss; oss << "ERROR: " << err_str << "\n"; @@ -706,6 +815,15 @@ int IPhreeqc::output_handler(const int type, const char *err_str, const int stop } break; + case OUTPUT_WARNING: + if (pIPhreeqc) + { + std::ostringstream oss; + oss << "WARNING: " << err_str << "\n"; + pIPhreeqc->AddWarning(oss.str().c_str()); + } + break; + case OUTPUT_PUNCH: this->AddSelectedOutput(err_str, format, args); break; @@ -1240,6 +1358,11 @@ void IPhreeqc::SetDumpOn(bool bValue) this->DumpOn = bValue; } +void IPhreeqc::SetDumpStringOn(bool bValue) +{ + this->DumpStringOn = bValue; +} + void IPhreeqc::SetErrorOn(bool bValue) { this->ErrorOn = bValue; @@ -1424,6 +1547,7 @@ VRESULT IPhreeqc::AccumulateLine(const char *line) try { this->ErrorReporter->Clear(); + this->WarningReporter->Clear(); this->StringInput.append(line); this->StringInput.append("\n"); return VR_OK; @@ -1449,11 +1573,7 @@ int IPhreeqc::Run(void) std::istringstream iss(this->GetAccumulatedLines()); // this may throw - int output_on = this->OutputOn ? 1 : 0; - int error_on = this->ErrorOn ? 1 : 0; - int log_on = this->LogOn ? 1 : 0; - int selected_output_on = this->SelectedOutputOn ? 1 : 0; - this->do_run(sz_routine, &iss, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); + this->do_run(sz_routine, &iss, NULL, NULL, NULL, NULL); } catch (PhreeqcStop) { @@ -1474,6 +1594,8 @@ int IPhreeqc::Run(void) this->ClearAccumulatedLines(); this->close_output_files(); + this->update_errors(); + return this->input_error; } @@ -1499,11 +1621,7 @@ int IPhreeqc::RunFile(const char* filename) } // this may throw - int output_on = this->OutputOn ? 1 : 0; - int error_on = this->ErrorOn ? 1 : 0; - int log_on = this->LogOn ? 1 : 0; - int selected_output_on = this->SelectedOutputOn ? 1 : 0; - this->do_run(sz_routine, &ifs, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); + this->do_run(sz_routine, &ifs, NULL, NULL, NULL, NULL); #else // open file // @@ -1516,11 +1634,7 @@ int IPhreeqc::RunFile(const char* filename) } // this may throw - int output_on = this->OutputOn ? 1 : 0; - int error_on = this->ErrorOn ? 1 : 0; - int log_on = this->LogOn ? 1 : 0; - int selected_output_on = this->SelectedOutputOn ? 1 : 0; - this->do_run(sz_routine, NULL, f, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); + this->do_run(sz_routine, NULL, f, NULL, NULL, NULL); #endif } catch (PhreeqcStop) @@ -1541,6 +1655,8 @@ int IPhreeqc::RunFile(const char* filename) } this->close_output_files(); + this->update_errors(); + return this->input_error; } @@ -1559,11 +1675,7 @@ int IPhreeqc::RunString(const char* input) std::istringstream iss(s); // this may throw - int output_on = this->OutputOn ? 1 : 0; - int error_on = this->ErrorOn ? 1 : 0; - int log_on = this->LogOn ? 1 : 0; - int selected_output_on = this->SelectedOutputOn ? 1 : 0; - this->do_run(sz_routine, &iss, NULL, output_on, error_on, log_on, selected_output_on, NULL, NULL, NULL); + this->do_run(sz_routine, &iss, NULL, NULL, NULL, NULL); } catch (PhreeqcStop) { @@ -1583,6 +1695,8 @@ int IPhreeqc::RunString(const char* input) } this->close_output_files(); + this->update_errors(); + return this->input_error; } @@ -1601,7 +1715,8 @@ VRESULT IPhreeqc::GetSelectedOutputValue(int row, int col, VAR* pVAR) this->ErrorReporter->Clear(); if (!pVAR) { - this->AddError("GetSelectedOutputValue: VR_INVALIDARG pVar is NULL.\n"); + this->AddError("GetSelectedOutputValue: VR_INVALIDARG pVAR is NULL.\n"); + this->update_errors(); return VR_INVALIDARG; } @@ -1626,5 +1741,47 @@ VRESULT IPhreeqc::GetSelectedOutputValue(int row, int col, VAR* pVAR) this->AddError("GetSelectedOutputValue: VR_INVALIDCOL Column index out of range.\n"); break; } + this->update_errors(); return v; } + +int IPhreeqc::GetDumpLineCount(void)const +{ + return (int)this->DumpLines.size(); +} + +const char* IPhreeqc::GetDumpLine(int n) +{ + if (n < 0 || n >= this->GetDumpLineCount()) + { + return 0; + } + return this->DumpLines[n].c_str(); +} + +int IPhreeqc::GetErrorLineCount(void)const +{ + return (int)this->ErrorLines.size(); +} + +const char* IPhreeqc::GetErrorLine(int n) +{ + if (n < 0 || n >= this->GetErrorLineCount()) + { + return 0; + } + return this->ErrorLines[n].c_str(); +} + +void IPhreeqc::update_errors(void) +{ + this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); + + this->ErrorLines.clear(); + std::istringstream iss(this->LastErrorString); + std::string line; + while (std::getline(iss, line)) + { + this->ErrorLines.push_back(line); + } +} diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp index d0baee42..9a69857d 100644 --- a/IPhreeqc.hpp +++ b/IPhreeqc.hpp @@ -24,17 +24,29 @@ public: void UnLoadDatabase(void); void OutputLastError(void); + const char* GetLastErrorString(void); + const char* GetLastWarningString(void); + const char* GetDumpString(void); + + int GetDumpLineCount(void)const; + const char* GetDumpLine(int n); + + int GetErrorLineCount(void)const; + const char* GetErrorLine(int n); VRESULT AccumulateLine(const char *line); - //{{ void SetDumpOn(bool bValue); + void SetDumpStringOn(bool bValue); + void SetErrorOn(bool bValue); + void SetLogOn(bool bValue); + void SetOutputOn(bool bValue); + void SetSelectedOutputOn(bool bValue); - //}} int Run(void); int RunFile(const char* filename); @@ -47,6 +59,7 @@ public: void OutputLines(void); size_t AddError(const char* error_msg); + size_t AddWarning(const char* warning_msg); const std::string& GetAccumulatedLines(void); void ClearAccumulatedLines(void); @@ -74,27 +87,36 @@ public: void AddSelectedOutput(const char* name, const char* format, va_list argptr); void check_database(const char* sz_routine); - void do_run(const char* sz_routine, std::istream* pis, FILE* fp, int output_on, int error_on, int log_on, int selected_output_on, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie); + void do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie); protected: void init(void); + void update_errors(void); protected: - // Data - IErrorReporter *ErrorReporter; - CSelectedOutput *SelectedOutput; - std::string PunchFileName; - bool DatabaseLoaded; - std::string StringInput; - bool SelectedOutputOn; - //{{ - bool OutputOn; - bool LogOn; - bool ErrorOn; - bool DumpOn; - bool DumpStringOn; - //}} + IErrorReporter *ErrorReporter; + std::string LastErrorString; + std::vector< std::string > ErrorLines; + + IErrorReporter *WarningReporter; + std::string LastWarningString; + std::vector< std::string > WarningLines; + + CSelectedOutput *SelectedOutput; + std::string PunchFileName; + bool DatabaseLoaded; + std::string StringInput; + + bool SelectedOutputOn; + bool OutputOn; + bool LogOn; + bool ErrorOn; + bool DumpOn; + bool DumpStringOn; + + std::string DumpString; + std::vector< std::string > DumpLines; private: static IPhreeqc* Instance; diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index 19ff8a51..cba61595 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -12,244 +12,11 @@ #include #include -#if defined(PHREEQC_CLASS) -#include "phrqtype.h" -#include "p2c.h" -#include "global_structures.h" -#include "basic.h" -#include "Phreeqc.h" - -// COMMENT: {2/24/2010 6:01:56 PM}extern int user_punch_count_headings; -// COMMENT: {2/24/2010 6:01:56 PM}extern char **user_punch_headings; -#endif - #include "SelectedOutput.hxx" -#include "phreeqcns.hxx" const size_t RESERVE_ROWS = 80; const size_t RESERVE_COLS = 80; -// COMMENT: {3/3/2010 5:31:34 PM}int EndRow(void); -void AddSelectedOutput(const char* name, const char* format, va_list argptr); -int warning_msg (const char *err_str); - -// COMMENT: {3/3/2010 8:55:29 PM}int Phreeqc::EndRow(void) -// COMMENT: {3/3/2010 8:55:29 PM}{ -// COMMENT: {3/3/2010 8:55:29 PM}// COMMENT: {3/3/2010 7:29:42 PM} if (CSelectedOutput::Instance()->GetRowCount() <= 1) -// COMMENT: {3/3/2010 8:55:29 PM} if (this->SelectedOutput.GetRowCount() <= 1) -// COMMENT: {3/3/2010 8:55:29 PM} { -// COMMENT: {3/3/2010 8:55:29 PM} // ensure all user_punch headings are included -// COMMENT: {3/3/2010 8:55:29 PM} for (int i = n_user_punch_index; i < user_punch_count_headings; ++i) -// COMMENT: {3/3/2010 8:55:29 PM} { -// COMMENT: {3/3/2010 8:55:29 PM} CSelectedOutput::Instance()->PushBackEmpty(user_punch_headings[i]); -// COMMENT: {3/3/2010 8:55:29 PM} } -// COMMENT: {3/3/2010 8:55:29 PM} } -// COMMENT: {3/3/2010 8:55:29 PM} return CSelectedOutput::Instance()->EndRow(); -// COMMENT: {3/3/2010 8:55:29 PM}} - -// COMMENT: {3/3/2010 8:55:40 PM}int PushBackDouble(const char* key, double dVal) -// COMMENT: {3/3/2010 8:55:40 PM}{ -// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackDouble(key, dVal); -// COMMENT: {3/3/2010 8:55:40 PM}} -// COMMENT: {3/3/2010 8:55:40 PM} -// COMMENT: {3/3/2010 8:55:40 PM}int PushBackLong(const char* key, long lVal) -// COMMENT: {3/3/2010 8:55:40 PM}{ -// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackLong(key, lVal); -// COMMENT: {3/3/2010 8:55:40 PM}} -// COMMENT: {3/3/2010 8:55:40 PM} -// COMMENT: {3/3/2010 8:55:40 PM}int PushBackString(const char* key, const char* sVal) -// COMMENT: {3/3/2010 8:55:40 PM}{ -// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackString(key, sVal); -// COMMENT: {3/3/2010 8:55:40 PM}} -// COMMENT: {3/3/2010 8:55:40 PM} -// COMMENT: {3/3/2010 8:55:40 PM}int PushBackEmpty(const char* key) -// COMMENT: {3/3/2010 8:55:40 PM}{ -// COMMENT: {3/3/2010 8:55:40 PM} return CSelectedOutput::Instance()->PushBackEmpty(key); -// COMMENT: {3/3/2010 8:55:40 PM}} - - -// COMMENT: {3/3/2010 8:58:25 PM}void AddSelectedOutput(const char* name, const char* format, va_list argptr) -// COMMENT: {3/3/2010 8:58:25 PM}{ -// COMMENT: {3/3/2010 8:58:25 PM} int bInt; -// COMMENT: {3/3/2010 8:58:25 PM} int bDouble; -// COMMENT: {3/3/2010 8:58:25 PM} int bString; -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} int state; -// COMMENT: {3/3/2010 8:58:25 PM} int bLongDouble; -// COMMENT: {3/3/2010 8:58:25 PM} char ch; -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} /* state values -// COMMENT: {3/3/2010 8:58:25 PM} 0 Haven't found start(%) -// COMMENT: {3/3/2010 8:58:25 PM} 1 Just read start(%) -// COMMENT: {3/3/2010 8:58:25 PM} 2 Just read Flags(-0+ #) (zero or more) -// COMMENT: {3/3/2010 8:58:25 PM} 3 Just read Width -// COMMENT: {3/3/2010 8:58:25 PM} 4 Just read Precision start (.) -// COMMENT: {3/3/2010 8:58:25 PM} 5 Just read Size modifier -// COMMENT: {3/3/2010 8:58:25 PM} 6 Just read Type -// COMMENT: {3/3/2010 8:58:25 PM} */ -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} if (name == NULL) { -// COMMENT: {3/3/2010 8:58:25 PM} return; -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} bDouble = 0; -// COMMENT: {3/3/2010 8:58:25 PM} bInt = 0; -// COMMENT: {3/3/2010 8:58:25 PM} bString = 0; -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} bLongDouble = 0; -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} state = 0; -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} while (ch != '\0') { -// COMMENT: {3/3/2010 8:58:25 PM} switch (state) { -// COMMENT: {3/3/2010 8:58:25 PM} case 0: /* looking for Start specification (%) */ -// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) { -// COMMENT: {3/3/2010 8:58:25 PM} case '%': -// COMMENT: {3/3/2010 8:58:25 PM} state = 1; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} default: -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 1: /* reading Flags (zero or more(-,+,0,# or space)) */ -// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) { -// COMMENT: {3/3/2010 8:58:25 PM} case '-': case '0': case '+': case ' ': case '#': -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} default: -// COMMENT: {3/3/2010 8:58:25 PM} state = 2; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 2: /* reading Minimum field width (decimal integer constant) */ -// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) { -// COMMENT: {3/3/2010 8:58:25 PM} case '.': -// COMMENT: {3/3/2010 8:58:25 PM} state = 3; -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} default: -// COMMENT: {3/3/2010 8:58:25 PM} state = 4; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 3: /* reading Precision specification (period already read) */ -// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) -// COMMENT: {3/3/2010 8:58:25 PM} { -// COMMENT: {3/3/2010 8:58:25 PM} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} default: -// COMMENT: {3/3/2010 8:58:25 PM} state = 4; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 4: /* reading Size modifier */ -// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) -// COMMENT: {3/3/2010 8:58:25 PM} { -// COMMENT: {3/3/2010 8:58:25 PM} case 'l': -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 'L': -// COMMENT: {3/3/2010 8:58:25 PM} bLongDouble = 1; -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 'h': -// COMMENT: {3/3/2010 8:58:25 PM} ch = *format++; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} state = 5; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 5: /* reading Conversion letter */ -// COMMENT: {3/3/2010 8:58:25 PM} switch (ch) { -// COMMENT: {3/3/2010 8:58:25 PM} case 'c': -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 'd': -// COMMENT: {3/3/2010 8:58:25 PM} case 'i': -// COMMENT: {3/3/2010 8:58:25 PM} bInt = 1; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 'n': -// COMMENT: {3/3/2010 8:58:25 PM} case 'o': -// COMMENT: {3/3/2010 8:58:25 PM} case 'p': -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 's': -// COMMENT: {3/3/2010 8:58:25 PM} bString = 1; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 'u': -// COMMENT: {3/3/2010 8:58:25 PM} case 'x': -// COMMENT: {3/3/2010 8:58:25 PM} case 'X': -// COMMENT: {3/3/2010 8:58:25 PM} case '%': -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} case 'f': -// COMMENT: {3/3/2010 8:58:25 PM} case 'e': -// COMMENT: {3/3/2010 8:58:25 PM} case 'E': -// COMMENT: {3/3/2010 8:58:25 PM} case 'g': -// COMMENT: {3/3/2010 8:58:25 PM} case 'G': -// COMMENT: {3/3/2010 8:58:25 PM} bDouble = 1; -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} default: -// COMMENT: {3/3/2010 8:58:25 PM} ASSERT(false); -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} ch = '\0'; /* done */ -// COMMENT: {3/3/2010 8:58:25 PM} break; -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} if (bDouble) { -// COMMENT: {3/3/2010 8:58:25 PM} double valDouble; -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} if (bLongDouble) { -// COMMENT: {3/3/2010 8:58:25 PM} valDouble = (double)va_arg(argptr, long double); -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} else { -// COMMENT: {3/3/2010 8:58:25 PM} valDouble = va_arg(argptr, double); -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackDouble(name, valDouble); -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} else if (bInt) { -// COMMENT: {3/3/2010 8:58:25 PM} int valInt; -// COMMENT: {3/3/2010 8:58:25 PM} valInt = va_arg(argptr, int); -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackLong(name, (long)valInt); -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} else if (bString) { -// COMMENT: {3/3/2010 8:58:25 PM} char* valString; -// COMMENT: {3/3/2010 8:58:25 PM} valString = (char *)va_arg(argptr, char *); -// COMMENT: {3/3/2010 8:58:25 PM} -// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackString(name, valString); -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM} else { -// COMMENT: {3/3/2010 8:58:25 PM} ASSERT(false); -// COMMENT: {3/3/2010 8:58:25 PM} CSelectedOutput::Instance()->PushBackEmpty(name); -// COMMENT: {3/3/2010 8:58:25 PM} } -// COMMENT: {3/3/2010 8:58:25 PM}} - -// COMMENT: {3/3/2010 8:56:03 PM}// COMMENT: {11/16/2004 10:18:22 PM}CSelectedOutput CSelectedOutput::singleton; -// COMMENT: {3/3/2010 8:56:03 PM}CSelectedOutput* CSelectedOutput::s_instance = 0; -// COMMENT: {3/3/2010 8:56:03 PM} -// COMMENT: {3/3/2010 8:56:03 PM}CSelectedOutput* CSelectedOutput::Instance() -// COMMENT: {3/3/2010 8:56:03 PM}{ -// COMMENT: {3/3/2010 8:56:03 PM} if (s_instance == 0) -// COMMENT: {3/3/2010 8:56:03 PM} { -// COMMENT: {3/3/2010 8:56:03 PM} s_instance = new CSelectedOutput; -// COMMENT: {3/3/2010 8:56:03 PM} } -// COMMENT: {3/3/2010 8:56:03 PM} return s_instance; -// COMMENT: {3/3/2010 8:56:03 PM}} -// COMMENT: {3/3/2010 8:56:03 PM} -// COMMENT: {3/3/2010 8:56:03 PM}void CSelectedOutput::Release() -// COMMENT: {3/3/2010 8:56:03 PM}{ -// COMMENT: {3/3/2010 8:56:03 PM} if (s_instance) -// COMMENT: {3/3/2010 8:56:03 PM} { -// COMMENT: {3/3/2010 8:56:03 PM} delete s_instance; -// COMMENT: {3/3/2010 8:56:03 PM} s_instance = 0; -// COMMENT: {3/3/2010 8:56:03 PM} } -// COMMENT: {3/3/2010 8:56:03 PM}} CSelectedOutput::CSelectedOutput() : m_nRowCount(0) @@ -343,9 +110,6 @@ int CSelectedOutput::EndRow(void) } } } -// COMMENT: {11/27/2006 7:22:37 PM}#if defined(_DEBUG) -// COMMENT: {11/27/2006 7:22:37 PM} this->AssertValid(); -// COMMENT: {11/27/2006 7:22:37 PM}#endif return 0; } diff --git a/fwrap.c b/fwrap.c index 8d650c0f..b43a2bb3 100644 --- a/fwrap.c +++ b/fwrap.c @@ -131,6 +131,42 @@ SetLogOnF(int* log_on) ::SetLogOn(*log_on); } +void +SetDumpOnF(int* dump_on) +{ + ::SetDumpOn(*dump_on); +} + +void +SetDumpStringOnF(int* dump_string_on) +{ + ::SetDumpStringOn(*dump_string_on); +} + +int +GetDumpLineCountF(void) +{ + return ::GetDumpLineCount(); +} + +void +GetDumpLineF(int* n, char* line, unsigned int line_length) +{ + padfstring(line, ::GetDumpLine((*n) - 1), line_length); +} + +int +GetErrorLineCountF(void) +{ + return ::GetErrorLineCount(); +} + +void +GetErrorLineF(int* n, char* line, unsigned int line_length) +{ + padfstring(line, ::GetErrorLine((*n) - 1), line_length); +} + int RunF(void) { @@ -293,6 +329,30 @@ void __stdcall SETLOGON(int *log_on) { SetLogOnF(log_on); } +void __stdcall SETDUMPON(int *dump_on) +{ + SetDumpOnF(dump_on); +} +void __stdcall SETDUMPSTRINGON(int *dump_string_on) +{ + SetDumpStringOnF(dump_string_on); +} +int __stdcall GETDUMPLINECOUNT(void) +{ + return GetDumpLineCountF(); +} +void __stdcall GETDUMPLINE(int *n, char* line, unsigned int line_length) +{ + GetDumpLineF(n, line, line_length); +} +int __stdcall GETERRORLINECOUNT(void) +{ + return GetErrorLineCountF(); +} +void __stdcall GETERRORLINE(int *n, char* line, unsigned int line_length) +{ + GetErrorLineF(n, line, line_length); +} int __stdcall RUN(void) { return RunF(); diff --git a/fwrap.h b/fwrap.h index 7c147cc2..c2012765 100644 --- a/fwrap.h +++ b/fwrap.h @@ -29,7 +29,19 @@ extern "C" { void SetErrorOnF(int* error_on); - void SetLogOnF(int* error_on); + void SetLogOnF(int* log_on); + + void SetDumpOnF(int* dump_on); + + void SetDumpStringOnF(int* dump_string_on); + + int GetDumpLineCountF(void); + + void GetDumpLineF(int* n, char* line, unsigned int line_length); + + int GetErrorLineCountF(void); + + void GetErrorLineF(int* n, char* line, unsigned int line_length); void OutputLastErrorF(void); diff --git a/fwrap2.c b/fwrap2.c index e5dd1205..db604a79 100644 --- a/fwrap2.c +++ b/fwrap2.c @@ -38,6 +38,30 @@ void SETLOGON(int *log_on) { SetLogOnF(log_on); } +void SETDUMPON(int *dump_on) +{ + SetDumpOnF(dump_on); +} +void SETDUMPSTRINGON(int *dump_string_on) +{ + SetDumpStringOnF(dump_string_on); +} +int GETDUMPLINECOUNT(void) +{ + return GetDumpLineCountF(); +} +void GETDUMPLINE(int *n, char* line, unsigned int line_length) +{ + GetDumpLineF(n, line, line_length); +} +int GETERRORLINECOUNT(void) +{ + return GetErrorLineCountF(); +} +void GETERRORLINE(int *n, char* line, unsigned int line_length) +{ + GetErrorLineF(n, line, line_length); +} int RUN(void) { return RunF(); diff --git a/fwrap3.c b/fwrap3.c index a8a42e4a..ccb620e1 100644 --- a/fwrap3.c +++ b/fwrap3.c @@ -38,6 +38,30 @@ void setlogon_(int *log_on) { SetLogOnF(log_on); } +void setdumpon_(int *dump_on) +{ + SetLogOnF(dump_on); +} +void setdumpstringon_(int *dump_string_on) +{ + SetDumpStringOnF(dump_string_on); +} +int getdumplinecount_(void) +{ + return GetDumpLineCountF(); +} +void getdumpline_(int *n, char* line, unsigned int line_length) +{ + GetDumpLineF(n, line, line_length); +} +int geterrorlinecount_(void) +{ + return GetErrorLineCountF(); +} +void geterrorline_(int *n, char* line, unsigned int line_length) +{ + GetErrorLineF(n, line, line_length); +} int run_(void) { return RunF(); diff --git a/phreeqcns.hxx b/phreeqcns.hxx deleted file mode 100644 index 5f059056..00000000 --- a/phreeqcns.hxx +++ /dev/null @@ -1,29 +0,0 @@ -// phreeqc namespace -// - -#if !defined(_INC_GLOBALNS) -#define _INC_GLOBALNS - -#if defined(_DEBUG) -#pragma warning(disable : 4786) // disable truncation warning -#endif - -#include - - -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern - -#include "global.h" -#include "phqalloc.h" -#include "input.h" -#include "output.h" -#include "phrqproto.h" -EXTERNAL int n_user_punch_index; - -#undef EXTERNAL -#endif - - -#endif /* _INC_GLOBALNS */ - From 650e24ed1b887d9f65f554ae304bd07d0e1c0e27 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 18 Mar 2010 04:39:55 +0000 Subject: [PATCH 08/32] fixed empty string bugs and added tests git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4168 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index c2a5ad58..c5bfc231 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -1752,9 +1752,10 @@ int IPhreeqc::GetDumpLineCount(void)const const char* IPhreeqc::GetDumpLine(int n) { + static const char empty[] = ""; if (n < 0 || n >= this->GetDumpLineCount()) { - return 0; + return empty; } return this->DumpLines[n].c_str(); } @@ -1766,9 +1767,10 @@ int IPhreeqc::GetErrorLineCount(void)const const char* IPhreeqc::GetErrorLine(int n) { + static const char empty[] = ""; if (n < 0 || n >= this->GetErrorLineCount()) { - return 0; + return empty; } return this->ErrorLines[n].c_str(); } From 714570975e2a9ee4c6e512f5c7230217b2d5fd8c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 18 Mar 2010 23:57:42 +0000 Subject: [PATCH 09/32] moved list_components from class_main.cpp to Phreeqc.cpp git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4173 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 32 ++++++++++++++++++++++++++++++++ IPhreeqc.hpp | 2 ++ 2 files changed, 34 insertions(+) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index c5bfc231..ca5d6c97 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -180,6 +180,32 @@ GetErrorLine(int n) return IPhreeqc::LibraryInstance()->GetErrorLine(n); } +int +GetComponentCount(void) +{ + return (int)IPhreeqc::LibraryInstance()->ListComponents().size(); +} + +const char* +GetComponent(int n) +{ + static const char empty[] = ""; + static std::string comp; + std::list< std::string > comps = IPhreeqc::LibraryInstance()->ListComponents(); + if (n < 0 || n >= (int)comps.size()) + { + return empty; + } + std::list< std::string >::iterator it = comps.begin(); + for(int i = 0; i < n; ++i) + { + ++it; + } + comp = (*it); + return comp.c_str(); +} + + IPhreeqc::IPhreeqc(void) : Phreeqc() , ErrorReporter(0) @@ -1787,3 +1813,9 @@ void IPhreeqc::update_errors(void) this->ErrorLines.push_back(line); } } +std::list< std::string > IPhreeqc::ListComponents(void) +{ + std::list< std::string > comps; + this->list_components(comps); + return comps; +} diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp index 9a69857d..c6f10570 100644 --- a/IPhreeqc.hpp +++ b/IPhreeqc.hpp @@ -35,6 +35,8 @@ public: int GetErrorLineCount(void)const; const char* GetErrorLine(int n); + std::list< std::string > ListComponents(void); + VRESULT AccumulateLine(const char *line); void SetDumpOn(bool bValue); From 507f5dc891a5db8397ebc5ff66e4eec9e7adeec3 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 19 Mar 2010 00:57:37 +0000 Subject: [PATCH 10/32] Added GETCOMPONENTCOUNT and GETCOMPONENT fortran routines git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4174 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- fwrap.c | 20 ++++++++++++++++++++ fwrap.h | 4 ++++ fwrap2.c | 8 ++++++++ fwrap3.c | 8 ++++++++ 4 files changed, 40 insertions(+) diff --git a/fwrap.c b/fwrap.c index b43a2bb3..eb56193b 100644 --- a/fwrap.c +++ b/fwrap.c @@ -167,6 +167,18 @@ GetErrorLineF(int* n, char* line, unsigned int line_length) padfstring(line, ::GetErrorLine((*n) - 1), line_length); } +int +GetComponentCountF(void) +{ + return ::GetComponentCount(); +} + +void +GetComponentF(int *n, char* line, unsigned int line_length) +{ + padfstring(line, ::GetComponent((*n) - 1), line_length); +} + int RunF(void) { @@ -353,6 +365,14 @@ void __stdcall GETERRORLINE(int *n, char* line, unsigned int line_length) { GetErrorLineF(n, line, line_length); } +int __stdcall GETCOMPONENTCOUNT(void) +{ + return GetComponentCountF(); +} +void __stdcall GETCOMPONENT(int *n, char* line, unsigned int line_length) +{ + GetComponentF(n, line, line_length); +} int __stdcall RUN(void) { return RunF(); diff --git a/fwrap.h b/fwrap.h index c2012765..c90682ef 100644 --- a/fwrap.h +++ b/fwrap.h @@ -43,6 +43,10 @@ extern "C" { void GetErrorLineF(int* n, char* line, unsigned int line_length); + int GetComponentCountF(void); + + void GetComponentF(int* n, char* line, unsigned int line_length); + void OutputLastErrorF(void); void OutputLinesF(void); diff --git a/fwrap2.c b/fwrap2.c index db604a79..08fff108 100644 --- a/fwrap2.c +++ b/fwrap2.c @@ -62,6 +62,14 @@ void GETERRORLINE(int *n, char* line, unsigned int line_length) { GetErrorLineF(n, line, line_length); } +int GETCOMPONENTCOUNT(void) +{ + return GetComponentCountF(); +} +void GETCOMPONENT(int *n, char* line, unsigned int line_length) +{ + GetComponentF(n, line, line_length); +} int RUN(void) { return RunF(); diff --git a/fwrap3.c b/fwrap3.c index ccb620e1..8662f432 100644 --- a/fwrap3.c +++ b/fwrap3.c @@ -62,6 +62,14 @@ void geterrorline_(int *n, char* line, unsigned int line_length) { GetErrorLineF(n, line, line_length); } +int getcomponentcount_(void) +{ + return GetComponentCountF(); +} +void getcomponent_(int *n, char* line, unsigned int line_length) +{ + GetComponentF(n, line, line_length); +} int run_(void) { return RunF(); From f7a93a02403f57ef57729c3d50305d37d7127292 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 19 Mar 2010 23:39:37 +0000 Subject: [PATCH 11/32] changed .c extensions to .cpp extensions for the following files: fwrap.c fwrap2.c fwrap3.c module_files.c module_output.c pp_sys.c updated unit test for GetComponent git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4180 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- fwrap.c => fwrap.cpp | 0 fwrap2.c => fwrap2.cpp | 0 fwrap3.c => fwrap3.cpp | 0 module_files.c => module_files.cpp | 0 module_output.c => module_output.cpp | 0 pp_sys.c => pp_sys.cpp | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename fwrap.c => fwrap.cpp (100%) rename fwrap2.c => fwrap2.cpp (100%) rename fwrap3.c => fwrap3.cpp (100%) rename module_files.c => module_files.cpp (100%) rename module_output.c => module_output.cpp (100%) rename pp_sys.c => pp_sys.cpp (100%) diff --git a/fwrap.c b/fwrap.cpp similarity index 100% rename from fwrap.c rename to fwrap.cpp diff --git a/fwrap2.c b/fwrap2.cpp similarity index 100% rename from fwrap2.c rename to fwrap2.cpp diff --git a/fwrap3.c b/fwrap3.cpp similarity index 100% rename from fwrap3.c rename to fwrap3.cpp diff --git a/module_files.c b/module_files.cpp similarity index 100% rename from module_files.c rename to module_files.cpp diff --git a/module_output.c b/module_output.cpp similarity index 100% rename from module_output.c rename to module_output.cpp diff --git a/pp_sys.c b/pp_sys.cpp similarity index 100% rename from pp_sys.c rename to pp_sys.cpp From 761c7de03e177fc10b9c8ababe7d4f88005b3a2a Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 20 Mar 2010 02:50:03 +0000 Subject: [PATCH 12/32] Added getter methods git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4182 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 30 ++++++++++++++++++++++++++++++ IPhreeqc.hpp | 7 +++++++ 2 files changed, 37 insertions(+) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index ca5d6c97..e18a50d6 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -1364,31 +1364,61 @@ void IPhreeqc::init(void) return; } +bool IPhreeqc::GetOutputOn(void)const +{ + return this->OutputOn; +} + void IPhreeqc::SetOutputOn(bool bValue) { this->OutputOn = bValue; } +bool IPhreeqc::GetSelectedOutputOn(void)const +{ + return this->SelectedOutputOn; +} + void IPhreeqc::SetSelectedOutputOn(bool bValue) { this->SelectedOutputOn = bValue; } +bool IPhreeqc::GetLogOn(void)const +{ + return this->LogOn; +} + void IPhreeqc::SetLogOn(bool bValue) { this->LogOn = bValue; } +bool IPhreeqc::GetDumpOn(void)const +{ + return this->DumpOn; +} + void IPhreeqc::SetDumpOn(bool bValue) { this->DumpOn = bValue; } +bool IPhreeqc::GetDumpStringOn(void)const +{ + return this->DumpStringOn; +} + void IPhreeqc::SetDumpStringOn(bool bValue) { this->DumpStringOn = bValue; } +bool IPhreeqc::GetErrorOn(void)const +{ + return this->ErrorOn; +} + void IPhreeqc::SetErrorOn(bool bValue) { this->ErrorOn = bValue; diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp index c6f10570..f0641afd 100644 --- a/IPhreeqc.hpp +++ b/IPhreeqc.hpp @@ -39,15 +39,22 @@ public: VRESULT AccumulateLine(const char *line); + bool GetDumpOn(void)const; void SetDumpOn(bool bValue); + + bool GetDumpStringOn(void)const; void SetDumpStringOn(bool bValue); + bool GetErrorOn(void)const; void SetErrorOn(bool bValue); + bool GetLogOn(void)const; void SetLogOn(bool bValue); + bool GetOutputOn(void)const; void SetOutputOn(bool bValue); + bool GetSelectedOutputOn(void)const; void SetSelectedOutputOn(bool bValue); int Run(void); From 14e17917535604544f1b59b615601fbc97d1a7c1 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 23 Mar 2010 21:05:40 +0000 Subject: [PATCH 13/32] git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4184 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 22 +++++++++++++++------- fwrap.cpp | 21 ++++++++++++++++----- fwrap2.cpp | 5 ++--- fwrap3.cpp | 5 ++--- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index e18a50d6..5ee1c020 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -1,4 +1,5 @@ #include +#include #include "IPhreeqc.h" #include "IPhreeqc.hpp" #include "ErrorReporter.hxx" @@ -824,29 +825,36 @@ int IPhreeqc::handler(const int action, const int type, const char *err_str, con int IPhreeqc::output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) { - IPhreeqc* pIPhreeqc = (IPhreeqc*) cookie; + assert(cookie == this); switch (type) { case OUTPUT_ERROR: - if (pIPhreeqc) + if (this) { - std::ostringstream oss; - oss << "ERROR: " << err_str << "\n"; if (stop == STOP) { + static std::string str(200, ' '); + static std::ostringstream oss(str); + oss << "ERROR: " << err_str << "\n"; oss << "Stopping.\n"; + this->AddError(oss.str().c_str()); + } + else + { + std::ostringstream oss; + oss << "ERROR: " << err_str << "\n"; + this->AddError(oss.str().c_str()); } - pIPhreeqc->AddError(oss.str().c_str()); } break; case OUTPUT_WARNING: - if (pIPhreeqc) + if (this) { std::ostringstream oss; oss << "WARNING: " << err_str << "\n"; - pIPhreeqc->AddWarning(oss.str().c_str()); + this->AddWarning(oss.str().c_str()); } break; diff --git a/fwrap.cpp b/fwrap.cpp index eb56193b..32ba6538 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -222,7 +222,12 @@ RunStringF(char* input, unsigned int input_length) int GetSelectedOutputRowCountF(void) { - return ::GetSelectedOutputRowCount(); + int rows = ::GetSelectedOutputRowCount(); + if (rows > 0) + { + rows -= 1; + } + return rows; } int @@ -237,7 +242,10 @@ GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* sv VRESULT result; VAR v; VarInit(&v); - result = ::GetSelectedOutputValue(*row, *col, &v); + char buffer[100]; + + int adjcol = *col - 1; + result = ::GetSelectedOutputValue(*row, adjcol, &v); switch (v.type) { case TT_EMPTY: @@ -249,10 +257,14 @@ GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* sv case TT_LONG: *vtype = TT_DOUBLE; *dvalue = (double)v.lVal; + ::sprintf(buffer, "%d", v.lVal); + padfstring(svalue, buffer, svalue_length); break; case TT_DOUBLE: *vtype = v.type; *dvalue = v.dVal; + ::sprintf(buffer, "%23.15e", v.dVal); + padfstring(svalue, buffer, svalue_length); break; case TT_STRING: *vtype = v.type; @@ -391,7 +403,7 @@ void __stdcall OUTPUTLINES(void) } int __stdcall GETSELECTEDOUTPUTROWCOUNT(void) { - return GetSelectedOutputRowCountF() - 1; + return GetSelectedOutputRowCountF(); } int __stdcall GETSELECTEDOUTPUTCOLUMNCOUNT(void) { @@ -399,8 +411,7 @@ int __stdcall GETSELECTEDOUTPUTCOLUMNCOUNT(void) } int __stdcall GETSELECTEDOUTPUTVALUE(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) { - int adjcol = *col - 1; - return GetSelectedOutputValueF(row, &adjcol, vtype, dvalue, svalue, svalue_length); + return GetSelectedOutputValueF(row, col, vtype, dvalue, svalue, svalue_length); } #if defined(__cplusplus) } diff --git a/fwrap2.cpp b/fwrap2.cpp index 08fff108..0cd78a14 100644 --- a/fwrap2.cpp +++ b/fwrap2.cpp @@ -88,7 +88,7 @@ void OUTPUTLINES(void) } int GETSELECTEDOUTPUTROWCOUNT(void) { - return GetSelectedOutputRowCountF() - 1; + return GetSelectedOutputRowCountF(); } int GETSELECTEDOUTPUTCOLUMNCOUNT(void) { @@ -96,8 +96,7 @@ int GETSELECTEDOUTPUTCOLUMNCOUNT(void) } int GETSELECTEDOUTPUTVALUE(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) { - int adjcol = *col - 1; - return GetSelectedOutputValueF(row, &adjcol, vtype, dvalue, svalue, svalue_length); + return GetSelectedOutputValueF(row, col, vtype, dvalue, svalue, svalue_length); } #if defined(__cplusplus) diff --git a/fwrap3.cpp b/fwrap3.cpp index 8662f432..252295ad 100644 --- a/fwrap3.cpp +++ b/fwrap3.cpp @@ -88,7 +88,7 @@ void outputlines_(void) } int getselectedoutputrowcount_(void) { - return GetSelectedOutputRowCountF() - 1; + return GetSelectedOutputRowCountF(); } int getselectedoutputcolumncount_(void) { @@ -96,8 +96,7 @@ int getselectedoutputcolumncount_(void) } int getselectedoutputvalue_(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) { - int adjcol = *col - 1; - return GetSelectedOutputValueF(row, &adjcol, vtype, dvalue, svalue, svalue_length); + return GetSelectedOutputValueF(row, col, vtype, dvalue, svalue, svalue_length); } #if defined(__cplusplus) From 5249f4be2a2af5be8c1aed915f3841323e3357fc Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 23 Mar 2010 21:20:51 +0000 Subject: [PATCH 14/32] Reduced risk during low memory conditions of error message handling git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4185 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index 5ee1c020..2e1ac4cc 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -832,19 +832,12 @@ int IPhreeqc::output_handler(const int type, const char *err_str, const int stop case OUTPUT_ERROR: if (this) { + this->AddError("ERROR: "); + this->AddError(err_str); + this->AddError("\n"); if (stop == STOP) { - static std::string str(200, ' '); - static std::ostringstream oss(str); - oss << "ERROR: " << err_str << "\n"; - oss << "Stopping.\n"; - this->AddError(oss.str().c_str()); - } - else - { - std::ostringstream oss; - oss << "ERROR: " << err_str << "\n"; - this->AddError(oss.str().c_str()); + this->AddError("Stopping.\n"); } } break; From 09aa7f357e57499b9ede9ddca2d1f6d5bc471a62 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 23 Mar 2010 22:25:37 +0000 Subject: [PATCH 15/32] renamed Run to RunAccumulated; fixed RunString for fortran wrappers fwrap2 and fwrap3 git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4186 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 10 +++++----- IPhreeqc.hpp | 2 +- fwrap.cpp | 8 ++++---- fwrap.h | 2 +- fwrap2.cpp | 6 +++--- fwrap3.cpp | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index 2e1ac4cc..74a7e154 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -97,9 +97,9 @@ SetDumpStringOn(int value) } int -Run(void) +RunAccumulated(void) { - return IPhreeqc::LibraryInstance()->Run(); + return IPhreeqc::LibraryInstance()->RunAccumulated(); } int @@ -1616,9 +1616,9 @@ VRESULT IPhreeqc::AccumulateLine(const char *line) return VR_OUTOFMEMORY; } -int IPhreeqc::Run(void) +int IPhreeqc::RunAccumulated(void) { - static const char *sz_routine = "Run"; + static const char *sz_routine = "RunAccumulated"; try { // this may throw @@ -1638,7 +1638,7 @@ int IPhreeqc::Run(void) } catch(...) { - const char *errmsg = "Run: An unhandled exception occured.\n"; + const char *errmsg = "RunAccumulated: An unhandled exception occured.\n"; try { this->error_msg(errmsg, STOP); // throws PhreeqcStop diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp index f0641afd..04b53b8b 100644 --- a/IPhreeqc.hpp +++ b/IPhreeqc.hpp @@ -57,7 +57,7 @@ public: bool GetSelectedOutputOn(void)const; void SetSelectedOutputOn(bool bValue); - int Run(void); + int RunAccumulated(void); int RunFile(const char* filename); int RunString(const char* input); diff --git a/fwrap.cpp b/fwrap.cpp index 32ba6538..949ffd53 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -180,9 +180,9 @@ GetComponentF(int *n, char* line, unsigned int line_length) } int -RunF(void) +RunAccumulatedF(void) { - return ::Run(); + return ::RunAccumulated(); } int @@ -385,9 +385,9 @@ void __stdcall GETCOMPONENT(int *n, char* line, unsigned int line_length) { GetComponentF(n, line, line_length); } -int __stdcall RUN(void) +int __stdcall RUNACCUMULATED(void) { - return RunF(); + return RunAccumulatedF(); } int __stdcall RUNFILE(char *filename, unsigned int len) { diff --git a/fwrap.h b/fwrap.h index c90682ef..71b25d58 100644 --- a/fwrap.h +++ b/fwrap.h @@ -11,7 +11,7 @@ extern "C" { VRESULT AccumulateLineF(char *line, unsigned int line_length); - int RunF(void); + int RunAccumulatedF(void); int RunFileF(char* filename, unsigned int filename_length); diff --git a/fwrap2.cpp b/fwrap2.cpp index 0cd78a14..f2c2bc36 100644 --- a/fwrap2.cpp +++ b/fwrap2.cpp @@ -70,9 +70,9 @@ void GETCOMPONENT(int *n, char* line, unsigned int line_length) { GetComponentF(n, line, line_length); } -int RUN(void) +int RUNACCUMULATED(void) { - return RunF(); + return RunAccumulatedF(); } int RUNFILE(char *filename, unsigned int len) { @@ -80,7 +80,7 @@ int RUNFILE(char *filename, unsigned int len) } int RUNSTRING(char *input, unsigned int len) { - return RunFileF(input, len); + return RunStringF(input, len); } void OUTPUTLINES(void) { diff --git a/fwrap3.cpp b/fwrap3.cpp index 252295ad..297fd3c9 100644 --- a/fwrap3.cpp +++ b/fwrap3.cpp @@ -70,9 +70,9 @@ void getcomponent_(int *n, char* line, unsigned int line_length) { GetComponentF(n, line, line_length); } -int run_(void) +int runaccumulated_(void) { - return RunF(); + return RunAccumulatedF(); } int runfile_(char *filename, unsigned int len) { @@ -80,7 +80,7 @@ int runfile_(char *filename, unsigned int len) } int runstring_(char *input, unsigned int len) { - return RunFileF(input, len); + return RunStringF(input, len); } void outputlines_(void) { From 91ccdfab2f4df21f4ae45fff372e447641d77405 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 23 Mar 2010 22:29:50 +0000 Subject: [PATCH 16/32] Working on Create and Destroy methods git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4187 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 30 ++++++++++++++++++++++++++++++ IPhreeqc.hpp | 6 +++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index 74a7e154..3c8fbc92 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -235,6 +235,36 @@ IPhreeqc::~IPhreeqc(void) delete this->SelectedOutput; } +std::map IPhreeqc::Instances; +size_t IPhreeqc::InstancesIndex = 0; + +int +IPhreeqc::Create(void) +{ + int n = (int)IPhreeqc::InstancesIndex; + try + { + IPhreeqc* instance = new IPhreeqc; + if (instance) + { + IPhreeqc::Instances[IPhreeqc::InstancesIndex] = instance; + ++IPhreeqc::InstancesIndex; + } + } + catch(...) + { + return -1; + } + return n; +} + +void +Destroy(int n) +{ + +} + + // the library singleton IPhreeqc* IPhreeqc::Instance = 0; diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp index 04b53b8b..e202550a 100644 --- a/IPhreeqc.hpp +++ b/IPhreeqc.hpp @@ -74,7 +74,9 @@ public: void ClearAccumulatedLines(void); // Singleton for library - static IPhreeqc* LibraryInstance(); + static IPhreeqc* LibraryInstance(void); + static int Create(void); + static void Destroy(int n); // Callbacks // @@ -129,6 +131,8 @@ protected: private: static IPhreeqc* Instance; + static std::map Instances; + static size_t InstancesIndex; }; #endif /* _INC_IPHREEQC_HPP */ From 803eda0a678130028315f0b516a59adad89954bc Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 2 Apr 2010 00:14:16 +0000 Subject: [PATCH 17/32] passes all tests on win32; before changing to multiple instances git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4201 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 1131 +++++++++++++++++++++------------------- IPhreeqc.hpp | 138 ----- IPhreeqc2.cpp | 1257 +++++++++++++++++++++++++++++++++++++++++++++ IPhreeqcLib.cpp | 468 +++++++++++++++++ module_files.cpp | 5 +- module_output.cpp | 2 +- 6 files changed, 2320 insertions(+), 681 deletions(-) delete mode 100644 IPhreeqc.hpp create mode 100644 IPhreeqc2.cpp create mode 100644 IPhreeqcLib.cpp diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index 3c8fbc92..ca33ba43 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -17,6 +17,17 @@ LoadDatabase(const char* filename) return IPhreeqc::LibraryInstance()->LoadDatabase(filename); } +// COMMENT: {3/29/2010 10:18:52 PM}int +// COMMENT: {3/29/2010 10:18:52 PM}LoadDatabaseM(int n, const char* filename) +// COMMENT: {3/29/2010 10:18:52 PM}{ +// COMMENT: {3/29/2010 10:18:52 PM} IPhreeqc* IPhreeqcPtr = IPhreeqc::GetInstance(n); +// COMMENT: {3/29/2010 10:18:52 PM} if (IPhreeqcPtr) +// COMMENT: {3/29/2010 10:18:52 PM} { +// COMMENT: {3/29/2010 10:18:52 PM} return IPhreeqcPtr->LoadDatabase(filename); +// COMMENT: {3/29/2010 10:18:52 PM} } +// COMMENT: {3/29/2010 10:18:52 PM} return PHR_BADINSTANCE; +// COMMENT: {3/29/2010 10:18:52 PM}} + int LoadDatabaseString(const char* input) { @@ -224,7 +235,7 @@ IPhreeqc::IPhreeqc(void) this->ErrorReporter = new CErrorReporter; this->WarningReporter = new CErrorReporter; this->SelectedOutput = new CSelectedOutput(); - this->init(); +// COMMENT: {3/25/2010 2:37:54 PM} this->init(); this->UnLoadDatabase(); } @@ -235,35 +246,61 @@ IPhreeqc::~IPhreeqc(void) delete this->SelectedOutput; } -std::map IPhreeqc::Instances; -size_t IPhreeqc::InstancesIndex = 0; - -int -IPhreeqc::Create(void) -{ - int n = (int)IPhreeqc::InstancesIndex; - try - { - IPhreeqc* instance = new IPhreeqc; - if (instance) - { - IPhreeqc::Instances[IPhreeqc::InstancesIndex] = instance; - ++IPhreeqc::InstancesIndex; - } - } - catch(...) - { - return -1; - } - return n; -} - -void -Destroy(int n) -{ - -} - +// COMMENT: {4/1/2010 5:52:55 PM}std::map IPhreeqc::Instances; +// COMMENT: {4/1/2010 5:52:55 PM}size_t IPhreeqc::InstancesIndex = 0; +// COMMENT: {4/1/2010 5:52:55 PM} +// COMMENT: {4/1/2010 5:52:55 PM}int +// COMMENT: {4/1/2010 5:52:55 PM}IPhreeqc::CreateIPhreeqc(void) +// COMMENT: {4/1/2010 5:52:55 PM}{ +// COMMENT: {4/1/2010 5:52:55 PM} int n = -1; +// COMMENT: {4/1/2010 5:52:55 PM} try +// COMMENT: {4/1/2010 5:52:55 PM} { +// COMMENT: {4/1/2010 5:52:55 PM} IPhreeqc* IPhreeqcPtr = new IPhreeqc; +// COMMENT: {4/1/2010 5:52:55 PM} if (IPhreeqcPtr) +// COMMENT: {4/1/2010 5:52:55 PM} { +// COMMENT: {4/1/2010 5:52:55 PM} std::map::value_type instance(IPhreeqc::InstancesIndex, IPhreeqcPtr); +// COMMENT: {4/1/2010 5:52:55 PM} std::pair::iterator, bool> pr = IPhreeqc::Instances.insert(instance); +// COMMENT: {4/1/2010 5:52:55 PM} if (pr.second) +// COMMENT: {4/1/2010 5:52:55 PM} { +// COMMENT: {4/1/2010 5:52:55 PM} n = (int) (*pr.first).first; +// COMMENT: {4/1/2010 5:52:55 PM} ++IPhreeqc::InstancesIndex; +// COMMENT: {4/1/2010 5:52:55 PM} } +// COMMENT: {4/1/2010 5:52:55 PM} } +// COMMENT: {4/1/2010 5:52:55 PM} } +// COMMENT: {4/1/2010 5:52:55 PM} catch(...) +// COMMENT: {4/1/2010 5:52:55 PM} { +// COMMENT: {4/1/2010 5:52:55 PM} return -1; +// COMMENT: {4/1/2010 5:52:55 PM} } +// COMMENT: {4/1/2010 5:52:55 PM} return n; +// COMMENT: {4/1/2010 5:52:55 PM}} +// COMMENT: {4/1/2010 5:52:55 PM} +// COMMENT: {4/1/2010 5:52:55 PM}int +// COMMENT: {4/1/2010 5:52:55 PM}IPhreeqc::DestroyIPhreeqc(int n) +// COMMENT: {4/1/2010 5:52:55 PM}{ +// COMMENT: {4/1/2010 5:52:55 PM} int retval = PHR_BADINSTANCE; +// COMMENT: {4/1/2010 5:52:55 PM} if (n >= 0) +// COMMENT: {4/1/2010 5:52:55 PM} { +// COMMENT: {4/1/2010 5:52:55 PM} std::map::iterator it = IPhreeqc::Instances.find(size_t(n)); +// COMMENT: {4/1/2010 5:52:55 PM} if (it != IPhreeqc::Instances.end()) +// COMMENT: {4/1/2010 5:52:55 PM} { +// COMMENT: {4/1/2010 5:52:55 PM} delete (*it).second; +// COMMENT: {4/1/2010 5:52:55 PM} IPhreeqc::Instances.erase(it); +// COMMENT: {4/1/2010 5:52:55 PM} retval = 0; +// COMMENT: {4/1/2010 5:52:55 PM} } +// COMMENT: {4/1/2010 5:52:55 PM} } +// COMMENT: {4/1/2010 5:52:55 PM} return retval; +// COMMENT: {4/1/2010 5:52:55 PM}} +// COMMENT: {4/1/2010 5:52:55 PM} +// COMMENT: {4/1/2010 5:52:55 PM}IPhreeqc* +// COMMENT: {4/1/2010 5:52:55 PM}IPhreeqc::GetInstance(int n) +// COMMENT: {4/1/2010 5:52:55 PM}{ +// COMMENT: {4/1/2010 5:52:55 PM} std::map::iterator it = IPhreeqc::Instances.find(size_t(n)); +// COMMENT: {4/1/2010 5:52:55 PM} if (it != IPhreeqc::Instances.end()) +// COMMENT: {4/1/2010 5:52:55 PM} { +// COMMENT: {4/1/2010 5:52:55 PM} return (*it).second; +// COMMENT: {4/1/2010 5:52:55 PM} } +// COMMENT: {4/1/2010 5:52:55 PM} return 0; +// COMMENT: {4/1/2010 5:52:55 PM}} // the library singleton IPhreeqc* IPhreeqc::Instance = 0; @@ -367,22 +404,25 @@ int IPhreeqc::LoadDatabase(const char* filename) // open file // - FILE* f = fopen(filename, "r"); - if (!f) + std::ifstream ifs; + ifs.open(filename); + + if (!ifs.is_open()) { std::ostringstream oss; oss << "LoadDatabase: Unable to open:" << "\"" << filename << "\"."; - this->error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop + this->error_msg(oss.str().c_str(), STOP); // throws } // read input // - this->read_database(getc_callback, f); - + this->read_database(istream_getc, &ifs); } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } catch (...) { @@ -393,10 +433,17 @@ int IPhreeqc::LoadDatabase(const char* filename) } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } } +#if defined(_WIN32) + int n = ::_fcloseall(); + assert(n == 0); +#endif + this->DatabaseLoaded = (this->input_error == 0); return this->input_error; } @@ -420,7 +467,9 @@ int IPhreeqc::LoadDatabaseString(const char* input) } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } catch(...) { @@ -431,7 +480,9 @@ int IPhreeqc::LoadDatabaseString(const char* input) } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } } @@ -914,486 +965,486 @@ int IPhreeqc::open_handler(const int type, const char *file_name) return n; } -void IPhreeqc::init(void) -{ - int i; - - moles_per_kilogram_string = 0; - pe_string = 0; - - debug_model = FALSE; - debug_prep = FALSE; - debug_set = FALSE; - debug_diffuse_layer = FALSE; - debug_inverse = FALSE; - itmax = 100; -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); -#else - ineq_tol = pow((double) 10, (double) -DBL_DIG); -#endif - convergence_tolerance = 1e-8; -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); -#else - inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); -#endif - step_size = 100.; - pe_step_size = 10.; - pp_scale = 1.0; - pp_column_scale = 1.0; - diagonal_scale = FALSE; - censor = 0.0; - mass_water_switch = FALSE; - delay_mass_water = FALSE; - incremental_reactions = FALSE; - aqueous_only = 0; - negative_concentrations = FALSE; - - LOG_10 = log(10.0); - - max_solution = MAX_SOLUTION; - max_pp_assemblage = MAX_PP_ASSEMBLAGE; - max_exchange = MAX_PP_ASSEMBLAGE; - max_surface = MAX_PP_ASSEMBLAGE; - max_gas_phase = MAX_PP_ASSEMBLAGE; - max_kinetics = MAX_PP_ASSEMBLAGE; - max_s_s_assemblage = MAX_PP_ASSEMBLAGE; - - max_elements = MAX_ELEMENTS; - max_elts = MAX_ELTS; - max_line = MAX_LINE; - max_master = MAX_MASTER; - max_mb_unknowns = MAX_TRXN; - max_phases = MAX_PHASES; - max_s = MAX_S; - max_strings = MAX_STRINGS; - max_trxn = MAX_TRXN; - max_logk = MAX_S; - max_master_isotope = MAX_ELTS; - - count_solution = 0; - count_pp_assemblage = 0; - count_exchange = 0; - count_surface = 0; - count_gas_phase = 0; - count_kinetics = 0; - count_s_s_assemblage = 0; - - count_elements = 0; - count_irrev = 0; - count_master = 0; - count_mix = 0; - count_phases = 0; - count_s = 0; - count_temperature = 0; - count_logk = 0; - count_master_isotope = 0; -/* - * Initialize advection - */ - count_ad_cells = 1; - count_ad_shifts = 1; - print_ad_modulus = 1; - punch_ad_modulus = 1; - - advection_punch = 0; - advection_kin_time = 0.0; - advection_kin_time_defined = FALSE; - advection_print = 0; - advection_warnings = TRUE; -/* - * Initialize transport - */ - count_cells = 1; - count_shifts = 1; - ishift = 1; - bcon_first = bcon_last = 3; - diffc = 0.3e-9; - simul_tr = 0; - tempr = 2.0; - heat_diffc = -0.1; - timest = 0.0; - multi_Dflag = FALSE; - interlayer_Dflag = FALSE; - interlayer_tortf = 100.0; - interlayer_Dpor = 0.1; -/* !!!! count_stag = 0; */ - mcd_substeps = 1.0; - print_modulus = 1; - punch_modulus = 1; - dump_modulus = 0; - dump_in = FALSE; - transport_warnings = TRUE; - - pp_assemblage = 0; - exchange = 0; - surface = 0; - gas_phase = 0; - kinetics = 0; - s_s_assemblage = 0; - cell_data = 0; - elements = 0; - elt_list = 0; - - - inverse = 0; - count_inverse = 0; - - irrev = 0; - - line = 0; - line_save = 0; - - master = 0; - - mb_unknowns = 0; - - mix = 0; - count_mix = 0; -/* !!!! */ - stag_data = 0; - - phases = 0; - - trxn.token = 0; - - s = 0; - - logk = 0; - - master_isotope = 0; - - solution = 0; - - temperature = 0; - - title_x = NULL; - pe_x = NULL; - description_x = NULL; - units_x = NULL; - s_x = NULL; - - sum_mb1 = NULL; - sum_mb2 = NULL; - sum_jacob0 = NULL; - sum_jacob1 = NULL; - sum_jacob2 = NULL; - sum_delta = NULL; - - isotopes_x = 0; - - x = NULL; - max_unknowns = 0; - - array = NULL; - delta = NULL; - residual = NULL; - s_h2o = NULL; - s_hplus = NULL; - s_h3oplus = NULL; - s_eminus = NULL; - s_co3 = NULL; - s_h2 = NULL; - s_o2 = NULL; - - logk_hash_table = 0; - master_isotope_hash_table = 0; - strings_hash_table = 0; - elements_hash_table = 0; - species_hash_table = 0; - phases_hash_table = 0; - keyword_hash_table = 0; -/* - * Initialize use pointers - */ - use.solution_in = FALSE; - use.pp_assemblage_in = FALSE; - use.mix_in = FALSE; - use.irrev_in = FALSE; -/* - * Initialize punch - */ - punch.in = FALSE; - punch.count_totals = 0; - punch.totals = 0; - punch.count_molalities = 0; - - punch.molalities = 0; - punch.count_activities = 0; - - punch.activities = 0; - punch.count_pure_phases = 0; - - punch.pure_phases = 0; - punch.count_si = 0; - - punch.si = 0; - punch.count_gases = 0; - - punch.gases = 0; - punch.count_s_s = 0; - punch.s_s = 0; - - punch.count_kinetics = 0; - punch.kinetics = 0; - - punch.count_isotopes = 0; - punch.isotopes = 0; - - punch.count_calculate_values = 0; - punch.calculate_values = 0; - - count_save_values = 0; - save_values = 0; - - - punch.inverse = TRUE; - - punch.sim = TRUE; - punch.state = TRUE; - punch.soln = TRUE; - punch.dist = TRUE; - punch.time = TRUE; - punch.step = TRUE; - punch.rxn = FALSE; - punch.temp = FALSE; - punch.ph = TRUE; - punch.pe = TRUE; - punch.alk = FALSE; - punch.mu = FALSE; - punch.water = FALSE; - punch.high_precision = FALSE; - punch.user_punch = TRUE; - punch.charge_balance = FALSE; - punch.percent_error = FALSE; -/* - * last model - */ - last_model.exchange = NULL; - last_model.gas_phase = NULL; - last_model.s_s_assemblage = NULL; - last_model.kinetics = NULL; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - last_model.surface_comp = NULL; - last_model.surface_charge = NULL; -/* - * Update hash table - */ - keyword_hash = 0; -/* - * rates - */ - rates = 0; - count_rates = 0; - initial_total_time = 0; - rate_m = 0; - rate_m0 = 0; - rate_p = NULL; - rate_time = 0; - rate_sim_time_start = 0; - rate_sim_time_end = 0; - rate_sim_time = 0; - rate_moles = 0; - initial_total_time = 0; - -/* - * user_print, user_punch - */ - user_print = 0; - user_punch = 0; - user_punch_headings = 0; - user_punch_count_headings = 0; -#ifdef PHREEQ98 -/* - * user_graph - */ - user_graph = 0; - user_graph_headings = 0 - user_graph_count_headings = 0; -#endif - /* - Initialize llnl aqueous model parameters - */ - llnl_temp = 0; - llnl_count_temp = 0; - - llnl_adh = 0; - llnl_count_adh = 0; - - llnl_bdh = 0; - llnl_count_bdh = 0; - - llnl_bdot = 0; - llnl_count_bdot = 0; - - llnl_co2_coefs = 0; - llnl_count_co2_coefs = 0; -/* - * - */ - command_hash_table = 0; - - change_surf = 0; - change_surf_count = 0; - - -#if defined(WINDOWS) || defined(_WINDOWS) - /* SRC pr.status = FALSE; */ -#endif - /* Initialize print here, not in global.h */ - pr.all = TRUE; - pr.initial_solutions = TRUE; - pr.initial_exchangers = TRUE; - pr.reactions = TRUE; - pr.gas_phase = TRUE; - pr.s_s_assemblage = TRUE; - pr.pp_assemblage = TRUE; - pr.surface = TRUE; - pr.exchange = TRUE; - pr.kinetics = TRUE; - pr.totals = TRUE; - pr.eh = TRUE; - pr.species = TRUE; - pr.saturation_indices = TRUE; - pr.irrev = TRUE; - pr.mix = TRUE; - pr.reaction = TRUE; - pr.use = TRUE; - pr.logfile = FALSE; - pr.punch = TRUE; - if (phast == TRUE) - { - pr.status = FALSE; - } - else - { - pr.status = TRUE; - } - pr.inverse = TRUE; - pr.dump = TRUE; - pr.user_print = TRUE; - pr.headings = TRUE; - pr.user_graph = TRUE; - pr.echo_input = TRUE; - count_warnings = 0; - pr.warnings = 100; - pr.initial_isotopes = TRUE; - pr.isotope_ratios = TRUE; - pr.isotope_alphas = TRUE; - pr.hdf = FALSE; - pr.alkalinity = FALSE; - - species_list = NULL; - - user_database = NULL; - first_read_input = TRUE; - have_punch_name = FALSE; - selected_output_file_name = NULL; - dump_file_name = NULL; - - /* calculate_value */ - max_calculate_value = MAX_ELTS; - count_calculate_value = 0; - - calculate_value = 0; - calculate_value_hash_table = 0; - - /* isotope_ratio */ - max_isotope_ratio = MAX_ELTS; - count_isotope_ratio = 0; - isotope_ratio = 0; - isotope_ratio_hash_table = 0; - - /* isotope_value */ - max_isotope_alpha = MAX_ELTS; - count_isotope_alpha = 0; - isotope_alpha = 0; - isotope_alpha_hash_table = 0; - - phreeqc_mpi_myself = 0; - - copy_solution.n_user = copy_solution.start = copy_solution.end = 0; - copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; - copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; - copy_surface.n_user = copy_surface.start = copy_surface.end = 0; - copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; - copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; - copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; - copy_mix.n_user = copy_mix.start = copy_mix.end = 0; - copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; - copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; - - set_forward_output_to_log(FALSE); - simulation = 0; - /* - * cvode - */ - - cvode_init(); - /* - * Pitzer - */ - pitzer_model = FALSE; - max_pitz_param = 100; - count_pitz_param = 0; - use_etheta = TRUE; - pitz_params = 0; - - max_theta_param = 100; - count_theta_param = 0; - theta_params = 0; - - ICON = TRUE; - OTEMP = 0.0; - for (i = 0; i < 23; i++) - { - BK[i] = 0.0; - DK[i] = 0.0; - } - pitzer_pe = FALSE; - - - /* - * SIT - */ - sit_model = FALSE; - max_sit_param = 100; - count_sit_param = 0; - sit_params = 0; - - /* - * to facilitate debuging - */ - dbg_use = &use; - dbg_solution = solution; - dbg_exchange = exchange; - dbg_surface = surface; - dbg_pp_assemblage = pp_assemblage; - dbg_kinetics = kinetics; - dbg_irrev = irrev; - dbg_mix = mix; - dbg_master = master; - calculating_deriv = FALSE; - numerical_deriv = FALSE; - - zeros = 0; - zeros_max = 1; - - cell_pore_volume = 0; - cell_volume = 0; - cell_porosity = 0; - cell_saturation = 0; - - charge_group = NULL; - print_density = 0; - - return; -} +// COMMENT: {3/25/2010 2:37:25 PM}void IPhreeqc::init(void) +// COMMENT: {3/25/2010 2:37:25 PM}{ +// COMMENT: {3/25/2010 2:37:25 PM} int i; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} moles_per_kilogram_string = 0; +// COMMENT: {3/25/2010 2:37:25 PM} pe_string = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} debug_model = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} debug_prep = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} debug_set = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} debug_diffuse_layer = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} debug_inverse = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} itmax = 100; +// COMMENT: {3/25/2010 2:37:25 PM}#ifdef USE_LONG_DOUBLE +// COMMENT: {3/25/2010 2:37:25 PM} /* from float.h, sets tolerance for cl1 routine */ +// COMMENT: {3/25/2010 2:37:25 PM} ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); +// COMMENT: {3/25/2010 2:37:25 PM}#else +// COMMENT: {3/25/2010 2:37:25 PM} ineq_tol = pow((double) 10, (double) -DBL_DIG); +// COMMENT: {3/25/2010 2:37:25 PM}#endif +// COMMENT: {3/25/2010 2:37:25 PM} convergence_tolerance = 1e-8; +// COMMENT: {3/25/2010 2:37:25 PM}#ifdef USE_LONG_DOUBLE +// COMMENT: {3/25/2010 2:37:25 PM} /* from float.h, sets tolerance for cl1 routine */ +// COMMENT: {3/25/2010 2:37:25 PM} inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); +// COMMENT: {3/25/2010 2:37:25 PM}#else +// COMMENT: {3/25/2010 2:37:25 PM} inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); +// COMMENT: {3/25/2010 2:37:25 PM}#endif +// COMMENT: {3/25/2010 2:37:25 PM} step_size = 100.; +// COMMENT: {3/25/2010 2:37:25 PM} pe_step_size = 10.; +// COMMENT: {3/25/2010 2:37:25 PM} pp_scale = 1.0; +// COMMENT: {3/25/2010 2:37:25 PM} pp_column_scale = 1.0; +// COMMENT: {3/25/2010 2:37:25 PM} diagonal_scale = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} censor = 0.0; +// COMMENT: {3/25/2010 2:37:25 PM} mass_water_switch = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} delay_mass_water = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} incremental_reactions = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} aqueous_only = 0; +// COMMENT: {3/25/2010 2:37:25 PM} negative_concentrations = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} LOG_10 = log(10.0); +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} max_solution = MAX_SOLUTION; +// COMMENT: {3/25/2010 2:37:25 PM} max_pp_assemblage = MAX_PP_ASSEMBLAGE; +// COMMENT: {3/25/2010 2:37:25 PM} max_exchange = MAX_PP_ASSEMBLAGE; +// COMMENT: {3/25/2010 2:37:25 PM} max_surface = MAX_PP_ASSEMBLAGE; +// COMMENT: {3/25/2010 2:37:25 PM} max_gas_phase = MAX_PP_ASSEMBLAGE; +// COMMENT: {3/25/2010 2:37:25 PM} max_kinetics = MAX_PP_ASSEMBLAGE; +// COMMENT: {3/25/2010 2:37:25 PM} max_s_s_assemblage = MAX_PP_ASSEMBLAGE; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} max_elements = MAX_ELEMENTS; +// COMMENT: {3/25/2010 2:37:25 PM} max_elts = MAX_ELTS; +// COMMENT: {3/25/2010 2:37:25 PM} max_line = MAX_LINE; +// COMMENT: {3/25/2010 2:37:25 PM} max_master = MAX_MASTER; +// COMMENT: {3/25/2010 2:37:25 PM} max_mb_unknowns = MAX_TRXN; +// COMMENT: {3/25/2010 2:37:25 PM} max_phases = MAX_PHASES; +// COMMENT: {3/25/2010 2:37:25 PM} max_s = MAX_S; +// COMMENT: {3/25/2010 2:37:25 PM} max_strings = MAX_STRINGS; +// COMMENT: {3/25/2010 2:37:25 PM} max_trxn = MAX_TRXN; +// COMMENT: {3/25/2010 2:37:25 PM} max_logk = MAX_S; +// COMMENT: {3/25/2010 2:37:25 PM} max_master_isotope = MAX_ELTS; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} count_solution = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_pp_assemblage = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_exchange = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_surface = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_gas_phase = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_kinetics = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_s_s_assemblage = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} count_elements = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_irrev = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_master = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_mix = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_phases = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_s = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_temperature = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_logk = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_master_isotope = 0; +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * Initialize advection +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} count_ad_cells = 1; +// COMMENT: {3/25/2010 2:37:25 PM} count_ad_shifts = 1; +// COMMENT: {3/25/2010 2:37:25 PM} print_ad_modulus = 1; +// COMMENT: {3/25/2010 2:37:25 PM} punch_ad_modulus = 1; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} advection_punch = 0; +// COMMENT: {3/25/2010 2:37:25 PM} advection_kin_time = 0.0; +// COMMENT: {3/25/2010 2:37:25 PM} advection_kin_time_defined = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} advection_print = 0; +// COMMENT: {3/25/2010 2:37:25 PM} advection_warnings = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * Initialize transport +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} count_cells = 1; +// COMMENT: {3/25/2010 2:37:25 PM} count_shifts = 1; +// COMMENT: {3/25/2010 2:37:25 PM} ishift = 1; +// COMMENT: {3/25/2010 2:37:25 PM} bcon_first = bcon_last = 3; +// COMMENT: {3/25/2010 2:37:25 PM} diffc = 0.3e-9; +// COMMENT: {3/25/2010 2:37:25 PM} simul_tr = 0; +// COMMENT: {3/25/2010 2:37:25 PM} tempr = 2.0; +// COMMENT: {3/25/2010 2:37:25 PM} heat_diffc = -0.1; +// COMMENT: {3/25/2010 2:37:25 PM} timest = 0.0; +// COMMENT: {3/25/2010 2:37:25 PM} multi_Dflag = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} interlayer_Dflag = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} interlayer_tortf = 100.0; +// COMMENT: {3/25/2010 2:37:25 PM} interlayer_Dpor = 0.1; +// COMMENT: {3/25/2010 2:37:25 PM}/* !!!! count_stag = 0; */ +// COMMENT: {3/25/2010 2:37:25 PM} mcd_substeps = 1.0; +// COMMENT: {3/25/2010 2:37:25 PM} print_modulus = 1; +// COMMENT: {3/25/2010 2:37:25 PM} punch_modulus = 1; +// COMMENT: {3/25/2010 2:37:25 PM} dump_modulus = 0; +// COMMENT: {3/25/2010 2:37:25 PM} dump_in = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} transport_warnings = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} pp_assemblage = 0; +// COMMENT: {3/25/2010 2:37:25 PM} exchange = 0; +// COMMENT: {3/25/2010 2:37:25 PM} surface = 0; +// COMMENT: {3/25/2010 2:37:25 PM} gas_phase = 0; +// COMMENT: {3/25/2010 2:37:25 PM} kinetics = 0; +// COMMENT: {3/25/2010 2:37:25 PM} s_s_assemblage = 0; +// COMMENT: {3/25/2010 2:37:25 PM} cell_data = 0; +// COMMENT: {3/25/2010 2:37:25 PM} elements = 0; +// COMMENT: {3/25/2010 2:37:25 PM} elt_list = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} inverse = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_inverse = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} irrev = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} line = 0; +// COMMENT: {3/25/2010 2:37:25 PM} line_save = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} master = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} mb_unknowns = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} mix = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_mix = 0; +// COMMENT: {3/25/2010 2:37:25 PM}/* !!!! */ +// COMMENT: {3/25/2010 2:37:25 PM} stag_data = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} phases = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} trxn.token = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} s = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} logk = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} master_isotope = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} solution = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} temperature = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} title_x = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} pe_x = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} description_x = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} units_x = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} s_x = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} sum_mb1 = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} sum_mb2 = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} sum_jacob0 = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} sum_jacob1 = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} sum_jacob2 = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} sum_delta = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} isotopes_x = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} x = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} max_unknowns = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} array = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} delta = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} residual = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} s_h2o = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} s_hplus = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} s_h3oplus = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} s_eminus = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} s_co3 = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} s_h2 = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} s_o2 = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} logk_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} master_isotope_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} strings_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} elements_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} species_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} phases_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} keyword_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * Initialize use pointers +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} use.solution_in = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} use.pp_assemblage_in = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} use.mix_in = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} use.irrev_in = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * Initialize punch +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} punch.in = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_totals = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.totals = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_molalities = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.molalities = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_activities = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.activities = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_pure_phases = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.pure_phases = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_si = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.si = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_gases = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.gases = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_s_s = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.s_s = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_kinetics = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.kinetics = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_isotopes = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.isotopes = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.count_calculate_values = 0; +// COMMENT: {3/25/2010 2:37:25 PM} punch.calculate_values = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} count_save_values = 0; +// COMMENT: {3/25/2010 2:37:25 PM} save_values = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.inverse = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} punch.sim = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.state = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.soln = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.dist = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.time = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.step = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.rxn = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.temp = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.ph = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.pe = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.alk = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.mu = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.water = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.high_precision = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.user_punch = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.charge_balance = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} punch.percent_error = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * last model +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} last_model.exchange = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} last_model.gas_phase = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} last_model.s_s_assemblage = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} last_model.kinetics = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} last_model.pp_assemblage = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} last_model.add_formula = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} last_model.si = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} last_model.surface_comp = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} last_model.surface_charge = NULL; +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * Update hash table +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} keyword_hash = 0; +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * rates +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} rates = 0; +// COMMENT: {3/25/2010 2:37:25 PM} count_rates = 0; +// COMMENT: {3/25/2010 2:37:25 PM} initial_total_time = 0; +// COMMENT: {3/25/2010 2:37:25 PM} rate_m = 0; +// COMMENT: {3/25/2010 2:37:25 PM} rate_m0 = 0; +// COMMENT: {3/25/2010 2:37:25 PM} rate_p = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} rate_time = 0; +// COMMENT: {3/25/2010 2:37:25 PM} rate_sim_time_start = 0; +// COMMENT: {3/25/2010 2:37:25 PM} rate_sim_time_end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} rate_sim_time = 0; +// COMMENT: {3/25/2010 2:37:25 PM} rate_moles = 0; +// COMMENT: {3/25/2010 2:37:25 PM} initial_total_time = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * user_print, user_punch +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} user_print = 0; +// COMMENT: {3/25/2010 2:37:25 PM} user_punch = 0; +// COMMENT: {3/25/2010 2:37:25 PM} user_punch_headings = 0; +// COMMENT: {3/25/2010 2:37:25 PM} user_punch_count_headings = 0; +// COMMENT: {3/25/2010 2:37:25 PM}#ifdef PHREEQ98 +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * user_graph +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} user_graph = 0; +// COMMENT: {3/25/2010 2:37:25 PM} user_graph_headings = 0 +// COMMENT: {3/25/2010 2:37:25 PM} user_graph_count_headings = 0; +// COMMENT: {3/25/2010 2:37:25 PM}#endif +// COMMENT: {3/25/2010 2:37:25 PM} /* +// COMMENT: {3/25/2010 2:37:25 PM} Initialize llnl aqueous model parameters +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} llnl_temp = 0; +// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_temp = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} llnl_adh = 0; +// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_adh = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} llnl_bdh = 0; +// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_bdh = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} llnl_bdot = 0; +// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_bdot = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} llnl_co2_coefs = 0; +// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_co2_coefs = 0; +// COMMENT: {3/25/2010 2:37:25 PM}/* +// COMMENT: {3/25/2010 2:37:25 PM} * +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} command_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} change_surf = 0; +// COMMENT: {3/25/2010 2:37:25 PM} change_surf_count = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM}#if defined(WINDOWS) || defined(_WINDOWS) +// COMMENT: {3/25/2010 2:37:25 PM} /* SRC pr.status = FALSE; */ +// COMMENT: {3/25/2010 2:37:25 PM}#endif +// COMMENT: {3/25/2010 2:37:25 PM} /* Initialize print here, not in global.h */ +// COMMENT: {3/25/2010 2:37:25 PM} pr.all = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.initial_solutions = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.initial_exchangers = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.reactions = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.gas_phase = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.s_s_assemblage = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.pp_assemblage = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.surface = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.exchange = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.kinetics = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.totals = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.eh = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.species = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.saturation_indices = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.irrev = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.mix = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.reaction = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.use = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.logfile = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.punch = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} if (phast == TRUE) +// COMMENT: {3/25/2010 2:37:25 PM} { +// COMMENT: {3/25/2010 2:37:25 PM} pr.status = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} } +// COMMENT: {3/25/2010 2:37:25 PM} else +// COMMENT: {3/25/2010 2:37:25 PM} { +// COMMENT: {3/25/2010 2:37:25 PM} pr.status = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} } +// COMMENT: {3/25/2010 2:37:25 PM} pr.inverse = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.dump = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.user_print = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.headings = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.user_graph = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.echo_input = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} count_warnings = 0; +// COMMENT: {3/25/2010 2:37:25 PM} pr.warnings = 100; +// COMMENT: {3/25/2010 2:37:25 PM} pr.initial_isotopes = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.isotope_ratios = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.isotope_alphas = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.hdf = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} pr.alkalinity = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} species_list = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} user_database = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} first_read_input = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} have_punch_name = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} selected_output_file_name = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} dump_file_name = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} /* calculate_value */ +// COMMENT: {3/25/2010 2:37:25 PM} max_calculate_value = MAX_ELTS; +// COMMENT: {3/25/2010 2:37:25 PM} count_calculate_value = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} calculate_value = 0; +// COMMENT: {3/25/2010 2:37:25 PM} calculate_value_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} /* isotope_ratio */ +// COMMENT: {3/25/2010 2:37:25 PM} max_isotope_ratio = MAX_ELTS; +// COMMENT: {3/25/2010 2:37:25 PM} count_isotope_ratio = 0; +// COMMENT: {3/25/2010 2:37:25 PM} isotope_ratio = 0; +// COMMENT: {3/25/2010 2:37:25 PM} isotope_ratio_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} /* isotope_value */ +// COMMENT: {3/25/2010 2:37:25 PM} max_isotope_alpha = MAX_ELTS; +// COMMENT: {3/25/2010 2:37:25 PM} count_isotope_alpha = 0; +// COMMENT: {3/25/2010 2:37:25 PM} isotope_alpha = 0; +// COMMENT: {3/25/2010 2:37:25 PM} isotope_alpha_hash_table = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} phreeqc_mpi_myself = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} copy_solution.n_user = copy_solution.start = copy_solution.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_surface.n_user = copy_surface.start = copy_surface.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_mix.n_user = copy_mix.start = copy_mix.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} set_forward_output_to_log(FALSE); +// COMMENT: {3/25/2010 2:37:25 PM} simulation = 0; +// COMMENT: {3/25/2010 2:37:25 PM} /* +// COMMENT: {3/25/2010 2:37:25 PM} * cvode +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} cvode_init(); +// COMMENT: {3/25/2010 2:37:25 PM} /* +// COMMENT: {3/25/2010 2:37:25 PM} * Pitzer +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} pitzer_model = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} max_pitz_param = 100; +// COMMENT: {3/25/2010 2:37:25 PM} count_pitz_param = 0; +// COMMENT: {3/25/2010 2:37:25 PM} use_etheta = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} pitz_params = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} max_theta_param = 100; +// COMMENT: {3/25/2010 2:37:25 PM} count_theta_param = 0; +// COMMENT: {3/25/2010 2:37:25 PM} theta_params = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} ICON = TRUE; +// COMMENT: {3/25/2010 2:37:25 PM} OTEMP = 0.0; +// COMMENT: {3/25/2010 2:37:25 PM} for (i = 0; i < 23; i++) +// COMMENT: {3/25/2010 2:37:25 PM} { +// COMMENT: {3/25/2010 2:37:25 PM} BK[i] = 0.0; +// COMMENT: {3/25/2010 2:37:25 PM} DK[i] = 0.0; +// COMMENT: {3/25/2010 2:37:25 PM} } +// COMMENT: {3/25/2010 2:37:25 PM} pitzer_pe = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} /* +// COMMENT: {3/25/2010 2:37:25 PM} * SIT +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} sit_model = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} max_sit_param = 100; +// COMMENT: {3/25/2010 2:37:25 PM} count_sit_param = 0; +// COMMENT: {3/25/2010 2:37:25 PM} sit_params = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} /* +// COMMENT: {3/25/2010 2:37:25 PM} * to facilitate debuging +// COMMENT: {3/25/2010 2:37:25 PM} */ +// COMMENT: {3/25/2010 2:37:25 PM} dbg_use = &use; +// COMMENT: {3/25/2010 2:37:25 PM} dbg_solution = solution; +// COMMENT: {3/25/2010 2:37:25 PM} dbg_exchange = exchange; +// COMMENT: {3/25/2010 2:37:25 PM} dbg_surface = surface; +// COMMENT: {3/25/2010 2:37:25 PM} dbg_pp_assemblage = pp_assemblage; +// COMMENT: {3/25/2010 2:37:25 PM} dbg_kinetics = kinetics; +// COMMENT: {3/25/2010 2:37:25 PM} dbg_irrev = irrev; +// COMMENT: {3/25/2010 2:37:25 PM} dbg_mix = mix; +// COMMENT: {3/25/2010 2:37:25 PM} dbg_master = master; +// COMMENT: {3/25/2010 2:37:25 PM} calculating_deriv = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} numerical_deriv = FALSE; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} zeros = 0; +// COMMENT: {3/25/2010 2:37:25 PM} zeros_max = 1; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} cell_pore_volume = 0; +// COMMENT: {3/25/2010 2:37:25 PM} cell_volume = 0; +// COMMENT: {3/25/2010 2:37:25 PM} cell_porosity = 0; +// COMMENT: {3/25/2010 2:37:25 PM} cell_saturation = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} charge_group = NULL; +// COMMENT: {3/25/2010 2:37:25 PM} print_density = 0; +// COMMENT: {3/25/2010 2:37:25 PM} +// COMMENT: {3/25/2010 2:37:25 PM} return; +// COMMENT: {3/25/2010 2:37:25 PM}} bool IPhreeqc::GetOutputOn(void)const { @@ -1664,7 +1715,9 @@ int IPhreeqc::RunAccumulated(void) } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } catch(...) { @@ -1675,7 +1728,9 @@ int IPhreeqc::RunAccumulated(void) } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } } @@ -1696,8 +1751,8 @@ int IPhreeqc::RunFile(const char* filename) this->input_error = 0; -#if 0 - // create input stream + // open file + // std::ifstream ifs; ifs.open(filename); if (!ifs.is_open()) @@ -1709,24 +1764,12 @@ int IPhreeqc::RunFile(const char* filename) // this may throw this->do_run(sz_routine, &ifs, NULL, NULL, NULL, NULL); -#else - // open file - // - FILE* f = ::fopen(filename, "r"); - if (!f) - { - std::ostringstream oss; - oss << "RunFile: Unable to open:" << "\"" << filename << "\"."; - this->error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop - } - - // this may throw - this->do_run(sz_routine, NULL, f, NULL, NULL, NULL); -#endif } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } catch(...) { @@ -1737,7 +1780,9 @@ int IPhreeqc::RunFile(const char* filename) } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } } @@ -1766,7 +1811,9 @@ int IPhreeqc::RunString(const char* input) } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } catch(...) { @@ -1777,7 +1824,9 @@ int IPhreeqc::RunString(const char* input) } catch (PhreeqcStop) { - // do nothing + assert(this->database_file == 0); + assert(this->input_file == 0); + assert(this->input_error > 0); } } diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp deleted file mode 100644 index e202550a..00000000 --- a/IPhreeqc.hpp +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef _INC_IPHREEQC_HPP -#define _INC_IPHREEQC_HPP - -#include "Phreeqc.h" /* Phreeqc */ -#include "IPhreeqcCallbacks.h" /* PFN_PRERUN_CALLBACK, PFN_POSTRUN_CALLBACK, PFN_CATCH_CALLBACK */ -#include "Var.h" /* VRESULT */ -#include "SelectedOutput.hxx" - - -class IErrorReporter; - -struct PhreeqcStop{}; - -class IPhreeqc : public Phreeqc -{ -public: - IPhreeqc(void); - ~IPhreeqc(void); - -public: - int LoadDatabase(const char* filename); - int LoadDatabaseString(const char* input); - - void UnLoadDatabase(void); - - void OutputLastError(void); - - const char* GetLastErrorString(void); - const char* GetLastWarningString(void); - const char* GetDumpString(void); - - int GetDumpLineCount(void)const; - const char* GetDumpLine(int n); - - int GetErrorLineCount(void)const; - const char* GetErrorLine(int n); - - std::list< std::string > ListComponents(void); - - VRESULT AccumulateLine(const char *line); - - bool GetDumpOn(void)const; - void SetDumpOn(bool bValue); - - bool GetDumpStringOn(void)const; - void SetDumpStringOn(bool bValue); - - bool GetErrorOn(void)const; - void SetErrorOn(bool bValue); - - bool GetLogOn(void)const; - void SetLogOn(bool bValue); - - bool GetOutputOn(void)const; - void SetOutputOn(bool bValue); - - bool GetSelectedOutputOn(void)const; - void SetSelectedOutputOn(bool bValue); - - int RunAccumulated(void); - int RunFile(const char* filename); - int RunString(const char* input); - - int GetSelectedOutputRowCount(void)const; - int GetSelectedOutputColumnCount(void)const; - VRESULT GetSelectedOutputValue(int row, int col, VAR* pVAR); - - void OutputLines(void); - - size_t AddError(const char* error_msg); - size_t AddWarning(const char* warning_msg); - - const std::string& GetAccumulatedLines(void); - void ClearAccumulatedLines(void); - - // Singleton for library - static IPhreeqc* LibraryInstance(void); - static int Create(void); - static void Destroy(int n); - - // Callbacks - // - - // IPhreeqc.cpp - static int handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); - int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); - int open_handler(const int type, const char *file_name/*, void *cookie*/); - - // module_files.c - static int module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); - int module_isopen_handler(const int type); - int module_open_handler(const int type, const char *file_name); - - // module_output.c - int output_isopen(const int type); - - virtual int EndRow(void); - void AddSelectedOutput(const char* name, const char* format, va_list argptr); - - void check_database(const char* sz_routine); - void do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie); - -protected: - void init(void); - void update_errors(void); - -protected: - - IErrorReporter *ErrorReporter; - std::string LastErrorString; - std::vector< std::string > ErrorLines; - - IErrorReporter *WarningReporter; - std::string LastWarningString; - std::vector< std::string > WarningLines; - - CSelectedOutput *SelectedOutput; - std::string PunchFileName; - bool DatabaseLoaded; - std::string StringInput; - - bool SelectedOutputOn; - bool OutputOn; - bool LogOn; - bool ErrorOn; - bool DumpOn; - bool DumpStringOn; - - std::string DumpString; - std::vector< std::string > DumpLines; - -private: - static IPhreeqc* Instance; - static std::map Instances; - static size_t InstancesIndex; -}; - -#endif /* _INC_IPHREEQC_HPP */ diff --git a/IPhreeqc2.cpp b/IPhreeqc2.cpp new file mode 100644 index 00000000..232f36b1 --- /dev/null +++ b/IPhreeqc2.cpp @@ -0,0 +1,1257 @@ +#include "IPhreeqc2.h" + +// COMMENT: {3/25/2010 7:28:15 PM}#define protected public +#include "Phreeqc.h" /* Phreeqc */ +// COMMENT: {3/25/2010 7:28:18 PM}#undef protected + +#include +#include "ErrorReporter.hxx" +#include "SelectedOutput.hxx" +#include "dumper.h" + +int istream_getc(void *cookie); + + +typedef enum { + ACTION_ISOPEN = -100, +} module_action_type; + +const char OUTPUT_FILENAME[] = "phreeqc.out"; +const char ERROR_FILENAME[] = "phreeqc.err"; +const char LOG_FILENAME[] = "phreeqc.log"; +const char PUNCH_FILENAME[] = "selected.out"; + +IPhreeqc2::IPhreeqc2(void) +: ErrorReporter(0) +, WarningReporter(0) +, SelectedOutput(0) +, DatabaseLoaded(false) +, SelectedOutputOn(false) +, OutputOn(false) +, LogOn(false) +, ErrorOn(false) +, DumpOn(false) +, DumpStringOn(false) +, PhreeqcPtr(0) +{ + this->ErrorReporter = new CErrorReporter; + this->WarningReporter = new CErrorReporter; + this->SelectedOutput = new CSelectedOutput(); + this->PhreeqcPtr = new Phreeqc; + ASSERT(this->PhreeqcPtr->phast == 0); + this->UnLoadDatabase(); +} + +IPhreeqc2::~IPhreeqc2(void) +{ + delete this->PhreeqcPtr; +} + +int IPhreeqc2::handler2(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +{ + int n = OK; + IPhreeqc2 *pThis = (IPhreeqc2*)cookie; + switch (action) + { + case Phreeqc::ACTION_OPEN: + n = pThis->open_handler2(type, err_str); + break; + + case Phreeqc::ACTION_OUTPUT: + n = pThis->output_handler2(type, err_str, stop, cookie, format, args); + break; + + default: + n = pThis->module_handler2(action, type, err_str, stop, cookie, format, args); + break; + } + + if (stop == STOP) + { + throw IPhreeqcStop(); + } + return n; +} + +int IPhreeqc2::output_handler2(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +{ + assert(cookie == this); + + switch (type) + { + case Phreeqc::OUTPUT_ERROR: + if (this) + { + this->AddError("ERROR: "); + this->AddError(err_str); + this->AddError("\n"); + if (stop == STOP) + { + this->AddError("Stopping.\n"); + } + } + break; + + case Phreeqc::OUTPUT_WARNING: + if (this) + { + std::ostringstream oss; + oss << "WARNING: " << err_str << "\n"; + this->AddWarning(oss.str().c_str()); + } + break; + + case Phreeqc::OUTPUT_PUNCH: + this->AddSelectedOutput(err_str, format, args); + break; + + case Phreeqc::OUTPUT_PUNCH_END_ROW: + this->EndRow(); + break; + + } + return module_handler2(Phreeqc::ACTION_OUTPUT, type, err_str, stop, cookie, format, args); +} + +int IPhreeqc2::open_handler2(const int type, const char *file_name) +{ + int n = OK; + switch (type) + { + case Phreeqc::OUTPUT_PUNCH: + if (file_name) + { + if (this->PunchFileName.compare(file_name) != 0) + { + this->PunchFileName = file_name; + } + } + if (this->SelectedOutputOn) + { + n = module_handler2(Phreeqc::ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); + } + break; + default: + n = module_handler2(Phreeqc::ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); + break; + } + return n; +} + +int IPhreeqc2::module_handler2(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +{ + IPhreeqc2* pThis = (IPhreeqc2*) cookie; + + switch (action) + { + case Phreeqc::ACTION_OPEN: + return pThis->module_open_handler2(type, err_str); + break; + case ACTION_ISOPEN: + return pThis->module_isopen_handler2(type); + break; + default: + return pThis->PhreeqcPtr->phreeqc_handler(action, type, err_str, stop, pThis->PhreeqcPtr, format, args); + break; + } + return ERROR; +} + +int IPhreeqc2::module_isopen_handler2(const int type) +{ + switch (type) + { + case Phreeqc::OUTPUT_PUNCH: + if (this->PhreeqcPtr->punch_file) return 1; + break; + default: + assert(0); + } + return 0; +} + +int IPhreeqc2::module_open_handler2(const int type, const char *file_name) +{ + assert(file_name && ::strlen(file_name)); + switch (type) + { + case Phreeqc::OUTPUT_MESSAGE: + if (this->PhreeqcPtr->output != NULL) + { + ::fclose(this->PhreeqcPtr->output); + this->PhreeqcPtr->output = NULL; + } + if ( (this->PhreeqcPtr->output = ::fopen(file_name, "w")) == NULL) + { + return ERROR; + } + break; + + case Phreeqc::OUTPUT_ERROR: + assert(this->PhreeqcPtr->error_file != stderr); + if (this->PhreeqcPtr->error_file != NULL) + { + ::fclose(this->PhreeqcPtr->error_file); + this->PhreeqcPtr->error_file = NULL; + } + if ( (this->PhreeqcPtr->error_file = ::fopen(file_name, "w")) == NULL) + { + return ERROR; + } + break; + + case Phreeqc::OUTPUT_LOG: + if (this->PhreeqcPtr->log_file != NULL) + { + ::fclose(this->PhreeqcPtr->log_file); + this->PhreeqcPtr->log_file = NULL; + } + if ( (this->PhreeqcPtr->log_file = ::fopen(file_name, "w")) == NULL) + { + return ERROR; + } + break; + + default: + return this->PhreeqcPtr->open_handler(type, file_name); + break; + + } + return(OK); +} + +int IPhreeqc2::output_isopen2(const int type) +{ + size_t i; + int isopen; + for (i = 0; i < this->PhreeqcPtr->count_output_callback; ++i) + { + isopen = (this->PhreeqcPtr->output_callbacks[i].callback)(ACTION_ISOPEN, type, NULL, CONTINUE, this->PhreeqcPtr->output_callbacks[i].cookie, NULL, NULL); + if (isopen) return 1; + } + return 0; +} + +// COMMENT: {3/25/2010 1:27:16 PM}int Phreeqc::EndRow(void) +// COMMENT: {3/25/2010 1:27:16 PM}{ +// COMMENT: {3/25/2010 1:27:16 PM} return OK; +// COMMENT: {3/25/2010 1:27:16 PM}} + +int IPhreeqc2::EndRow(void) +{ + if (this->SelectedOutput->GetRowCount() <= 1) + { + assert(this->PhreeqcPtr->n_user_punch_index >= 0); + // ensure all user_punch headings are included + for (int i = this->PhreeqcPtr->n_user_punch_index; i < this->PhreeqcPtr->user_punch_count_headings; ++i) + { + this->SelectedOutput->PushBackEmpty(this->PhreeqcPtr->user_punch_headings[i]); + } + } + return this->SelectedOutput->EndRow(); +} + +void IPhreeqc2::ClearAccumulatedLines(void) +{ + this->StringInput.erase(); +} + +size_t IPhreeqc2::AddError(const char* error_msg) +{ + return this->ErrorReporter->AddError(error_msg); +} + +size_t IPhreeqc2::AddWarning(const char* error_msg) +{ + return this->WarningReporter->AddError(error_msg); +} + +const std::string& IPhreeqc2::GetAccumulatedLines(void) +{ + return this->StringInput; +} + +void IPhreeqc2::OutputLines(void) +{ + std::cout << this->StringInput.c_str() << std::endl; +} + +int IPhreeqc2::LoadDatabase(const char* filename) +{ + try + { + // cleanup + // + this->UnLoadDatabase(); + this->SelectedOutput->Clear(); + + // open file + // + std::ifstream ifs; + ifs.open(filename); + + if (!ifs.is_open()) + { + std::ostringstream oss; + oss << "LoadDatabase: Unable to open:" << "\"" << filename << "\"."; + this->PhreeqcPtr->error_msg(oss.str().c_str(), STOP); // throws + } + + // read input + // + this->PhreeqcPtr->read_database(istream_getc, &ifs); + } + catch (IPhreeqcStop) + { + this->PhreeqcPtr->close_input_files(); + } + catch (...) + { + const char *errmsg = "LoadDatabase: An unhandled exception occured.\n"; + try + { + this->PhreeqcPtr->error_msg(errmsg, STOP); // throws IPhreeqcStop + } + catch (IPhreeqcStop) + { + // do nothing + } + } + + this->DatabaseLoaded = (this->PhreeqcPtr->input_error == 0); + return this->PhreeqcPtr->input_error; +} + +int IPhreeqc2::LoadDatabaseString(const char* input) +{ + try + { + // cleanup + // + this->UnLoadDatabase(); + + this->SelectedOutput->Clear(); + + std::string s(input); + std::istringstream iss(s); + + // read input + // + this->PhreeqcPtr->read_database(istream_getc, &iss); + } + catch (IPhreeqcStop) + { + this->PhreeqcPtr->close_input_files(); + } + catch(...) + { + const char *errmsg = "LoadDatabaseString: An unhandled exception occured.\n"; + try + { + this->PhreeqcPtr->error_msg(errmsg, STOP); // throws PhreeqcStop + } + catch (IPhreeqcStop) + { + // do nothing + } + } + + this->DatabaseLoaded = (this->PhreeqcPtr->input_error == 0); + return this->PhreeqcPtr->input_error; +} + +void IPhreeqc2::UnLoadDatabase(void) +{ + // init IPhreeqc + // + this->DatabaseLoaded = false; + + // clear error state + // + ASSERT(this->ErrorReporter); + this->ErrorReporter->Clear(); + this->LastErrorString.clear(); + + // clear warning state + // + ASSERT(this->WarningReporter); + this->WarningReporter->Clear(); + this->LastWarningString.clear(); + + // clear selectedoutput + // + ASSERT(this->SelectedOutput); + this->SelectedOutput->Clear(); + + // clear dump string + // + this->DumpString.clear(); + this->DumpLines.clear(); + + // initialize phreeqc + // + this->PhreeqcPtr->clean_up(); + this->PhreeqcPtr->add_output_callback(IPhreeqc2::handler2, this); + this->PhreeqcPtr->do_initialize(); + this->PhreeqcPtr->input_error = 0; +} + +bool IPhreeqc2::GetOutputOn(void)const +{ + return this->OutputOn; +} + +void IPhreeqc2::SetOutputOn(bool bValue) +{ + this->OutputOn = bValue; +} + +bool IPhreeqc2::GetSelectedOutputOn(void)const +{ + return this->SelectedOutputOn; +} + +void IPhreeqc2::SetSelectedOutputOn(bool bValue) +{ + this->SelectedOutputOn = bValue; +} + +bool IPhreeqc2::GetLogOn(void)const +{ + return this->LogOn; +} + +void IPhreeqc2::SetLogOn(bool bValue) +{ + this->LogOn = bValue; +} + +bool IPhreeqc2::GetDumpOn(void)const +{ + return this->DumpOn; +} + +void IPhreeqc2::SetDumpOn(bool bValue) +{ + this->DumpOn = bValue; +} + +bool IPhreeqc2::GetDumpStringOn(void)const +{ + return this->DumpStringOn; +} + +void IPhreeqc2::SetDumpStringOn(bool bValue) +{ + this->DumpStringOn = bValue; +} + +bool IPhreeqc2::GetErrorOn(void)const +{ + return this->ErrorOn; +} + +void IPhreeqc2::SetErrorOn(bool bValue) +{ + this->ErrorOn = bValue; +} + +void IPhreeqc2::AddSelectedOutput(const char* name, const char* format, va_list argptr) +{ + int bInt; + int bDouble; + int bString; + + int state; + int bLongDouble; + char ch; + + + /* state values + 0 Haven't found start(%) + 1 Just read start(%) + 2 Just read Flags(-0+ #) (zero or more) + 3 Just read Width + 4 Just read Precision start (.) + 5 Just read Size modifier + 6 Just read Type + */ + + if (name == NULL) { + return; + } + + bDouble = 0; + bInt = 0; + bString = 0; + + bLongDouble = 0; + + state = 0; + ch = *format++; + while (ch != '\0') + { + switch (state) + { + case 0: /* looking for Start specification (%) */ + switch (ch) + { + case '%': + state = 1; + break; + default: + break; + } + ch = *format++; + break; + case 1: /* reading Flags (zero or more(-,+,0,# or space)) */ + switch (ch) + { + case '-': case '0': case '+': case ' ': case '#': + ch = *format++; + break; + default: + state = 2; + break; + } + break; + case 2: /* reading Minimum field width (decimal integer constant) */ + switch (ch) + { + case '.': + state = 3; + ch = *format++; + break; + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + ch = *format++; + break; + default: + state = 4; + break; + } + break; + case 3: /* reading Precision specification (period already read) */ + switch (ch) + { + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': + ch = *format++; + break; + default: + state = 4; + break; + } + break; + case 4: /* reading Size modifier */ + switch (ch) + { + case 'l': + ch = *format++; + break; + case 'L': + bLongDouble = 1; + ch = *format++; + break; + case 'h': + ch = *format++; + break; + } + state = 5; + break; + case 5: /* reading Conversion letter */ + switch (ch) + { + case 'c': + break; + case 'd': + case 'i': + bInt = 1; + break; + case 'n': + case 'o': + case 'p': + break; + case 's': + bString = 1; + break; + case 'u': + case 'x': + case 'X': + case '%': + break; + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + bDouble = 1; + break; + default: + ASSERT(false); + break; + } + ch = '\0'; /* done */ + break; + } + } + + if (bDouble) + { + double valDouble; + + if (bLongDouble) + { + valDouble = (double)va_arg(argptr, long double); + } + else + { + valDouble = va_arg(argptr, double); + } + + this->SelectedOutput->PushBackDouble(name, valDouble); + } + else if (bInt) + { + int valInt; + valInt = va_arg(argptr, int); + + this->SelectedOutput->PushBackLong(name, (long)valInt); + } + else if (bString) + { + char* valString; + valString = (char *)va_arg(argptr, char *); + + this->SelectedOutput->PushBackString(name, valString); + } + else + { + ASSERT(false); + this->SelectedOutput->PushBackEmpty(name); + } +} + +const char* IPhreeqc2::GetLastErrorString(void) +{ + this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); + return this->LastErrorString.c_str(); +} + +const char* IPhreeqc2::GetLastWarningString(void) +{ + this->LastWarningString = ((CErrorReporter*)this->WarningReporter)->GetOS()->str(); + return this->LastWarningString.c_str(); +} + +const char* IPhreeqc2::GetDumpString(void) +{ + return this->DumpString.c_str(); +} + + +void IPhreeqc2::check_database(const char* sz_routine) +{ + this->ErrorReporter->Clear(); + this->SelectedOutput->Clear(); + + if (!this->DatabaseLoaded) + { + std::ostringstream oss; + oss << sz_routine << ": No database is loaded"; + this->PhreeqcPtr->input_error = 1; + this->PhreeqcPtr->error_msg(oss.str().c_str(), STOP); // throws + } +} + +void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie) +{ + std::auto_ptr auto_iss(NULL); + char token[MAX_LENGTH]; + + if (this->OutputOn) + { + if (this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_MESSAGE, OUTPUT_FILENAME) != OK) + { + std::ostringstream oss; + oss << sz_routine << ": Unable to open:" << "\"" << OUTPUT_FILENAME << "\".\n"; + this->PhreeqcPtr->warning_msg(oss.str().c_str()); + } + } + if (this->ErrorOn) + { + if (this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_ERROR, ERROR_FILENAME) != OK) + { + std::ostringstream oss; + oss << sz_routine << ": Unable to open:" << "\"" << ERROR_FILENAME << "\".\n"; + this->PhreeqcPtr->warning_msg(oss.str().c_str()); + } + } + if (this->LogOn) + { + if (this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_LOG, LOG_FILENAME) != OK) + { + std::ostringstream oss; + oss << sz_routine << ": Unable to open:" << "\"" << LOG_FILENAME << "\".\n"; + this->PhreeqcPtr->warning_msg(oss.str().c_str()); + } + } + +/* + * call pre-run callback + */ + if (pfn_pre) + { + pfn_pre(cookie); + } + +/* + * set read callback + */ + if (!pis) + { + if (fp) + { + this->PhreeqcPtr->set_read_callback(Phreeqc::getc_callback, fp, FALSE); + } + else + { + std::auto_ptr a_iss(new std::istringstream(this->GetAccumulatedLines())); + auto_iss = a_iss; + this->PhreeqcPtr->set_read_callback(istream_getc, auto_iss.get(), FALSE); + } + } + else + { + this->PhreeqcPtr->set_read_callback(istream_getc, pis, FALSE); + } + + +/* + * Read input data for simulation + */ + for (this->PhreeqcPtr->simulation = 1; ; this->PhreeqcPtr->simulation++) { + +#ifdef PHREEQ98 + AddSeries = !connect_simulations; +#endif + ::sprintf(token, "Reading input data for simulation %d.", this->PhreeqcPtr->simulation); + + this->PhreeqcPtr->output_msg(Phreeqc::OUTPUT_GUI_ERROR, "\nSimulation %d\n", this->PhreeqcPtr->simulation); + +#ifdef SWIG_SHARED_OBJ + int save_punch_in = this->PhreeqcPtr->punch.in; +#endif // SWIG_SHARED_OBJ + this->PhreeqcPtr->dup_print(token, TRUE); + if (this->PhreeqcPtr->read_input() == EOF) break; + +#ifdef SWIG_SHARED_OBJ + if (this->PhreeqcPtr->simulation > 1 && save_punch_in == TRUE && this->PhreeqcPtr->punch.new_def == TRUE) + { + std::ostringstream oss; + oss << sz_routine << ": Warning SELECTED_OUTPUT has been redefined.\n"; + this->PhreeqcPtr->warning_msg(oss.str().c_str()); + + } + if (this->PhreeqcPtr->simulation > 1 && this->PhreeqcPtr->keyword[39].keycount > 0) + { + std::ostringstream oss; + oss << sz_routine << ": Warning USER_PUNCH has been redefined.\n"; + this->PhreeqcPtr->warning_msg(oss.str().c_str()); + } +#endif // SWIG_SHARED_OBJ + + if (this->PhreeqcPtr->title_x != NULL) { + ::sprintf(token, "TITLE"); + this->PhreeqcPtr->dup_print(token, TRUE); + if (this->PhreeqcPtr->pr.headings == TRUE) this->PhreeqcPtr->output_msg(Phreeqc::OUTPUT_MESSAGE, "%s\n\n", this->PhreeqcPtr->title_x); + } + +#ifdef SWIG_SHARED_OBJ + if (this->PhreeqcPtr->punch.in == TRUE) + { + // + // (punch.in == TRUE) when any "RUN" has contained + // a SELECTED_OUTPUT block since the last LoadDatabase call. + // + // Since LoadDatabase inititializes punch.in to FALSE + // (via UnLoadDatabase...do_initialize) + // and punch.in is set to TRUE in read_selected_output + // + // This causes the SELECTED_OUTPUT to contain the same headings + // until another SELECTED_OUTPUT is defined which sets the variable + // punch.new_def to TRUE + // + // WHAT IF A USER_PUNCH IS DEFINED?? IS punch.new_def SET TO + // TRUE ??? + // + // + if (!this->SelectedOutputOn) ASSERT(!this->output_isopen2(Phreeqc::OUTPUT_PUNCH)); + + if (this->PhreeqcPtr->pr.punch == FALSE) + { + // No selected_output for this simulation + // this happens when + // PRINT; -selected_output false + // is given as input + // Note: this also disables the CSelectedOutput object + } + else + { + if (this->PhreeqcPtr->punch.new_def == FALSE) + { + if (this->SelectedOutputOn && !this->output_isopen2(Phreeqc::OUTPUT_PUNCH)) + { + // + // LoadDatabase + // do_run -- containing SELECTED_OUTPUT ****TODO**** check -file option + // another do_run without SELECTED_OUTPUT + // + std::string filename = this->PunchFileName; + this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_PUNCH, filename.c_str()); + if (!this->output_isopen2(Phreeqc::OUTPUT_PUNCH)) + { + std::ostringstream oss; + oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n"; + this->PhreeqcPtr->warning_msg(oss.str().c_str()); + } + else + { + // output selected_output headings + this->PhreeqcPtr->punch.new_def = TRUE; + this->PhreeqcPtr->tidy_punch(); + } + } + } + else + { + if (this->SelectedOutputOn && !this->output_isopen2(Phreeqc::OUTPUT_PUNCH)) + { + // This is a special case which could not occur in + // phreeqc + // + // LoadDatabase + // do_run -- containing SELECTED_OUTPUT ****TODO**** check -file option + // another do_run with SELECTED_OUTPUT + // + std::string filename = PUNCH_FILENAME; + if (this->PunchFileName.size()) + { + filename = this->PunchFileName; + } + this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_PUNCH, filename.c_str()); + if (!this->output_isopen2(Phreeqc::OUTPUT_PUNCH)) + { + std::ostringstream oss; + oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n"; + this->PhreeqcPtr->warning_msg(oss.str().c_str()); + } + else + { + // output selected_output headings + ASSERT(this->PhreeqcPtr->punch.new_def == TRUE); + this->PhreeqcPtr->tidy_punch(); + } + } + } + } + } + + if (!this->SelectedOutputOn) ASSERT(!this->output_isopen2(Phreeqc::OUTPUT_PUNCH)); + /* the converse is not necessarily true */ + + this->PhreeqcPtr->n_user_punch_index = -1; +#endif // SWIG_SHARED_OBJ + this->PhreeqcPtr->tidy_model(); +#ifdef PHREEQC_CPP + //test_classes(); +#endif +#ifdef PHREEQ98 + if (!phreeq98_debug) { +#endif + + +/* + * Calculate distribution of species for initial solutions + */ + if (this->PhreeqcPtr->new_solution) this->PhreeqcPtr->initial_solutions(TRUE); +/* + * Calculate distribution for exchangers + */ + if (this->PhreeqcPtr->new_exchange) this->PhreeqcPtr->initial_exchangers(TRUE); +/* + * Calculate distribution for surfaces + */ + if (this->PhreeqcPtr->new_surface) this->PhreeqcPtr->initial_surfaces(TRUE); +/* + * Calculate initial gas composition + */ + if (this->PhreeqcPtr->new_gas_phase) this->PhreeqcPtr->initial_gas_phases(TRUE); +/* + * Calculate reactions + */ + this->PhreeqcPtr->reactions(); +/* + * Calculate inverse models + */ + this->PhreeqcPtr->inverse_models(); +/* + * Calculate advection + */ + if (this->PhreeqcPtr->use.advect_in == TRUE) { + this->PhreeqcPtr->dup_print ("Beginning of advection calculations.", TRUE); + this->PhreeqcPtr->advection(); + } +/* + * Calculate transport + */ + if (this->PhreeqcPtr->use.trans_in == TRUE) { + this->PhreeqcPtr->dup_print ("Beginning of transport calculations.", TRUE); + this->PhreeqcPtr->transport(); + } + +#ifdef PHREEQC_CPP +/* + * run + */ + this->PhreeqcPtr->run_as_cells(); +#endif + +/* + * Copy + */ + if (this->PhreeqcPtr->new_copy) this->PhreeqcPtr->copy_entities(); +#ifdef PHREEQC_CPP + +/* + * dump + */ + dumper dump_info_save(this->PhreeqcPtr->dump_info); + if (this->DumpOn) + { + this->PhreeqcPtr->dump_entities(); + } + if (this->DumpStringOn) + { + this->PhreeqcPtr->dump_info = dump_info_save; + if (this->PhreeqcPtr->dump_info.Get_bool_any()) + { + std::ostringstream oss; + this->PhreeqcPtr->dump_ostream(oss); + if (this->PhreeqcPtr->dump_info.get_append()) + { + this->DumpString += oss.str(); + } + else + { + this->DumpString = oss.str(); + } + + /* Fill dump lines */ + this->DumpLines.clear(); + std::istringstream iss(this->DumpString); + std::string line; + while (std::getline(iss, line)) + { + this->DumpLines.push_back(line); + } + } + } +/* + * delete + */ + this->PhreeqcPtr->delete_entities(); +#endif + +/* + * End of simulation + */ + this->PhreeqcPtr->dup_print( "End of simulation.", TRUE); +#ifdef PHREEQ98 + } /* if (!phreeq98_debug) */ +#endif + } + +/* + * Display successful status + */ + this->PhreeqcPtr->do_status(); + +/* + * call post-run callback + */ + if (pfn_post) + { + pfn_post(cookie); + } + + if (this->PhreeqcPtr->input_error > 0) + { + std::ostringstream oss; + oss << "\n"; + oss << this->StringInput.c_str(); + oss << "\n"; + this->PhreeqcPtr->error_msg(oss.str().c_str(), CONTINUE); + } + this->update_errors(); +} + +VRESULT IPhreeqc2::AccumulateLine(const char *line) +{ + try + { + this->ErrorReporter->Clear(); + this->WarningReporter->Clear(); + this->StringInput.append(line); + this->StringInput.append("\n"); + return VR_OK; + } + catch (...) + { + this->AddError("AccumulateLine: An unhandled exception occured.\n"); + } + return VR_OUTOFMEMORY; +} + +int IPhreeqc2::RunAccumulated(void) +{ + static const char *sz_routine = "RunAccumulated"; + try + { + // this may throw + this->check_database(sz_routine); + + this->PhreeqcPtr->input_error = 0; + + // create input stream + std::istringstream iss(this->GetAccumulatedLines()); + + // this may throw + this->do_run(sz_routine, &iss, NULL, NULL, NULL, NULL); + } + catch (IPhreeqcStop) + { + // do nothing + } + catch(...) + { + const char *errmsg = "RunAccumulated: An unhandled exception occured.\n"; + try + { + this->PhreeqcPtr->error_msg(errmsg, STOP); // throws PhreeqcStop + } + catch (IPhreeqcStop) + { + // do nothing + } + } + + this->ClearAccumulatedLines(); + this->PhreeqcPtr->close_output_files(); + this->update_errors(); + + return this->PhreeqcPtr->input_error; +} + +int IPhreeqc2::RunFile(const char* filename) +{ + static const char *sz_routine = "RunFile"; + try + { + // this may throw + this->check_database(sz_routine); + + this->PhreeqcPtr->input_error = 0; + + // open file + // + std::ifstream ifs; + ifs.open(filename); + if (!ifs.is_open()) + { + std::ostringstream oss; + oss << "RunFile: Unable to open:" << "\"" << filename << "\"."; + this->PhreeqcPtr->error_msg(oss.str().c_str(), STOP); // throws + } + + // this may throw + this->do_run(sz_routine, &ifs, NULL, NULL, NULL, NULL); + } + catch (IPhreeqcStop) + { + this->PhreeqcPtr->close_input_files(); + } + catch(...) + { + const char *errmsg = "RunFile: An unhandled exception occured.\n"; + try + { + this->PhreeqcPtr->error_msg(errmsg, STOP); // throws PhreeqcStop + } + catch (IPhreeqcStop) + { + // do nothing + } + } + + this->PhreeqcPtr->close_output_files(); + this->update_errors(); + + return this->PhreeqcPtr->input_error; +} + +int IPhreeqc2::RunString(const char* input) +{ + static const char *sz_routine = "RunString"; + try + { + // this may throw + this->check_database(sz_routine); + + this->PhreeqcPtr->input_error = 0; + + // create input stream + std::string s(input); + std::istringstream iss(s); + + // this may throw + this->do_run(sz_routine, &iss, NULL, NULL, NULL, NULL); + } + catch (IPhreeqcStop) + { + this->PhreeqcPtr->close_input_files(); + } + catch(...) + { + const char *errmsg = "RunString: An unhandled exception occured.\n"; + try + { + this->PhreeqcPtr->error_msg(errmsg, STOP); // throws PhreeqcStop + } + catch (IPhreeqcStop) + { + // do nothing + } + } + + this->PhreeqcPtr->close_output_files(); + this->update_errors(); + + return this->PhreeqcPtr->input_error; +} + +int IPhreeqc2::GetSelectedOutputRowCount(void)const +{ + return (int)this->SelectedOutput->GetRowCount(); +} + +int IPhreeqc2::GetSelectedOutputColumnCount(void)const +{ + return (int)this->SelectedOutput->GetColCount(); +} + +VRESULT IPhreeqc2::GetSelectedOutputValue(int row, int col, VAR* pVAR) +{ + this->ErrorReporter->Clear(); + if (!pVAR) + { + this->AddError("GetSelectedOutputValue: VR_INVALIDARG pVAR is NULL.\n"); + this->update_errors(); + return VR_INVALIDARG; + } + + VRESULT v = this->SelectedOutput->Get(row, col, pVAR); + switch (v) + { + case VR_OK: + break; + case VR_OUTOFMEMORY: + this->AddError("GetSelectedOutputValue: VR_OUTOFMEMORY Out of memory.\n"); + break; + case VR_BADVARTYPE: + this->AddError("GetSelectedOutputValue: VR_BADVARTYPE pVar must be initialized(VarInit) and/or cleared(VarClear).\n"); + break; + case VR_INVALIDARG: + // not possible + break; + case VR_INVALIDROW: + this->AddError("GetSelectedOutputValue: VR_INVALIDROW Row index out of range.\n"); + break; + case VR_INVALIDCOL: + this->AddError("GetSelectedOutputValue: VR_INVALIDCOL Column index out of range.\n"); + break; + } + this->update_errors(); + return v; +} + +int IPhreeqc2::GetDumpLineCount(void)const +{ + return (int)this->DumpLines.size(); +} + +const char* IPhreeqc2::GetDumpLine(int n) +{ + static const char empty[] = ""; + if (n < 0 || n >= this->GetDumpLineCount()) + { + return empty; + } + return this->DumpLines[n].c_str(); +} + +int IPhreeqc2::GetErrorLineCount(void)const +{ + return (int)this->ErrorLines.size(); +} + +const char* IPhreeqc2::GetErrorLine(int n) +{ + static const char empty[] = ""; + if (n < 0 || n >= this->GetErrorLineCount()) + { + return empty; + } + return this->ErrorLines[n].c_str(); +} + +void IPhreeqc2::update_errors(void) +{ + this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); + + this->ErrorLines.clear(); + std::istringstream iss(this->LastErrorString); + std::string line; + while (std::getline(iss, line)) + { + this->ErrorLines.push_back(line); + } +} + +std::list< std::string > IPhreeqc2::ListComponents(void) +{ + std::list< std::string > comps; + this->PhreeqcPtr->list_components(comps); + return comps; +} + +size_t IPhreeqc2::GetComponentCount(void) +{ + std::list< std::string > comps; + this->PhreeqcPtr->list_components(comps); + return comps.size(); +} + +const char* IPhreeqc2::GetComponent(int n) +{ + static const char empty[] = ""; + this->Components = this->ListComponents(); + if (n < 0 || n >= (int)this->Components.size()) + { + return empty; + } + std::list< std::string >::iterator it = this->Components.begin(); + for(int i = 0; i < n; ++i) + { + ++it; + } + return (*it).c_str(); +} diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp new file mode 100644 index 00000000..de8ba6de --- /dev/null +++ b/IPhreeqcLib.cpp @@ -0,0 +1,468 @@ +#include "IPhreeqcLib.h" +#include "IPhreeqc2.h" +#include + + +int +CreateIPhreeqc(void) +{ + return IPhreeqcLib::CreateIPhreeqc(); +} + +IPL_RESULT +DestroyIPhreeqc(int n) +{ + return IPhreeqcLib::DestroyIPhreeqc(n); +} + +int +LoadDatabaseM(int n, const char* filename) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->LoadDatabase(filename); + } + return IPL_BADINSTANCE; +} + +int +LoadDatabaseStringM(int n, const char* input) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->LoadDatabaseString(input); + } + return IPL_BADINSTANCE; +} + +int +UnLoadDatabaseM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + IPhreeqcPtr->UnLoadDatabase(); + return IPL_OK; + } + return IPL_BADINSTANCE; +} + +const char* +GetLastErrorStringM(int n) +{ + static const char err_msg[] = "GetLastErrorString: Bad instance.\n"; + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetLastErrorString(); + } + return err_msg; +} + +const char* +GetDumpStringM(int n) +{ + static const char empty[] = ""; + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetDumpString(); + } + return empty; +} + +int +GetDumpLineCountM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetDumpLineCount(); + } + return 0; +} + +const char* +GetDumpLineM(int id, int n) +{ + static const char err_msg[] = "GetDumpLine: Bad instance.\n"; + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetDumpLine(n); + } + return err_msg; +} + +int +GetComponentCountM(int id) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->ListComponents().size(); + } + return 0; +} + +const char* +GetComponentM(int id, int n) +{ + static const char err_msg[] = "GetComponent: Bad instance.\n"; + static const char empty[] = ""; + static std::string comp; + + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + std::list< std::string > comps = IPhreeqcPtr->ListComponents(); + if (n < 0 || n >= (int)comps.size()) + { + return empty; + } + std::list< std::string >::iterator it = comps.begin(); + for(int i = 0; i < n; ++i) + { + ++it; + } + comp = (*it); + return comp.c_str(); + } + return err_msg; +} + +IPL_RESULT +AccumulateLineM(int n, const char *line) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + switch (IPhreeqcPtr->AccumulateLine(line)) + { + case VR_OK: + return IPL_OK; + case VR_OUTOFMEMORY: + return IPL_OUTOFMEMORY; + default: + assert(false); + } + } + return IPL_BADINSTANCE; +} + +int +GetSelectedOutputOnM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + if (IPhreeqcPtr->GetSelectedOutputOn()) + { + return 1; + } + else + { + return 0; + } + } + return IPL_BADINSTANCE; +} + +IPL_RESULT +SetSelectedOutputOnM(int n, int value) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + IPhreeqcPtr->SetSelectedOutputOn(value != 0); + return IPL_OK; + } + return IPL_BADINSTANCE; +} + +int +GetOutputOnM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + if (IPhreeqcPtr->GetOutputOn()) + { + return 1; + } + else + { + return 0; + } + } + return IPL_BADINSTANCE; +} + +IPL_RESULT +SetOutputOnM(int n, int value) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + IPhreeqcPtr->SetOutputOn(value != 0); + return IPL_OK; + } + return IPL_BADINSTANCE; +} + +int +GetErrorOnM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + if (IPhreeqcPtr->GetErrorOn()) + { + return 1; + } + else + { + return 0; + } + } + return IPL_BADINSTANCE; +} + +IPL_RESULT +SetErrorOnM(int n, int value) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + IPhreeqcPtr->SetErrorOn(value != 0); + return IPL_OK; + } + return IPL_BADINSTANCE; +} + +int +GetLogOnM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + if (IPhreeqcPtr->GetLogOn()) + { + return 1; + } + else + { + return 0; + } + } + return IPL_BADINSTANCE; +} + +IPL_RESULT +SetLogOnM(int n, int value) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + IPhreeqcPtr->SetLogOn(value != 0); + return IPL_OK; + } + return IPL_BADINSTANCE; +} + + +int +GetDumpOnM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + if (IPhreeqcPtr->GetDumpOn()) + { + return 1; + } + else + { + return 0; + } + } + return IPL_BADINSTANCE; +} + +IPL_RESULT +SetDumpOnM(int n, int value) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + IPhreeqcPtr->SetDumpOn(value != 0); + return IPL_OK; + } + return IPL_BADINSTANCE; +} + +int +GetDumpStringOnM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + if (IPhreeqcPtr->GetDumpStringOn()) + { + return 1; + } + else + { + return 0; + } + } + return IPL_BADINSTANCE; +} + +IPL_RESULT +SetDumpStringOnM(int n, int value) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + IPhreeqcPtr->SetDumpStringOn(value != 0); + return IPL_OK; + } + return IPL_BADINSTANCE; +} + +int +RunAccumulatedM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->RunAccumulated(); + } + return IPL_BADINSTANCE; +} + +int +RunFileM(int n, const char* filename) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->RunFile(filename); + } + return IPL_BADINSTANCE; +} + +int +GetSelectedOutputRowCountM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetSelectedOutputRowCount(); + } + return IPL_BADINSTANCE; +} + +int +GetSelectedOutputColumnCountM(int n) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetSelectedOutputColumnCount(); + } + return IPL_BADINSTANCE; +} + + +IPL_RESULT +GetSelectedOutputValueM(int n, int row, int col, VAR* pVAR) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + switch(IPhreeqcPtr->GetSelectedOutputValue(row, col, pVAR)) + { + case VR_OK: return IPL_OK; + case VR_OUTOFMEMORY: return IPL_OUTOFMEMORY; + case VR_BADVARTYPE: return IPL_BADVARTYPE; + case VR_INVALIDARG: return IPL_INVALIDARG; + case VR_INVALIDROW: return IPL_INVALIDROW; + case VR_INVALIDCOL: return IPL_INVALIDCOL; + default: + assert(false); + } + } + return IPL_BADINSTANCE; +} + +int +AddErrorM(int n, const char* error_msg) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + if (IPhreeqcPtr) + { + return (int)IPhreeqcPtr->AddError(error_msg); + } + return IPL_BADINSTANCE; +} + +std::map IPhreeqcLib::Instances; +size_t IPhreeqcLib::InstancesIndex = 0; + +int +IPhreeqcLib::CreateIPhreeqc(void) +{ + int n = IPL_OUTOFMEMORY; + try + { + IPhreeqc2* IPhreeqcPtr = new IPhreeqc2; + if (IPhreeqcPtr) + { + std::map::value_type instance(IPhreeqcLib::InstancesIndex, IPhreeqcPtr); + std::pair::iterator, bool> pr = IPhreeqcLib::Instances.insert(instance); + if (pr.second) + { + n = (int) (*pr.first).first; + ++IPhreeqcLib::InstancesIndex; + } + } + } + catch(...) + { + return IPL_OUTOFMEMORY; + } + return n; +} + +IPL_RESULT +IPhreeqcLib::DestroyIPhreeqc(int n) +{ + IPL_RESULT retval = IPL_BADINSTANCE; + if (n >= 0) + { + std::map::iterator it = IPhreeqcLib::Instances.find(size_t(n)); + if (it != IPhreeqcLib::Instances.end()) + { + delete (*it).second; + IPhreeqcLib::Instances.erase(it); + retval = IPL_OK; + } + } + return retval; +} + +IPhreeqc2* +IPhreeqcLib::GetInstance(int n) +{ + std::map::iterator it = IPhreeqcLib::Instances.find(size_t(n)); + if (it != IPhreeqcLib::Instances.end()) + { + return (*it).second; + } + return 0; +} + diff --git a/module_files.cpp b/module_files.cpp index 3c27973d..7bfbab3b 100644 --- a/module_files.cpp +++ b/module_files.cpp @@ -2,12 +2,15 @@ #if defined(R_SO) #include "phreeqc_files.inl" #else -#include "phreeqcpp/phreeqc/phreeqc_files.c" +// COMMENT: {3/25/2010 12:36:14 PM}#include "phreeqcpp/phreeqc/phreeqc_files.c" #endif // COMMENT: {3/2/2010 4:06:35 PM}static int module_isopen_handler(const int type); // COMMENT: {3/2/2010 4:06:35 PM}static int module_open_handler(const int type, const char *file_name); +//{{{3/25/2010 12:37:19 PM} +#include +//}}{3/25/2010 12:37:19 PM} #include "IPhreeqc.hpp" int IPhreeqc::module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) diff --git a/module_output.cpp b/module_output.cpp index 51d2fc45..70c1561a 100644 --- a/module_output.cpp +++ b/module_output.cpp @@ -5,7 +5,7 @@ #if defined(R_SO) #include "output.inl" #else -#include "phreeqcpp/phreeqc/output.c" +// COMMENT: {3/25/2010 12:36:24 PM}#include "phreeqcpp/phreeqc/output.c" #endif From c48a3533d72ea9e1bc8dd0e39242fc4466362267 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 2 Apr 2010 00:43:29 +0000 Subject: [PATCH 18/32] RunF => RunAccumulatedF git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4202 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- fwrap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fwrap.cpp b/fwrap.cpp index 949ffd53..0dbe0a6c 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -13,7 +13,7 @@ compile fortran with: #if defined(__GNUC__) #define LoadDatabaseF loaddatabasef_ #define AccumulateLineF accumulatelinef_ -#define RunF runf_ +#define RunAccumulatedF runaccumulatedf_ #define RunFileF runfilef_ #define GetSelectedOutputValueF getselectedoutputvaluef_ #define OutputLastErrorF outputlasterrorf_ From f8d6737e83a9e5b8f968aa7d48bff93d5021e3c2 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 3 Apr 2010 03:57:22 +0000 Subject: [PATCH 19/32] updated for linux git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4210 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc2.cpp | 22 ++++++++++------------ IPhreeqcF.F | 19 +++++++++---------- fwrap.cpp | 3 ++- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/IPhreeqc2.cpp b/IPhreeqc2.cpp index 232f36b1..4f0c5f9f 100644 --- a/IPhreeqc2.cpp +++ b/IPhreeqc2.cpp @@ -1,13 +1,11 @@ #include "IPhreeqc2.h" +#include "Phreeqc.h" // Phreeqc -// COMMENT: {3/25/2010 7:28:15 PM}#define protected public -#include "Phreeqc.h" /* Phreeqc */ -// COMMENT: {3/25/2010 7:28:18 PM}#undef protected - -#include -#include "ErrorReporter.hxx" -#include "SelectedOutput.hxx" -#include "dumper.h" +#include // assert +#include // auto_ptr +#include "ErrorReporter.hxx" // CErrorReporter +#include "SelectedOutput.hxx" // CSelectedOutput +#include "dumper.h" // dumper int istream_getc(void *cookie); @@ -22,16 +20,16 @@ const char LOG_FILENAME[] = "phreeqc.log"; const char PUNCH_FILENAME[] = "selected.out"; IPhreeqc2::IPhreeqc2(void) -: ErrorReporter(0) -, WarningReporter(0) -, SelectedOutput(0) -, DatabaseLoaded(false) +: DatabaseLoaded(false) , SelectedOutputOn(false) , OutputOn(false) , LogOn(false) , ErrorOn(false) , DumpOn(false) , DumpStringOn(false) +, ErrorReporter(0) +, WarningReporter(0) +, SelectedOutput(0) , PhreeqcPtr(0) { this->ErrorReporter = new CErrorReporter; diff --git a/IPhreeqcF.F b/IPhreeqcF.F index fdf25dd5..a0dcb2d5 100644 --- a/IPhreeqcF.F +++ b/IPhreeqcF.F @@ -51,16 +51,16 @@ AccumulateLine = AccumulateLineF(LINE) END FUNCTION AccumulateLine !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION Run(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) + FUNCTION RunAccumulated(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) IMPLICIT NONE LOGICAL :: OUTPUT_ON LOGICAL :: ERROR_ON LOGICAL :: LOG_ON LOGICAL :: SELECTED_ON - INTEGER :: Run + INTEGER :: RunAccumulated #if defined(_WIN32) INTERFACE - FUNCTION RunF(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) + FUNCTION RunAccumulatedF(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) !DEC$ ATTRIBUTES C,REFERENCE::RunF !DEC$ ATTRIBUTES ALIAS:'_RunF'::RunF LOGICAL(KIND=4) :: OUTPUT_ON @@ -68,13 +68,14 @@ LOGICAL(KIND=4) :: LOG_ON LOGICAL(KIND=4) :: SELECTED_ON INTEGER(KIND=4) :: RunF - END FUNCTION RunF + END FUNCTION RunAccumulatedF END INTERFACE #else - INTEGER :: RunF + INTEGER :: RunAccumulatedF #endif - Run = RunF(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) - END FUNCTION Run + RunAccumulated = RunAccumulatedF(OUTPUT_ON, ERROR_ON, + & LOG_ON, SELECTED_ON) + END FUNCTION RunAccumulated !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FUNCTION RunFile(FILENAME,OUTPUT_ON,ERROR_ON,LOG_ON,SELECTED_ON) IMPLICIT NONE @@ -161,7 +162,6 @@ REAL*8 :: DVALUE CHARACTER(LEN=*) :: SVALUE INTEGER :: GetSelectedOutputValue - INTEGER :: adjcol #if defined(_WIN32) INTERFACE FUNCTION Get(ROW,COL,VTYPE,DVALUE,SVALUE) @@ -179,9 +179,8 @@ GetSelectedOutputValue = Get(ROW,adjcol,VTYPE,DVALUE,SVALUE) #else INTEGER :: GetSelectedOutputValueF - adjcol = col - 1 GetSelectedOutputValue = GetSelectedOutputValueF(ROW, - & adjcol,VTYPE,DVALUE,SVALUE) + & COL,VTYPE,DVALUE,SVALUE) #endif END FUNCTION GetSelectedOutputValue !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/fwrap.cpp b/fwrap.cpp index 0dbe0a6c..d62c89f1 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -2,6 +2,7 @@ #include /* malloc */ #include /* memcpy */ #include /* assert */ +#include /* sprintf */ #include "phrqtype.h" #include "IPhreeqc.h" @@ -257,7 +258,7 @@ GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* sv case TT_LONG: *vtype = TT_DOUBLE; *dvalue = (double)v.lVal; - ::sprintf(buffer, "%d", v.lVal); + ::sprintf(buffer, "%ld", v.lVal); padfstring(svalue, buffer, svalue_length); break; case TT_DOUBLE: From 44cd787d98fb11f3b2276504ce65ce0909708747 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 5 Apr 2010 22:38:14 +0000 Subject: [PATCH 20/32] Added TestRunString to cunit git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4211 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqcLib.cpp | 125 ++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 57 deletions(-) diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp index de8ba6de..55cf6dfa 100644 --- a/IPhreeqcLib.cpp +++ b/IPhreeqcLib.cpp @@ -10,15 +10,15 @@ CreateIPhreeqc(void) } IPL_RESULT -DestroyIPhreeqc(int n) +DestroyIPhreeqc(int id) { - return IPhreeqcLib::DestroyIPhreeqc(n); + return IPhreeqcLib::DestroyIPhreeqc(id); } int -LoadDatabaseM(int n, const char* filename) +LoadDatabaseM(int id, const char* filename) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->LoadDatabase(filename); @@ -27,9 +27,9 @@ LoadDatabaseM(int n, const char* filename) } int -LoadDatabaseStringM(int n, const char* input) +LoadDatabaseStringM(int id, const char* input) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->LoadDatabaseString(input); @@ -38,9 +38,9 @@ LoadDatabaseStringM(int n, const char* input) } int -UnLoadDatabaseM(int n) +UnLoadDatabaseM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->UnLoadDatabase(); @@ -50,10 +50,10 @@ UnLoadDatabaseM(int n) } const char* -GetLastErrorStringM(int n) +GetLastErrorStringM(int id) { static const char err_msg[] = "GetLastErrorString: Bad instance.\n"; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetLastErrorString(); @@ -62,10 +62,10 @@ GetLastErrorStringM(int n) } const char* -GetDumpStringM(int n) +GetDumpStringM(int id) { static const char empty[] = ""; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetDumpString(); @@ -74,9 +74,9 @@ GetDumpStringM(int n) } int -GetDumpLineCountM(int n) +GetDumpLineCountM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetDumpLineCount(); @@ -134,9 +134,9 @@ GetComponentM(int id, int n) } IPL_RESULT -AccumulateLineM(int n, const char *line) +AccumulateLineM(int id, const char *line) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { switch (IPhreeqcPtr->AccumulateLine(line)) @@ -153,9 +153,9 @@ AccumulateLineM(int n, const char *line) } int -GetSelectedOutputOnM(int n) +GetSelectedOutputOnM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetSelectedOutputOn()) @@ -171,9 +171,9 @@ GetSelectedOutputOnM(int n) } IPL_RESULT -SetSelectedOutputOnM(int n, int value) +SetSelectedOutputOnM(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetSelectedOutputOn(value != 0); @@ -183,9 +183,9 @@ SetSelectedOutputOnM(int n, int value) } int -GetOutputOnM(int n) +GetOutputOnM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetOutputOn()) @@ -201,9 +201,9 @@ GetOutputOnM(int n) } IPL_RESULT -SetOutputOnM(int n, int value) +SetOutputOnM(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetOutputOn(value != 0); @@ -213,9 +213,9 @@ SetOutputOnM(int n, int value) } int -GetErrorOnM(int n) +GetErrorOnM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetErrorOn()) @@ -231,9 +231,9 @@ GetErrorOnM(int n) } IPL_RESULT -SetErrorOnM(int n, int value) +SetErrorOnM(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetErrorOn(value != 0); @@ -243,9 +243,9 @@ SetErrorOnM(int n, int value) } int -GetLogOnM(int n) +GetLogOnM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetLogOn()) @@ -261,9 +261,9 @@ GetLogOnM(int n) } IPL_RESULT -SetLogOnM(int n, int value) +SetLogOnM(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetLogOn(value != 0); @@ -274,9 +274,9 @@ SetLogOnM(int n, int value) int -GetDumpOnM(int n) +GetDumpOnM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetDumpOn()) @@ -292,9 +292,9 @@ GetDumpOnM(int n) } IPL_RESULT -SetDumpOnM(int n, int value) +SetDumpOnM(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetDumpOn(value != 0); @@ -304,9 +304,9 @@ SetDumpOnM(int n, int value) } int -GetDumpStringOnM(int n) +GetDumpStringOnM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetDumpStringOn()) @@ -322,9 +322,9 @@ GetDumpStringOnM(int n) } IPL_RESULT -SetDumpStringOnM(int n, int value) +SetDumpStringOnM(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetDumpStringOn(value != 0); @@ -334,9 +334,9 @@ SetDumpStringOnM(int n, int value) } int -RunAccumulatedM(int n) +RunAccumulatedM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->RunAccumulated(); @@ -345,9 +345,9 @@ RunAccumulatedM(int n) } int -RunFileM(int n, const char* filename) +RunFileM(int id, const char* filename) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->RunFile(filename); @@ -356,9 +356,20 @@ RunFileM(int n, const char* filename) } int -GetSelectedOutputRowCountM(int n) +RunStringM(int id, const char* input) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->RunString(input); + } + return IPL_BADINSTANCE; +} + +int +GetSelectedOutputRowCountM(int id) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetSelectedOutputRowCount(); @@ -367,9 +378,9 @@ GetSelectedOutputRowCountM(int n) } int -GetSelectedOutputColumnCountM(int n) +GetSelectedOutputColumnCountM(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetSelectedOutputColumnCount(); @@ -379,9 +390,9 @@ GetSelectedOutputColumnCountM(int n) IPL_RESULT -GetSelectedOutputValueM(int n, int row, int col, VAR* pVAR) +GetSelectedOutputValueM(int id, int row, int col, VAR* pVAR) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { switch(IPhreeqcPtr->GetSelectedOutputValue(row, col, pVAR)) @@ -400,9 +411,9 @@ GetSelectedOutputValueM(int n, int row, int col, VAR* pVAR) } int -AddErrorM(int n, const char* error_msg) +AddErrorM(int id, const char* error_msg) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(n); + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return (int)IPhreeqcPtr->AddError(error_msg); @@ -439,12 +450,12 @@ IPhreeqcLib::CreateIPhreeqc(void) } IPL_RESULT -IPhreeqcLib::DestroyIPhreeqc(int n) +IPhreeqcLib::DestroyIPhreeqc(int id) { IPL_RESULT retval = IPL_BADINSTANCE; - if (n >= 0) + if (id >= 0) { - std::map::iterator it = IPhreeqcLib::Instances.find(size_t(n)); + std::map::iterator it = IPhreeqcLib::Instances.find(size_t(id)); if (it != IPhreeqcLib::Instances.end()) { delete (*it).second; @@ -456,9 +467,9 @@ IPhreeqcLib::DestroyIPhreeqc(int n) } IPhreeqc2* -IPhreeqcLib::GetInstance(int n) +IPhreeqcLib::GetInstance(int id) { - std::map::iterator it = IPhreeqcLib::Instances.find(size_t(n)); + std::map::iterator it = IPhreeqcLib::Instances.find(size_t(id)); if (it != IPhreeqcLib::Instances.end()) { return (*it).second; From 0a15d767a58fcd10eed12d4637dd63a1177aede7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Apr 2010 20:56:38 +0000 Subject: [PATCH 21/32] Remove from unit: TestInterface.cpp TestInterface.h IPhreeqc.hpp IPhreeqc.h IPhreeqc.cpp module_output.cpp module_files.cpp fwrap.cpp fwrap2.cpp fwrap3.cpp IPhreeqc.cpp CVar.hxx ErrorReporter.hxx OutputFiles.hxx Phreeqc.hxx PhreeqcParser.hxx SelectedOutput.hxx Var.h Remove from IPhreeqc IPhreeqc.cpp IPhreeqc.h IPhreeqc.hpp module_output.cpp module_files.cpp git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4213 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 1931 ----------------------------------------------- IPhreeqc2.cpp | 28 +- IPhreeqcLib.cpp | 51 ++ fwrap.cpp | 259 ++++--- fwrap.h | 45 +- fwrap2.cpp | 94 +-- fwrap3.cpp | 94 +-- 7 files changed, 329 insertions(+), 2173 deletions(-) delete mode 100644 IPhreeqc.cpp diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp deleted file mode 100644 index ca33ba43..00000000 --- a/IPhreeqc.cpp +++ /dev/null @@ -1,1931 +0,0 @@ -#include -#include -#include "IPhreeqc.h" -#include "IPhreeqc.hpp" -#include "ErrorReporter.hxx" - -int istream_getc(void *cookie); - -const char OUTPUT_FILENAME[] = "phreeqc.out"; -const char ERROR_FILENAME[] = "phreeqc.err"; -const char LOG_FILENAME[] = "phreeqc.log"; -const char PUNCH_FILENAME[] = "selected.out"; - -int -LoadDatabase(const char* filename) -{ - return IPhreeqc::LibraryInstance()->LoadDatabase(filename); -} - -// COMMENT: {3/29/2010 10:18:52 PM}int -// COMMENT: {3/29/2010 10:18:52 PM}LoadDatabaseM(int n, const char* filename) -// COMMENT: {3/29/2010 10:18:52 PM}{ -// COMMENT: {3/29/2010 10:18:52 PM} IPhreeqc* IPhreeqcPtr = IPhreeqc::GetInstance(n); -// COMMENT: {3/29/2010 10:18:52 PM} if (IPhreeqcPtr) -// COMMENT: {3/29/2010 10:18:52 PM} { -// COMMENT: {3/29/2010 10:18:52 PM} return IPhreeqcPtr->LoadDatabase(filename); -// COMMENT: {3/29/2010 10:18:52 PM} } -// COMMENT: {3/29/2010 10:18:52 PM} return PHR_BADINSTANCE; -// COMMENT: {3/29/2010 10:18:52 PM}} - -int -LoadDatabaseString(const char* input) -{ - return IPhreeqc::LibraryInstance()->LoadDatabaseString(input); -} - -void -UnLoadDatabase(void) -{ - IPhreeqc::LibraryInstance()->UnLoadDatabase(); -} - -void -OutputLastError(void) -{ - IPhreeqc::LibraryInstance()->OutputLastError(); -} - -const char* -GetLastErrorString(void) -{ - return IPhreeqc::LibraryInstance()->GetLastErrorString(); -} - -const char* -GetLastWarningString(void) -{ - return IPhreeqc::LibraryInstance()->GetLastWarningString(); -} - -const char* -GetDumpString(void) -{ - return IPhreeqc::LibraryInstance()->GetDumpString(); -} - - -VRESULT -AccumulateLine(const char *line) -{ - return IPhreeqc::LibraryInstance()->AccumulateLine(line); -} - -void -SetSelectedOutputOn(int value) -{ - return IPhreeqc::LibraryInstance()->SetSelectedOutputOn(value != 0); -} - -void -SetOutputOn(int value) -{ - return IPhreeqc::LibraryInstance()->SetOutputOn(value != 0); -} - -void -SetErrorOn(int value) -{ - return IPhreeqc::LibraryInstance()->SetErrorOn(value != 0); -} - -void -SetLogOn(int value) -{ - return IPhreeqc::LibraryInstance()->SetLogOn(value != 0); -} - -void -SetDumpOn(int value) -{ - return IPhreeqc::LibraryInstance()->SetDumpOn(value != 0); -} - -void -SetDumpStringOn(int value) -{ - return IPhreeqc::LibraryInstance()->SetDumpStringOn(value != 0); -} - -int -RunAccumulated(void) -{ - return IPhreeqc::LibraryInstance()->RunAccumulated(); -} - -int -RunFile(const char* filename) -{ - return IPhreeqc::LibraryInstance()->RunFile(filename); -} - -int -RunString(const char* input) -{ - return IPhreeqc::LibraryInstance()->RunString(input); -} - -int -GetSelectedOutputRowCount(void) -{ - return (int)IPhreeqc::LibraryInstance()->GetSelectedOutputRowCount(); -} - -int -GetSelectedOutputColumnCount(void) -{ - return (int)IPhreeqc::LibraryInstance()->GetSelectedOutputColumnCount(); -} - -VRESULT -GetSelectedOutputValue(int row, int col, VAR* pVAR) -{ - return IPhreeqc::LibraryInstance()->GetSelectedOutputValue(row, col, pVAR); -} - -size_t -AddError(const char* error_msg) -{ - return IPhreeqc::LibraryInstance()->AddError(error_msg); -} - - -void -OutputLines(void) -{ - IPhreeqc::LibraryInstance()->OutputLines(); -} - -const std::string& -GetAccumulatedLines(void) -{ - return IPhreeqc::LibraryInstance()->GetAccumulatedLines(); -} - -void -ClearAccumulatedLines(void) -{ - IPhreeqc::LibraryInstance()->ClearAccumulatedLines(); -} - -int -GetDumpLineCount(void) -{ - return IPhreeqc::LibraryInstance()->GetDumpLineCount(); -} - -const char* -GetDumpLine(int n) -{ - return IPhreeqc::LibraryInstance()->GetDumpLine(n); -} - -int -GetErrorLineCount(void) -{ - return IPhreeqc::LibraryInstance()->GetErrorLineCount(); -} - -const char* -GetErrorLine(int n) -{ - return IPhreeqc::LibraryInstance()->GetErrorLine(n); -} - -int -GetComponentCount(void) -{ - return (int)IPhreeqc::LibraryInstance()->ListComponents().size(); -} - -const char* -GetComponent(int n) -{ - static const char empty[] = ""; - static std::string comp; - std::list< std::string > comps = IPhreeqc::LibraryInstance()->ListComponents(); - if (n < 0 || n >= (int)comps.size()) - { - return empty; - } - std::list< std::string >::iterator it = comps.begin(); - for(int i = 0; i < n; ++i) - { - ++it; - } - comp = (*it); - return comp.c_str(); -} - - -IPhreeqc::IPhreeqc(void) -: Phreeqc() -, ErrorReporter(0) -, WarningReporter(0) -, SelectedOutput(0) -, DatabaseLoaded(false) -, SelectedOutputOn(false) -, OutputOn(false) -, LogOn(false) -, ErrorOn(false) -, DumpOn(false) -, DumpStringOn(false) -{ - ASSERT(this->phast == 0); - this->ErrorReporter = new CErrorReporter; - this->WarningReporter = new CErrorReporter; - this->SelectedOutput = new CSelectedOutput(); -// COMMENT: {3/25/2010 2:37:54 PM} this->init(); - this->UnLoadDatabase(); -} - -IPhreeqc::~IPhreeqc(void) -{ - delete this->ErrorReporter; - delete this->WarningReporter; - delete this->SelectedOutput; -} - -// COMMENT: {4/1/2010 5:52:55 PM}std::map IPhreeqc::Instances; -// COMMENT: {4/1/2010 5:52:55 PM}size_t IPhreeqc::InstancesIndex = 0; -// COMMENT: {4/1/2010 5:52:55 PM} -// COMMENT: {4/1/2010 5:52:55 PM}int -// COMMENT: {4/1/2010 5:52:55 PM}IPhreeqc::CreateIPhreeqc(void) -// COMMENT: {4/1/2010 5:52:55 PM}{ -// COMMENT: {4/1/2010 5:52:55 PM} int n = -1; -// COMMENT: {4/1/2010 5:52:55 PM} try -// COMMENT: {4/1/2010 5:52:55 PM} { -// COMMENT: {4/1/2010 5:52:55 PM} IPhreeqc* IPhreeqcPtr = new IPhreeqc; -// COMMENT: {4/1/2010 5:52:55 PM} if (IPhreeqcPtr) -// COMMENT: {4/1/2010 5:52:55 PM} { -// COMMENT: {4/1/2010 5:52:55 PM} std::map::value_type instance(IPhreeqc::InstancesIndex, IPhreeqcPtr); -// COMMENT: {4/1/2010 5:52:55 PM} std::pair::iterator, bool> pr = IPhreeqc::Instances.insert(instance); -// COMMENT: {4/1/2010 5:52:55 PM} if (pr.second) -// COMMENT: {4/1/2010 5:52:55 PM} { -// COMMENT: {4/1/2010 5:52:55 PM} n = (int) (*pr.first).first; -// COMMENT: {4/1/2010 5:52:55 PM} ++IPhreeqc::InstancesIndex; -// COMMENT: {4/1/2010 5:52:55 PM} } -// COMMENT: {4/1/2010 5:52:55 PM} } -// COMMENT: {4/1/2010 5:52:55 PM} } -// COMMENT: {4/1/2010 5:52:55 PM} catch(...) -// COMMENT: {4/1/2010 5:52:55 PM} { -// COMMENT: {4/1/2010 5:52:55 PM} return -1; -// COMMENT: {4/1/2010 5:52:55 PM} } -// COMMENT: {4/1/2010 5:52:55 PM} return n; -// COMMENT: {4/1/2010 5:52:55 PM}} -// COMMENT: {4/1/2010 5:52:55 PM} -// COMMENT: {4/1/2010 5:52:55 PM}int -// COMMENT: {4/1/2010 5:52:55 PM}IPhreeqc::DestroyIPhreeqc(int n) -// COMMENT: {4/1/2010 5:52:55 PM}{ -// COMMENT: {4/1/2010 5:52:55 PM} int retval = PHR_BADINSTANCE; -// COMMENT: {4/1/2010 5:52:55 PM} if (n >= 0) -// COMMENT: {4/1/2010 5:52:55 PM} { -// COMMENT: {4/1/2010 5:52:55 PM} std::map::iterator it = IPhreeqc::Instances.find(size_t(n)); -// COMMENT: {4/1/2010 5:52:55 PM} if (it != IPhreeqc::Instances.end()) -// COMMENT: {4/1/2010 5:52:55 PM} { -// COMMENT: {4/1/2010 5:52:55 PM} delete (*it).second; -// COMMENT: {4/1/2010 5:52:55 PM} IPhreeqc::Instances.erase(it); -// COMMENT: {4/1/2010 5:52:55 PM} retval = 0; -// COMMENT: {4/1/2010 5:52:55 PM} } -// COMMENT: {4/1/2010 5:52:55 PM} } -// COMMENT: {4/1/2010 5:52:55 PM} return retval; -// COMMENT: {4/1/2010 5:52:55 PM}} -// COMMENT: {4/1/2010 5:52:55 PM} -// COMMENT: {4/1/2010 5:52:55 PM}IPhreeqc* -// COMMENT: {4/1/2010 5:52:55 PM}IPhreeqc::GetInstance(int n) -// COMMENT: {4/1/2010 5:52:55 PM}{ -// COMMENT: {4/1/2010 5:52:55 PM} std::map::iterator it = IPhreeqc::Instances.find(size_t(n)); -// COMMENT: {4/1/2010 5:52:55 PM} if (it != IPhreeqc::Instances.end()) -// COMMENT: {4/1/2010 5:52:55 PM} { -// COMMENT: {4/1/2010 5:52:55 PM} return (*it).second; -// COMMENT: {4/1/2010 5:52:55 PM} } -// COMMENT: {4/1/2010 5:52:55 PM} return 0; -// COMMENT: {4/1/2010 5:52:55 PM}} - -// the library singleton -IPhreeqc* IPhreeqc::Instance = 0; - -IPhreeqc* IPhreeqc::LibraryInstance() -{ - if (IPhreeqc::Instance == 0) - { - IPhreeqc::Instance = new IPhreeqc; - } - return IPhreeqc::Instance; -} - -int Phreeqc::EndRow(void) -{ - return OK; -} - -int IPhreeqc::EndRow(void) -{ - if (this->SelectedOutput->GetRowCount() <= 1) - { - // ensure all user_punch headings are included - for (int i = this->n_user_punch_index; i < this->user_punch_count_headings; ++i) - { - this->SelectedOutput->PushBackEmpty(this->user_punch_headings[i]); - } - } - return this->SelectedOutput->EndRow(); -} - -void IPhreeqc::ClearAccumulatedLines(void) -{ - this->StringInput.erase(); -} - -size_t IPhreeqc::AddError(const char* error_msg) -{ - return this->ErrorReporter->AddError(error_msg); -} - -size_t IPhreeqc::AddWarning(const char* error_msg) -{ - return this->WarningReporter->AddError(error_msg); -} - -const std::string& IPhreeqc::GetAccumulatedLines(void) -{ - return this->StringInput; -} - -void IPhreeqc::OutputLines(void) -{ - std::cout << this->StringInput.c_str() << std::endl; -} - -void IPhreeqc::UnLoadDatabase(void) -{ - // init IPhreeqc - // - this->DatabaseLoaded = false; - - // clear error state - // - ASSERT(this->ErrorReporter); - this->ErrorReporter->Clear(); - this->LastErrorString.clear(); - - // clear warning state - // - ASSERT(this->WarningReporter); - this->WarningReporter->Clear(); - this->LastWarningString.clear(); - - // clear selectedoutput - // - ASSERT(this->SelectedOutput); - this->SelectedOutput->Clear(); - - // clear dump string - // - this->DumpString.clear(); - this->DumpLines.clear(); - - // initialize phreeqc - // - this->clean_up(); - this->add_output_callback(IPhreeqc::handler, this); - this->do_initialize(); - this->input_error = 0; -} - -int IPhreeqc::LoadDatabase(const char* filename) -{ - try - { - // cleanup - // - this->UnLoadDatabase(); - this->SelectedOutput->Clear(); - - // open file - // - std::ifstream ifs; - ifs.open(filename); - - if (!ifs.is_open()) - { - std::ostringstream oss; - oss << "LoadDatabase: Unable to open:" << "\"" << filename << "\"."; - this->error_msg(oss.str().c_str(), STOP); // throws - } - - // read input - // - this->read_database(istream_getc, &ifs); - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - catch (...) - { - const char *errmsg = "LoadDatabase: An unhandled exception occured.\n"; - try - { - this->error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - } - -#if defined(_WIN32) - int n = ::_fcloseall(); - assert(n == 0); -#endif - - this->DatabaseLoaded = (this->input_error == 0); - return this->input_error; -} - -int IPhreeqc::LoadDatabaseString(const char* input) -{ - try - { - // cleanup - // - this->UnLoadDatabase(); - - this->SelectedOutput->Clear(); - - std::string s(input); - std::istringstream iss(s); - - // read input - // - this->read_database(istream_getc, &iss); - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - catch(...) - { - const char *errmsg = "LoadDatabaseString: An unhandled exception occured.\n"; - try - { - this->error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - } - - this->DatabaseLoaded = (this->input_error == 0); - return this->input_error; -} - -void IPhreeqc::OutputLastError(void) -{ - std::cout << this->GetLastErrorString() << std::endl; -} - -const char* IPhreeqc::GetLastErrorString(void) -{ - this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); - return this->LastErrorString.c_str(); -} - -const char* IPhreeqc::GetLastWarningString(void) -{ - this->LastWarningString = ((CErrorReporter*)this->WarningReporter)->GetOS()->str(); - return this->LastWarningString.c_str(); -} - - -const char* IPhreeqc::GetDumpString(void) -{ - return this->DumpString.c_str(); -} - -void IPhreeqc::check_database(const char* sz_routine) -{ - this->ErrorReporter->Clear(); - this->SelectedOutput->Clear(); - - if (!this->DatabaseLoaded) - { - std::ostringstream oss; - oss << sz_routine << ": No database is loaded"; - this->input_error = 1; - this->error_msg(oss.str().c_str(), STOP); // throws PhreeqcStop - } -} - -void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie) -{ - std::auto_ptr auto_iss(NULL); - char token[MAX_LENGTH]; - - if (this->OutputOn) - { - if (this->output_open(OUTPUT_MESSAGE, OUTPUT_FILENAME) != OK) - { - std::ostringstream oss; - oss << sz_routine << ": Unable to open:" << "\"" << OUTPUT_FILENAME << "\".\n"; - this->warning_msg(oss.str().c_str()); - } - } - if (this->ErrorOn) - { - if (this->output_open(OUTPUT_ERROR, ERROR_FILENAME) != OK) - { - std::ostringstream oss; - oss << sz_routine << ": Unable to open:" << "\"" << ERROR_FILENAME << "\".\n"; - this->warning_msg(oss.str().c_str()); - } - } - if (this->LogOn) - { - if (this->output_open(OUTPUT_LOG, LOG_FILENAME) != OK) - { - std::ostringstream oss; - oss << sz_routine << ": Unable to open:" << "\"" << LOG_FILENAME << "\".\n"; - this->warning_msg(oss.str().c_str()); - } - } - -/* - * call pre-run callback - */ - if (pfn_pre) - { - pfn_pre(cookie); - } - -/* - * set read callback - */ - if (!pis) - { - if (fp) - { - this->set_read_callback(getc_callback, fp, FALSE); - } - else - { - std::auto_ptr a_iss(new std::istringstream(this->GetAccumulatedLines())); - auto_iss = a_iss; - this->set_read_callback(istream_getc, auto_iss.get(), FALSE); - } - } - else - { - this->set_read_callback(istream_getc, pis, FALSE); - } - - -/* - * Read input data for simulation - */ - for (this->simulation = 1; ; this->simulation++) { - -#ifdef PHREEQ98 - AddSeries = !connect_simulations; -#endif - ::sprintf(token, "Reading input data for simulation %d.", simulation); - - this->output_msg(OUTPUT_GUI_ERROR, "\nSimulation %d\n", simulation); - -#ifdef SWIG_SHARED_OBJ - int save_punch_in = this->punch.in; -#endif // SWIG_SHARED_OBJ -// COMMENT: {3/3/2010 10:46:12 PM} dup_print(token, TRUE); - if (this->read_input() == EOF) break; - -#ifdef SWIG_SHARED_OBJ - if (this->simulation > 1 && save_punch_in == TRUE && this->punch.new_def == TRUE) - { - std::ostringstream oss; - oss << sz_routine << ": Warning SELECTED_OUTPUT has been redefined.\n"; - this->warning_msg(oss.str().c_str()); - - } - if (this->simulation > 1 && this->keyword[39].keycount > 0) - { - std::ostringstream oss; - oss << sz_routine << ": Warning USER_PUNCH has been redefined.\n"; - this->warning_msg(oss.str().c_str()); - } -#endif // SWIG_SHARED_OBJ - - if (this->title_x != NULL) { - ::sprintf(token, "TITLE"); - this->dup_print(token, TRUE); - if (this->pr.headings == TRUE) this->output_msg(OUTPUT_MESSAGE, "%s\n\n", this->title_x); - } - -#ifdef SWIG_SHARED_OBJ - if (this->punch.in == TRUE) - { - // - // (punch.in == TRUE) when any "RUN" has contained - // a SELECTED_OUTPUT block since the last LoadDatabase call. - // - // Since LoadDatabase inititializes punch.in to FALSE - // (via UnLoadDatabase...do_initialize) - // and punch.in is set to TRUE in read_selected_output - // - // This causes the SELECTED_OUTPUT to contain the same headings - // until another SELECTED_OUTPUT is defined which sets the variable - // punch.new_def to TRUE - // - // WHAT IF A USER_PUNCH IS DEFINED?? IS punch.new_def SET TO - // TRUE ??? - // - // - if (!this->SelectedOutputOn) ASSERT(!this->output_isopen(OUTPUT_PUNCH)); - - if (this->pr.punch == FALSE) - { - // No selected_output for this simulation - // this happens when - // PRINT; -selected_output false - // is given as input - // Note: this also disables the CSelectedOutput object - } - else - { - if (this->punch.new_def == FALSE) - { - if (this->SelectedOutputOn && !this->output_isopen(OUTPUT_PUNCH)) - { - // - // LoadDatabase - // do_run -- containing SELECTED_OUTPUT ****TODO**** check -file option - // another do_run without SELECTED_OUTPUT - // - std::string filename = this->PunchFileName; - this->output_open(OUTPUT_PUNCH, filename.c_str()); - if (!this->output_isopen(OUTPUT_PUNCH)) - { - std::ostringstream oss; - oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n"; - this->warning_msg(oss.str().c_str()); - } - else - { - // output selected_output headings - this->punch.new_def = TRUE; - this->tidy_punch(); - } - } - } - else - { - if (this->SelectedOutputOn && !this->output_isopen(OUTPUT_PUNCH)) - { - // This is a special case which could not occur in - // phreeqc - // - // LoadDatabase - // do_run -- containing SELECTED_OUTPUT ****TODO**** check -file option - // another do_run with SELECTED_OUTPUT - // - std::string filename = PUNCH_FILENAME; - if (this->PunchFileName.size()) - { - filename = this->PunchFileName; - } - this->output_open(OUTPUT_PUNCH, filename.c_str()); - if (!this->output_isopen(OUTPUT_PUNCH)) - { - std::ostringstream oss; - oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n"; - this->warning_msg(oss.str().c_str()); - } - else - { - // output selected_output headings - ASSERT(punch.new_def == TRUE); - this->tidy_punch(); - } - } - } - } - } - - if (!this->SelectedOutputOn) ASSERT(!this->output_isopen(OUTPUT_PUNCH)); - /* the converse is not necessarily true */ - - this->n_user_punch_index = -1; -#endif // SWIG_SHARED_OBJ - this->tidy_model(); -#ifdef PHREEQC_CPP - //test_classes(); -#endif -#ifdef PHREEQ98 - if (!phreeq98_debug) { -#endif - - -/* - * Calculate distribution of species for initial solutions - */ - if (this->new_solution) this->initial_solutions(TRUE); -/* - * Calculate distribution for exchangers - */ - if (this->new_exchange) this->initial_exchangers(TRUE); -/* - * Calculate distribution for surfaces - */ - if (this->new_surface) this->initial_surfaces(TRUE); -/* - * Calculate initial gas composition - */ - if (this->new_gas_phase) this->initial_gas_phases(TRUE); -/* - * Calculate reactions - */ - this->reactions(); -/* - * Calculate inverse models - */ - this->inverse_models(); -/* - * Calculate advection - */ - if (this->use.advect_in == TRUE) { - this->dup_print ("Beginning of advection calculations.", TRUE); - this->advection(); - } -/* - * Calculate transport - */ - if (this->use.trans_in == TRUE) { - this->dup_print ("Beginning of transport calculations.", TRUE); - this->transport(); - } - -#ifdef PHREEQC_CPP -/* - * run - */ - this->run_as_cells(); -#endif - -/* - * Copy - */ - if (this->new_copy) this->copy_entities(); -#ifdef PHREEQC_CPP - -/* - * dump - */ - dumper dump_info_save(dump_info); - if (this->DumpOn) - { - this->dump_entities(); - } - if (this->DumpStringOn) - { - dump_info = dump_info_save; - if (dump_info.Get_bool_any()) - { - std::ostringstream oss; - this->dump_ostream(oss); - if (dump_info.get_append()) - { - this->DumpString += oss.str(); - } - else - { - this->DumpString = oss.str(); - } - - /* Fill dump lines */ - this->DumpLines.clear(); - std::istringstream iss(this->DumpString); - std::string line; - while (std::getline(iss, line)) - { - this->DumpLines.push_back(line); - } - } - } -/* - * delete - */ - this->delete_entities(); -#endif - -/* - * End of simulation - */ - this->dup_print( "End of simulation.", TRUE); -#ifdef PHREEQ98 - } /* if (!phreeq98_debug) */ -#endif - } - -/* - * Display successful status - */ - this->do_status(); - -/* - * call post-run callback - */ - if (pfn_post) - { - pfn_post(cookie); - } - - if (this->input_error > 0) - { - std::ostringstream oss; - oss << "\n"; - oss << this->StringInput.c_str(); - oss << "\n"; - this->error_msg(oss.str().c_str(), CONTINUE); - } - //{{ - this->update_errors(); - //}} -} - - - -int istream_getc(void *cookie) -{ - if (cookie) - { - std::istream* is = (std::istream*)cookie; - int n = is->get(); - if (n == 13 && is->peek() == 10) - { - n = is->get(); - } - return n; - } - return EOF; -} - -int IPhreeqc::handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) -{ - int n = OK; - IPhreeqc *pThis = (IPhreeqc*)cookie; - switch (action) - { - case ACTION_OPEN: - n = pThis->open_handler(type, err_str); - break; - - case ACTION_OUTPUT: - n = pThis->output_handler(type, err_str, stop, cookie, format, args); - break; - - default: - n = pThis->module_handler(action, type, err_str, stop, cookie, format, args); - break; - } - - if (stop == STOP) - { - throw PhreeqcStop(); - } - return n; -} - -int IPhreeqc::output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) -{ - assert(cookie == this); - - switch (type) - { - case OUTPUT_ERROR: - if (this) - { - this->AddError("ERROR: "); - this->AddError(err_str); - this->AddError("\n"); - if (stop == STOP) - { - this->AddError("Stopping.\n"); - } - } - break; - - case OUTPUT_WARNING: - if (this) - { - std::ostringstream oss; - oss << "WARNING: " << err_str << "\n"; - this->AddWarning(oss.str().c_str()); - } - break; - - case OUTPUT_PUNCH: - this->AddSelectedOutput(err_str, format, args); - break; - - } - return module_handler(ACTION_OUTPUT, type, err_str, stop, cookie, format, args); -} - -int IPhreeqc::open_handler(const int type, const char *file_name) -{ - int n = OK; - switch (type) - { - case OUTPUT_PUNCH: - if (file_name) - { - if (this->PunchFileName.compare(file_name) != 0) - { - this->PunchFileName = file_name; - } - } - if (this->SelectedOutputOn) - { - n = module_handler(ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); - } - break; - default: - n = module_handler(ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); - break; - } - return n; -} - -// COMMENT: {3/25/2010 2:37:25 PM}void IPhreeqc::init(void) -// COMMENT: {3/25/2010 2:37:25 PM}{ -// COMMENT: {3/25/2010 2:37:25 PM} int i; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} moles_per_kilogram_string = 0; -// COMMENT: {3/25/2010 2:37:25 PM} pe_string = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} debug_model = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} debug_prep = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} debug_set = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} debug_diffuse_layer = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} debug_inverse = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} itmax = 100; -// COMMENT: {3/25/2010 2:37:25 PM}#ifdef USE_LONG_DOUBLE -// COMMENT: {3/25/2010 2:37:25 PM} /* from float.h, sets tolerance for cl1 routine */ -// COMMENT: {3/25/2010 2:37:25 PM} ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); -// COMMENT: {3/25/2010 2:37:25 PM}#else -// COMMENT: {3/25/2010 2:37:25 PM} ineq_tol = pow((double) 10, (double) -DBL_DIG); -// COMMENT: {3/25/2010 2:37:25 PM}#endif -// COMMENT: {3/25/2010 2:37:25 PM} convergence_tolerance = 1e-8; -// COMMENT: {3/25/2010 2:37:25 PM}#ifdef USE_LONG_DOUBLE -// COMMENT: {3/25/2010 2:37:25 PM} /* from float.h, sets tolerance for cl1 routine */ -// COMMENT: {3/25/2010 2:37:25 PM} inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); -// COMMENT: {3/25/2010 2:37:25 PM}#else -// COMMENT: {3/25/2010 2:37:25 PM} inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); -// COMMENT: {3/25/2010 2:37:25 PM}#endif -// COMMENT: {3/25/2010 2:37:25 PM} step_size = 100.; -// COMMENT: {3/25/2010 2:37:25 PM} pe_step_size = 10.; -// COMMENT: {3/25/2010 2:37:25 PM} pp_scale = 1.0; -// COMMENT: {3/25/2010 2:37:25 PM} pp_column_scale = 1.0; -// COMMENT: {3/25/2010 2:37:25 PM} diagonal_scale = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} censor = 0.0; -// COMMENT: {3/25/2010 2:37:25 PM} mass_water_switch = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} delay_mass_water = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} incremental_reactions = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} aqueous_only = 0; -// COMMENT: {3/25/2010 2:37:25 PM} negative_concentrations = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} LOG_10 = log(10.0); -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} max_solution = MAX_SOLUTION; -// COMMENT: {3/25/2010 2:37:25 PM} max_pp_assemblage = MAX_PP_ASSEMBLAGE; -// COMMENT: {3/25/2010 2:37:25 PM} max_exchange = MAX_PP_ASSEMBLAGE; -// COMMENT: {3/25/2010 2:37:25 PM} max_surface = MAX_PP_ASSEMBLAGE; -// COMMENT: {3/25/2010 2:37:25 PM} max_gas_phase = MAX_PP_ASSEMBLAGE; -// COMMENT: {3/25/2010 2:37:25 PM} max_kinetics = MAX_PP_ASSEMBLAGE; -// COMMENT: {3/25/2010 2:37:25 PM} max_s_s_assemblage = MAX_PP_ASSEMBLAGE; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} max_elements = MAX_ELEMENTS; -// COMMENT: {3/25/2010 2:37:25 PM} max_elts = MAX_ELTS; -// COMMENT: {3/25/2010 2:37:25 PM} max_line = MAX_LINE; -// COMMENT: {3/25/2010 2:37:25 PM} max_master = MAX_MASTER; -// COMMENT: {3/25/2010 2:37:25 PM} max_mb_unknowns = MAX_TRXN; -// COMMENT: {3/25/2010 2:37:25 PM} max_phases = MAX_PHASES; -// COMMENT: {3/25/2010 2:37:25 PM} max_s = MAX_S; -// COMMENT: {3/25/2010 2:37:25 PM} max_strings = MAX_STRINGS; -// COMMENT: {3/25/2010 2:37:25 PM} max_trxn = MAX_TRXN; -// COMMENT: {3/25/2010 2:37:25 PM} max_logk = MAX_S; -// COMMENT: {3/25/2010 2:37:25 PM} max_master_isotope = MAX_ELTS; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} count_solution = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_pp_assemblage = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_exchange = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_surface = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_gas_phase = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_kinetics = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_s_s_assemblage = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} count_elements = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_irrev = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_master = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_mix = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_phases = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_s = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_temperature = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_logk = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_master_isotope = 0; -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * Initialize advection -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} count_ad_cells = 1; -// COMMENT: {3/25/2010 2:37:25 PM} count_ad_shifts = 1; -// COMMENT: {3/25/2010 2:37:25 PM} print_ad_modulus = 1; -// COMMENT: {3/25/2010 2:37:25 PM} punch_ad_modulus = 1; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} advection_punch = 0; -// COMMENT: {3/25/2010 2:37:25 PM} advection_kin_time = 0.0; -// COMMENT: {3/25/2010 2:37:25 PM} advection_kin_time_defined = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} advection_print = 0; -// COMMENT: {3/25/2010 2:37:25 PM} advection_warnings = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * Initialize transport -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} count_cells = 1; -// COMMENT: {3/25/2010 2:37:25 PM} count_shifts = 1; -// COMMENT: {3/25/2010 2:37:25 PM} ishift = 1; -// COMMENT: {3/25/2010 2:37:25 PM} bcon_first = bcon_last = 3; -// COMMENT: {3/25/2010 2:37:25 PM} diffc = 0.3e-9; -// COMMENT: {3/25/2010 2:37:25 PM} simul_tr = 0; -// COMMENT: {3/25/2010 2:37:25 PM} tempr = 2.0; -// COMMENT: {3/25/2010 2:37:25 PM} heat_diffc = -0.1; -// COMMENT: {3/25/2010 2:37:25 PM} timest = 0.0; -// COMMENT: {3/25/2010 2:37:25 PM} multi_Dflag = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} interlayer_Dflag = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} interlayer_tortf = 100.0; -// COMMENT: {3/25/2010 2:37:25 PM} interlayer_Dpor = 0.1; -// COMMENT: {3/25/2010 2:37:25 PM}/* !!!! count_stag = 0; */ -// COMMENT: {3/25/2010 2:37:25 PM} mcd_substeps = 1.0; -// COMMENT: {3/25/2010 2:37:25 PM} print_modulus = 1; -// COMMENT: {3/25/2010 2:37:25 PM} punch_modulus = 1; -// COMMENT: {3/25/2010 2:37:25 PM} dump_modulus = 0; -// COMMENT: {3/25/2010 2:37:25 PM} dump_in = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} transport_warnings = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} pp_assemblage = 0; -// COMMENT: {3/25/2010 2:37:25 PM} exchange = 0; -// COMMENT: {3/25/2010 2:37:25 PM} surface = 0; -// COMMENT: {3/25/2010 2:37:25 PM} gas_phase = 0; -// COMMENT: {3/25/2010 2:37:25 PM} kinetics = 0; -// COMMENT: {3/25/2010 2:37:25 PM} s_s_assemblage = 0; -// COMMENT: {3/25/2010 2:37:25 PM} cell_data = 0; -// COMMENT: {3/25/2010 2:37:25 PM} elements = 0; -// COMMENT: {3/25/2010 2:37:25 PM} elt_list = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} inverse = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_inverse = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} irrev = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} line = 0; -// COMMENT: {3/25/2010 2:37:25 PM} line_save = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} master = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} mb_unknowns = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} mix = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_mix = 0; -// COMMENT: {3/25/2010 2:37:25 PM}/* !!!! */ -// COMMENT: {3/25/2010 2:37:25 PM} stag_data = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} phases = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} trxn.token = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} s = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} logk = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} master_isotope = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} solution = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} temperature = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} title_x = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} pe_x = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} description_x = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} units_x = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} s_x = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} sum_mb1 = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} sum_mb2 = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} sum_jacob0 = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} sum_jacob1 = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} sum_jacob2 = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} sum_delta = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} isotopes_x = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} x = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} max_unknowns = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} array = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} delta = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} residual = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} s_h2o = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} s_hplus = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} s_h3oplus = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} s_eminus = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} s_co3 = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} s_h2 = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} s_o2 = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} logk_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} master_isotope_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} strings_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} elements_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} species_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} phases_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} keyword_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * Initialize use pointers -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} use.solution_in = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} use.pp_assemblage_in = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} use.mix_in = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} use.irrev_in = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * Initialize punch -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} punch.in = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_totals = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.totals = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_molalities = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.molalities = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_activities = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.activities = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_pure_phases = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.pure_phases = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_si = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.si = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_gases = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.gases = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_s_s = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.s_s = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_kinetics = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.kinetics = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_isotopes = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.isotopes = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.count_calculate_values = 0; -// COMMENT: {3/25/2010 2:37:25 PM} punch.calculate_values = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} count_save_values = 0; -// COMMENT: {3/25/2010 2:37:25 PM} save_values = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.inverse = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} punch.sim = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.state = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.soln = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.dist = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.time = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.step = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.rxn = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.temp = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.ph = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.pe = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.alk = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.mu = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.water = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.high_precision = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.user_punch = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.charge_balance = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} punch.percent_error = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * last model -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} last_model.exchange = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} last_model.gas_phase = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} last_model.s_s_assemblage = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} last_model.kinetics = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} last_model.pp_assemblage = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} last_model.add_formula = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} last_model.si = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} last_model.surface_comp = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} last_model.surface_charge = NULL; -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * Update hash table -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} keyword_hash = 0; -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * rates -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} rates = 0; -// COMMENT: {3/25/2010 2:37:25 PM} count_rates = 0; -// COMMENT: {3/25/2010 2:37:25 PM} initial_total_time = 0; -// COMMENT: {3/25/2010 2:37:25 PM} rate_m = 0; -// COMMENT: {3/25/2010 2:37:25 PM} rate_m0 = 0; -// COMMENT: {3/25/2010 2:37:25 PM} rate_p = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} rate_time = 0; -// COMMENT: {3/25/2010 2:37:25 PM} rate_sim_time_start = 0; -// COMMENT: {3/25/2010 2:37:25 PM} rate_sim_time_end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} rate_sim_time = 0; -// COMMENT: {3/25/2010 2:37:25 PM} rate_moles = 0; -// COMMENT: {3/25/2010 2:37:25 PM} initial_total_time = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * user_print, user_punch -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} user_print = 0; -// COMMENT: {3/25/2010 2:37:25 PM} user_punch = 0; -// COMMENT: {3/25/2010 2:37:25 PM} user_punch_headings = 0; -// COMMENT: {3/25/2010 2:37:25 PM} user_punch_count_headings = 0; -// COMMENT: {3/25/2010 2:37:25 PM}#ifdef PHREEQ98 -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * user_graph -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} user_graph = 0; -// COMMENT: {3/25/2010 2:37:25 PM} user_graph_headings = 0 -// COMMENT: {3/25/2010 2:37:25 PM} user_graph_count_headings = 0; -// COMMENT: {3/25/2010 2:37:25 PM}#endif -// COMMENT: {3/25/2010 2:37:25 PM} /* -// COMMENT: {3/25/2010 2:37:25 PM} Initialize llnl aqueous model parameters -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} llnl_temp = 0; -// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_temp = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} llnl_adh = 0; -// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_adh = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} llnl_bdh = 0; -// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_bdh = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} llnl_bdot = 0; -// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_bdot = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} llnl_co2_coefs = 0; -// COMMENT: {3/25/2010 2:37:25 PM} llnl_count_co2_coefs = 0; -// COMMENT: {3/25/2010 2:37:25 PM}/* -// COMMENT: {3/25/2010 2:37:25 PM} * -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} command_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} change_surf = 0; -// COMMENT: {3/25/2010 2:37:25 PM} change_surf_count = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM}#if defined(WINDOWS) || defined(_WINDOWS) -// COMMENT: {3/25/2010 2:37:25 PM} /* SRC pr.status = FALSE; */ -// COMMENT: {3/25/2010 2:37:25 PM}#endif -// COMMENT: {3/25/2010 2:37:25 PM} /* Initialize print here, not in global.h */ -// COMMENT: {3/25/2010 2:37:25 PM} pr.all = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.initial_solutions = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.initial_exchangers = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.reactions = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.gas_phase = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.s_s_assemblage = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.pp_assemblage = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.surface = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.exchange = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.kinetics = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.totals = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.eh = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.species = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.saturation_indices = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.irrev = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.mix = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.reaction = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.use = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.logfile = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.punch = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} if (phast == TRUE) -// COMMENT: {3/25/2010 2:37:25 PM} { -// COMMENT: {3/25/2010 2:37:25 PM} pr.status = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} } -// COMMENT: {3/25/2010 2:37:25 PM} else -// COMMENT: {3/25/2010 2:37:25 PM} { -// COMMENT: {3/25/2010 2:37:25 PM} pr.status = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} } -// COMMENT: {3/25/2010 2:37:25 PM} pr.inverse = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.dump = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.user_print = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.headings = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.user_graph = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.echo_input = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} count_warnings = 0; -// COMMENT: {3/25/2010 2:37:25 PM} pr.warnings = 100; -// COMMENT: {3/25/2010 2:37:25 PM} pr.initial_isotopes = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.isotope_ratios = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.isotope_alphas = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.hdf = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} pr.alkalinity = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} species_list = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} user_database = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} first_read_input = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} have_punch_name = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} selected_output_file_name = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} dump_file_name = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} /* calculate_value */ -// COMMENT: {3/25/2010 2:37:25 PM} max_calculate_value = MAX_ELTS; -// COMMENT: {3/25/2010 2:37:25 PM} count_calculate_value = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} calculate_value = 0; -// COMMENT: {3/25/2010 2:37:25 PM} calculate_value_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} /* isotope_ratio */ -// COMMENT: {3/25/2010 2:37:25 PM} max_isotope_ratio = MAX_ELTS; -// COMMENT: {3/25/2010 2:37:25 PM} count_isotope_ratio = 0; -// COMMENT: {3/25/2010 2:37:25 PM} isotope_ratio = 0; -// COMMENT: {3/25/2010 2:37:25 PM} isotope_ratio_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} /* isotope_value */ -// COMMENT: {3/25/2010 2:37:25 PM} max_isotope_alpha = MAX_ELTS; -// COMMENT: {3/25/2010 2:37:25 PM} count_isotope_alpha = 0; -// COMMENT: {3/25/2010 2:37:25 PM} isotope_alpha = 0; -// COMMENT: {3/25/2010 2:37:25 PM} isotope_alpha_hash_table = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} phreeqc_mpi_myself = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} copy_solution.n_user = copy_solution.start = copy_solution.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_surface.n_user = copy_surface.start = copy_surface.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_mix.n_user = copy_mix.start = copy_mix.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} set_forward_output_to_log(FALSE); -// COMMENT: {3/25/2010 2:37:25 PM} simulation = 0; -// COMMENT: {3/25/2010 2:37:25 PM} /* -// COMMENT: {3/25/2010 2:37:25 PM} * cvode -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} cvode_init(); -// COMMENT: {3/25/2010 2:37:25 PM} /* -// COMMENT: {3/25/2010 2:37:25 PM} * Pitzer -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} pitzer_model = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} max_pitz_param = 100; -// COMMENT: {3/25/2010 2:37:25 PM} count_pitz_param = 0; -// COMMENT: {3/25/2010 2:37:25 PM} use_etheta = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} pitz_params = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} max_theta_param = 100; -// COMMENT: {3/25/2010 2:37:25 PM} count_theta_param = 0; -// COMMENT: {3/25/2010 2:37:25 PM} theta_params = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} ICON = TRUE; -// COMMENT: {3/25/2010 2:37:25 PM} OTEMP = 0.0; -// COMMENT: {3/25/2010 2:37:25 PM} for (i = 0; i < 23; i++) -// COMMENT: {3/25/2010 2:37:25 PM} { -// COMMENT: {3/25/2010 2:37:25 PM} BK[i] = 0.0; -// COMMENT: {3/25/2010 2:37:25 PM} DK[i] = 0.0; -// COMMENT: {3/25/2010 2:37:25 PM} } -// COMMENT: {3/25/2010 2:37:25 PM} pitzer_pe = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} /* -// COMMENT: {3/25/2010 2:37:25 PM} * SIT -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} sit_model = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} max_sit_param = 100; -// COMMENT: {3/25/2010 2:37:25 PM} count_sit_param = 0; -// COMMENT: {3/25/2010 2:37:25 PM} sit_params = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} /* -// COMMENT: {3/25/2010 2:37:25 PM} * to facilitate debuging -// COMMENT: {3/25/2010 2:37:25 PM} */ -// COMMENT: {3/25/2010 2:37:25 PM} dbg_use = &use; -// COMMENT: {3/25/2010 2:37:25 PM} dbg_solution = solution; -// COMMENT: {3/25/2010 2:37:25 PM} dbg_exchange = exchange; -// COMMENT: {3/25/2010 2:37:25 PM} dbg_surface = surface; -// COMMENT: {3/25/2010 2:37:25 PM} dbg_pp_assemblage = pp_assemblage; -// COMMENT: {3/25/2010 2:37:25 PM} dbg_kinetics = kinetics; -// COMMENT: {3/25/2010 2:37:25 PM} dbg_irrev = irrev; -// COMMENT: {3/25/2010 2:37:25 PM} dbg_mix = mix; -// COMMENT: {3/25/2010 2:37:25 PM} dbg_master = master; -// COMMENT: {3/25/2010 2:37:25 PM} calculating_deriv = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} numerical_deriv = FALSE; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} zeros = 0; -// COMMENT: {3/25/2010 2:37:25 PM} zeros_max = 1; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} cell_pore_volume = 0; -// COMMENT: {3/25/2010 2:37:25 PM} cell_volume = 0; -// COMMENT: {3/25/2010 2:37:25 PM} cell_porosity = 0; -// COMMENT: {3/25/2010 2:37:25 PM} cell_saturation = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} charge_group = NULL; -// COMMENT: {3/25/2010 2:37:25 PM} print_density = 0; -// COMMENT: {3/25/2010 2:37:25 PM} -// COMMENT: {3/25/2010 2:37:25 PM} return; -// COMMENT: {3/25/2010 2:37:25 PM}} - -bool IPhreeqc::GetOutputOn(void)const -{ - return this->OutputOn; -} - -void IPhreeqc::SetOutputOn(bool bValue) -{ - this->OutputOn = bValue; -} - -bool IPhreeqc::GetSelectedOutputOn(void)const -{ - return this->SelectedOutputOn; -} - -void IPhreeqc::SetSelectedOutputOn(bool bValue) -{ - this->SelectedOutputOn = bValue; -} - -bool IPhreeqc::GetLogOn(void)const -{ - return this->LogOn; -} - -void IPhreeqc::SetLogOn(bool bValue) -{ - this->LogOn = bValue; -} - -bool IPhreeqc::GetDumpOn(void)const -{ - return this->DumpOn; -} - -void IPhreeqc::SetDumpOn(bool bValue) -{ - this->DumpOn = bValue; -} - -bool IPhreeqc::GetDumpStringOn(void)const -{ - return this->DumpStringOn; -} - -void IPhreeqc::SetDumpStringOn(bool bValue) -{ - this->DumpStringOn = bValue; -} - -bool IPhreeqc::GetErrorOn(void)const -{ - return this->ErrorOn; -} - -void IPhreeqc::SetErrorOn(bool bValue) -{ - this->ErrorOn = bValue; -} - -void IPhreeqc::AddSelectedOutput(const char* name, const char* format, va_list argptr) -{ - int bInt; - int bDouble; - int bString; - - int state; - int bLongDouble; - char ch; - - - /* state values - 0 Haven't found start(%) - 1 Just read start(%) - 2 Just read Flags(-0+ #) (zero or more) - 3 Just read Width - 4 Just read Precision start (.) - 5 Just read Size modifier - 6 Just read Type - */ - - if (name == NULL) { - return; - } - - bDouble = 0; - bInt = 0; - bString = 0; - - bLongDouble = 0; - - state = 0; - ch = *format++; - while (ch != '\0') - { - switch (state) - { - case 0: /* looking for Start specification (%) */ - switch (ch) - { - case '%': - state = 1; - break; - default: - break; - } - ch = *format++; - break; - case 1: /* reading Flags (zero or more(-,+,0,# or space)) */ - switch (ch) - { - case '-': case '0': case '+': case ' ': case '#': - ch = *format++; - break; - default: - state = 2; - break; - } - break; - case 2: /* reading Minimum field width (decimal integer constant) */ - switch (ch) - { - case '.': - state = 3; - ch = *format++; - break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - ch = *format++; - break; - default: - state = 4; - break; - } - break; - case 3: /* reading Precision specification (period already read) */ - switch (ch) - { - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - ch = *format++; - break; - default: - state = 4; - break; - } - break; - case 4: /* reading Size modifier */ - switch (ch) - { - case 'l': - ch = *format++; - break; - case 'L': - bLongDouble = 1; - ch = *format++; - break; - case 'h': - ch = *format++; - break; - } - state = 5; - break; - case 5: /* reading Conversion letter */ - switch (ch) - { - case 'c': - break; - case 'd': - case 'i': - bInt = 1; - break; - case 'n': - case 'o': - case 'p': - break; - case 's': - bString = 1; - break; - case 'u': - case 'x': - case 'X': - case '%': - break; - case 'f': - case 'e': - case 'E': - case 'g': - case 'G': - bDouble = 1; - break; - default: - ASSERT(false); - break; - } - ch = '\0'; /* done */ - break; - } - } - - if (bDouble) - { - double valDouble; - - if (bLongDouble) - { - valDouble = (double)va_arg(argptr, long double); - } - else - { - valDouble = va_arg(argptr, double); - } - - this->SelectedOutput->PushBackDouble(name, valDouble); - } - else if (bInt) - { - int valInt; - valInt = va_arg(argptr, int); - - this->SelectedOutput->PushBackLong(name, (long)valInt); - } - else if (bString) - { - char* valString; - valString = (char *)va_arg(argptr, char *); - - this->SelectedOutput->PushBackString(name, valString); - } - else - { - ASSERT(false); - this->SelectedOutput->PushBackEmpty(name); - } -} - -VRESULT IPhreeqc::AccumulateLine(const char *line) -{ - try - { - this->ErrorReporter->Clear(); - this->WarningReporter->Clear(); - this->StringInput.append(line); - this->StringInput.append("\n"); - return VR_OK; - } - catch (...) - { - this->AddError("AccumulateLine: An unhandled exception occured.\n"); - } - return VR_OUTOFMEMORY; -} - -int IPhreeqc::RunAccumulated(void) -{ - static const char *sz_routine = "RunAccumulated"; - try - { - // this may throw - this->check_database(sz_routine); - - this->input_error = 0; - - // create input stream - std::istringstream iss(this->GetAccumulatedLines()); - - // this may throw - this->do_run(sz_routine, &iss, NULL, NULL, NULL, NULL); - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - catch(...) - { - const char *errmsg = "RunAccumulated: An unhandled exception occured.\n"; - try - { - this->error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - } - - this->ClearAccumulatedLines(); - this->close_output_files(); - this->update_errors(); - - return this->input_error; -} - -int IPhreeqc::RunFile(const char* filename) -{ - static const char *sz_routine = "RunFile"; - try - { - // this may throw - this->check_database(sz_routine); - - this->input_error = 0; - - // open file - // - std::ifstream ifs; - ifs.open(filename); - if (!ifs.is_open()) - { - std::ostringstream oss; - oss << "RunFile: Unable to open:" << "\"" << filename << "\"."; - this->error_msg(oss.str().c_str(), STOP); // throws - } - - // this may throw - this->do_run(sz_routine, &ifs, NULL, NULL, NULL, NULL); - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - catch(...) - { - const char *errmsg = "RunFile: An unhandled exception occured.\n"; - try - { - this->error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - } - - this->close_output_files(); - this->update_errors(); - - return this->input_error; -} - -int IPhreeqc::RunString(const char* input) -{ - static const char *sz_routine = "RunString"; - try - { - // this may throw - this->check_database(sz_routine); - - this->input_error = 0; - - // create input stream - std::string s(input); - std::istringstream iss(s); - - // this may throw - this->do_run(sz_routine, &iss, NULL, NULL, NULL, NULL); - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - catch(...) - { - const char *errmsg = "RunString: An unhandled exception occured.\n"; - try - { - this->error_msg(errmsg, STOP); // throws PhreeqcStop - } - catch (PhreeqcStop) - { - assert(this->database_file == 0); - assert(this->input_file == 0); - assert(this->input_error > 0); - } - } - - this->close_output_files(); - this->update_errors(); - - return this->input_error; -} - -int IPhreeqc::GetSelectedOutputRowCount(void)const -{ - return (int)this->SelectedOutput->GetRowCount(); -} - -int IPhreeqc::GetSelectedOutputColumnCount(void)const -{ - return (int)this->SelectedOutput->GetColCount(); -} - -VRESULT IPhreeqc::GetSelectedOutputValue(int row, int col, VAR* pVAR) -{ - this->ErrorReporter->Clear(); - if (!pVAR) - { - this->AddError("GetSelectedOutputValue: VR_INVALIDARG pVAR is NULL.\n"); - this->update_errors(); - return VR_INVALIDARG; - } - - VRESULT v = this->SelectedOutput->Get(row, col, pVAR); - switch (v) - { - case VR_OK: - break; - case VR_OUTOFMEMORY: - this->AddError("GetSelectedOutputValue: VR_OUTOFMEMORY Out of memory.\n"); - break; - case VR_BADVARTYPE: - this->AddError("GetSelectedOutputValue: VR_BADVARTYPE pVar must be initialized(VarInit) and/or cleared(VarClear).\n"); - break; - case VR_INVALIDARG: - // not possible - break; - case VR_INVALIDROW: - this->AddError("GetSelectedOutputValue: VR_INVALIDROW Row index out of range.\n"); - break; - case VR_INVALIDCOL: - this->AddError("GetSelectedOutputValue: VR_INVALIDCOL Column index out of range.\n"); - break; - } - this->update_errors(); - return v; -} - -int IPhreeqc::GetDumpLineCount(void)const -{ - return (int)this->DumpLines.size(); -} - -const char* IPhreeqc::GetDumpLine(int n) -{ - static const char empty[] = ""; - if (n < 0 || n >= this->GetDumpLineCount()) - { - return empty; - } - return this->DumpLines[n].c_str(); -} - -int IPhreeqc::GetErrorLineCount(void)const -{ - return (int)this->ErrorLines.size(); -} - -const char* IPhreeqc::GetErrorLine(int n) -{ - static const char empty[] = ""; - if (n < 0 || n >= this->GetErrorLineCount()) - { - return empty; - } - return this->ErrorLines[n].c_str(); -} - -void IPhreeqc::update_errors(void) -{ - this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); - - this->ErrorLines.clear(); - std::istringstream iss(this->LastErrorString); - std::string line; - while (std::getline(iss, line)) - { - this->ErrorLines.push_back(line); - } -} -std::list< std::string > IPhreeqc::ListComponents(void) -{ - std::list< std::string > comps; - this->list_components(comps); - return comps; -} diff --git a/IPhreeqc2.cpp b/IPhreeqc2.cpp index 4f0c5f9f..7b7e4693 100644 --- a/IPhreeqc2.cpp +++ b/IPhreeqc2.cpp @@ -19,6 +19,21 @@ const char ERROR_FILENAME[] = "phreeqc.err"; const char LOG_FILENAME[] = "phreeqc.log"; const char PUNCH_FILENAME[] = "selected.out"; +int istream_getc(void *cookie) +{ + if (cookie) + { + std::istream* is = (std::istream*)cookie; + int n = is->get(); + if (n == 13 && is->peek() == 10) + { + n = is->get(); + } + return n; + } + return EOF; +} + IPhreeqc2::IPhreeqc2(void) : DatabaseLoaded(false) , SelectedOutputOn(false) @@ -230,17 +245,12 @@ int IPhreeqc2::output_isopen2(const int type) return 0; } -// COMMENT: {3/25/2010 1:27:16 PM}int Phreeqc::EndRow(void) -// COMMENT: {3/25/2010 1:27:16 PM}{ -// COMMENT: {3/25/2010 1:27:16 PM} return OK; -// COMMENT: {3/25/2010 1:27:16 PM}} - int IPhreeqc2::EndRow(void) { if (this->SelectedOutput->GetRowCount() <= 1) { - assert(this->PhreeqcPtr->n_user_punch_index >= 0); // ensure all user_punch headings are included + assert(this->PhreeqcPtr->n_user_punch_index >= 0); for (int i = this->PhreeqcPtr->n_user_punch_index; i < this->PhreeqcPtr->user_punch_count_headings; ++i) { this->SelectedOutput->PushBackEmpty(this->PhreeqcPtr->user_punch_headings[i]); @@ -269,11 +279,17 @@ const std::string& IPhreeqc2::GetAccumulatedLines(void) return this->StringInput; } +void IPhreeqc2::OutputLastError(void) +{ + std::cout << this->GetLastErrorString() << std::endl; +} + void IPhreeqc2::OutputLines(void) { std::cout << this->StringInput.c_str() << std::endl; } + int IPhreeqc2::LoadDatabase(const char* filename) { try diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp index 55cf6dfa..d7bf26ae 100644 --- a/IPhreeqcLib.cpp +++ b/IPhreeqcLib.cpp @@ -1,6 +1,7 @@ #include "IPhreeqcLib.h" #include "IPhreeqc2.h" #include +#include int @@ -49,6 +50,19 @@ UnLoadDatabaseM(int id) return IPL_BADINSTANCE; } +void +OutputLastErrorM(int id) +{ + static const char err_msg[] = "OutputLastError: Bad instance.\n"; + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + IPhreeqcPtr->OutputLastError(); + return; + } + std::cout << err_msg << std::endl; +} + const char* GetLastErrorStringM(int id) { @@ -421,6 +435,43 @@ AddErrorM(int id, const char* error_msg) return IPL_BADINSTANCE; } +void +OutputLinesM(int id) +{ + static const char err_msg[] = "OutputLines: Bad instance.\n"; + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + IPhreeqcPtr->OutputLines(); + return; + } + std::cout << err_msg << std::endl; +} + +int +GetErrorLineCountM(int id) +{ + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return (int)IPhreeqcPtr->GetErrorLineCount(); + } + return IPL_BADINSTANCE; +} + +const char* +GetErrorLineM(int id, int n) +{ + static const char err_msg[] = "GetErrorLine: Bad instance.\n"; + IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetErrorLine(n); + } + return err_msg; +} + + std::map IPhreeqcLib::Instances; size_t IPhreeqcLib::InstancesIndex = 0; diff --git a/fwrap.cpp b/fwrap.cpp index d62c89f1..bb376daf 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -4,7 +4,7 @@ #include /* assert */ #include /* sprintf */ #include "phrqtype.h" -#include "IPhreeqc.h" +#include "IPhreeqcLib.h" // TODO DELETE AFTER RENAMING TO IPhreeqc.h /******************************* When using GNU gcc/g++/g77 @@ -56,174 +56,180 @@ padfstring(char *dest, const char *src, unsigned int len) } int -LoadDatabaseF(char* filename, unsigned int filename_length) +CreateIPhreeqcF(void) +{ + return ::CreateIPhreeqc(); +} + +int +LoadDatabaseF(int *id, char* filename, unsigned int filename_length) { char* cfilename; cfilename = f2cstring(filename, filename_length); if (!cfilename) { - AddError("LoadDatabase: Out of memory.\n"); + ::AddErrorM(*id, "LoadDatabase: Out of memory.\n"); return VR_OUTOFMEMORY; } - int n = ::LoadDatabase(cfilename); + int n = ::LoadDatabaseM(*id, cfilename); free(cfilename); return n; } int -LoadDatabaseStringF(char* input, unsigned int input_length) +LoadDatabaseStringF(int *id, char* input, unsigned int input_length) { char* cinput; cinput = f2cstring(input, input_length); if (!cinput) { - AddError("LoadDatabase: Out of memory.\n"); + ::AddErrorM(*id, "LoadDatabase: Out of memory.\n"); return VR_OUTOFMEMORY; } - int n = ::LoadDatabaseString(cinput); + int n = ::LoadDatabaseStringM(*id, cinput); free(cinput); return n; } -VRESULT -AccumulateLineF(char *line, unsigned int line_length) +IPL_RESULT +AccumulateLineF(int *id, char *line, unsigned int line_length) { - VRESULT n; + IPL_RESULT n; char* cline; cline = f2cstring(line, line_length); if (!cline) { - AddError("AccumulateLine: Out of memory.\n"); - return VR_OUTOFMEMORY; + ::AddErrorM(*id, "AccumulateLine: Out of memory.\n"); + return IPL_OUTOFMEMORY; } - n = AccumulateLine(cline); + n = ::AccumulateLineM(*id, cline); free(cline); return n; } -void -SetSelectedOutputOnF(int* sel_on) +IPL_RESULT +SetSelectedOutputOnF(int *id, int* sel_on) { - ::SetSelectedOutputOn(*sel_on); + return ::SetSelectedOutputOnM(*id, *sel_on); } -void -SetOutputOnF(int* output_on) +IPL_RESULT +SetOutputOnF(int *id, int* output_on) { - ::SetOutputOn(*output_on); + return ::SetOutputOnM(*id, *output_on); } -void -SetErrorOnF(int* error_on) +IPL_RESULT +SetErrorOnF(int *id, int* error_on) { - ::SetErrorOn(*error_on); + return ::SetErrorOnM(*id, *error_on); } -void -SetLogOnF(int* log_on) +IPL_RESULT +SetLogOnF(int *id, int* log_on) { - ::SetLogOn(*log_on); + return ::SetLogOnM(*id, *log_on); } -void -SetDumpOnF(int* dump_on) +IPL_RESULT +SetDumpOnF(int *id, int* dump_on) { - ::SetDumpOn(*dump_on); + return ::SetDumpOnM(*id, *dump_on); } -void -SetDumpStringOnF(int* dump_string_on) +IPL_RESULT +SetDumpStringOnF(int *id, int* dump_string_on) { - ::SetDumpStringOn(*dump_string_on); + return ::SetDumpStringOnM(*id, *dump_string_on); } int -GetDumpLineCountF(void) +GetDumpLineCountF(int *id) { - return ::GetDumpLineCount(); + return ::GetDumpLineCountM(*id); } void -GetDumpLineF(int* n, char* line, unsigned int line_length) +GetDumpLineF(int *id, int* n, char* line, unsigned int line_length) { - padfstring(line, ::GetDumpLine((*n) - 1), line_length); + padfstring(line, ::GetDumpLineM(*id, (*n) - 1), line_length); } int -GetErrorLineCountF(void) +GetErrorLineCountF(int *id) { - return ::GetErrorLineCount(); + return ::GetErrorLineCountM(*id); } void -GetErrorLineF(int* n, char* line, unsigned int line_length) +GetErrorLineF(int *id, int* n, char* line, unsigned int line_length) { - padfstring(line, ::GetErrorLine((*n) - 1), line_length); + padfstring(line, ::GetErrorLineM(*id, (*n) - 1), line_length); } int -GetComponentCountF(void) +GetComponentCountF(int *id) { - return ::GetComponentCount(); + return ::GetComponentCountM(*id); } void -GetComponentF(int *n, char* line, unsigned int line_length) +GetComponentF(int *id, int *n, char* line, unsigned int line_length) { - padfstring(line, ::GetComponent((*n) - 1), line_length); + padfstring(line, ::GetComponentM(*id, (*n) - 1), line_length); } int -RunAccumulatedF(void) +RunAccumulatedF(int *id) { - return ::RunAccumulated(); + return ::RunAccumulatedM(*id); } int -RunFileF(char* filename, unsigned int filename_length) +RunFileF(int *id, char* filename, unsigned int filename_length) { char* cfilename; cfilename = f2cstring(filename, filename_length); if (!cfilename) { - AddError("RunFile: Out of memory.\n"); + ::AddErrorM(*id, "RunFile: Out of memory.\n"); return (int)VR_OUTOFMEMORY; } - int n = ::RunFile(cfilename); + int n = ::RunFileM(*id, cfilename); free(cfilename); return n; } int -RunStringF(char* input, unsigned int input_length) +RunStringF(int *id, char* input, unsigned int input_length) { char* cinput; cinput = f2cstring(input, input_length); if (!cinput) { - AddError("RunString: Out of memory.\n"); + ::AddErrorM(*id, "RunString: Out of memory.\n"); return (int)VR_OUTOFMEMORY; } - int n = ::RunString(cinput); + int n = ::RunStringM(*id, cinput); free(cinput); return n; } int -GetSelectedOutputRowCountF(void) +GetSelectedOutputRowCountF(int *id) { - int rows = ::GetSelectedOutputRowCount(); + int rows = ::GetSelectedOutputRowCountM(*id); if (rows > 0) { rows -= 1; @@ -232,23 +238,24 @@ GetSelectedOutputRowCountF(void) } int -GetSelectedOutputColumnCountF(void) +GetSelectedOutputColumnCountF(int *id) { - return ::GetSelectedOutputColumnCount(); + return ::GetSelectedOutputColumnCountM(*id); } -VRESULT -GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +IPL_RESULT +GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) { - VRESULT result; + IPL_RESULT result; VAR v; VarInit(&v); char buffer[100]; int adjcol = *col - 1; - result = ::GetSelectedOutputValue(*row, adjcol, &v); + result = ::GetSelectedOutputValueM(*id, *row, adjcol, &v); - switch (v.type) { + switch (v.type) + { case TT_EMPTY: *vtype = v.type; break; @@ -279,37 +286,37 @@ GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* sv } void -OutputLastErrorF(void) +OutputLastErrorF(int *id) { - ::OutputLastError(); + ::OutputLastErrorM(*id); } void -OutputLinesF(void) +OutputLinesF(int *id) { - ::OutputLines(); + ::OutputLinesM(*id); } #if defined(__cplusplus) extern "C" { #endif -int -SystemF(char* command, unsigned int command_length) -{ - char* ccommand; - - ccommand = f2cstring(command, command_length); - if (!ccommand) - { - AddError("System: Out of memory.\n"); - return (int)VR_OUTOFMEMORY; - } - - int n = system(ccommand); - free(ccommand); - return n; -} +// COMMENT: {4/5/2010 7:12:55 PM}int +// COMMENT: {4/5/2010 7:12:55 PM}SystemF(char* command, unsigned int command_length) +// COMMENT: {4/5/2010 7:12:55 PM}{ +// COMMENT: {4/5/2010 7:12:55 PM} char* ccommand; +// COMMENT: {4/5/2010 7:12:55 PM} +// COMMENT: {4/5/2010 7:12:55 PM} ccommand = f2cstring(command, command_length); +// COMMENT: {4/5/2010 7:12:55 PM} if (!ccommand) +// COMMENT: {4/5/2010 7:12:55 PM} { +// COMMENT: {4/5/2010 7:12:55 PM} AddError("System: Out of memory.\n"); +// COMMENT: {4/5/2010 7:12:55 PM} return (int)VR_OUTOFMEMORY; +// COMMENT: {4/5/2010 7:12:55 PM} } +// COMMENT: {4/5/2010 7:12:55 PM} +// COMMENT: {4/5/2010 7:12:55 PM} int n = system(ccommand); +// COMMENT: {4/5/2010 7:12:55 PM} free(ccommand); +// COMMENT: {4/5/2010 7:12:55 PM} return n; +// COMMENT: {4/5/2010 7:12:55 PM}} #if defined(__cplusplus) } @@ -326,93 +333,97 @@ extern "C" { // // Intel Fortran compiler 9.1 /iface:cvf // -int __stdcall LOADDATABASE(char *filename, unsigned int len) +int __stdcall CREATEIPHREEQC(void) { - return LoadDatabaseF(filename, len); + return CreateIPhreeqcF(); } -void __stdcall OUTPUTLASTERROR(void) +int __stdcall LOADDATABASE(int *id, char *filename, unsigned int len) { - OutputLastErrorF(); + return LoadDatabaseF(id, filename, len); } -int __stdcall ACCUMULATELINE(char *line, unsigned int len) +void __stdcall OUTPUTLASTERROR(int *id) { - return AccumulateLineF(line, len); + OutputLastErrorF(id); } -void __stdcall SETSELECTEDOUTPUTON(int *selected_on) +int __stdcall ACCUMULATELINE(int *id, char *line, unsigned int len) { - SetSelectedOutputOnF(selected_on); + return AccumulateLineF(id, line, len); } -void __stdcall SETOUTPUTON(int *output_on) +void __stdcall SETSELECTEDOUTPUTON(int *id, int *selected_on) { - SetOutputOnF(output_on); + SetSelectedOutputOnF(id, selected_on); } -void __stdcall SETERRORON(int *error_on) +void __stdcall SETOUTPUTON(int *id, int *output_on) { - SetErrorOnF(error_on); + SetOutputOnF(id, output_on); } -void __stdcall SETLOGON(int *log_on) +void __stdcall SETERRORON(int *id, int *error_on) { - SetLogOnF(log_on); + SetErrorOnF(id, error_on); } -void __stdcall SETDUMPON(int *dump_on) +void __stdcall SETLOGON(int *id, int *log_on) { - SetDumpOnF(dump_on); + SetLogOnF(id, log_on); } -void __stdcall SETDUMPSTRINGON(int *dump_string_on) +void __stdcall SETDUMPON(int *id, int *dump_on) { - SetDumpStringOnF(dump_string_on); + SetDumpOnF(id, dump_on); } -int __stdcall GETDUMPLINECOUNT(void) +void __stdcall SETDUMPSTRINGON(int *id, int *dump_string_on) { - return GetDumpLineCountF(); + SetDumpStringOnF(id, dump_string_on); } -void __stdcall GETDUMPLINE(int *n, char* line, unsigned int line_length) +int __stdcall GETDUMPLINECOUNT(int *id) { - GetDumpLineF(n, line, line_length); + return GetDumpLineCountF(id); } -int __stdcall GETERRORLINECOUNT(void) +void __stdcall GETDUMPLINE(int *id, int *n, char* line, unsigned int line_length) { - return GetErrorLineCountF(); + GetDumpLineF(id, n, line, line_length); } -void __stdcall GETERRORLINE(int *n, char* line, unsigned int line_length) +int __stdcall GETERRORLINECOUNT(int *id) { - GetErrorLineF(n, line, line_length); + return GetErrorLineCountF(id); } -int __stdcall GETCOMPONENTCOUNT(void) +void __stdcall GETERRORLINE(int *id, int *n, char* line, unsigned int line_length) { - return GetComponentCountF(); + GetErrorLineF(id, n, line, line_length); } -void __stdcall GETCOMPONENT(int *n, char* line, unsigned int line_length) +int __stdcall GETCOMPONENTCOUNT(int *id) { - GetComponentF(n, line, line_length); + return GetComponentCountF(id); } -int __stdcall RUNACCUMULATED(void) +void __stdcall GETCOMPONENT(int *id, int *n, char* line, unsigned int line_length) { - return RunAccumulatedF(); + GetComponentF(id, n, line, line_length); } -int __stdcall RUNFILE(char *filename, unsigned int len) +int __stdcall RUNACCUMULATED(int *id) { - return RunFileF(filename, len); + return RunAccumulatedF(id); } -int __stdcall RUNSTRING(char *input, unsigned int len) +int __stdcall RUNFILE(int *id, char *filename, unsigned int len) { - return RunStringF(input, len); + return RunFileF(id, filename, len); } -void __stdcall OUTPUTLINES(void) +int __stdcall RUNSTRING(int *id, char *input, unsigned int len) { - OutputLinesF(); + return RunStringF(id, input, len); } -int __stdcall GETSELECTEDOUTPUTROWCOUNT(void) +void __stdcall OUTPUTLINES(int *id) { - return GetSelectedOutputRowCountF(); + OutputLinesF(id); } -int __stdcall GETSELECTEDOUTPUTCOLUMNCOUNT(void) +int __stdcall GETSELECTEDOUTPUTROWCOUNT(int *id) { - return GetSelectedOutputColumnCountF(); + return GetSelectedOutputRowCountF(id); } -int __stdcall GETSELECTEDOUTPUTVALUE(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +int __stdcall GETSELECTEDOUTPUTCOLUMNCOUNT(int *id) { - return GetSelectedOutputValueF(row, col, vtype, dvalue, svalue, svalue_length); + return GetSelectedOutputColumnCountF(id); +} +int __stdcall GETSELECTEDOUTPUTVALUE(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +{ + return GetSelectedOutputValueF(id, row, col, vtype, dvalue, svalue, svalue_length); } #if defined(__cplusplus) } diff --git a/fwrap.h b/fwrap.h index 71b25d58..a765f784 100644 --- a/fwrap.h +++ b/fwrap.h @@ -6,50 +6,51 @@ extern "C" { #endif + int CreateIPhreeqcF(void); - int LoadDatabaseF(char* filename, unsigned int filename_length); + int LoadDatabaseF(int *id, char* filename, unsigned int filename_length); - VRESULT AccumulateLineF(char *line, unsigned int line_length); + IPL_RESULT AccumulateLineF(int *id, char *line, unsigned int line_length); - int RunAccumulatedF(void); + int RunAccumulatedF(int *id); - int RunFileF(char* filename, unsigned int filename_length); + int RunFileF(int *id, char* filename, unsigned int filename_length); - int RunStringF(char* input, unsigned int input_length); + int RunStringF(int *id, char* input, unsigned int input_length); - int GetSelectedOutputRowCountF(void); + int GetSelectedOutputRowCountF(int *id); - int GetSelectedOutputColumnCountF(void); + int GetSelectedOutputColumnCountF(int *id); - VRESULT GetSelectedOutputValueF(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length); + IPL_RESULT GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length); - void SetSelectedOutputOnF(int* selected_output_on); + IPL_RESULT SetSelectedOutputOnF(int *id, int* selected_output_on); - void SetOutputOnF(int* output_on); + IPL_RESULT SetOutputOnF(int *id, int* output_on); - void SetErrorOnF(int* error_on); + IPL_RESULT SetErrorOnF(int *id, int* error_on); - void SetLogOnF(int* log_on); + IPL_RESULT SetLogOnF(int *id, int* log_on); - void SetDumpOnF(int* dump_on); + IPL_RESULT SetDumpOnF(int *id, int* dump_on); - void SetDumpStringOnF(int* dump_string_on); + IPL_RESULT SetDumpStringOnF(int *id, int* dump_string_on); - int GetDumpLineCountF(void); + int GetDumpLineCountF(int *id); - void GetDumpLineF(int* n, char* line, unsigned int line_length); + void GetDumpLineF(int *id, int* n, char* line, unsigned int line_length); - int GetErrorLineCountF(void); + int GetErrorLineCountF(int *id); - void GetErrorLineF(int* n, char* line, unsigned int line_length); + void GetErrorLineF(int *id, int* n, char* line, unsigned int line_length); - int GetComponentCountF(void); + int GetComponentCountF(int *id); - void GetComponentF(int* n, char* line, unsigned int line_length); + void GetComponentF(int *id, int* n, char* line, unsigned int line_length); - void OutputLastErrorF(void); + void OutputLastErrorF(int *id); - void OutputLinesF(void); + void OutputLinesF(int *id); #if defined(__cplusplus) diff --git a/fwrap2.cpp b/fwrap2.cpp index f2c2bc36..974da1ca 100644 --- a/fwrap2.cpp +++ b/fwrap2.cpp @@ -1,4 +1,4 @@ -#include "Var.h" +#include "IPhreeqcLib.h" // TODO DELETE AFTER RENAMING TO IPhreeqc.h #include "fwrap.h" #if defined(_WIN32) @@ -10,93 +10,97 @@ extern "C" { // // Intel Fortran compiler 9.1 /iface:cvf // -int LOADDATABASE(char *filename, unsigned int len) +int CREATEIPHREEQC(void) { - return LoadDatabaseF(filename, len); + return CreateIPhreeqcF(); } -void OUTPUTLASTERROR(void) +int LOADDATABASE(int *id, char *filename, unsigned int len) { - OutputLastErrorF(); + return LoadDatabaseF(id, filename, len); } -int ACCUMULATELINE(char *line, unsigned int len) +void OUTPUTLASTERROR(int *id) { - return AccumulateLineF(line, len); + OutputLastErrorF(id); } -void SETSELECTEDOUTPUTON(int *selected_on) +int ACCUMULATELINE(int *id, char *line, unsigned int len) { - SetSelectedOutputOnF(selected_on); + return AccumulateLineF(id, line, len); } -void SETOUTPUTON(int *output_on) +void SETSELECTEDOUTPUTON(int *id, int *selected_on) { - SetOutputOnF(output_on); + SetSelectedOutputOnF(id, selected_on); } -void SETERRORON(int *error_on) +void SETOUTPUTON(int *id, int *output_on) { - SetErrorOnF(error_on); + SetOutputOnF(id, output_on); } -void SETLOGON(int *log_on) +void SETERRORON(int *id, int *error_on) { - SetLogOnF(log_on); + SetErrorOnF(id, error_on); } -void SETDUMPON(int *dump_on) +void SETLOGON(int *id, int *log_on) { - SetDumpOnF(dump_on); + SetLogOnF(id, log_on); } -void SETDUMPSTRINGON(int *dump_string_on) +void SETDUMPON(int *id, int *dump_on) { - SetDumpStringOnF(dump_string_on); + SetDumpOnF(id, dump_on); } -int GETDUMPLINECOUNT(void) +void SETDUMPSTRINGON(int *id, int *dump_string_on) { - return GetDumpLineCountF(); + SetDumpStringOnF(id, dump_string_on); } -void GETDUMPLINE(int *n, char* line, unsigned int line_length) +int GETDUMPLINECOUNT(int *id) { - GetDumpLineF(n, line, line_length); + return GetDumpLineCountF(id); } -int GETERRORLINECOUNT(void) +void GETDUMPLINE(int *id, int *n, char* line, unsigned int line_length) { - return GetErrorLineCountF(); + GetDumpLineF(id, n, line, line_length); } -void GETERRORLINE(int *n, char* line, unsigned int line_length) +int GETERRORLINECOUNT(int *id) { - GetErrorLineF(n, line, line_length); + return GetErrorLineCountF(id); } -int GETCOMPONENTCOUNT(void) +void GETERRORLINE(int *id, int *n, char* line, unsigned int line_length) { - return GetComponentCountF(); + GetErrorLineF(id, n, line, line_length); } -void GETCOMPONENT(int *n, char* line, unsigned int line_length) +int GETCOMPONENTCOUNT(int *id) { - GetComponentF(n, line, line_length); + return GetComponentCountF(id); } -int RUNACCUMULATED(void) +void GETCOMPONENT(int *id, int *n, char* line, unsigned int line_length) { - return RunAccumulatedF(); + GetComponentF(id, n, line, line_length); } -int RUNFILE(char *filename, unsigned int len) +int RUNACCUMULATED(int *id) { - return RunFileF(filename, len); + return RunAccumulatedF(id); } -int RUNSTRING(char *input, unsigned int len) +int RUNFILE(int *id, char *filename, unsigned int len) { - return RunStringF(input, len); + return RunFileF(id, filename, len); } -void OUTPUTLINES(void) +int RUNSTRING(int *id, char *input, unsigned int len) { - OutputLinesF(); + return RunStringF(id, input, len); } -int GETSELECTEDOUTPUTROWCOUNT(void) +void OUTPUTLINES(int *id) { - return GetSelectedOutputRowCountF(); + OutputLinesF(id); } -int GETSELECTEDOUTPUTCOLUMNCOUNT(void) +int GETSELECTEDOUTPUTROWCOUNT(int *id) { - return GetSelectedOutputColumnCountF(); + return GetSelectedOutputRowCountF(id); } -int GETSELECTEDOUTPUTVALUE(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +int GETSELECTEDOUTPUTCOLUMNCOUNT(int *id) { - return GetSelectedOutputValueF(row, col, vtype, dvalue, svalue, svalue_length); + return GetSelectedOutputColumnCountF(id); +} +int GETSELECTEDOUTPUTVALUE(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +{ + return GetSelectedOutputValueF(id, row, col, vtype, dvalue, svalue, svalue_length); } #if defined(__cplusplus) diff --git a/fwrap3.cpp b/fwrap3.cpp index 297fd3c9..1fb8903a 100644 --- a/fwrap3.cpp +++ b/fwrap3.cpp @@ -1,4 +1,4 @@ -#include "Var.h" +#include "IPhreeqcLib.h" // TODO DELETE AFTER RENAMING TO IPhreeqc.h #include "fwrap.h" #if defined(_WIN32) @@ -10,93 +10,97 @@ extern "C" { // // Intel Fortran compiler 9.1 /iface:cref /assume:underscore // -int loaddatabase_(char *filename, unsigned int len) +int createiphreeqc_(void) { - return LoadDatabaseF(filename, len); + return CreateIPhreeqcF(); } -void outputlasterror_(void) +int loaddatabase_(int *id, char *filename, unsigned int len) { - OutputLastErrorF(); + return LoadDatabaseF(id, filename, len); } -int accumulateline_(char *line, unsigned int len) +void outputlasterror_(int *id) { - return AccumulateLineF(line, len); + OutputLastErrorF(id); } -void setselectedoutputon_(int *selected_on) +int accumulateline_(int *id, char *line, unsigned int len) { - SetSelectedOutputOnF(selected_on); + return AccumulateLineF(id, line, len); } -void setoutputon_(int *output_on) +void setselectedoutputon_(int *id, int *selected_on) { - SetOutputOnF(output_on); + SetSelectedOutputOnF(id, selected_on); } -void seterroron_(int *error_on) +void setoutputon_(int *id, int *output_on) { - SetErrorOnF(error_on); + SetOutputOnF(id, output_on); } -void setlogon_(int *log_on) +void seterroron_(int *id, int *error_on) { - SetLogOnF(log_on); + SetErrorOnF(id, error_on); } -void setdumpon_(int *dump_on) +void setlogon_(int *id, int *log_on) { - SetLogOnF(dump_on); + SetLogOnF(id, log_on); } -void setdumpstringon_(int *dump_string_on) +void setdumpon_(int *id, int *dump_on) { - SetDumpStringOnF(dump_string_on); + SetLogOnF(id, dump_on); } -int getdumplinecount_(void) +void setdumpstringon_(int *id, int *dump_string_on) { - return GetDumpLineCountF(); + SetDumpStringOnF(id, dump_string_on); } -void getdumpline_(int *n, char* line, unsigned int line_length) +int getdumplinecount_(int *id) { - GetDumpLineF(n, line, line_length); + return GetDumpLineCountF(id); } -int geterrorlinecount_(void) +void getdumpline_(int *id, int *n, char* line, unsigned int line_length) { - return GetErrorLineCountF(); + GetDumpLineF(id, n, line, line_length); } -void geterrorline_(int *n, char* line, unsigned int line_length) +int geterrorlinecount_(int *id) { - GetErrorLineF(n, line, line_length); + return GetErrorLineCountF(id); } -int getcomponentcount_(void) +void geterrorline_(int *id, int *n, char* line, unsigned int line_length) { - return GetComponentCountF(); + GetErrorLineF(id, n, line, line_length); } -void getcomponent_(int *n, char* line, unsigned int line_length) +int getcomponentcount_(int *id) { - GetComponentF(n, line, line_length); + return GetComponentCountF(id); } -int runaccumulated_(void) +void getcomponent_(int *id, int *n, char* line, unsigned int line_length) { - return RunAccumulatedF(); + GetComponentF(id, n, line, line_length); } -int runfile_(char *filename, unsigned int len) +int runaccumulated_(int *id) { - return RunFileF(filename, len); + return RunAccumulatedF(id); } -int runstring_(char *input, unsigned int len) +int runfile_(int *id, char *filename, unsigned int len) { - return RunStringF(input, len); + return RunFileF(id, filename, len); } -void outputlines_(void) +int runstring_(int *id, char *input, unsigned int len) { - OutputLinesF(); + return RunStringF(id, input, len); } -int getselectedoutputrowcount_(void) +void outputlines_(int *id) { - return GetSelectedOutputRowCountF(); + OutputLinesF(id); } -int getselectedoutputcolumncount_(void) +int getselectedoutputrowcount_(int *id) { - return GetSelectedOutputColumnCountF(); + return GetSelectedOutputRowCountF(id); } -int getselectedoutputvalue_(int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +int getselectedoutputcolumncount_(int *id) { - return GetSelectedOutputValueF(row, col, vtype, dvalue, svalue, svalue_length); + return GetSelectedOutputColumnCountF(id); +} +int getselectedoutputvalue_(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +{ + return GetSelectedOutputValueF(id, row, col, vtype, dvalue, svalue, svalue_length); } #if defined(__cplusplus) From d64227b546328aba6ed37e746faee1b038eb6f0f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Apr 2010 21:50:37 +0000 Subject: [PATCH 22/32] renamed return values IPL_ to IPQ_ git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4214 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqcLib.cpp | 106 ++++++++++++++++++++++++------------------------ fwrap.cpp | 22 +++++----- fwrap.h | 16 ++++---- 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp index d7bf26ae..48a02dd2 100644 --- a/IPhreeqcLib.cpp +++ b/IPhreeqcLib.cpp @@ -10,7 +10,7 @@ CreateIPhreeqc(void) return IPhreeqcLib::CreateIPhreeqc(); } -IPL_RESULT +IPQ_RESULT DestroyIPhreeqc(int id) { return IPhreeqcLib::DestroyIPhreeqc(id); @@ -24,7 +24,7 @@ LoadDatabaseM(int id, const char* filename) { return IPhreeqcPtr->LoadDatabase(filename); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -35,7 +35,7 @@ LoadDatabaseStringM(int id, const char* input) { return IPhreeqcPtr->LoadDatabaseString(input); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -45,9 +45,9 @@ UnLoadDatabaseM(int id) if (IPhreeqcPtr) { IPhreeqcPtr->UnLoadDatabase(); - return IPL_OK; + return IPQ_OK; } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } void @@ -147,7 +147,7 @@ GetComponentM(int id, int n) return err_msg; } -IPL_RESULT +IPQ_RESULT AccumulateLineM(int id, const char *line) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); @@ -156,14 +156,14 @@ AccumulateLineM(int id, const char *line) switch (IPhreeqcPtr->AccumulateLine(line)) { case VR_OK: - return IPL_OK; + return IPQ_OK; case VR_OUTOFMEMORY: - return IPL_OUTOFMEMORY; + return IPQ_OUTOFMEMORY; default: assert(false); } } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -181,19 +181,19 @@ GetSelectedOutputOnM(int id) return 0; } } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } -IPL_RESULT +IPQ_RESULT SetSelectedOutputOnM(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetSelectedOutputOn(value != 0); - return IPL_OK; + return IPQ_OK; } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -211,19 +211,19 @@ GetOutputOnM(int id) return 0; } } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } -IPL_RESULT +IPQ_RESULT SetOutputOnM(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetOutputOn(value != 0); - return IPL_OK; + return IPQ_OK; } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -241,19 +241,19 @@ GetErrorOnM(int id) return 0; } } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } -IPL_RESULT +IPQ_RESULT SetErrorOnM(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetErrorOn(value != 0); - return IPL_OK; + return IPQ_OK; } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -271,19 +271,19 @@ GetLogOnM(int id) return 0; } } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } -IPL_RESULT +IPQ_RESULT SetLogOnM(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetLogOn(value != 0); - return IPL_OK; + return IPQ_OK; } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } @@ -302,19 +302,19 @@ GetDumpOnM(int id) return 0; } } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } -IPL_RESULT +IPQ_RESULT SetDumpOnM(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetDumpOn(value != 0); - return IPL_OK; + return IPQ_OK; } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -332,19 +332,19 @@ GetDumpStringOnM(int id) return 0; } } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } -IPL_RESULT +IPQ_RESULT SetDumpStringOnM(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetDumpStringOn(value != 0); - return IPL_OK; + return IPQ_OK; } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -355,7 +355,7 @@ RunAccumulatedM(int id) { return IPhreeqcPtr->RunAccumulated(); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -366,7 +366,7 @@ RunFileM(int id, const char* filename) { return IPhreeqcPtr->RunFile(filename); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -377,7 +377,7 @@ RunStringM(int id, const char* input) { return IPhreeqcPtr->RunString(input); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -388,7 +388,7 @@ GetSelectedOutputRowCountM(int id) { return IPhreeqcPtr->GetSelectedOutputRowCount(); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -399,11 +399,11 @@ GetSelectedOutputColumnCountM(int id) { return IPhreeqcPtr->GetSelectedOutputColumnCount(); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } -IPL_RESULT +IPQ_RESULT GetSelectedOutputValueM(int id, int row, int col, VAR* pVAR) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); @@ -411,17 +411,17 @@ GetSelectedOutputValueM(int id, int row, int col, VAR* pVAR) { switch(IPhreeqcPtr->GetSelectedOutputValue(row, col, pVAR)) { - case VR_OK: return IPL_OK; - case VR_OUTOFMEMORY: return IPL_OUTOFMEMORY; - case VR_BADVARTYPE: return IPL_BADVARTYPE; - case VR_INVALIDARG: return IPL_INVALIDARG; - case VR_INVALIDROW: return IPL_INVALIDROW; - case VR_INVALIDCOL: return IPL_INVALIDCOL; + case VR_OK: return IPQ_OK; + case VR_OUTOFMEMORY: return IPQ_OUTOFMEMORY; + case VR_BADVARTYPE: return IPQ_BADVARTYPE; + case VR_INVALIDARG: return IPQ_INVALIDARG; + case VR_INVALIDROW: return IPQ_INVALIDROW; + case VR_INVALIDCOL: return IPQ_INVALIDCOL; default: assert(false); } } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } int @@ -432,7 +432,7 @@ AddErrorM(int id, const char* error_msg) { return (int)IPhreeqcPtr->AddError(error_msg); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } void @@ -456,7 +456,7 @@ GetErrorLineCountM(int id) { return (int)IPhreeqcPtr->GetErrorLineCount(); } - return IPL_BADINSTANCE; + return IPQ_BADINSTANCE; } const char* @@ -478,7 +478,7 @@ size_t IPhreeqcLib::InstancesIndex = 0; int IPhreeqcLib::CreateIPhreeqc(void) { - int n = IPL_OUTOFMEMORY; + int n = IPQ_OUTOFMEMORY; try { IPhreeqc2* IPhreeqcPtr = new IPhreeqc2; @@ -495,15 +495,15 @@ IPhreeqcLib::CreateIPhreeqc(void) } catch(...) { - return IPL_OUTOFMEMORY; + return IPQ_OUTOFMEMORY; } return n; } -IPL_RESULT +IPQ_RESULT IPhreeqcLib::DestroyIPhreeqc(int id) { - IPL_RESULT retval = IPL_BADINSTANCE; + IPQ_RESULT retval = IPQ_BADINSTANCE; if (id >= 0) { std::map::iterator it = IPhreeqcLib::Instances.find(size_t(id)); @@ -511,7 +511,7 @@ IPhreeqcLib::DestroyIPhreeqc(int id) { delete (*it).second; IPhreeqcLib::Instances.erase(it); - retval = IPL_OK; + retval = IPQ_OK; } } return retval; diff --git a/fwrap.cpp b/fwrap.cpp index bb376daf..fefe79de 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -96,17 +96,17 @@ LoadDatabaseStringF(int *id, char* input, unsigned int input_length) } -IPL_RESULT +IPQ_RESULT AccumulateLineF(int *id, char *line, unsigned int line_length) { - IPL_RESULT n; + IPQ_RESULT n; char* cline; cline = f2cstring(line, line_length); if (!cline) { ::AddErrorM(*id, "AccumulateLine: Out of memory.\n"); - return IPL_OUTOFMEMORY; + return IPQ_OUTOFMEMORY; } n = ::AccumulateLineM(*id, cline); @@ -114,37 +114,37 @@ AccumulateLineF(int *id, char *line, unsigned int line_length) return n; } -IPL_RESULT +IPQ_RESULT SetSelectedOutputOnF(int *id, int* sel_on) { return ::SetSelectedOutputOnM(*id, *sel_on); } -IPL_RESULT +IPQ_RESULT SetOutputOnF(int *id, int* output_on) { return ::SetOutputOnM(*id, *output_on); } -IPL_RESULT +IPQ_RESULT SetErrorOnF(int *id, int* error_on) { return ::SetErrorOnM(*id, *error_on); } -IPL_RESULT +IPQ_RESULT SetLogOnF(int *id, int* log_on) { return ::SetLogOnM(*id, *log_on); } -IPL_RESULT +IPQ_RESULT SetDumpOnF(int *id, int* dump_on) { return ::SetDumpOnM(*id, *dump_on); } -IPL_RESULT +IPQ_RESULT SetDumpStringOnF(int *id, int* dump_string_on) { return ::SetDumpStringOnM(*id, *dump_string_on); @@ -243,10 +243,10 @@ GetSelectedOutputColumnCountF(int *id) return ::GetSelectedOutputColumnCountM(*id); } -IPL_RESULT +IPQ_RESULT GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) { - IPL_RESULT result; + IPQ_RESULT result; VAR v; VarInit(&v); char buffer[100]; diff --git a/fwrap.h b/fwrap.h index a765f784..fdfab211 100644 --- a/fwrap.h +++ b/fwrap.h @@ -10,7 +10,7 @@ extern "C" { int LoadDatabaseF(int *id, char* filename, unsigned int filename_length); - IPL_RESULT AccumulateLineF(int *id, char *line, unsigned int line_length); + IPQ_RESULT AccumulateLineF(int *id, char *line, unsigned int line_length); int RunAccumulatedF(int *id); @@ -22,19 +22,19 @@ extern "C" { int GetSelectedOutputColumnCountF(int *id); - IPL_RESULT GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length); + IPQ_RESULT GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length); - IPL_RESULT SetSelectedOutputOnF(int *id, int* selected_output_on); + IPQ_RESULT SetSelectedOutputOnF(int *id, int* selected_output_on); - IPL_RESULT SetOutputOnF(int *id, int* output_on); + IPQ_RESULT SetOutputOnF(int *id, int* output_on); - IPL_RESULT SetErrorOnF(int *id, int* error_on); + IPQ_RESULT SetErrorOnF(int *id, int* error_on); - IPL_RESULT SetLogOnF(int *id, int* log_on); + IPQ_RESULT SetLogOnF(int *id, int* log_on); - IPL_RESULT SetDumpOnF(int *id, int* dump_on); + IPQ_RESULT SetDumpOnF(int *id, int* dump_on); - IPL_RESULT SetDumpStringOnF(int *id, int* dump_string_on); + IPQ_RESULT SetDumpStringOnF(int *id, int* dump_string_on); int GetDumpLineCountF(int *id); From 2d8f7e0e51a6d5b39b699fada2d6b3015dc75512 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 7 Apr 2010 00:51:52 +0000 Subject: [PATCH 23/32] updated for linux git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4219 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqcF.F | 314 ++++++++++++++++++++++++++++------------------------ fwrap.cpp | 67 ++++++----- fwrap.h | 2 + 3 files changed, 211 insertions(+), 172 deletions(-) diff --git a/IPhreeqcF.F b/IPhreeqcF.F index a0dcb2d5..8a31436d 100644 --- a/IPhreeqcF.F +++ b/IPhreeqcF.F @@ -1,193 +1,217 @@ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION LoadDatabase(FILENAME) + FUNCTION CreateIPhreeqc() IMPLICIT NONE + INTEGER :: CreateIPhreeqc + INTEGER :: CreateIPhreeqcF + CreateIPhreeqc = CreateIPhreeqcF() + END FUNCTION CreateIPhreeqc +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION LoadDatabase(ID,FILENAME) + IMPLICIT NONE + INTEGER :: ID CHARACTER(LEN=*) :: FILENAME INTEGER :: LoadDatabase -#if defined(_WIN32) - INTERFACE - FUNCTION LoadDatabaseF(FILENAME) - !DEC$ ATTRIBUTES C,REFERENCE::LoadDatabaseF - !DEC$ ATTRIBUTES ALIAS:'_LoadDatabaseF'::LoadDatabaseF - CHARACTER(LEN=*) :: FILENAME - INTEGER(KIND=4) :: LoadDatabaseF - END FUNCTION LoadDatabaseF - END INTERFACE -#else INTEGER :: LoadDatabaseF -#endif - - LoadDatabase = LoadDatabaseF(FILENAME) + LoadDatabase = LoadDatabaseF(ID,FILENAME) END FUNCTION LoadDatabase !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - SUBROUTINE OutputLastError + FUNCTION LoadDatabaseString(ID,INPUT) IMPLICIT NONE -#if defined(_WIN32) - INTERFACE - SUBROUTINE OutputLastErrorF - !DEC$ ATTRIBUTES C,REFERENCE::OutputLastErrorF - !DEC$ ATTRIBUTES ALIAS:'_OutputLastError'::OutputLastErrorF - END SUBROUTINE OutputLastErrorF - END INTERFACE -#endif - CALL OutputLastErrorF - END SUBROUTINE OutputLastError + INTEGER :: ID + CHARACTER(LEN=*) :: INPUT + INTEGER :: LoadDatabaseString + INTEGER :: LoadDatabaseStringF + LoadDatabaseString = LoadDatabaseStringF(ID,INPUT) + END FUNCTION LoadDatabaseString !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION AccumulateLine(LINE) + FUNCTION AccumulateLine(ID,LINE) IMPLICIT NONE + INTEGER :: ID CHARACTER(LEN=*) :: LINE INTEGER :: AccumulateLine -#if defined(_WIN32) - INTERFACE - FUNCTION AccumulateLineF(LINE) - !DEC$ ATTRIBUTES C,REFERENCE::AccumulateLineF - !DEC$ ATTRIBUTES ALIAS:'_AccumulateLineF'::AccumulateLineF - CHARACTER(LEN=*) :: LINE - INTEGER(KIND=4) :: AccumulateLineF - END FUNCTION AccumulateLineF - END INTERFACE -#else INTEGER :: AccumulateLineF -#endif - AccumulateLine = AccumulateLineF(LINE) + AccumulateLine = AccumulateLineF(ID,LINE) END FUNCTION AccumulateLine !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION RunAccumulated(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) + FUNCTION SetSelectedOutputOn(ID,SELECTED_ON) IMPLICIT NONE - LOGICAL :: OUTPUT_ON - LOGICAL :: ERROR_ON - LOGICAL :: LOG_ON - LOGICAL :: SELECTED_ON + INTEGER :: ID + LOGICAL :: SELECTED_ON + INTEGER :: SetSelectedOutputOn + INTEGER :: SetSelectedOutputOnF + SetSelectedOutputOn = SetSelectedOutputOnF(ID,SELECTED_ON) + END FUNCTION SetSelectedOutputOn +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION SetOutputOn(ID,OUTPUT_ON) + IMPLICIT NONE + INTEGER :: ID + LOGICAL :: OUTPUT_ON + INTEGER :: SetOutputOn + INTEGER :: SetOutputOnF + SetOutputOn = SetOutputOnF(ID,OUTPUT_ON) + END FUNCTION SetOutputOn +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION SetErrorOn(ID,ERROR_ON) + IMPLICIT NONE + INTEGER :: ID + LOGICAL :: ERROR_ON + INTEGER :: SetErrorOn + INTEGER :: SetErrorOnF + SetErrorOn = SetErrorOnF(ID,ERROR_ON) + END FUNCTION SetErrorOn +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION SetLogOn(ID,LOG_ON) + IMPLICIT NONE + INTEGER :: ID + LOGICAL :: LOG_ON + INTEGER :: SetLogOn + INTEGER :: SetLogOnF + SetLogOn = SetLogOnF(ID,LOG_ON) + END FUNCTION SetLogOn +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION SetDumpOn(ID,DUMP_ON) + IMPLICIT NONE + INTEGER :: ID + LOGICAL :: DUMP_ON + INTEGER :: SetDumpOn + INTEGER :: SetDumpOnF + SetDumpOn = SetDumpOnF(ID,DUMP_ON) + END FUNCTION SetDumpOn +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION SetDumpStringOn(ID,DUMP_STRING_ON) + IMPLICIT NONE + INTEGER :: ID + LOGICAL :: DUMP_STRING_ON + INTEGER :: SetDumpStringOn + INTEGER :: SetDumpStringOnF + SetDumpStringOn = SetDumpStringOnF(ID,DUMP_STRING_ON) + END FUNCTION SetDumpStringOn +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION GetDumpLineCount(ID) + IMPLICIT NONE + INTEGER :: ID + INTEGER :: GetDumpLineCount + INTEGER :: GetDumpLineCountF + GetDumpLineCount = GetDumpLineCountF(ID) + END FUNCTION GetDumpLineCount +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION GetDumpLine(ID,N,LINE) + IMPLICIT NONE + INTEGER :: ID + INTEGER :: N + CHARACTER(LEN=*) :: LINE + INTEGER :: GetDumpLine + INTEGER :: GetDumpLineF + GetDumpLine = GetDumpLineF(ID,N,LINE) + END FUNCTION GetDumpLine +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION GetErrorLineCount(ID) + IMPLICIT NONE + INTEGER :: ID + INTEGER :: GetErrorLineCount + INTEGER :: GetErrorLineCountF + GetErrorLineCount = GetErrorLineCountF(ID) + END FUNCTION GetErrorLineCount +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION GetErrorLine(ID,N,LINE) + IMPLICIT NONE + INTEGER :: ID + INTEGER :: N + CHARACTER(LEN=*) :: LINE + INTEGER :: GetErrorLine + INTEGER :: GetErrorLineF + GetErrorLine = GetErrorLineF(ID,N,LINE) + END FUNCTION GetErrorLine +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION GetComponentCount(ID) + IMPLICIT NONE + INTEGER :: ID + INTEGER :: GetComponentCount + INTEGER :: GetComponentCountF + GetComponentCount = GetComponentCountF(ID) + END FUNCTION GetComponentCount +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION GetComponent(ID,N,COMP) + IMPLICIT NONE + INTEGER :: ID + INTEGER :: N + CHARACTER(LEN=*) :: COMP + INTEGER :: GetComponent + INTEGER :: GetComponentF + GetComponent = GetComponentF(ID,N,COMP) + END FUNCTION GetComponent +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION RunAccumulated(ID) + IMPLICIT NONE + INTEGER :: ID INTEGER :: RunAccumulated -#if defined(_WIN32) - INTERFACE - FUNCTION RunAccumulatedF(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) - !DEC$ ATTRIBUTES C,REFERENCE::RunF - !DEC$ ATTRIBUTES ALIAS:'_RunF'::RunF - LOGICAL(KIND=4) :: OUTPUT_ON - LOGICAL(KIND=4) :: ERROR_ON - LOGICAL(KIND=4) :: LOG_ON - LOGICAL(KIND=4) :: SELECTED_ON - INTEGER(KIND=4) :: RunF - END FUNCTION RunAccumulatedF - END INTERFACE -#else INTEGER :: RunAccumulatedF -#endif - RunAccumulated = RunAccumulatedF(OUTPUT_ON, ERROR_ON, - & LOG_ON, SELECTED_ON) + RunAccumulated = RunAccumulatedF(ID) END FUNCTION RunAccumulated !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION RunFile(FILENAME,OUTPUT_ON,ERROR_ON,LOG_ON,SELECTED_ON) + FUNCTION RunFile(ID,FILENAME) IMPLICIT NONE + INTEGER :: ID CHARACTER(LEN=*) :: FILENAME - LOGICAL :: OUTPUT_ON - LOGICAL :: ERROR_ON - LOGICAL :: LOG_ON - LOGICAL :: SELECTED_ON INTEGER :: RunFile -#if defined(_WIN32) - INTERFACE - FUNCTION RunFileF(OUT_ON, ERR_ON, LOG_ON, SEL_ON, FILE) - !DEC$ ATTRIBUTES C,REFERENCE::RunFileF - !DEC$ ATTRIBUTES ALIAS:'_RunFileF'::RunFileF - LOGICAL(KIND=4) :: OUT_ON - LOGICAL(KIND=4) :: ERR_ON - LOGICAL(KIND=4) :: LOG_ON - LOGICAL(KIND=4) :: SEL_ON - CHARACTER(LEN=*) :: FILE - INTEGER(KIND=4) :: RunFileF - END FUNCTION RunFileF - END INTERFACE -#else INTEGER :: RunFileF -#endif - RunFile = RunFileF(OUTPUT_ON, ERROR_ON, LOG_ON, - & SELECTED_ON, FILENAME) + RunFile = RunFileF(ID,FILENAME) END FUNCTION RunFile !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - SUBROUTINE OutputLines + FUNCTION RunString(ID,INPUT) IMPLICIT NONE -#if defined(_WIN32) - INTERFACE - SUBROUTINE OutputLinesF - !DEC$ ATTRIBUTES C,REFERENCE::OutputLinesF - !DEC$ ATTRIBUTES ALIAS:'_OutputLines'::OutputLinesF - END SUBROUTINE OutputLinesF - END INTERFACE -#endif - CALL OutputLinesF - END SUBROUTINE OutputLines + INTEGER :: ID + CHARACTER(LEN=*) :: INPUT + INTEGER :: RunString + INTEGER :: RunStringF + RunString = RunStringF(ID,INPUT) + END FUNCTION RunString !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION GetSelectedOutputRowCount() + FUNCTION GetSelectedOutputRowCount(ID) IMPLICIT NONE - INTEGER :: GetSelectedOutputRowCount -#if defined(_WIN32) - INTERFACE - FUNCTION FRows - !DEC$ ATTRIBUTES C,REFERENCE::FRows - !DEC$ ATTRIBUTES ALIAS:'_GetSelectedOutputRowCountF'::FRows - INTEGER(KIND=4) :: FRows - END FUNCTION FRows - END INTERFACE - GetSelectedOutputRowCount = FRows() - 1 -#else - INTEGER :: GetSelectedOutputRowCountF - GetSelectedOutputRowCount = GetSelectedOutputRowCountF() - 1 -#endif + INTEGER :: ID + INTEGER :: GetSelectedOutputRowCount + INTEGER :: GetSelectedOutputRowCountF + GetSelectedOutputRowCount = GetSelectedOutputRowCountF(ID) END FUNCTION GetSelectedOutputRowCount !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION GetSelectedOutputColumnCount() + FUNCTION GetSelectedOutputColumnCount(ID) IMPLICIT NONE + INTEGER :: ID INTEGER :: GetSelectedOutputColumnCount -#if defined(_WIN32) - INTERFACE - FUNCTION FCols - !DEC$ ATTRIBUTES C,REFERENCE::FCols - !DEC$ ATTRIBUTES ALIAS:'_GetSelectedOutputColumnCount'::FCols - INTEGER(KIND=4) :: FCols - END FUNCTION FCols - END INTERFACE - GetSelectedOutputColumnCount = FCols() -#else INTEGER :: GetSelectedOutputColumnCountF - GetSelectedOutputColumnCount = GetSelectedOutputColumnCountF() -#endif + GetSelectedOutputColumnCount = GetSelectedOutputColumnCountF(ID) END FUNCTION GetSelectedOutputColumnCount !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION GetSelectedOutputValue(ROW,COL,VTYPE,DVALUE,SVALUE) + FUNCTION GetSelectedOutputValue(ID,ROW,COL,VTYPE,DVALUE,SVALUE) IMPLICIT NONE + INTEGER :: ID INTEGER :: ROW INTEGER :: COL INTEGER :: VTYPE REAL*8 :: DVALUE CHARACTER(LEN=*) :: SVALUE INTEGER :: GetSelectedOutputValue -#if defined(_WIN32) - INTERFACE - FUNCTION Get(ROW,COL,VTYPE,DVALUE,SVALUE) - !DEC$ ATTRIBUTES C,REFERENCE::Get - !DEC$ ATTRIBUTES ALIAS:'_GetSelectedOutputValueF'::Get - INTEGER(KIND=4) :: ROW - INTEGER(KIND=4) :: COL - INTEGER(KIND=4) :: VTYPE - REAL(KIND=8) :: DVALUE - CHARACTER(LEN=*) :: SVALUE - INTEGER(KIND=4) :: Get - END FUNCTION Get - END INTERFACE - adjcol = col - 1 - GetSelectedOutputValue = Get(ROW,adjcol,VTYPE,DVALUE,SVALUE) -#else INTEGER :: GetSelectedOutputValueF - GetSelectedOutputValue = GetSelectedOutputValueF(ROW, + GetSelectedOutputValue = GetSelectedOutputValueF(ID,ROW, & COL,VTYPE,DVALUE,SVALUE) -#endif END FUNCTION GetSelectedOutputValue !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION System(COMMAND) + SUBROUTINE OutputLastError IMPLICIT NONE - CHARACTER(LEN=*) :: COMMAND - INTEGER :: System - INTEGER :: SystemF - System = SystemF(COMMAND) - END FUNCTION System + CALL OutputLastErrorF + END SUBROUTINE OutputLastError +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + SUBROUTINE OutputLines(ID) + IMPLICIT NONE + INTEGER :: ID + CALL OutputLinesF(ID) + END SUBROUTINE OutputLines +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!! FUNCTION System(COMMAND) +!! IMPLICIT NONE +!! CHARACTER(LEN=*) :: COMMAND +!! INTEGER :: System +!! INTEGER :: SystemF +!! System = SystemF(COMMAND) +!! END FUNCTION System diff --git a/fwrap.cpp b/fwrap.cpp index fefe79de..78854e4c 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -12,17 +12,31 @@ compile fortran with: g77 -fno-second-underscore ********************************/ #if defined(__GNUC__) -#define LoadDatabaseF loaddatabasef_ #define AccumulateLineF accumulatelinef_ -#define RunAccumulatedF runaccumulatedf_ -#define RunFileF runfilef_ +#define CreateIPhreeqcF createiphreeqcf_ +#define GetComponentCountF getcomponentcountf_ +#define GetComponentF getcomponentf_ +#define GetDumpLineCountF getdumplinecountf_ +#define GetDumpLineF getdumplinef_ +#define GetErrorLineCountF geterrorlinecountf_ +#define GetErrorLineF geterrorlinef_ +#define GetSelectedOutputColumnCountF getselectedoutputcolumncountf_ +#define GetSelectedOutputRowCountF getselectedoutputrowcountf_ #define GetSelectedOutputValueF getselectedoutputvaluef_ +#define LoadDatabaseF loaddatabasef_ +#define LoadDatabaseStringF loaddatabasestringf_ #define OutputLastErrorF outputlasterrorf_ #define OutputLinesF outputlinesf_ -#define GetSelectedOutputRowCountF getselectedoutputrowcountf_ -#define GetSelectedOutputColumnCountF getselectedoutputcolumncountf_ -#define GetSelectedOutputValueF getselectedoutputvaluef_ -#define SystemF systemf_ +#define RunAccumulatedF runaccumulatedf_ +#define RunFileF runfilef_ +#define RunStringF runstringf_ +#define SetDumpOnF setdumponf_ +#define SetDumpStringOnF setdumpstringonf_ +#define SetErrorOnF seterroronf_ +#define SetLogOnF setlogonf_ +#define SetOutputOnF setoutputonf_ +#define SetSelectedOutputOnF setselectedoutputonf_ +//#define SystemF systemf_ #endif #include "fwrap.h" @@ -86,7 +100,7 @@ LoadDatabaseStringF(int *id, char* input, unsigned int input_length) cinput = f2cstring(input, input_length); if (!cinput) { - ::AddErrorM(*id, "LoadDatabase: Out of memory.\n"); + ::AddErrorM(*id, "LoadDatabaseString: Out of memory.\n"); return VR_OUTOFMEMORY; } @@ -95,7 +109,6 @@ LoadDatabaseStringF(int *id, char* input, unsigned int input_length) return n; } - IPQ_RESULT AccumulateLineF(int *id, char *line, unsigned int line_length) { @@ -181,9 +194,9 @@ GetComponentCountF(int *id) } void -GetComponentF(int *id, int *n, char* line, unsigned int line_length) +GetComponentF(int *id, int *n, char* comp, unsigned int line_length) { - padfstring(line, ::GetComponentM(*id, (*n) - 1), line_length); + padfstring(comp, ::GetComponentM(*id, (*n) - 1), line_length); } int @@ -301,22 +314,22 @@ OutputLinesF(int *id) extern "C" { #endif -// COMMENT: {4/5/2010 7:12:55 PM}int -// COMMENT: {4/5/2010 7:12:55 PM}SystemF(char* command, unsigned int command_length) -// COMMENT: {4/5/2010 7:12:55 PM}{ -// COMMENT: {4/5/2010 7:12:55 PM} char* ccommand; -// COMMENT: {4/5/2010 7:12:55 PM} -// COMMENT: {4/5/2010 7:12:55 PM} ccommand = f2cstring(command, command_length); -// COMMENT: {4/5/2010 7:12:55 PM} if (!ccommand) -// COMMENT: {4/5/2010 7:12:55 PM} { -// COMMENT: {4/5/2010 7:12:55 PM} AddError("System: Out of memory.\n"); -// COMMENT: {4/5/2010 7:12:55 PM} return (int)VR_OUTOFMEMORY; -// COMMENT: {4/5/2010 7:12:55 PM} } -// COMMENT: {4/5/2010 7:12:55 PM} -// COMMENT: {4/5/2010 7:12:55 PM} int n = system(ccommand); -// COMMENT: {4/5/2010 7:12:55 PM} free(ccommand); -// COMMENT: {4/5/2010 7:12:55 PM} return n; -// COMMENT: {4/5/2010 7:12:55 PM}} +int +SystemF(char* command, unsigned int command_length) +{ + char* ccommand; + + ccommand = f2cstring(command, command_length); + if (!ccommand) + { + //AddError("System: Out of memory.\n"); + return (int)VR_OUTOFMEMORY; + } + + int n = system(ccommand); + free(ccommand); + return n; +} #if defined(__cplusplus) } diff --git a/fwrap.h b/fwrap.h index fdfab211..3b1c0a16 100644 --- a/fwrap.h +++ b/fwrap.h @@ -10,6 +10,8 @@ extern "C" { int LoadDatabaseF(int *id, char* filename, unsigned int filename_length); + int LoadDatabaseStringF(int *id, char* input, unsigned int input_length); + IPQ_RESULT AccumulateLineF(int *id, char *line, unsigned int line_length); int RunAccumulatedF(int *id); From 094d4c0684ec713ac2c89e96a559fb5d0ea31ad2 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 7 Apr 2010 20:52:16 +0000 Subject: [PATCH 24/32] Renamed IPhreeqcLib.h to IPhreeqc.h git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4221 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqcLib.cpp | 2 +- fwrap.cpp | 2 +- fwrap2.cpp | 2 +- fwrap3.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp index 48a02dd2..b327c399 100644 --- a/IPhreeqcLib.cpp +++ b/IPhreeqcLib.cpp @@ -1,4 +1,4 @@ -#include "IPhreeqcLib.h" +#include "IPhreeqc.h" #include "IPhreeqc2.h" #include #include diff --git a/fwrap.cpp b/fwrap.cpp index 78854e4c..e6e404d6 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -4,7 +4,7 @@ #include /* assert */ #include /* sprintf */ #include "phrqtype.h" -#include "IPhreeqcLib.h" // TODO DELETE AFTER RENAMING TO IPhreeqc.h +#include "IPhreeqc.h" /******************************* When using GNU gcc/g++/g77 diff --git a/fwrap2.cpp b/fwrap2.cpp index 974da1ca..9fed894c 100644 --- a/fwrap2.cpp +++ b/fwrap2.cpp @@ -1,4 +1,4 @@ -#include "IPhreeqcLib.h" // TODO DELETE AFTER RENAMING TO IPhreeqc.h +#include "IPhreeqc.h" #include "fwrap.h" #if defined(_WIN32) diff --git a/fwrap3.cpp b/fwrap3.cpp index 1fb8903a..cb328836 100644 --- a/fwrap3.cpp +++ b/fwrap3.cpp @@ -1,4 +1,4 @@ -#include "IPhreeqcLib.h" // TODO DELETE AFTER RENAMING TO IPhreeqc.h +#include "IPhreeqc.h" #include "fwrap.h" #if defined(_WIN32) From 1daa55e41cbf786ed8939d0416cab65216423ca0 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 7 Apr 2010 21:30:49 +0000 Subject: [PATCH 25/32] renamed *M routines without the M git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4223 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqcLib.cpp | 77 ++++++++++++++++++++++++++++--------------------- fwrap.cpp | 56 +++++++++++++++++------------------ 2 files changed, 72 insertions(+), 61 deletions(-) diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp index b327c399..b50f7597 100644 --- a/IPhreeqcLib.cpp +++ b/IPhreeqcLib.cpp @@ -3,6 +3,17 @@ #include #include +class IPhreeqcLib +{ +public: + static int CreateIPhreeqc(void); + static IPQ_RESULT DestroyIPhreeqc(int n); + static IPhreeqc2* GetInstance(int n); + +private: + static std::map Instances; + static size_t InstancesIndex; +}; int CreateIPhreeqc(void) @@ -17,7 +28,7 @@ DestroyIPhreeqc(int id) } int -LoadDatabaseM(int id, const char* filename) +LoadDatabase(int id, const char* filename) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -28,7 +39,7 @@ LoadDatabaseM(int id, const char* filename) } int -LoadDatabaseStringM(int id, const char* input) +LoadDatabaseString(int id, const char* input) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -39,7 +50,7 @@ LoadDatabaseStringM(int id, const char* input) } int -UnLoadDatabaseM(int id) +UnLoadDatabase(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -51,7 +62,7 @@ UnLoadDatabaseM(int id) } void -OutputLastErrorM(int id) +OutputLastError(int id) { static const char err_msg[] = "OutputLastError: Bad instance.\n"; IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); @@ -64,7 +75,7 @@ OutputLastErrorM(int id) } const char* -GetLastErrorStringM(int id) +GetLastErrorString(int id) { static const char err_msg[] = "GetLastErrorString: Bad instance.\n"; IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); @@ -76,7 +87,7 @@ GetLastErrorStringM(int id) } const char* -GetDumpStringM(int id) +GetDumpString(int id) { static const char empty[] = ""; IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); @@ -88,7 +99,7 @@ GetDumpStringM(int id) } int -GetDumpLineCountM(int id) +GetDumpLineCount(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -99,7 +110,7 @@ GetDumpLineCountM(int id) } const char* -GetDumpLineM(int id, int n) +GetDumpLine(int id, int n) { static const char err_msg[] = "GetDumpLine: Bad instance.\n"; IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); @@ -111,7 +122,7 @@ GetDumpLineM(int id, int n) } int -GetComponentCountM(int id) +GetComponentCount(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -122,7 +133,7 @@ GetComponentCountM(int id) } const char* -GetComponentM(int id, int n) +GetComponent(int id, int n) { static const char err_msg[] = "GetComponent: Bad instance.\n"; static const char empty[] = ""; @@ -148,7 +159,7 @@ GetComponentM(int id, int n) } IPQ_RESULT -AccumulateLineM(int id, const char *line) +AccumulateLine(int id, const char *line) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -167,7 +178,7 @@ AccumulateLineM(int id, const char *line) } int -GetSelectedOutputOnM(int id) +GetSelectedOutputOn(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -185,7 +196,7 @@ GetSelectedOutputOnM(int id) } IPQ_RESULT -SetSelectedOutputOnM(int id, int value) +SetSelectedOutputOn(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -197,7 +208,7 @@ SetSelectedOutputOnM(int id, int value) } int -GetOutputOnM(int id) +GetOutputOn(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -215,7 +226,7 @@ GetOutputOnM(int id) } IPQ_RESULT -SetOutputOnM(int id, int value) +SetOutputOn(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -227,7 +238,7 @@ SetOutputOnM(int id, int value) } int -GetErrorOnM(int id) +GetErrorOn(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -245,7 +256,7 @@ GetErrorOnM(int id) } IPQ_RESULT -SetErrorOnM(int id, int value) +SetErrorOn(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -257,7 +268,7 @@ SetErrorOnM(int id, int value) } int -GetLogOnM(int id) +GetLogOn(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -275,7 +286,7 @@ GetLogOnM(int id) } IPQ_RESULT -SetLogOnM(int id, int value) +SetLogOn(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -288,7 +299,7 @@ SetLogOnM(int id, int value) int -GetDumpOnM(int id) +GetDumpOn(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -306,7 +317,7 @@ GetDumpOnM(int id) } IPQ_RESULT -SetDumpOnM(int id, int value) +SetDumpOn(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -318,7 +329,7 @@ SetDumpOnM(int id, int value) } int -GetDumpStringOnM(int id) +GetDumpStringOn(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -336,7 +347,7 @@ GetDumpStringOnM(int id) } IPQ_RESULT -SetDumpStringOnM(int id, int value) +SetDumpStringOn(int id, int value) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -348,7 +359,7 @@ SetDumpStringOnM(int id, int value) } int -RunAccumulatedM(int id) +RunAccumulated(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -359,7 +370,7 @@ RunAccumulatedM(int id) } int -RunFileM(int id, const char* filename) +RunFile(int id, const char* filename) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -370,7 +381,7 @@ RunFileM(int id, const char* filename) } int -RunStringM(int id, const char* input) +RunString(int id, const char* input) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -381,7 +392,7 @@ RunStringM(int id, const char* input) } int -GetSelectedOutputRowCountM(int id) +GetSelectedOutputRowCount(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -392,7 +403,7 @@ GetSelectedOutputRowCountM(int id) } int -GetSelectedOutputColumnCountM(int id) +GetSelectedOutputColumnCount(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -404,7 +415,7 @@ GetSelectedOutputColumnCountM(int id) IPQ_RESULT -GetSelectedOutputValueM(int id, int row, int col, VAR* pVAR) +GetSelectedOutputValue(int id, int row, int col, VAR* pVAR) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -425,7 +436,7 @@ GetSelectedOutputValueM(int id, int row, int col, VAR* pVAR) } int -AddErrorM(int id, const char* error_msg) +AddError(int id, const char* error_msg) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -436,7 +447,7 @@ AddErrorM(int id, const char* error_msg) } void -OutputLinesM(int id) +OutputLines(int id) { static const char err_msg[] = "OutputLines: Bad instance.\n"; IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); @@ -449,7 +460,7 @@ OutputLinesM(int id) } int -GetErrorLineCountM(int id) +GetErrorLineCount(int id) { IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) @@ -460,7 +471,7 @@ GetErrorLineCountM(int id) } const char* -GetErrorLineM(int id, int n) +GetErrorLine(int id, int n) { static const char err_msg[] = "GetErrorLine: Bad instance.\n"; IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); diff --git a/fwrap.cpp b/fwrap.cpp index e6e404d6..18787f12 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -83,11 +83,11 @@ LoadDatabaseF(int *id, char* filename, unsigned int filename_length) cfilename = f2cstring(filename, filename_length); if (!cfilename) { - ::AddErrorM(*id, "LoadDatabase: Out of memory.\n"); + ::AddError(*id, "LoadDatabase: Out of memory.\n"); return VR_OUTOFMEMORY; } - int n = ::LoadDatabaseM(*id, cfilename); + int n = ::LoadDatabase(*id, cfilename); free(cfilename); return n; } @@ -100,11 +100,11 @@ LoadDatabaseStringF(int *id, char* input, unsigned int input_length) cinput = f2cstring(input, input_length); if (!cinput) { - ::AddErrorM(*id, "LoadDatabaseString: Out of memory.\n"); + ::AddError(*id, "LoadDatabaseString: Out of memory.\n"); return VR_OUTOFMEMORY; } - int n = ::LoadDatabaseStringM(*id, cinput); + int n = ::LoadDatabaseString(*id, cinput); free(cinput); return n; } @@ -118,11 +118,11 @@ AccumulateLineF(int *id, char *line, unsigned int line_length) cline = f2cstring(line, line_length); if (!cline) { - ::AddErrorM(*id, "AccumulateLine: Out of memory.\n"); + ::AddError(*id, "AccumulateLine: Out of memory.\n"); return IPQ_OUTOFMEMORY; } - n = ::AccumulateLineM(*id, cline); + n = ::AccumulateLine(*id, cline); free(cline); return n; } @@ -130,79 +130,79 @@ AccumulateLineF(int *id, char *line, unsigned int line_length) IPQ_RESULT SetSelectedOutputOnF(int *id, int* sel_on) { - return ::SetSelectedOutputOnM(*id, *sel_on); + return ::SetSelectedOutputOn(*id, *sel_on); } IPQ_RESULT SetOutputOnF(int *id, int* output_on) { - return ::SetOutputOnM(*id, *output_on); + return ::SetOutputOn(*id, *output_on); } IPQ_RESULT SetErrorOnF(int *id, int* error_on) { - return ::SetErrorOnM(*id, *error_on); + return ::SetErrorOn(*id, *error_on); } IPQ_RESULT SetLogOnF(int *id, int* log_on) { - return ::SetLogOnM(*id, *log_on); + return ::SetLogOn(*id, *log_on); } IPQ_RESULT SetDumpOnF(int *id, int* dump_on) { - return ::SetDumpOnM(*id, *dump_on); + return ::SetDumpOn(*id, *dump_on); } IPQ_RESULT SetDumpStringOnF(int *id, int* dump_string_on) { - return ::SetDumpStringOnM(*id, *dump_string_on); + return ::SetDumpStringOn(*id, *dump_string_on); } int GetDumpLineCountF(int *id) { - return ::GetDumpLineCountM(*id); + return ::GetDumpLineCount(*id); } void GetDumpLineF(int *id, int* n, char* line, unsigned int line_length) { - padfstring(line, ::GetDumpLineM(*id, (*n) - 1), line_length); + padfstring(line, ::GetDumpLine(*id, (*n) - 1), line_length); } int GetErrorLineCountF(int *id) { - return ::GetErrorLineCountM(*id); + return ::GetErrorLineCount(*id); } void GetErrorLineF(int *id, int* n, char* line, unsigned int line_length) { - padfstring(line, ::GetErrorLineM(*id, (*n) - 1), line_length); + padfstring(line, ::GetErrorLine(*id, (*n) - 1), line_length); } int GetComponentCountF(int *id) { - return ::GetComponentCountM(*id); + return ::GetComponentCount(*id); } void GetComponentF(int *id, int *n, char* comp, unsigned int line_length) { - padfstring(comp, ::GetComponentM(*id, (*n) - 1), line_length); + padfstring(comp, ::GetComponent(*id, (*n) - 1), line_length); } int RunAccumulatedF(int *id) { - return ::RunAccumulatedM(*id); + return ::RunAccumulated(*id); } int @@ -213,11 +213,11 @@ RunFileF(int *id, char* filename, unsigned int filename_length) cfilename = f2cstring(filename, filename_length); if (!cfilename) { - ::AddErrorM(*id, "RunFile: Out of memory.\n"); + ::AddError(*id, "RunFile: Out of memory.\n"); return (int)VR_OUTOFMEMORY; } - int n = ::RunFileM(*id, cfilename); + int n = ::RunFile(*id, cfilename); free(cfilename); return n; } @@ -230,11 +230,11 @@ RunStringF(int *id, char* input, unsigned int input_length) cinput = f2cstring(input, input_length); if (!cinput) { - ::AddErrorM(*id, "RunString: Out of memory.\n"); + ::AddError(*id, "RunString: Out of memory.\n"); return (int)VR_OUTOFMEMORY; } - int n = ::RunStringM(*id, cinput); + int n = ::RunString(*id, cinput); free(cinput); return n; } @@ -242,7 +242,7 @@ RunStringF(int *id, char* input, unsigned int input_length) int GetSelectedOutputRowCountF(int *id) { - int rows = ::GetSelectedOutputRowCountM(*id); + int rows = ::GetSelectedOutputRowCount(*id); if (rows > 0) { rows -= 1; @@ -253,7 +253,7 @@ GetSelectedOutputRowCountF(int *id) int GetSelectedOutputColumnCountF(int *id) { - return ::GetSelectedOutputColumnCountM(*id); + return ::GetSelectedOutputColumnCount(*id); } IPQ_RESULT @@ -265,7 +265,7 @@ GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue, char buffer[100]; int adjcol = *col - 1; - result = ::GetSelectedOutputValueM(*id, *row, adjcol, &v); + result = ::GetSelectedOutputValue(*id, *row, adjcol, &v); switch (v.type) { @@ -301,13 +301,13 @@ GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue, void OutputLastErrorF(int *id) { - ::OutputLastErrorM(*id); + ::OutputLastError(*id); } void OutputLinesF(int *id) { - ::OutputLinesM(*id); + ::OutputLines(*id); } #if defined(__cplusplus) From a9e0a887fd0cc4fe8506ee8a07e9942b9bd7baba Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 7 Apr 2010 21:41:55 +0000 Subject: [PATCH 26/32] renamed *2 routines without the 2 git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4224 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc2.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/IPhreeqc2.cpp b/IPhreeqc2.cpp index 7b7e4693..bf27fce3 100644 --- a/IPhreeqc2.cpp +++ b/IPhreeqc2.cpp @@ -60,22 +60,22 @@ IPhreeqc2::~IPhreeqc2(void) delete this->PhreeqcPtr; } -int IPhreeqc2::handler2(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +int IPhreeqc2::handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) { int n = OK; IPhreeqc2 *pThis = (IPhreeqc2*)cookie; switch (action) { case Phreeqc::ACTION_OPEN: - n = pThis->open_handler2(type, err_str); + n = pThis->open_handler(type, err_str); break; case Phreeqc::ACTION_OUTPUT: - n = pThis->output_handler2(type, err_str, stop, cookie, format, args); + n = pThis->output_handler(type, err_str, stop, cookie, format, args); break; default: - n = pThis->module_handler2(action, type, err_str, stop, cookie, format, args); + n = pThis->module_handler(action, type, err_str, stop, cookie, format, args); break; } @@ -86,7 +86,7 @@ int IPhreeqc2::handler2(const int action, const int type, const char *err_str, c return n; } -int IPhreeqc2::output_handler2(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +int IPhreeqc2::output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) { assert(cookie == this); @@ -123,10 +123,10 @@ int IPhreeqc2::output_handler2(const int type, const char *err_str, const int st break; } - return module_handler2(Phreeqc::ACTION_OUTPUT, type, err_str, stop, cookie, format, args); + return module_handler(Phreeqc::ACTION_OUTPUT, type, err_str, stop, cookie, format, args); } -int IPhreeqc2::open_handler2(const int type, const char *file_name) +int IPhreeqc2::open_handler(const int type, const char *file_name) { int n = OK; switch (type) @@ -141,27 +141,27 @@ int IPhreeqc2::open_handler2(const int type, const char *file_name) } if (this->SelectedOutputOn) { - n = module_handler2(Phreeqc::ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); + n = module_handler(Phreeqc::ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); } break; default: - n = module_handler2(Phreeqc::ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); + n = module_handler(Phreeqc::ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL); break; } return n; } -int IPhreeqc2::module_handler2(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +int IPhreeqc2::module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) { IPhreeqc2* pThis = (IPhreeqc2*) cookie; switch (action) { case Phreeqc::ACTION_OPEN: - return pThis->module_open_handler2(type, err_str); + return pThis->module_open_handler(type, err_str); break; case ACTION_ISOPEN: - return pThis->module_isopen_handler2(type); + return pThis->module_isopen_handler(type); break; default: return pThis->PhreeqcPtr->phreeqc_handler(action, type, err_str, stop, pThis->PhreeqcPtr, format, args); @@ -170,7 +170,7 @@ int IPhreeqc2::module_handler2(const int action, const int type, const char *err return ERROR; } -int IPhreeqc2::module_isopen_handler2(const int type) +int IPhreeqc2::module_isopen_handler(const int type) { switch (type) { @@ -183,7 +183,7 @@ int IPhreeqc2::module_isopen_handler2(const int type) return 0; } -int IPhreeqc2::module_open_handler2(const int type, const char *file_name) +int IPhreeqc2::module_open_handler(const int type, const char *file_name) { assert(file_name && ::strlen(file_name)); switch (type) @@ -233,7 +233,7 @@ int IPhreeqc2::module_open_handler2(const int type, const char *file_name) return(OK); } -int IPhreeqc2::output_isopen2(const int type) +int IPhreeqc2::output_isopen(const int type) { size_t i; int isopen; @@ -405,7 +405,7 @@ void IPhreeqc2::UnLoadDatabase(void) // initialize phreeqc // this->PhreeqcPtr->clean_up(); - this->PhreeqcPtr->add_output_callback(IPhreeqc2::handler2, this); + this->PhreeqcPtr->add_output_callback(IPhreeqc2::handler, this); this->PhreeqcPtr->do_initialize(); this->PhreeqcPtr->input_error = 0; } @@ -798,7 +798,7 @@ void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_ // TRUE ??? // // - if (!this->SelectedOutputOn) ASSERT(!this->output_isopen2(Phreeqc::OUTPUT_PUNCH)); + if (!this->SelectedOutputOn) ASSERT(!this->output_isopen(Phreeqc::OUTPUT_PUNCH)); if (this->PhreeqcPtr->pr.punch == FALSE) { @@ -812,7 +812,7 @@ void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_ { if (this->PhreeqcPtr->punch.new_def == FALSE) { - if (this->SelectedOutputOn && !this->output_isopen2(Phreeqc::OUTPUT_PUNCH)) + if (this->SelectedOutputOn && !this->output_isopen(Phreeqc::OUTPUT_PUNCH)) { // // LoadDatabase @@ -821,7 +821,7 @@ void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_ // std::string filename = this->PunchFileName; this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_PUNCH, filename.c_str()); - if (!this->output_isopen2(Phreeqc::OUTPUT_PUNCH)) + if (!this->output_isopen(Phreeqc::OUTPUT_PUNCH)) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n"; @@ -837,7 +837,7 @@ void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_ } else { - if (this->SelectedOutputOn && !this->output_isopen2(Phreeqc::OUTPUT_PUNCH)) + if (this->SelectedOutputOn && !this->output_isopen(Phreeqc::OUTPUT_PUNCH)) { // This is a special case which could not occur in // phreeqc @@ -852,7 +852,7 @@ void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_ filename = this->PunchFileName; } this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_PUNCH, filename.c_str()); - if (!this->output_isopen2(Phreeqc::OUTPUT_PUNCH)) + if (!this->output_isopen(Phreeqc::OUTPUT_PUNCH)) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n"; @@ -869,7 +869,7 @@ void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_ } } - if (!this->SelectedOutputOn) ASSERT(!this->output_isopen2(Phreeqc::OUTPUT_PUNCH)); + if (!this->SelectedOutputOn) ASSERT(!this->output_isopen(Phreeqc::OUTPUT_PUNCH)); /* the converse is not necessarily true */ this->PhreeqcPtr->n_user_punch_index = -1; From 7728a79b35b4ca1cff44c3d133ef418186fa03d3 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 7 Apr 2010 22:13:33 +0000 Subject: [PATCH 27/32] renamed IPhreeqc2.h to IPhreeqc.hpp renamed IPhreeqc2.cpp to IPhreeqc.cpp git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4225 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc2.cpp => IPhreeqc.cpp | 2 +- IPhreeqcLib.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename IPhreeqc2.cpp => IPhreeqc.cpp (95%) diff --git a/IPhreeqc2.cpp b/IPhreeqc.cpp similarity index 95% rename from IPhreeqc2.cpp rename to IPhreeqc.cpp index bf27fce3..b52df730 100644 --- a/IPhreeqc2.cpp +++ b/IPhreeqc.cpp @@ -1,4 +1,4 @@ -#include "IPhreeqc2.h" +#include "IPhreeqc.hpp" #include "Phreeqc.h" // Phreeqc #include // assert diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp index b50f7597..2e2a41ca 100644 --- a/IPhreeqcLib.cpp +++ b/IPhreeqcLib.cpp @@ -1,5 +1,5 @@ #include "IPhreeqc.h" -#include "IPhreeqc2.h" +#include "IPhreeqc.hpp" #include #include From 7499d8f14dfa6db5291c8e1560488c78a1194cee Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 7 Apr 2010 22:59:00 +0000 Subject: [PATCH 28/32] removed module_files.h module_files.cpp module_output.cpp FInterface.for renamed IPhreeqc2 to IPhreeqc git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4226 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- CVar.hxx | 9 ++-- FInterface.for | 116 ----------------------------------------- IPhreeqc.cpp | 127 +++++++++++++++++++++++---------------------- IPhreeqcLib.cpp | 84 +++++++++++++++--------------- SelectedOutput.cpp | 19 +++---- module_files.cpp | 95 --------------------------------- module_files.h | 25 --------- module_output.cpp | 22 -------- 8 files changed, 119 insertions(+), 378 deletions(-) delete mode 100644 FInterface.for delete mode 100644 module_files.cpp delete mode 100644 module_files.h delete mode 100644 module_output.cpp diff --git a/CVar.hxx b/CVar.hxx index dffa495d..f4c46e21 100644 --- a/CVar.hxx +++ b/CVar.hxx @@ -1,8 +1,6 @@ -#ifndef __CVAR_HXX_INC -#define __CVAR_HXX_INC +#ifndef INC_CVAR_HXX +#define INC_CVAR_HXX - -#include "Debug.h" // ASSERT #include "Var.h" #include // std::ostream @@ -93,7 +91,6 @@ public: VRESULT InternalClear() { VRESULT vr = Clear(); - ASSERT(vr == VR_OK); if (vr != VR_OK) { type = TT_ERROR; @@ -162,4 +159,4 @@ inline std::ostream& operator<< (std::ostream &os, const CVar &a) return os; } -#endif // __CVAR_HXX_INC +#endif // INC_CVAR_HXX diff --git a/FInterface.for b/FInterface.for deleted file mode 100644 index d1bc3317..00000000 --- a/FInterface.for +++ /dev/null @@ -1,116 +0,0 @@ -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION LoadDatabase(FILENAME) - CHARACTER(LEN=*) :: FILENAME - INTEGER(KIND=4) :: LoadDatabase - INTERFACE - FUNCTION FLoadDatabase(FILENAME) - !DEC$ ATTRIBUTES C,REFERENCE::FLoadDatabase - !DEC$ ATTRIBUTES ALIAS:'_LoadDatabaseF'::FLoadDatabase - CHARACTER(LEN=*) :: FILENAME - INTEGER(KIND=4) :: FLoadDatabase - END FUNCTION FLoadDatabase - END INTERFACE - LoadDatabase = FLoadDatabase(FILENAME) - END FUNCTION LoadDatabase -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - SUBROUTINE OutputLastError - INTERFACE - SUBROUTINE FOutputLastError - !DEC$ ATTRIBUTES C,REFERENCE::FOutputLines - !DEC$ ATTRIBUTES ALIAS:'_OutputLastError'::FOutputLastError - END SUBROUTINE FOutputLastError - END INTERFACE - CALL FOutputLastError - END SUBROUTINE OutputLastError -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION AccumulateLine(LINE) - CHARACTER(LEN=*) :: LINE - INTEGER(KIND=4) :: AccumulateLine - INTERFACE - FUNCTION FAccumulate(LINE) - !DEC$ ATTRIBUTES C,REFERENCE::FAccumulate - !DEC$ ATTRIBUTES ALIAS:'_AccumulateLineF'::FAccumulate - CHARACTER(LEN=*) :: LINE - INTEGER(KIND=4) :: FAccumulate - END FUNCTION FAccumulate - END INTERFACE - AccumulateLine = FAccumulate(LINE) - END FUNCTION AccumulateLine -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION Run(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) - LOGICAL(KIND=4) :: OUTPUT_ON - LOGICAL(KIND=4) :: ERROR_ON - LOGICAL(KIND=4) :: LOG_ON - LOGICAL(KIND=4) :: SELECTED_ON - INTEGER(KIND=4) :: Run - INTERFACE - FUNCTION FRun(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) - !DEC$ ATTRIBUTES C,REFERENCE::FRun - !DEC$ ATTRIBUTES ALIAS:'_RunF'::FRun - LOGICAL(KIND=4) :: OUTPUT_ON - LOGICAL(KIND=4) :: ERROR_ON - LOGICAL(KIND=4) :: LOG_ON - LOGICAL(KIND=4) :: SELECTED_ON - INTEGER(KIND=4) :: FRun - END FUNCTION FRun - END INTERFACE - Run = FRun(OUTPUT_ON, ERROR_ON, LOG_ON, SELECTED_ON) - END FUNCTION Run -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - SUBROUTINE OutputLines - INTERFACE - SUBROUTINE FOutputLines - !DEC$ ATTRIBUTES C,REFERENCE::FOutputLines - !DEC$ ATTRIBUTES ALIAS:'_OutputLines'::FOutputLines - END SUBROUTINE FOutputLines - END INTERFACE - CALL FOutputLines - END SUBROUTINE OutputLines -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION GetSelectedOutputRowCount - INTEGER(KIND=4) :: GetSelectedOutputRowCount - INTERFACE - FUNCTION FRows - !DEC$ ATTRIBUTES C,REFERENCE::FRows - !DEC$ ATTRIBUTES ALIAS:'_GetSelectedOutputRowCount'::FRows - INTEGER(KIND=4) :: FRows - END FUNCTION FRows - END INTERFACE - GetSelectedOutputRowCount = FRows() - 1 - END FUNCTION GetSelectedOutputRowCount -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION GetSelectedOutputColumnCount - INTEGER(KIND=4) :: GetSelectedOutputColumnCount - INTERFACE - FUNCTION FCols - !DEC$ ATTRIBUTES C,REFERENCE::FCols - !DEC$ ATTRIBUTES ALIAS:'_GetSelectedOutputColumnCount'::FCols - INTEGER(KIND=4) :: FCols - END FUNCTION FCols - END INTERFACE - GetSelectedOutputColumnCount = FCols() - END FUNCTION GetSelectedOutputColumnCount -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - FUNCTION GetSelectedOutputValue(ROW,COL,VTYPE,DVALUE,SVALUE) - INTEGER(KIND=4) :: ROW - INTEGER(KIND=4) :: COL - INTEGER(KIND=4) :: VTYPE - REAL(KIND=8) :: DVALUE - CHARACTER(LEN=*) :: SVALUE - INTEGER(KIND=4) :: GetSelectedOutputValue - INTEGER(KIND=4) :: adjcol - INTERFACE - FUNCTION Get(ROW,COL,VTYPE,DVALUE,SVALUE) - !DEC$ ATTRIBUTES C,REFERENCE::Get - !DEC$ ATTRIBUTES ALIAS:'_GetSelectedOutputValueF'::Get - INTEGER(KIND=4) :: ROW - INTEGER(KIND=4) :: COL - INTEGER(KIND=4) :: VTYPE - REAL(KIND=8) :: DVALUE - CHARACTER(LEN=*) :: SVALUE - INTEGER(KIND=4) :: Get - END FUNCTION Get - END INTERFACE - adjcol = col - 1 - GetSelectedOutputValue = Get(ROW,adjcol,VTYPE,DVALUE,SVALUE) - END FUNCTION GetSelectedOutputValue diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index b52df730..e1e574dc 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -1,8 +1,9 @@ -#include "IPhreeqc.hpp" +#include // auto_ptr + +#include "IPhreeqc.hpp" // IPhreeqc #include "Phreeqc.h" // Phreeqc -#include // assert -#include // auto_ptr +#include "Debug.h" // ASSERT #include "ErrorReporter.hxx" // CErrorReporter #include "SelectedOutput.hxx" // CSelectedOutput #include "dumper.h" // dumper @@ -34,7 +35,7 @@ int istream_getc(void *cookie) return EOF; } -IPhreeqc2::IPhreeqc2(void) +IPhreeqc::IPhreeqc(void) : DatabaseLoaded(false) , SelectedOutputOn(false) , OutputOn(false) @@ -55,15 +56,15 @@ IPhreeqc2::IPhreeqc2(void) this->UnLoadDatabase(); } -IPhreeqc2::~IPhreeqc2(void) +IPhreeqc::~IPhreeqc(void) { delete this->PhreeqcPtr; } -int IPhreeqc2::handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +int IPhreeqc::handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) { int n = OK; - IPhreeqc2 *pThis = (IPhreeqc2*)cookie; + IPhreeqc *pThis = (IPhreeqc*)cookie; switch (action) { case Phreeqc::ACTION_OPEN: @@ -86,9 +87,9 @@ int IPhreeqc2::handler(const int action, const int type, const char *err_str, co return n; } -int IPhreeqc2::output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +int IPhreeqc::output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) { - assert(cookie == this); + ASSERT(cookie == this); switch (type) { @@ -126,7 +127,7 @@ int IPhreeqc2::output_handler(const int type, const char *err_str, const int sto return module_handler(Phreeqc::ACTION_OUTPUT, type, err_str, stop, cookie, format, args); } -int IPhreeqc2::open_handler(const int type, const char *file_name) +int IPhreeqc::open_handler(const int type, const char *file_name) { int n = OK; switch (type) @@ -151,9 +152,9 @@ int IPhreeqc2::open_handler(const int type, const char *file_name) return n; } -int IPhreeqc2::module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +int IPhreeqc::module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) { - IPhreeqc2* pThis = (IPhreeqc2*) cookie; + IPhreeqc* pThis = (IPhreeqc*) cookie; switch (action) { @@ -170,7 +171,7 @@ int IPhreeqc2::module_handler(const int action, const int type, const char *err_ return ERROR; } -int IPhreeqc2::module_isopen_handler(const int type) +int IPhreeqc::module_isopen_handler(const int type) { switch (type) { @@ -178,14 +179,14 @@ int IPhreeqc2::module_isopen_handler(const int type) if (this->PhreeqcPtr->punch_file) return 1; break; default: - assert(0); + ASSERT(0); } return 0; } -int IPhreeqc2::module_open_handler(const int type, const char *file_name) +int IPhreeqc::module_open_handler(const int type, const char *file_name) { - assert(file_name && ::strlen(file_name)); + ASSERT(file_name && ::strlen(file_name)); switch (type) { case Phreeqc::OUTPUT_MESSAGE: @@ -201,7 +202,7 @@ int IPhreeqc2::module_open_handler(const int type, const char *file_name) break; case Phreeqc::OUTPUT_ERROR: - assert(this->PhreeqcPtr->error_file != stderr); + ASSERT(this->PhreeqcPtr->error_file != stderr); if (this->PhreeqcPtr->error_file != NULL) { ::fclose(this->PhreeqcPtr->error_file); @@ -233,7 +234,7 @@ int IPhreeqc2::module_open_handler(const int type, const char *file_name) return(OK); } -int IPhreeqc2::output_isopen(const int type) +int IPhreeqc::output_isopen(const int type) { size_t i; int isopen; @@ -245,12 +246,12 @@ int IPhreeqc2::output_isopen(const int type) return 0; } -int IPhreeqc2::EndRow(void) +int IPhreeqc::EndRow(void) { if (this->SelectedOutput->GetRowCount() <= 1) { // ensure all user_punch headings are included - assert(this->PhreeqcPtr->n_user_punch_index >= 0); + ASSERT(this->PhreeqcPtr->n_user_punch_index >= 0); for (int i = this->PhreeqcPtr->n_user_punch_index; i < this->PhreeqcPtr->user_punch_count_headings; ++i) { this->SelectedOutput->PushBackEmpty(this->PhreeqcPtr->user_punch_headings[i]); @@ -259,38 +260,38 @@ int IPhreeqc2::EndRow(void) return this->SelectedOutput->EndRow(); } -void IPhreeqc2::ClearAccumulatedLines(void) +void IPhreeqc::ClearAccumulatedLines(void) { this->StringInput.erase(); } -size_t IPhreeqc2::AddError(const char* error_msg) +size_t IPhreeqc::AddError(const char* error_msg) { return this->ErrorReporter->AddError(error_msg); } -size_t IPhreeqc2::AddWarning(const char* error_msg) +size_t IPhreeqc::AddWarning(const char* error_msg) { return this->WarningReporter->AddError(error_msg); } -const std::string& IPhreeqc2::GetAccumulatedLines(void) +const std::string& IPhreeqc::GetAccumulatedLines(void) { return this->StringInput; } -void IPhreeqc2::OutputLastError(void) +void IPhreeqc::OutputLastError(void) { std::cout << this->GetLastErrorString() << std::endl; } -void IPhreeqc2::OutputLines(void) +void IPhreeqc::OutputLines(void) { std::cout << this->StringInput.c_str() << std::endl; } -int IPhreeqc2::LoadDatabase(const char* filename) +int IPhreeqc::LoadDatabase(const char* filename) { try { @@ -336,7 +337,7 @@ int IPhreeqc2::LoadDatabase(const char* filename) return this->PhreeqcPtr->input_error; } -int IPhreeqc2::LoadDatabaseString(const char* input) +int IPhreeqc::LoadDatabaseString(const char* input) { try { @@ -374,7 +375,7 @@ int IPhreeqc2::LoadDatabaseString(const char* input) return this->PhreeqcPtr->input_error; } -void IPhreeqc2::UnLoadDatabase(void) +void IPhreeqc::UnLoadDatabase(void) { // init IPhreeqc // @@ -405,72 +406,72 @@ void IPhreeqc2::UnLoadDatabase(void) // initialize phreeqc // this->PhreeqcPtr->clean_up(); - this->PhreeqcPtr->add_output_callback(IPhreeqc2::handler, this); + this->PhreeqcPtr->add_output_callback(IPhreeqc::handler, this); this->PhreeqcPtr->do_initialize(); this->PhreeqcPtr->input_error = 0; } -bool IPhreeqc2::GetOutputOn(void)const +bool IPhreeqc::GetOutputOn(void)const { return this->OutputOn; } -void IPhreeqc2::SetOutputOn(bool bValue) +void IPhreeqc::SetOutputOn(bool bValue) { this->OutputOn = bValue; } -bool IPhreeqc2::GetSelectedOutputOn(void)const +bool IPhreeqc::GetSelectedOutputOn(void)const { return this->SelectedOutputOn; } -void IPhreeqc2::SetSelectedOutputOn(bool bValue) +void IPhreeqc::SetSelectedOutputOn(bool bValue) { this->SelectedOutputOn = bValue; } -bool IPhreeqc2::GetLogOn(void)const +bool IPhreeqc::GetLogOn(void)const { return this->LogOn; } -void IPhreeqc2::SetLogOn(bool bValue) +void IPhreeqc::SetLogOn(bool bValue) { this->LogOn = bValue; } -bool IPhreeqc2::GetDumpOn(void)const +bool IPhreeqc::GetDumpOn(void)const { return this->DumpOn; } -void IPhreeqc2::SetDumpOn(bool bValue) +void IPhreeqc::SetDumpOn(bool bValue) { this->DumpOn = bValue; } -bool IPhreeqc2::GetDumpStringOn(void)const +bool IPhreeqc::GetDumpStringOn(void)const { return this->DumpStringOn; } -void IPhreeqc2::SetDumpStringOn(bool bValue) +void IPhreeqc::SetDumpStringOn(bool bValue) { this->DumpStringOn = bValue; } -bool IPhreeqc2::GetErrorOn(void)const +bool IPhreeqc::GetErrorOn(void)const { return this->ErrorOn; } -void IPhreeqc2::SetErrorOn(bool bValue) +void IPhreeqc::SetErrorOn(bool bValue) { this->ErrorOn = bValue; } -void IPhreeqc2::AddSelectedOutput(const char* name, const char* format, va_list argptr) +void IPhreeqc::AddSelectedOutput(const char* name, const char* format, va_list argptr) { int bInt; int bDouble; @@ -644,25 +645,25 @@ void IPhreeqc2::AddSelectedOutput(const char* name, const char* format, va_list } } -const char* IPhreeqc2::GetLastErrorString(void) +const char* IPhreeqc::GetLastErrorString(void) { this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); return this->LastErrorString.c_str(); } -const char* IPhreeqc2::GetLastWarningString(void) +const char* IPhreeqc::GetLastWarningString(void) { this->LastWarningString = ((CErrorReporter*)this->WarningReporter)->GetOS()->str(); return this->LastWarningString.c_str(); } -const char* IPhreeqc2::GetDumpString(void) +const char* IPhreeqc::GetDumpString(void) { return this->DumpString.c_str(); } -void IPhreeqc2::check_database(const char* sz_routine) +void IPhreeqc::check_database(const char* sz_routine) { this->ErrorReporter->Clear(); this->SelectedOutput->Clear(); @@ -676,7 +677,7 @@ void IPhreeqc2::check_database(const char* sz_routine) } } -void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie) +void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie) { std::auto_ptr auto_iss(NULL); char token[MAX_LENGTH]; @@ -1008,7 +1009,7 @@ void IPhreeqc2::do_run(const char* sz_routine, std::istream* pis, FILE* fp, PFN_ this->update_errors(); } -VRESULT IPhreeqc2::AccumulateLine(const char *line) +VRESULT IPhreeqc::AccumulateLine(const char *line) { try { @@ -1025,7 +1026,7 @@ VRESULT IPhreeqc2::AccumulateLine(const char *line) return VR_OUTOFMEMORY; } -int IPhreeqc2::RunAccumulated(void) +int IPhreeqc::RunAccumulated(void) { static const char *sz_routine = "RunAccumulated"; try @@ -1065,7 +1066,7 @@ int IPhreeqc2::RunAccumulated(void) return this->PhreeqcPtr->input_error; } -int IPhreeqc2::RunFile(const char* filename) +int IPhreeqc::RunFile(const char* filename) { static const char *sz_routine = "RunFile"; try @@ -1112,7 +1113,7 @@ int IPhreeqc2::RunFile(const char* filename) return this->PhreeqcPtr->input_error; } -int IPhreeqc2::RunString(const char* input) +int IPhreeqc::RunString(const char* input) { static const char *sz_routine = "RunString"; try @@ -1152,17 +1153,17 @@ int IPhreeqc2::RunString(const char* input) return this->PhreeqcPtr->input_error; } -int IPhreeqc2::GetSelectedOutputRowCount(void)const +int IPhreeqc::GetSelectedOutputRowCount(void)const { return (int)this->SelectedOutput->GetRowCount(); } -int IPhreeqc2::GetSelectedOutputColumnCount(void)const +int IPhreeqc::GetSelectedOutputColumnCount(void)const { return (int)this->SelectedOutput->GetColCount(); } -VRESULT IPhreeqc2::GetSelectedOutputValue(int row, int col, VAR* pVAR) +VRESULT IPhreeqc::GetSelectedOutputValue(int row, int col, VAR* pVAR) { this->ErrorReporter->Clear(); if (!pVAR) @@ -1197,12 +1198,12 @@ VRESULT IPhreeqc2::GetSelectedOutputValue(int row, int col, VAR* pVAR) return v; } -int IPhreeqc2::GetDumpLineCount(void)const +int IPhreeqc::GetDumpLineCount(void)const { return (int)this->DumpLines.size(); } -const char* IPhreeqc2::GetDumpLine(int n) +const char* IPhreeqc::GetDumpLine(int n) { static const char empty[] = ""; if (n < 0 || n >= this->GetDumpLineCount()) @@ -1212,12 +1213,12 @@ const char* IPhreeqc2::GetDumpLine(int n) return this->DumpLines[n].c_str(); } -int IPhreeqc2::GetErrorLineCount(void)const +int IPhreeqc::GetErrorLineCount(void)const { return (int)this->ErrorLines.size(); } -const char* IPhreeqc2::GetErrorLine(int n) +const char* IPhreeqc::GetErrorLine(int n) { static const char empty[] = ""; if (n < 0 || n >= this->GetErrorLineCount()) @@ -1227,7 +1228,7 @@ const char* IPhreeqc2::GetErrorLine(int n) return this->ErrorLines[n].c_str(); } -void IPhreeqc2::update_errors(void) +void IPhreeqc::update_errors(void) { this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); @@ -1240,21 +1241,21 @@ void IPhreeqc2::update_errors(void) } } -std::list< std::string > IPhreeqc2::ListComponents(void) +std::list< std::string > IPhreeqc::ListComponents(void) { std::list< std::string > comps; this->PhreeqcPtr->list_components(comps); return comps; } -size_t IPhreeqc2::GetComponentCount(void) +size_t IPhreeqc::GetComponentCount(void) { std::list< std::string > comps; this->PhreeqcPtr->list_components(comps); return comps.size(); } -const char* IPhreeqc2::GetComponent(int n) +const char* IPhreeqc::GetComponent(int n) { static const char empty[] = ""; this->Components = this->ListComponents(); diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp index 2e2a41ca..0b2781ac 100644 --- a/IPhreeqcLib.cpp +++ b/IPhreeqcLib.cpp @@ -8,10 +8,10 @@ class IPhreeqcLib public: static int CreateIPhreeqc(void); static IPQ_RESULT DestroyIPhreeqc(int n); - static IPhreeqc2* GetInstance(int n); + static IPhreeqc* GetInstance(int n); private: - static std::map Instances; + static std::map Instances; static size_t InstancesIndex; }; @@ -30,7 +30,7 @@ DestroyIPhreeqc(int id) int LoadDatabase(int id, const char* filename) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->LoadDatabase(filename); @@ -41,7 +41,7 @@ LoadDatabase(int id, const char* filename) int LoadDatabaseString(int id, const char* input) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->LoadDatabaseString(input); @@ -52,7 +52,7 @@ LoadDatabaseString(int id, const char* input) int UnLoadDatabase(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->UnLoadDatabase(); @@ -65,7 +65,7 @@ void OutputLastError(int id) { static const char err_msg[] = "OutputLastError: Bad instance.\n"; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->OutputLastError(); @@ -78,7 +78,7 @@ const char* GetLastErrorString(int id) { static const char err_msg[] = "GetLastErrorString: Bad instance.\n"; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetLastErrorString(); @@ -90,7 +90,7 @@ const char* GetDumpString(int id) { static const char empty[] = ""; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetDumpString(); @@ -101,7 +101,7 @@ GetDumpString(int id) int GetDumpLineCount(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetDumpLineCount(); @@ -113,7 +113,7 @@ const char* GetDumpLine(int id, int n) { static const char err_msg[] = "GetDumpLine: Bad instance.\n"; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetDumpLine(n); @@ -124,7 +124,7 @@ GetDumpLine(int id, int n) int GetComponentCount(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->ListComponents().size(); @@ -139,7 +139,7 @@ GetComponent(int id, int n) static const char empty[] = ""; static std::string comp; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { std::list< std::string > comps = IPhreeqcPtr->ListComponents(); @@ -161,7 +161,7 @@ GetComponent(int id, int n) IPQ_RESULT AccumulateLine(int id, const char *line) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { switch (IPhreeqcPtr->AccumulateLine(line)) @@ -180,7 +180,7 @@ AccumulateLine(int id, const char *line) int GetSelectedOutputOn(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetSelectedOutputOn()) @@ -198,7 +198,7 @@ GetSelectedOutputOn(int id) IPQ_RESULT SetSelectedOutputOn(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetSelectedOutputOn(value != 0); @@ -210,7 +210,7 @@ SetSelectedOutputOn(int id, int value) int GetOutputOn(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetOutputOn()) @@ -228,7 +228,7 @@ GetOutputOn(int id) IPQ_RESULT SetOutputOn(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetOutputOn(value != 0); @@ -240,7 +240,7 @@ SetOutputOn(int id, int value) int GetErrorOn(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetErrorOn()) @@ -258,7 +258,7 @@ GetErrorOn(int id) IPQ_RESULT SetErrorOn(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetErrorOn(value != 0); @@ -270,7 +270,7 @@ SetErrorOn(int id, int value) int GetLogOn(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetLogOn()) @@ -288,7 +288,7 @@ GetLogOn(int id) IPQ_RESULT SetLogOn(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetLogOn(value != 0); @@ -301,7 +301,7 @@ SetLogOn(int id, int value) int GetDumpOn(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetDumpOn()) @@ -319,7 +319,7 @@ GetDumpOn(int id) IPQ_RESULT SetDumpOn(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetDumpOn(value != 0); @@ -331,7 +331,7 @@ SetDumpOn(int id, int value) int GetDumpStringOn(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { if (IPhreeqcPtr->GetDumpStringOn()) @@ -349,7 +349,7 @@ GetDumpStringOn(int id) IPQ_RESULT SetDumpStringOn(int id, int value) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->SetDumpStringOn(value != 0); @@ -361,7 +361,7 @@ SetDumpStringOn(int id, int value) int RunAccumulated(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->RunAccumulated(); @@ -372,7 +372,7 @@ RunAccumulated(int id) int RunFile(int id, const char* filename) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->RunFile(filename); @@ -383,7 +383,7 @@ RunFile(int id, const char* filename) int RunString(int id, const char* input) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->RunString(input); @@ -394,7 +394,7 @@ RunString(int id, const char* input) int GetSelectedOutputRowCount(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetSelectedOutputRowCount(); @@ -405,7 +405,7 @@ GetSelectedOutputRowCount(int id) int GetSelectedOutputColumnCount(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetSelectedOutputColumnCount(); @@ -417,7 +417,7 @@ GetSelectedOutputColumnCount(int id) IPQ_RESULT GetSelectedOutputValue(int id, int row, int col, VAR* pVAR) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { switch(IPhreeqcPtr->GetSelectedOutputValue(row, col, pVAR)) @@ -438,7 +438,7 @@ GetSelectedOutputValue(int id, int row, int col, VAR* pVAR) int AddError(int id, const char* error_msg) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return (int)IPhreeqcPtr->AddError(error_msg); @@ -450,7 +450,7 @@ void OutputLines(int id) { static const char err_msg[] = "OutputLines: Bad instance.\n"; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { IPhreeqcPtr->OutputLines(); @@ -462,7 +462,7 @@ OutputLines(int id) int GetErrorLineCount(int id) { - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return (int)IPhreeqcPtr->GetErrorLineCount(); @@ -474,7 +474,7 @@ const char* GetErrorLine(int id, int n) { static const char err_msg[] = "GetErrorLine: Bad instance.\n"; - IPhreeqc2* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); if (IPhreeqcPtr) { return IPhreeqcPtr->GetErrorLine(n); @@ -483,7 +483,7 @@ GetErrorLine(int id, int n) } -std::map IPhreeqcLib::Instances; +std::map IPhreeqcLib::Instances; size_t IPhreeqcLib::InstancesIndex = 0; int @@ -492,11 +492,11 @@ IPhreeqcLib::CreateIPhreeqc(void) int n = IPQ_OUTOFMEMORY; try { - IPhreeqc2* IPhreeqcPtr = new IPhreeqc2; + IPhreeqc* IPhreeqcPtr = new IPhreeqc; if (IPhreeqcPtr) { - std::map::value_type instance(IPhreeqcLib::InstancesIndex, IPhreeqcPtr); - std::pair::iterator, bool> pr = IPhreeqcLib::Instances.insert(instance); + std::map::value_type instance(IPhreeqcLib::InstancesIndex, IPhreeqcPtr); + std::pair::iterator, bool> pr = IPhreeqcLib::Instances.insert(instance); if (pr.second) { n = (int) (*pr.first).first; @@ -517,7 +517,7 @@ IPhreeqcLib::DestroyIPhreeqc(int id) IPQ_RESULT retval = IPQ_BADINSTANCE; if (id >= 0) { - std::map::iterator it = IPhreeqcLib::Instances.find(size_t(id)); + std::map::iterator it = IPhreeqcLib::Instances.find(size_t(id)); if (it != IPhreeqcLib::Instances.end()) { delete (*it).second; @@ -528,10 +528,10 @@ IPhreeqcLib::DestroyIPhreeqc(int id) return retval; } -IPhreeqc2* +IPhreeqc* IPhreeqcLib::GetInstance(int id) { - std::map::iterator it = IPhreeqcLib::Instances.find(size_t(id)); + std::map::iterator it = IPhreeqcLib::Instances.find(size_t(id)); if (it != IPhreeqcLib::Instances.end()) { return (*it).second; diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index cba61595..edc2ae90 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -2,22 +2,22 @@ // ////////////////////////////////////////////////////////////////////// #if defined(WIN32) -#include // reqd to avoid namespace problems +#include // OutputDebugString #endif #if defined(_DEBUG) -#include // std::ostringstream +#include // std::ostringstream #endif #include #include -#include "SelectedOutput.hxx" +#include "Debug.h" // ASSERT +#include "SelectedOutput.hxx" // CSelectedOutput const size_t RESERVE_ROWS = 80; const size_t RESERVE_COLS = 80; - CSelectedOutput::CSelectedOutput() : m_nRowCount(0) { @@ -195,7 +195,8 @@ void CSelectedOutput::Dump(const char* heading) oss << *this; std::istringstream iss(oss.str()); std::string line; - while (std::getline(iss, line)) { + while (std::getline(iss, line)) + { ::OutputDebugStringA(line.c_str()); ::OutputDebugStringA("\n"); } @@ -216,13 +217,13 @@ void CSelectedOutput::AssertValid(void)const std::ostream& operator<< (std::ostream &os, const CSelectedOutput &a) { -#if defined(_WIN32) os << "CSelectedOutput(rows=" << a.GetRowCount() << ", cols=" << a.GetColCount() << ")\n"; -#endif CVar v; - for (size_t r = 0; r < a.GetRowCount(); ++r) { - for (size_t c = 0; c < a.GetColCount(); ++c) { + for (size_t r = 0; r < a.GetRowCount(); ++r) + { + for (size_t c = 0; c < a.GetColCount(); ++c) + { a.Get((int)r, (int)c, &v); os << v << ", "; ::VarClear(&v); diff --git a/module_files.cpp b/module_files.cpp deleted file mode 100644 index 7bfbab3b..00000000 --- a/module_files.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "module_files.h" -#if defined(R_SO) -#include "phreeqc_files.inl" -#else -// COMMENT: {3/25/2010 12:36:14 PM}#include "phreeqcpp/phreeqc/phreeqc_files.c" -#endif - -// COMMENT: {3/2/2010 4:06:35 PM}static int module_isopen_handler(const int type); -// COMMENT: {3/2/2010 4:06:35 PM}static int module_open_handler(const int type, const char *file_name); - -//{{{3/25/2010 12:37:19 PM} -#include -//}}{3/25/2010 12:37:19 PM} -#include "IPhreeqc.hpp" - -int IPhreeqc::module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) -{ - IPhreeqc* pThis = (IPhreeqc*) cookie; - - switch (action) { - case ACTION_OPEN: - return pThis->module_open_handler(type, err_str); - break; - case ACTION_ISOPEN: - return pThis->module_isopen_handler(type); - break; - default: - return pThis->phreeqc_handler(action, type, err_str, stop, cookie, format, args); - break; - } - return ERROR; -} - -int IPhreeqc::module_isopen_handler(const int type) -{ - switch (type) - { - case OUTPUT_PUNCH: - if (this->punch_file) return 1; - break; - default: - assert(0); - } - return 0; -} - -int IPhreeqc::module_open_handler(const int type, const char *file_name) -{ - assert(file_name && ::strlen(file_name)); - switch (type) - { - case OUTPUT_MESSAGE: - if (this->output != NULL) - { - ::fclose(this->output); - this->output = NULL; - } - if ( (this->output = ::fopen(file_name, "w")) == NULL) - { - return ERROR; - } - break; - - case OUTPUT_ERROR: - assert(this->error_file != stderr); - if (this->error_file != NULL) - { - ::fclose(this->error_file); - this->error_file = NULL; - } - if ( (this->error_file = ::fopen(file_name, "w")) == NULL) - { - return ERROR; - } - break; - - case OUTPUT_LOG: - if (this->log_file != NULL) - { - ::fclose(this->log_file); - this->log_file = NULL; - } - if ( (this->log_file = ::fopen(file_name, "w")) == NULL) - { - return ERROR; - } - break; - - default: - return this->Phreeqc::open_handler(type, file_name); - break; - - } - return(OK); -} diff --git a/module_files.h b/module_files.h deleted file mode 100644 index 35436586..00000000 --- a/module_files.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __MODULE_FILES__H -#define __MODULE_FILES__H - -#include -#include - - -#if defined(__cplusplus) -extern "C" { -#endif - -// COMMENT: {3/2/2010 4:07:45 PM}int module_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); -// COMMENT: {3/2/2010 4:07:45 PM}int output_isopen(const int type); - - -typedef enum { - ACTION_ISOPEN = -100, -} module_action_type; - - -#if defined(__cplusplus) -} -#endif - -#endif /* __MODULE_FILES__H */ diff --git a/module_output.cpp b/module_output.cpp deleted file mode 100644 index 70c1561a..00000000 --- a/module_output.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "module_files.h" - -#include "IPhreeqc.hpp" - -#if defined(R_SO) -#include "output.inl" -#else -// COMMENT: {3/25/2010 12:36:24 PM}#include "phreeqcpp/phreeqc/output.c" -#endif - - -int IPhreeqc::output_isopen(const int type) -{ - size_t i; - int isopen; - for (i = 0; i < this->count_output_callback; ++i) - { - isopen = (this->output_callbacks[i].callback)(ACTION_ISOPEN, type, NULL, CONTINUE, this->output_callbacks[i].cookie, NULL, NULL); - if (isopen) return 1; - } - return 0; -} From 95e46c165984bbb45e2a5442116cae9edacc5d96 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 8 Apr 2010 00:26:48 +0000 Subject: [PATCH 29/32] git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4227 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- IPhreeqc.cpp | 50 ++++++++++++++++++++++++++++++++++++++-------- IPhreeqcLib.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++ SelectedOutput.hxx | 1 - fwrap.cpp | 20 +++++++++++++++++++ fwrap.h | 4 ++++ fwrap2.cpp | 8 ++++++++ fwrap3.cpp | 8 ++++++++ 7 files changed, 129 insertions(+), 9 deletions(-) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index e1e574dc..468925a0 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -270,9 +270,9 @@ size_t IPhreeqc::AddError(const char* error_msg) return this->ErrorReporter->AddError(error_msg); } -size_t IPhreeqc::AddWarning(const char* error_msg) +size_t IPhreeqc::AddWarning(const char* warn_msg) { - return this->WarningReporter->AddError(error_msg); + return this->WarningReporter->AddError(warn_msg); } const std::string& IPhreeqc::GetAccumulatedLines(void) @@ -285,6 +285,11 @@ void IPhreeqc::OutputLastError(void) std::cout << this->GetLastErrorString() << std::endl; } +void IPhreeqc::OutputLastWarning(void) +{ + std::cout << this->GetLastWarningString() << std::endl; +} + void IPhreeqc::OutputLines(void) { std::cout << this->StringInput.c_str() << std::endl; @@ -1228,16 +1233,45 @@ const char* IPhreeqc::GetErrorLine(int n) return this->ErrorLines[n].c_str(); } +int IPhreeqc::GetWarningLineCount(void)const +{ + return (int)this->WarningLines.size(); +} + +const char* IPhreeqc::GetWarningLine(int n) +{ + static const char empty[] = ""; + if (n < 0 || n >= this->GetWarningLineCount()) + { + return empty; + } + return this->WarningLines[n].c_str(); +} + void IPhreeqc::update_errors(void) { - this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); - this->ErrorLines.clear(); - std::istringstream iss(this->LastErrorString); - std::string line; - while (std::getline(iss, line)) + this->LastErrorString = ((CErrorReporter*)this->ErrorReporter)->GetOS()->str(); + if (this->LastErrorString.size()) { - this->ErrorLines.push_back(line); + std::istringstream iss(this->LastErrorString); + std::string line; + while (std::getline(iss, line)) + { + this->ErrorLines.push_back(line); + } + } + + this->WarningLines.clear(); + this->LastWarningString = ((CErrorReporter*)this->WarningReporter)->GetOS()->str(); + if (this->LastWarningString.size()) + { + std::istringstream iss(this->LastWarningString); + std::string line; + while (std::getline(iss, line)) + { + this->WarningLines.push_back(line); + } } } diff --git a/IPhreeqcLib.cpp b/IPhreeqcLib.cpp index 0b2781ac..0226bb9f 100644 --- a/IPhreeqcLib.cpp +++ b/IPhreeqcLib.cpp @@ -74,6 +74,19 @@ OutputLastError(int id) std::cout << err_msg << std::endl; } +void +OutputLastWarning(int id) +{ + static const char err_msg[] = "OutputLastWarning: Bad instance.\n"; + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + IPhreeqcPtr->OutputLastWarning(); + return; + } + std::cout << err_msg << std::endl; +} + const char* GetLastErrorString(int id) { @@ -86,6 +99,18 @@ GetLastErrorString(int id) return err_msg; } +const char* +GetLastWarningString(int id) +{ + static const char err_msg[] = "GetLastWarningString: Bad instance.\n"; + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetLastWarningString(); + } + return err_msg; +} + const char* GetDumpString(int id) { @@ -482,6 +507,28 @@ GetErrorLine(int id, int n) return err_msg; } +int +GetWarningLineCount(int id) +{ + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return (int)IPhreeqcPtr->GetWarningLineCount(); + } + return IPQ_BADINSTANCE; +} + +const char* +GetWarningLine(int id, int n) +{ + static const char err_msg[] = "GetWarningLine: Bad instance.\n"; + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetWarningLine(n); + } + return err_msg; +} std::map IPhreeqcLib::Instances; size_t IPhreeqcLib::InstancesIndex = 0; diff --git a/SelectedOutput.hxx b/SelectedOutput.hxx index b5018f7f..9d44b151 100644 --- a/SelectedOutput.hxx +++ b/SelectedOutput.hxx @@ -15,7 +15,6 @@ #include #include "CVar.hxx" -// TODO: templatize class CSelectedOutput { public: diff --git a/fwrap.cpp b/fwrap.cpp index 18787f12..a47fa27b 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -187,6 +187,18 @@ GetErrorLineF(int *id, int* n, char* line, unsigned int line_length) padfstring(line, ::GetErrorLine(*id, (*n) - 1), line_length); } +int +GetWarningLineCountF(int *id) +{ + return ::GetWarningLineCount(*id); +} + +void +GetWarningLineF(int *id, int* n, char* line, unsigned int line_length) +{ + padfstring(line, ::GetWarningLine(*id, (*n) - 1), line_length); +} + int GetComponentCountF(int *id) { @@ -402,6 +414,14 @@ void __stdcall GETERRORLINE(int *id, int *n, char* line, unsigned int line_lengt { GetErrorLineF(id, n, line, line_length); } +int __stdcall GETWARNINGLINECOUNT(int *id) +{ + return GetWarningLineCountF(id); +} +void __stdcall GETWARNINGLINE(int *id, int *n, char* line, unsigned int line_length) +{ + GetWarningLineF(id, n, line, line_length); +} int __stdcall GETCOMPONENTCOUNT(int *id) { return GetComponentCountF(id); diff --git a/fwrap.h b/fwrap.h index 3b1c0a16..d69436e9 100644 --- a/fwrap.h +++ b/fwrap.h @@ -46,6 +46,10 @@ extern "C" { void GetErrorLineF(int *id, int* n, char* line, unsigned int line_length); + int GetWarningLineCountF(int *id); + + void GetWarningLineF(int *id, int* n, char* line, unsigned int line_length); + int GetComponentCountF(int *id); void GetComponentF(int *id, int* n, char* line, unsigned int line_length); diff --git a/fwrap2.cpp b/fwrap2.cpp index 9fed894c..598a2fcb 100644 --- a/fwrap2.cpp +++ b/fwrap2.cpp @@ -66,6 +66,14 @@ void GETERRORLINE(int *id, int *n, char* line, unsigned int line_length) { GetErrorLineF(id, n, line, line_length); } +int GETWARNINGLINECOUNT(int *id) +{ + return GetWarningLineCountF(id); +} +void GETWARNINGLINE(int *id, int *n, char* line, unsigned int line_length) +{ + GetWarningLineF(id, n, line, line_length); +} int GETCOMPONENTCOUNT(int *id) { return GetComponentCountF(id); diff --git a/fwrap3.cpp b/fwrap3.cpp index cb328836..423066f0 100644 --- a/fwrap3.cpp +++ b/fwrap3.cpp @@ -66,6 +66,14 @@ void geterrorline_(int *id, int *n, char* line, unsigned int line_length) { GetErrorLineF(id, n, line, line_length); } +int getwarninglinecount_(int *id) +{ + return GetWarningLineCountF(id); +} +void getwarningline_(int *id, int *n, char* line, unsigned int line_length) +{ + GetWarningLineF(id, n, line, line_length); +} int getcomponentcount_(int *id) { return GetComponentCountF(id); From 3ec05f6ddae72747fc73e57066e37669b85dc68d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 8 Apr 2010 00:37:39 +0000 Subject: [PATCH 30/32] added GetWarningLineCount GetWarningLine for fortran git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4229 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- fwrap.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fwrap.cpp b/fwrap.cpp index a47fa27b..6eff2c10 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -23,6 +23,8 @@ compile fortran with: #define GetSelectedOutputColumnCountF getselectedoutputcolumncountf_ #define GetSelectedOutputRowCountF getselectedoutputrowcountf_ #define GetSelectedOutputValueF getselectedoutputvaluef_ +#define GetWarningLineCountF getwarninglinecountf +#define GetWarningLineF getwarninglinef #define LoadDatabaseF loaddatabasef_ #define LoadDatabaseStringF loaddatabasestringf_ #define OutputLastErrorF outputlasterrorf_ From 611d6fc59a637f0b17b8a6d51e008072ca5a27e5 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 8 Apr 2010 00:52:26 +0000 Subject: [PATCH 31/32] added underscores git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4230 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- fwrap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fwrap.cpp b/fwrap.cpp index 6eff2c10..fc5c531f 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -23,8 +23,8 @@ compile fortran with: #define GetSelectedOutputColumnCountF getselectedoutputcolumncountf_ #define GetSelectedOutputRowCountF getselectedoutputrowcountf_ #define GetSelectedOutputValueF getselectedoutputvaluef_ -#define GetWarningLineCountF getwarninglinecountf -#define GetWarningLineF getwarninglinef +#define GetWarningLineCountF getwarninglinecountf_ +#define GetWarningLineF getwarninglinef_ #define LoadDatabaseF loaddatabasef_ #define LoadDatabaseStringF loaddatabasestringf_ #define OutputLastErrorF outputlasterrorf_ From c0f7528bf53f23e747cb37538d6b30d2b5e59b18 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 9 Apr 2010 04:22:42 +0000 Subject: [PATCH 32/32] Added support for dll run time libraries git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4239 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- fwrap.cpp | 50 +++++++++++++++++++++++++------------------------- fwrap.h | 5 +++++ fwrap2.cpp | 50 +++++++++++++++++++++++++------------------------- fwrap3.cpp | 50 +++++++++++++++++++++++++------------------------- 4 files changed, 80 insertions(+), 75 deletions(-) diff --git a/fwrap.cpp b/fwrap.cpp index fc5c531f..f3c84623 100644 --- a/fwrap.cpp +++ b/fwrap.cpp @@ -360,103 +360,103 @@ extern "C" { // // Intel Fortran compiler 9.1 /iface:cvf // -int __stdcall CREATEIPHREEQC(void) +DLL_EXPORT int __stdcall CREATEIPHREEQC(void) { return CreateIPhreeqcF(); } -int __stdcall LOADDATABASE(int *id, char *filename, unsigned int len) +DLL_EXPORT int __stdcall LOADDATABASE(int *id, char *filename, unsigned int len) { return LoadDatabaseF(id, filename, len); } -void __stdcall OUTPUTLASTERROR(int *id) +DLL_EXPORT void __stdcall OUTPUTLASTERROR(int *id) { OutputLastErrorF(id); } -int __stdcall ACCUMULATELINE(int *id, char *line, unsigned int len) +DLL_EXPORT int __stdcall ACCUMULATELINE(int *id, char *line, unsigned int len) { return AccumulateLineF(id, line, len); } -void __stdcall SETSELECTEDOUTPUTON(int *id, int *selected_on) +DLL_EXPORT void __stdcall SETSELECTEDOUTPUTON(int *id, int *selected_on) { SetSelectedOutputOnF(id, selected_on); } -void __stdcall SETOUTPUTON(int *id, int *output_on) +DLL_EXPORT void __stdcall SETOUTPUTON(int *id, int *output_on) { SetOutputOnF(id, output_on); } -void __stdcall SETERRORON(int *id, int *error_on) +DLL_EXPORT void __stdcall SETERRORON(int *id, int *error_on) { SetErrorOnF(id, error_on); } -void __stdcall SETLOGON(int *id, int *log_on) +DLL_EXPORT void __stdcall SETLOGON(int *id, int *log_on) { SetLogOnF(id, log_on); } -void __stdcall SETDUMPON(int *id, int *dump_on) +DLL_EXPORT void __stdcall SETDUMPON(int *id, int *dump_on) { SetDumpOnF(id, dump_on); } -void __stdcall SETDUMPSTRINGON(int *id, int *dump_string_on) +DLL_EXPORT void __stdcall SETDUMPSTRINGON(int *id, int *dump_string_on) { SetDumpStringOnF(id, dump_string_on); } -int __stdcall GETDUMPLINECOUNT(int *id) +DLL_EXPORT int __stdcall GETDUMPLINECOUNT(int *id) { return GetDumpLineCountF(id); } -void __stdcall GETDUMPLINE(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void __stdcall GETDUMPLINE(int *id, int *n, char* line, unsigned int line_length) { GetDumpLineF(id, n, line, line_length); } -int __stdcall GETERRORLINECOUNT(int *id) +DLL_EXPORT int __stdcall GETERRORLINECOUNT(int *id) { return GetErrorLineCountF(id); } -void __stdcall GETERRORLINE(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void __stdcall GETERRORLINE(int *id, int *n, char* line, unsigned int line_length) { GetErrorLineF(id, n, line, line_length); } -int __stdcall GETWARNINGLINECOUNT(int *id) +DLL_EXPORT int __stdcall GETWARNINGLINECOUNT(int *id) { return GetWarningLineCountF(id); } -void __stdcall GETWARNINGLINE(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void __stdcall GETWARNINGLINE(int *id, int *n, char* line, unsigned int line_length) { GetWarningLineF(id, n, line, line_length); } -int __stdcall GETCOMPONENTCOUNT(int *id) +DLL_EXPORT int __stdcall GETCOMPONENTCOUNT(int *id) { return GetComponentCountF(id); } -void __stdcall GETCOMPONENT(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void __stdcall GETCOMPONENT(int *id, int *n, char* line, unsigned int line_length) { GetComponentF(id, n, line, line_length); } -int __stdcall RUNACCUMULATED(int *id) +DLL_EXPORT int __stdcall RUNACCUMULATED(int *id) { return RunAccumulatedF(id); } -int __stdcall RUNFILE(int *id, char *filename, unsigned int len) +DLL_EXPORT int __stdcall RUNFILE(int *id, char *filename, unsigned int len) { return RunFileF(id, filename, len); } -int __stdcall RUNSTRING(int *id, char *input, unsigned int len) +DLL_EXPORT int __stdcall RUNSTRING(int *id, char *input, unsigned int len) { return RunStringF(id, input, len); } -void __stdcall OUTPUTLINES(int *id) +DLL_EXPORT void __stdcall OUTPUTLINES(int *id) { OutputLinesF(id); } -int __stdcall GETSELECTEDOUTPUTROWCOUNT(int *id) +DLL_EXPORT int __stdcall GETSELECTEDOUTPUTROWCOUNT(int *id) { return GetSelectedOutputRowCountF(id); } -int __stdcall GETSELECTEDOUTPUTCOLUMNCOUNT(int *id) +DLL_EXPORT int __stdcall GETSELECTEDOUTPUTCOLUMNCOUNT(int *id) { return GetSelectedOutputColumnCountF(id); } -int __stdcall GETSELECTEDOUTPUTVALUE(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +DLL_EXPORT int __stdcall GETSELECTEDOUTPUTVALUE(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) { return GetSelectedOutputValueF(id, row, col, vtype, dvalue, svalue, svalue_length); } diff --git a/fwrap.h b/fwrap.h index d69436e9..82506ce3 100644 --- a/fwrap.h +++ b/fwrap.h @@ -1,6 +1,11 @@ #ifndef __FWRAP__H #define __FWRAP__H +#if defined(_WINDLL) +#define DLL_EXPORT __declspec(dllexport) +#else +#define DLL_EXPORT +#endif #if defined(__cplusplus) extern "C" { diff --git a/fwrap2.cpp b/fwrap2.cpp index 598a2fcb..e60b645e 100644 --- a/fwrap2.cpp +++ b/fwrap2.cpp @@ -10,103 +10,103 @@ extern "C" { // // Intel Fortran compiler 9.1 /iface:cvf // -int CREATEIPHREEQC(void) +DLL_EXPORT int CREATEIPHREEQC(void) { return CreateIPhreeqcF(); } -int LOADDATABASE(int *id, char *filename, unsigned int len) +DLL_EXPORT int LOADDATABASE(int *id, char *filename, unsigned int len) { return LoadDatabaseF(id, filename, len); } -void OUTPUTLASTERROR(int *id) +DLL_EXPORT void OUTPUTLASTERROR(int *id) { OutputLastErrorF(id); } -int ACCUMULATELINE(int *id, char *line, unsigned int len) +DLL_EXPORT int ACCUMULATELINE(int *id, char *line, unsigned int len) { return AccumulateLineF(id, line, len); } -void SETSELECTEDOUTPUTON(int *id, int *selected_on) +DLL_EXPORT void SETSELECTEDOUTPUTON(int *id, int *selected_on) { SetSelectedOutputOnF(id, selected_on); } -void SETOUTPUTON(int *id, int *output_on) +DLL_EXPORT void SETOUTPUTON(int *id, int *output_on) { SetOutputOnF(id, output_on); } -void SETERRORON(int *id, int *error_on) +DLL_EXPORT void SETERRORON(int *id, int *error_on) { SetErrorOnF(id, error_on); } -void SETLOGON(int *id, int *log_on) +DLL_EXPORT void SETLOGON(int *id, int *log_on) { SetLogOnF(id, log_on); } -void SETDUMPON(int *id, int *dump_on) +DLL_EXPORT void SETDUMPON(int *id, int *dump_on) { SetDumpOnF(id, dump_on); } -void SETDUMPSTRINGON(int *id, int *dump_string_on) +DLL_EXPORT void SETDUMPSTRINGON(int *id, int *dump_string_on) { SetDumpStringOnF(id, dump_string_on); } -int GETDUMPLINECOUNT(int *id) +DLL_EXPORT int GETDUMPLINECOUNT(int *id) { return GetDumpLineCountF(id); } -void GETDUMPLINE(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void GETDUMPLINE(int *id, int *n, char* line, unsigned int line_length) { GetDumpLineF(id, n, line, line_length); } -int GETERRORLINECOUNT(int *id) +DLL_EXPORT int GETERRORLINECOUNT(int *id) { return GetErrorLineCountF(id); } -void GETERRORLINE(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void GETERRORLINE(int *id, int *n, char* line, unsigned int line_length) { GetErrorLineF(id, n, line, line_length); } -int GETWARNINGLINECOUNT(int *id) +DLL_EXPORT int GETWARNINGLINECOUNT(int *id) { return GetWarningLineCountF(id); } -void GETWARNINGLINE(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void GETWARNINGLINE(int *id, int *n, char* line, unsigned int line_length) { GetWarningLineF(id, n, line, line_length); } -int GETCOMPONENTCOUNT(int *id) +DLL_EXPORT int GETCOMPONENTCOUNT(int *id) { return GetComponentCountF(id); } -void GETCOMPONENT(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void GETCOMPONENT(int *id, int *n, char* line, unsigned int line_length) { GetComponentF(id, n, line, line_length); } -int RUNACCUMULATED(int *id) +DLL_EXPORT int RUNACCUMULATED(int *id) { return RunAccumulatedF(id); } -int RUNFILE(int *id, char *filename, unsigned int len) +DLL_EXPORT int RUNFILE(int *id, char *filename, unsigned int len) { return RunFileF(id, filename, len); } -int RUNSTRING(int *id, char *input, unsigned int len) +DLL_EXPORT int RUNSTRING(int *id, char *input, unsigned int len) { return RunStringF(id, input, len); } -void OUTPUTLINES(int *id) +DLL_EXPORT void OUTPUTLINES(int *id) { OutputLinesF(id); } -int GETSELECTEDOUTPUTROWCOUNT(int *id) +DLL_EXPORT int GETSELECTEDOUTPUTROWCOUNT(int *id) { return GetSelectedOutputRowCountF(id); } -int GETSELECTEDOUTPUTCOLUMNCOUNT(int *id) +DLL_EXPORT int GETSELECTEDOUTPUTCOLUMNCOUNT(int *id) { return GetSelectedOutputColumnCountF(id); } -int GETSELECTEDOUTPUTVALUE(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +DLL_EXPORT int GETSELECTEDOUTPUTVALUE(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) { return GetSelectedOutputValueF(id, row, col, vtype, dvalue, svalue, svalue_length); } diff --git a/fwrap3.cpp b/fwrap3.cpp index 423066f0..cad155e0 100644 --- a/fwrap3.cpp +++ b/fwrap3.cpp @@ -10,103 +10,103 @@ extern "C" { // // Intel Fortran compiler 9.1 /iface:cref /assume:underscore // -int createiphreeqc_(void) +DLL_EXPORT int createiphreeqc_(void) { return CreateIPhreeqcF(); } -int loaddatabase_(int *id, char *filename, unsigned int len) +DLL_EXPORT int loaddatabase_(int *id, char *filename, unsigned int len) { return LoadDatabaseF(id, filename, len); } -void outputlasterror_(int *id) +DLL_EXPORT void outputlasterror_(int *id) { OutputLastErrorF(id); } -int accumulateline_(int *id, char *line, unsigned int len) +DLL_EXPORT int accumulateline_(int *id, char *line, unsigned int len) { return AccumulateLineF(id, line, len); } -void setselectedoutputon_(int *id, int *selected_on) +DLL_EXPORT void setselectedoutputon_(int *id, int *selected_on) { SetSelectedOutputOnF(id, selected_on); } -void setoutputon_(int *id, int *output_on) +DLL_EXPORT void setoutputon_(int *id, int *output_on) { SetOutputOnF(id, output_on); } -void seterroron_(int *id, int *error_on) +DLL_EXPORT void seterroron_(int *id, int *error_on) { SetErrorOnF(id, error_on); } -void setlogon_(int *id, int *log_on) +DLL_EXPORT void setlogon_(int *id, int *log_on) { SetLogOnF(id, log_on); } -void setdumpon_(int *id, int *dump_on) +DLL_EXPORT void setdumpon_(int *id, int *dump_on) { SetLogOnF(id, dump_on); } -void setdumpstringon_(int *id, int *dump_string_on) +DLL_EXPORT void setdumpstringon_(int *id, int *dump_string_on) { SetDumpStringOnF(id, dump_string_on); } -int getdumplinecount_(int *id) +DLL_EXPORT int getdumplinecount_(int *id) { return GetDumpLineCountF(id); } -void getdumpline_(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void getdumpline_(int *id, int *n, char* line, unsigned int line_length) { GetDumpLineF(id, n, line, line_length); } -int geterrorlinecount_(int *id) +DLL_EXPORT int geterrorlinecount_(int *id) { return GetErrorLineCountF(id); } -void geterrorline_(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void geterrorline_(int *id, int *n, char* line, unsigned int line_length) { GetErrorLineF(id, n, line, line_length); } -int getwarninglinecount_(int *id) +DLL_EXPORT int getwarninglinecount_(int *id) { return GetWarningLineCountF(id); } -void getwarningline_(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void getwarningline_(int *id, int *n, char* line, unsigned int line_length) { GetWarningLineF(id, n, line, line_length); } -int getcomponentcount_(int *id) +DLL_EXPORT int getcomponentcount_(int *id) { return GetComponentCountF(id); } -void getcomponent_(int *id, int *n, char* line, unsigned int line_length) +DLL_EXPORT void getcomponent_(int *id, int *n, char* line, unsigned int line_length) { GetComponentF(id, n, line, line_length); } -int runaccumulated_(int *id) +DLL_EXPORT int runaccumulated_(int *id) { return RunAccumulatedF(id); } -int runfile_(int *id, char *filename, unsigned int len) +DLL_EXPORT int runfile_(int *id, char *filename, unsigned int len) { return RunFileF(id, filename, len); } -int runstring_(int *id, char *input, unsigned int len) +DLL_EXPORT int runstring_(int *id, char *input, unsigned int len) { return RunStringF(id, input, len); } -void outputlines_(int *id) +DLL_EXPORT void outputlines_(int *id) { OutputLinesF(id); } -int getselectedoutputrowcount_(int *id) +DLL_EXPORT int getselectedoutputrowcount_(int *id) { return GetSelectedOutputRowCountF(id); } -int getselectedoutputcolumncount_(int *id) +DLL_EXPORT int getselectedoutputcolumncount_(int *id) { return GetSelectedOutputColumnCountF(id); } -int getselectedoutputvalue_(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) +DLL_EXPORT int getselectedoutputvalue_(int *id, int *row, int *col, int *vtype, double* dvalue, char* svalue, unsigned int svalue_length) { return GetSelectedOutputValueF(id, row, col, vtype, dvalue, svalue, svalue_length); }