mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 00:28:23 +01:00
working on Dump/Output routines
git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/ErrorHandling@5951 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
f3c38358ce
commit
d31e8b0037
@ -802,6 +802,42 @@
|
||||
RelativePath=".\src\IPhreeqc.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\IPhreeqcF.f"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="ReleaseDll|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="DebugDll|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\IPhreeqcLib.cpp"
|
||||
>
|
||||
|
||||
@ -1,80 +1,80 @@
|
||||
PROGRAM example
|
||||
INCLUDE "IPhreeqc.f90.inc"
|
||||
INTEGER(KIND=4) :: id
|
||||
INTEGER(KIND=4) :: i
|
||||
CHARACTER(LEN=80) :: line
|
||||
|
||||
id = CreateIPhreeqc()
|
||||
IF (id.LT.0) THEN
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (SetDumpStringOn(id, .TRUE.).NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (LoadDatabase(id, "phreeqc.dat").NE.0) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "SOLUTION 1 Pure water").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "EQUILIBRIUM_PHASES 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, " Calcite 0 10").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "SAVE solution 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "SAVE equilibrium_phases 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "DUMP").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, " -solution 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, " -equilibrium_phases 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
WRITE(*,*) "Input:"
|
||||
CALL OutputAccumulatedLines(id)
|
||||
|
||||
IF (RunAccumulated(id).NE.0) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
WRITE(*,*) "Dump:"
|
||||
DO i=1,GetDumpStringLineCount(id)
|
||||
CALL GetDumpStringLine(id, i, line)
|
||||
WRITE(*,*) TRIM(line)
|
||||
END DO
|
||||
|
||||
IF (DestroyIPhreeqc(id).NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
END PROGRAM example
|
||||
PROGRAM example
|
||||
INCLUDE "IPhreeqc.f90.inc"
|
||||
INTEGER(KIND=4) :: id
|
||||
INTEGER(KIND=4) :: i
|
||||
CHARACTER(LEN=80) :: line
|
||||
|
||||
id = CreateIPhreeqc()
|
||||
IF (id.LT.0) THEN
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (SetOutputStringOn(id, .TRUE.).NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (LoadDatabase(id, "phreeqc.dat").NE.0) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "SOLUTION 1 Pure water").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "EQUILIBRIUM_PHASES 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, " Calcite 0 10").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "SAVE solution 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "SAVE equilibrium_phases 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, "DUMP").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, " -solution 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
IF (AccumulateLine(id, " -equilibrium_phases 1").NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
WRITE(*,*) "Input:"
|
||||
CALL OutputAccumulatedLines(id)
|
||||
|
||||
IF (RunAccumulated(id).NE.0) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
|
||||
WRITE(*,*) "Output:"
|
||||
DO i=1,GetOutputStringLineCount(id)
|
||||
CALL GetOutputStringLine(id, i, line)
|
||||
WRITE(*,*) TRIM(line)
|
||||
END DO
|
||||
|
||||
IF (DestroyIPhreeqc(id).NE.IPQ_OK) THEN
|
||||
CALL OutputErrorString(id)
|
||||
STOP
|
||||
END IF
|
||||
END PROGRAM example
|
||||
50
doc/examples/GetOutputString.c
Normal file
50
doc/examples/GetOutputString.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <IPhreeqc.h>
|
||||
|
||||
#define TRUE 1
|
||||
|
||||
const char input[] =
|
||||
"SOLUTION 1 Pure water \n"
|
||||
"EQUILIBRIUM_PHASES 1 \n"
|
||||
" Calcite 0 10 \n"
|
||||
"SAVE solution 1 \n"
|
||||
"SAVE equilibrium_phases 1 \n"
|
||||
"DUMP \n"
|
||||
" -solution 1 \n"
|
||||
" -equilibrium_phases 1\n";
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int id;
|
||||
|
||||
id = CreateIPhreeqc();
|
||||
if (id < 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (LoadDatabase(id, "phreeqc.dat") != 0) {
|
||||
OutputErrorString(id);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (SetDumpStringOn(id, TRUE) != IPQ_OK) {
|
||||
OutputErrorString(id);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (RunString(id, input) != 0) {
|
||||
OutputErrorString(id);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Output:\n");
|
||||
printf("%s\n", GetOutputString(id));
|
||||
|
||||
if (DestroyIPhreeqc(id) != IPQ_OK) {
|
||||
OutputErrorString(id);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@ -16,6 +16,7 @@ TARGETS = \
|
||||
CreateIPhreeqc \
|
||||
GetComponent \
|
||||
GetDumpString \
|
||||
GetOutputString \
|
||||
GetSelectedOutputValue \
|
||||
IPhreeqc
|
||||
|
||||
@ -24,6 +25,7 @@ F90_TARGETS = \
|
||||
F90CreateIPhreeqc \
|
||||
F90GetComponent \
|
||||
F90GetDumpStringLine \
|
||||
F90GetOutputStringLine \
|
||||
F90ClearAccumulatedLines \
|
||||
F90GetSelectedOutputValue
|
||||
|
||||
@ -42,6 +44,9 @@ GetComponent: GetComponent.lo $(IPHREEQC_LA)
|
||||
GetDumpString: GetDumpString.lo $(IPHREEQC_LA)
|
||||
$(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $< $(IPHREEQC_LA)
|
||||
|
||||
GetOutputString: GetOutputString.lo $(IPHREEQC_LA)
|
||||
$(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $< $(IPHREEQC_LA)
|
||||
|
||||
GetSelectedOutputValue: GetSelectedOutputValue.lo $(IPHREEQC_LA)
|
||||
$(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $< $(IPHREEQC_LA)
|
||||
|
||||
@ -61,6 +66,9 @@ F90GetComponent: F90GetComponent.lo $(IPHREEQC_LA)
|
||||
F90GetDumpStringLine: F90GetDumpStringLine.lo $(IPHREEQC_LA)
|
||||
$(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $< $(IPHREEQC_LA) $(FCLIBS)
|
||||
|
||||
F90GetOutputStringLine: F90GetOutputStringLine.lo $(IPHREEQC_LA)
|
||||
$(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $< $(IPHREEQC_LA) $(FCLIBS)
|
||||
|
||||
F90ClearAccumulatedLines: F90ClearAccumulatedLines.lo $(IPHREEQC_LA)
|
||||
$(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $< $(IPHREEQC_LA) $(FCLIBS)
|
||||
|
||||
@ -90,7 +98,8 @@ LO_FILES = \
|
||||
CreateIPhreeqc.lo \
|
||||
DestroyIPhreeqc.lo \
|
||||
GetComponent.lo \
|
||||
GetDumpString.lo\
|
||||
GetDumpString.lo \
|
||||
GetOutputString.lo \
|
||||
IPhreeqc.lo \
|
||||
GetSelectedOutputValue.lo
|
||||
|
||||
@ -101,6 +110,7 @@ F90_LO_FILES = \
|
||||
F90DestroyIPhreeqc.lo \
|
||||
F90GetComponent.lo \
|
||||
F90GetDumpStringLine.lo \
|
||||
F90GetOutputStringLine.lo \
|
||||
F90ClearAccumulatedLines.lo \
|
||||
F90GetSelectedOutputValue.lo
|
||||
|
||||
|
||||
@ -491,7 +491,7 @@ extern "C" {
|
||||
/**
|
||||
* Retrieves the current value of the output file switch.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @return Non-zero if output is written to the <B><I>phreeqc.out</I></B> file, 0 (zero) otherwise.
|
||||
* @return Non-zero if output is written to the <B><I>phreeqc.id.out</I></B> file, 0 (zero) otherwise.
|
||||
* @see SetOutputFileOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
@ -507,6 +507,91 @@ extern "C" {
|
||||
*/
|
||||
IPQ_DLL_EXPORT int GetOutputFileOn(int id);
|
||||
|
||||
/**
|
||||
* Retrieves the string buffer containing phreeqc output.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @return A null terminated string containing phreeqc output.
|
||||
* @pre \ref SetOutputStringOn must have been set to true (non-zero) in order to recieve phreeqc output.
|
||||
* @see GetOutputFileOn, GetOutputStringLine, GetOutputStringLineCount, SetOutputFileOn, GetOutputStringOn, SetOutputStringOn
|
||||
* @par Fortran90 Interface:
|
||||
* Not implemented. (see \ref GetOutputStringLineCount, \ref GetOutputStringLine)
|
||||
*
|
||||
* \anchor GetOutputString_c
|
||||
* @par C Example:
|
||||
* \include GetOutputString.c
|
||||
*/
|
||||
IPQ_DLL_EXPORT const char* GetOutputString(int id);
|
||||
|
||||
/**
|
||||
* Retrieves the given output line.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @param n The zero-based index of the line to retrieve.
|
||||
* @return A null terminated string containing the given line.
|
||||
* Returns an empty string if n is out of range.
|
||||
* @pre \ref SetOutputStringOn must have been set to true (non-zero).
|
||||
* @see GetOutputFileOn, GetOutputString, GetOutputStringLineCount, GetOutputStringOn, SetOutputFileOn, SetOutputStringOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
* (Note: N is one-based for the Fortran interface.)
|
||||
* <CODE>
|
||||
* <PRE>
|
||||
* SUBROUTINE GetOutputStringLine(ID,N,LINE)
|
||||
* INTEGER(KIND=4), INTENT(IN) :: ID
|
||||
* INTEGER(KIND=4), INTENT(IN) :: N
|
||||
* CHARACTER(LEN=*), INTENT(OUT) :: LINE
|
||||
* END SUBROUTINE GetOutputStringLine
|
||||
* </PRE>
|
||||
* </CODE>
|
||||
* @endhtmlonly
|
||||
*
|
||||
* \anchor GetOutputStringLine_f90
|
||||
* @par Fortran90 Example:
|
||||
* \include F90GetOutputStringLine.f90
|
||||
*/
|
||||
IPQ_DLL_EXPORT const char* GetOutputStringLine(int id, int n);
|
||||
|
||||
/**
|
||||
* Retrieves the number of lines in the current output string buffer.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @return The number of lines.
|
||||
* @pre \ref SetOutputStringOn must have been set to true (non-zero).
|
||||
* @see GetOutputFileOn, GetOutputString, GetOutputStringLine, GetOutputStringOn, SetOutputFileOn, SetOutputStringOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
* <CODE>
|
||||
* <PRE>
|
||||
* FUNCTION GetOutputStringLineCount(ID)
|
||||
* INTEGER(KIND=4), INTENT(IN) :: ID
|
||||
* INTEGER(KIND=4) :: GetOutputStringLineCount
|
||||
* END FUNCTION GetOutputStringLineCount
|
||||
* </PRE>
|
||||
* </CODE>
|
||||
* @endhtmlonly
|
||||
*
|
||||
* @par Fortran90 Example:
|
||||
* see \ref GetOutputStringLine_f90 "GetOutputStringLine"
|
||||
*/
|
||||
IPQ_DLL_EXPORT int GetOutputStringLineCount(int id);
|
||||
|
||||
/**
|
||||
* Retrieves the current value of the output string switch.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @return Non-zero if output is stored, 0 (zero) otherwise.
|
||||
* @see GetOutputFileOn, GetOutputString, GetOutputStringLine, GetOutputStringLineCount, SetOutputFileOn, SetOutputStringOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
* <CODE>
|
||||
* <PRE>
|
||||
* FUNCTION GetOutputStringOn(ID)
|
||||
* INTEGER(KIND=4), INTENT(IN) :: ID
|
||||
* LOGICAL(KIND=4) :: GetOutputStringOn
|
||||
* END FUNCTION GetOutputStringOn
|
||||
* </PRE>
|
||||
* </CODE>
|
||||
* @endhtmlonly
|
||||
*/
|
||||
IPQ_DLL_EXPORT int GetOutputStringOn(int id);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the number of columns in the selected-output buffer.
|
||||
@ -1189,6 +1274,37 @@ Headings
|
||||
*/
|
||||
IPQ_DLL_EXPORT IPQ_RESULT SetOutputFileOn(int id, int output_on);
|
||||
|
||||
/**
|
||||
* Sets the output string switch on or off. This switch controls whether or not the data normally sent
|
||||
* to the output file are stored in a buffer for retrieval. The initial setting after calling
|
||||
* \ref CreateIPhreeqc is off.
|
||||
* @param id The instance id returned from \ref CreateIPhreeqc.
|
||||
* @param dump_string_on If non-zero, captures the phreeqc output into a string buffer;
|
||||
* if zero, phreeqc output is not captured to a string buffer.
|
||||
* @retval IPQ_OK Success.
|
||||
* @retval IPQ_BADINSTANCE The given id is invalid.
|
||||
* @see GetOutputFileOn, GetOutputStringOn, GetOutputString, GetOutputStringLine, GetOutputStringLineCount, SetOutputFileOn
|
||||
* @par Fortran90 Interface:
|
||||
* @htmlonly
|
||||
* <CODE>
|
||||
* <PRE>
|
||||
* FUNCTION SetOutputStringOn(ID,OUTPUT_STRING_ON)
|
||||
* INTEGER(KIND=4), INTENT(IN) :: ID
|
||||
* LOGICAL(KIND=4), INTENT(IN) :: OUTPUT_STRING_ON
|
||||
* INTEGER(KIND=4) :: SetOutputStringOn
|
||||
* END FUNCTION SetOutputStringOn
|
||||
* </PRE>
|
||||
* </CODE>
|
||||
* @endhtmlonly
|
||||
*
|
||||
* @par C Example:
|
||||
* see \ref GetOutputString_c "GetOutputString"
|
||||
*
|
||||
* @par Fortran90 Example:
|
||||
* see \ref GetOutputStringLine_f90 "GetOutputStringLine"
|
||||
*/
|
||||
IPQ_DLL_EXPORT IPQ_RESULT SetOutputStringOn(int id, int value);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the selected-output file switch on or off. This switch controls whether or not phreeqc writes output to
|
||||
|
||||
@ -591,8 +591,11 @@ int IPhreeqc::RunString(const char* input)
|
||||
|
||||
void IPhreeqc::SetDumpFileName(const char *filename)
|
||||
{
|
||||
this->DumpFileName = filename;
|
||||
this->PhreeqcPtr->dump_info.Set_file_name(this->DumpFileName);
|
||||
if (filename && ::strlen(filename))
|
||||
{
|
||||
this->DumpFileName = filename;
|
||||
this->PhreeqcPtr->dump_info.Set_file_name(this->DumpFileName);
|
||||
}
|
||||
}
|
||||
|
||||
void IPhreeqc::SetDumpFileOn(bool bValue)
|
||||
@ -617,7 +620,10 @@ void IPhreeqc::SetLogFileOn(bool bValue)
|
||||
|
||||
void IPhreeqc::SetOutputFileName(const char *filename)
|
||||
{
|
||||
this->OutputFileName = filename;
|
||||
if (filename && ::strlen(filename))
|
||||
{
|
||||
this->OutputFileName = filename;
|
||||
}
|
||||
}
|
||||
|
||||
void IPhreeqc::SetOutputStringOn(bool bValue)
|
||||
|
||||
@ -66,6 +66,13 @@
|
||||
INTEGER(KIND=4) :: GetComponentCountF
|
||||
GetComponentCount = GetComponentCountF(ID)
|
||||
END FUNCTION GetComponentCount
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
SUBROUTINE GetDumpFileName(ID,FNAME)
|
||||
IMPLICIT NONE
|
||||
INTEGER(KIND=4) :: ID
|
||||
CHARACTER(LEN=*) :: FNAME
|
||||
CALL GetDumpFileNameF(ID,FNAME)
|
||||
END SUBROUTINE GetDumpFileName
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
FUNCTION GetDumpFileOn(ID)
|
||||
IMPLICIT NONE
|
||||
@ -154,6 +161,13 @@
|
||||
GetLogFileOn = .TRUE.
|
||||
ENDIF
|
||||
END FUNCTION GetLogFileOn
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
SUBROUTINE GetOutputFileName(ID,FNAME)
|
||||
IMPLICIT NONE
|
||||
INTEGER(KIND=4) :: ID
|
||||
CHARACTER(LEN=*) :: FNAME
|
||||
CALL GetOutputFileNameF(ID,FNAME)
|
||||
END SUBROUTINE GetOutputFileName
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
FUNCTION GetOutputFileOn(ID)
|
||||
IMPLICIT NONE
|
||||
@ -290,6 +304,14 @@
|
||||
INTEGER(KIND=4) :: RunStringF
|
||||
RunString = RunStringF(ID,INPUT)
|
||||
END FUNCTION RunString
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
FUNCTION SetDumpFileName(ID,FNAME)
|
||||
IMPLICIT NONE
|
||||
INTEGER(KIND=4) :: ID
|
||||
CHARACTER(LEN=*) :: FNAME
|
||||
INTEGER(KIND=4) :: SetDumpFileName
|
||||
SetDumpFileName = SetDumpFileNameF(ID,FNAME)
|
||||
END FUNCTION SetDumpFileName
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
FUNCTION SetDumpFileOn(ID,DUMP_ON)
|
||||
IMPLICIT NONE
|
||||
@ -326,6 +348,14 @@
|
||||
INTEGER(KIND=4) :: SetLogFileOnF
|
||||
SetLogFileOn = SetLogFileOnF(ID,LOG_ON)
|
||||
END FUNCTION SetLogFileOn
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
FUNCTION SetOutputFileName(ID,FNAME)
|
||||
IMPLICIT NONE
|
||||
INTEGER(KIND=4) :: ID
|
||||
CHARACTER(LEN=*) :: FNAME
|
||||
INTEGER(KIND=4) :: SetOutputFileName
|
||||
SetOutputFileName = SetOutputFileNameF(ID,FNAME)
|
||||
END FUNCTION SetOutputFileName
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
FUNCTION SetOutputFileOn(ID,OUTPUT_ON)
|
||||
IMPLICIT NONE
|
||||
|
||||
@ -288,6 +288,59 @@ GetOutputFileOn(int id)
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
const char*
|
||||
GetOutputString(int id)
|
||||
{
|
||||
static const char empty[] = "";
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
return IPhreeqcPtr->GetOutputString();
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
const char*
|
||||
GetOutputStringLine(int id, int n)
|
||||
{
|
||||
static const char err_msg[] = "GetOutputStringLine: Invalid instance id.\n";
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
return IPhreeqcPtr->GetOutputStringLine(n);
|
||||
}
|
||||
return err_msg;
|
||||
}
|
||||
|
||||
int
|
||||
GetOutputStringLineCount(int id)
|
||||
{
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
return IPhreeqcPtr->GetOutputStringLineCount();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
GetOutputStringOn(int id)
|
||||
{
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
if (IPhreeqcPtr->GetOutputStringOn())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
int
|
||||
GetSelectedOutputColumnCount(int id)
|
||||
{
|
||||
@ -562,6 +615,18 @@ SetOutputFileOn(int id, int value)
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
IPQ_RESULT
|
||||
SetOutputStringOn(int id, int value)
|
||||
{
|
||||
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
|
||||
if (IPhreeqcPtr)
|
||||
{
|
||||
IPhreeqcPtr->SetOutputStringOn(value != 0);
|
||||
return IPQ_OK;
|
||||
}
|
||||
return IPQ_BADINSTANCE;
|
||||
}
|
||||
|
||||
IPQ_RESULT
|
||||
SetSelectedOutputFileOn(int id, int value)
|
||||
{
|
||||
|
||||
@ -2699,3 +2699,223 @@ void TestIPhreeqcLib::TestSetOutputFileName(void)
|
||||
::DeleteFile(OUTPUT_FILENAME);
|
||||
}
|
||||
}
|
||||
|
||||
void TestIPhreeqcLib::TestOutputStringOnOff(void)
|
||||
{
|
||||
int n = ::CreateIPhreeqc();
|
||||
CPPUNIT_ASSERT(n >= 0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( false, ::GetOutputStringOn(n) != 0 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputStringOn(n, 1) );
|
||||
CPPUNIT_ASSERT_EQUAL( true, ::GetOutputStringOn(n) != 0 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputStringOn(n, 0) );
|
||||
CPPUNIT_ASSERT_EQUAL( false, ::GetOutputStringOn(n) != 0 );
|
||||
|
||||
if (n >= 0)
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
|
||||
}
|
||||
}
|
||||
|
||||
void TestIPhreeqcLib::TestGetOutputString(void)
|
||||
{
|
||||
int n = ::CreateIPhreeqc();
|
||||
CPPUNIT_ASSERT(n >= 0);
|
||||
|
||||
char OUTPUT_FILENAME[80];
|
||||
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand());
|
||||
if (::FileExists(OUTPUT_FILENAME))
|
||||
{
|
||||
::DeleteFile(OUTPUT_FILENAME);
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL( false, ::FileExists(OUTPUT_FILENAME) );
|
||||
|
||||
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, ::SetOutputStringOn(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( 0, ::RunAccumulated(n) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( true, ::FileExists(OUTPUT_FILENAME) );
|
||||
|
||||
{
|
||||
std::ifstream ifs(OUTPUT_FILENAME);
|
||||
std::string fline((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
|
||||
std::string sline(::GetOutputString(n));
|
||||
CPPUNIT_ASSERT( sline.size() > 0 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( fline, sline );
|
||||
}
|
||||
|
||||
if (::FileExists(OUTPUT_FILENAME))
|
||||
{
|
||||
::DeleteFile(OUTPUT_FILENAME);
|
||||
}
|
||||
if (n >= 0)
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
|
||||
}
|
||||
}
|
||||
|
||||
void TestIPhreeqcLib::TestGetOutputStringLineCount(void)
|
||||
{
|
||||
int n = ::CreateIPhreeqc();
|
||||
CPPUNIT_ASSERT(n >= 0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::GetOutputStringLineCount(n) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat"));
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::GetOutputStringLineCount(n) );
|
||||
|
||||
// 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, ::SetOutputStringOn(n, 0) );
|
||||
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputFileOn(n, 0) );
|
||||
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( 0, ::RunAccumulated(n) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::GetOutputStringLineCount(n) );
|
||||
|
||||
// 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) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputStringOn(n, 1) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) );
|
||||
CPPUNIT_ASSERT_EQUAL( 98, ::GetOutputStringLineCount(n) );
|
||||
|
||||
|
||||
// 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) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputStringOn(n, 0) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::GetOutputStringLineCount(n) );
|
||||
|
||||
if (n >= 0)
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
|
||||
}
|
||||
}
|
||||
|
||||
void TestIPhreeqcLib::TestGetOutputStringLine(void)
|
||||
{
|
||||
int n = ::CreateIPhreeqc();
|
||||
CPPUNIT_ASSERT(n >= 0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::GetOutputStringLineCount(n) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat"));
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::GetOutputStringLineCount(n) );
|
||||
|
||||
// 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, ::SetOutputStringOn(n, 0) );
|
||||
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputFileOn(n, 0) );
|
||||
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( 0, ::RunAccumulated(n) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::GetOutputStringLineCount(n) );
|
||||
|
||||
int line = 0;
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, line++)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, line++)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, line++)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, line++)) );
|
||||
|
||||
// negative lines should be empty
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, -1)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, -2)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, -3)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, -4)) );
|
||||
|
||||
// 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) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputStringOn(n, 1) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) );
|
||||
CPPUNIT_ASSERT_EQUAL( 98, ::GetOutputStringLineCount(n) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), std::string(::GetOutputStringLine(n, 0)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("Reading input data for simulation 1."), std::string(::GetOutputStringLine(n, 1)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), std::string(::GetOutputStringLine(n, 2)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("-----------------------------Solution composition------------------------------"), std::string(::GetOutputStringLine(n, 16)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("----------------------------Description of solution----------------------------"), std::string(::GetOutputStringLine(n, 24)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("----------------------------Distribution of species----------------------------"), std::string(::GetOutputStringLine(n, 40)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("------------------------------Saturation indices-------------------------------"), std::string(::GetOutputStringLine(n, 73)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("End of run.") , std::string(::GetOutputStringLine(n, 95)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, 98)) );
|
||||
|
||||
// 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) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputStringOn(n, 0) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, ::GetOutputStringLineCount(n) );
|
||||
|
||||
line = 0;
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, line++)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, line++)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, line++)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, line++)) );
|
||||
|
||||
// negative lines should be empty
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, -1)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, -2)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, -3)) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetOutputStringLine(n, -4)) );
|
||||
|
||||
if (n >= 0)
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,20 +34,25 @@ class TestIPhreeqcLib : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST( TestDumpOnOff );
|
||||
CPPUNIT_TEST( TestSelOutOnOff );
|
||||
CPPUNIT_TEST( TestLongHeadings );
|
||||
CPPUNIT_TEST( TestDatabaseKeyword ); // ***
|
||||
CPPUNIT_TEST( TestDatabaseKeyword );
|
||||
CPPUNIT_TEST( TestDumpString );
|
||||
CPPUNIT_TEST( TestGetDumpStringLineCount ); // ***
|
||||
CPPUNIT_TEST( TestGetDumpStringLine ); // ***
|
||||
CPPUNIT_TEST( TestGetComponentCount ); // ***
|
||||
CPPUNIT_TEST( TestGetDumpStringLineCount );
|
||||
CPPUNIT_TEST( TestGetDumpStringLine );
|
||||
CPPUNIT_TEST( TestGetComponentCount );
|
||||
CPPUNIT_TEST( TestGetComponent );
|
||||
CPPUNIT_TEST( TestGetErrorStringLine );
|
||||
CPPUNIT_TEST( TestErrorFileOn ); // new
|
||||
CPPUNIT_TEST( TestLogFileOn ); // new
|
||||
CPPUNIT_TEST( TestErrorFileOn );
|
||||
CPPUNIT_TEST( TestLogFileOn );
|
||||
CPPUNIT_TEST( TestGetWarningStringLine );
|
||||
CPPUNIT_TEST( TestPitzer );
|
||||
CPPUNIT_TEST( TestClearAccumulatedLines );
|
||||
CPPUNIT_TEST( TestSetDumpFileName );
|
||||
CPPUNIT_TEST( TestSetOutputFileName );
|
||||
CPPUNIT_TEST( TestOutputStringOnOff );
|
||||
CPPUNIT_TEST( TestGetOutputString );
|
||||
CPPUNIT_TEST( TestGetOutputStringLineCount );
|
||||
CPPUNIT_TEST( TestGetOutputStringLine );
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -96,6 +101,10 @@ public:
|
||||
void TestClearAccumulatedLines(void);
|
||||
void TestSetDumpFileName(void);
|
||||
void TestSetOutputFileName(void);
|
||||
void TestOutputStringOnOff(void);
|
||||
void TestGetOutputString(void);
|
||||
void TestGetOutputStringLineCount(void);
|
||||
void TestGetOutputStringLine(void);
|
||||
|
||||
protected:
|
||||
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user