Applications often have to manage groups of strings in which each string represents some object. Typical examples of the contents of such groups may be:
The GRP package provides facilities for managing the storage and retrieval of strings within such groups. Applications may explicitly specify strings to be stored within a group, or instead may specify the name of a text file from which to read such strings. The contents of a group may be written out to a text file, providing an easy means of passing groups of objects between applications.
The concept of a group within GRP may be compared with an “array” structure within a high level programming language such as Fortran. Arrays are used for storing many values in a single object, with each value associated with an integer “index”. A value can be stored in, or retrieved from, a particular element of an array by specifying the index for that element. The facilities provided by the GRP package are similar. GRP allows character strings to be stored in, or retrieved from, one of several “groups” (in this sense, a “group” is the GRP equivalent of a character array). Each element within the group has an associated index, and different groups are distinguished by different “identifiers” (similar to the way that different arrays are distinguished by having different names).
GRP also provides the following features not available through the use of Fortran arrays:
you might specify the output files using a string such as:
This would cause the addition of the prefix “A_” and substitution of “TXT” for “DAT”, resulting in the output file names:
OBJECTS.LIS
the following response could be
given:
If the same editing is to be applied to a list of literal values typed in directly at the keyboard, then a response such as the following could be given:
GRP is a general purpose library which makes no attempt to attach any particular meaning or properties to the strings stored in a group. It is expected that other, more specialized libraries will be written which use GRP to handle specific types of strings (eg coordinate values, names of data files, etc). Such packages will provide additional features to handle the objects stored by GRP (eg the creation, opening and closing of data files).
The facilities of GRP are particularly useful for processing lists of text strings provided in response to a prompt. The user of an application can specify the strings literally, or can specify the name of a text file containing the strings, or can specify the editing to be used to derive them by modification of the strings stored somewhere else.
Here is a simple example of the use of GRP which illustrates the ideas of indirection and modification. In this example, each stored string corresponds to the name of a file but obviously an application could apply other interpretations. The user is prompted for a set of input file names and then prompted again for a set of output file names. Each input file is processed in some way (by routine PROC) to produce the corresponding output file. The source code that follows is not intended to provide all the information necessary to write GRP applications, but simply to give a feeling for the way GRP works:
Programming notes:
If the example above was run, the user could respond in several ways to the prompts for parameters IN_FILES and OUT_FILES. The following paragraphs illustrate the use of indirection and modification in this context. Indirection. When prompted for IN_FILES the user could reply with the following text:
This would cause the GRP package to place the two strings IC_1575_RAW
and IC_4320_RAW
in two
elements of the first group and then search for a file called NGC_OBJECTS.LIS
. If this file contains the
following two lines of text:
then the strings NGC_5128_RAW
and NGC_2534_RAW
would be added to the same group, and a search
made for the file OTHERS.LIS
. If this file, in turn, contained the two lines:
then the final group would consist of the six strings:
This illustrates the use of indirection as a means of specifying the strings to be stored in a group, and shows it being combined with the specification of literal strings, and indirections being nested.
Strings stored in a text file can be edited “on the fly” before being stored in a group. For instance, the user could give the following response to a prompt for IN_FILES:
This would cause the GRP package to read the values stored in text file NGC_OBJECTS.LIS
, replacing all
occurrences of the string “_RAW” with the string “_CAL”. If the file NGC_OBJECTS.LIS
contained the
same values as before, then the editing would also be applied to the values stored in the file
OTHERS.LIS
.
Modification. As an example of the use of “modification”, let’s suppose that the user responds to
the prompt for OUT_FILES with the string:
This would cause the application to generate six strings, based on the six strings held in the first group (see programming note (8)). The names are generated as follows
Modification can be combined with indirection and/or the specification of literal strings. For instance, the user could have replied to the prompt for OUT_FILES with the string:
This would have caused the second group to contain not only the six names described above, but also the additional names NEW_FILE and any names read from the text file LIST.DAT. In this case, the number of output files would have exceeded the number of input files and the check described in programming note (9) would fail.