From fb0ec4984facadaeacbd47a6372674b4fdca1cd8 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 24 Jan 2012 00:04:40 +0000 Subject: [PATCH] working on documentation examples git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/ErrorHandling@6096 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- doc/examples/F90GetErrorStringLine.f90 | 60 ++++++++++++++++++++++++++ doc/examples/GetErrorString.c | 45 +++++++++++++++++++ src/IPhreeqc.h | 16 +++++-- 3 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 doc/examples/F90GetErrorStringLine.f90 create mode 100644 doc/examples/GetErrorString.c diff --git a/doc/examples/F90GetErrorStringLine.f90 b/doc/examples/F90GetErrorStringLine.f90 new file mode 100644 index 00000000..fd26f898 --- /dev/null +++ b/doc/examples/F90GetErrorStringLine.f90 @@ -0,0 +1,60 @@ +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 (SetErrorStringOn(id, .TRUE.).NE.IPQ_OK) 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 + + WRITE(*,*) "Input:" + CALL OutputAccumulatedLines(id) + + IF (RunAccumulated(id).NE.0) THEN + CALL OutputErrorString(id) + STOP + END IF + + WRITE(*,*) "Error:" + DO i=1,GetErrorStringLineCount(id) + CALL GetErrorStringLine(id, i, line) + WRITE(*,*) TRIM(line) + END DO + + IF (DestroyIPhreeqc(id).NE.IPQ_OK) THEN + CALL OutputErrorString(id) + STOP + END IF +END PROGRAM example diff --git a/doc/examples/GetErrorString.c b/doc/examples/GetErrorString.c new file mode 100644 index 00000000..cc391ecb --- /dev/null +++ b/doc/examples/GetErrorString.c @@ -0,0 +1,45 @@ +#include +#include +#include + +#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 (SetErrorStringOn(id, TRUE) != IPQ_OK) { + OutputErrorString(id); + return EXIT_FAILURE; + } + + if (RunString(id, input) != 0) { + OutputErrorString(id); + return EXIT_FAILURE; + } + + printf("Error:\n"); + printf("%s\n", GetErrorString(id)); + + if (DestroyIPhreeqc(id) != IPQ_OK) { + OutputErrorString(id); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/src/IPhreeqc.h b/src/IPhreeqc.h index 0947cbc1..3579a136 100644 --- a/src/IPhreeqc.h +++ b/src/IPhreeqc.h @@ -420,6 +420,10 @@ extern "C" { * @see GetErrorFileOn, GetErrorStringLine, GetErrorStringLineCount, OutputErrorString, SetErrorFileOn * @par Fortran90 Interface: * Not implemented. (see \ref GetErrorStringLineCount, \ref GetErrorStringLine, \ref OutputErrorString) + * + * \anchor GetErrorString_c + * @par C Example: + * \include GetErrorString.c */ IPQ_DLL_EXPORT const char* GetErrorString(int id); @@ -443,6 +447,10 @@ extern "C" { * * * @endhtmlonly + * + * \anchor GetErrorStringLine_f90 + * @par Fortran90 Example: + * \include F90GetErrorStringLine.f90 */ IPQ_DLL_EXPORT const char* GetErrorStringLine(int id, int n); @@ -537,9 +545,9 @@ extern "C" { * @par Fortran90 Interface: * Not implemented. (see \ref GetLogStringLineCount, \ref GetLogStringLine) * - * \anchor GetOutputString_c + * \anchor GetLogString_c * @par C Example: - * \include GetOutputString.c + * \include GetLogString.c */ IPQ_DLL_EXPORT const char* GetLogString(int id); @@ -1484,7 +1492,7 @@ Headings * to the error file are stored in a buffer for retrieval. The initial setting after calling * \ref CreateIPhreeqc is on. * @param id The instance id returned from \ref CreateIPhreeqc. - * @param output_string_on If non-zero, captures the error output into a string buffer; + * @param error_string_on If non-zero, captures the error output into a string buffer; * if zero, error output is not captured to a string buffer. * @retval IPQ_OK Success. * @retval IPQ_BADINSTANCE The given id is invalid. @@ -1563,7 +1571,7 @@ Headings * to the log 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 output_string_on If non-zero, captures the log output into a string buffer; + * @param log_string_on If non-zero, captures the log output into a string buffer; * if zero, log output is not captured to a string buffer. * @retval IPQ_OK Success. * @retval IPQ_BADINSTANCE The given id is invalid.