Automation Tools
Batch Mode and RiverWare Command Language
This section describes methodology to run RiverWare from the command line and optionally execute a RiverWare Command Language (RCL) script. This Batch Mode allows you to run RiverWare without seeing the user interface and allows for automation of many processes including advancing the run dates, running DMIs to bring in new data, running the model, generating output, and saving the model.
Running RiverWare From the Command Line
Running RiverWare from the command line provides an alternative to selecting the RiverWare icon from the Windows system. In addition, RiverWare supports certain commands directly from the command line like loading models and rulesets and certain other operations. To access the command line, in the Windows Start menu Search field, type cmd.
Then select the option for cmd.exe.
A window similar to that shown in
Figure 2.1 will open. To start RiverWare from this window, enter the full RiverWare path (depending on your PATH configuration).
Figure 2.1 Starting RiverWare from the Windows Command Line
A complete list of command line options can be viewed by invoking RiverWare with the --help command line argument. On the Windows command line, type:
riverware.exe --help
When RiverWare is executed from a command line window, it is run as an independent process from the command shell, so exiting the command window will not automatically terminate RiverWare. The Windows task manager can be used to terminate batch runs of RiverWare.
Sometimes, the user wishes to run one or more models as automatic tasks (as Windows “Scheduled Tasks”). Setting up the runs using batch mode and the command line options can be useful in this approach. For example, a user may wish to run a series of models overnight when the machine is more available. One command line option that is useful is the --log <file> switch. This option sends any diagnostic output to the specified file.
Running RiverWare in Batch Mode
The RiverWare Command Language (RCL) facility allows models to be run in batch mode. While in this mode, RiverWare does not open a user interface, but instead runs in background mode.
In batch mode, the user provides RiverWare with a script file, which contains the commands RiverWare executes. Commands are entered through the RCL file, rather than through the user interface. The commands are described in detail in the following document.
The syntax to invoke RiverWare in batch mode from a command prompt is:
riverware --batch <script file>
The following example will invoke the batch script file called BasinOperationsScript.rcl and will write the diagnostics output to file called BasinOperationsDiagnostics.txt.
riverware --batch “C:\MyRiverWareFiles\BasinOperationsScript.rcl” --log “C:\MyOutputs\BasinOperationsDiagnostics.txt”
The <script file> defines how the batch run should proceed. In the file, you specify commands to load a model, load a ruleset if necessary, start a run, and save the results. In the simplest case, you will load a model, run a simulation, save the model, and exit batch mode. The following RCL commands support these actions:
# Load the model
OpenWorkspace <Model Name>
# run the simulation
StartController
# save the model
SaveWorkspace <Model Name>.saved.mdl
# Close the opened model and exit RiverWare
CloseWorkspace
This is a very simple example. The full complement of key words and commands is presented in the following section.
About RiverWare Command Language
This section provides general information about the RiverWare Command Language (RCL) syntax and variables.
Syntax Key
• Angled brackets (<>) indicate a required parameter.
• Brackets ([]) indicate an optional parameter.
• A vertical bar “|” within angled brackets or brackets indicates a choice of parameters. For example, “<#RunInfo|#MRM>” indicates that either “#RunInfo” or “#MRM” must be provided as a required parameter.
• Parameters starting with “!” are tokens, which should appear exactly as is.
• Parameters starting with “#” are RiverWare names, which should appear exactly as is.
• A “#” sign at the beginning of the line represents a comment. Anything occurring after the “#” will be ignored.
• Parameters which contain embedded white space characters must be enclosed in curly braces {}, or quotes “ ”.
• Anywhere there is a file referenced below, the user can specify the path using either a full reference or using environment variables (see next section). On Windows, path names should use “/” or '\\'. Also, the file may reference a shared network: RCL accepts '\' but it has to be escaped with '\', so the RCL syntax is as follows:
\\\\ComputerName\\ShareName\\...
Environment Variables
Environment variables are system variables that allow portability of models across machines and platforms.
Setting Environment Variables
If you wish to set environment variables and then reference them in the RCL script, they can be set using the TCL command “set env” as follows:
set env(variable) value
Then the variable can be accessed within the RCL script using the
$env(variable) syntax. These variables are only available within the script, RiverWare has already inherited the environment before this is set and are then not available. To set variables to be available to RiverWare, use the
SetEnv command; see
“SetEnv”. This command has the following syntax:
SetEnv <variable> <value>
These variables are then available in RiverWare but not available within the script. Most likely, you will want to set both variables within the script. Consider the following example:
# for use in the script:
set env(DMI_DIR) C:/DMI/data
# for use by RiverWare:
SetEnv DMI_DIR $env(DMI_DIR)
# open the model using the TCL environment variable syntax:
OpenWorkspace $env(DMI_DIR)/model.mdl.gz
Then within RiverWare, you can reference DMI_DIR using the $DMI_DIR syntax in DMI’s, MRM or other places.
Using Environment Variables
Environment variables set outside of the RCL script can be referenced using the form:
• $VARIABLE
• $(VARIABLE)
• ${VARIABLE}
VARIABLE is a letter followed by zero or more letters, digits or underscores. If the variable is followed by a letter, digit or underscore it must be “quoted” with () or {}.
Special Parameters
• {date time}
A date and time of the format {MM/DD/YYYY HH:MM} or {MM-DD-YYYY HH:MM}, where the year includes the century and the hour is 24-hour based.
Note: A date and time, which includes embedded white space, must be enclosed in braces {}.
• {delta time}
A timestep or time duration of the format {count units}, where units are “HOURS,” “DAYS,” “WEEKS,” or “MONTHS.”
Note: A delta time, which includes embedded white space, must be enclosed in braces {}.