*--------------------------------------------------------------------*  PLO00010
*                            P L O T                                 *  PLO00020
* Subroutine PLOT -- Perform the actual plotting.  Coordinates are   *  PLO00030
*                    scaled and plotted. Axes are generated if CODE=1*  PLO00040
*                                                                    *  PLO00050
*     Variables Used:                                                *  PLO00060
*        CODE .... If CODE = 1 plot axes, otherwise do not plot axes *  PLO00070
*        GRAPH ... stores the image of the graph to be plotted       *  PLO00080
*        NROW .... number of row positions in graph                  *  PLO00090
*        NCOL .... number of column positions on graph               *  PLO00100
*        XARRAY .. storage for x coordinate of point to be plotted   *  PLO00110
*        YARRAY .. storage for y coordinate of point to be plotted   *  PLO00120
*        ZARRAY .. storage for character to be plotted               *  PLO00130
*        N ....... number of points submitted for plotting           *  PLO00140
*        INIT .... switch to insure proper initialization is done    *  PLO00150
*        LIMIT ... contains the number of points actually plotted    *  PLO00160
*        XLOW, XHIGH ... min and max of all x data                   *  PLO00170
*        YLOW, YHIGH ... min and max of all y data                   *  PLO00180
*        YORD ..... y coordinates for printing                       *  PLO00190
*        ABSCIS .. x coordinates for printing                        *  PLO00200
*        TITLE ... Title of the plot                                 *  PLO00210
*--------------------------------------------------------------------*  PLO00220
      SUBROUTINE PLOT( CODE )                                           PLO00230
                                                                        PLO00240
      CHARACTER GRAPH( 81, 81 ), ZARRAY( 5000 ), TITLE*72               PLO00250
      COMMON /ZGRID2/ GRAPH, ZARRAY, TITLE                              PLO00260
      common /io/ iounit                                                        
                                                                        PLO00270
      INTEGER NROW, NCOL, N                                             PLO00280
      REAL XARRAY( 5000 ), YARRAY( 5000 )                               PLO00290
      LOGICAL INIT                                                      PLO00300
      COMMON /POINTZ/ NROW, NCOL, N, INIT, XARRAY, YARRAY               PLO00310
                                                                        PLO00320
      CHARACTER VBAR/'|'/, SPACE/' '/, PLUS/'+'/, STAR/'*'/, BAR/'-'/   PLO00330
      INTEGER I, J, CODE, IXX, IYY, IX, IY, LIMIT, FACTOR, YFACTR       PLO00340
      REAL XLOW, XHIGH, YLOW, YHIGH, XUNIT, YUNIT, RANGE, SCALE, CORR,  PLO00350
     1     XPOINT, YPOINT, XSIZE, YSIZE, YORD, ABSCIS(9)                PLO00360
      CHARACTER C                                                       PLO00370
      INTEGER POS                                                       PLO00380
                                                                        PLO00390
9000  FORMAT( 9X, 81A1 )                                                PLO00400
9001  FORMAT( 1X, F8.5, 81A1 )                                          PLO00410
*9002  FORMAT( <I+3>X, 12F10.4 )                                        PLO00420
9002  FORMAT( 8X, 12F10.4 )                                             PLO00430
9009  FORMAT(//,2X,'Scale Factors: X-axis 10**',I6,5X,' Y-axis 10**',I6,PLO00440
     1        /,2X,'Number of points plotted:',I5,                              
     2        //,8X, A72)                                               PLO00450
                                                                        PLO00460
* Check that the plot routines have been initialized.                   PLO00470
      IF( .NOT. INIT ) THEN                                             PLO00480
         PRINT*,' ERROR - NO INITIALIZATION.'                           PLO00490
         GOTO 999                                                       PLO00500
      ENDIF                                                             PLO00510
                                                                        PLO00520
* Check the number of points to be plotted. If n > 1000                 PLO00530
* only 5000 points have been stored.                                    PLO00540
      IF( N .EQ. 0 ) THEN                                               PLO00550
         PRINT*,'ERROR - ATTEMPT TO PLOT 0 POINTS.'                     PLO00560
         GOTO 999                                                       PLO00570
      ENDIF                                                             PLO00580
      LIMIT = N                                                         PLO00590
      LIMIT = MIN( 5000, LIMIT )                                        PLO00600
                                                                        PLO00630
* Determine the high and low values for both X and Y coordinates        PLO00640
      XLOW = XARRAY(1)                                                  PLO00650
      XHIGH = XARRAY(1)                                                 PLO00660
      YLOW = YARRAY(1)                                                  PLO00670
      YHIGH = YARRAY(1)                                                 PLO00680
      DO 500 I = 1, LIMIT                                               PLO00690
         XPOINT = XARRAY(I)                                             PLO00700
         YPOINT = YARRAY(I)                                             PLO00710
         IF( XPOINT .LT. XLOW ) XLOW = XPOINT                           PLO00720
         IF( XPOINT .GT. XHIGH ) XHIGH = XPOINT                         PLO00730
         IF( YPOINT .LT. YLOW ) YLOW = YPOINT                           PLO00740
         IF( YPOINT .GT. YHIGH ) YHIGH = YPOINT                         PLO00750
500   CONTINUE                                                          PLO00760
                                                                        PLO00770
* If upper and lower limits are the same for either x or y axis         PLO00780
* alter the high and low values so that (high - low) is not zero.       PLO00790
      IF( XHIGH .EQ. XLOW ) THEN                                        PLO00800
         XHIGH = XHIGH + 1.0                                            PLO00810
         XLOW = XLOW - 1.0                                              PLO00820
         PRINT *,'WARNING - ALL POINTS HAVE SAME X-VALUE.'              PLO00830
      ENDIF                                                             PLO00860
      IF( YHIGH .EQ. YLOW ) THEN                                        PLO00870
         YHIGH = YHIGH + 1.0                                            PLO00880
         YLOW = YLOW - 1.0                                              PLO00890
         PRINT *, 'WARNING - ALL POINTS HAVE SAME Y-VALUE.'             PLO00900
      ENDIF                                                             PLO00930
                                                                        PLO00940
* Prepare location for axes:  If the origin would lie totally outside   PLO00950
* the graph, determined by plus or minus 10%, then force the axes along PLO00960
* the edge of the graph.                                                PLO00970
      IF( LIMIT .LT. 5000 ) LIMIT = LIMIT + 1                           PLO00980
      XARRAY(LIMIT) = XLOW                                              PLO00990
      YARRAY(LIMIT) = YLOW                                              PLO01000
      ZARRAY(LIMIT) = PLUS                                              PLO01010
      IF( XLOW*XHIGH .LE. 0 ) THEN                                      PLO01020
*        Put y-axis inside.                                             PLO01030
         XARRAY(LIMIT) = 0.0                                            PLO01040
                                                                        PLO01050
      ELSEIF( XLOW .GE. 0 ) THEN                                        PLO01060
         IF( XLOW .LE. 0.1*XHIGH ) THEN                                 PLO01070
              XARRAY(LIMIT) = 0.0                                       PLO01080
              XLOW = 0.0                                                PLO01090
         ENDIF                                                          PLO01100
      ELSE                                                              PLO01110
         XARRAY(LIMIT) = XHIGH                                          PLO01120
         IF( -XHIGH .LE. -0.1*XLOW ) THEN                               PLO01130
              XARRAY(LIMIT) = 0.0                                       PLO01140
              XHIGH = 0.0                                               PLO01150
         ENDIF                                                          PLO01160
      ENDIF                                                             PLO01170
                                                                        PLO01180
                                                                        PLO01190
      IF( YLOW*YHIGH .LE. 0 ) THEN                                      PLO01200
         YARRAY(LIMIT) = 0.0                                            PLO01210
      ELSEIF( YLOW .GE. 0 ) THEN                                        PLO01220
         IF( YLOW .LE. 0.1*YHIGH ) THEN                                 PLO01230
              YARRAY(LIMIT) = 0.0                                       PLO01240
              YLOW = 0.0                                                PLO01250
         ENDIF                                                          PLO01260
      ELSE                                                              PLO01270
         YARRAY(LIMIT) = YHIGH                                          PLO01280
         IF( -YHIGH .LE. -0.1*YLOW ) THEN                               PLO01290
              YARRAY(LIMIT) = 0.0                                       PLO01300
              YHIGH = 0.0                                               PLO01310
         ENDIF                                                          PLO01320
      ENDIF                                                             PLO01330
                                                                        PLO01340
* Mark the origin with a '+'if axes were requested and if the origin    PLO01350
* is within the plot region.                                            PLO01360
      IF(XARRAY(LIMIT) .EQ. 0.0 .AND. YARRAY(LIMIT) .EQ. 0.0            PLO01370
     1                          .AND. CODE .EQ. 1) ZARRAY(LIMIT) = PLUS PLO01380
                                                                        PLO01390
* Compute the range of X and Y values, and the unit range for           PLO01400
* each printer position.                                                PLO01410
      XSIZE = XHIGH - XLOW                                              PLO01420
      YSIZE = YHIGH - YLOW                                              PLO01430
      XUNIT = XSIZE/(NCOL - 1)                                          PLO01440
      YUNIT = YSIZE/(NROW - 1)                                          PLO01450
      IXX = IFIX( (XARRAY(LIMIT) - XLOW)/XUNIT + 1.5 )                  PLO01460
      IYY = IFIX( (YARRAY(LIMIT) - YLOW)/YUNIT + 1.5 )                  PLO01470
                                                                        PLO01480
* If axes are requested, build up the characters in the array graph.    PLO01490
      IF( CODE .EQ. 1 ) THEN                                            PLO01500
*        Draw the x axis                                                PLO01510
         DO 700 I = 1, NCOL                                             PLO01520
              POS = NROW + 1 - IYY                                      PLO01530
              GRAPH(POS, I) = BAR                                       PLO01540
              IF(MOD(I-IXX,10) .EQ. 0) GRAPH(POS,I) = PLUS              PLO01550
700      CONTINUE                                                       PLO01560
*        Draw th y axis                                                 PLO01570
         DO 800 I = 1, NROW                                             PLO01580
              POS = NROW + 1 - I                                        PLO01590
              GRAPH(POS,IXX) = VBAR                                     PLO01600
              IF(MOD(NROW + IYY - I, 5) .EQ. 1) GRAPH(POS,IXX) = PLUS   PLO01610
800      CONTINUE                                                       PLO01620
      ENDIF                                                             PLO01630
                                                                        PLO01640
* Now generate the plot in the buffer (GRAPH).  If the character        PLO01650
* position contains a character other than a space, "-", "|", "+",      PLO01660
* or the current character, two curves have intersected - place a "*".  PLO01670
      DO 950 I = 1, LIMIT                                               PLO01680
         IX = IFIX((XARRAY(I) - XLOW)/XUNIT + 1.5 )                     PLO01690
         IY = IFIX((YARRAY(I) - YLOW)/YUNIT + 1.5 )                     PLO01700
         IY = NROW + 1 - IY                                             PLO01710
         C = GRAPH(IY,IX)                                               PLO01720
         IF( C.NE.SPACE .AND. C.NE.BAR .AND. C.NE.VBAR .AND. C.NE.PLUS  PLO01730
     1                  .AND. C.NE.ZARRAY(I) ) THEN                     PLO01740
              GRAPH(IY,IX) = STAR                                       PLO01750
         ELSE                                                           PLO01760
              GRAPH(IY,IX) = ZARRAY(I)                                  PLO01770
         ENDIF                                                          PLO01780
950   CONTINUE                                                          PLO01790
                                                                        PLO01800
* Compute y - axis scale factor                                         PLO01810
      YFACTR = 0                                                        PLO01820
      SCALE = 1.0                                                       PLO01830
      RANGE = ABS(YHIGH)                                                PLO01840
      IF( ABS(YLOW) .GE. RANGE ) RANGE = ABS(YLOW)                      PLO01850
975   IF( RANGE .GE. 10 .OR. RANGE .LT. 1 ) THEN                        PLO01860
         IF( RANGE .LT. 1 ) THEN                                        PLO01870
              RANGE = RANGE*10.0                                        PLO01880
              SCALE = SCALE*10.0                                        PLO01890
              YFACTR = YFACTR - 1                                       PLO01900
         ELSE                                                           PLO01910
              RANGE = RANGE/10.0                                        PLO01920
              SCALE = SCALE/10.0                                        PLO01930
              YFACTR = YFACTR + 1                                       PLO01940
         ENDIF                                                          PLO01950
         GOTO 975                                                       PLO01960
      ENDIF                                                             PLO01970
                                                                        PLO01990
* Compute axis alignment correction                                     PLO02000
      CORR = 0.0                                                        PLO02010
      IF( YLOW*YHIGH .LT. 0.0 ) CORR = (YLOW + (IYY - 1)*YUNIT)*SCALE   PLO02020
                                                                        PLO02030
* And print the plot                                                    PLO02040
      DO 980 I = 1, NROW                                                PLO02050
         IF( MOD(NROW+1-IYY-I,5) .NE. 0 ) THEN                          PLO02060
              write(iounit,9000) (GRAPH(I,J),J=1,NCOL)                  PLO02070
         ELSE                                                           PLO02080
              YORD = (YLOW+(NROW - I)*YUNIT)*SCALE - CORR               PLO02090
              write(iounit,9001) YORD, (GRAPH(I,J),J=1,NCOL)            PLO02100
         ENDIF                                                          PLO02110
980   CONTINUE                                                          PLO02120
                                                                        PLO02130
* Generate the abscissa coordinates                                     PLO02140
      FACTOR = 0                                                        PLO02150
      SCALE = 1.0                                                       PLO02160
      RANGE = ABS(XHIGH)                                                PLO02170
      IF(ABS(XLOW) .GE. RANGE) RANGE = ABS(XLOW)                        PLO02180
990   IF( RANGE .GE. 10 .OR. RANGE .LT. 1 ) THEN                        PLO02190
         IF( RANGE .LT. 1 ) THEN                                        PLO02200
              RANGE = RANGE*10.0                                        PLO02210
              SCALE = SCALE*10.0                                        PLO02220
              FACTOR = FACTOR - 1                                       PLO02230
         ELSE                                                           PLO02240
              RANGE = RANGE/10.0                                        PLO02250
              SCALE = SCALE/10.0                                        PLO02260
              FACTOR = FACTOR + 1                                       PLO02270
         ENDIF                                                          PLO02280
         GOTO 990                                                       PLO02290
      ENDIF                                                             PLO02300
                                                                        PLO02310
* Compute axis alignment correction                                     PLO02320
      CORR = 0.0                                                        PLO02330
      IF( XLOW*XHIGH .LT. 0.0 ) CORR = (XLOW + (IXX - 1)*XUNIT)*SCALE   PLO02340
      I = MOD(IXX,10)                                                   PLO02350
                                                                        PLO02360
* Label the abscissa axis                                               PLO02370
      K = 0                                                             PLO02380
      write(iounit,9099)                                                PLO02390
9099  format(/)                                                                 
      DO 1200 J = I, NCOL, 10                                           PLO02400
         K = K + 1                                                      PLO02410
         ABSCIS(K) = (XLOW+(J-1)*XUNIT)*SCALE - CORR                    PLO02420
1200  CONTINUE                                                          PLO02430
      write(iounit,9002) (ABSCIS(J), J=1,K)                             PLO02440
                                                                        PLO02450
* Output summary information - scale factors, number of points          PLO02460
* processed, and title:                                                 PLO02470
      write(iounit,9009) FACTOR, YFACTR, LIMIT, TITLE                   PLO02480
999   RETURN                                                            PLO02530
      END                                                               PLO02540
*--------------------------------------------------------------------*  SET00010
*     Subroutine SETPLT -- Initialize the plotting package, and      *  SET00020
*                          establish the actual number of rows and   *  SET00030
*                          columns in the printed plot.              *  SET00040
*                                                                    *  SET00050
*     Variables Used:                                                *  SET00060
*        XLIMIT ..... Maximum number of columns                      *  SET00070
*        YLIMIT ..... Maximum number of rows                         *  SET00080
*        I .......... loop counter                                   *  SET00090
*        BLANK ...... The blank character ' '                        *  SET00100
*--------------------------------------------------------------------*  SET00110
      SUBROUTINE SETPLT( NCHARX, NCHARY ,IOUNIT, TYTLE )                SET00120
                                                                        SET00130
      CHARACTER GRAPH(81, 81), ZARRAY(5000), TITLE*72                   SET00140
      COMMON /ZGRID2/ GRAPH, ZARRAY, TITLE                              SET00150
      integer iounit, unit                                                      
      common /io/ unit                                                          
                                                                        SET00160
      INTEGER NROW, NCOL, N                                             SET00170
      REAL XARRAY(5000), YARRAY(5000)                                   SET00180
      LOGICAL INIT                                                      SET00190
      COMMON /POINTZ/ NROW, NCOL, N, INIT, XARRAY, YARRAY               SET00200
                                                                        SET00210
      INTEGER I, J, XLIMIT/81/, YLIMIT/81/                              SET00220
      CHARACTER BLANK/' '/, TYTLE*(*)                                   SET00230
                                                                        SET00240
* Statement function to adjust M to 11, 21, 31, ...                     SET00250
                                                                        SET00260
      ADJUST( M ) = ((M + 8) / 10)*10 + 1                               SET00270
      TITLE = TYTLE                                                     SET00280
                                                                                
      If( iounit .lt. 1 .or. iounit .gt. 99 ) iounit = 6                        
      unit = iounit                                                             
* Check supplied number of rows and columns.  Adjust and set            SET00290
* to default values if out of range.                                    SET00300
                                                                        SET00310
      NCOL = ADJUST( NCHARX )                                           SET00320
      IF( NCOL .LE. 1 ) THEN                                            SET00330
         NCOL = 11                                                      SET00340
         PRINT*,'PLOT-WIDTH TOO SMALL, 11 CHARACTERS USED.'             SET00350
      ENDIF                                                             SET00360
      IF( NCOL .GT. XLIMIT ) THEN                                       SET00370
         NCOL = XLIMIT                                                  SET00380
         PRINT *, 'PLOT-WIDTH TOO LARGE, ',XLIMIT,' CHARACTERS USED.'   SET00390
      ENDIF                                                             SET00400
                                                                        SET00410
      NROW = ADJUST( NCHARY )                                           SET00420
      IF( NROW .LE. 1 ) THEN                                            SET00430
         NROW = 11                                                      SET00440
         PRINT *,'PLOT-HEIGHT TOO SMALL, 11 CHARACTERS USED.'           SET00450
      ENDIF                                                             SET00460
      IF( NROW .GT. YLIMIT ) THEN                                       SET00470
         NROW = YLIMIT                                                  SET00480
         PRINT *,'PLOT-HEIGHT TOO LARGE, ',YLIMIT,' CHARACTERS USED.'   SET00490
      ENDIF                                                             SET00500
                                                                        SET00510
* Initialize elements of the array GRAPH to blanks.  Zero the points    SET00520
* counter and set the initialization flag.                              SET00530
                                                                        SET00540
      DO 100 I = 1, YLIMIT                                              SET00550
         DO 100 J = 1, XLIMIT                                           SET00560
              GRAPH(I,J) = BLANK                                        SET00570
100   CONTINUE                                                          SET00580
                                                                        SET00590
      N = 0                                                             SET00600
      INIT = .TRUE.                                                     SET00610
      RETURN                                                            SET00620
      END                                                               SET00630
*--------------------------------------------------------------------*  STO00010
*                       S T O P N T                                  *  STO00020
*     Stores x,y coordinates for later plotting.                     *  STO00030
*                                                                    *  STO00040
*     Variables Used:                                                *  STO00050
*        X, Y ..... The coordinates of the point to be stored        *  STO00060
*        Z ........ The plotting character for this point            *  STO00070
*--------------------------------------------------------------------*  STO00080
      SUBROUTINE STOPNT( X, Y, Z )                                      STO00090
                                                                        STO00100
      CHARACTER GRAPH( 81, 81 ), ZARRAY( 5000 ), TITLE*72               STO00110
      COMMON /ZGRID2/ GRAPH, ZARRAY, TITLE                              STO00120
                                                                        STO00130
      INTEGER NROW, NCOL, N                                             STO00140
      REAL XARRAY( 5000 ), YARRAY( 5000 )                               STO00150
      LOGICAL INIT                                                      STO00160
      COMMON /POINTZ/ NROW, NCOL, N, INIT, XARRAY, YARRAY               STO00170
                                                                        STO00180
      REAL X, Y                                                         STO00190
      CHARACTER Z                                                       STO00200
                                                                        STO00210
* Check for initialization                                              STO00220
      IF( .NOT. INIT ) THEN                                             STO00230
         PRINT *,'WARNING - PLOT NOT INITIALIZED.'                      STO00240
         STOP                                                           STO00250
      ENDIF                                                             STO00260
                                                                        STO00270
      N = N + 1                                                         STO00280
      IF( N.LT.5001 ) THEN                                              STO00290
         XARRAY(N) = X                                                  STO00300
         YARRAY(N) = Y                                                  STO00310
         ZARRAY(N) = Z                                                  STO00320
      ELSE                                                              STO00330
         IF( N .EQ. 5001 ) THEN                                         STO00340
              PRINT*,'TOO MANY POINTS - FIRST 5000 USED.'               STO00350
         ENDIF                                                          STO00360
      ENDIF                                                             STO00370
                                                                        STO00380
      RETURN                                                            STO00390
      END                                                               STO00400
