Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.adass.org/adass/proceedings/adass96/reprints/eliasn.pdf
Дата изменения: Wed Jan 14 23:21:09 1998
Дата индексирования: Tue Oct 2 11:42:35 2012
Кодировка:

Поисковые слова: http astrokuban.info astrokuban
Astronomical Data Analysis Software and Systems VI ASP Conference Series, Vol. 125, 1997 Gareth Hunt and H. E. Payne, eds.

Tcl- and [Incr tcl]- Based Applications for Astronomy and the Sciences
Nicholas M. Elias I I United States Naval Observatory, Navy Prototype Optical Interferometer, 3450 Massachusetts Avenue NW, Washington, DC 20392-5420, e-mail: nme@fornax.usno.navy.mil Abstract. Tcl is a shell/script language used to create b oth instrumental control systems and interactive data reduction programs. It has extensions for creating GUI (Tk) and ob ject-oriented ([incr tcl]) applications. Several Tcl-based tools that may b e used for astronomical and other scientific applications have b een created and are discussed. One example is ptcl, which registers PGPLOT functions as Tcl commands, creating a p owerful interactive plotting package. The Tcl-astronomy WWW homepage and ma jordomo mailing list server are also describ ed.

1.

Introduction

Tcl is a general-purp ose shell and script language. It is maintained by J. K. Ousterhout,1 and is available free of charge over the World Wide Web. 2 Tcl consists of a p owerful set of "core" commands that look like a cross b etween C functions and (t)csh commands. This core includes math functions, variables, associative arrays, string and list commands, flexible parsing/substitution, program control (for, while, if, etc.), regular expressions, I/O, and error handling. New Tcl commands can b e added either by "registering" C/fortran functions or using the "proc" Tcl core command. Tcl can also access UNIX shell commands without awkward escap e sequences. Therefore, Tcl may b e used as "glue" to create exciting new software packages. Tcl has some advantages over compiled languages such as fortran, C, or C++. For example, programming ideas can b e tested "on the fly" (while the application is running), decreasing development time. Also, Tcl installs on any UNIX workstation that has an ANSI-C compiler (versions for MS-Windows and Macintosh exist as well), making Tcl-based applications very p ortable. In addition, Tcl can b e bundled with other software with no restrictions or charges. 2. The Most Common Tcl Extensions, Tk and [Incr tcl]

Most scientists use X-Windows based window managers to interact with the UNIX op erating systems on their workstations. Creating graphical user inter1 2

http://www.sunlabs.com:80/people/john.ousterhout http://www.sunlabs.com/research/tcl

124

© Copyright 1997 Astronomical Society of the Pacific. All rights reserved.


Tcl- and [Incr tcl]- Based Applications

125

faces (GUIs) in C is straightforward but very time consuming, esp ecially in the debugging stage. J. K. Ousterhout's answer to this problem is the Tcl extension called Tk,3 an X-Windows toolkit. This toolkit consists mainly of window widgets registered as Tcl commands. With Tk, all the annoying details of XWindows are hidden from the programmer, allowing him/her to create GUIs in minutes to hours instead of hours to days. More complicated "mega-widgets" (typically combinations of the standard widgets) can b e created by writing C code, if desired. Like Tcl, Tk installs on any UNIX workstation (it must have X-Windows, of course) that has an ANSI-C compiler, and Tcl/Tk scripts are totally p ortable (no machine dep endent C code is necessary). Ob ject-oriented programming systems (OOPS) are b ecoming more and more prevalent b ecause of their many advantages, such as configurable class templates, inheritance, and "memb ers-only" manipulation of data (encapsulation). [Incr tcl]4 is an ob ject-oriented extension of Tcl, created by M. J. McLennan.5 In addition to the ab ove advantages, [incr tcl] is useful for grouping a large numb er of Tcl commands into classes, making a command-line application much more manageable. 3. Tcl-Based To ols and Software

Many software libraries have b een created over the years by scientists for scientists, and have b ecome standards in the community. These packages can b e made interactive using Tcl, thus extending their usefulness. For example, PGPLOT6 (the Caltech plotting package written by T. J. Pearson) library functions have b een registered as Tcl commands in the ptcl 7 package. Also, HDS8 (the Hierarchical Database System of the Starlink Pro ject) functions have b een registered as Tcl commands in the htcl 9 package. A sample ptcl script and its corresp onding PGPLOT fortran subroutine are shown in Figure 1. The Tcl script and fortran code are very similar, which means that someone who is already familiar with PGPLOT can learn ptcl quickly. Also, recall that Tcl scripts can b e modified and tested while an application is still running, which means that the Tcl procedure quad plot can b e modified more quickly than the fortran subroutine QUAD PLOT. Software for the Navy Prototyp e Optical Interferometer (NPOI) laser metrology system10 has b een created using [incr tcl], ptcl and htcl. The general structure of these programs (b ottom to top) is: low-level C code, mid-level C code, C code that registers mid-level functions as Tcl commands, and [incr
3 4 5 6 7 8 9 10

http://www.sunlabs.com/research/tcl http://www.tcltk.com/itcl/index.html#moreInfo http://www.tcltk.com/itcl/mmc.html http://astro.caltech.edu/tjp/pgplot ftp://fornax.usno.navy.mil/dist/ptcl/ptcl.html http://star-www.rl.ac.uk ftp://fornax.usno.navy.mil/dist/htcl/htcl.html http://aries.usno.navy.mil/ad/npoi/npoi.html


126

Elias

proc quad_plot {x} {

SUBROUTINE QUAD_PLOT( N, X ) INTEGER*4 N REAL*4 X(N),Y(N)

set n [llength $x] set y "" foreach x2 $x { lappend y [expr $x2*$x2] } pgbeg 0 /xs 1 1 pgsci 1 pgsch 1.3 set xmin [lindex set xmax [lindex set ymin [lindex set ymax [lindex pgenv $xmin $xmax $x 0] $x [expr $n-1]] $y 0] $y [expr $n-1]] $ymin $ymax 0 0 : pglab x y "Quad Plot" : pgsci 2 pgpt $n $x $y 17 pgsci 4 pgline $n $x $y pgend DO 10 I=1,N Y(I)=X(I)*X(I) 10 CONTINUE CALL PGBEG( 0, "/xs", 1, 1 ) CALL PGSCI( 1 ) CALL PGSCH( 1.3 )

CALL PGENV( X(1), X(N), Y(1), Y(N), 0, 0 ) CALL PGLAB( "x", "y", "Quad Plot" ) CALL PGSCI( 2 ) CALL PGPT( N, X, Y, 17 ) CALL PGSCI( 4 ) CALL PGLINE( N, X, Y ) CALL PGEND RETURN

}

END

Figure 1. A simple ptcl procedure to plot the square of an array. For the sake of comparison, a fortran subroutine using PGPLOT subroutines is also shown.

tcl] classes corresp onding to each typ e of data (logs, raw data, averaged data, configuration information, etc.). The [incr tcl] classes can b e accessed directly from the Tcl command line or from GUIs. There are two main programs in this package, FAKE (creates simulated data) and INCHWORM (laser interferometer and environmental sensor analysis). Both programs use the same C code, Tcl commands, and [incr tcl] classes; only the GUIs are different. A library of Tcl scripts are also included.


Tcl- and [Incr tcl]- Based Applications 4. Tcl and the World Wide Web

127

New "bytecode" languages, such as Java, are now b eing used to create exciting Web-based applets. Tcl can now b e considered a "Web language", since Tcl/Tk bytecode "plug-ins"11 have b een created for Netscap e, i.e., Netscap e can b e used to run Tcl/Tk applet scripts. A Tcl-astronomy homepage on the World Wide Web is now b eing maintained by the author. ptcl and htcl can b e obtained here, and links to other Tcl pages are provided as well. In addition, De Clark (de@ucolick.org) maintains a ma jordomo mailing list manager called "tclastro"; check the Tcl-astronomy home page for directions on how to subscrib e.

11

http://www.sunlabs.com/research/tcl/plugin