PhreeqcUsers Discussion Forum
Click here to donate to keep PhreeqcUsers open

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 

  • Forum Home
  • Login
  • Register

  • PhreeqcUsers Discussion Forum »
  • Conceptual Models »
  • Design of conceptual models »
  • Fortran interface PhreeqC
« previous next »
  • Print
Pages: [1]   Go Down

Author Topic: Fortran interface PhreeqC  (Read 45 times)

IliasBouchkira

  • Top Contributor
  • Posts: 29
Fortran interface PhreeqC
« on: May 23, 2023, 12:29:16 PM »
Dear all

I am interfacing Matlab and PhreeqC using the following code:
 
Code: [Select]
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.GetSelectedOutputArray
out1=OUTphreeqSTRING(2,:);
m_H_25(i)=out1{1};
m_HSO4_25(i)=out1{2};
m_SO4_25(i)=out1{3};

end

For some reasons I need to do the same but from Fortran

Is there any possibilities? is here any examples ?

Many thanks in advance,

Ilias.
Logged

dlparkhurst

  • Top Contributor
  • Posts: 2917
Re: Fortran interface PhreeqC
« Reply #1 on: May 23, 2023, 02:43:21 PM »
Matlab is using the IPhreeqcCOM version of phreeqc. There is a non-COM IPhreeqc that can be downloaded and compiled from https://www.usgs.gov/software/phreeqc-version-3. It can be used in C++, Fortran, or C programs to perform PHREEQC calculations. It should work similarly to the COM version. You can create a string with the PHREEQC input that you want and then run it with a RunString command.

There is a README file to help with compilation of the library, which you will need to link with your Fortran code. An example is provided.
Logged

IliasBouchkira

  • Top Contributor
  • Posts: 29
Re: Fortran interface PhreeqC
« Reply #2 on: May 31, 2023, 02:53:42 PM »
Dear Dr Parkhurst

Many thanks for the answer on how to use fortran to create a string with the PHREEQC input that I want and then run it with a RunString command.

 I have tried all my best to make the code but I still cannot manage this. Is there anyway to provide a very simple fortran code (for exemple that calculates water activity of any property) that I can use as a start and build more complex one? I will be very grateful.

many thanks in advance,

Kind regards;

Ilias.

Logged

dlparkhurst

  • Top Contributor
  • Posts: 2917
Re: Fortran interface PhreeqC
« Reply #3 on: May 31, 2023, 03:44:19 PM »
I assume you downloaded this link:

Windows (any processor): iphreeqc-3.7.3-15968.zip [13M] -Source with CMake, database files, examples, and documentation https://water.usgs.gov/water-resources/software/PHREEQC/iphreeqc-3.7.3-15968.zip

and that you followed the steps to build the IPhreeqc library.

There is a Fortran example in the directory examples/Fortran/advect with a README file on how to compile the library and the advect example.

When using CMake to build a Visual Studio solution (.sln file), enable the option IPHREEQC_FORTRAN_TESTING and there will be an option test_F90 that tests all of the methods of IPhreeqc. You can look at that code for examples.
Logged

  • Print
Pages: [1]   Go Up
« previous next »
  • PhreeqcUsers Discussion Forum »
  • Conceptual Models »
  • Design of conceptual models »
  • Fortran interface PhreeqC
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines | Terms and Policies
  • XHTML
  • RSS
  • WAP2