next up previous 229
Next: Token delimiters.
Up: Formatting Transformation Functions
Previous: Formatting Transformation Functions

Example 8. A ``packaged'' transformation.

This illustrates the use of TRN_STOKR in a subroutine to ``package up'' the creation of a simple [ $1 \leftrightarrow 1$] transformation which contains several adjustable numerical parameters. The same principles can be followed to write routines for creating a variety of specialised transformations.

      SUBROUTINE LINEAR( SCALE, ZERO, ELOC, NAME, LOCTR, STATUS )

*  Declare variables.
      INCLUDE 'SAE_PAR'
      INTEGER STATUS, NSUBS
      REAL SCALE, ZERO, INVSCL
      CHARACTER * ( * ) ELOC, NAME, LOCTR
      CHARACTER FOR( 1 ) * 80, INV( 1 ) * 80

*  Check STATUS.
      IF ( STATUS .NE. SAI__OK ) RETURN

*  Formulate the forward transformation function.
      FOR( 1 ) = 'out = ( in - zero ) * scale'                 [1]
      CALL TRN_STOKR( 'zero', ZERO, FOR( 1 ), NSUBS, STATUS )
      CALL TRN_STOKR( 'scale', SCALE, FOR( 1 ), NSUBS, STATUS )

*  If possible, formulate the inverse transformation function.
      IF( SCALE .NE. 0.0 ) THEN
         INVSCL = 1.0 / SCALE
         INV( 1 ) = 'in = ( out * inv_scale ) + zero'          [2]
         CALL TRN_STOKR( 'zero', ZERO, INV( 1 ), NSUBS, STATUS )
         CALL TRN_STOKR( 'inv_scale', INVSCL, INV( 1 ), NSUBS, STATUS )

*  Inverse is undefined...
      ELSE
         INV( 1 ) = 'in'                                       [3]
      ENDIF

*  Create the transformation.
      CALL TRN_NEW( 1, 1, FOR, INV, '_REAL:',                  [4]
     :              'Shift and linear scaling: in --> out',
     :              ELOC, NAME, LOCTR, STATUS )

      END

Programming notes:

  1. The forward transformation function is assigned and the numerical parameters SCALE and ZERO are substituted into it.

  2. If possible, the inverse transformation function is defined similarly. Note that the reciprocal of SCALE is taken so that multiplication may be used in preference to the less efficient division operation.

  3. If SCALE is zero, then the inverse mapping cannot be defined so the inverse transformation function is assigned a value to indicate this.

  4. The transformation is created.



next up previous 229
Next: Token delimiters.
Up: Formatting Transformation Functions
Previous: Formatting Transformation Functions

TRANSFORM Coordinate Transformation Facility
Starlink User Note 61
R.F. Warren-Smith
12th January 2006
E-mail:starlink@jiscmail.ac.uk

Copyright © 2000 Council for the Central Laboratory of the Research Councils