SUBROUTINE PLOTCT(Y,X,CHAR,N)
C
C     PURPOSE--THIS SUBROUTINE YIELDS A NARROW-WIDTH (71-CHARACTER)
C              PLOT OF Y(I) VERSUS X(I) WITH SPECIAL PLOTTING
C              CHARACTERS.
C              ITS NARROW WIDTH MAKES IT APPROPRIATE FOR USE ON A
C              TERMINAL.
C              THIS 'SPECIAL PLOTTING CHARACTER' CAPABILITY 
C              ALLOWS THE DATA ANALYST TO INCORPORATE INFORMATION
C              FROM A THIRD VARIABLE (ASIDE FROM Y AND X) INTO
C              THE PLOT.
C              THE PLOT CHARACTER USED AT THE I-TH PLOTTING 
C              POSITION (THAT IS, AT THE COORDINATE (X(I),Y(I)))
C              WILL BE
C              1 IF CHAR(I) IS BETWEEN  0.5 AND  1.5
C              2 IF CHAR(I) IS BETWEEN  1.5 AND  2.5
C                .
C                .
C                .
C              9 IF CHAR(I) IS BETWEEN  8.5 AND  9.5
C              0 IF CHAR(I) IS BETWEEN  9.5 AND 10.5
C              A IF CHAR(I) IS BETWEEN 10.5 AND 11.5
C              B IF CHAR(I) IS BETWEEN 11.5 AND 12.5
C              C IF CHAR(I) IS BETWEEN 12.5 AND 13.5
C                .
C                .
C                .
C              W IF CHAR(I) IS BETWEEN 32.5 AND 33.5
C              X IF CHAR(I) IS BETWEEN 33.5 AND 34.5
C              Y IF CHAR(I) IS BETWEEN 34.5 AND 35.5
C              Z IF CHAR(I) IS BETWEEN 35.5 AND 36.5
C              X IF CHAR(I) IS ANY VALUE OUTSIDE THE RANGE
C                                       0.5 TO  36.5.
C     INPUT ARGUMENTS--Y      = THE SINGLE PRECISION VECTOR OF
C                               (UNSORTED OR SORTED) OBSERVATIONS
C                               TO BE PLOTTED VERTICALLY.
C                    --X      = THE SINGLE PRECISION VECTOR OF
C                               (UNSORTED OR SORTED) OBSERVATIONS
C                               TO BE PLOTTED HORIZONTALLY. 
C                    --CHAR   = THE SINGLE PRECISION VECTOR OF
C                               OBSERVATIONS WHICH CONTROL THE
C                               VALUE OF EACH INDIVIDUAL PLOT
C                               CHARACTER.
C                    --N      = THE INTEGER NUMBER OF OBSERVATIONS
C                               IN THE VECTOR Y.
C     OUTPUT--A NARROW-WIDTH (71-CHARACTER) TERMINAL PLOT
C             OF Y(I) VERSUS X(I) WITH SPECIAL PLOT CHARACTERS.
C             THE BODY OF THE PLOT (NOT COUNTING AXIS VALUES
C             AND MARGINS) IS 25 ROWS (LINES) AND 49 COLUMNS.
C     PRINTING--YES.
C     RESTRICTIONS--THERE IS NO RESTRICTION ON THE MAXIMUM VALUE
C                   OF N FOR THIS SUBROUTINE.
C     OTHER DATAPAC   SUBROUTINES NEEDED--NONE.
C     FORTRAN LIBRARY SUBROUTINES NEEDED--NONE.
C     MODE OF INTERNAL OPERATIONS--SINGLE PRECISION.
C     LANGUAGE--ANSI FORTRAN. 
C     COMMENT--VALUES IN THE VERTICAL AXIS VECTOR (Y),
C              THE HORIZONTAL AXIS VECTOR (X),
C              OR THE PLOT CHARACTER VECTOR (CHAR) WHICH ARE
C              EQUAL TO OR IN EXCESS OF 10.0**10 WILL NOT BE
C              PLOTTED.
C              THIS CONVENTION GREATLY SIMPLIFIES THE PROBLEM
C              OF PLOTTING WHEN SOME ELEMENTS IN THE VECTOR Y
C              (OR X, OR CHAR) ARE 'MISSING DATA', OR WHEN WE PURPOSELY
C              WANT TO IGNORE CERTAIN ELEMENTS IN THE VECTOR Y
C              (OR X, OR CHAR) FOR PLOTTING PURPOSES (THAT IS, WE DO NOT
C              WANT CERTAIN ELEMENTS IN Y (OR X, OR CHAR) TO BE
C              PLOTTED).
C              TO CAUSE SPECIFIC ELEMENTS IN Y (OR X, OR CHAR) TO BE
C              IGNORED, WE REPLACE THE ELEMENTS BEFOREHAND
C              (BY, FOR EXAMPLE, USE OF THE   REPLAC   SUBROUTINE)
C              BY SOME LARGE VALUE (LIKE, SAY, 10.0**10) AND
C              THEY WILL SUBSEQUENTLY BE IGNORED IN THE PLOTC
C              SUBROUTINE.
C            --NOTE THAT THE STORAGE REQUIREMENTS FOR THIS
C              (AND THE OTHER) TERMINAL PLOT SUBROUTINESS ARE .
C              VERY SMALL.
C              THIS IS DUE TO THE 'ONE LINE AT A TIME' ALGORITHM
C              EMPLOYED FOR THE PLOT.
C     REFERENCES--FILLIBEN, 'STATISTICAL ANALYSIS OF INTERLAB
C                 FATIGUE TIME DATA', UNPUBLISHED MANUSCRIPT
C                 (AVAILABLE FROM AUTHOR)
C                 PRESENTED AT THE 'COMPUTER-ASSISTED DATA
C                 ANALYSIS' SESSION AT THE NATIONAL MEETING 
C                 OF THE AMERICAN STATISTICAL ASSOCIATION,
C                 NEW YORK CITY, DECEMBER 27-30, 1973.
C     WRITTEN BY--JAMES J. FILLIBEN
C                 STATISTICAL ENGINEERING LABORATORY (205.03)
C                 NATIONAL BUREAU OF STANDARDS
C                 WASHINGTON, D. C. 20234
C                 PHONE--301-921-2315
C     ORIGINAL VERSION--FEBRUARY  1974. 
C     UPDATED         --APRIL     1974. 
C     UPDATED         --OCTOBER   1974. 
C     UPDATED         --OCTOBER   1975. 
C     UPDATED         --NOVEMBER  1975. 
C     UPDATED         --FEBRUARY  1977. 
C
C---------------------------------------------------------------------
C
      CHARACTER*4 ILINE
      CHARACTER*4 IPLOTC
      CHARACTER*4 JPLOTC
      CHARACTER*4 IAXISC
      CHARACTER*4 SBNAM1,SBNAM2
      CHARACTER*4 ALPH11,ALPH12,ALPH21,ALPH22,ALPH31,ALPH32 
      CHARACTER*4 ALPH41,ALPH42
      CHARACTER*4 BLANK,HYPHEN,ALPHAI
C
      DIMENSION Y(1)
      DIMENSION X(1)
      DIMENSION CHAR(1)
      DIMENSION ILINE(72),XLABLE(10)
      DIMENSION IPLOTC(37)
C
      DATA SBNAM1,SBNAM2/'PLOT','CT  '/ 
      DATA ALPH11,ALPH12/'FIRS','T   '/ 
      DATA ALPH21,ALPH22/'SECO','ND  '/ 
      DATA ALPH31,ALPH32/'THIR','D   '/ 
      DATA ALPH41,ALPH42/'FOUR','TH  '/ 
      DATA BLANK,HYPHEN,ALPHAI/' ','-','I'/
      DATA IPLOTC(1),IPLOTC(2),IPLOTC(3),IPLOTC(4),IPLOTC(5),
     1IPLOTC(6),IPLOTC(7),IPLOTC(8),IPLOTC(9),IPLOTC(10),
     1IPLOTC(11),IPLOTC(12),IPLOTC(13),IPLOTC(14),IPLOTC(15),
     1IPLOTC(16),IPLOTC(17),IPLOTC(18),IPLOTC(19),IPLOTC(20),
     1IPLOTC(21),IPLOTC(22),IPLOTC(23),IPLOTC(24),IPLOTC(25),
     1IPLOTC(26),IPLOTC(27),IPLOTC(28),IPLOTC(29),IPLOTC(30),
     1IPLOTC(31),IPLOTC(32),IPLOTC(33),IPLOTC(34),IPLOTC(35),
     1IPLOTC(36),IPLOTC(37)
     1/'1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F',
     1'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V',
     1'W','X','Y','Z','X'/
C
      IPR=6
      CUTOFF=(10.0**10)-1000.0
C
C     CHECK THE INPUT ARGUMENTS FOR ERRORS
C
      IF(N.LT.1)GOTO52
      GOTO54
   52 WRITE(IPR,5)
      WRITE(IPR,10) 
      WRITE(IPR,15)ALPH41,ALPH42,SBNAM1,SBNAM2
      WRITE(IPR,20)N
      WRITE(IPR,5)
      RETURN
   54 CONTINUE
      IF(N.EQ.1)GOTO56
      GOTO58
   56 WRITE(IPR,5)
      WRITE(IPR,10) 
      WRITE(IPR,15)ALPH41,ALPH42,SBNAM1,SBNAM2
      WRITE(IPR,22)N
      WRITE(IPR,5)
      RETURN
   58 CONTINUE
C
      HOLD=Y(1)
      DO60I=2,N
      IF(Y(I).NE.HOLD)GOTO62
   60 CONTINUE
      WRITE(IPR,5)
      WRITE(IPR,10) 
      WRITE(IPR,15)ALPH11,ALPH12,SBNAM1,SBNAM2
      WRITE(IPR,30)HOLD
      WRITE(IPR,5)
      RETURN
   62 CONTINUE
      HOLD=X(1)
      DO64I=2,N
      IF(X(I).NE.HOLD)GOTO66
   64 CONTINUE
      WRITE(IPR,5)
      WRITE(IPR,10) 
      WRITE(IPR,15)ALPH21,ALPH22,SBNAM1,SBNAM2
      WRITE(IPR,30)HOLD
      WRITE(IPR,5)
      RETURN
   66 CONTINUE
      HOLD=CHAR(1)
      DO68I=2,N
      IF(CHAR(I).NE.HOLD)GOTO70
   68 CONTINUE
      WRITE(IPR,5)
      WRITE(IPR,11) 
      WRITE(IPR,15)ALPH31,ALPH32,SBNAM1,SBNAM2
      WRITE(IPR,30)HOLD
      WRITE(IPR,5)
   70 CONTINUE
C
      DO76I=1,N
      IF(Y(I).LT.CUTOFF)GOTO78
   76 CONTINUE
      WRITE(IPR,5)
      WRITE(IPR,10) 
      WRITE(IPR,15)ALPH11,ALPH12,SBNAM1,SBNAM2
      WRITE(IPR,32) 
      WRITE(IPR,33)CUTOFF
      WRITE(IPR,5)
      RETURN
   78 CONTINUE
      DO80I=1,N
      IF(X(I).LT.CUTOFF)GOTO82
   80 CONTINUE
      WRITE(IPR,5)
      WRITE(IPR,10) 
      WRITE(IPR,15)ALPH21,ALPH22,SBNAM1,SBNAM2
      WRITE(IPR,32) 
      WRITE(IPR,33)CUTOFF
      WRITE(IPR,5)
      RETURN
   82 CONTINUE
      DO84I=1,N
      IF(CHAR(I).LT.CUTOFF)GOTO86
   84 CONTINUE
      WRITE(IPR,5)
      WRITE(IPR,10) 
      WRITE(IPR,15)ALPH31,ALPH32,SBNAM1,SBNAM2
      WRITE(IPR,32) 
      WRITE(IPR,33)CUTOFF
      WRITE(IPR,5)
      RETURN
   86 CONTINUE
C
      N2=0
      DO96I=1,N
      IF(Y(I).LT.CUTOFF.AND.X(I).LT.CUTOFF.AND.CHAR(I).LT.CUTOFF)GOTO98
      GOTO96
   98 N2=N2+1
      IF(N2.GE.2)GOTO99
   96 CONTINUE
      WRITE(IPR,5)
      WRITE(IPR,10) 
      WRITE(IPR,18)ALPH11,ALPH12,ALPH21,ALPH22,ALPH31,ALPH32
      WRITE(IPR,19)SBNAM1,SBNAM2
      WRITE(IPR,40) 
      WRITE(IPR,41)N2
      WRITE(IPR,5)
      RETURN
   99 CONTINUE
C
    5 FORMAT(1H ,'**************************************************',
     1'********************') 
   10 FORMAT(1H ,'                   FATAL ERROR                    ')
   11 FORMAT(1H ,'               NON-FATAL DIAGNOSTIC               ')
   15 FORMAT(1H ,'THE ',A4,A4,' INPUT ARGUMENT TO THE ',A4,A4,
     1' SUBROUTINE')
   18 FORMAT(1H ,'THE ',A4,A4,2H, ,A4,A4,', AND ',A4,A4)
   19 FORMAT(1H ,'INPUT ARGUMENTS TO THE ',A4,A4,' SUBROUTINE')
   20 FORMAT(1H ,'IS NON-NEGATIVE (WITH VALUE = ',I8,')')
   22 FORMAT(1H ,'HAS THE VALUE 1')
   30 FORMAT(1H ,'HAS ALL ELEMENTS = ',E15.8)
   32 FORMAT(1H ,'HAS ALL ELEMENTS IN EXCESS OF THE CUTOFF')
   33 FORMAT(1H ,'VALUE OF ',E15.8)
   40 FORMAT(1H ,'ARE SUCH THAT TOO MANY POINTS HAVE BEEN', 
     1' EXCLUDED FROM THE PLOT.')
   41 FORMAT(1H ,'ONLY ',I3,' POINTS ARE LEFT TO BE PLOTTED.')
C
C-----START POINT-----------------------------------------------------
C
C     DEFINE THE NUMBER OF ROWS AND COLUMNS WITHIN THE PLOT--THIS HAS 
C     BEEN SET TO 25 ROWS AND 49 COLUMNS.
C
      NUMROW=25
      NUMCOL=49
      ANUMR=NUMROW
      ANUMRM=NUMROW-1
      ANUMCM=NUMCOL-1
      NUMR25=(NUMROW/4)+1
      NUMR50=(NUMROW/2)+1
      NUMR75=3*(NUMROW/4)+1
      IXDEL=(NUMCOL-1)/4
      NUMLAB=5
      ANUMLM=NUMLAB-1
C
C     SKIP A LINE, WRITE OUT AN IDENTIFYING LINE FOR THE TYPE OF PLOT,
C     WRITE OUT THE TOP HORIZONTAL AXIS OF THE PLOT, AND SKIP 1 LINE
C     FOR A MARGIN WITHIN THE PLOT.
C
      WRITE(IPR,999)
      WRITE(IPR,205)
      DO100ICOL=1,NUMCOL
      ILINE(ICOL)=HYPHEN
  100 CONTINUE
      DO200ICOL=1,NUMCOL,IXDEL
      ILINE(ICOL)=ALPHAI
  200 CONTINUE
      WRITE(IPR,305)(ILINE(I),I=1,NUMCOL)
      WRITE(IPR,310)BLANK
C
C     DETERMINE THE MIN AND MAX VALUES OF Y, AND OF X.
C
      DO250I=1,N
      IF(Y(I).GE.CUTOFF)GOTO250
      IF(X(I).GE.CUTOFF)GOTO250
      IF(CHAR(I).GE.CUTOFF)GOTO250
      YMIN=Y(I)
      YMAX=Y(I)
      XMIN=X(I)
      XMAX=X(I)
      GOTO270
  250 CONTINUE
  270 DO300I=1,N
      IF(Y(I).GE.CUTOFF)GOTO300
      IF(X(I).GE.CUTOFF)GOTO300
      IF(CHAR(I).GE.CUTOFF)GOTO300
      IF(Y(I).LT.YMIN)YMIN=Y(I)
      IF(Y(I).GT.YMAX)YMAX=Y(I)
      IF(X(I).LT.XMIN)XMIN=X(I)
      IF(X(I).GT.XMAX)XMAX=X(I)
  300 CONTINUE
      DELY=YMAX-YMIN
      DELX=XMAX-XMIN
      YWIDTH=DELY/ANUMRM
      XWIDTH=DELX/ANUMCM
C
C     DETERMINE AND WRITE OUT THE PLOT POSITIONS ONE LINE AT A TIME.
C     ALSO DETERMINE THE APPROPRIATE PLOT CHARACTERS.
C
      DO400IROW=1,NUMROW
      DO500ICOL=1,NUMCOL
      ILINE(ICOL)=BLANK
  500 CONTINUE
      AIROW=IROW
      YUPPER=YMAX+(1.5-AIROW)*YWIDTH
      YLABLE=YMAX+(1.0-AIROW)*YWIDTH
      YLOWER=YMAX+(0.5-AIROW)*YWIDTH
      IF(IROW.EQ.NUMROW)YLABLE=YMIN
      DO600I=1,N
      IF(Y(I).GE.CUTOFF)GOTO600
      IF(X(I).GE.CUTOFF)GOTO600
      IF(CHAR(I).GE.CUTOFF)GOTO600
      IF(YLOWER.LE.Y(I).AND.Y(I).LT.YUPPER)GOTO650
      GOTO600
  650 ICOL=((X(I)-XMIN)/XWIDTH)+1.5
      IA=CHAR(I)+0.5
      IF(1.LE.IA.AND.IA.LE.36)GOTO630
  620 JPLOTC=IPLOTC(37)
      GOTO640
  630 JPLOTC=IPLOTC(IA)
  640 ILINE(ICOL)=JPLOTC
  600 CONTINUE
      ICOLMX=1
      DO700ICOL=1,NUMCOL
      IF(ILINE(ICOL).NE.BLANK)ICOLMX=ICOL
  700 CONTINUE
      IAXISC=ALPHAI 
      IF(IROW.EQ.1.OR.IROW.EQ.NUMROW)IAXISC=HYPHEN
      IF(IROW.EQ.NUMR25.OR.IROW.EQ.NUMR50.OR.IROW.EQ.NUMR75)
     1IAXISC=HYPHEN 
      WRITE(IPR,710)YLABLE,IAXISC,(ILINE(ICOL),ICOL=1,ICOLMX)
  400 CONTINUE
C
C     SKIP 1 LINE FOR A BOTTOM MARGIN WITHIN THE PLOT, WRITE OUT THE
C     BOTTOM HORIZONTAL AXIS, AND WRITE OUT THE X AXIS LABLES.
C
      WRITE(IPR,310)BLANK
      DO800ICOL=1,NUMCOL
      ILINE(ICOL)=HYPHEN
  800 CONTINUE
      DO900ICOL=1,NUMCOL,IXDEL
      ILINE(ICOL)=ALPHAI
  900 CONTINUE
      WRITE(IPR,305)(ILINE(ICOL),ICOL=1,NUMCOL)
      DO1000I=1,NUMLAB
      AIM1=I-1
      XLABLE(I)=XMIN+(AIM1/ANUMLM)*DELX 
 1000 CONTINUE
      WRITE(IPR,910)(XLABLE(I),I=1,NUMLAB)
C
  205 FORMAT(1H ,'THE FOLLOWING IS A PLOT OF Y(I) VERSUS X(I)')
  305 FORMAT(1H ,18X,54A1)
  310 FORMAT(1H ,15X,A1)
  710 FORMAT(1H ,E14.7,1X,A1,2X,50A1)
  910 FORMAT(1H ,9X,5E12.4)
  999 FORMAT(1H )
C
      RETURN
      END