added get_error_count

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/ErrorHandling@5866 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2011-12-06 06:00:57 +00:00
parent b6fe6dd6b6
commit dd713ed065

View File

@ -330,8 +330,8 @@ int IPhreeqc::LoadDatabase(const char* filename)
}
}
this->PhreeqcPtr->clear_istream();
this->DatabaseLoaded = (this->PhreeqcPtr->input_error == 0);
return this->PhreeqcPtr->input_error;
this->DatabaseLoaded = (this->get_error_count() == 0);
return this->get_error_count();
}
int IPhreeqc::LoadDatabaseString(const char* input)
@ -371,8 +371,8 @@ int IPhreeqc::LoadDatabaseString(const char* input)
}
this->PhreeqcPtr->clear_istream();
this->DatabaseLoaded = (this->PhreeqcPtr->input_error == 0);
return this->PhreeqcPtr->input_error;
this->DatabaseLoaded = (this->get_error_count() == 0);
return this->get_error_count();
}
void IPhreeqc::OutputAccumulatedLines(void)
@ -400,8 +400,7 @@ int IPhreeqc::RunAccumulated(void)
this->check_database(sz_routine);
this->PhreeqcPtr->input_error = 0;
// COMMENT: {11/29/2011 6:16:39 PM} this->IPHRQ_ioPtr->Set_io_error_count(0);
this->Set_io_error_count(0);
this->io_error_count = 0;
// create input stream
std::istringstream iss(this->GetAccumulatedLines());
@ -431,7 +430,7 @@ int IPhreeqc::RunAccumulated(void)
this->update_errors();
this->PhreeqcPtr->clear_istream();
return this->PhreeqcPtr->input_error;
return this->get_error_count();
}
int IPhreeqc::RunFile(const char* filename)
@ -444,6 +443,7 @@ int IPhreeqc::RunFile(const char* filename)
this->check_database(sz_routine);
this->PhreeqcPtr->input_error = 0;
this->io_error_count = 0;
// open file
//
@ -480,7 +480,7 @@ int IPhreeqc::RunFile(const char* filename)
this->update_errors();
this->PhreeqcPtr->clear_istream();
return this->PhreeqcPtr->input_error;
return this->get_error_count();
}
int IPhreeqc::RunString(const char* input)
@ -493,6 +493,7 @@ int IPhreeqc::RunString(const char* input)
this->check_database(sz_routine);
this->PhreeqcPtr->input_error = 0;
this->io_error_count = 0;
// create input stream
std::string s(input);
@ -522,7 +523,7 @@ int IPhreeqc::RunString(const char* input)
this->update_errors();
this->PhreeqcPtr->clear_istream();
return this->PhreeqcPtr->input_error;
return this->get_error_count();
}
void IPhreeqc::SetDumpFileOn(bool bValue)
@ -588,209 +589,9 @@ void IPhreeqc::UnLoadDatabase(void)
// initialize phreeqc
//
this->PhreeqcPtr->clean_up();
// COMMENT: {11/16/2011 10:01:40 PM} this->PhreeqcPtr->add_output_callback(IPhreeqc::handler, this);
this->PhreeqcPtr->do_initialize();
this->PhreeqcPtr->input_error = 0;
// COMMENT: {11/29/2011 7:18:29 PM} this->IPHRQ_ioPtr->Set_io_error_count(0);
}
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;
// COMMENT: {11/16/2011 10:02:40 PM} switch (action)
// COMMENT: {11/16/2011 10:02:40 PM} {
// COMMENT: {11/16/2011 10:02:40 PM} case Phreeqc::ACTION_OPEN:
// COMMENT: {11/16/2011 10:02:40 PM} n = pThis->open_handler(type, err_str);
// COMMENT: {11/16/2011 10:02:40 PM} break;
// COMMENT: {11/16/2011 10:02:40 PM}
// COMMENT: {11/16/2011 10:02:40 PM} case Phreeqc::ACTION_OUTPUT:
// COMMENT: {11/16/2011 10:02:40 PM} n = pThis->output_handler(type, err_str, stop, cookie, format, args);
// COMMENT: {11/16/2011 10:02:40 PM} break;
// COMMENT: {11/16/2011 10:02:40 PM}
// COMMENT: {11/16/2011 10:02:40 PM} default:
// COMMENT: {11/16/2011 10:02:40 PM} n = pThis->module_handler(action, type, err_str, stop, cookie, format, args);
// COMMENT: {11/16/2011 10:02:40 PM} break;
// COMMENT: {11/16/2011 10:02:40 PM} }
if (stop == STOP)
{
throw IPhreeqcStop();
}
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);
// COMMENT: {11/16/2011 10:04:42 PM} switch (type)
// COMMENT: {11/16/2011 10:04:42 PM} {
// COMMENT: {11/16/2011 10:04:42 PM} case Phreeqc::OUTPUT_ERROR:
// COMMENT: {11/16/2011 10:04:42 PM} if (this)
// COMMENT: {11/16/2011 10:04:42 PM} {
// COMMENT: {11/16/2011 10:04:42 PM} this->AddError("ERROR: ");
// COMMENT: {11/16/2011 10:04:42 PM} this->AddError(err_str);
// COMMENT: {11/16/2011 10:04:42 PM} this->AddError("\n");
// COMMENT: {11/16/2011 10:04:42 PM}#if 0
// COMMENT: {11/16/2011 10:04:42 PM} if (stop == STOP)
// COMMENT: {11/16/2011 10:04:42 PM} {
// COMMENT: {11/16/2011 10:04:42 PM} this->AddError("Stopping.\n");
// COMMENT: {11/16/2011 10:04:42 PM} }
// COMMENT: {11/16/2011 10:04:42 PM}#endif
// COMMENT: {11/16/2011 10:04:42 PM} }
// COMMENT: {11/16/2011 10:04:42 PM} break;
// COMMENT: {11/16/2011 10:04:42 PM}
// COMMENT: {11/16/2011 10:04:42 PM} case Phreeqc::OUTPUT_WARNING:
// COMMENT: {11/16/2011 10:04:42 PM} if (this)
// COMMENT: {11/16/2011 10:04:42 PM} {
// COMMENT: {11/16/2011 10:04:42 PM} std::ostringstream oss;
// COMMENT: {11/16/2011 10:04:42 PM} oss << "WARNING: " << err_str << "\n";
// COMMENT: {11/16/2011 10:04:42 PM} this->AddWarning(oss.str().c_str());
// COMMENT: {11/16/2011 10:04:42 PM} }
// COMMENT: {11/16/2011 10:04:42 PM} break;
// COMMENT: {11/16/2011 10:04:42 PM}
// COMMENT: {11/16/2011 10:04:42 PM} case Phreeqc::OUTPUT_PUNCH:
// COMMENT: {11/16/2011 10:04:42 PM} this->AddSelectedOutput(err_str, format, args);
// COMMENT: {11/16/2011 10:04:42 PM} break;
// COMMENT: {11/16/2011 10:04:42 PM}
// COMMENT: {11/16/2011 10:04:42 PM} case Phreeqc::OUTPUT_PUNCH_END_ROW:
// COMMENT: {11/16/2011 10:04:42 PM} this->EndRow();
// COMMENT: {11/16/2011 10:04:42 PM} break;
// COMMENT: {11/16/2011 10:04:42 PM}
// COMMENT: {11/16/2011 10:04:42 PM}// COMMENT: {5/19/2010 4:50:29 PM} case Phreeqc::OUTPUT_LOG:
// COMMENT: {11/16/2011 10:04:42 PM}// COMMENT: {5/19/2010 4:50:29 PM} if (this)
// COMMENT: {11/16/2011 10:04:42 PM}// COMMENT: {5/19/2010 4:50:29 PM} {
// COMMENT: {11/16/2011 10:04:42 PM}// COMMENT: {5/19/2010 4:50:29 PM} std::ostringstream oss;
// COMMENT: {11/16/2011 10:04:42 PM}// COMMENT: {5/19/2010 4:50:29 PM} oss << "WARNING: " << err_str << "\n";
// COMMENT: {11/16/2011 10:04:42 PM}// COMMENT: {5/19/2010 4:50:29 PM} this->AddWarning(oss.str().c_str());
// COMMENT: {11/16/2011 10:04:42 PM}// COMMENT: {5/19/2010 4:50:29 PM} }
// COMMENT: {11/16/2011 10:04:42 PM}// COMMENT: {5/19/2010 4:50:29 PM} break;
// COMMENT: {11/16/2011 10:04:42 PM} }
#if 0
return module_handler(Phreeqc::ACTION_OUTPUT, type, err_str, stop, cookie, format, args);
#else
return 0;
#endif
}
int IPhreeqc::open_handler(const int type, const char *file_name)
{
int n = OK;
// COMMENT: {11/16/2011 10:04:23 PM} switch (type)
// COMMENT: {11/16/2011 10:04:23 PM} {
// COMMENT: {11/16/2011 10:04:23 PM} case Phreeqc::OUTPUT_PUNCH:
// COMMENT: {11/16/2011 10:04:23 PM} if (file_name)
// COMMENT: {11/16/2011 10:04:23 PM} {
// COMMENT: {11/16/2011 10:04:23 PM} if (this->PunchFileName.compare(file_name) != 0)
// COMMENT: {11/16/2011 10:04:23 PM} {
// COMMENT: {11/16/2011 10:04:23 PM} this->PunchFileName = file_name;
// COMMENT: {11/16/2011 10:04:23 PM} }
// COMMENT: {11/16/2011 10:04:23 PM} }
// COMMENT: {11/16/2011 10:04:23 PM} if (this->SelectedOutputOn)
// COMMENT: {11/16/2011 10:04:23 PM} {
// COMMENT: {11/16/2011 10:04:23 PM} n = module_handler(Phreeqc::ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL);
// COMMENT: {11/16/2011 10:04:23 PM} }
// COMMENT: {11/16/2011 10:04:23 PM} break;
// COMMENT: {11/16/2011 10:04:23 PM} default:
// COMMENT: {11/16/2011 10:04:23 PM} n = module_handler(Phreeqc::ACTION_OPEN, type, file_name, CONTINUE, this, NULL, NULL);
// COMMENT: {11/16/2011 10:04:23 PM} break;
// COMMENT: {11/16/2011 10:04:23 PM} }
return n;
}
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;
// COMMENT: {11/16/2011 10:05:03 PM} switch (action)
// COMMENT: {11/16/2011 10:05:03 PM} {
// COMMENT: {11/16/2011 10:05:03 PM} case Phreeqc::ACTION_OPEN:
// COMMENT: {11/16/2011 10:05:03 PM} return pThis->module_open_handler(type, err_str);
// COMMENT: {11/16/2011 10:05:03 PM} break;
// COMMENT: {11/16/2011 10:05:03 PM} case ACTION_ISOPEN:
// COMMENT: {11/16/2011 10:05:03 PM} return pThis->module_isopen_handler(type);
// COMMENT: {11/16/2011 10:05:03 PM} break;
// COMMENT: {11/16/2011 10:05:03 PM} default:
// COMMENT: {11/16/2011 10:05:03 PM} return pThis->PhreeqcPtr->phreeqc_handler(action, type, err_str, stop, pThis->PhreeqcPtr, format, args);
// COMMENT: {11/16/2011 10:05:03 PM} break;
// COMMENT: {11/16/2011 10:05:03 PM} }
return ERROR;
}
int IPhreeqc::module_isopen_handler(const int type)
{
// COMMENT: {11/16/2011 10:05:16 PM} switch (type)
// COMMENT: {11/16/2011 10:05:16 PM} {
// COMMENT: {11/16/2011 10:05:16 PM} case Phreeqc::OUTPUT_PUNCH:
// COMMENT: {11/16/2011 10:05:16 PM} if (this->PhreeqcPtr->punch_file) return 1;
// COMMENT: {11/16/2011 10:05:16 PM} break;
// COMMENT: {11/16/2011 10:05:16 PM} default:
// COMMENT: {11/16/2011 10:05:16 PM} ASSERT(0);
// COMMENT: {11/16/2011 10:05:16 PM} }
return 0;
}
int IPhreeqc::module_open_handler(const int type, const char *file_name)
{
ASSERT(file_name && ::strlen(file_name));
// COMMENT: {11/16/2011 10:05:34 PM} switch (type)
// COMMENT: {11/16/2011 10:05:34 PM} {
// COMMENT: {11/16/2011 10:05:34 PM} case Phreeqc::OUTPUT_MESSAGE:
// COMMENT: {11/16/2011 10:05:34 PM} if (this->PhreeqcPtr->output_file != NULL)
// COMMENT: {11/16/2011 10:05:34 PM} {
// COMMENT: {11/16/2011 10:05:34 PM} ::fclose(this->PhreeqcPtr->output_file);
// COMMENT: {11/16/2011 10:05:34 PM} this->PhreeqcPtr->output_file = NULL;
// COMMENT: {11/16/2011 10:05:34 PM} }
// COMMENT: {11/16/2011 10:05:34 PM} if ( (this->PhreeqcPtr->output_file = ::fopen(file_name, "w")) == NULL)
// COMMENT: {11/16/2011 10:05:34 PM} {
// COMMENT: {11/16/2011 10:05:34 PM} return ERROR;
// COMMENT: {11/16/2011 10:05:34 PM} }
// COMMENT: {11/16/2011 10:05:34 PM} break;
// COMMENT: {11/16/2011 10:05:34 PM}
// COMMENT: {11/16/2011 10:05:34 PM} case Phreeqc::OUTPUT_ERROR:
// COMMENT: {11/16/2011 10:05:34 PM} ASSERT(this->PhreeqcPtr->error_file != stderr);
// COMMENT: {11/16/2011 10:05:34 PM} if (this->PhreeqcPtr->error_file != NULL)
// COMMENT: {11/16/2011 10:05:34 PM} {
// COMMENT: {11/16/2011 10:05:34 PM} ::fclose(this->PhreeqcPtr->error_file);
// COMMENT: {11/16/2011 10:05:34 PM} this->PhreeqcPtr->error_file = NULL;
// COMMENT: {11/16/2011 10:05:34 PM} }
// COMMENT: {11/16/2011 10:05:34 PM} if ( (this->PhreeqcPtr->error_file = ::fopen(file_name, "w")) == NULL)
// COMMENT: {11/16/2011 10:05:34 PM} {
// COMMENT: {11/16/2011 10:05:34 PM} return ERROR;
// COMMENT: {11/16/2011 10:05:34 PM} }
// COMMENT: {11/16/2011 10:05:34 PM} break;
// COMMENT: {11/16/2011 10:05:34 PM}
// COMMENT: {11/16/2011 10:05:34 PM} case Phreeqc::OUTPUT_LOG:
// COMMENT: {11/16/2011 10:05:34 PM} if (this->PhreeqcPtr->log_file != NULL)
// COMMENT: {11/16/2011 10:05:34 PM} {
// COMMENT: {11/16/2011 10:05:34 PM} ::fclose(this->PhreeqcPtr->log_file);
// COMMENT: {11/16/2011 10:05:34 PM} this->PhreeqcPtr->log_file = NULL;
// COMMENT: {11/16/2011 10:05:34 PM} }
// COMMENT: {11/16/2011 10:05:34 PM} if ( (this->PhreeqcPtr->log_file = ::fopen(file_name, "w")) == NULL)
// COMMENT: {11/16/2011 10:05:34 PM} {
// COMMENT: {11/16/2011 10:05:34 PM} return ERROR;
// COMMENT: {11/16/2011 10:05:34 PM} }
// COMMENT: {11/16/2011 10:05:34 PM} break;
// COMMENT: {11/16/2011 10:05:34 PM}
// COMMENT: {11/16/2011 10:05:34 PM} default:
// COMMENT: {11/16/2011 10:05:34 PM} return this->PhreeqcPtr->open_handler(type, file_name);
// COMMENT: {11/16/2011 10:05:34 PM} break;
// COMMENT: {11/16/2011 10:05:34 PM}
// COMMENT: {11/16/2011 10:05:34 PM} }
return(OK);
}
int IPhreeqc::output_isopen(const int type)
{
// COMMENT: {11/16/2011 10:06:17 PM} size_t i;
// COMMENT: {11/16/2011 10:06:17 PM} int isopen;
// COMMENT: {11/16/2011 10:06:17 PM} for (i = 0; i < this->PhreeqcPtr->count_output_callback; ++i)
// COMMENT: {11/16/2011 10:06:17 PM} {
// COMMENT: {11/16/2011 10:06:17 PM} isopen = (this->PhreeqcPtr->output_callbacks[i].callback)(ACTION_ISOPEN, type, NULL, CONTINUE, this->PhreeqcPtr->output_callbacks[i].cookie, NULL, NULL);
// COMMENT: {11/16/2011 10:06:17 PM} if (isopen) return 1;
// COMMENT: {11/16/2011 10:06:17 PM} }
return 0;
this->io_error_count = 0;
}
int IPhreeqc::EndRow(void)
@ -807,180 +608,6 @@ int IPhreeqc::EndRow(void)
return this->SelectedOutput->EndRow();
}
// COMMENT: {11/29/2011 3:58:27 PM}void IPhreeqc::AddSelectedOutput(const char* name, const char* format, va_list argptr)
// COMMENT: {11/29/2011 3:58:27 PM}{
// COMMENT: {11/29/2011 3:58:27 PM} int bInt;
// COMMENT: {11/29/2011 3:58:27 PM} int bDouble;
// COMMENT: {11/29/2011 3:58:27 PM} int bString;
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} int state;
// COMMENT: {11/29/2011 3:58:27 PM} int bLongDouble;
// COMMENT: {11/29/2011 3:58:27 PM} char ch;
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} /* state values
// COMMENT: {11/29/2011 3:58:27 PM} 0 Haven't found start(%)
// COMMENT: {11/29/2011 3:58:27 PM} 1 Just read start(%)
// COMMENT: {11/29/2011 3:58:27 PM} 2 Just read Flags(-0+ #) (zero or more)
// COMMENT: {11/29/2011 3:58:27 PM} 3 Just read Width
// COMMENT: {11/29/2011 3:58:27 PM} 4 Just read Precision start (.)
// COMMENT: {11/29/2011 3:58:27 PM} 5 Just read Size modifier
// COMMENT: {11/29/2011 3:58:27 PM} 6 Just read Type
// COMMENT: {11/29/2011 3:58:27 PM} */
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} if (name == NULL) {
// COMMENT: {11/29/2011 3:58:27 PM} return;
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} bDouble = 0;
// COMMENT: {11/29/2011 3:58:27 PM} bInt = 0;
// COMMENT: {11/29/2011 3:58:27 PM} bString = 0;
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} bLongDouble = 0;
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} state = 0;
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} while (ch != '\0')
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} switch (state)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} case 0: /* looking for Start specification (%) */
// COMMENT: {11/29/2011 3:58:27 PM} switch (ch)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} case '%':
// COMMENT: {11/29/2011 3:58:27 PM} state = 1;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} default:
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 1: /* reading Flags (zero or more(-,+,0,# or space)) */
// COMMENT: {11/29/2011 3:58:27 PM} switch (ch)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} case '-': case '0': case '+': case ' ': case '#':
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} default:
// COMMENT: {11/29/2011 3:58:27 PM} state = 2;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 2: /* reading Minimum field width (decimal integer constant) */
// COMMENT: {11/29/2011 3:58:27 PM} switch (ch)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} case '.':
// COMMENT: {11/29/2011 3:58:27 PM} state = 3;
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} default:
// COMMENT: {11/29/2011 3:58:27 PM} state = 4;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 3: /* reading Precision specification (period already read) */
// COMMENT: {11/29/2011 3:58:27 PM} switch (ch)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} default:
// COMMENT: {11/29/2011 3:58:27 PM} state = 4;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 4: /* reading Size modifier */
// COMMENT: {11/29/2011 3:58:27 PM} switch (ch)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} case 'l':
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 'L':
// COMMENT: {11/29/2011 3:58:27 PM} bLongDouble = 1;
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 'h':
// COMMENT: {11/29/2011 3:58:27 PM} ch = *format++;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} state = 5;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 5: /* reading Conversion letter */
// COMMENT: {11/29/2011 3:58:27 PM} switch (ch)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} case 'c':
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 'd':
// COMMENT: {11/29/2011 3:58:27 PM} case 'i':
// COMMENT: {11/29/2011 3:58:27 PM} bInt = 1;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 'n':
// COMMENT: {11/29/2011 3:58:27 PM} case 'o':
// COMMENT: {11/29/2011 3:58:27 PM} case 'p':
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 's':
// COMMENT: {11/29/2011 3:58:27 PM} bString = 1;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 'u':
// COMMENT: {11/29/2011 3:58:27 PM} case 'x':
// COMMENT: {11/29/2011 3:58:27 PM} case 'X':
// COMMENT: {11/29/2011 3:58:27 PM} case '%':
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} case 'f':
// COMMENT: {11/29/2011 3:58:27 PM} case 'e':
// COMMENT: {11/29/2011 3:58:27 PM} case 'E':
// COMMENT: {11/29/2011 3:58:27 PM} case 'g':
// COMMENT: {11/29/2011 3:58:27 PM} case 'G':
// COMMENT: {11/29/2011 3:58:27 PM} bDouble = 1;
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} default:
// COMMENT: {11/29/2011 3:58:27 PM} ASSERT(false);
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} ch = '\0'; /* done */
// COMMENT: {11/29/2011 3:58:27 PM} break;
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} if (bDouble)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} double valDouble;
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} if (bLongDouble)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} valDouble = (double)va_arg(argptr, long double);
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} else
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} valDouble = va_arg(argptr, double);
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} this->SelectedOutput->PushBackDouble(name, valDouble);
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} else if (bInt)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} int valInt;
// COMMENT: {11/29/2011 3:58:27 PM} valInt = va_arg(argptr, int);
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} this->SelectedOutput->PushBackLong(name, (long)valInt);
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} else if (bString)
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} char* valString;
// COMMENT: {11/29/2011 3:58:27 PM} valString = (char *)va_arg(argptr, char *);
// COMMENT: {11/29/2011 3:58:27 PM}
// COMMENT: {11/29/2011 3:58:27 PM} this->SelectedOutput->PushBackString(name, valString);
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM} else
// COMMENT: {11/29/2011 3:58:27 PM} {
// COMMENT: {11/29/2011 3:58:27 PM} ASSERT(false);
// COMMENT: {11/29/2011 3:58:27 PM} this->SelectedOutput->PushBackEmpty(name);
// COMMENT: {11/29/2011 3:58:27 PM} }
// COMMENT: {11/29/2011 3:58:27 PM}}
void IPhreeqc::check_database(const char* sz_routine)
{
this->ErrorReporter->Clear();
@ -997,7 +624,6 @@ void IPhreeqc::check_database(const char* sz_routine)
void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALLBACK pfn_pre, PFN_POSTRUN_CALLBACK pfn_post, void *cookie)
{
std::auto_ptr<std::istringstream> auto_iss(NULL);
char token[MAX_LENGTH];
/*
@ -1011,18 +637,14 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
/*
* set read callback
*/
std::auto_ptr<std::istringstream> auto_iss(0);
if (!pis)
{
{
std::auto_ptr<std::istringstream> a_iss(new std::istringstream(this->GetAccumulatedLines()));
auto_iss = a_iss;
// COMMENT: {11/22/2011 7:01:32 PM} this->PhreeqcPtr->set_read_callback(istream_getc, auto_iss.get(), FALSE);
this->PhreeqcPtr->push_istream(auto_iss.get(), false);
}
auto_iss.reset(new std::istringstream(this->GetAccumulatedLines()));
this->PhreeqcPtr->push_istream(auto_iss.get(), false);
}
else
{
// COMMENT: {11/22/2011 7:01:42 PM} this->PhreeqcPtr->set_read_callback(istream_getc, pis, FALSE);
ASSERT(this->PhreeqcPtr->get_istream() == NULL);
this->PhreeqcPtr->push_istream(pis, false);
}
@ -1031,23 +653,20 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
/*
* Read input data for simulation
*/
for (this->PhreeqcPtr->simulation = 1; ; this->PhreeqcPtr->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);
// COMMENT: {11/16/2011 10:06:56 PM} this->PhreeqcPtr->output_msg(Phreeqc::OUTPUT_GUI_ERROR, "\nSimulation %d\n", this->PhreeqcPtr->simulation);
// TODO
#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
this->PhreeqcPtr->dup_print(token, TRUE);
if (this->PhreeqcPtr->read_input() == EOF)
break;
if (this->PhreeqcPtr->simulation > 1 && save_punch_in == TRUE && this->PhreeqcPtr->punch.new_def == TRUE)
{
std::ostringstream oss;
@ -1055,18 +674,17 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
this->PhreeqcPtr->warning_msg(oss.str().c_str());
}
// COMMENT: {11/30/2011 11:14:18 PM} if (this->PhreeqcPtr->simulation > 1 && this->PhreeqcPtr->keyword[39].keycount > 0)
// COMMENT: {11/30/2011 11:14:18 PM} {
// COMMENT: {11/30/2011 11:14:18 PM} std::ostringstream oss;
// COMMENT: {11/30/2011 11:14:18 PM} oss << sz_routine << ": Warning USER_PUNCH has been redefined.\n";
// COMMENT: {11/30/2011 11:14:18 PM} this->PhreeqcPtr->warning_msg(oss.str().c_str());
// COMMENT: {11/30/2011 11:14:18 PM} }
#endif // SWIG_SHARED_OBJ
if (this->PhreeqcPtr->simulation > 1 && this->PhreeqcPtr->keycount[Keywords::KEY_USER_PUNCH] > 0)
{
std::ostringstream oss;
oss << sz_routine << ": Warning USER_PUNCH has been redefined.\n";
this->PhreeqcPtr->warning_msg(oss.str().c_str());
}
if (this->PhreeqcPtr->title_x != NULL) {
if (this->PhreeqcPtr->title_x != NULL)
{
::sprintf(token, "TITLE");
this->PhreeqcPtr->dup_print(token, TRUE);
// COMMENT: {11/16/2011 10:07:07 PM} if (this->PhreeqcPtr->pr.headings == TRUE) this->PhreeqcPtr->output_msg(Phreeqc::OUTPUT_MESSAGE, "%s\n\n", this->PhreeqcPtr->title_x);
if (this->PhreeqcPtr->pr.headings == TRUE)
{
char *p = this->PhreeqcPtr->sformatf("%s\n\n", this->PhreeqcPtr->title_x);
@ -1093,7 +711,6 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
// TRUE ???
//
//
// COMMENT: {11/16/2011 10:07:25 PM} if (!this->SelectedOutputOn) ASSERT(!this->output_isopen(Phreeqc::OUTPUT_PUNCH));
if (!this->SelectedOutputOn)
{
ASSERT(!this->punch_file);
@ -1111,7 +728,6 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
{
if (this->PhreeqcPtr->punch.new_def == FALSE)
{
// COMMENT: {11/16/2011 10:07:38 PM} if (this->SelectedOutputOn && !this->output_isopen(Phreeqc::OUTPUT_PUNCH))
if (this->SelectedOutputOn && !this->punch_file)
{
//
@ -1120,14 +736,13 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
// another do_run without SELECTED_OUTPUT
//
std::string filename = this->PunchFileName;
// COMMENT: {11/16/2011 10:08:23 PM} this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_PUNCH, filename.c_str());
// COMMENT: {11/16/2011 10:08:23 PM} if (!this->output_isopen(Phreeqc::OUTPUT_PUNCH))
// COMMENT: {11/16/2011 10:08:23 PM} {
// COMMENT: {11/16/2011 10:08:23 PM} std::ostringstream oss;
// COMMENT: {11/16/2011 10:08:23 PM} oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n";
// COMMENT: {11/16/2011 10:08:23 PM} this->PhreeqcPtr->warning_msg(oss.str().c_str());
// COMMENT: {11/16/2011 10:08:23 PM} }
// COMMENT: {11/16/2011 10:08:23 PM} else
if (!this->punch_open(filename.c_str()))
{
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;
@ -1137,7 +752,6 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
}
else
{
// COMMENT: {11/16/2011 10:08:38 PM} if (this->SelectedOutputOn && !this->output_isopen(Phreeqc::OUTPUT_PUNCH))
if (this->SelectedOutputOn && !this->punch_file)
{
// This is a special case which could not occur in
@ -1152,14 +766,6 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
{
filename = this->PunchFileName;
}
// COMMENT: {11/16/2011 10:09:10 PM} this->PhreeqcPtr->output_open(Phreeqc::OUTPUT_PUNCH, filename.c_str());
// COMMENT: {11/16/2011 10:09:10 PM} if (!this->output_isopen(Phreeqc::OUTPUT_PUNCH))
// COMMENT: {11/16/2011 10:09:10 PM} {
// COMMENT: {11/16/2011 10:09:10 PM} std::ostringstream oss;
// COMMENT: {11/16/2011 10:09:10 PM} oss << sz_routine << ": Unable to open:" << "\"" << filename << "\".\n";
// COMMENT: {11/16/2011 10:09:10 PM} this->PhreeqcPtr->warning_msg(oss.str().c_str());
// COMMENT: {11/16/2011 10:09:10 PM} }
// COMMENT: {11/16/2011 10:09:10 PM} else
if (!this->punch_open(filename.c_str()))
{
std::ostringstream oss;
@ -1177,36 +783,37 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
}
}
// COMMENT: {11/16/2011 10:09:47 PM} if (!this->SelectedOutputOn) ASSERT(!this->output_isopen(Phreeqc::OUTPUT_PUNCH));
if (!this->SelectedOutputOn) ASSERT(!this->punch_file);
/* 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) {
if (!phreeq98_debug)
{
#endif
/*
* Calculate distribution of species for initial solutions
*/
if (this->PhreeqcPtr->new_solution) this->PhreeqcPtr->initial_solutions(TRUE);
if (this->PhreeqcPtr->new_solution)
this->PhreeqcPtr->initial_solutions(TRUE);
/*
* Calculate distribution for exchangers
*/
if (this->PhreeqcPtr->new_exchange) this->PhreeqcPtr->initial_exchangers(TRUE);
if (this->PhreeqcPtr->new_exchange)
this->PhreeqcPtr->initial_exchangers(TRUE);
/*
* Calculate distribution for surfaces
*/
if (this->PhreeqcPtr->new_surface) this->PhreeqcPtr->initial_surfaces(TRUE);
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);
if (this->PhreeqcPtr->new_gas_phase)
this->PhreeqcPtr->initial_gas_phases(TRUE);
/*
* Calculate reactions
*/
@ -1218,31 +825,27 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
/*
* Calculate advection
*/
if (this->PhreeqcPtr->use.advect_in == TRUE) {
this->PhreeqcPtr->dup_print ("Beginning of advection calculations.", TRUE);
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);
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
this->PhreeqcPtr->run_as_cells();
/*
* Copy
*/
if (this->PhreeqcPtr->new_copy) this->PhreeqcPtr->copy_entities();
#ifdef PHREEQC_CPP
/*
* dump
*/
@ -1280,8 +883,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
/*
* delete
*/
this->PhreeqcPtr->delete_entities();
#endif
this->PhreeqcPtr->delete_entities();
/*
* End of simulation
@ -1464,7 +1066,6 @@ void IPhreeqc::fpunchf_end_row(const char *format)
}
bool IPhreeqc::punch_open(const char *file_name)
/* ---------------------------------------------------------------------- */
{
if (file_name)
{
@ -1479,3 +1080,8 @@ bool IPhreeqc::punch_open(const char *file_name)
}
return true;
}
int IPhreeqc::get_error_count(void)const
{
return this->PhreeqcPtr->input_error + this->io_error_count;
}