git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4227 1feff8c3-07ed-0310-ac33-dd36852eb9cd

This commit is contained in:
Scott R Charlton 2010-04-08 00:26:48 +00:00
parent 33c23851e6
commit 564ee782ad
13 changed files with 254 additions and 20 deletions

View File

@ -1970,6 +1970,10 @@
RelativePath="src\ErrorReporter.hxx"
>
</File>
<File
RelativePath=".\src\fwrap.h"
>
</File>
<File
RelativePath="include\IPhreeqc.f90.inc"
>

View File

@ -198,6 +198,23 @@
END INTERFACE
INTERFACE
FUNCTION GetWarningLineCount(ID)
INTEGER(KIND=4) :: ID
INTEGER(KIND=4) :: GetWarningLineCount
END FUNCTION GetWarningLineCount
END INTERFACE
INTERFACE
SUBROUTINE GetWarningLine(ID,N,LINE)
INTEGER(KIND=4) :: ID
INTEGER(KIND=4) :: N
CHARACTER(LEN=*) :: LINE
END SUBROUTINE
END INTERFACE
INTERFACE
FUNCTION GetComponentCount(ID)
INTEGER(KIND=4) :: ID

View File

@ -31,13 +31,6 @@ extern "C" {
*/
int AddError(int id, const char* error_msg);
/**
* TODO
* @internal
*/
// TODO void ClearErrors(void);
int CreateIPhreeqc(void);
IPQ_RESULT DestroyIPhreeqc(int id);
@ -105,10 +98,11 @@ extern "C" {
*/
void OutputLastError(int id);
void OutputLastWarning(int id);
const char* GetLastErrorString(int id);
// TODO const char* GetLastWarningString(void);
const char* GetLastWarningString(int id);
const char* GetDumpString(int id);
@ -571,6 +565,38 @@ int GetErrorLineCount(int id);
*/
const char* GetErrorLine(int id, int n);
/**
* TODO
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* FUNCTION GetErrorLineCount
* INTEGER :: GetErrorLineCount
* END FUNCTION GetErrorLineCount
* </PRE>
* </CODE>
* @endhtmlonly
*/
int GetWarningLineCount(int id);
/**
* 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* GetWarningLine(int id, int n);
#if defined(__cplusplus)
}

View File

@ -45,6 +45,7 @@ public:
VRESULT GetSelectedOutputValue(int row, int col, VAR* pVAR);
void OutputLastError(void);
void OutputLastWarning(void);
void OutputLines(void);
const std::string& GetAccumulatedLines(void);
@ -57,6 +58,9 @@ public:
int GetErrorLineCount(void)const;
const char* GetErrorLine(int n);
int GetWarningLineCount(void)const;
const char* GetWarningLine(int n);
std::list< std::string > ListComponents(void);
size_t GetComponentCount(void);
const char* GetComponent(int n);

View File

@ -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<std::ostringstream>*)this->ErrorReporter)->GetOS()->str();
this->ErrorLines.clear();
std::istringstream iss(this->LastErrorString);
std::string line;
while (std::getline(iss, line))
this->LastErrorString = ((CErrorReporter<std::ostringstream>*)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<std::ostringstream>*)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);
}
}
}

View File

@ -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<size_t, IPhreeqc*> IPhreeqcLib::Instances;
size_t IPhreeqcLib::InstancesIndex = 0;

View File

@ -15,7 +15,6 @@
#include <vector>
#include "CVar.hxx"
// TODO: templatize
class CSelectedOutput
{
public:

View File

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

View File

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

View File

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

View File

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

View File

@ -1650,13 +1650,23 @@ void TestIPhreeqcLib::TestDatabaseKeyword()
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( 1, ::RunFile(n, "dump"));
const char *expected =
const char *exp_errs =
"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(n);
CPPUNIT_ASSERT_EQUAL(std::string(expected), std::string(err));
CPPUNIT_ASSERT_EQUAL(std::string(exp_errs), std::string(err));
const char *exp_warn =
"WARNING: DATABASE keyword is ignored by IPhreeqc.\n"
"WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 100.\n"
"WARNING: No dispersivities were read; disp = 0 assumed.\n"
"WARNING: Could not find element in database, Amm.\n"
" Concentration is set to zero.\n";
const char* warn = ::GetLastWarningString(n);
CPPUNIT_ASSERT_EQUAL(std::string(exp_warn), std::string(warn));
if (n >= 0)
{
@ -1944,3 +1954,52 @@ void TestIPhreeqcLib::TestGetComponent(void)
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
}
}
void TestIPhreeqcLib::TestGetErrorLine(void)
{
int n = ::CreateIPhreeqc();
CPPUNIT_ASSERT(n >= 0);
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat") );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetErrorOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetLogOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( 1, ::RunFile(n, "dump") );
CPPUNIT_ASSERT_EQUAL( 3, ::GetErrorLineCount(n) );
CPPUNIT_ASSERT_EQUAL( std::string("ERROR: Gas not found in PHASES data base, Amm(g)."), std::string(::GetErrorLine(n, 0)) );
CPPUNIT_ASSERT_EQUAL( std::string("ERROR: Calculations terminating due to input errors."), std::string(::GetErrorLine(n, 1)) );
CPPUNIT_ASSERT_EQUAL( std::string("Stopping."), std::string(::GetErrorLine(n, 2)) );
if (n >= 0)
{
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
}
}
void TestIPhreeqcLib::TestGetWarningLine(void)
{
int n = ::CreateIPhreeqc();
CPPUNIT_ASSERT(n >= 0);
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat") );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetErrorOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetLogOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( 1, ::RunFile(n, "dump") );
CPPUNIT_ASSERT_EQUAL( 5, ::GetWarningLineCount(n) );
CPPUNIT_ASSERT_EQUAL( std::string("WARNING: DATABASE keyword is ignored by IPhreeqc."), std::string(::GetWarningLine(n, 0)) );
CPPUNIT_ASSERT_EQUAL( std::string("WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 100."), std::string(::GetWarningLine(n, 1)) );
CPPUNIT_ASSERT_EQUAL( std::string("WARNING: No dispersivities were read; disp = 0 assumed."), std::string(::GetWarningLine(n, 2)) );
CPPUNIT_ASSERT_EQUAL( std::string("WARNING: Could not find element in database, Amm."), std::string(::GetWarningLine(n, 3)) );
CPPUNIT_ASSERT_EQUAL( std::string(" Concentration is set to zero."), std::string(::GetWarningLine(n, 4)) );
if (n >= 0)
{
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
}
}

View File

@ -41,6 +41,8 @@ class TestIPhreeqcLib : public CppUnit::TestFixture
CPPUNIT_TEST( TestGetDumpLine );
CPPUNIT_TEST( TestGetComponentCount );
CPPUNIT_TEST( TestGetComponent );
CPPUNIT_TEST( TestGetErrorLine );
CPPUNIT_TEST( TestGetWarningLine );
CPPUNIT_TEST_SUITE_END();
public:
@ -81,6 +83,8 @@ public:
void TestGetDumpLine(void);
void TestGetComponentCount(void);
void TestGetComponent(void);
void TestGetErrorLine(void);
void TestGetWarningLine(void);
protected:
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on);