next up previous contents index
Next: Using four windows Up: GRAPH EXAMPLES Previous: A script to

Read some data and plot two curves on common axes

               

The script file, graph.pcm, listed below, reads three columns of numbers from a file. The filename is passed to the script via a generalized parameter, ?1. The first column is stored in a vector called X, the second column is stored in a vector called Y1, and the third column is stored in a vector called Y2. The script then produces a graph of Y1 versus X and overlays a curve of Y2 versus X. It then replots both curves on a common scale. Identifying text is read into a string array variable called TXT and located on the plot with the graphics cursor. The date and time are also drawn on the plot, but the position and justification are pre-set, so the graphics cursor is not used. The figure below was produced by entering the command: @graph file.dat The data file, with three columns of numbers and two lines of header is also shown below.

 THIS IS ONE HEADER LINE
 THIS IS ANOTHER HEADER LINE
 1.1  2.2  -3.3
 1.2  2.4  -3.6
 1.3  2.6  -4.6
 1.4  3.1  -5.7
 1.5  4.5  -6.2         
 1.6  5.1  -7.9

2curves
                     
 ! script file  graph.pcm
 !
 READ\TEXT\CONTINUE ?1\[1:2] TXT ! read string array variable from lines 1 and 2
                                 !   and don't close the file after
 READ ?1 X Y1 Y2                 ! read vector data (starting in line 3)
 GRAPH X Y1                      ! plot data with axes
 SET LINTYP 10                   ! change line type
 GRAPH\-AXES X Y2                ! overlay a curve
 REPLOT                          ! replot on common scale
 TEXT TXT[1]                     ! draw the first text string
 TEXT TXT[2]                     ! now the second string
 SET
   %TXTHIT 1.5                   ! set text height to 1.5% of the window height
   %XLOC 95                      ! set text x location to 95% of window width
   %YLOC 2                       ! set text y location to 95% of window height
   CURSOR -3                     ! set text justification to right justification
                                 ! blank line to finish SET command
 TEXT DATE//` '//TIME            ! plot the date and time, not positioned interactively
 DEFAULTS                        ! reset program defaults