      PROGRAM GRAPH
*
* Fortran source GRAPH.for v1.0      Copyright (C) D.I.Hoyer, 1988
*
      INTEGER*2 IGRAPH
      CHARACTER*80 GLABEL, XLABEL, YLABEL, LEGEND, STRNG
      DIMENSION IGRAPH(1040,110), X(200), Y(200), P(20)
*
* Graph plotting on dot matrix printers. 
*
* This is a sample main program for plotting a graph from a data file,
* which must be set up as described in the manual.
*
* The program is set up for IBM, Epson, Star type dot matrix printers.
* If you have a printer which uses different graphics commands, or if
* the graph doesn't appear to print properly, check your printer manual
* and change the appropriate parameters in subroutine PRTGRF.
*
* Maximum graph size (nominal, for Hi-res plotting) = 20 x 25 cm.
* This can be changed by changing the DIMENSION of IGRAPH :
* DIMENSION IGRAPH(a,b) : a = max no. of dot columns across page
*                         b = (max no of dot rows)/14 + 1
*
* GLABEL, XLABEL & YLABEL : Graph heading, and X & Y axis labels.
* XL,YL  = Lengths of X and Y axes, cm.  
* MAXX = Number of dots across x-axis. (calculated by PREP)
* MAXY = Number of dots along y-axis.  (calculated by PREP)
* XMIN, XMAX, YMIN, YMAX = Min & max x,y values to define edges of
*                          plotting area.
* XMINA, XMAX, YMINA, YMAXA = Total plotting area, including space above,
*                             below and left of the graph for labels. These
*                             are calculated by PREP
* NDIVX, NDIVY   = No of divisions along axes (0 for log. scales)
* NSDIVX, NSDIVY = No of secondary divisions along axes (between other 
*                  divisions). Use 1 or 9 for log. scales.
* NDPX, NDPY     = No of decimal places to be printed after dec. point, for
*                  axis values. Ignored for log. scales.
* IVH   = 1 for vertical (portrait) printout, 2 for horizontal (landscape).
* IGRPRT= 1 to print the axes,
*         0 to suppress printing of axes.
* LOHI  = 1 for Low-res (quick) plot, 2 for Hi-Res.
* IOFF  = Offset. This number of blank spaces will be printed from the left
*                 margin ahead of the graph.
* IGRID = 0 to print axes without grid lines, 
*         1 to n for grid lines of line type LTYP.
* NSETS = No of sets of data to be plotted.
*         Each set of points, curve, function or text string is a data set.
* LEGPOS= Position of legend block. 1 = top left, to 4 = top right.
*                                   5 = bott. " , to 8 = bott. "  .
* NPTS  = No of data points for current data set
*         (0 to plot a function curve, -1 for text)
* LTYP  = Line type for joining points. 
*         0 = no line, 
*         1 to 5 straight lines, 
*         -5 to -1 for cubic spline fit (smooth curve).
* MARK  = Symbol to be plotted at each point 
*         (1 = dot, 2..8 = symbol, 32..126 = ASCII character)
* MSIZE = Size of MARK (1..n) Try 3 for a start. 
* LEGEND= Text to describe each data set. 
*         Blank to suppress.
* IFN   = Function number (pre-compiled in FUNCT) to plot if NPTS=0.
* NPARMS= Number of parameters to be passed to function IFN (max 100).
* X1,X2 = Start and end values of x for plotting IFN.
* P(J),J=1,NPARMS = The parameters to be passed to function IFN.
* ITXSIZ= Size of text to be plotted (1 to n).  2 = "normal".
* STRNG = A string of text to be printed on the graph
*
* MMAXX,MMAXY are for passing the dimension of IGRAPH through subs. 
*             (calculated by PREP)
*             MMAXX is the number of columns of dots across the page,
*             MMAXY is the (number of rows of dots)/14
*
      READ(5,606) IGRPRT, XL, YL, GLABEL
 606  FORMAT(I10,2F10.0,A60)
      READ(5,505) XMIN, XMAX, YMIN, YMAX
 505  FORMAT(8F10.0)
      READ(5,101) NDIVX, NSDIVX, NDPX, XLABEL
 101  FORMAT(3I10,A60)
      READ(5,101) NDIVY, NSDIVY, NDPY, YLABEL
      READ(5,202) IVH, LOHI, IOFF, IGRID, NSETS, LEGPOS
 202  FORMAT(8I10)
*
* Do some preparations/calcs before plotting axes or data
*
      CALL PREP(XL,YL,NDIVX,NDIVY,XMINA,XMAXA,YMINA,YMAXA,
     $ XMIN,YMIN,XMAX,YMAX,MAXX,MAXY,MMAXX,MMAXY,LOHI,IVH)
*
* Clear the graph (this is only necessary if you want your program
* to print more than one graph, as the first graph is clear when you start).
* Remove the comment asterisk in column 1 to activate the next line if you
* need to clear the graph: 
*
*     CALL CLRGRF(MMAXX,MMAXY,IGRAPH)
*
* Draw the axes
*
      IF(IGRPRT.EQ.1) CALL AXES(IGRID,NDIVX,NDIVY,NSDIVX,NSDIVY,NDPX,
     $ NDPY,GLABEL,XLABEL,YLABEL,XMINA,XMAXA,YMINA,YMAXA,XMIN,YMIN,XMAX,
     $ YMAX,MAXX,MAXY,MMAXX,MMAXY,LOHI,IGRAPH,IVH)
*
* Read the NSETS sets of data
*
      ILEGND = 0
      DO 10 I=1, NSETS
        READ(5,707) NPTS, LTYP, MARK, MSIZE, LEGEND
 707    FORMAT(4I10,A)

        IF(NPTS.LT.0) THEN  ! If NPTS<0 then text is to be plotted.
          READ(5,808) IORI, ITXSIZ, XX, YY
 808      FORMAT(2I10,2F10.0)
          READ(5,909) STRNG
 909      FORMAT(A)

        ELSEIF(NPTS.EQ.0) THEN  ! If NPTS=0 then a function plot is required.
          READ(5,404) IFN, NPARMS, X1, X2
 404      FORMAT(2I10,2F10.0)
          READ(5,505) (P(J),J=1,NPARMS)

        ELSE  ! A set of points is to be plotted
          READ(5,303) (X(J),Y(J),J=1,NPTS)
 303      FORMAT(2F10.0)
        ENDIF
*-------Plot the data set (text, function or points)
        CALL PLOTD(NPTS,LTYP,MARK,MSIZE,LEGEND,IORI,ITXSIZ,XX,YY,
     $    XMINA,XMAXA,YMINA,YMAXA,XMIN,YMIN,XMAX,YMAX,MAXX,MAXY,MMAXX,
     $    MMAXY,LOHI,IGRAPH,IVH,STRNG,IFN,X1,X2,P,X,Y,ILEGND,LEGPOS,
     $    NDIVX,NDIVY)
  10  CONTINUE
*
* Print out the graph
*
      CALL PRTGRF(IOFF,MMAXX,MMAXY,LOHI,IGRAPH)
      STOP
      END

*---------------------------------------------------------------------------

      INCLUDE "GRAPHFNS.for"
      INCLUDE "GRAPHLIB.for"

*---------------------------------------------------------------------------