USER_PUNCH/USER_GRAPH > SELECTED_OUTPUT

SELECTED_OUTPUT of molalities for all species possible?

(1/1)

d_guse:
Good afternoon!

Using SELECTED_OUTPUT, it is possible to output molalities and activities of selected species. Is there a way to output this information for all existing species instead of having to list each species separately?

Since I'm using IPhreeqC with Matlab I would also be interested in alternative ways apart from SELECTED_OUTPUT, e.g. in order to list all calculated species as a string.

Kind regards
David

dlparkhurst:
Maybe I should have had an option, but I think I did not because the set of species often changes with each calculation. Here is a way to get a list of species. Note that it will generate a line for each calculation within a simulation (SOLUTION; EQUILIBRIUM_PHASES; END would produce two lines).

This code


--- Code: ---SOLUTION 1
SELECTED_OUTPUT 2
USER_PUNCH 2
10 t = SYS("aq", count, name$, type$, moles)
20 FOR i = 1 to count
30   PUNCH PAD(name$(i), 5) STR_F$(LM(name$(i)),6, 2)
40 NEXT i
50 END

--- End code ---

produces the following tab-delimited selected-output file. [Note that EOL$ can be used to end a line, for example PUNCH name$(i), LM(name$(i)), EOL$.]


--- Code: ---       OH-         -6.99        H+           -7.00        H2          -25.15        O2       -42.08

--- End code ---

With IPhreeqc you can get this line as a string with the following:


--- Code: ---SetCurrentSelectedOutputUserNumber (2)
SetOutputStringOn (true)
... run simulation ...
GetOutputStringLine (1)

--- End code ---

d_guse:
Thank you Mr. Parkhurst for your most helpful answer (as well as your work in general)! I think everything should work out know.

However, I do have two follow-up questions concerning the PhreeqC code.
   1.  I couldn't find documentation on STR_F$ (only on STR$). The second number (2) seems to
        determine the number of decimal places, but I can't tell what the first number (6) is for.
   2.  Using your code, as well as my slightly adjusted code, results in the following warning. Do you
        have an idea why?
        "WARNING: USER_PUNCH: Headings count does not match number of calls to PUNCH."

My slightly adjusted PhreeqC code:

--- Code: ---SOLUTION 1
   Cu 0.1
   N(+5) 0.2
SELECTED_OUTPUT 1
   -reset false
USER_PUNCH 1
   10 t = SYS("aq", count, name$, type$, moles)
   20 FOR i = 1 to count
   30 PUNCH PAD(name$(i), 8) STR_F$(LM(name$(i)),6 , 4) # _F? und 6?c und sim 2?!
   40 NEXT i
   50 END
   -end
SELECTED_OUTPUT 2
   -reset true
   -molalities Cu+2 NO3-

--- End code ---

And my Matlab test code, if anyone ever has a similar problem:


--- Code: ---iphreeqc=actxserver('IPhreeqcCOM.Object');                                                      % Activate communication with PhreeqC
iphreeqc.LoadDatabase('E:\Program Files\USGS\IPhreeqcCOM 3.6.2-15100\database\phreeqc.dat');    % Load database

IPC_Cell = {
    'SOLUTION 1',  ...          % first solution
        'Cu 0.1',  ...          % moles of Cu2+ cations
        'N(+5) 0.2', ...        % moles of (NO3)- anions
    'SELECTED_OUTPUT 1',  ...       % main output
        '-reset false', ...         % no further info on calculation
    'USER_PUNCH 1',...
        '10 t = SYS("aq", count, name$, type$, moles)',...
        '20 FOR i = 1 to count',...
        '30 PUNCH name$(i) STR_F$(LM(name$(i)),6 , 4)',...
        '40 NEXT i',...
        '50 END',...
    'SELECTED_OUTPUT 2',...         % control output
        '-reset true',...           % complete info on calculation
        '-molalities Cu+2 NO3-',... % chosen molalities
        };                                             
   
IPC_string = sprintf('%s\n', IPC_Cell{:});  % Transform cell array into a multiline string
iphreeqc.OutputStringOn = true;             % Load output into string buffer instead of file
iphreeqc.RunString(IPC_string);             % Data transfer to IPhreeqC and execution in IPhreeqC

iphreeqc.CurrentSelectedOutputUserNumber = 1;       % Select SELECTED_OUTPUT
OUT_IPC_STRING1 = iphreeqc.GetOutputString;         % Possibility 1: get buffered (complete) output string
OUT_IPC_STRING2 = iphreeqc.GetSelectedOutputArray;  % Possibility 2: get SELECTED_OUTPUT 1
STRING2_corr = OUT_IPC_STRING2(2,1:2:end);          % Get only the species names of string2

iphreeqc.CurrentSelectedOutputUserNumber = 2;       % Select control SELECTED_OUTPUT
OUT_IPC_STRING3 = iphreeqc.GetSelectedOutputArray; % Get (manually selected) molalities (+ calculation info)

--- End code ---

dlparkhurst:
The latest documentation is online at https://water.usgs.gov/water-resources/software/PHREEQC/documentation/phreeqc3-html/phreeqc3.htm or in the Help provided in PhreeqcI. These two sources have new capabilities noted in green font.

The arguments of STR_F$ are the number, the field width, and the number of decimal places.

Just ignore the warning from USER_PUNCH. USER_PUNCH has the option -headings, and there is a check to see if the number of headings defined in -headings matches the number of items that are printed with PUNCH Basic statements. With your variable output, there probably is no way to anticipate the number of headings needed.

Navigation

[0] Message Index

Go to full version