Our next step is to run the SpecTcl we have created, attach it to the online system and use it to analyze data from our setup. Before we start on the remainder of this section, Be sure you have opened a terminal window, have started your readout software, an begun a run. In another terminal window, cd to the directory in which you developed SpecTcl.
Run the SpecTcl program. Several X-windows will pop up. In the remainder of this section I will:
Describe the windows and what they do.
Show how to look at Spectra with Xamine and how to save a window file for later restoration.
This section will describe the following SpecTcl windows:
TkCon - A console that you can use to interact with SpecTcl at a command level
SpecTcl - SpecTcl's GUI, which you can tailor to meet your needs by programming in Tk, Tcl's user interface language.
Xamine - which provides a viewport into your spectra.
The figure below shows SpecTcl's TkCon window:
TkCon is a modified version of the Tcl/Tk console developed by Jeff Hobbs, currently release manager for Tcl/Tk and working at ActiveState. This window looks very much like a terminal window. Like a terminal window, you can Tcl/Tk and SpecTcl commands.
If you type the command
spectrum -list
You will get back an empty response. This because we have not yet loaded our setup
file. Recall that our setup file is just a Tcl script. It can be loaded using the
Tcl source command:
source setup.tcl
After loading the setup file, the spectrum -list yields the following output:
{0 slot10.channel00 1 {slot10.channel00} {{0.000000 4095.000000 4096}} long}
{32 slot10.channel00-vs-slot10.channel01 2 {slot10.channel00 slot10.channel01} {{0.000000 4095.000000 512} {0.000000 4095.000000 512}} word}
{1 slot10.channel01 1 {slot10.channel01} {{0.000000 4095.000000 4096}} long}
{2 slot10.channel02 1 {slot10.channel02} {{0.000000 4095.000000 4096}} long}
{3 slot10.channel03 1 {slot10.channel03} {{0.000000 4095.000000 4096}} long}
{4 slot10.channel04 1 {slot10.channel04} {{0.000000 4095.000000 4096}} long}
{5 slot10.channel05 1 {slot10.channel05} {{0.000000 4095.000000 4096}} long}
{6 slot10.channel06 1 {slot10.channel06} {{0.000000 4095.000000 4096}} long}
{7 slot10.channel07 1 {slot10.channel07} {{0.000000 4095.000000 4096}} long}
{8 slot10.channel08 1 {slot10.channel08} {{0.000000 4095.000000 4096}} long}
{9 slot10.channel09 1 {slot10.channel09} {{0.000000 4095.000000 4096}} long}
{10 slot10.channel10 1 {slot10.channel10} {{0.000000 4095.000000 4096}} long}
{11 slot10.channel11 1 {slot10.channel11} {{0.000000 4095.000000 4096}} long}
{12 slot10.channel12 1 {slot10.channel12} {{0.000000 4095.000000 4096}} long}
{13 slot10.channel13 1 {slot10.channel13} {{0.000000 4095.000000 4096}} long}
{14 slot10.channel14 1 {slot10.channel14} {{0.000000 4095.000000 4096}} long}
{15 slot10.channel15 1 {slot10.channel15} {{0.000000 4095.000000 4096}} long}
{16 slot10.channel16 1 {slot10.channel16} {{0.000000 4095.000000 4096}} long}
{17 slot10.channel17 1 {slot10.channel17} {{0.000000 4095.000000 4096}} long}
{18 slot10.channel18 1 {slot10.channel18} {{0.000000 4095.000000 4096}} long}
{19 slot10.channel19 1 {slot10.channel19} {{0.000000 4095.000000 4096}} long}
{20 slot10.channel20 1 {slot10.channel20} {{0.000000 4095.000000 4096}} long}
{21 slot10.channel21 1 {slot10.channel21} {{0.000000 4095.000000 4096}} long}
{22 slot10.channel22 1 {slot10.channel22} {{0.000000 4095.000000 4096}} long}
{23 slot10.channel23 1 {slot10.channel23} {{0.000000 4095.000000 4096}} long}
{24 slot10.channel24 1 {slot10.channel24} {{0.000000 4095.000000 4096}} long}
{25 slot10.channel25 1 {slot10.channel25} {{0.000000 4095.000000 4096}} long}
{26 slot10.channel26 1 {slot10.channel26} {{0.000000 4095.000000 4096}} long}
{27 slot10.channel27 1 {slot10.channel27} {{0.000000 4095.000000 4096}} long}
{28 slot10.channel28 1 {slot10.channel28} {{0.000000 4095.000000 4096}} long}
{29 slot10.channel29 1 {slot10.channel29} {{0.000000 4095.000000 4096}} long}
{30 slot10.channel30 1 {slot10.channel30} {{0.000000 4095.000000 4096}} long}
{31 slot10.channel31 1 {slot10.channel31} {{0.000000 4095.000000 4096}} long}
If you do not know Tcl very well, this output will seem a bit odd. It is a Tcl formatted list (list elements separated by newlines). Each list element itself is a list that describes a single spectrum. Most of SpecTcl's commands return values in a way that allows them to be manipulated by other Tcl commands. This makes writing scripts that extend SpecTcl's functionality rather simple.
Suppose, for example, you just wanted to get spectrum names, types and parameters. Carefully type the following to the TkCon window:
foreach spectrum [spectrum -list] {
set name [lindex $spectrum 1]
set type [lindex $spectrum 2]
set parameters [lindex $spectrum 3]
lappend description [list $name $type $parameters]
}
You may have been expecting something to happen.. all you've done is produce
a variable named description that contains the desired information.
now puts $description. That gets you the not very useful:
{slot10.channel00 1 slot10.channel00} {slot10.channel00-vs-slot10.channel01
2 {slot10.channel00 slot10.channel01}} {slot10.channel01 1 slot10.channel01}
{slot10.channel02 1 slot10.channel02} {slot10.channel03 1 slot10.channel03}
{slot10.channel04 1 slot10.channel04} {slot10.channel05 1 slot10.channel05}
{slot10.channel06 1 slot10.channel06} {slot10.channel07 1 slot10.channel07} {
slot10.channel08 1 slot10.channel08} {slot10.channel09 1 slot10.channel09} {slot10.channel10
1 slot10.channel10} {slot10.channel11 1 slot10.channel11} {slot10.channel12
1 slot10.channel12} {slot10.channel13 1 slot10.channel13} {slot10.channel14 1
slot10.channel14} {slot10.channel15 1 slot10.channel15} {slot10.channel16 1 slot
10.channel16} {slot10.channel17 1 slot10.channel17} {slot10.channel18 1 slot10.
channel18} {slot10.channel19 1 slot10.channel19} {slot10.channel20 1 slot10.channel20
} {slot10.channel21 1 slot10.channel21} {slot10.channel22 1 slot10.channel22}
{slot10.channel23 1 slot10.channel23} {slot10.channel24 1 slot10.channel24} {slot10.
channel25 1 slot10.channel25} {slot10.channel26 1 slot10.channel26} {slot10.channel27 1
slot10.channel27} {slot10.channel28 1 slot10.channel28} {slot10.channel29 1 slot10.channel29
} {slot10.channel30 1 slot10.channel30} {slot10.channel31 1 slot10.channel31}
or something very much like this depending on the width of yout TkCon window.
Let's make this a bit more useful, type:
foreach item $description {
puts [format "%-38s %3s %-25s" \
[lindex $item 0] [lindex $item 1] [lindex $item 2]]
}
This will output something a bit more interesting:
slot10.channel00 1 slot10.channel00
slot10.channel00-vs-slot10.channel01 2 slot10.channel00 slot10.channel01
slot10.channel01 1 slot10.channel01
slot10.channel02 1 slot10.channel02
slot10.channel03 1 slot10.channel03
slot10.channel04 1 slot10.channel04
slot10.channel05 1 slot10.channel05
slot10.channel06 1 slot10.channel06
slot10.channel07 1 slot10.channel07
slot10.channel08 1 slot10.channel08
slot10.channel09 1 slot10.channel09
slot10.channel10 1 slot10.channel10
slot10.channel11 1 slot10.channel11
slot10.channel12 1 slot10.channel12
slot10.channel13 1 slot10.channel13
slot10.channel14 1 slot10.channel14
slot10.channel15 1 slot10.channel15
slot10.channel16 1 slot10.channel16
slot10.channel17 1 slot10.channel17
slot10.channel18 1 slot10.channel18
slot10.channel19 1 slot10.channel19
slot10.channel20 1 slot10.channel20
slot10.channel21 1 slot10.channel21
slot10.channel22 1 slot10.channel22
slot10.channel23 1 slot10.channel23
slot10.channel24 1 slot10.channel24
slot10.channel25 1 slot10.channel25
slot10.channel26 1 slot10.channel26
slot10.channel27 1 slot10.channel27
slot10.channel28 1 slot10.channel28
slot10.channel29 1 slot10.channel29
slot10.channel30 1 slot10.channel30
slot10.channel31 1 slot10.channel31
This is a bit better, but a pain to have to type each time you need it. So lets now edit a file named show.tcl to contain:
proc speclist {{pattern *}} {
set format "%-35s %3s %-25s\n"
set value [format $format Name Type Parameters]
foreach spectrum [spectrum -list $pattern] {
set name [lindex $spectrum 1]
set type [lindex $spectrum 2]
set params [lindex $spectrum 3]
append value [format $format $name $type $params]
}
return $value
}
Use source to load this file as you did setup.tcl. This file contains a proc. A proc, or procedure is one way to define a new command. The command we have defined is called speclist It takes an optional parameter which is a spectrum name matching pattern defaulting to *. It returns a formatted list of the spectra that match that pattern. Let's play with this new command a bit:
speclist
Name Type Parameters
slot10.channel00 1 slot10.channel00
slot10.channel00-vs-slot10.channel01 2 slot10.channel00 slot10.channel01
slot10.channel01 1 slot10.channel01
slot10.channel02 1 slot10.channel02
slot10.channel03 1 slot10.channel03
slot10.channel04 1 slot10.channel04
slot10.channel05 1 slot10.channel05
slot10.channel06 1 slot10.channel06
slot10.channel07 1 slot10.channel07
slot10.channel08 1 slot10.channel08
slot10.channel09 1 slot10.channel09
slot10.channel10 1 slot10.channel10
slot10.channel11 1 slot10.channel11
slot10.channel12 1 slot10.channel12
slot10.channel13 1 slot10.channel13
slot10.channel14 1 slot10.channel14
slot10.channel15 1 slot10.channel15
slot10.channel16 1 slot10.channel16
slot10.channel17 1 slot10.channel17
slot10.channel18 1 slot10.channel18
slot10.channel19 1 slot10.channel19
slot10.channel20 1 slot10.channel20
slot10.channel21 1 slot10.channel21
slot10.channel22 1 slot10.channel22
slot10.channel23 1 slot10.channel23
slot10.channel24 1 slot10.channel24
slot10.channel25 1 slot10.channel25
slot10.channel26 1 slot10.channel26
slot10.channel27 1 slot10.channel27
slot10.channel28 1 slot10.channel28
slot10.channel29 1 slot10.channel29
slot10.channel30 1 slot10.channel30
slot10.channel31 1 slot10.channel31
We get a nice formatted list of all the spectra.
Let's get a bit fancier... here's a dialog:
speclist *channel0*
Name Type Parameters
slot10.channel00 1 slot10.channel00
slot10.channel00-vs-slot10.channel01 2 slot10.channel00 slot10.channel01
slot10.channel01 1 slot10.channel01
slot10.channel02 1 slot10.channel02
slot10.channel03 1 slot10.channel03
slot10.channel04 1 slot10.channel04
slot10.channel05 1 slot10.channel05
slot10.channel06 1 slot10.channel06
slot10.channel07 1 slot10.channel07
slot10.channel08 1 slot10.channel08
slot10.channel09 1 slot10.channel09
Using the pattern paramter allowed us to select a subset of the spectra
to be listed. This is because the spectrum -list command
accepts a pattern with optional wild cards.
set a [speclist *channel0*]
Name Type Parameters
slot10.channel00 1 slot10.channel00
slot10.channel00-vs-slot10.channel01 2 slot10.channel00 slot10.channel01
slot10.channel01 1 slot10.channel01
slot10.channel02 1 slot10.channel02
slot10.channel03 1 slot10.channel03
slot10.channel04 1 slot10.channel04
slot10.channel05 1 slot10.channel05
slot10.channel06 1 slot10.channel06
slot10.channel07 1 slot10.channel07
slot10.channel08 1 slot10.channel08
slot10.channel09 1 slot10.channel09
% set a
Name Type Parameters
slot10.channel00 1 slot10.channel00
slot10.channel00-vs-slot10.channel01 2 slot10.channel00 slot10.channel01
slot10.channel01 1 slot10.channel01
slot10.channel02 1 slot10.channel02
slot10.channel03 1 slot10.channel03
slot10.channel04 1 slot10.channel04
slot10.channel05 1 slot10.channel05
slot10.channel06 1 slot10.channel06
slot10.channel07 1 slot10.channel07
slot10.channel08 1 slot10.channel08
slot10.channel09 1 slot10.channel09
In this final example, we've taken the result of the speclist command and assigned it to the variable a which we then displayed a second time using the command set a.
TkCon also has several menus. The File menu allows you to source files, Edit does the usual copy, cut paste. History gives access to the recent command history so that you can easily repeat prior commands. The Packages entry of Interp allows you to located and load Tcl library packages.
Our SpecTcl GUI window is quite simple looking. Just a strip of buttons:
Note that the bottomost of these is the button we created in our setup.tcl script. To attach SpecTcl to the online system, click that button. Note that as analysis is started, the top button label is changed to . In general it is a bad idea to stop analying on line data.
The SpecTcl GUI is completely tailorable. Let's make a status line that shows
us how many buffers SpecTcl has analyzed from the current run. SpecTcl maintains
this information for us in a variable called BuffersAnalyzed.
To build this gui, we must:
Create a frame to hold our piece of he GUI.
Create two labels, one which contains the fixed text: Buffers Analyzed. The second will track the BuffersAnalyzed variable value.
Layout the widgets inside the frame and layout the frame in our GUI.
The following Tcl/Tk does the trick (you can either type it directly in to TkCon or edit it into a file and source it in.
Hopefully this simple example will give you an idea how easy it is to use Tcl/Tk to build user interface extensions, or to layout your entire GUI.The Xamine window provides a viewport into your data. Xamine is actually a separate application, a display server for spectra. SpecTcl creates spectra in an agreed upon form in a shared memory segment, and Xamine displays/interacts with these spectra. All of Xamine's interactions are read-only to the spectra.
The Xamine window looks like this:
The window is divided in four strips from top to bottom:
A menu bar that provides access to most, if not all of the Xamine functionality.
A large central area; in which the spectra will be displayed.
A status bar that provides information about where the pointer is.
A set of boxes containing buttons for many of the more frequently used functions.
Click the button. A dialog listing the set of spectra that have been loaded into the Xamine shared memory region (using sbind). Double click on SLOT10.CHANNEL00 to display that spectrum, and the dialog is dismissed.
Usually, it is convenient to view more than one spectrum at a time. Click on the Button. In the dialog that appears, select 2 rows, and 3 columns, then click . Xamine now subdivides the display area as described. At any time, one of the panes in the display area is selected. That pane has a pushed in appearance. The and buttons load spectra into the panes. More about these in the next subsection.
Double clicking a pane expands it to take up the entire spectrum window. Double clicking again returns you to the subdivided layout. The Xamine window can be resized. When resized, the bulk of the size change affects the spectrum display area. Xamine has intelligent titling and axis display algorithms. It attempts to display as much ancillary information as possible, using font selection and then prioritized information reduction as the avaialble space for annotation shrinks.
We have seen that it is possible to divide the Xamine spectrum display area and display several spectra simultaneously. The process of making a setup like this is called creating a window definition. Xamine has a few features that make creating a window definition easy.
Furthermore it is possible to create window definition files. A window definition file is a file to which a window definition can be stored, and from which it can be restored later on.
Let's look first at how to build window definitions. Subdivide the Xamine window int 5 rows by 7 columns (we have 33 spectra to display). How do we load this grid of spectra up, most efficiently.
As you know, you can click on a pane to select it, click on , then double click a spectrum. That's 4 clicks to chose a spectrum, much too hard.
Click on the upper left pane. Click the button (just below the button). Double click SLOT10.CHANNEL00. That spectrum is loaded into the selected pane and the selection moves to the next pane on the row. Successivly double click on SLOT10.CHANNEL01 through SLOT10.CHANNEL06. When the selected pane is at the end of a row, it drops down to the leftmost pane in the next row. This allows you to create a window definition very efficiently. Double click SLOT10.CHANNEL01 through SLOT10.CHANNEL31, then double click on the 2-d spectrum name: SLOT10.CHANNEL00-VS-SLOT10.CHANNEL01.
To Save this window definition:
Click the -> menu item.
Enter a filename for the window file e.g. mywindows.win then either Click the or hit the Enter key.
To restore this window file,
Click the -> menu item.
Double click on the window file you created (e.g. mywindows.win) to load it.