Run TUFLOW From a Batch-file: Difference between revisions

Content deleted Content added
 
(26 intermediate revisions by 4 users not shown)
Line 23:
 
===Pause===
A second line with the text "pause" can be added, this will prompt the user to press a key at the end of the batch file. This is useful if the DOSconsole window disappears from the screen, before you can read the output. The pause command will keep the window open.
<pre>"C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" "M01_5m_001.tcf"
pause</pre>
Line 60:
<pre>Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" M01_5m_001.tcf
Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" M01_2.5m_001.tcf</pre>
==no console simulation==
 
==No Console Option==
Using the -nc switch will run a simulation without opening a DOS console window. This option is desirable for people running simulation on the cloud. Note, if an invalid .tcf file is specified, the simulation stops and returns an error level of 1 to the operating system.
 
<pre>Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nc M01_5m_001.tcf
Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nc M01_2.5m_001.tcf</pre>
 
It is possible to get a text output of the console using:
<pre>Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nc M01_5m_001.tcf > M01_5m_001.txt
Start "TUFLOW" /wait /min "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nc M01_2.5m_001.tcf > M01_2.5m_001.txt</pre>
 
== TUFLOW switches in a batch file==
Line 74 ⟶ 77:
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -t "M01_5m_001.tcf"</pre>
 
===Batch mode in TUFLOW===
The use of the –b (batch) switch which suppresses the need to press the return key at the end of a simulation. This ensures that one simulation proceeds on to the next without any need for user input. This is required for running multiple simulations in series (one after the other).
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b "M01_5m_001.tcf"</pre>
 
===Automatically Create Folders in a TUFLOW model===
The use of the -acf (automatically create folders) switch prevents the dialog prompt from appearing when encountering non-existent folders (ie. results folders), and creates these folders automatically. If for any reason the folder can't be created, a dialog will appear. This feature was first introduced for Build 2012-05-AE and is not available for TUFLOW builds prior to this. For models simulated with Build 2013-12-AA or later, non-existent folders are now automatically created. If you would prefer to have the create folder query dialog to appear, you can specify the –qcf run time option (stands for query create folders).<br>
Line 96 ⟶ 101:
;* “a” (all);<br>
: The addition of the “a” flag (e.g. -ca) copies all files of the same name for all input files (ie. same name, but different extensions). This option is particularly useful if the .tab and other associated files of a GIS layer need to be archived or delivered.<br>
;*“L” (list);<br>
: The addition of the “L” flag will output the files used by TUFLOW into a .tcl (TUFLOW Copy List) file but not copy the files to a destination folder. This can be useful if scripting the copying of models. To run the copy list the character “L” needs to be specified after the -c input argument. This works for all copy options, for example, the following are all valid; -cL, -caL, -capL. The .tcl file produced is output in the same directory as the .tcf and takes the simulation name.
;* “p” (path); and<br>
: The addition of the “p” flag (e.g. -cp) allows the user to specify an alternate path in which to copy the model. Without this flag, the location defaults to the .tcf’s location. For example, specifying the following, will place a copy of the model into a folder C:\put_model_here:<br>
REM <ttpre> start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -cp "C:\put_model_here" "C:\TUFLOW\runs\M01_5m_001.tcf" </ttpre><br>
;* “ncf” (no check files)<br>
: The addition of the “ncf” flag (e.g. -cncf) copies the essential input files and excludes all check files.<br>
Line 197 ⟶ 204:
 
The following command could be used to run a model with CPU hardware on 8 threads:
<pre>"C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -hwcpu -nt8 FS_Hardware_01.tcf </pre>
 
The following command could be used to run a model on GPU hardware using 2 devices (GPU 0 and GPU1):
<pre>"C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -hwgpu -pu0 -pu1 FS_Hardware_01.tcf </pre>
 
===Set Start Time for a Simulation===
The use of the -st<time_in_hours> (start time) switch allows the user to specify the start time for a simulation. Any start time specified via this run option argument is given the highest priority and overrides the "Start Time ==" settings in the .tcf, event files (.tef) and override files. <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -st0 "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
===Set End Time for a Simulation===
The use of the -et<time_in_hours> (end time) switch allows the user to specify the end time for a simulation. Any end time specified via this run option argument is given the highest priority and overrides the "End Time ==" settings in the .tcf, event files (.tef) and override files. <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -et3 "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
===Suppress Message Box Prompts===
The use of the -nmb (no message boxes) switch suppresses the use of Windows message boxes to prompt the user. All prompts will be via the console window. <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nmb "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
===Search for a Network License===
The use of the -nwk (network) switch forces TUFLOW to search for a network licence. I.e. Skip the search for a local license. <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -nwk "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
===Search for a WIBU License===
The use of the -wibu (WIBU license) switch forces TUFLOW to search only for a WIBU Codemeter license.<br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -wibu "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
===Specify the Output Drive===
The -od<drive> (output drive) switch allows the user to specify the Output Drive for a simulation. <br>
For example, the following will redirect all outputs to the C:\ drive:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -odC "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
===Specify Map Output===
The -oz<name> (output zone) switch specifies that the map output includes the input zone. <br>
For example, the following would include output for 'Zone A':<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -ozZoneA "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
===Query the Creation of a Folder===
The -qcf (query the creation of a folder) switch is useful if you would prefer to have the create folder query dialog appear (rather than TUFLOW automatically creating folders - see <u>[[Run_TUFLOW_From_a_Batch-file#Automatically_Create_Folders_in_a_TUFLOW_model | -acf]]</u>). <br>
An example is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -qcf "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
===Execute a Simulation (the Default)===
The -x (execute) switch executes the simulation. This switch is used by default and does not need to be included on the TUFLOW command line.
 
===Copy or Test Model License Free===
For Build 2018-03-AA or later, it is possible to use the <u>[[Run_TUFLOW_From_a_Batch-file#Copy_a_TUFLOW_model | copy model]]</u> (-c option) or <u>[[Run_TUFLOW_From_a_Batch-file#Testing_a_simulation | test model]]</u> (-t option) without using a license. To utilise this licence free copy/test, the -nlc (no license check) input argument must be specified. If running without a TUFLOW licence, no diagnostic output is generated (e.g. messages layer). If these are required, the -nlc option must be removed.
 
===Simulation Log Path (Legacy)===
The -slp (simulation log path) switch is a legacy option for Solftlock (blue) dongles to set the path to a folder on the intranet to log all simulation initiated from the lock. Refer to the <u>[https://www.tuflow.com/downloads/ TUFLOW Manual]</u> (2018 or earlier) for details.<br>
 
==Advanced Batch Files==
Line 221 ⟶ 277:
Start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" M01_2.5m_001.tcf</pre>
For this to work the wait.bat file needs to be in the same folder as the batchfile calling it. You can put the file in a specific location and add this path as an environment variable. If this is done "call wait <time in seconds> can be added to any batch file.<br>
To set the environment variable, you will need to have administrator access to the machine, and add a colon (;) and then the batchfile location (e.g. "C:\batch_files\" , without the quotes) in the '''path''' system variables. The separator character is a colon (;) this is added to specify a new path. For more details on modifying the environment please see here: [httphttps://support.microsoft.com/kb/310519 httphttps://support.microsoft.com/kb/310519].
 
===Variables===
Batch files can be easily setup so that they are more generic and easily customised when moving from one project to another. For example, in the below a variable, TUFLOWEXE, is used to define the path to the TUFLOW exe to be used, and a variable RUN is used to incorporate options such as the /wait so that the simulations run in series (one after the other).
 
<pre>set TUFLOWEXE="C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe"
set RUN=start "TUFLOW" /wait "%TUFLOWEXE%" -b
%RUN% MR_H99_C25_Q100.tcf
%RUN% MR_H99_C25_Q050.tcf
%RUN% MR_H99_C25_Q020.tcf</pre>
The advantage of using variables is if the path to the TUFLOW exe changes, or to run a different version of TUFLOW, it is just a simple change in the .bat file. In the above, note the use of quotes around %TUFLOWEXE% in the definition for theTUFLOW RUNexecutable variablepath – quotes are needed around file pathnames whenever they contain a space.
 
===Looping in a batch file===
If you have a large number of events to run using the event files a for loop can be used in a batch file. In this example we have 5 event magnitudes (-e1 input) and 5 event durations (-e2 input). The following batch file can be used to run all 25 simulations one after the other:
Line 247 ⟶ 304:
FOR %%a in (%A%) do (
FOR %%b in (%B%) DO (
start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b filename.tcf
)
)
Line 253 ⟶ 310:
</pre>
In order to test the syntax, you can test the batch file by replacing the following line:<br>
<tt>start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b filename.tcf</tt><br>
With the following line:<br>
<tt><u>echo</u> start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b filename.tcf</tt><br>
By using the echo in the command line, rather than starting the simulations the command line will be displayed in the DOSconsole window output. In the example above the DOSconsole window output is shown in the image below.
[[File:DOS nested batch output.png|frame|none]]
 
Line 266 ⟶ 323:
set B=10min 30min 60min 120min 270min
 
FOR %%a in (%A%) do FOR %%b in (%B%) do start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b filename_~e1~_~e2~.tcf
pause
</pre>
Line 280 ⟶ 337:
FOR %%b in (%B%) do (
FOR %%c in (%C%) do (
start "TUFLOW" /wait "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -b -e1 %%a -e2 %%b -s1 %%c filename_~e1~_~e2~_~s1~.tcf
)
)
Line 354 ⟶ 411:
 
REM ______________SET RUN VARIABLES_____________
set TUFLOWEXE="C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe"
set RUN=start "TUFLOW" /low "%TUFLOWEXE%" -b
set /a CPU_Cores=5
 
Line 399 ⟶ 456:
endlocal
</pre>
 
===Copy model, checks and results in a looped batch file===
This batch file uses the copy model function to copy the model (inputs and check files), of both scenarios 5m and 2.5m, to a specified folder location. After copying, <u>[https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy robocopy]</u> is used to copy the results, based off the tcf filename and specified scenarios, to the destination result folder.
<pre>
@echo off
 
set TUFLOWEXE_iSP="C:\Releases\2023-03-AF\TUFLOW_iSP_w64.exe"
set RUN_iSP=start "TUFLOW" /wait %TUFLOWEXE_iSP% -cp "D:\tuflow_models\copy"
 
set A=5m 2.5m
set source_results=..\results
set destination_results=C:\tuflow_models\copy\results
 
 
FOR %%a in (%A%) do (
:: Copy model
%RUN_iSP% -s1 %%a M01_~s1~_001.tcf
:: Copy results folder to copy model location
robocopy "%source_results%" "%destination_results%" "M01_%%a_001*" /S
)
pause
</pre>
 
===Coordinating Asynchronous Simulations===
This batch file will set off asynchronous runs on separate threads, and then wait for all runs to finish before moving to the next process. This example kicks off 8 tuflow.exe processes and then waits before collating (in fortran) and processing the results (in python). Both “combine_therad_outputs.exe” and “Post_process.py” are dummy programs only (with dummy arguments), and are included just to demonstrate how any sort of post processing might be called after the synchronisation of all TUFLOW simulations.
Line 409 ⟶ 491:
:: User defined variables – will need to be changed
set "for_infile=inputs_fortran.inp"
set "run_exe=tuflow"C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe""
set "file_prefix=C:\temp\test"
set "sum_exe=combine_thread_outputs.exe"