How to interface PHREEQC with MATLAB?

37 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 20 Mai 2019
How to interface PHREEQC with MATLAB?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 20 Mai 2019
Modifié(e) : MathWorks Support Team le 20 Mai 2019
In order to use PHREEQC with MATLAB, please install one of the 'IPhreeqcCOM' modules which provides a COM-Server-Interface to 'PHREEQC'. This is available on: https://www.usgs.gov/software/phreeqc-version-3
In the attachments you can find a Live Script which provides a full example to interface the PHREEQC software using the ActiveX interface.
To create an ActiveX server, the following was defined in the code, please change the path so it fits to your installation.:
%Creation of the ActiveX server:
iphreeqc = actxserver('IPhreeqcCOM.Object');
%Specify the database file according to the location on your file system.
iphreeqc.LoadDatabase('C:\Program Files\USGS\IPhreeqcCOM 3.5.0-14000\database\wateq4f.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 Aqueous Solution
cca=10; %Conc. of Ca2+ (mmol/l)
cmg=50; %Conc. of Mg2+ (mmol/l)
%Define input string as cell array of strings and combine them to a multiline string using the sprintf command.
IPCstringCell= {'SOLUTION 1', ...
'-temp 10', ...
'-units mmol/L', ...
['Ca ', num2str(cca)], ...
['Mg ', num2str(cmg)], ...
'Na 550', ...
'K 10', ...
'Cl 470', ...
'S(6) 28', ...
'C(4) 2.1', ...
'Alkalinity 2.3', ...
'SELECTED_OUTPUT', ...
'-saturation_indices Calcite Dolomite', ...
'-molalities CO2 HCO3-', ...
'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.GetSelectedOutputArray
The interface which is defined in the script can be improved by the development of a PHREEQC-class in MATLAB. There you could implement the 'actxserver' and 'iphreeqc.LoadDatabase' into the class constructor.
If you need more general information about ActiveX interfaces in MATLAB, please see the following site in our documentation: https://mathworks.com/help/matlab/using-com-objects-in-matlab.html?s_tid=CRUX_lftnav

Plus de réponses (0)

Produits


Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by