TCLLINK

Description

This module provides a simple link between apsim and TCL interpreters. Variables are exchanged through a Get/Set mechanism.

Settings

Rules are defined just like the manager: the rules in [xyz.tcllink.init] will be evaluated at the simulation’s initialisation.
The other rules of interest are “init”, “prepare”, “start_of_day”, “process”,“ post”, “end_of_day”, and “exit”.

Apsim messages are generated with the TCL procedure apsimSendMessage.
It has two mandatory arguments, the destination module, the message name, and optional message name/value pairs are encoded as list elements.
For example,

apsimSendMessage wheat sow {cultivar hartog} {plants 120} {sowing_depth 30}

Apsim variables are set/get with apsimGet, apsimSet.
The procedure apsimWriteToSummaryFile sends a log message to the current summary file

Command Line Debugger

A simple “command line” debugger is provided in the sample directory.
It demonstrates the ability to examine apsim variables, step through simulations and set breakpoints.

nb. In the following samples,

1.             On the first line, the “(Sample) # %” (where # is just a number) part is just the command prompt. It is what comes after that is important. It is the command.

2.             Also the next line underneath (if it exists) is the result or output(or the echo) of doing the command above.

3.             The final line (if it exists) is an explanation of the result or output(or echo).

 (Sample) 1 % link clock.day day 

Link the apsim variable “clock.day” to the tcl variable “day”.
(Sample) 2 % b {$day == 182} 
{$day == 182} 

Set a breakpoint for day 182. Equivalent to

“ b {[apsimGet clock.day] == 182} ”
(Sample) 3 % c 
-1 

Continue. Control returns after a crop is planted
(Sample) 4 % p wheat.biomass 
12.874

Print an apsim variable
(Sample) 5 % s 
1 

Single step
(Sample) 6 % p wheat.biomass 
14.095 
etc..
(Sample) 7 %

Missing features

Cannot uncrack messageData structures (eg newmet)