next up previous 229
Next: Transforming 2-Dimensional Coordinate Data
Up: Transforming 1-Dimensional Coordinate Data
Previous: Transforming 1-Dimensional Coordinate Data

Example 4. Plotting a graph of a user-specified function.

In the following, TRN_TR1R is used to generate data for a graph. The function to be plotted is specified by the user via an expression obtained through the ADAM parameter system. For instance, if the user entered:

X*EXP(-4.4*X)

then a graph of the function $y=xe^{-4.4x}$ would be plotted over the range $0\le x\le 1$.

\verb#*  Declare variables.
      INCLUDE 'SAE_PAR'
      INTEGER NPTS
      PARAMETER ( NPTS = 1000 )
      INTEGER STATUS, ID, IPOINT
      REAL X( NPTS ), Y( NPTS )
      CHARACTER EXPRS * 80, FOR( 1 ) * 82, INV( 1 ) * 1
      CHARACTER * ( DAT__SZLOC ) LOCTR

*  Obtain an expression and formulate the transformation functions.
      CALL PAR_GET0C( 'EXPRESSION', EXPRS, STATUS )           [1]
      FOR( 1 ) = 'Y=' // EXPRS
      INV( 1 ) = 'X'

*  Create a temporary transformation and compile it.
      CALL TRN_NEW( 1, 1, FOR, INV, '_REAL:',                 [2]
                    'X --> f( X )', ' ', ' ', LOCTR, STATUS )
      CALL TRN_COMP( LOCTR, .TRUE., ID, STATUS )

*  Set up the X values, then transform to yield the Y values.
      DO 1 IPOINT = 1, NPTS
         X( IPOINT ) = REAL( IPOINT - 1 ) / REAL( NPTS - 1 )
    1 CONTINUE
      CALL TRN_TR1R( .FALSE., NPTS, X, ID, Y, STATUS )        [3]

*  Plot the graph and clean up.
      CALL GPL( NPTS, X, Y )                                  [4]
      CALL DAT_ANNUL( LOCTR, STATUS )                         [5]
      CALL TRN_ANNUL( ID, STATUS )

Programming notes:

  1. An expression is obtained via the parameter system and used to formulate suitable transformation functions. Only the forward mapping is specified.

  2. A temporary transformation is created (TRN_NEW) and is then compiled (TRN_COMP).

  3. After generating the X values, TRN_TR1R is called to apply the compiled mapping, thereby generating the corresponding Y values. The BAD argument is set to .FALSE. since there are no bad input coordinates.

  4. A graph is plotted using the GKS polyline routine GPL. It is assumed that a suitable coordinate system has been established.

  5. Lastly, a clean up is performed by annulling the temporary transformation (DAT_ANNUL) and the compiled mapping (TRN_ANNUL - described later in Section [*]).



next up previous 229
Next: Transforming 2-Dimensional Coordinate Data
Up: Transforming 1-Dimensional Coordinate Data
Previous: Transforming 1-Dimensional Coordinate Data

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

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