need to test on linux

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4165 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2010-03-18 03:21:45 +00:00
parent 587b763f39
commit 3384e61308
17 changed files with 809 additions and 464 deletions

View File

@ -20,6 +20,11 @@ Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "testf90", "testf90\testf90.
{F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7} = {F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7}
EndProjectSection
EndProject
Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "test_getline", "test_getline\test_getline.vfproj", "{D95AB257-163E-4ABD-8577-94FB8D1EF62C}"
ProjectSection(ProjectDependencies) = postProject
{F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7} = {F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -57,6 +62,12 @@ Global
{29C3C862-28CA-4BF2-BAF5-A8F8ABF15C12}.MemDebug|Win32.Build.0 = Debug|Win32
{29C3C862-28CA-4BF2-BAF5-A8F8ABF15C12}.Release|Win32.ActiveCfg = Release|Win32
{29C3C862-28CA-4BF2-BAF5-A8F8ABF15C12}.Release|Win32.Build.0 = Release|Win32
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.Debug|Win32.ActiveCfg = Debug|Win32
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.Debug|Win32.Build.0 = Debug|Win32
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.MemDebug|Win32.ActiveCfg = Debug|Win32
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.MemDebug|Win32.Build.0 = Debug|Win32
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.Release|Win32.ActiveCfg = Release|Win32
{D95AB257-163E-4ABD-8577-94FB8D1EF62C}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -44,7 +44,7 @@
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="$(DEV_GMP_INC);include;src;src/phreeqcpp;src/phreeqcpp/phreeqc"
PreprocessorDefinitions="NDEBUG;WIN32;_LIB;SWIG_SHARED_OBJ;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;PHREEQC_CPP;XX_INVERSE_CL1MP_XX;PHREEQC_CLASS;USE_PHRQ_ALLOC"
PreprocessorDefinitions="NDEBUG;WIN32;_LIB;SWIG_SHARED_OBJ;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;PHREEQC_CPP;PHREEQC_CLASS;USE_PHRQ_ALLOC"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
@ -118,7 +118,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="$(DEV_GMP_INC);include;src;src/phreeqcpp;src/phreeqcpp/phreeqc"
PreprocessorDefinitions="_DEBUG;WIN32;_LIB;SWIG_SHARED_OBJ;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;PHREEQC_CPP;XX_INVERSE_CL1MP_XX;PHREEQC_CLASS;USE_PHRQ_ALLOC"
PreprocessorDefinitions="_DEBUG;WIN32;_LIB;SWIG_SHARED_OBJ;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;PHREEQC_CPP;PHREEQC_CLASS;USE_PHRQ_ALLOC"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@ -2016,10 +2016,6 @@
RelativePath="src\module_files.h"
>
</File>
<File
RelativePath="src\phreeqcns.hxx"
>
</File>
<File
RelativePath="src\SelectedOutput.hxx"
>

View File

@ -43,7 +43,7 @@
END FUNCTION AccumulateLine
END INTERFACE
INTERFACE
FUNCTION Run()
INTEGER(KIND=4) :: Run
@ -73,7 +73,7 @@
END SUBROUTINE SetSelectedOutputOn
END INTERFACE
INTERFACE
SUBROUTINE SetOutputOn(OUT_ON)
LOGICAL(KIND=4) :: OUT_ON
@ -95,6 +95,20 @@
END INTERFACE
INTERFACE
SUBROUTINE SetDumpOn(DUMP_ON)
LOGICAL(KIND=4) :: DUMP_ON
END SUBROUTINE SetDumpOn
END INTERFACE
INTERFACE
SUBROUTINE SetDumpStringOn(DUMP_STRING_ON)
LOGICAL(KIND=4) :: DUMP_STRING_ON
END SUBROUTINE SetDumpStringOn
END INTERFACE
INTERFACE
SUBROUTINE OutputLines
END SUBROUTINE OutputLines
@ -125,3 +139,33 @@
INTEGER(KIND=4) :: GetSelectedOutputValue
END FUNCTION GetSelectedOutputValue
END INTERFACE
INTERFACE
FUNCTION GetDumpLineCount()
INTEGER(KIND=4) :: GetDumpLineCount
END FUNCTION GetDumpLineCount
END INTERFACE
INTERFACE
SUBROUTINE GetDumpLine(N,LINE)
INTEGER(KIND=4) :: N
CHARACTER(LEN=*) :: LINE
END SUBROUTINE
END INTERFACE
INTERFACE
FUNCTION GetErrorLineCount()
INTEGER(KIND=4) :: GetErrorLineCount
END FUNCTION GetErrorLineCount
END INTERFACE
INTERFACE
SUBROUTINE GetErrorLine(N,LINE)
INTEGER(KIND=4) :: N
CHARACTER(LEN=*) :: LINE
END SUBROUTINE
END INTERFACE

View File

@ -157,6 +157,38 @@ void SetErrorOn(int error_on);
*/
void SetLogOn(int error_on);
/**
* Sets the dump flag on or off
* @param dump_on If non-zero turns on output to the <B>DUMP</B> (<B>dump.out</B> if unspecified) file.
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* SUBROUTINE SetDumpOn(DUMP_ON)
* LOGICAL, INTENT(IN) :: DUMP_ON
* END SUBROUTINE SetDumpOn
* </PRE>
* </CODE>
* @endhtmlonly
*/
void SetDumpOn(int dump_on);
/**
* Sets the dump string flag on or off
* @param dump_string_on If non-zero captures as a string the output defined by the <B>DUMP</B> keyword.
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* SUBROUTINE SetDumpStringOn(DUMP_STRING_ON)
* LOGICAL, INTENT(IN) :: DUMP_STRING_ON
* END SUBROUTINE SetDumpStringOn
* </PRE>
* </CODE>
* @endhtmlonly
*/
void SetDumpStringOn(int dump_string_on);
/**
* Runs the accumulated input sent to AccumulateLine.
@ -453,6 +485,72 @@ int CatchErrors(PFN_CATCH_CALLBACK pfn, void *cookie);
const char* GetLastErrorString(void);
const char* GetLastWarningString(void);
const char* GetDumpString(void);
/**
* TODO
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* FUNCTION GetDumpLineCount
* INTEGER :: GetDumpLineCount
* END FUNCTION GetDumpLineCount
* </PRE>
* </CODE>
* @endhtmlonly
*/
int GetDumpLineCount(void);
/**
* TODO
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* SUBROUTINE GetDumpLine
* INTEGER, INTENT(IN) :: N
* CHARACTER(LEN=*), INTENT(OUT) :: LINE
* END SUBROUTINE GetDumpLine
* </PRE>
* </CODE>
* @endhtmlonly
*/
const char* GetDumpLine(int n);
/**
* TODO
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* FUNCTION GetErrorLineCount
* INTEGER :: GetErrorLineCount
* END FUNCTION GetErrorLineCount
* </PRE>
* </CODE>
* @endhtmlonly
*/
int GetErrorLineCount(void);
/**
* TODO
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* SUBROUTINE GetErrorLine
* INTEGER, INTENT(IN) :: N
* CHARACTER(LEN=*), INTENT(OUT) :: LINE
* END SUBROUTINE GetErrorLine
* </PRE>
* </CODE>
* @endhtmlonly
*/
const char* GetErrorLine(int n);
#if defined(WIN32)
void DebugOutputLines(void);
#endif

View File

@ -4,7 +4,6 @@
#include <iosfwd> // std::ostream
#include <cstdio> // std::fprintf
#include "phreeqcns.hxx"
class IErrorReporter
{

View File

@ -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<std::ostringstream>;
this->SelectedOutput = new CSelectedOutput();
this->ErrorReporter = new CErrorReporter<std::ostringstream>;
this->WarningReporter = new CErrorReporter<std::ostringstream>;
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<std::ostringstream>*)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<std::ostringstream>*)this->ErrorReporter)->GetOS()->str();
return str.c_str();
this->LastErrorString = ((CErrorReporter<std::ostringstream>*)this->ErrorReporter)->GetOS()->str();
return this->LastErrorString.c_str();
}
const char* IPhreeqc::GetLastWarningString(void)
{
this->LastWarningString = ((CErrorReporter<std::ostringstream>*)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<std::istringstream> 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 << "</input>\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<std::ostringstream>*)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);
}
}

View File

@ -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;

View File

@ -12,244 +12,11 @@
#include <stdarg.h>
#include <stdio.h>
#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;
}

View File

@ -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();

View File

@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -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 <math.h>
#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 */

View File

@ -27,6 +27,7 @@
CALL SetErrorOn(.FALSE.)
CALL SetLogOn(.FALSE.)
CALL SetSelectedOutputOn(.TRUE.)
CALL SetDumpOn(.FALSE.)
iresult = Run()
IF (iresult.NE.VR_OK) THEN
CALL OutputLastError

View File

@ -13,9 +13,12 @@ int DeleteFile(const char* szPathName)
}
#endif
#include "../include/IPhreeqc.h"
#include "../src/CVar.hxx"
#include "../src/phreeqcns.hxx"
#include "IPhreeqc.hpp"
#undef true
#undef false
#include "IPhreeqc.h"
#include "CVar.hxx"
#include <iostream>
#include <cmath>
@ -25,7 +28,10 @@ bool FileExists(const char *szPathName);
VRESULT SOLUTION(double C, double Ca, double Na);
VRESULT EQUILIBRIUM_PHASES(const char* phase, double si, double amount);
VRESULT USER_PUNCH(const char* element, int max);
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on);
VRESULT SELECTED_OUTPUT(void);
VRESULT DUMP(void);
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on);
TestInterface::TestInterface()
@ -114,10 +120,10 @@ void TestInterface::TestLoadDatabaseString()
void TestInterface::TestLoadDatabaseMissingFile()
{
CPPUNIT_ASSERT_EQUAL((bool)false, ::FileExists("missing.file"));
CPPUNIT_ASSERT_EQUAL(1, ::LoadDatabase("missing.file"));
CPPUNIT_ASSERT_EQUAL(1, ::LoadDatabase("missing.file"));
CPPUNIT_ASSERT_EQUAL(1, ::LoadDatabase("missing.file"));
CPPUNIT_ASSERT_EQUAL(false, ::FileExists("missing.file"));
CPPUNIT_ASSERT_EQUAL(1, ::LoadDatabase("missing.file"));
CPPUNIT_ASSERT_EQUAL(1, ::LoadDatabase("missing.file"));
CPPUNIT_ASSERT_EQUAL(1, ::LoadDatabase("missing.file"));
const char expected[] =
"ERROR: LoadDatabase: Unable to open:\"missing.file\".\n"
@ -175,6 +181,7 @@ void TestInterface::TestRun()
::SetErrorOn(files_on);
::SetLogOn(files_on);
::SetSelectedOutputOn(files_on);
::SetDumpOn(files_on);
CPPUNIT_ASSERT_EQUAL(0, ::Run());
}
@ -206,6 +213,7 @@ void TestInterface::TestRunWithErrors()
::SetErrorOn(files_on);
::SetLogOn(files_on);
::SetSelectedOutputOn(files_on);
::SetDumpOn(files_on);
CPPUNIT_ASSERT_EQUAL(1, ::Run());
const char expected[] =
@ -215,7 +223,7 @@ void TestInterface::TestRunWithErrors()
CPPUNIT_ASSERT_EQUAL( std::string(expected), std::string(err) );
CPPUNIT_ASSERT_EQUAL((bool)true, ::FileExists(dump_file) );
CPPUNIT_ASSERT_EQUAL(true, ::FileExists(dump_file) );
CPPUNIT_ASSERT(::DeleteFile(dump_file));
}
@ -238,6 +246,7 @@ void TestInterface::TestRunFile()
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL(1, ::RunFile("conv_fail.in"));
const char expected[] =
@ -247,7 +256,7 @@ void TestInterface::TestRunFile()
CPPUNIT_ASSERT_EQUAL(std::string(expected), std::string(err));
CPPUNIT_ASSERT_EQUAL((bool)true, ::FileExists(dump_file));
CPPUNIT_ASSERT_EQUAL(true, ::FileExists(dump_file));
CPPUNIT_ASSERT(::DeleteFile(dump_file));
}
@ -264,9 +273,9 @@ void TestInterface::TestGetSelectedOutputRowCount()
::SetOutputOn(0);
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(1);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL(0, ::Run());
//// CPPUNIT_ASSERT_EQUAL(0, ::Run(1, 1, 1, 1));
CPPUNIT_ASSERT_EQUAL(3, ::GetSelectedOutputRowCount()); // rows + header
}
@ -282,10 +291,12 @@ void TestInterface::TestGetSelectedOutputValue()
CPPUNIT_ASSERT_EQUAL(VR_OK, SOLUTION(1.0, 1.0, 1.0));
CPPUNIT_ASSERT_EQUAL(VR_OK, EQUILIBRIUM_PHASES("calcite", 0.0, 0.010));
CPPUNIT_ASSERT_EQUAL(VR_OK, USER_PUNCH("Ca", max));
::SetOutputOn(0);
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL(0, ::Run());
/*
@ -873,53 +884,53 @@ EXPECTED selected.out:
void TestInterface::TestGetSelectedOutputColumnCount()
{
// COMMENT: {3/3/2010 4:57:53 PM} CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("llnl.dat"));
// COMMENT: {3/3/2010 4:57:53 PM} CPPUNIT_ASSERT_EQUAL( 0, ::GetSelectedOutputColumnCount() );
// COMMENT: {3/3/2010 4:57:53 PM} CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
// COMMENT: {3/3/2010 4:57:53 PM} CPPUNIT_ASSERT_EQUAL( VR_OK, EQUILIBRIUM_PHASES("calcite", 1.0, 1.0) );
// COMMENT: {3/3/2010 4:57:53 PM} CPPUNIT_ASSERT_EQUAL( VR_OK, USER_PUNCH("Ca", 10) );
// COMMENT: {3/3/2010 4:57:53 PM} CPPUNIT_ASSERT_EQUAL( 0, ::Run(0, 0, 0, 0) );
// COMMENT: {3/3/2010 4:57:53 PM} CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount() );
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("llnl.dat"));
CPPUNIT_ASSERT_EQUAL( 0, ::GetSelectedOutputColumnCount() );
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
CPPUNIT_ASSERT_EQUAL( VR_OK, EQUILIBRIUM_PHASES("calcite", 1.0, 1.0) );
CPPUNIT_ASSERT_EQUAL( VR_OK, USER_PUNCH("Ca", 10) );
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount() );
}
void TestInterface::TestAddError()
{
// COMMENT: {3/3/2010 4:58:00 PM} CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase("phreeqc.dat"));
// COMMENT: {3/3/2010 4:58:00 PM}
// COMMENT: {3/3/2010 4:58:00 PM} // make sure initialized to empty
// COMMENT: {3/3/2010 4:58:00 PM} //
// COMMENT: {3/3/2010 4:58:00 PM} const char* err = ::GetLastErrorString();
// COMMENT: {3/3/2010 4:58:00 PM} CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(err) );
// COMMENT: {3/3/2010 4:58:00 PM}
// COMMENT: {3/3/2010 4:58:00 PM} // make sure initialized to empty
// COMMENT: {3/3/2010 4:58:00 PM} //
// COMMENT: {3/3/2010 4:58:00 PM} const char *expected = "TESTING AddError\n";
// COMMENT: {3/3/2010 4:58:00 PM} CPPUNIT_ASSERT_EQUAL(1u, ::AddError(expected));
// COMMENT: {3/3/2010 4:58:00 PM}
// COMMENT: {3/3/2010 4:58:00 PM} // check 1
// COMMENT: {3/3/2010 4:58:00 PM} //
// COMMENT: {3/3/2010 4:58:00 PM} err = ::GetLastErrorString();
// COMMENT: {3/3/2010 4:58:00 PM} CPPUNIT_ASSERT_EQUAL( std::string(expected), std::string(err) );
// COMMENT: {3/3/2010 4:58:00 PM}
// COMMENT: {3/3/2010 4:58:00 PM} // check increment
// COMMENT: {3/3/2010 4:58:00 PM} //
// COMMENT: {3/3/2010 4:58:00 PM} const char *expected2 = "XXXXXX\n";
// COMMENT: {3/3/2010 4:58:00 PM} CPPUNIT_ASSERT_EQUAL(2u, ::AddError(expected2));
// COMMENT: {3/3/2010 4:58:00 PM}
// COMMENT: {3/3/2010 4:58:00 PM} // check concatenation
// COMMENT: {3/3/2010 4:58:00 PM} //
// COMMENT: {3/3/2010 4:58:00 PM} err = ::GetLastErrorString();
// COMMENT: {3/3/2010 4:58:00 PM} CPPUNIT_ASSERT_EQUAL( std::string(expected) + std::string(expected2), std::string(err) );
// COMMENT: {3/3/2010 4:58:00 PM}
// COMMENT: {3/3/2010 4:58:00 PM}
// COMMENT: {3/3/2010 4:58:00 PM} // clear errors
// COMMENT: {3/3/2010 4:58:00 PM} //
// COMMENT: {3/3/2010 4:58:00 PM} CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase("phreeqc.dat"));
// COMMENT: {3/3/2010 4:58:00 PM}
// COMMENT: {3/3/2010 4:58:00 PM} // make sure back to empty
// COMMENT: {3/3/2010 4:58:00 PM} //
// COMMENT: {3/3/2010 4:58:00 PM} err = ::GetLastErrorString();
// COMMENT: {3/3/2010 4:58:00 PM} CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(err) );
CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase("phreeqc.dat"));
// make sure initialized to empty
//
const char* err = ::GetLastErrorString();
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(err) );
// make sure initialized to empty
//
const char *expected = "TESTING AddError\n";
CPPUNIT_ASSERT_EQUAL(1u, ::AddError(expected));
// check 1
//
err = ::GetLastErrorString();
CPPUNIT_ASSERT_EQUAL( std::string(expected), std::string(err) );
// check increment
//
const char *expected2 = "XXXXXX\n";
CPPUNIT_ASSERT_EQUAL(2u, ::AddError(expected2));
// check concatenation
//
err = ::GetLastErrorString();
CPPUNIT_ASSERT_EQUAL( std::string(expected) + std::string(expected2), std::string(err) );
// clear errors
//
CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase("phreeqc.dat"));
// make sure back to empty
//
err = ::GetLastErrorString();
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(err) );
}
void TestInterface::TestAccumulateLine()
@ -944,6 +955,7 @@ void TestInterface::TestRunNoDatabaseLoaded()
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 1, ::Run() );
const char expected[] =
@ -961,6 +973,7 @@ void TestInterface::TestRunFileNoDatabaseLoaded()
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 1, ::RunFile("dummy") );
const char expected[] =
@ -971,7 +984,6 @@ void TestInterface::TestRunFileNoDatabaseLoaded()
CPPUNIT_ASSERT_EQUAL( std::string(expected), std::string(err) );
}
void TestInterface::TestCase1()
{
// Case 1 (see do_run)
@ -985,13 +997,16 @@ void TestInterface::TestCase1()
{
CPPUNIT_ASSERT(::DeleteFile("selected.out"));
}
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
// clear all flags
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("phreeqc.dat") );
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("phreeqc.dat") );
// COMMENT: {3/4/2010 6:28:53 PM} CPPUNIT_ASSERT_EQUAL( FALSE, punch.in);
// COMMENT: {3/4/2010 6:28:53 PM} CPPUNIT_ASSERT_EQUAL( TRUE, pr.punch);
CPPUNIT_ASSERT_EQUAL( FALSE, IPhreeqc::LibraryInstance()->punch.in);
CPPUNIT_ASSERT_EQUAL( TRUE, IPhreeqc::LibraryInstance()->pr.punch);
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
CPPUNIT_ASSERT_EQUAL( VR_OK, USER_PUNCH("Ca", 10) );
@ -999,8 +1014,9 @@ void TestInterface::TestCase1()
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(1);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( (bool)true, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount() );
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
@ -1008,8 +1024,9 @@ void TestInterface::TestCase1()
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(1);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( (bool)true, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount() );
}
@ -1031,13 +1048,15 @@ void TestInterface::TestCase2()
{
::DeleteFile("case2.punch");
}
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("case2.punch") );
// clear all flags
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("phreeqc.dat") );
// COMMENT: {3/4/2010 6:29:02 PM} CPPUNIT_ASSERT_EQUAL( FALSE, punch.in);
// COMMENT: {3/4/2010 6:29:02 PM} CPPUNIT_ASSERT_EQUAL( TRUE, pr.punch);
CPPUNIT_ASSERT_EQUAL( FALSE, IPhreeqc::LibraryInstance()->punch.in);
CPPUNIT_ASSERT_EQUAL( TRUE, IPhreeqc::LibraryInstance()->pr.punch);
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
CPPUNIT_ASSERT_EQUAL( VR_OK, USER_PUNCH("Ca", 10) );
@ -1046,9 +1065,10 @@ void TestInterface::TestCase2()
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(1);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( (bool)true, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount() );
@ -1062,25 +1082,26 @@ void TestInterface::TestCase2()
{
::DeleteFile("case2.punch");
}
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
CPPUNIT_ASSERT_EQUAL( VR_OK, USER_PUNCH("Ca", 10) );
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
CPPUNIT_ASSERT_EQUAL( VR_OK, USER_PUNCH("Ca", 10) );
::SetOutputOn(0);
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(1);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( (bool)true, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount() );
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount() );
if (::FileExists("case2.punch"))
{
::DeleteFile("case2.punch");
}
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("case2.punch") );
}
void TestInterface::TestPrintSelectedOutputFalse()
@ -1091,7 +1112,7 @@ void TestInterface::TestPrintSelectedOutputFalse()
{
::DeleteFile("selected.out");
}
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("phreeqc.dat") );
@ -1099,15 +1120,9 @@ void TestInterface::TestPrintSelectedOutputFalse()
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
// add selected output block
{
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
CPPUNIT_ASSERT_EQUAL( VR_OK, ::AccumulateLine(oss.str().c_str()) );
}
CPPUNIT_ASSERT_EQUAL( VR_OK, SELECTED_OUTPUT() );
// add selected output block
// turn off selected output
CPPUNIT_ASSERT_EQUAL( VR_OK, ::AccumulateLine("PRINT; -selected_output false \n") );
// run
@ -1115,6 +1130,7 @@ void TestInterface::TestPrintSelectedOutputFalse()
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(1);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( 0, ::GetSelectedOutputColumnCount() );
@ -1128,19 +1144,14 @@ void TestInterface::TestPrintSelectedOutputFalse()
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
// add selected output block
{
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
CPPUNIT_ASSERT_EQUAL( VR_OK, ::AccumulateLine(oss.str().c_str()) );
}
CPPUNIT_ASSERT_EQUAL( VR_OK, SELECTED_OUTPUT() );
// run
::SetOutputOn(0);
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(1);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( 11, ::GetSelectedOutputColumnCount() );
@ -1149,42 +1160,59 @@ void TestInterface::TestPrintSelectedOutputFalse()
void TestInterface::TestOutputOnOff()
{
int onoff[4];
int onoff[5];
onoff[0] = 1; // output_on
onoff[1] = 0; // error_on
onoff[2] = 0; // log_on
onoff[3] = 0; // selected_output_on
TestOnOff("phreeqc.out", onoff[0], onoff[1], onoff[2], onoff[3]);
onoff[4] = 0; // dump_on
TestOnOff("phreeqc.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestInterface::TestErrorOnOff()
{
int onoff[4];
int onoff[5];
onoff[0] = 0; // output_on
onoff[1] = 1; // error_on
onoff[2] = 0; // log_on
onoff[3] = 0; // selected_output_on
TestOnOff("phreeqc.err", onoff[0], onoff[1], onoff[2], onoff[3]);
onoff[4] = 0; // dump_on
TestOnOff("phreeqc.err", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestInterface::TestLogOnOff()
{
int onoff[4];
int onoff[5];
onoff[0] = 0; // output_on
onoff[1] = 0; // error_on
onoff[2] = 1; // log_on
onoff[3] = 0; // selected_output_on
TestOnOff("phreeqc.log", onoff[0], onoff[1], onoff[2], onoff[3]);
onoff[4] = 0; // dump_on
TestOnOff("phreeqc.log", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void
TestInterface::TestDumpOn()
{
int onoff[5];
onoff[0] = 0; // output_on
onoff[1] = 0; // error_on
onoff[2] = 0; // log_on
onoff[3] = 0; // selected_output_on
onoff[4] = 1; // dump_on
TestOnOff("dump.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestInterface::TestSelOutOnOff()
{
int onoff[4];
int onoff[5];
onoff[0] = 0; // output_on
onoff[1] = 0; // error_on
onoff[2] = 0; // log_on
onoff[3] = 1; // selected_output_on
TestOnOff("selected.out", onoff[0], onoff[1], onoff[2], onoff[3]);
onoff[4] = 0; // dump_on
TestOnOff("selected.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
VRESULT
@ -1245,6 +1273,28 @@ USER_PUNCH(const char* element, int max)
return ::AccumulateLine(oss.str().c_str());
}
VRESULT
SELECTED_OUTPUT(void)
{
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
return ::AccumulateLine(oss.str().c_str());
}
VRESULT
DUMP(void)
{
std::ostringstream oss;
oss << "DUMP" << "\n";
oss << "-solution 1" << "\n";
return ::AccumulateLine(oss.str().c_str());
}
#if defined(_WIN32) || defined(__CYGWIN32__)
bool FileExists(const char *szPathName)
{
@ -1280,17 +1330,17 @@ bool FileExists(const char *szPathName)
}
#endif
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on)
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on)
{
//const char *FILENAME = "phreeqc.out";
// remove punch files if they exists
// remove FILENAME if it exists
//
if (::FileExists(FILENAME))
{
::DeleteFile(FILENAME);
}
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists(FILENAME) );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists(FILENAME) );
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("phreeqc.dat") );
@ -1298,21 +1348,19 @@ void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, in
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
// add selected output block
{
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
CPPUNIT_ASSERT_EQUAL( VR_OK, ::AccumulateLine(oss.str().c_str()) );
}
CPPUNIT_ASSERT_EQUAL( VR_OK, SELECTED_OUTPUT() );
// add dump block
CPPUNIT_ASSERT_EQUAL( VR_OK, DUMP() );
// run all off
::SetOutputOn(0);
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists(FILENAME) );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists(FILENAME) );
@ -1322,21 +1370,19 @@ void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, in
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
// add selected output block
{
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
CPPUNIT_ASSERT_EQUAL( VR_OK, ::AccumulateLine(oss.str().c_str()) );
}
CPPUNIT_ASSERT_EQUAL( VR_OK, SELECTED_OUTPUT() );
// add dump block
CPPUNIT_ASSERT_EQUAL( VR_OK, DUMP() );
// run
::SetOutputOn(output_on);
::SetErrorOn(error_on);
::SetLogOn(log_on);
::SetSelectedOutputOn(selected_output_on);
::SetDumpOn(dump_on);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( (bool)true, ::FileExists(FILENAME) );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists(FILENAME) );
CPPUNIT_ASSERT( ::DeleteFile(FILENAME) );
@ -1347,21 +1393,19 @@ void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, in
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
// add selected output block
{
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
CPPUNIT_ASSERT_EQUAL( VR_OK, ::AccumulateLine(oss.str().c_str()) );
}
CPPUNIT_ASSERT_EQUAL( VR_OK, SELECTED_OUTPUT() );
// add dump block
CPPUNIT_ASSERT_EQUAL( VR_OK, DUMP() );
// run
::SetOutputOn(0);
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( (bool)false, ::FileExists(FILENAME) );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists(FILENAME) );
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("phreeqc.dat") );
@ -1369,21 +1413,19 @@ void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, in
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
// add selected output block
{
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
CPPUNIT_ASSERT_EQUAL( VR_OK, ::AccumulateLine(oss.str().c_str()) );
}
CPPUNIT_ASSERT_EQUAL( VR_OK, SELECTED_OUTPUT() );
// add dump block
CPPUNIT_ASSERT_EQUAL( VR_OK, DUMP() );
// run
::SetOutputOn(output_on);
::SetErrorOn(error_on);
::SetLogOn(log_on);
::SetSelectedOutputOn(selected_output_on);
::SetDumpOn(dump_on);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL( (bool)true, ::FileExists(FILENAME) );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists(FILENAME) );
CPPUNIT_ASSERT( ::DeleteFile(FILENAME) );
}
@ -1412,6 +1454,7 @@ TestInterface::TestLongHeadings()
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
CPPUNIT_ASSERT_EQUAL(2, ::GetSelectedOutputRowCount());
@ -1430,3 +1473,75 @@ TestInterface::TestLongHeadings()
CPPUNIT_ASSERT( ::GetSelectedOutputValue(1, 1, &v1) == VR_INVALIDCOL );
CPPUNIT_ASSERT( ::GetSelectedOutputValue(2, 0, &v1) == VR_INVALIDROW );
}
void
TestInterface::TestDatabaseKeyword()
{
CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase("phreeqc.dat"));
::SetOutputOn(0);
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
CPPUNIT_ASSERT_EQUAL(1, ::RunFile("dump"));
const char *expected =
"ERROR: Gas not found in PHASES data base, Amm(g).\n"
"ERROR: Calculations terminating due to input errors.\n"
"Stopping.\n";
const char* err = ::GetLastErrorString();
CPPUNIT_ASSERT_EQUAL(std::string(expected), std::string(err));
}
void
TestInterface::TestDumpString()
{
CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase("phreeqc.dat"));
// add solution block
CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) );
// add dump block
CPPUNIT_ASSERT_EQUAL( VR_OK, DUMP() );
// run
::SetOutputOn(0);
::SetErrorOn(0);
::SetLogOn(0);
::SetSelectedOutputOn(0);
::SetDumpOn(0);
::SetDumpStringOn(1);
CPPUNIT_ASSERT_EQUAL( 0, ::Run() );
const char *expected =
"SOLUTION_RAW 1 \n"
" -temp 25\n"
" -total_h 111.0132593403\n"
" -total_o 55.509043478605\n"
" -cb 0.0021723831003929\n"
" -totals\n"
" C(4) 0.0010000000000376\n"
" Ca 0.001000000004331\n"
" H(0) 1.4149476909313e-025\n"
" Na 0.001\n"
" -Isotopes\n"
" -pH 7\n"
" -pe 4\n"
" -mu 0.0028961089894362\n"
" -ah2o 0.99994915105857\n"
" -mass_water 1\n"
" -total_alkalinity 0.00082761690826911\n"
" -activities\n"
" C(-4) -67.370522674574\n"
" C(4) -6.4415889265024\n"
" Ca -3.1040445240857\n"
" E -4\n"
" H(0) -25.15\n"
" Na -3.0255625287599\n"
" O(0) -42.080044167952\n"
" -gammas\n";
const char* dump_str = ::GetDumpString();
CPPUNIT_ASSERT_EQUAL(std::string(expected), std::string(dump_str));
}

View File

@ -33,6 +33,9 @@ class TestInterface :
CPPUNIT_TEST( TestLogOnOff );
CPPUNIT_TEST( TestSelOutOnOff );
CPPUNIT_TEST( TestLongHeadings );
CPPUNIT_TEST( TestDatabaseKeyword );
CPPUNIT_TEST( TestDumpOn );
CPPUNIT_TEST( TestDumpString );
CPPUNIT_TEST_SUITE_END();
@ -65,6 +68,9 @@ public:
void TestLogOnOff();
void TestSelOutOnOff();
void TestLongHeadings();
void TestDatabaseKeyword();
void TestDumpOn();
void TestDumpString();
};

41
unit/dump Normal file
View File

@ -0,0 +1,41 @@
database ../database/Amm.dat
solution 0
units mol/kgw
-water 0.4
pH 7 charge
Na 1
solution 101
units mol/kgw
-water 0.2
pH 7 charge
solution 1-100
units mol/kgw
pH 7 charge
-water 0.2
Amm 1
GAS_PHASE 1-100
-fixed_volume
-volume 1
-temperature 30
Amm(g) 0.1
N2(g) 0.9
#---------------- OUTPUT and TRANSPORT ----------------#
transport
-cells 100
-shifts 100
-lengths 0.1
-time_step 0.1
-flow_direction diffusion
-bc 1 1
-dump dump.phrq
-dump_frequency 10
-dump_restart 0
-print_frequency 50
end