Jump to content
Geochemist's Workbench Support Forum

[OLD] Scripting GWB REACT


Recommended Posts

From: James Laurinat

Subject: Scripting GWB REACT


Is there a way to run REACT and save output files and command line input and output from a script file, either from Windows or MS-DOS? I would like to automate REACT calculations for a matrix of solution temperatures and compositions. Currently, I run a single-user license copy of REACT (Version 3.1) from Windows 98.


From: Robert C Lee

Subject: Re: Scripting GWB REACT

Scripting was much easier when GWB used to be supported on UNIX (subliminal message: Port GWB to Linux NOW.). Before I continue, I should mention that PHREEQC is designed to be "script" driven - you may consider it. For GWB, it is still doable in Windows. Here is one approach: Simply supply the list of commands in a linear manner (just as you where sitting in front of the terminal) in an long input script. Then supply this script to react via "react -i myinput.dat".


myinput.dat will look something like:

# React script "Model 1"

pH = 7

T = 25

total mg/l Ca++ = 31

[..more basis species here ]


$ren react_output.txt model1_out.txt


# React script "ModelN"

pH = 7.21

[..more basis species here ]


$ren react_output.txt modelN_out.txt


[ more input ]


The KEYS to this approach are: *The forked command to the shell "$ren react_output.txt model1_out.txt". This renames the default output so it doesn't get overwritten in the next run. You can fork *any* command to the shell using the "$", like "$format c:" if you like ;-) *The "reset" command - so you start the next run with a clean slate.

Some Caveats are: *You'll have to rig a way to capture the messages to the terminal (the > "STDOUT") during execution if you want that info for each run (like electrical imbalances, etc). I know of no way to do this in Windows. *It will look ugly - the "MS-DOS" command window will pop up and disappear with each "$" command. Ignore it.


From: Craig Bethke

Subject: RE: Scripting GWB REACT

A facility for just this purpose already exists in Windows (at least NT/2000/XP, its functionality in Win98 is somewhat limited, as I remember): it's called a “named pipe�. You write a master program in some language, open a named pipe, and then launch React as a slave program, using the named pipe as the input file. Now output to the pipe from the master program becomes input to React. You can also redirect the output stream. There's info on named pipes in most any advanced programming text, and on Microsoft's web site.


From: Joel Brugger

Subject: RE: Scripting GWB REACT

I have also been calculating matrices of results for wide ranges of temperatures and fluid compositions. I am also planning to use react to calculate speciation within non-linear least-square regression programs to interpret solubility experiments. I am using a high-level programming language (in this case Matlab) to construct a *.rea script file, run GWB, and then extract the information I'm interested in from the react.output file. This works fine, but it is quite slow because it involves thousands of restarts of the react program. I have been campaigning for a more efficient way to communicate between react & external applications such as Matlab or visual basic. The most

primitive - but already mightily powerful! - solution I can think of involves the possibility to give commands in the react window using a scripting language such as Visual Basic. The trick is to let the scripting application know when react has finished the calculation.

I would appreciate advice about how easy it is to implement such capabilities in react. Also, please rise your hands if you are interested in such functions - may be there is a market out there for users who wish using react as a module in their own software!


From: Robert C Lee

Subject: RE: Scripting GWB REACT

Joel - you're right. It would be wonderful for GWB to have a programmable library - in the same grain as the GNU math library. A library with a few simple calls would do the trick - just to make it easier to extend GWB. The user community could then work out the appropriate bindings for languages like Perl, Python, Matlab, etc. This is one way GWB could capture the some of the OpenSource excitement without giving away it's code entirely.


From: Craig Bethke

Subject: Re: Scripting GWB REACT

To amplify on Rob Lee's comments:

(1) Actually, GWB input is fully scriptable. Just create a file of input commands using a text editor. Then load the file by choosing File; Read Script, or by typing “read filename�. You can even read scripts from within scripts, using the “read� command.

(2) Instead of renaming the output files to preserve them once they are created, it's probably easier to use the “suffix� command to give the file from each run a unique name.

(3) If you'd like to eyeball the output from each run, you can put in your script a “pause� command after each “go�. Just hit the return key to continue executing the script.

From: James Cleverley

Subject: Scripts for GWB

I am playing with scripting in react since the recent discussion and I am wondering if it is possible to implement C shell commands from with in the script such that you can include loops to define variables. For example measuring solubility over a range of redox-pH conditions where a nested loop in the script changes pH and redox variables for each run.


$pH = 10

While $pH > 1 then

log f O2(g) = -40

pH = $pH

suffix $pH


$pH = $pH - 1

end loop

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...