C0=[0.1:0.1:4.02];for i=1:length(C0)%Creation of the ActiveX server:iphreeqc = actxserver('IPhreeqcCOM.Object');%Specify the database file according to the location on your file system.iphreeqc.LoadDatabase([pwd,'\pitzer.dat']);%Please change this line if you installed this somewhere else%Call PhreeqC functionality using separate input file%Note that in this way dynamic assignment of values to variables is not possible.%I assume that the input file for PhreeqC is located in the current working directory.%iphreeqc.RunFile([pwd,'\inputPhreeqC.txt']);OUTphreeqFILE = iphreeqc.GetSelectedOutputArray;%Call PhreeqC functionality providing input as MATLAB multiline String%Define input string as cell array of strings and combine them to a multiline string using the sprintf command.mS =C0(i);tem=20;IPCstringCell= {'SOLUTION 1', ... ['temp ' num2str(tem)],... '-pH 1 charge',... '-units mol/kgw ', ... ['S(6) ' num2str(mS)],... 'SAVE SOLUTION 1', ... 'SELECTED_OUTPUT', ... '-molalities H+ HSO4- SO4-2', ... 'soln false', ... 'pH false', ... 'sim false', ... 'state false', ... 'time false', ... 'step false', ... 'pe false', ... 'distance false' ... };IPCstring = sprintf('%s\n', IPCstringCell{:})%Use the PhreeqC object method RunString with the above defined multiline string.iphreeqc.RunString( IPCstring );OUTphreeqSTRING = iphreeqc.GetSelectedOutputArrayout1=OUTphreeqSTRING(2,:);m_H_25(i)=out1{1};m_HSO4_25(i)=out1{2};m_SO4_25(i)=out1{3};end
SOLUTION 1 temp 25 pH 7 charge pe 4 redox pe units mmol/kgw density 1 Cl 1 mol/kgw Na 1 mol/kgw Ca 1 mol/kgw -water 1 # kgSELECTED_OUTPUT 1 -file selected_output_1.sel -ionic_strength true -water true -molalities Na+ Ca+2
Ierr = AccumulateLine(Id, "SOLUTION 1") Ierr = AccumulateLine(Id, " temp 25")... Ierr = AccumulateLine(Id, "END") Ierr = RunAccumulated(Id)
module Subs integer :: Id contains subroutine EHandler() use IPhreeqc IMPLICIT NONE call OutputErrorString(Id) stop end subroutine EHandler end module Subs program File_PhreeqC use Subs use IPhreeqc IMPLICIT NONE integer :: Ierr !Create module, load database, define initial conditions and selected output Id = CreateIPhreeqc() if (LoadDatabase(Id, "phreeqc.dat") .ne. 0) call EHandler() If (RunFile(Id, "ic") .ne. 0) call EHandler()! RunString ----$ Ierr = AccumulateLine(Id, " SOLUTION 1") Ierr = AccumulateLine(Id, " temp 25" ) Ierr = AccumulateLine(Id, " pH 7 charge " ) Ierr = AccumulateLine(Id, " units mmol/kgw" ) Ierr = AccumulateLine(Id, " Mg 0.1") Ierr = AccumulateLine(Id, " -water 1 # kg") Ierr = AccumulateLine(Id, " Ca 0.1 mol/kgw" ) Ierr = AccumulateLine(Id, " Mg 0.1 mol/kgw") Ierr = AccumulateLine(Id, " Cl 0.1 mol/kgw") Ierr = AccumulateLine(Id, "SELECTED_OUTPUT 1") Ierr = AccumulateLine(Id, " -file V:\selected_output_1.txt") Ierr = AccumulateLine(Id, "-ionic_strength true") Ierr = AccumulateLine(Id, "-water true") Ierr = AccumulateLine(Id, " -molalities Ca+2") Ierr = RunAccumulated(Id) end program File_PhreeqC
Ierr = SetSelectedOutputFileOn(Id, 1) Ierr = SetSelectedOutputFileName(Id, "myoutput.sel") Ierr = SetOutputFileOn(Id, 1) Ierr = SetOutputFileName(Id, "myoutput.out") Ierr = RunAccumulated(Id)