Scripts can be used with WEAP in two different ways:
Internally: to create more powerful expressions and functions for a WEAP model (e.g., create a script to calculate reservoir water quality, and Call the script from a WEAP expression).
Externally: to automate WEAP via its Application Programming Interface (API) to perform a sequence of actions (e.g., create and run 100 WEAP scenarios by varying the value of several parameters (sensitivity analysis), and export the results to Excel for further analysis);
WEAP has its own built-in script editor that can be used to edit, interactively debug and run scripts. You may also use any text editor to create or edit your scripts.
When used internally, scripts can either be called from the Call function in an expression, or associated with events that will run at various times before, during and after WEAP's calculations. When Called by an expression, functions take only numeric parameters and should always return a numeric value (integer or floating point). Functions can have any number of parameters (or none at all), but it is the user's responsibility to pass the correct number of parameters in a comma separated list in the Call statement. For example, Call(Test.vbs ! Add, 4, 5) or Call(Test.js ! add, 4, 5)
You may also run a script from the main menu: Advanced, Scripting, Run.
A few trivial example functions are shown here.
Function Add(x, y)
Add = x + y
Function Multiply(x, y)
Multiply = x * y
function add(x, y)
return x + y;
return x * y;
def add(x, y):
return x + y
def multiply(x, y):
return x * y
In VBScript, each function starts with the keyword Function and ends with the keywords End Function; function results are set by assigning values to the function name (in this case Add or Multiply). In JScript and Python, function results are set with the return keyword.
Some other internet-based resources you may find useful:
VBScript reference guide
JScript reference guide
Free versions of Python, Perl, PHP and Ruby