$STORAGE:2
C           FORTRAN SUBROUTINE TO PLOT DATA LINE BY LINE
C
C                        PLTR
C
C              J. ROSS MACDONALD  06/19/91
C		
C    ****************************************************************
C
      SUBROUTINE PLTR(XIN,YIN,ND,IRES)
	IMPLICIT REAL*8 (A-H,O-Z)
        DIMENSION XIN(151),YIN(151)
C
C        FIND RANGE OF X AND Y VALUES
         CALL MINMAX(ND,XIN,YIN,XMIN,XDEN,YNUM,YMAX,IRES)
C
C        INVOKE PLOTTER
         CALL PLOTP(ND,XIN,YIN,XMIN,XDEN,YNUM,YMAX,IRES)
	 WRITE(*,*)
         PAUSE
	RETURN
        END
C
C        DETERMINE EXTREME VALUES OF XIN AND YIN
C
        SUBROUTINE MINMAX(ND,XIN,YIN,XMIN,XDEND,YNUMD,YMAX,IRES)
	IMPLICIT REAL*8 (A-H,O-Z)
	SAVE
        DIMENSION XIN(151),YIN(151)
C	COMMON /CM39/ XDEND,YNUMD
C
        XMIN=XIN(1)
        XMAX=XMIN
        YMIN=YIN(1)
        YMAX=YMIN
        DO 100 IY=2,ND
                IF(XMIN.GT.XIN(IY)) XMIN=XIN(IY)
                IF(XMAX.LT.XIN(IY)) XMAX=XIN(IY)
                IF(YMIN.GT.YIN(IY)) YMIN=YIN(IY)
                IF(YMAX.LT.YIN(IY)) YMAX=YIN(IY)
100        CONTINUE
C
	YNUMD = YMAX - YMIN
	XDEND = 1.D0/(XMAX -XMIN)
	YXRAT = YNUMD*XDEND
	WRITE(*,436) IRES
436	FORMAT(3X,'*** RESIDUAL PLOT CHOICE NO.',I3,' ***')
       WRITE(*,437) XMIN,XMAX
437        FORMAT('   * * * * * * :    X,Y POINTS'/,
     2        '   O O O O O O :    X, OVERLAPPING Y VALUES'/,
     3  '   XMIN=',1PD9.2,3X,'XMAX=',1PD9.2)
C
	  WRITE(*,439) YMIN,YMAX
439     FORMAT( '   YMIN=',1PD9.2,3X,'YMAX=',1PD9.2)
C
	  WRITE(*,441) YXRAT
441     FORMAT( '   YRANGE/XRANGE='1PD9.2)
C
	IF(IRES.LT.0) THEN
		WRITE(3,436) IRES
        	WRITE(3,437) XMIN,XMAX
	  	WRITE(3,439) YMIN,YMAX
	        WRITE(3,441) YXRAT
	ENDIF
C
        RETURN
        END
C
C        PRINTER PLOT OF YIN, AGAINST XIN
        SUBROUTINE PLOTP(ND,XIN,YIN,XMIN,XDEN,YNUM,YMAX,IRES)
  	 IMPLICIT REAL*8 (A-H,O-Z)
C	REAL*8 XIN,YIN,XMIN,XMAX,YMIN,YMAX,XDEN,YNUM,XSCALE,XORG,YSCALE
C     1,YORG
         PARAMETER (NXGRID=44,NYGRID=22)
         DIMENSION XIN(151),YIN(151)
         SAVE
C
         CHARACTER*1 LINE(NXGRID)
         CHARACTER*1 FIGURE,GROUND,XEDGE,YEDGE,FIG3,XAXIS,
     1   YAXIS,FIG4
         DATA FIGURE/'*'/,GROUND/' '/,XEDGE/'.'/,YEDGE/':'/,
     1   FIG3/'O'/,XAXIS/'-'/,YAXIS/'|'/
C
C                USE * * * FOR SINGLE SET PLOTTING
C                USE O O O FOR OVERLAPPING POINTS
C                
C          CALCULATE  X SCALE FACTOR, THEN X ORIGIN
           XSCALE=(NXGRID - 1)*XDEN
           XORG=1.D0 - XSCALE*XMIN
C
C        CALCULATE  Y SCALE FACTOR, THEN Y ORIGIN
           YSCALE=(1.D0 - NYGRID)/YNUM
                  YORG=1.D0 - YSCALE*YMAX
                  IYA= INT(XORG + 0.5001D0)
                  IXA= INT(YORG + 0.5001D0)          
C
        DO 60 IL=1,NYGRID 
                IF(IL.EQ.1.OR.IL.EQ.NYGRID.OR.IL.EQ.IXA) GO TO 24
C                    MAKE EDGES ON GRAPH
                        LINE(1)=YEDGE
                        LINE(NXGRID)=YEDGE
                        DO 22 IB=2,(NXGRID - 1)
C                            INITIALIZE REST OF GRAPH TO GROUND
                             LINE(IB)=GROUND
22                      CONTINUE
                   LINE(IYA)=YAXIS
                        GO TO 30
24                CONTINUE
                     DO 26 IC=1,NXGRID
                     IF(IL.EQ.IXA) THEN
                               LINE(IC)=XAXIS
                     ELSE 
                               LINE(IC) = XEDGE
                     ENDIF

26                   CONTINUE
30                CONTINUE
                DO 35 IG=1,ND
C                   X POSITION
                           IX= XSCALE*XIN(IG) + XORG + 0.5001D0
C                    INVERTED Y POSITION
                           IY= YSCALE*YIN(IG) + YORG + 0.5001D0 
                           IF(IY.EQ.0) IY=1
                           IF(IY.NE.IL) GO TO 678
                           FIG4=FIGURE
                   IF(LINE(IX).EQ.FIG4) FIG4=FIG3
                           LINE(IX)=FIG4
678			CONTINUE
35              CONTINUE
C        OUTPUT ONE HORIZONTAL LINE OF PLOT
         WRITE(*,*) (LINE(IQ),IQ=1,NXGRID)
         IF(IRES.LT.0) WRITE(3,*) (LINE(IQ),IQ=1,NXGRID)
60      CONTINUE
        RETURN
        END
