mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-15 16:18:22 +01:00
added Kinniburgh memory leak project
git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/trunk@5004 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
181868693f
commit
e65a77807e
14
IPhreeqc.sln
14
IPhreeqc.sln
@ -25,6 +25,8 @@ Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "test_f", "tests\test_f.vfpr
|
||||
{F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7} = {F9C18E06-F73A-4EB0-92E0-AE1713EA7FD7}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "memory_leak_f", "memory_leak_f\memory_leak_f.vfproj", "{941BC4D5-7D05-4786-BC65-38914514EA9B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
@ -127,6 +129,18 @@ Global
|
||||
{66E68C3F-EFCE-47EE-80F1-4D8F6F8AB450}.ReleaseDll|Win32.Build.0 = ReleaseDll|Win32
|
||||
{66E68C3F-EFCE-47EE-80F1-4D8F6F8AB450}.ReleaseDll|x64.ActiveCfg = ReleaseDll|x64
|
||||
{66E68C3F-EFCE-47EE-80F1-4D8F6F8AB450}.ReleaseDll|x64.Build.0 = ReleaseDll|x64
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.Debug|x64.ActiveCfg = Debug|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.DebugDll|Win32.ActiveCfg = Debug|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.DebugDll|Win32.Build.0 = Debug|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.DebugDll|x64.ActiveCfg = Debug|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.Release|Win32.Build.0 = Release|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.Release|x64.ActiveCfg = Release|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.ReleaseDll|Win32.ActiveCfg = Release|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.ReleaseDll|Win32.Build.0 = Release|Win32
|
||||
{941BC4D5-7D05-4786-BC65-38914514EA9B}.ReleaseDll|x64.ActiveCfg = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
117
memory_leak_f/init.f90
Normal file
117
memory_leak_f/init.f90
Normal file
@ -0,0 +1,117 @@
|
||||
MODULE init
|
||||
|
||||
IMPLICIT NONE
|
||||
|
||||
PRIVATE
|
||||
PUBLIC :: line, lineorig, new_phreeqc_id, readinput, replacestring, cx, cy
|
||||
|
||||
INTEGER(KIND=4) :: ID_IPHREEQC(2),thisid1, thisid2
|
||||
CHARACTER(LEN=160), DIMENSION(120) :: line = ""
|
||||
CHARACTER(LEN=160), DIMENSION(120) :: lineorig = ""
|
||||
CHARACTER(LEN=32) :: cx, cy
|
||||
|
||||
|
||||
contains
|
||||
|
||||
!**************************************************************************************************
|
||||
|
||||
SUBROUTINE readinput(n)
|
||||
|
||||
INTEGER, INTENT(OUT) :: n
|
||||
INTEGER :: ios
|
||||
|
||||
OPEN (UNIT = 11, FILE = 'test_memory_leak.pqi', STATUS = 'OLD', IOSTAT = ios)
|
||||
|
||||
IF (ios.NE.0) STOP 'Could not open input file'
|
||||
|
||||
n = 1
|
||||
|
||||
DO
|
||||
|
||||
READ (UNIT = 11, FMT = '(A)', IOSTAT=ios) lineorig(n)
|
||||
IF (ios.EQ.-1) EXIT
|
||||
IF (ios.NE.0) STOP 'File error.'
|
||||
n = n + 1
|
||||
|
||||
ENDDO
|
||||
|
||||
n = n - 1
|
||||
|
||||
CLOSE (UNIT = 11)
|
||||
|
||||
IF (n.GT.0) then
|
||||
line(1:n) = lineorig(1:n)
|
||||
ELSE
|
||||
STOP 'no chemical input.'
|
||||
ENDIF
|
||||
|
||||
END SUBROUTINE readinput
|
||||
|
||||
!**************************************************************************************************
|
||||
|
||||
FUNCTION new_phreeqc_id()
|
||||
|
||||
INCLUDE 'IPhreeqc.f90.inc'
|
||||
|
||||
INTEGER(KIND=4) :: new_phreeqc_id
|
||||
|
||||
new_phreeqc_id = CreateIPhreeqc()
|
||||
|
||||
END FUNCTION new_phreeqc_id
|
||||
|
||||
!**************************************************************************************************
|
||||
|
||||
SUBROUTINE replacestring(string, targetstring, newstring)
|
||||
|
||||
! replace all occurrences of targetstring with newstring
|
||||
! trailing blanks (as per TRIM) in targetstring and newstring are removed
|
||||
! ie cannot be used to replace one blank with two blanks
|
||||
|
||||
IMPLICIT NONE
|
||||
!
|
||||
! Dummy arguments
|
||||
!
|
||||
CHARACTER(*) :: string, targetstring, newstring
|
||||
INTENT (IN) newstring, targetstring
|
||||
INTENT (INOUT) string
|
||||
!
|
||||
! Local variables
|
||||
!
|
||||
INTEGER :: len_string, len_target, len_newstring, index_target
|
||||
|
||||
! first check for trivial cases of 'no change'
|
||||
IF (TRIM(targetstring).EQ.'' .OR. newstring.EQ.targetstring) RETURN
|
||||
|
||||
index_target = 1
|
||||
|
||||
len_string = LEN_TRIM(string)
|
||||
len_target = LEN_TRIM(targetstring)
|
||||
len_newstring = LEN_TRIM(newstring)
|
||||
|
||||
DO WHILE (index_target.GT.0 .AND. index_target.LE.len_string)
|
||||
len_string = LEN_TRIM(string)
|
||||
IF (len_target.GT.0) THEN
|
||||
index_target = INDEX(string,TRIM(targetstring))
|
||||
ELSE
|
||||
index_target = INDEX(string,TRIM(targetstring))
|
||||
ENDIF
|
||||
IF (len_newstring.GT.0) THEN
|
||||
IF (index_target.GT.1) THEN
|
||||
string = string(1:index_target-1)//TRIM(newstring)//string(index_target+len_target:)
|
||||
ELSEIF (index_target.EQ.1) THEN
|
||||
string = TRIM(newstring)//string(1+len_target:)
|
||||
ENDIF
|
||||
ELSE
|
||||
IF (index_target.GT.1) THEN
|
||||
string = string(1:index_target-1)//string(index_target+len_target:)
|
||||
ELSEIF (index_target.EQ.1) then
|
||||
string = string(1+len_target:)
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
ENDDO
|
||||
|
||||
END SUBROUTINE replacestring
|
||||
|
||||
|
||||
END MODULE init
|
||||
32
memory_leak_f/memory_leak_f.vfproj
Normal file
32
memory_leak_f/memory_leak_f.vfproj
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<VisualStudioProject ProjectCreator="Intel Fortran" Keyword="Console Application" Version="11.0" ProjectIdGuid="{941BC4D5-7D05-4786-BC65-38914514EA9B}">
|
||||
<Platforms>
|
||||
<Platform Name="Win32"/></Platforms>
|
||||
<Configurations>
|
||||
<Configuration Name="Debug|Win32">
|
||||
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" DebugInformationFormat="debugEnabled" Optimization="optimizeDisabled" AdditionalIncludeDirectories="../include" Interfaces="true" WarnInterfaces="true" Traceback="true" BoundsCheck="true" RuntimeLibrary="rtMultiThreadedDebug"/>
|
||||
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" AdditionalLibraryDirectories="../lib" GenerateDebugInformation="true" SubSystem="subSystemConsole" AdditionalDependencies="IPhreeqcd.lib"/>
|
||||
<Tool Name="VFResourceCompilerTool"/>
|
||||
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
|
||||
<Tool Name="VFCustomBuildTool"/>
|
||||
<Tool Name="VFPreLinkEventTool"/>
|
||||
<Tool Name="VFPreBuildEventTool"/>
|
||||
<Tool Name="VFPostBuildEventTool"/>
|
||||
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
|
||||
<Configuration Name="Release|Win32">
|
||||
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" AdditionalIncludeDirectories="../include"/>
|
||||
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" AdditionalLibraryDirectories="../lib" SubSystem="subSystemConsole" AdditionalDependencies="IPhreeqc.lib"/>
|
||||
<Tool Name="VFResourceCompilerTool"/>
|
||||
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
|
||||
<Tool Name="VFCustomBuildTool"/>
|
||||
<Tool Name="VFPreLinkEventTool"/>
|
||||
<Tool Name="VFPreBuildEventTool"/>
|
||||
<Tool Name="VFPostBuildEventTool"/>
|
||||
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration></Configurations>
|
||||
<Files>
|
||||
<Filter Name="Header Files" Filter="fi;fd"/>
|
||||
<Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"/>
|
||||
<Filter Name="Source Files" Filter="f90;for;f;fpp;ftn;def;odl;idl">
|
||||
<File RelativePath=".\init.f90"/>
|
||||
<File RelativePath=".\test_memory_leak.f90"/></Filter></Files>
|
||||
<Globals/></VisualStudioProject>
|
||||
119
memory_leak_f/test_memory_leak.f90
Normal file
119
memory_leak_f/test_memory_leak.f90
Normal file
@ -0,0 +1,119 @@
|
||||
|
||||
|
||||
!**************************************************************************************************
|
||||
|
||||
|
||||
PROGRAM test_memory_leak
|
||||
|
||||
USE init
|
||||
|
||||
INCLUDE "IPhreeqc.f90.inc"
|
||||
|
||||
REAL*8 :: xmin, xmax, ymin, ymax, dx, dy, x, y
|
||||
INTEGER :: nstep, i, ii, nlines, nt = 0, ios
|
||||
INTEGER :: id1, accumstat=0, nerr=0, nrow=0, ncol=0
|
||||
|
||||
INTEGER(4) :: v
|
||||
REAL(8) :: d, c
|
||||
CHARACTER(80) :: s, species, mainspecies
|
||||
|
||||
OPEN(UNIT=13, file='test_memory_leak.log', STATUS='UNKNOWN', IOSTAT = ios)
|
||||
IF (ios.NE.0) STOP 'Could not open log file'
|
||||
|
||||
id1 = new_phreeqc_id()
|
||||
|
||||
nerr = SetSelectedOutputFileOn(id1,.TRUE.)
|
||||
nerr = SetOutputFileOn(id1,.TRUE.)
|
||||
nerr = SetDumpFileOn(id1,.TRUE.)
|
||||
nerr = SetErrorFileOn(id1,.TRUE.)
|
||||
nerr = SetLogFileOn(id1,.TRUE.)
|
||||
|
||||
nerr = LoadDatabase(id1,'wateq4f.dat')
|
||||
IF (nerr.GE.1) THEN
|
||||
PRINT *, nerr,' errors reading the database.'
|
||||
STOP
|
||||
ENDIF
|
||||
|
||||
CALL readinput(nlines)
|
||||
|
||||
LINE(:) = LINEORIG(:)
|
||||
|
||||
xmin = 2
|
||||
xmax = 7
|
||||
|
||||
ymin = -80
|
||||
ymax = 0
|
||||
|
||||
!dx = 0.01d0
|
||||
!nstep = (xmax-xmin)/dx + 1
|
||||
|
||||
nstep = 20
|
||||
|
||||
dx = (xmax-xmin)/FLOAT(nstep)
|
||||
dy = (ymax-ymin)/FLOAT(nstep)
|
||||
|
||||
mainspecies ="Fe"
|
||||
|
||||
DO y = ymin, ymax, dy
|
||||
DO x = xmin, xmax, dx
|
||||
|
||||
nt = nt + 1
|
||||
|
||||
WRITE (cx,'(ES20.12)') x
|
||||
WRITE (cy,'(ES20.12)') y
|
||||
|
||||
DO i = 1, nlines
|
||||
IF (INDEX(line(i),'<x_axis>')>0) THEN
|
||||
CALL replacestring(line(i),'<x_axis>',ADJUSTL(cx))
|
||||
ENDIF
|
||||
IF (INDEX(line(i),'<y_axis>')>0) THEN
|
||||
CALL replacestring(line(i),'<y_axis>',ADJUSTL(cy))
|
||||
ENDIF
|
||||
IF (INDEX(line(i),'<mainspecies>')>0) THEN
|
||||
CALL replacestring(line(i),'<mainspecies>',mainspecies)
|
||||
ENDIF
|
||||
accumstat = AccumulateLine(id1,line(i))
|
||||
! print '(i0,t5,A)', i, trim(line(i))
|
||||
IF (accumstat.NE.IPQ_OK) THEN
|
||||
PRINT *,'Error accumulating line ',i,"."
|
||||
STOP
|
||||
ENDIF
|
||||
ENDDO
|
||||
|
||||
nerr = RunAccumulated(id1)
|
||||
|
||||
IF (nerr.NE.0) THEN
|
||||
PRINT *, nerr,' errors when running.'
|
||||
CALL OutputErrorString(id1)
|
||||
STOP
|
||||
ENDIF
|
||||
|
||||
nrow = GetSelectedOutputRowCount(id1)
|
||||
ncol = GetSelectedOutputColumnCount(id1)
|
||||
|
||||
do i = 1, 2 ! ncol
|
||||
if (mod(i,2).EQ.1) then
|
||||
nerr = GetSelectedOutputValue(id1,nrow,i,v,c,species)
|
||||
else
|
||||
nerr = GetSelectedOutputValue(id1,nrow,i,v,d,s) + nerr
|
||||
IF (nerr.EQ.0) THEN
|
||||
WRITE (13,'(I0,t15,F10.5,t30,F10.5,t45,A,t60,F11.3)') nt, x, y, TRIM(species), LOG10(d)
|
||||
WRITE (*,'(I0,t15,F10.5,t30,F10.5,t45,A,t60,F11.3)') nt, x, y, TRIM(species), LOG10(d)
|
||||
ELSE
|
||||
STOP 'bad data.'
|
||||
ENDIF
|
||||
endif
|
||||
enddo
|
||||
|
||||
line(:) = lineorig(:)
|
||||
line(:) = lineorig(:)
|
||||
|
||||
ENDDO
|
||||
ENDDO
|
||||
|
||||
nerr = DestroyIPhreeqc(id1)
|
||||
|
||||
CLOSE (UNIT = 13)
|
||||
|
||||
END PROGRAM test_memory_leak
|
||||
|
||||
37
memory_leak_f/test_memory_leak.pqi
Normal file
37
memory_leak_f/test_memory_leak.pqi
Normal file
@ -0,0 +1,37 @@
|
||||
# Simple predominance diagram
|
||||
PRINT
|
||||
-reset false
|
||||
PHASES
|
||||
Fix_H+
|
||||
H+ = H+
|
||||
log_k 0.0
|
||||
SELECTED_OUTPUT
|
||||
-high_precision true
|
||||
-reset false
|
||||
|
||||
USER_PUNCH
|
||||
-headings
|
||||
-start
|
||||
50 main$ = "<mainspecies>"
|
||||
60 IF STEP_NO = 0 THEN 100 ELSE 70
|
||||
70 totel = SYS(main$, n, n$, t$, c)
|
||||
80 h2o = TOT("water")
|
||||
90 PUNCH n$(1), c(1)/h2o
|
||||
100 END
|
||||
-end
|
||||
END
|
||||
|
||||
SOLUTION 1
|
||||
pH 1.8
|
||||
units mol/kgw
|
||||
Fe(3) 1e-1
|
||||
Na 1e-1
|
||||
Cl 1e-1
|
||||
|
||||
EQUILIBRIUM_PHASES 1
|
||||
Fix_H+ -<x_axis> NaOH 10
|
||||
-force_equality true
|
||||
O2(g) <y_axis>
|
||||
Fe(OH)3(a) 0 0
|
||||
END
|
||||
|
||||
3846
memory_leak_f/wateq4f.dat
Normal file
3846
memory_leak_f/wateq4f.dat
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user