PhreeqcUsers Discussion Forum

Beginners => PHREEQC basics => Topic started by: ehsan on July 10, 2021, 07:54:06 PM

Title: phreeqc matlab
Post by: ehsan on July 10, 2021, 07:54:06 PM
hi dears
I have problem
why cant builded H2S_90.prn file and open the H2S_90.prn file in matlab
Code: [Select]
clc
clear
n=10;
PRESS=zeros(n,1);%PSI
TEMP=zeros(n,1);%C
MOL_Na=zeros(n,1);%mg/liter
MOL_Cl=zeros(n,1);%mg/liter
MOL_K=zeros(n,1);%mg/liter
MOL_Ca=zeros(n,1);%mg/liter
MOL_Mg=zeros(n,1);%mg/liter
for i=1:n
    PRESS(i)=rand(1)*400;
    TEMP(i)=50;
    MOL_Na(i)=rand(1)*40000;
    MOL_Cl(i)=rand(1)*76000;
    MOL_K(i)=rand(1)*2000;
    MOL_Ca(i)=rand(1)*5000;
    MOL_Mg(i)=rand(1)*1600;
    PRESS=PRESS(i)
    TEMP=TEMP(i);
    MOL_Na=MOL_Na(i);
    MOL_Cl=MOL_Cl(i);
    MOL_K=MOL_K(i);
    MOL_Ca=MOL_Ca(i);
    MOL_Mg=MOL_Mg(i);
     iphreeqc = actxserver('IPhreeqcCOM.Object');
     iphreeqc.LoadDatabase('C:\Program Files\USGS\IPhreeqcCOM 3.7.0-15749\database\phreeqc.dat');
     IPCstringCell= {'PHASES', ...
    'H2S(g)',...
   'H2S  =  H+ + HS-',...
   'log_k      -7.97',...
   '-delta_h   9.1',...
   '# -analytic -9.7354e+001 -3.1576e-002 1.8285e+003 3.7440e+001 2.8560e+001',...
   '-T_c  373.2',...
   '-P_c  88.2',...
   '-Omega 0.1',...
    'SOLUTION_SPECIES',...
    'HS- + H+ = H2S',...
   '-log_k   6.994',...
    '-gamma 0 0.1',...
   '-delta_h -5.30   kcal',...
    '#   -analytical  -11.17  0.02386  3279.0',...
   '-dw    2.1e-9',...
   '-Vm  7.81  2.96  -0.46 # supcrt',...
    'SOLUTION 1',...
    ['-temp ',num2str(TEMP) ],  ...
    '-units mg/l',  ...
    ['Ca ', num2str(MOL_Ca)], ...
    ['Mg ', num2str(MOL_Mg)], ...
    ['Na ', num2str(MOL_Na)], ...
    ['K  ', num2str(MOL_K) ], ...
    ['Cl ', num2str(MOL_Cl)], ...
    'S(-2)     1    H2S(g) 0',...
    'SELECTED_OUTPUT 1; -reset false; -file H2S_90.prn',...
    'USER_PUNCH 1',...
    '-start',...
    '10 s$ = s$ + ''USE solution 1'' + EOL$',...
    '20 s$ = s$ + ''EQUILIBRIUM_PHASES 1''+ EOL$',...
    '30 s$ = s$ + ''H2S(g)''+ STR$(LOG10(PRESS))+'' 10 ''+ EOL$',...
    '40 s$ = s$ +''END''+ EOL$',...
    '50 PUNCH s$',...
    'END',...
'SELECTED_OUTPUT 1; -active false',...
'INCLUDE$ H2S_90.prn',...
'END'};
IPCstring = sprintf('%s\n', IPCstringCell{:});
iphreeqc.RunString( IPCstring )
OUTphreeqSTRING = iphreeqc.GetSelectedOutputArray
end