Embedded Scripting (Controller)
Redesign Home Design Problem Scripting Compatibility
Interfaces

As an interactive data analysis environment, XSPEC has always had an event loop that processes user commands. From XSPEC10 onward (1997) this event loop has been implemented using an embedded tcl/tk shell. This means that on initialization XSPEC starts a tcl interpreter and adds its command set to those of the tcl language. XSPEC's I/O is channeled through the tcl (or tk) I/O devices and logging is implemented by branching the output to two output channels, one to the screen and one to a file. XSPEC12 operates similarly except that the ability to use C++ data structures considerably simplifies the code. The implementation of commands constitutes the Controller layer of the design, and serves to parse user input, check for errors, and act as the "catch" point for exceptions thrown by the Model layer.

The abstract nature of the I/O system allows the program to communicate with a user either through a command line using tcl channels or through widgets in a tk-based GUI environment.

Having such a shell in an interactive program gives several advantages and a great deal of flexibility both to the developer and the user:

  • It facilitates a clean separation of the Controller layer from the Model. Tasks within the program are encapsulated into single commands which the user (writer of scripts) treats as atomic
  • This clean separation also, in principle, allows the chosen  language to be exchanged for another without too much effort.
  • The implementation "outsources" the task of providing an event loop
  • By adding the command set to the shell, the user may write scripts for repetitive tasks
  • The developer can implement commands as scripts in the extended language. These are not added to the embedded shell but supplied in a script library with the distribution.
  • Users unfamiliar with the  language can ignore its presence and still have access to the full command set. They can write "scripts" that contain no statements native to the scripting language but only program commands.
  • The entire interactive analysis tool can be operated in a batch mode with a script supplied on the command line
  • The availability of an event loop, however implemented, allows the program to be its own test harness as the project progresses so that new functionality can be shown to satisfy integration tests very easily.

The choice of tcl/tk as the scripting language was motivated in part by the natural extension of tcl based command line programs to GUI programs using tk language based widgets. Other choices are possible today.

[Redesign Home]
[Design]
[Problem]
[Scripting]
[Compatibility]

Xspec Xspec Home Page


HEASARC Home | Observatories | Archive | Calibration | Software | Tools | Students/Teachers/Public

Last modified: Wednesday, 02-Mar-2011 11:11:10 EST