Jump to content
Geochemist's Workbench Support Forum

Reading a script from tcl


awebb

Recommended Posts

Hello,

 

If I have written a script that does something like this:

 

script start

go

pickup reactants minerals
save minerals.rea

#do some other stuff

#recall the minerals you saved earlier
read minerals.rea

 

GWB throws up an error about not being able to locate the database file. The problem is that the beginning of every saved .rea has the line

 

data = "C:\Program Files\Gwb\Gtdata\thermo.dat" verify

 

But of course those slashes really need to be escaped like:

 

data = "C:\\Program Files\\Gwb\Gtdata\\thermo.dat" verify

 

with the result that the wrong file string is sent to GWB.

 

Is there a simple way around this?

 

I have worked around it by using the following code to delete the first two lines of the file like so:

 

set source [open "fluid0$cellCurrent\.rea" r]
set outFluid [open "fluid0$cellCurrent\_deleted.rea" w]
gets $source aline
gets $source aline
while {$aline!=""} {
	gets $source aline
	puts $outFluid $aline
}
close $source
close $outFluid

 

By the way, this problem threw up a secondary issue where the "read" tcl command conflicts with the "read" GWB command. So I've had to use "gets" to work around that issue. The above code is very inflexible and clumsy because I can't read the whole file into tcl. Is there a way to specify that a command is for tcl and not for GWB?

 

So to recap, two issues, is there a way to save parts of the system to a file without the preamble database file string? It would be great to be able to save just the minerals or just the fluid, for example. And is there a way to solve the conflict of the "read" command?

Link to comment
Share on other sites

I've just noticed that escaping the slashes makes the file string correct but actually doesn't solve the error.

 

So before escaping the slashes, the error is:

 

Error: Can't find file "{C:Program FilesGwbGtdata hermo.dat}"

 

Whereas with double slashes the file path appears correctly but the error still occurs:

 

Error: Can't find file "{C:\Program Files\Gwb\Gtdata\thermo.dat}"

Link to comment
Share on other sites

Hello,

 

The easiest way around your current issue is to stop script processing before reading a file and resuming it afterwards.

 

So your given example would be changed to the following:

 

script start

go

pickup reactants minerals
save minerals.rea

#do some other stuff

#recall the minerals you saved earlier
script end
read minerals.rea
script start

#do more stuff

 

This seems like a bug and will be looked into, but the extra script end/script start around read commands should bypass it for now.

 

As for the tcl read command it has been renamed within GWB to fread so that both are usable. Similarly flush has been renamed to fflush and time has been renamed to dtime.

 

 

Hope this helps,

Dan Saalfeld

Link to comment
Share on other sites

  • 1 month later...

Hello awebb,

 

Just wanted to let you know that our latest maintenance release, 9.0.6, has the following change that should fix your problem:

 

Disable control script mode when reading an input file from within a control script (unless the input file itself turns control script mode back on) and restore control script mode when finished.

 

Please let us know if you have any questions.

 

Regards,

 

Brian Farrell

Aqueous Solutions LLC

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.

Guest
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.

Loading...
×
×
  • Create New...