From 9ce16bc323b66b2387d96ac00aa249509063bf31 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 19 Mar 2010 00:57:37 +0000 Subject: [PATCH] Added GETCOMPONENTCOUNT and GETCOMPONENT fortran routines git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4174 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- include/IPhreeqc.f90.inc | 15 +++++++++++++++ src/fwrap.c | 20 ++++++++++++++++++++ src/fwrap.h | 4 ++++ src/fwrap2.c | 8 ++++++++ src/fwrap3.c | 8 ++++++++ test/kinn.for | 10 ++++++++++ test2/test2.for | 4 ++++ unit/TestInterface.cpp | 13 +++++++------ 8 files changed, 76 insertions(+), 6 deletions(-) diff --git a/include/IPhreeqc.f90.inc b/include/IPhreeqc.f90.inc index 984c6a1f..d6e247de 100644 --- a/include/IPhreeqc.f90.inc +++ b/include/IPhreeqc.f90.inc @@ -169,3 +169,18 @@ CHARACTER(LEN=*) :: LINE END SUBROUTINE END INTERFACE + + + INTERFACE + FUNCTION GetComponentCount() + INTEGER(KIND=4) :: GetComponentCount + END FUNCTION GetComponentCount + END INTERFACE + + + INTERFACE + SUBROUTINE GetComponent(N,COMP) + INTEGER(KIND=4) :: N + CHARACTER(LEN=*) :: COMP + END SUBROUTINE + END INTERFACE diff --git a/src/fwrap.c b/src/fwrap.c index b43a2bb3..eb56193b 100644 --- a/src/fwrap.c +++ b/src/fwrap.c @@ -167,6 +167,18 @@ GetErrorLineF(int* n, char* line, unsigned int line_length) padfstring(line, ::GetErrorLine((*n) - 1), line_length); } +int +GetComponentCountF(void) +{ + return ::GetComponentCount(); +} + +void +GetComponentF(int *n, char* line, unsigned int line_length) +{ + padfstring(line, ::GetComponent((*n) - 1), line_length); +} + int RunF(void) { @@ -353,6 +365,14 @@ void __stdcall GETERRORLINE(int *n, char* line, unsigned int line_length) { GetErrorLineF(n, line, line_length); } +int __stdcall GETCOMPONENTCOUNT(void) +{ + return GetComponentCountF(); +} +void __stdcall GETCOMPONENT(int *n, char* line, unsigned int line_length) +{ + GetComponentF(n, line, line_length); +} int __stdcall RUN(void) { return RunF(); diff --git a/src/fwrap.h b/src/fwrap.h index c2012765..c90682ef 100644 --- a/src/fwrap.h +++ b/src/fwrap.h @@ -43,6 +43,10 @@ extern "C" { void GetErrorLineF(int* n, char* line, unsigned int line_length); + int GetComponentCountF(void); + + void GetComponentF(int* n, char* line, unsigned int line_length); + void OutputLastErrorF(void); void OutputLinesF(void); diff --git a/src/fwrap2.c b/src/fwrap2.c index db604a79..08fff108 100644 --- a/src/fwrap2.c +++ b/src/fwrap2.c @@ -62,6 +62,14 @@ void GETERRORLINE(int *n, char* line, unsigned int line_length) { GetErrorLineF(n, line, line_length); } +int GETCOMPONENTCOUNT(void) +{ + return GetComponentCountF(); +} +void GETCOMPONENT(int *n, char* line, unsigned int line_length) +{ + GetComponentF(n, line, line_length); +} int RUN(void) { return RunF(); diff --git a/src/fwrap3.c b/src/fwrap3.c index ccb620e1..8662f432 100644 --- a/src/fwrap3.c +++ b/src/fwrap3.c @@ -62,6 +62,14 @@ void geterrorline_(int *n, char* line, unsigned int line_length) { GetErrorLineF(n, line, line_length); } +int getcomponentcount_(void) +{ + return GetComponentCountF(); +} +void getcomponent_(int *n, char* line, unsigned int line_length) +{ + GetComponentF(n, line, line_length); +} int run_(void) { return RunF(); diff --git a/test/kinn.for b/test/kinn.for index 8fa5b3b5..c63b38f2 100644 --- a/test/kinn.for +++ b/test/kinn.for @@ -7,6 +7,8 @@ INTEGER i, j, k, rows, cols INTEGER vtype CHARACTER(30) svalue + CHARACTER(30) comp + INTEGER n INTEGER len REAL*8 dvalue @@ -79,6 +81,14 @@ 40 CONTINUE !!!!45 CONTINUE + !! test ListComponents + n = GetComponentCount() + DO i = 1, n + CALL GetComponent(i, comp) + WRITE (*, *) trim(comp) + END DO + + 50 FORMAT(A15,A,$) 60 FORMAT(1PG15.7E2,A,$) END PROGRAM DRIVER diff --git a/test2/test2.for b/test2/test2.for index 957a1c4b..691216e6 100644 --- a/test2/test2.for +++ b/test2/test2.for @@ -4,6 +4,9 @@ INCLUDE '..\include\IPhreeqc.f90.inc' INTEGER iresult INTEGER rows, cols + CHARACTER(30) comp + INTEGER n + INTEGER i iresult = LoadDatabase &('wateq4f.dat') @@ -30,6 +33,7 @@ PRINT*,'Rows= ',rows PRINT*,'Cols= ',cols + STOP 'Ok' diff --git a/unit/TestInterface.cpp b/unit/TestInterface.cpp index 496d7a21..c838000f 100644 --- a/unit/TestInterface.cpp +++ b/unit/TestInterface.cpp @@ -1723,24 +1723,25 @@ TestInterface::TestGetComponent(void) CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) ); // run - ::SetOutputOn(1); + ::SetOutputOn(0); ::SetErrorOn(0); ::SetLogOn(0); ::SetSelectedOutputOn(0); ::SetDumpOn(0); ::SetDumpStringOn(0); - std::cout << "\n"; - ::OutputLines(); - std::cout << "\n"; - CPPUNIT_ASSERT_EQUAL( 0, ::Run() ); - CPPUNIT_ASSERT_EQUAL( 4, ::GetComponentCount() ); + CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetComponent(-2)) ); + CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetComponent(-1)) ); + CPPUNIT_ASSERT_EQUAL( std::string("Ca"), std::string(::GetComponent(0)) ); CPPUNIT_ASSERT_EQUAL( std::string("H"), std::string(::GetComponent(1)) ); CPPUNIT_ASSERT_EQUAL( std::string("Na"), std::string(::GetComponent(2)) ); CPPUNIT_ASSERT_EQUAL( std::string("O"), std::string(::GetComponent(3)) ); + + CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetComponent(4)) ); + CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetComponent(5)) ); }