next up previous 204
Next: An Example of a Simple GRP Application
Up: Introduction
Previous: Introduction


Facilities Provided by GRP

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:

  1. In order to store values in a normal character array, you must assign an explicit character string to each element of the array. The GRP package provides similar facilities for storing explicit strings, but also provides facilities for reading the values to be stored from a text file. This is known as indirection; instead of providing a set of strings to be stored, you provide the name of a file which contains the strings to to be stored. For instance, if you were prompted for a list of data files to be processed, you could then respond either with the explicit name of each data file, or with the name of a text file containing a list of the names of the data files.

  2. An alternative method for specifying values to be stored in a group is by modification of the values already stored in another group. For instance, if values are to be assigned to elements 1 to 3, the actual strings stored would be obtained by taking the values stored in elements 1 to 3 of another group and applying some editing to them. The same editing is used for each element; it can include the addition of a suffix and/or a prefix, and the substitution of one sub-string with another. A typical use of this facility could be to specify a set of output files by describing the editing and the names of the corresponding input files. Thus, if a group describing the input files contained the three strings:

          OBJ1.DAT
          OBJ2.DAT
          OBJ3.DAT
    

    you might specify the output files using a string such as:

          A_*|DAT|TXT|
    

    This would cause the addition of the prefix ``A_'' and substitution of ``TXT'' for ``DAT'', resulting in the output file names:

          A_OBJ1.TXT
          A_OBJ2.TXT
          A_OBJ3.TXT
    

  3. In the above example, a group of values was obtained by copying them from another group, and then applying some specified editing. This technique of editing values can be combined with other ways of specifying the original values. For instance, to apply the same editing as above to each of the values stored in the text file OBJECTS.LIS the following response could be given:

          A_{^OBJECTS.LIS}|DAT|TXT|
    

    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:

          A_{OBJ1.DAT,OBJ2.DAT,OBJ3.DAT}|DAT|TXT|
    

  4. Groups have dynamic size (i.e. they expand in size as required to make room for new values), which is often more convenient than the fixed size of an array specified in its declaration. Thus if an application wants to process many data files, and chooses to store the file names in a GRP group, then no limit is imposed on the number of files which the user may specify.

  5. The contents of a group may be written out to a text file using a single subroutine call. This, together with the ability to read a group's contents from a text file, provides a convenient means of passing groups of objects between applications. For instance, an application may produce a text file holding the names of all the output data files it has created. A later application can then read this text file to obtain the names of the data files which it is to process.

  6. Elements within a group can be copied in a single call to another group. Duplicate names may also be purged from a group in a single call.

  7. GRP stores information about how each value within a group group was obtained (i.e. whether it was given explicitly, or by indirection, or by modification). The names of indirection files are stored, as are the identifiers for groups used as the basis for ``modified'' elements, and all this information is available to the calling application.

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).


next up previous 204
Next: An Example of a Simple GRP Application
Up: Introduction
Previous: Introduction

GRP Routines for Managing Groups of Objects
Starlink User Note 150
D.S. Berry
21st October 2009
E-mail:ussc@star.rl.ac.uk

Copyright © 2009 Science and Technology Facilities Council