diff --git a/include/IPhreeqc.f.inc b/include/IPhreeqc.f.inc index 7aa7b9d5..40c922e0 100644 --- a/include/IPhreeqc.f.inc +++ b/include/IPhreeqc.f.inc @@ -74,5 +74,6 @@ C INTEGER(KIND=4) SetDumpStringOn INTEGER(KIND=4) SetErrorFileOn INTEGER(KIND=4) SetLogFileOn + INTEGER(KIND=4) SetOutputFileName INTEGER(KIND=4) SetOutputFileOn INTEGER(KIND=4) SetSelectedOutputFileOn diff --git a/include/IPhreeqc.f90.inc b/include/IPhreeqc.f90.inc index 4d10f3f7..336f5e9b 100644 --- a/include/IPhreeqc.f90.inc +++ b/include/IPhreeqc.f90.inc @@ -156,6 +156,14 @@ END INTERFACE + INTERFACE + SUBROUTINE GetOutputFileName(ID,FNAME) + INTEGER(KIND=4), INTENT(IN) :: ID + CHARACTER(LEN=*), INTENT(OUT) :: FNAME + END SUBROUTINE GetOutputFileName + END INTERFACE + + INTERFACE FUNCTION GetOutputFileOn(ID) INTEGER(KIND=4), INTENT(IN) :: ID @@ -328,6 +336,15 @@ END INTERFACE + INTERFACE + FUNCTION SetOutputFileName(ID,FNAME) + INTEGER(KIND=4), INTENT(IN) :: ID + CHARACTER(LEN=*), INTENT(IN) :: FNAME + INTEGER(KIND=4) :: SetOutputFileName + END FUNCTION SetOutputFileName + END INTERFACE + + INTERFACE FUNCTION SetOutputFileOn(ID,OUT_ON) INTEGER(KIND=4), INTENT(IN) :: ID diff --git a/include/IPhreeqc.h b/include/IPhreeqc.h index 8b293189..601614cd 100644 --- a/include/IPhreeqc.h +++ b/include/IPhreeqc.h @@ -240,7 +240,7 @@ extern "C" { * @par Fortran90 Example: * see \ref GetComponent_f90 "GetComponent" */ - IPQ_DLL_EXPORT int GetComponentCount(int id); + IPQ_DLL_EXPORT int GetComponentCount(int id); /** @@ -261,7 +261,7 @@ extern "C" { * * @endhtmlonly */ - IPQ_DLL_EXPORT const char* GetDumpFileName(int id); + IPQ_DLL_EXPORT const char* GetDumpFileName(int id); /** @@ -281,7 +281,7 @@ extern "C" { * * @endhtmlonly */ - IPQ_DLL_EXPORT int GetDumpFileOn(int id); + IPQ_DLL_EXPORT int GetDumpFileOn(int id); /** @@ -468,6 +468,25 @@ extern "C" { */ IPQ_DLL_EXPORT int GetLogFileOn(int id); +/** + * Retrieves the name of the output file. The default name is phreeqc.id.out. + * @param id The instance id returned from \ref CreateIPhreeqc. + * @return filename The name of the output file. + * @see GetOutputFileOn, GetOutputString, GetOutputStringOn, GetOutputStringLine, GetOutputStringLineCount, SetOutputFileName, SetOutputFileOn, SetOutputStringOn + * @par Fortran90 Interface: + * @htmlonly + * + *
+ *  SUBROUTINE GetOutputFileName(ID,FILENAME)
+ *    INTEGER(KIND=4),   INTENT(IN)   :: ID
+ *    CHARACTER(LEN=*),  INTENT(OUT)  :: FILENAME
+ *  END SUBROUTINE GetOutputFileName
+ *  
+ *
+ * @endhtmlonly + */ + IPQ_DLL_EXPORT const char* GetOutputFileName(int id); + /** * Retrieves the current value of the output file switch. @@ -995,7 +1014,9 @@ Headings * Sets the name of the dump file. This file name is used if not specified within DUMP input. * The default value is dump.id.out. * @param id The instance id returned from \ref CreateIPhreeqc. - * @return filename The name of the file to write DUMP output to. + * @param filename The name of the file to write DUMP output to. + * @retval IPQ_OK Success. + * @retval IPQ_BADINSTANCE The given id is invalid. * @see GetDumpFileName, GetDumpFileOn, GetDumpString, GetDumpStringOn, GetDumpStringLine, GetDumpStringLineCount, SetDumpFileOn, SetDumpStringOn * @par Fortran90 Interface: * @htmlonly @@ -1004,7 +1025,7 @@ Headings * FUNCTION SetDumpFileName(ID,FILENAME) * INTEGER(KIND=4), INTENT(IN) :: ID * CHARACTER(LEN=*), INTENT(OUT) :: FILENAME - * INTEGER(KIND=4) :: SetDumpFileOn + * INTEGER(KIND=4) :: SetDumpFileName * END FUNCTION SetDumpFileName * * @@ -1121,6 +1142,28 @@ Headings */ IPQ_DLL_EXPORT IPQ_RESULT SetLogFileOn(int id, int log_on); +/** + * Sets the name of the output file. This file name is used if not specified within DUMP input. + * The default value is phreeqc.id.out. + * @param id The instance id returned from \ref CreateIPhreeqc. + * @param filename The name of the phreeqc output file. + * @retval IPQ_OK Success. + * @retval IPQ_BADINSTANCE The given id is invalid. + * @see GetOutputFileName, GetOutputFileOn, GetOutputString, GetOutputStringOn, GetOutputStringLine, GetOutputStringLineCount, SetOutputFileOn, SetOutputStringOn + * @par Fortran90 Interface: + * @htmlonly + * + *
+ *  FUNCTION SetOutputFileName(ID,FILENAME)
+ *    INTEGER(KIND=4),   INTENT(IN)   :: ID
+ *    CHARACTER(LEN=*),  INTENT(OUT)  :: FILENAME
+ *    INTEGER(KIND=4)                 :: SetOutputFileName
+ *  END FUNCTION SetOutputFileName
+ *  
+ *
+ * @endhtmlonly + */ + IPQ_DLL_EXPORT IPQ_RESULT SetOutputFileName(int id, const char* filename); /** * Sets the output file switch on or off. This switch controls whether or not phreeqc diff --git a/src/IPhreeqcLib.cpp b/src/IPhreeqcLib.cpp index ddadf2e2..7121ff0f 100644 --- a/src/IPhreeqcLib.cpp +++ b/src/IPhreeqcLib.cpp @@ -258,6 +258,18 @@ GetLogFileOn(int id) return IPQ_BADINSTANCE; } +const char* +GetOutputFileName(int id) +{ + static const char empty[] = ""; + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + return IPhreeqcPtr->GetOutputFileName(); + } + return empty; +} + int GetOutputFileOn(int id) { @@ -526,6 +538,18 @@ SetLogFileOn(int id, int value) return IPQ_BADINSTANCE; } +IPQ_RESULT +SetOutputFileName(int id, const char* filename) +{ + IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id); + if (IPhreeqcPtr) + { + IPhreeqcPtr->SetOutputFileName(filename); + return IPQ_OK; + } + return IPQ_BADINSTANCE; +} + IPQ_RESULT SetOutputFileOn(int id, int value) { diff --git a/src/fwrap.cpp b/src/fwrap.cpp index 36e38ac7..08959f19 100644 --- a/src/fwrap.cpp +++ b/src/fwrap.cpp @@ -182,6 +182,12 @@ GetLogFileOnF(int *id) return ::GetLogFileOn(*id); } +void +GetOutputFileNameF(int *id, char* fname, unsigned int fname_length) +{ + padfstring(fname, ::GetOutputFileName(*id), fname_length); +} + int GetOutputFileOnF(int *id) { @@ -402,6 +408,23 @@ SetLogFileOnF(int *id, int* log_on) return ::SetLogFileOn(*id, *log_on); } +IPQ_RESULT +SetOutputFileNameF(int *id, char* fname, unsigned int fname_length) +{ + char* cinput; + + cinput = f2cstring(fname, fname_length); + if (!cinput) + { + ::AddError(*id, "SetOutputFileName: Out of memory.\n"); + return IPQ_OUTOFMEMORY; + } + + IPQ_RESULT n = ::SetOutputFileName(*id, cinput); + free(cinput); + return n; +} + IPQ_RESULT SetOutputFileOnF(int *id, int* output_on) { @@ -493,6 +516,10 @@ IPQ_DLL_EXPORT int __stdcall GETLOGFILEON(int *id) { return GetLogFileOnF(id); } +IPQ_DLL_EXPORT void __stdcall GETOUTPUTFILENAME(int *id, char *filename, unsigned int len) +{ + GetOutputFileNameF(id, filename, len); +} IPQ_DLL_EXPORT int __stdcall GETOUTPUTFILEON(int *id) { return GetOutputFileOnF(id); @@ -574,6 +601,10 @@ IPQ_DLL_EXPORT int __stdcall SETLOGFILEON(int *id, int *log_on) { return SetLogFileOnF(id, log_on); } +IPQ_DLL_EXPORT int __stdcall SETOUTPUTFILENAME(int *id, char *filename, unsigned int len) +{ + return SetOutputFileNameF(id, filename, len); +} IPQ_DLL_EXPORT int __stdcall SETOUTPUTFILEON(int *id, int *output_on) { return SetOutputFileOnF(id, output_on); diff --git a/src/fwrap.h b/src/fwrap.h index cd1f40b7..9ba40435 100644 --- a/src/fwrap.h +++ b/src/fwrap.h @@ -70,6 +70,7 @@ extern "C" { void GetErrorStringLineF(int *id, int* n, char* line, unsigned int line_length); int GetErrorFileOnF(int *id); int GetLogFileOnF(int *id); + void GetOutputFileNameF(int *id, char* filename, unsigned int filename_length); int GetOutputFileOnF(int *id); int GetSelectedOutputColumnCountF(int *id); int GetSelectedOutputFileOnF(int *id); @@ -90,6 +91,7 @@ extern "C" { IPQ_RESULT SetDumpStringOnF(int *id, int* dump_string_on); IPQ_RESULT SetErrorFileOnF(int *id, int* error_on); IPQ_RESULT SetLogFileOnF(int *id, int* log_on); + IPQ_RESULT SetOutputFileNameF(int *id, char* fname, unsigned int fname_length); IPQ_RESULT SetOutputFileOnF(int *id, int* output_on); IPQ_RESULT SetSelOutFileOnF(int *id, int* selected_output_on); diff --git a/src/fwrap2.cpp b/src/fwrap2.cpp index 1c740b3a..9aa2b29f 100644 --- a/src/fwrap2.cpp +++ b/src/fwrap2.cpp @@ -80,6 +80,10 @@ IPQ_DLL_EXPORT int GETLOGFILEON(int *id) { return GetLogFileOnF(id); } +IPQ_DLL_EXPORT void GETOUTPUTFILENAME(int *id, char *filename, unsigned int len) +{ + GetOutputFileNameF(id, filename, len); +} IPQ_DLL_EXPORT int GETOUTPUTFILEON(int *id) { return GetOutputFileOnF(id); @@ -160,6 +164,10 @@ IPQ_DLL_EXPORT int SETLOGFILEON(int *id, int *log_on) { return SetLogFileOnF(id, log_on); } +IPQ_DLL_EXPORT int SETOUTPUTFILENAME(int *id, char *filename, unsigned int len) +{ + return SetOutputFileNameF(id, filename, len); +} IPQ_DLL_EXPORT int SETOUTPUTFILEON(int *id, int *output_on) { return SetOutputFileOnF(id, output_on); diff --git a/src/fwrap3.cpp b/src/fwrap3.cpp index ae4b23fe..ed67d689 100644 --- a/src/fwrap3.cpp +++ b/src/fwrap3.cpp @@ -80,6 +80,10 @@ IPQ_DLL_EXPORT int getlogfileon_(int *id) { return GetLogFileOnF(id); } +IPQ_DLL_EXPORT void getoutputfilename_(int *id, char *filename, unsigned int len) +{ + GetOutputFileNameF(id, filename, len); +} IPQ_DLL_EXPORT int getoutputfileon_(int *id) { return GetOutputFileOnF(id); @@ -161,6 +165,10 @@ IPQ_DLL_EXPORT int setlogfileon_(int *id, int *log_on) { return SetLogFileOnF(id, log_on); } +IPQ_DLL_EXPORT int setoutputfilename_(int *id, char *filename, unsigned int len) +{ + return SetOutputFileNameF(id, filename, len); +} IPQ_DLL_EXPORT int setoutputfileon_(int *id, int *output_on) { return SetOutputFileOnF(id, output_on); diff --git a/tests/test_f.f b/tests/test_f.f index 12e8dfc5..609a87a5 100644 --- a/tests/test_f.f +++ b/tests/test_f.f @@ -40,6 +40,9 @@ EXTERNAL GetDumpFileName EXTERNAL SetDumpFileName + + EXTERNAL GetOutputFileName + EXTERNAL SetOutputFileName id = CreateIPhreeqc() IF (id.LT.0) THEN @@ -83,6 +86,13 @@ C Output RETURN END IF +C Output filename + IF (TestGetSetName(id,GetOutputFileName,SetOutputFileName) + & .NE.0) THEN + F_MAIN = EXIT_FAILURE + RETURN + END IF + C Selected output IF (TestGetSet(id,GetSelectedOutputFileOn,SetSelectedOutputFileOn) & .NE.0) THEN diff --git a/tests/test_f90.f90 b/tests/test_f90.f90 index c8dd4f7b..fbe1e0be 100644 --- a/tests/test_f90.f90 +++ b/tests/test_f90.f90 @@ -71,6 +71,12 @@ FUNCTION F_MAIN() RETURN END IF + ! Output filename + IF (TestGetSetName(id,GetOutputFileName,SetOutputFileName).NE.0) THEN + F_MAIN = EXIT_FAILURE + RETURN + END IF + ! Selected output IF (TestGetSet(id,GetSelectedOutputFileOn,SetSelectedOutputFileOn).NE.0) THEN F_MAIN = EXIT_FAILURE diff --git a/unit/TestIPhreeqcLib.cpp b/unit/TestIPhreeqcLib.cpp index b024efca..1b2d7151 100644 --- a/unit/TestIPhreeqcLib.cpp +++ b/unit/TestIPhreeqcLib.cpp @@ -2437,3 +2437,265 @@ void TestIPhreeqcLib::TestSetDumpFileName(void) CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n)); } } + +void TestIPhreeqcLib::TestSetOutputFileName(void) +{ + char OUTPUT_FILENAME[80]; + sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); + if (::FileExists(OUTPUT_FILENAME)) + { + ::DeleteFile(OUTPUT_FILENAME); + } + + int n = ::CreateIPhreeqc(); + CPPUNIT_ASSERT(n >= 0); + + CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat")); + + // add solution block + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SOLUTION(n, 1.0, 1.0, 1.0) ); + + // add dump block + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::DUMP(n) ); + + // run + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputFileOn(n, 1) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetErrorFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetLogFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpStringOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputFileName(n, OUTPUT_FILENAME) ); + + CPPUNIT_ASSERT_EQUAL( std::string(OUTPUT_FILENAME), std::string(::GetOutputFileName(n)) ); + + + CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) ); + + CPPUNIT_ASSERT_EQUAL( true, ::FileExists(OUTPUT_FILENAME) ); + + std::string lines[101]; + std::ifstream ifs(OUTPUT_FILENAME); + + size_t i = 0; + while (i < sizeof(lines)/sizeof(lines[0]) && std::getline(ifs, lines[i])) + { + ++i; + } + + CPPUNIT_ASSERT_EQUAL( 98u, i ); + + int line = 0; +#if defined(_MSC_VER) + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Reading input data for simulation 1."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" SOLUTION 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" C 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Ca 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Na 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" DUMP"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" -solution 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-------------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Beginning of initial solution calculations."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-------------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Initial solution 1. "), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-----------------------------Solution composition------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Elements Molality Moles"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" C 1.000e-003 1.000e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Ca 1.000e-003 1.000e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Na 1.000e-003 1.000e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("----------------------------Description of solution----------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" pH = 7.000 "), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" pe = 4.000 "), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Activity of water = 1.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Ionic strength = 2.896e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Mass of water (kg) = 1.000e+000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Total alkalinity (eq/kg) = 8.276e-004"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Total CO2 (mol/kg) = 1.000e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Temperature (deg C) = 25.00"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Electrical balance (eq) = 2.172e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Percent error, 100*(Cat-|An|)/(Cat+|An|) = 57.04"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Iterations = 6"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Total H = 1.110133e+002"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Total O = 5.550904e+001"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("----------------------------Distribution of species----------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Log Log Log "), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Species Molality Activity Molality Activity Gamma"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" OH- 1.062e-007 1.001e-007 -6.974 -7.000 -0.026"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H+ 1.056e-007 1.000e-007 -6.976 -7.000 -0.024"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H2O 5.551e+001 9.999e-001 1.744 -0.000 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("C(-4) 0.000e+000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CH4 0.000e+000 0.000e+000 -67.371 -67.371 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("C(4) 1.000e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" HCO3- 8.171e-004 7.714e-004 -3.088 -3.113 -0.025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CO2 1.733e-004 1.734e-004 -3.761 -3.761 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaHCO3+ 8.204e-006 7.745e-006 -5.086 -5.111 -0.025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaCO3 4.779e-007 4.782e-007 -6.321 -6.320 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CO3-2 4.555e-007 3.618e-007 -6.342 -6.442 -0.100"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaHCO3 4.087e-007 4.090e-007 -6.389 -6.388 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaCO3- 6.736e-009 6.351e-009 -8.172 -8.197 -0.026"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Ca 1.000e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Ca+2 9.913e-004 7.870e-004 -3.004 -3.104 -0.100"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaHCO3+ 8.204e-006 7.745e-006 -5.086 -5.111 -0.025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaCO3 4.779e-007 4.782e-007 -6.321 -6.320 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaOH+ 1.385e-009 1.306e-009 -8.859 -8.884 -0.026"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("H(0) 1.415e-025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H2 7.075e-026 7.079e-026 -25.150 -25.150 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Na 1.000e-003"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Na+ 9.996e-004 9.428e-004 -3.000 -3.026 -0.025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaHCO3 4.087e-007 4.090e-007 -6.389 -6.388 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaCO3- 6.736e-009 6.351e-009 -8.172 -8.197 -0.026"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaOH 6.225e-011 6.229e-011 -10.206 -10.206 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("O(0) 0.000e+000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" O2 0.000e+000 0.000e+000 -42.080 -42.080 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------Saturation indices-------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Phase SI log IAP log K(298 K, 1 atm)"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Aragonite -1.21 -9.55 -8.34 CaCO3"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Calcite -1.07 -9.55 -8.48 CaCO3"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CH4(g) -64.51 -67.37 -2.86 CH4"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CO2(g) -2.29 -3.76 -1.47 CO2"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H2(g) -22.00 -25.15 -3.15 H2"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H2O(g) -1.51 -0.00 1.51 H2O"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" O2(g) -39.12 -42.08 -2.96 O2"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("End of simulation."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Reading input data for simulation 2."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-----------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("End of run."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-----------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); +#endif + +#if defined(__GNUC__) + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Reading input data for simulation 1."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" SOLUTION 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" C 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Ca 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Na 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" DUMP"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" -solution 1"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-------------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Beginning of initial solution calculations."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-------------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Initial solution 1. "), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-----------------------------Solution composition------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Elements Molality Moles"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" C 1.000e-03 1.000e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Ca 1.000e-03 1.000e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Na 1.000e-03 1.000e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("----------------------------Description of solution----------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" pH = 7.000 "), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" pe = 4.000 "), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Activity of water = 1.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Ionic strength = 2.896e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Mass of water (kg) = 1.000e+00"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Total alkalinity (eq/kg) = 8.276e-04"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Total CO2 (mol/kg) = 1.000e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Temperature (deg C) = 25.00"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Electrical balance (eq) = 2.172e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Percent error, 100*(Cat-|An|)/(Cat+|An|) = 57.04"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Iterations = 6"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Total H = 1.110133e+02"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Total O = 5.550904e+01"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("----------------------------Distribution of species----------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Log Log Log "), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Species Molality Activity Molality Activity Gamma"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" OH- 1.062e-07 1.001e-07 -6.974 -7.000 -0.026"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H+ 1.056e-07 1.000e-07 -6.976 -7.000 -0.024"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("C(-4) 0.000e+00"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CH4 0.000e+00 0.000e+00 -67.371 -67.371 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("C(4) 1.000e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" HCO3- 8.171e-04 7.714e-04 -3.088 -3.113 -0.025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CO2 1.733e-04 1.734e-04 -3.761 -3.761 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaHCO3+ 8.204e-06 7.745e-06 -5.086 -5.111 -0.025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaCO3 4.779e-07 4.782e-07 -6.321 -6.320 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CO3-2 4.555e-07 3.618e-07 -6.342 -6.442 -0.100"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaHCO3 4.087e-07 4.090e-07 -6.389 -6.388 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaCO3- 6.736e-09 6.351e-09 -8.172 -8.197 -0.026"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Ca 1.000e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Ca+2 9.913e-04 7.870e-04 -3.004 -3.104 -0.100"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaHCO3+ 8.204e-06 7.745e-06 -5.086 -5.111 -0.025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaCO3 4.779e-07 4.782e-07 -6.321 -6.320 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CaOH+ 1.385e-09 1.306e-09 -8.859 -8.884 -0.026"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("H(0) 1.415e-25"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H2 7.075e-26 7.079e-26 -25.150 -25.150 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Na 1.000e-03"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Na+ 9.996e-04 9.428e-04 -3.000 -3.026 -0.025"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaHCO3 4.087e-07 4.090e-07 -6.389 -6.388 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaCO3- 6.736e-09 6.351e-09 -8.172 -8.197 -0.026"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" NaOH 6.225e-11 6.229e-11 -10.206 -10.206 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("O(0) 0.000e+00"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------Saturation indices-------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Phase SI log IAP log K(298 K, 1 atm)"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Aragonite -1.21 -9.55 -8.34 CaCO3"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" Calcite -1.07 -9.55 -8.48 CaCO3"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CH4(g) -64.51 -67.37 -2.86 CH4"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" CO2(g) -2.29 -3.76 -1.47 CO2"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H2(g) -22.00 -25.15 -3.15 H2"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" H2O(g) -1.51 -0.00 1.51 H2O"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(" O2(g) -39.12 -42.08 -2.96 O2"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("End of simulation."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("Reading input data for simulation 2."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-----------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("End of run."), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string("-----------"), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); + CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] ); +#endif + + if (::FileExists(OUTPUT_FILENAME)) + { + ::DeleteFile(OUTPUT_FILENAME); + } +} diff --git a/unit/TestIPhreeqcLib.h b/unit/TestIPhreeqcLib.h index 94b19356..b17d7de3 100644 --- a/unit/TestIPhreeqcLib.h +++ b/unit/TestIPhreeqcLib.h @@ -47,6 +47,7 @@ class TestIPhreeqcLib : public CppUnit::TestFixture CPPUNIT_TEST( TestPitzer ); CPPUNIT_TEST( TestClearAccumulatedLines ); CPPUNIT_TEST( TestSetDumpFileName ); + CPPUNIT_TEST( TestSetOutputFileName ); CPPUNIT_TEST_SUITE_END(); public: @@ -94,6 +95,7 @@ public: void TestPitzer(void); void TestClearAccumulatedLines(void); void TestSetDumpFileName(void); + void TestSetOutputFileName(void); protected: void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on);