UNIDATA

Investigations of Tcl/Tk in Building a Graphical User Interface for McIDAS-X

Tom Yoksas

Unidata Program Center
University Corporation for Atmospheric Research
Boulder, Colorado

Susan Gorski, David Santek

Space Science and Engineering Center
University of Wisconsin-Madison
Madison, Wisconsin

Introduction

"The mission of the Unidata1 Program is to empower universities, through innovative applications of current computing and networking technology, to make the best use of atmospheric and related data for enhancing education and research (Fulker, 1992)."

As part of its mission, Unidata distributes four UNIX-based meteorological display and analysis packages to its user community: McIDAS-X (the Man-computer Interactive Data Access System for X Windows, developed by the Space Science and Engineering Center (SSEC) of the University of Wisconsin-Madison), GEMPAK (the GEneral Meteorological PAcKage originally developed by the Severe Storms Division of the Goddard Space Flight Center of NASA), WXP (the Weather Processor developed by Purdue University), and Ynot (developed by MacDonald Dettwiler and Associates Ltd.).

Many users have requested that Unidata standardize the method of interaction with these packages by building an intuitive, interactive, mouse-driven, graphical user interface (GUI) that will allow seamless access to all of these packages by a full spectrum of users, novice to expert. The development of a common GUI for Unidata applications has long been an area of interest by both Unidata and its various advisory committees. To date, only one Unidata package, Ynot, is distributed with a GUI. This paper focuses on ongoing, exploratory efforts at Unidata and the SSEC to build a GUI for the McIDAS-X package.

Comments by community representatives at several Unidata advisory committee meetings indicate that users want to play an integral role in the design if not implementation of a GUI for their favorite application.

Additional comments by many of the same users indicate that GUI elements considered critical for one class of users was not desirable for others. This conflict, combined with the numerous efforts in the university and commercial community to develop easy-to-use application interfaces indicates that it is probable that no single GUI will be acceptable to all users. What is needed, rather, is a toolkit that allows individual users to customize a "standard" GUI to suite their own institutional and personal needs. The search for such a toolkit led Unidata to explore the Tcl/Tk package developed by John Ousterhout of UC Berkeley. Tcl/Tk is freely-available by anonymous FTP from sprite.berkeley.edu.

Overview of Tcl/Tk

The following paraphrases descriptions of Tcl/Tk by John Ousterhout (Ousterhout, 1991,1992,1993):

Tcl, the Tool Command Language (pronounced "tickle"), and Tk, the Tool Kit (pronounced "tee-kay"), provide a system for developing and using graphical user interface applications. Tcl is a simple scripting language that is useful for controlling and extending applications. It provides generic programming facilities, such as internal variables, loop and logical flow constructs, mathematical and arithmetic operations, and procedures that are useful for a variety of applications. Tcl is also embeddable: its command interpreter is implemented as a library of C procedures that can easily be incorporated into user applications. Each application can extend the core Tcl features with additional commands specific to that application.

Tk is one of the earliest and most useful extensions to Tcl. Tk extends the core Tcl facilities with additional commands for building user interfaces. By using Tk, one can construct graphical user interfaces by writing Tcl scripts instead of C code. Like Tcl, Tk is implemented as a library of C procedures so it too can be embedded in user applications. User-developed routines can also be used to extend the base Tk features with such things as new user-interface widgets and geometry managers.

Tcl/Tk provide several benefits to application developers and users alike (Ousterhout, 1993):

Tcl's set of built-in commands is listed below.

Tcl Built-In Commands

process control break, case, continue, eval, for, foreach, if, while
manipulation of variables and procedures global, proc, return, set, unset
array and list manipulation array, concat, index, join, lappend, lindex, linsert, list, llength, lrange, lreplace, lsearch lsort, split, uplevel, upvar
expressions expr
string manipulation append, format, scan, string
file manipulation close, file, flush, gets, glob, open, print, puts, read, seek, source, tell
subprocesses exec
error handling catch, error
regular expressions regexp, regsub
mathematical functions abs, acos, asin, atan, atan2, ceil, cos, cosh, double exp, floor, fmod, hypot, int, log, log10, pow, round, sin, sinh, sqrt, tan, tanh
arithmetic operators full compliment of arithmetic, logical, and bit-wise operators
miscellaneous cd, exit, history, info, pwd, rename, time, trace

Tk extends Tcl functionality with graphical components, referred to as widgets, and X Window event handlers. Some examples of Tk widgets are frames, labels, buttons (simple, check, and radio), menus (pull-down, pop-up, and cascaded), listboxes, text entries, scrollbars, text, canvases, scales, and messages. Tk widgets are organized into classes whose elements have similar appearances and behaviors The built-in Tk widget classes implement the Motif (TM) look-and-feel standard specified by the Open Software Foundation. Users can easily add new Tk widgets using templates provided in the Tcl/Tk package.

Tk widgets can be arranged into appealing applications using Tk's geometry manager. Tk applications are controlled by two different types of processes: initialization scripts and event handlers. Typical Tk applications will be composed of a large collection of event handlers and the Tcl procedures that they invoke. Tk applications are, therefore, event-driven: the application can present an interface that allows the user to decide what to do next.

One of the first Tk applications, wish (which stands for windowing shell), combines all of the Tcl and Tk built-in commands. wish can be used to interactively prototype both user interface look-and-feel and functionality. The Tcl/Tk functionality provided by wish is most easily incorporated in applications supporting a command-line interface (like McIDAS-X) by use of the exec built-in.

Even though Tcl/Tk is easy to use, some users will, no doubt, be reluctant to modify GUI templates much less create entirely new interfaces. This dilemma has been addressed in part by Sven Delmas of the Victoria University of Wellington in New Zealand. Delmas developed the Tcl/Tk interactive interface builder, XF. XF provides a high level interface for creating, configuring, and arranging widgets, and creating event bindings for the widgets. Since development is done while the application is active, the user can immediately view and test the new interface components thus speeding the design cycle. Unidata is investigating XF for its own McIDAS-X user interface work.

McIDAS-X environment and command structure

McIDAS-X operates as a self-contained environment in which a user executes and receives output from large collection of McIDAS-X commands. The McIDAS-X environment is defined by a collection of routines that inter-communicate through shared system memory referred to as User Common. Execution of individual McIDAS-X commands is not limited, however, to this environment. Since input to and output from routines are accomplished through standard VO. McIDAS-X commands may be executed from outside of the McIDAS-X environment (e.g. from the UNIX shell) as long as the routines are provided the shared memory segment address that they will need to access.

Each instance of McIDAS-X, a so-called McIDAS-X session, is associated with a unique shared memory segment. Every session initiated from a common directory is also assigned a unique, integer, terminal number which identifies the session. When a McIDAS-X session is started several files, whose names' contain the terminal number, are created in the session's startup (~user/ mcidas/data) directory. One of these files, named UCTERM.nnn (nnn refers to the terminal number), contains the address of the shared memory segment that will be used by all of the McIDAS-X applications run in the session. Since this file is read accessible (i.e. it is not locked), all of the information needed to run McIDAS-X commands outside of the McIDAS-X environment is available for use for use by Tcl/Tk and/or wish scripts. This implies that the user can run McIDAS-X commands and extract output from those commands in a strictly non-McIDAS-X environment as long as a McIDAS-X session exists.

Tcl/Tk script control of McIDAS-X applications

The form of an interactive wish script that can run a single McIDAS-X command is remarkably simple. The user need only specify the terminal number of the session in which the wish initiated McIDAS-X command is to run; retrieve the address of the McIDAS-X session's shared memory segment from UCTERM.nnn; describe the look of the Tk window that solicits input; bind the input result to a Tcl variable; and exec the desired McIDAS-X process.

The following wish script demonstrates how to load a satellite image by using the McIDAS-X DF command:

#!/usr/local/bin/wish -f
set terminal [lindex $argv 0]
set file [format "UCTERM.00%s" $terminal]
set fid [open $file r]
seek $fid 4
set uc [read $fid 4]
set MCPIPE [format "McText%sW0" $terminal]
label .label -text "Enter McIDAS AREA num"
entry .num -width 10 -relief sunken -textvariable num
pack .label .num -side left -padx 1m -pady 2m
bind .num  {exec echo DF $num 1 | ../bin/df.mx $uc \
>$MCPIPE &
exit}

This script:

Of course, McIDAS-X provides the user with a myriad of capabilities on how the image should be loaded, which enhancement and stretch tables to use during loads, image centering and scaling options, etc. Adding these capabilities to a easy-to-use GUI widget is simple in concept, but voluminous in implementation.

Even though the wish script used to generate this interface contains more complex functionality than a simple example of cascading menus and slider bar widgets, and is several hundred lines in length, it is really no more difficult in concept. Widgets soliciting user response bind input to Tcl variables which are then used to build a McIDAS-X command line which, in turn, is executed by the Tcl exec built-in.

A typical user need only spend a couple of hours learning the various features of Tcl/Tk before being able to develop simple GUIs to command-line driven applications. Development of a complete, intuitive interface to any but the most trivial function, on the other hand, can take significant amounts of time and effort but is still a relatively straightforward process. As one gains more experience in the use of Tcl/Tk, the development time for additions of new functionality to exiting GUIs or development of new GUIs is considerably lessened.

Tcl/Tk GUI development efforts

Unidata

In the summer of 1993, Unidata made available its latest release of McIDAS-X, Version 1.80. Included with the package was an implementation of the Function Key Menu system that has long been available in the McIDAS-OS2 system available from both the SSEC and Unidata. One part of the Menu system was a Motif application whose sole purpose was to solicit singular user input that would then be used in the execution of McIDAS-X commands. Building this application, askl, requires that user sites have Motif-linkable libraries on their workstations (McIDAS-X is available in source code form from Unidata). While Motif support is available on IBM RS/6000 and SGI platforms, it is not included in the standard distribution of SunOS(TM) or Solaris(TM). It is for this reason that Unidata made this application available as a statically-linked executable. A problem with distributing this application arose shortly after Unidata sites began using the Function Key Menu on a regular basis. While tests at Unidata uncovered no problem with the askl application, users complained that periodically their OpenWindows(TM) environment would be "blown away" while running askl. The cause of the problem was soon discovered to be subtle incompatibilities between OpenWindows, which was XllR4 compliant, and the Motif library in use at Unidata, which was XllRS compliant.

Instead of acquiring an X11R4 compliant implementation of the Motif linkable library (since future releases of OpenWindows will be XllRS compliant and Sun is moving from OpenLook(TM) to Motif), Unidata chose to replace the askl functionality with wish scripts. The replacement effort was, to say the least, minimal (it required about of 30 minutes of work!). The complexity of the wish scripts needed to do this were on the order of the simple script presented above. This change was offered to the Unidata McIDAS-X community in early October of 1993.

The next use of Tcl/Tk at Unidata was the replacement of the Unidata Function Key Menu with a GUI that mimicked the Version 1.80 menu's functionality. The new, simple GUI was scheduled for release by Unidata in November, 1993.

At the time that this paper was being written, several experimental GUIs (Tcl and non-Tcl based), which give users full access to McIDAS-X's functionality, were in the process of being developed both by Unidata and the SSEC (Santek, et. al., 1993).

Some of the features of the interface being designed by Unidata are a history function (allows a user to see the commands that have been issued during a McIDAS-X session), a "learn" capability (used to encapsulate sequences of user commands into easily reexecutable procedures), and a flexible on-line help facility. The online help facility investigation includes evaluation of addition of hypertext functionality that would allow users to easily view concepts that are associated with general topics.

Even though not strictly a GUI effort, Unidata is considering replacing the McIDAS-X McBASI scripting language, offered in the Unidata McIDAS-X since November of 1992, with Tcl. The major advantage that Tcl offers over McBASI is an environment that is more familiar to seasoned UNIX users and offers, through various Tcl/Tk application packages, interprocess communication capabilities.

One of the next Unidata uses of Tcl/Tk, tentatively scheduled for the spring of 1994, will be in the development of a prototype GUI for the Purdue WXP package . The purpose of this effort will be the evaluation of the possibility of building a GUI that is consistent in use across diverse application packages, in this case McIDAS-X and WXP. Unidata will keep its user community informed about this effort through its various electronic mailing lists and periodic newsletters.

SSEC

Tcl/Tk development efforts at SSEC in the Fall of 1993 were aimed at creation of library of specialized utility widgets. These widgets, developed as Tcl procedures, were being designed to provide a standard "look-and-feel" that could easily be incorporated into a variety of GUIs. Some examples of these widgets include:

SSEC is also developing Tcl/Tk GUIs for all McIDAS-X commands. These GUIs will not map one-to-one to McIDAS-X routines, however. Instead, GUIs will allow access to several routines that share similar classes of functionality. For instance, there will be one interface that will allow the user to plot surface and upper-air maps and another that would display single or loops of satellite images. The user will no longer need to remember the different McIDAS-X commands needed to produce these displays. This grouping will not eliminate the access to individual functions that many expert users need. Access to the command line invocation of individual commands will still be available.

Another innovation already in development at SSEC is GUIs that offer a range of options based on a user's perception of his or her expertise. This capability is pictured in Fig. 2 as the Low, Medium, and High buttons at the top of the DF GUI widget. Reasonable defaults will be used for options not offered to the non-expert class of users.

These experimental systems, while representing additional levels of script complexity, do not require significantly more expertise in the use of Tcl/Tk. It is hoped that both Unidata and SSEC user sites that have local expertise in UNIX shell script programming will lead the way in the development of increasingly functional interfaces that can be used throughout the McIDAS-X community.

Conclusion

Tcl/Tk is a robust package that is remarkably simple to use in implementing intuitive, mouse-driven, interactive graphical user interfaces especially for commands that support command line interfaces. Test uses of Tcl/Tk with McIDAS-X at both Unidata and the SSEC indicate that the package is complete enough to build fully functional GUIs that can be modified and extended by end users. Tcl/Tk's implementation as an interpreted language allows for rapid prototyping of GUIs' look-and-feel and functionality. Its embeddability allows for generally desired features to be integrated into individual applications where execution speed is critical. Its extendability allows for new widgets and geometry managers to be developed to fill gaps in or extend GUI functionality.

References

Fulker, D.W., 1992: Unidata: 1993 to 1998 A Proposal to the National Science Foundation, May, 1992

Santek, D.S., S. Gorski, T. Whittaker, J.T. Young, 1993: McIDAS-GUI: A Graphical User Interface for McIDAS. Preprints, Ninth Conf. on Interactive Information and Processing Systems for Meteorology, Oceanography, and Hydrology, Anaheim, AMS, 123-125.

Ousterhout, J.K., 1990: Tcl: An Embeddable Command Language, USENIX Conference Proceedings, Winter 1990, 133-146.

Ousterhout, J.K., 1991: An Xll Toolkit Based on the Tcl Language, USENIX Conference Proceedings,Winter 1991, 105-115.

Ousterhout, J.K., 1993: Tcl and the Tk Toolkit, Addison-Wesley, manuscript in preparation.

1. The Unidata Program Center is sponsored by the National Science Foundation and managed by the University Corporation for Atmospheric Research. Mention of a commercial company or product does not constitute an endorsement by the Unidata Program Center.



This page was Webified by Jennifer Philion.
Questions or comments can be sent to <support@unidata.ucar.edu>.
This page was updated on .