      PROGRAM SPLOT
************************************************************************
* Program to produce a scatter plot of a data set stored in a file.    *
* The name of the file is passed to subroutine PLOT.  Identifiers      *
* used are:                                                            *
*     FNAME    : function to be plotted                                *
*                                                                      *
* Input:  FNAME                                                        *
* Output: User prompts and the scatter plot                            *
************************************************************************

      CHARACTER*20 FNAME

      PRINT *, 'THIS PROGRAM PRODUCES A SCATTER PLOT OF DATA POINTS'
      PRINT *, 'STORED IN A DATA FILE.  THE FIRST LINE OF THIS FILE'
      PRINT *, 'MUST CONTAIN THE MINIMUM AND MAXIMUM X VALUES AND'
      PRINT *, 'THE MINIMUM AND MAXIMUM Y VALUES, IN THIS ORDER.'
      PRINT *
      PRINT *, 'ENTER THE NAME OF THE DATA FILE:'
      READ '(A)', FNAME
      CALL PLOT(FNAME)

      END


**PLOT******************************************************************
* Subroutine to produce a scatter plot of data points stored in a file,*
* the first line of which contains values for XMIN, XMAX, YMIN, and    *
* YMIN, in this order. Local identifiers used are:                     *
*     FNAME  : name of file containing the data points                 *
*     HLIMIT,                                                          *
*     VLIMIT : parameters:  limits on the size of the graphics WINDOW  *
*     WINDOW : two-dimensional character array -- the graphics window  *
*     SYMBOL : plotting character -- represents a point on the graph   *
*     XMIN, XMAX : minimum and maximum X values                        *
*     YMIN, YMAX : minimum and maximum Y values                        *
*     DELX, DELY : X and Y increments                                  *
*     X, Y   : a point on the graph                                    *
*     XLOC, YLOC   : location of a point in the window                 *
*     COUNT  : counts units on Y-axis for labeling purposes            *
*     EOF    : end-of-file indicator                                   *
*                                                                      *
* Accepts:          FNAME                                              *
* Output (screen):  The graphics WINDOW                                *
************************************************************************

      SUBROUTINE PLOT(FNAME)

      CHARACTER*(*) FNAME
      REAL XMIN, XMAX, YMIN, YMAX, DELX, DELY, X, Y
      INTEGER HLIMIT, VLIMIT, XLOC, YLOC, EOF, COUNT
      PARAMETER (HLIMIT = 69, VLIMIT = 20)
      CHARACTER*1 WINDOW(0: HLIMIT, 0:VLIMIT), SYMBOL
      PARAMETER (SYMBOL = '*')

      OPEN (UNIT = 20, FILE = FNAME, STATUS = 'OLD')

      READ (20, *) XMIN, XMAX, YMIN, YMAX
      DELX = (XMAX - XMIN) / REAL(HLIMIT)
      DELY = (YMAX - YMIN) / REAL(VLIMIT)

      DO 20 YLOC = 0, VLIMIT
         DO 10 XLOC = 0, HLIMIT
            WINDOW(XLOC, YLOC) = ' '
 10      CONTINUE
 20   CONTINUE
      
* Read data pairs and turn on points in WINDOW corresponding to pairs

      READ (20, *, IOSTAT = EOF) X, Y
 30   IF (EOF .GE. 0) THEN
         XLOC = NINT((X - XMIN)/ DELX + 0.5)
         YLOC = NINT((Y - YMIN)/ DELY + 0.5)
         WINDOW(XLOC, YLOC) = SYMBOL
         READ (20, *, IOSTAT = EOF) X, Y
      GO TO 30
      END IF

* Draw the WINDOW together with labeled Y-axis

      Y = YMAX
      COUNT = 5 * (VLIMIT / 5)
      DO 40 YLOC = VLIMIT, 0, -1
         IF (MOD(COUNT, 5) .EQ. 0) THEN
            PRINT 100, Y, (WINDOW(XLOC,YLOC), XLOC = 0, HLIMIT)
 100        FORMAT(1X, F8.2, ':', 200A)
         ELSE
            PRINT 101, (WINDOW(XLOC,YLOC), XLOC = 0, HLIMIT)
 101        FORMAT(9X, ':', 200A)
         END IF
         COUNT = COUNT - 1
         Y = Y - DELY
 40   CONTINUE

* Draw a labeled X-axis

      PRINT 102, ('.', XLOC = 0, HLIMIT)
 102  FORMAT(9X, 200A)
      PRINT 103, (XMIN + XLOC*DELX, XLOC = 0, HLIMIT, 10)
 103  FORMAT(3X, 50F10.3)

      END
