Run TUFLOW From a Batch-file: Difference between revisions

Content deleted Content added
No edit summary
 
(11 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 62:
 
==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 101 ⟶ 105:
;* “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 144 ⟶ 148:
: The addition of the “L” flag (e.g. -pmL) list the files to be copied into an output file, but don’t copy.<br>
;* “ini” (file.ini)<br>
: The addition of the “ini” flag (e.g. -pmini) provides a .ini file with user defined options. A .ini file can be used to overwrite the default base and destination folders, and specify events/scenarios for models with events/scenarios in filenames. ValidNote, optionsscenarios shouldand beevents separatedare byspecified ato verticalhelp barthe package model utility find files that use scenario or event variable names in file names and does not limit the package to specific event and scenarios. To limit the scenarios and events, please use the [[#Copy_a_TUFLOW_model | copy model functionality]]. See the example below for more information.<br>
 
Combinations of the above are also valid, with the order of the optional switches not being important (-pmAllL would be treated the same as -pmLAll).<br>
Line 163 ⟶ 167:
An example of package model that copies all files with specified .ini file (-pmAllini) is:<br>
<pre>start "TUFLOW" "C:\TUFLOW\Releases\2020-10-AE\TUFLOW_iSP_w64.exe" -pmAllini package.ini "C:\TUFLOW\Tutorial_Wiki\TUFLOW\runs\M01_5m_001.tcf"</pre>
 
An example of .ini file to overwrite the default base and destination folders, and specify events/scenarios for models with events/scenarios in filenames:<br>
====INI files with Events and Scenarios====
An example of .ini file to overwrite the default base and destination folders, and specify events/scenarios for models with events/scenarios in filenames:.<br>
The model scenario and event options are required only if there are files that use the event or scenario variables in file names. This option does not limit the files that TUFLOW will package by scenario or event.
E.g. you may have the following command to read in either a base or development TIF grid:
<pre>
Read GRID Zpts == ..\model\grid\DEM_<<~s1~>>.tif
</pre>
In this example, we can assume that the <tt><<~s1~>></tt> variable could be replaced with either <tt>"Base"</tt> or <tt>"Dev"</tt>. The example ini file below shows how to ensure that TUFLOW will package both the "Base" and "Dev" files correctly. The same concept applies for event variables, noting that events defined in the event file (TEF) and their associated boundary files are not required to use this. It is only required if the event variable is used i.e. <tt><<~e1~>></tt>.
<pre>
Base Folder == <folder>C:\TUFLOW\Model_to_Package
Copy Destination == <folder>C:\TUFLOW\Packaged_Model
Model Scenario ~s<number>s1~ == <scenario A> | <scenario B>Base | Dev
Model Event ~e<number>e1~ == <event A> | <event B>60m | 90m
</pre>
 
Line 279 ⟶ 291:
 
<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===
Line 309 ⟶ 321:
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 408 ⟶ 420:
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 451 ⟶ 463:
 
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>
 
Line 520 ⟶ 556:
In order to restart the machine rather than power it off the /s can be replaced with /r. This can be useful when a heavily utilised modelling computer needs a restart!
</ol>
 
==Special Characters==
If your TCF file reference contains any special characters (e.g. é, ë, ä, ö… etc) you may find that TUFLOW does not find the TCF path. The best way to fix this is to make sure the batch file content (the text) and the console are using the same encoding so that the correct characters are being passed to TUFLOW. This can be achieved by using a text editor like Notepad++ to make sure the text is encoded in a chosen format (e.g. UTF-8), then using the <code>chcp [code]</code> command in the batch file to set the encoding to be identical.
 
An example using UTF-8 is shown below. In Windows, UTF-8 has the code page code = 65001, so at the top of the batch file, set the code page to 65001 to tell the console window what encoding to expect.
<pre>
chcp 65001
TUFLOW.exe -b spëcial.tcf
</pre>