The best way to proceed is to copy an existing instrument, and modify it to your needs. The interface to the TCL language can be done almost entirely through the tcl++ class library. Use the NEWCMD macro to instantiate a new TCL command. This may be the complete widget, or merely a component of it. The instrument may be encoded entirely in TCL code, accessing the model's state variables in the usual way. Alternatively, you may write C++ code to access the state variables directly through the model's class defintion.
An alternative approach is taken in analysis.cc. A variable that has been registered in the TCL_obj database can have a reference set up to it using the declare macro, defined in TCL_obj_base.h. For example, in the ecolab model, ecolab.density is the TCL name for the density member of the ecolab model. Then
declare(density,iarray,"ecolab.density");declares a variable of type
iarray&that may be used to refer to this member. Argument 3, the string parameter needn't be a constant string, but can be any string, eg a string passed through argv.