Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reverted from v. 14

About the command line runner

The riversystem.commandline.exe provides a mechanism to run existing projects without the Source interface. Results can be returned for recorded items or global expressions within the project.

It can run in three modes:

  • Inprocess - This mode will run a model on the machine where the executable is run. All resources are initialised when the .exe starts and cleaned up when it finishes. This is the default mode and no special parameters are needed to run in this mode;
  • Server - This mode will start a server on the machine the .exe is run on. The .exe will not exit, but will continue to run until you press Enter to exit. This server can then be used to run the calculations and display the results on the machine that the client is run on. Resources are progressively initialised and not freed completely until you exit the server; or
  • Client - This mode runs like the "inprocess" mode but calculations are performed on a specified server. In this mode the model can be loaded, run or stepped, or re-run multiple times depending on the command line options used. The results are displayed on the client machine, while model processing is done on the server machine. These may be the same machine.

Examples

The following set of examples indicate the type of commands used for each of the three modes.

Inprocess

The next example runs the project from start to finish and puts all recorded values in the file ‘test.csv’.

>RiverSystem.CommandLine.exe -p "C:\ProjectDir\test.rsproj" -o test.csv
Loading 100%
Meta-Parameters:
+ $inflow
+ Straight-Through Routing\Default Link #1\Upstream Flow Volume
+ Straight-Through Routing\Default Link #1\Downstream Flow Volume
+ Straight-Through Routing\Default Link #1\Mass Balance
+ Inflow\Inflow 1\Upstream Flow Volume
+ Inflow\Inflow 1\Downstream Flow Volume
+ Inflow\Inflow 1\Inflow Volume
+ Inflow\Inflow 1\Mass Balance
+ Gauge\Gauge 2\Upstream Flow Volume
+ Gauge\Gauge 2\Mass Balance
+ Global Expressions\$inflow\Value
Running 100%

Server

This command starts a basic server on the same machine as the client:

>RiverSystem.CommandLine.exe --mode server
The service is ready at net.tcp://localhost:8523/eWater/Services/RiverSystemService
Press Enter to stop the service.

In this command, a basic server runs on the same machine as the client. This server will look for project files passed from the client in the directory "C:\ProjectDir":

>RiverSystem.CommandLine.exe --mode server --d "C:\ProjectDir"
The service is ready at net.tcp://localhost:8523/eWater/Services/RiverSystemService
Press Enter to stop the service.

The following command will start up a server, load a project from the directory C:\Users\man25n\Documents\eWater Source Projects using the address specified (net.tcp://192.168.1.5:8080/myWaterService/):

>RiverSystem.CommandLine.exe --mode server -d "C:\Users\man25n\Documents\eWater Source Projects" -a "net.tcp://192.168.1.5:8080/myWaterService/"
Press Enter to stop the service.

The address consists of the communication protocol (net.tcp) and the name of the end-point. For a machine that runs both the client and server, the address of the end-point must match.

Client

In the following command, the server is running from the previous example:

> RiverSystem.CommandLine.exe --mode server --d "C:\ProjectDir"
The service is ready at net.tcp://localhost:8523/eWater/Services/RiverSystemService

Option descriptions

Notice in the examples that the command line contains various options, which result in different outputs. The function of these options is provided in Table 110. Note that these are optional extras.

Client/Server configuration

A command line can run in a server/client mode, meaning that there would be one command line that would run projects. It would not do anything except for loading a project until a second command line is run in client mode. In this way, multiple runs can be completed with the server loading the project only once. It also enables the server to run on a different machine to the client.

in When running the command for client/server This means that there would be one command line that would run projects etc. It would not do anything except for loading a project until a second command line is run in client mode. The options that are used in the server/client mode can be configured in two different ways:

  • XML file: riversystem.commandline.exe.config - This file contains a section called <system.serviceModel> which can configure hundreds of options for the services and client including transport types, maximum data size, security etc. These are the default options used when running in client or server mode. The location of the server defined in this file, by default, is "localhost" which means the server and client are configured to run on the same machine; or
  • Command line options - For testing purposes and ad-hoc configuration, two main command line options are also provided to configure the location/type of the server and message time out. When run in this mode the <system.serviceModel> section of the riversystem.commandline.exe.config file may need to be deleted as creating two servers of the same type is not supported. This means that the net.tcp server on localhost defined in the exe.config file will stop you creating an adhoc server of the same type.

Using riversystem.commandline in Source

This section provides a few examples of some common functions that can be carried out in Source using the command line. Refer to Table 111.

PEST calibration using the command line

PEST (Parameter ESTimation and uncertainty analysis) allows analysis of complex environmental models, and can be used in Source for calibration of catchments. You can use the command line to do calibration and uncertainty in a catchments model. The steps to do the calibration are as follows:

  • Starting with a Source Catchment project file, use the new calibration tool to set up ‘global expressions’ for the parameters of the rainfall runoff models. When defining the metaparameters in the Calibration Wizard (#anchor-95-anchor), the list of Existing Metaparameters will be used in the parameter file for invoking riversystem.commandline;
  • Turn on any recorders for the hydrological quantities that will be used in the objective function. In step 4 of the Calibration Wizard, choose Manual optimisation and enable Create global expressions for use from an external tool;
  • Save the project;
  • Set up the Riversystem.Commandline input file;
  • Setup the PEST input and template files;
  • Prepare a batch file to invoke the commandline and pre-processors; and
  • Run PEST.

Once the Calibration wizard has been set up, start the command line server (riversystem.commandline -p projectname.rsproj -m server) and then PEST (pest pestcontrolfile.pst).

Command Line Runner (options)

Display option commands

Function

Example

-p, --project

Path to project, or project name on server and optional scenario within that project

-p "projectName.rsproj" or -p "c:\somePath\projectName.rsproj;someScenarioName"

-m, --mode

Application mode Client/Server/InProcess.

-m Client or -m Server

-d, --directory

Directory in which to look for projects.

-d "c:\ProjectFiles"

-o, --output

File to save output into. The extension selects the output format based on the standard TIME I/O formats. A directory of the name specifed will be created if the format only supports a single time series.

-o "output.csv" for CSV or -o "output.nc" for NetCDF etc.

-r, --results

Which results to return. This can appear multiple times.

-r "someResult" -r "someOtherResult"

-v, --value

Set value of meta-parameter or internal setting.

-v "$metaparam=25", or -v "$anotherMetaParam=2.3"

-s, --step

Number of time steps to run.

--step 1

-t, --reset

Reset the loaded project.

-e, --timeout

Operation timeout for WCF service in seconds.

-e 2000

-b, -baseSIUnits

Ignore units set within project and output base SI units

Using command line runner in Source

Function

Command

Define the location of the executable

SourceExe = shQuote("C:\\Program Files\\eWater\\Source 2.19.1.27\\RiverSystem.CommandLine.exe")

Define the project that you want to load

ProjectFile = shQuote("D:\\Working\\FloodPlain.rsproj")

Start the server in background with project

system (paste(SourceExe,"-p",ProjectFile,"-m Server"), wait=FALSE)

Load a client and run the server (results to screen)

system (paste(SourceExe,"-m Client"))

Load a client and send the results to a temporary directory

DefaultOutputFile = paste(tempdir(), "SourceOutput.csv", sep="\\")

system (paste(SourceExe,"-m Client","-o",shQuote(DefaultOutputFile)))

Reading an output csv back into R

results=read.csv (DefaultOutputFile, nrows=365*120)