E Demonstration – the INDEMO Program

 E.1 Fortran source

The following pages contain a listing of the Fortran source for a program called INDEMO. It produces a plot of a spiral, with a logarithmic y-axis and an x-axis with the scale running right to left. The objective is to demonstrate the SNX_CURS input routine, and to show that data coordinates can be read in and used. Again, the source is distributed with the SNX software: in the directory NCAR_DIR on VAX/VMS and /star/starlink/lib/snx/examples on UNIX.

On VAX/VMS, this program may be compiled, linked and run using the command sequence

  $ FORTRAN NCAR_DIR:INDEMO
  $ LINK INDEMO, NCAR_DIR:SNX_LINK/OPT, STAR_LINK/OPT
  $ RUN INDEMO

On UNIX, this program may already be installed in directory /star/bin/examples/snx. If it has been deinstalled and removed to save space, you can copy the entire source directory to a scratch dircetory, and with the SYSTEM environment variable set appropriately, build and run it thus:

  % setenv SYSTEM alpha_OSF/1
  % ./mk indemo
  % ./indemo

Give the SGS workstation name in response to the “Workstation?" prompt. The graph will be plotted, and the cursor will appear. Adjust the cursor position and press the “hit" key (normally numeric 1 and 2 on the keyboard). A cross will be drawn at the cursor position, and next to it a message giving the data coordinates at that point. The program will exit when a cursor “hit" is made outside the plot bounds, or a zero cursor choice entered.

E.1 Fortran source

        PROGRAM INDEMO
  
  *+
  *
  *     - - - - - - -
  *      I N D E M O
  *     - - - - - - -
  *
  *   Demonstrate cursor input following NCAR AUTOGRAPH plot.
  *
  *   P T Wallace   Starlink   May 1987
  *   P C T Rees    Starlink   April 1992
  *      Added exit on cursor choice 0.
  *
  *+
  
        IMPLICIT NONE
  
        INTEGER I,N
        LOGICAL LOOP
        REAL V,T,X(1000),Y(1000),XU,YU,XG,YG,XA(1),YA(1)
        CHARACTER S*13
  
        REAL snx_AGUGX,snx_AGUGY
  
  
  
  *  Fill the data arrays.
        XU = 300.0
        YU = 400.0
  
        DO I=1,1000
           V = REAL(I-1)
           T = V/50.0
           X(I) = XU + V*COS(T)/2.0
           Y(I) = YU + V*SIN(T)/2.5
        END DO
  
  *  Open NCAR/SGS/GKS.
        CALL snx_AGOP
  
  *  X axis is reversed linear.
        CALL AGSETI(’X/ORDER.’,1)
  
  *  Y axis is logarithmic.
        CALL AGSETI(’Y/LOG.’,1)
  
  *  Plot the graph.
        CALL snx_EZRXY(X,Y,1000,’Spiral’,’x’,’y’)
  
  *  Loop - mark positions on plot.
        LOOP = .TRUE.
  
        DO WHILE (LOOP)
  
  *     Input a cursor position.
           CALL snx_CURS(XU,YU,N)
  
  *     Check cursor choice and finish if zero.
           IF (N.LE.0) THEN
  
  *        Finish.
              LOOP=.FALSE.
           ELSE
  
  *        Transform to grid coordinates.
              XG = snx_AGUGX(XU)
              YG = snx_AGUGY(YU)
  
  *        Inside or outside grid window?
              IF (XG.LE.1.0.AND.XG.GE.0.0.AND.
       :          YG.LE.1.0.AND.YG.GE.0.0) THEN
  
  *           Inside - mark the selected position.
                 WRITE (S,’(’’(’’,F5.1,’’,’’,F5.1,’’)’’)’) XU,YU
                 XA(1) = XU
                 YA(1) = YU
                 CALL POINTS(XA,YA,1,-2,0)
                 CALL snx_WRTST(XG+0.02,YG,S,0.02,0,-2)
              ELSE
  
  *           Outside - finished.
                 LOOP = .FALSE.
              END IF
           END IF
  
  *  Next position
        END DO
  
  *  Wrap up
        CALL sgs_CLOSE
  
        END