home *** CD-ROM | disk | FTP | other *** search
/ PC-SIG Library 8 / PC-SIG Library CD-ROM (8th Edition) (1990-04).iso / 1901_000 / disk1926 / graph.for < prev    next >
Encoding:
Text File  |  1989-01-12  |  5.9 KB  |  141 lines

  1.       PROGRAM GRAPH
  2. *
  3. * Fortran source GRAPH.for v1.0      Copyright (C) D.I.Hoyer, 1988
  4. *
  5.       INTEGER*2 IGRAPH
  6.       CHARACTER*80 GLABEL, XLABEL, YLABEL, LEGEND, STRNG
  7.       DIMENSION IGRAPH(1040,110), X(200), Y(200), P(20)
  8. *
  9. * Graph plotting on dot matrix printers. 
  10. *
  11. * This is a sample main program for plotting a graph from a data file,
  12. * which must be set up as described in the manual.
  13. *
  14. * The program is set up for IBM, Epson, Star type dot matrix printers.
  15. * If you have a printer which uses different graphics commands, or if
  16. * the graph doesn't appear to print properly, check your printer manual
  17. * and change the appropriate parameters in subroutine PRTGRF.
  18. *
  19. * Maximum graph size (nominal, for Hi-res plotting) = 20 x 25 cm.
  20. * This can be changed by changing the DIMENSION of IGRAPH :
  21. * DIMENSION IGRAPH(a,b) : a = max no. of dot columns across page
  22. *                         b = (max no of dot rows)/14 + 1
  23. *
  24. * GLABEL, XLABEL & YLABEL : Graph heading, and X & Y axis labels.
  25. * XL,YL  = Lengths of X and Y axes, cm.  
  26. * MAXX = Number of dots across x-axis. (calculated by PREP)
  27. * MAXY = Number of dots along y-axis.  (calculated by PREP)
  28. * XMIN, XMAX, YMIN, YMAX = Min & max x,y values to define edges of
  29. *                          plotting area.
  30. * XMINA, XMAX, YMINA, YMAXA = Total plotting area, including space above,
  31. *                             below and left of the graph for labels. These
  32. *                             are calculated by PREP
  33. * NDIVX, NDIVY   = No of divisions along axes (0 for log. scales)
  34. * NSDIVX, NSDIVY = No of secondary divisions along axes (between other 
  35. *                  divisions). Use 1 or 9 for log. scales.
  36. * NDPX, NDPY     = No of decimal places to be printed after dec. point, for
  37. *                  axis values. Ignored for log. scales.
  38. * IVH   = 1 for vertical (portrait) printout, 2 for horizontal (landscape).
  39. * IGRPRT= 1 to print the axes,
  40. *         0 to suppress printing of axes.
  41. * LOHI  = 1 for Low-res (quick) plot, 2 for Hi-Res.
  42. * IOFF  = Offset. This number of blank spaces will be printed from the left
  43. *                 margin ahead of the graph.
  44. * IGRID = 0 to print axes without grid lines, 
  45. *         1 to n for grid lines of line type LTYP.
  46. * NSETS = No of sets of data to be plotted.
  47. *         Each set of points, curve, function or text string is a data set.
  48. * LEGPOS= Position of legend block. 1 = top left, to 4 = top right.
  49. *                                   5 = bott. " , to 8 = bott. "  .
  50. * NPTS  = No of data points for current data set
  51. *         (0 to plot a function curve, -1 for text)
  52. * LTYP  = Line type for joining points. 
  53. *         0 = no line, 
  54. *         1 to 5 straight lines, 
  55. *         -5 to -1 for cubic spline fit (smooth curve).
  56. * MARK  = Symbol to be plotted at each point 
  57. *         (1 = dot, 2..8 = symbol, 32..126 = ASCII character)
  58. * MSIZE = Size of MARK (1..n) Try 3 for a start. 
  59. * LEGEND= Text to describe each data set. 
  60. *         Blank to suppress.
  61. * IFN   = Function number (pre-compiled in FUNCT) to plot if NPTS=0.
  62. * NPARMS= Number of parameters to be passed to function IFN (max 100).
  63. * X1,X2 = Start and end values of x for plotting IFN.
  64. * P(J),J=1,NPARMS = The parameters to be passed to function IFN.
  65. * ITXSIZ= Size of text to be plotted (1 to n).  2 = "normal".
  66. * STRNG = A string of text to be printed on the graph
  67. *
  68. * MMAXX,MMAXY are for passing the dimension of IGRAPH through subs. 
  69. *             (calculated by PREP)
  70. *             MMAXX is the number of columns of dots across the page,
  71. *             MMAXY is the (number of rows of dots)/14
  72. *
  73.       READ(5,606) IGRPRT, XL, YL, GLABEL
  74.  606  FORMAT(I10,2F10.0,A60)
  75.       READ(5,505) XMIN, XMAX, YMIN, YMAX
  76.  505  FORMAT(8F10.0)
  77.       READ(5,101) NDIVX, NSDIVX, NDPX, XLABEL
  78.  101  FORMAT(3I10,A60)
  79.       READ(5,101) NDIVY, NSDIVY, NDPY, YLABEL
  80.       READ(5,202) IVH, LOHI, IOFF, IGRID, NSETS, LEGPOS
  81.  202  FORMAT(8I10)
  82. *
  83. * Do some preparations/calcs before plotting axes or data
  84. *
  85.       CALL PREP(XL,YL,NDIVX,NDIVY,XMINA,XMAXA,YMINA,YMAXA,
  86.      $ XMIN,YMIN,XMAX,YMAX,MAXX,MAXY,MMAXX,MMAXY,LOHI,IVH)
  87. *
  88. * Clear the graph (this is only necessary if you want your program
  89. * to print more than one graph, as the first graph is clear when you start).
  90. * Remove the comment asterisk in column 1 to activate the next line if you
  91. * need to clear the graph: 
  92. *
  93. *     CALL CLRGRF(MMAXX,MMAXY,IGRAPH)
  94. *
  95. * Draw the axes
  96. *
  97.       IF(IGRPRT.EQ.1) CALL AXES(IGRID,NDIVX,NDIVY,NSDIVX,NSDIVY,NDPX,
  98.      $ NDPY,GLABEL,XLABEL,YLABEL,XMINA,XMAXA,YMINA,YMAXA,XMIN,YMIN,XMAX,
  99.      $ YMAX,MAXX,MAXY,MMAXX,MMAXY,LOHI,IGRAPH,IVH)
  100. *
  101. * Read the NSETS sets of data
  102. *
  103.       ILEGND = 0
  104.       DO 10 I=1, NSETS
  105.         READ(5,707) NPTS, LTYP, MARK, MSIZE, LEGEND
  106.  707    FORMAT(4I10,A)
  107.  
  108.         IF(NPTS.LT.0) THEN  ! If NPTS<0 then text is to be plotted.
  109.           READ(5,808) IORI, ITXSIZ, XX, YY
  110.  808      FORMAT(2I10,2F10.0)
  111.           READ(5,909) STRNG
  112.  909      FORMAT(A)
  113.  
  114.         ELSEIF(NPTS.EQ.0) THEN  ! If NPTS=0 then a function plot is required.
  115.           READ(5,404) IFN, NPARMS, X1, X2
  116.  404      FORMAT(2I10,2F10.0)
  117.           READ(5,505) (P(J),J=1,NPARMS)
  118.  
  119.         ELSE  ! A set of points is to be plotted
  120.           READ(5,303) (X(J),Y(J),J=1,NPTS)
  121.  303      FORMAT(2F10.0)
  122.         ENDIF
  123. *-------Plot the data set (text, function or points)
  124.         CALL PLOTD(NPTS,LTYP,MARK,MSIZE,LEGEND,IORI,ITXSIZ,XX,YY,
  125.      $    XMINA,XMAXA,YMINA,YMAXA,XMIN,YMIN,XMAX,YMAX,MAXX,MAXY,MMAXX,
  126.      $    MMAXY,LOHI,IGRAPH,IVH,STRNG,IFN,X1,X2,P,X,Y,ILEGND,LEGPOS,
  127.      $    NDIVX,NDIVY)
  128.   10  CONTINUE
  129. *
  130. * Print out the graph
  131. *
  132.       CALL PRTGRF(IOFF,MMAXX,MMAXY,LOHI,IGRAPH)
  133.       STOP
  134.       END
  135.  
  136. *---------------------------------------------------------------------------
  137.  
  138.       INCLUDE "GRAPHFNS.for"
  139.       INCLUDE "GRAPHLIB.for"
  140.  
  141. *---------------------------------------------------------------------------