Next: Datastream Compression for IRAF Image Display
Previous: The Distributed Processing Library (DPL)
Table of Contents --- Search --- PS reprint


Astronomical Data Analysis Software and Systems V
ASP Conference Series, Vol. 101, 1996
George H. Jacoby and Jeannette Barnes, eds.

Parsley: a Command-Line Parser for Astronomical Applications

William Deich

Netherlands Foundation for Research in Astronomy, P.O. Box 2, 7990 AA Dwingeloo, The Netherlands

Abstract:

Parsley is a sophisticated keyword+value parser, packaged as a library of routines that offers an easy method for providing command-line arguments to programs. It makes it easy for the user to enter values, and it makes it easy for the programmer to collect and validate the user's entries. Parsley is tuned for astronomical applications: for example, dates entered in Julian, Modified Julian, calendar, or several other formats are all recognized without special effort by the user or by the programmer; angles can be entered using decimal degrees or dd:mm:ss; time-like intervals as decimal hours, hh:mm:ss, or a variety of other units. Vectors of data are accepted as readily as scalars.

1. Introduction

Parsing command lines and interpreting optional and required arguments is a mundane but essential part of many programs. Parsley is a library of routines that aims to provide a consistent user interface across applications, good command-line help, and plenty of convenience features to aid both the user and programmer.

Both simple and complex command-line parsers have been written in the past. Perhaps the most familiar of these is getopt(3), a routine that parses single-letter option strings, including options that require a single argument. Of growing popularity is the GNU version of the same routine, which allows long option names. Yet neither of these handles vectors of data, and they don't address the common problems of providing help information or simple argument-validation checking (such as verifying that an argument is an integer). Public-domain packages have been written which do address some of these problems, but they are generally written for C or C++ applications, and are not easily called from Fortran programs.

2. Design Goals

Parsley was designed with two goals in mind: to make it easier for users to enter arguments on the command line, and to make it easier for programs to collect and validate the arguments. In its very first incarnation (an afternoon's programming), the goal was modest: to provide support for vectors, and to provide builtin help.

Parsley has grown greatly since then, in order to provide many more user-friendly features. Unfortunately, some of this growth has required a larger programming interface, which takes away from the goal of programming ease. However, by carefully maintaining sensible defaults, parsley makes sure that programs never have to call any but the basic interface. Access to the special features is obtained through ancillary function calls.

3. Consistency and Convenience for Users

The emphasis on ease of use has endowed parsley with a very large number of features which cannot all be covered in this brief space, so below are listed just some of its user-interface capabilities.

4. Files and Commands with Parsley Input

Parsley goes to some effort to make sure it can read files as easily as command lines. At any point, you may place an argument of the form @ filename (the whitespace is optional), in which case the file contents are ``interpolated'' into the input. The effect is much the same as if you typed the contents of the file in place of the @ filename string. Some special strings that may be used in place of the filename are:

 
 -- 	        read standard input;

< d or <& d read from file descriptor d (a digit).

| command interpolate the output of the given shell command.

Otherwise, if the filename isn't an existing file, parsley will apply its smart filename guessing rules. Frequently, a series of files will be named something like scan499050001.dat, scan499050002.dat, etc. A typical parsley program will receive the correct filename if the user simply enters 1.dat, 2.dat, etc. (or even just types `` 1,'' `` 2,'' etc.).

5. Consistency and Convenience for Programmers

Parsley not only makes the user's life a bit easier, it also simplifies the programmer's task through a variety of mechanisms.

Again, only a subset of parsley's features can be summarized here.

6. Future Directions

Parsley's most important evolution for the near future is to provide a graphical user interface. It already knows enough to automatically generate a good menu-based interface, and it is requires only a few more routines to give the programmer more detailed control over the presentation of the graphical interface to the user. The user will be presented a window with a nicely (nested) menus, and a ``go'' button to start the program running; standard output and standard error can either go to a subwindow or to the original location from which the program was started.

Two less-visible changes are also in the works. First, parsley's design makes it inefficient when reading large arrays, and its internal design must be overhauled so that it can process these many times faster than it currently does. Second, parsley will be modified so that it can handle arbitrarily complex structures of data, not merely arrays of atomic types.

Parsley is available for anonymous ftp from
ftp.nfra.nl:pub/outgoing/will/parsley- version.tar.gz.


Next: Datastream Compression for IRAF Image Display
Previous: The Distributed Processing Library (DPL)
Table of Contents --- Search --- PS reprint
Wed Jul 3 07:37:50 MST 1996