Subject: Exposure/Offset Sequences

From: Alan Watson

Submitted: Mon, 8 Jul 1996 11:53:10 -0600

Message number: 21 (previous: 20, next: 22 up: Index)

People seem to be becoming more interested in having the MC take
series of GRIM II exposures with interleaved offsets. The current
programming paradigm for this is a set of distinct TCL procedures
which are called sequentially. One is used for each exposure or offset
and each contains the logic to determine the flow of control. The
result is extremely flexible but not especially pretty.

I have a suggestion which, I think, is a significant improvement in
that it cleanly separates the actions of the telescope and the
instrument from the code required to glue them together. This makes it
much easier to create, check, and modify sequences.

The basic idea is to write a procedure that first defines the actions
of the telescope and instrument and then calls a separate procedure to
perform those actions. For example, a procedure to take an object/sky
pair could be defined as:

    proc pair {itime n east north} {
        global cmd
        set cmd(0) 0
        set cmd(1) "nexpose inst=grim itime=$itime n=$n"
        set cmd(2) "offset $east $north"
        set cmd(3) "nexpose inst=grim itime=$itime n=$n"
        set cmd(4) "offset [expr -$east] [expr -$north]"
        set cmd(5) ""

This procedure defines cmd() to be a global array. cmd(0) is used as a
`program counter' and must be initialized to zero. cmd(1) and
subsequent elements hold the MC commands which are to be executed. The
final element of cmd is set to a null string, to indicate that there
are no more commands to be executed. After constructing the array,
docmd is called to do the hard work of actually executing the commands
in sequence, printing the responses, and aborting if an error occurs.
Here is a definition of docmd:

    proc docmd {args} {
        global MID cmd

        # show result of previous command
        if {$cmd(0) > 0} {
            puts "docmd:$cmd(0): $args"

        # abort if failure
        if {$cmd(0) > 0 && [cindex $args 1] == "f"} {
            puts "\adocmd:$cmd(0): aborting"

        # return if informational
        if {$cmd(0) > 0 && [cindex $args 1] == "i"} {

        # return if end of command sequence
        incr cmd(0)
        if {$cmd($cmd(0)) == ""} {
            puts "\adocmd:$cmd(0): done"

        # execute next command
        puts "docmd:$cmd(0): $cmd($cmd(0))"
        incr MID
        sendhub $MID 0 docmd "$cmd($cmd(0))"


Note that only one docmd procedure need be defined -- it can serve
to execute the actions of many difference sequence.

While this method lacks the flexibility of the distinct procedure
approach, it is perfectly adequate for simple sequences of exposures
and offsets.

Alan Watson (

APO APO APO APO APO  Apache Point Observatory 3.5m  APO APO APO
APO  This is message 21 in the apo35-grim archive. You can find
APO  the archive on
APO  To join/leave the list, send mail to
APO  To post a message, mail it to