Next: A complementary approach Up: The command mode Previous: General principles

Command and function shell scripts

The command lines may have three possible structures:

  1. command star-number-list: extract information for a number of stars. The datatype is implied by the command name, as for example: ric 5 21 37.
  2. command option values: make a specific action driven by the option chosen. The values may be a list of stars or cutoff parameters, as for example: ubv -a 1 2 3 or mk -d 5.
  3. command parameter comparator values: perform a selection according to the chosen parameter and limits given by values, as for example: ubv b-v -gt 1.5 or mk ref -eq 999.

Five comparators are used for making selections:

The basic principle of the command software is the following:

  1. the command parses the command line and calls the appropriate option,
  2. the option function collects the necessary elements (column headers, data file, calls a awk function and displays the output,
  3. the awk function does the real selection work.

The options have been grouped in a small number of scripts. Their names begin with opt_and end with the options they contain, as for example opt_pgine. The names of older functions are formed simply by concatenation of "op" and the option name, as for example op-d. These options often call functions written in the awk language. With this structure and task distribution, any new option added to the system is immediately available for all commands without further modifications.

Figure 4.1 gives the listing of the ubv command which handles the UBV data through some 15 options. It has been chosen as an example because nearly all commands working on photometric data are simply links to the ubv command. This script first places the command name in the variable TY and writes it in a temporary file, and sets the variable FS to the name of the corresponding data file given by the function nof (name of file). Then it tests the number of arguments on the command line. If this number is equal to zero it displays the headers of the columns and lists the whole file. If there are one or more arguments on the command line, the script first tests if the first argument is numerical. If it is, it is assumed that the arguments are stars numbers and it calls the function opt_noet and passes to it the source filename, the datatype and all arguments.

If the first argument is not numerical, the script tests if it is a known option, and calls the respective function if the answer is positive. Finally, the command line may contain parameters for a selection and the option is then the second argument, which is tested. The position of the field used to do the selection is searched in the pos.dic file located in the directory bda/dictionnaire and is then passed to the function opt_pgine.

Figure 4.2 shows the code of this central function that performs the selections on star numbers, references, and parameters. It first puts in the variable opt the option, passed as the first argument and tests its value. In all five cases the structure of the code is similar: the whole action is put in a sub-shell so that the pagination made by more or page will leave the headers apparent on the top of the first page. The first part sends the appropriate column headers; the second feeds a pipe with a data file and the data are filtered by the corresponding awk function. The result is displayed on the standard output, but a copy is sent for further use to a temporary file sortie.out located in the directory bda/tmp, which is recorded as the environment variable SRT. When the action is finished, the file sortie.out is read to count the number of stars and display a message like: "Selected stars: 10". The command zex contains a simple if test. If the file is compressed, use zcat, else use cat.

The following figure 4.3 shows a typical example of the awk functions used to perform the real work. The preamble BEGIN is used to recover the arguments of the command line. The information on the data field passed to the function are the column number (pos) of the beginning of the field, its length in character (lon) and the cutoff value (lim). The substring is extracted and compared to the limit. If the test is positive, the line is printed. The other awk functions used in opt_pginediffers by the comparaison made in the function.



Next: A complementary approach Up: The command mode Previous: General principles


mermio@
Thu Sep 1 17:27:31 MET DST 1994