3 Using LPG

 3.1 Monolith
 3.2 Tuning
 3.3 Applications
 3.4 Other Parameters
 3.5 Output Parameters

To introduce the looping facility into an applications package a number of steps are required. These affect the monolith routine, individual applications and possibly their interface files, and documentation.

3.1 Monolith

You must modify both the monolith to loop. The basic arrangement is shown below.

  *  External References:
        LOGICAL LPG_AGAIN           ! Invoke the application again?
  
             :           :           :           :           :
  
  *  Obtain the command from the environment.  This returns uppercase
  *  names.
        CALL TASK_GET_NAME( ACTION, STATUS )
  
  *  Initialise the common blocks used to control multiple invocation of
  *  applications to process lists of NDFs or catalogues.
        CALL LPG_START( VERB, DELAY, DISAB, STATUS )
  
  *  Loop round invoking the task for each set of NDFS or catalogues
  *  specified by the user.
        DO WHILE ( LPG_AGAIN( STATUS ) )
  
           IF ( ACTION .EQ. ’ADD’ ) THEN
              CALL ADD( STATUS )
  
           ELSE IF ( ACTION .EQ. ’BIND’ ) THEN
              CALL BIND( STATUS )
  
           ELSE IF...
              ...
           END IF
        END DO

LPG_AGAIN returns .TRUE. value until the list of data files is exhausted.

The additional code is the LPG_START call, the testing of LPG_AGAIN for any further files to process in a DO WHILE …END DO loop (or use IF .. END IF with a GOTO if you prefer), and the declaration of LPG_AGAIN.

3.2 Tuning

LPG_START has three tuning arguments.

There is a further tuning possibility. Some users like to be able supply the same data for output as input, although this is potentially hazardous. Here is another extract from Kappa showing how this is switched using LPG_REPLA.

  *  See if input NDFs are allowed to be overwritten by output NDFs.
        CALL KPG1_ENVDF( ’KAPPA_REPLACE’, REPL, STATUS )
        CALL LPG_REPLA( REPL, STATUS )

Variable REPL is boolean. The environment variable need just have a value, any value for this switch to be enabled.

3.3 Applications

The applications should use the routines LPG_ASSOC, LPG_PROP, LPG_CREAT, and
LPG_CREP to get identifier for NDFs, in place of the corresponding routines (i.e. replace LPG with NDF in the names) from the NDF library.

For catalogues, routines LPG_CATASSOC and LPG_CATCREAT should be used in place of CAT_ASSOC and CAT_CREAT.

On the first invocation of the application, groups of data files are obtained whenever one of the above LPG routines is used to get an NDF or CAT identifier, and an identifier corresponding to the first name in each group is returned to the application. On subsequent invocations, the names in the groups obtained during the first invocation are used without obtaining new parameter values from the environment. The index of the returned data file within each group is incremented by 1 each time the application is invoked.

3.4 Other Parameters

If an application is invoked more than once, all other parameters retain the values they had at the end of the first invocation. Applications that use this scheme should avoid having parameters with VPATH=DYNAMIC in the interface file (described in SUN/115), since the dynamic default calculated on the first invocation will then be re-used for all subsequent invocations; that may be inappropriate. A better scheme is to have VPATH=DEFAULT, PPATH=DYNAMIC and DEFAULT=!. The code should then annul any PAR__NULL status after accessing the parameter, and use the previously calculated dynamic default value for the parameter. In this scheme, the parameter value is ! at the end of the first invocation, and so retains this value for all subsequent invocations, resulting in appropriate dynamic defaults being used.

A situation in which the above suggestion does not work is if an application sometimes sets a dynamic default, and sometimes does not. In this case, you do not want to have VPATH=DEFAULT, DEFAULT=! because this would require the application to abort in the cases where there is no dynamic default available. It is probably better in these cases to have VPATH=PROMPT, PPATH=DYNAMIC and accept the fact that the user will be prompted for a parameter that was previously defaulted.

Some applications test to see if a parameter was specified on the command line, and vary their behaviour accordingly. This is achieved by checking the state of the parameter before accessing it, a state of PAR__ACTIVE (or SUBPAR__ACTIVE) indicating that the parameter already has a value. This is correct on the first invocation, but not on subsequent invocations because the first invocation may have set a parameter value, resulting in subsequent invocations thinking that the parameter was given on the command line. To avoid this, applications should call LPG_STATE in place of PAR_STATE. LPG_STATE remembers the state of the parameter on the first invocation, and returns that state, rather than the current parameter state, on subsequent invocations. The arguments are the same.

3.5 Output Parameters

One disadvantage of LPG is that any parameters written by the application, such the results of some analysis or statistics, will only record the values for the last data file processed.