SUBROUTINE PLOTXT(X,N)
C
C     PURPOSE--THIS SUBROUTINE YIELDS A NARROW-WIDTH (71-CHARACTER)
C              PLOT OF X(I) VERSUS I.  ITS NARROW WIDTH MAKES IT
C              APPROPRIATE FOR USE ON A TERMINAL. 
C     INPUT ARGUMENTS--X      = THE SINGLE PRECISION VECTOR OF
C                               (UNSORTED OR SORTED) OBSERVATIONS
C                               TO BE PLOTTED VERTICALLY.
C                    --N      = THE INTEGER NUMBER OF OBSERVATIONS
C                               IN THE VECTOR X.
C     OUTPUT--A NARROW-WIDTH (71-CHARACTER) TERMINAL PLOT
C             OF X(I) VERSUS I.
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 (X) 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 X
C              ARE 'MISSING DATA', OR WHEN WE PURPOSELY
C              WANT TO IGNORE CERTAIN ELEMENTS IN THE VECTOR X
C              FOR PLOTTING PURPOSES (THAT IS, WE DO NOT
C              WANT CERTAIN ELEMENTS IN X TO BE PLOTTED).
C              TO CAUSE SPECIFIC ELEMENTS IN X 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 PLOTX
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--NONE.
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 IAXISC
      CHARACTER*4 SBNAM1,SBNAM2
      CHARACTER*4 ALPH11,ALPH12,ALPH21,ALPH22
      CHARACTER*4 BLANK,HYPHEN,ALPHAI,ALPHAX
C
      DIMENSION X(1)
      DIMENSION ILINE(72),AILABL(10)
C
      DATA SBNAM1,SBNAM2/'PLOT','XT  '/ 
      DATA ALPH11,ALPH12/'FIRS','T   '/ 
      DATA ALPH21,ALPH22/'SECO','ND  '/ 
      DATA BLANK,HYPHEN,ALPHAI,ALPHAX/' ','-','I','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)ALPH21,ALPH22,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)ALPH21,ALPH22,SBNAM1,SBNAM2
      WRITE(IPR,22)N
      WRITE(IPR,5)
      RETURN
   58 CONTINUE
C
      HOLD=X(1)
      DO60I=2,N
      IF(X(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
C
      DO76I=1,N
      IF(X(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
C
    5 FORMAT(1H ,'**************************************************',
     1'********************') 
   10 FORMAT(1H ,'                   FATAL ERROR                    ')
   15 FORMAT(1H ,'THE ',A4,A4,' INPUT ARGUMENT TO THE ',A4,A4,
     1' SUBROUTINE')
   20 FORMAT(1H ,'IS NON-NEGATIVE (WITH VALUE = ',I8,1H))
   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)
C
C-----START POINT-----------------------------------------------------
C
C     DEFINE THE NUMBER OF ROWS AND COLUMNS WITHIN THE PLOT--
C     THIS HAS 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     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 X, AND OF I.
C
      XMIN=X(1)
      XMAX=X(1)
      AIMIN=1
      AIMAX=N
      DO300I=1,N
      IF(X(I).GE.CUTOFF)GOTO300
      IF(X(I).LT.XMIN)XMIN=X(I)
      IF(X(I).GT.XMAX)XMAX=X(I)
  300 CONTINUE
      DELX=XMAX-XMIN
      DELAI=AIMAX-AIMIN
      XWIDTH=DELX/ANUMRM
      AIWIDT=DELAI/ANUMCM
C
C     DETERMINE AND WRITE OUT THE PLOT POSITIONS ONE LINE AT A TIME.
C
      DO400IROW=1,NUMROW
      DO500ICOL=1,NUMCOL
      ILINE(ICOL)=BLANK
  500 CONTINUE
      AIROW=IROW
      XUPPER=XMAX+(1.5-AIROW)*XWIDTH
      XLABLE=XMAX+(1.0-AIROW)*XWIDTH
      XLOWER=XMAX+(0.5-AIROW)*XWIDTH
      IF(IROW.EQ.NUMROW)XLABLE=XMIN
      DO600I=1,N
      AI=I
      IF(X(I).GE.CUTOFF)GOTO600
      IF(XLOWER.LE.X(I).AND.X(I).LT.XUPPER)GOTO650
      GOTO600
  650 ICOL=((AI-AIMIN)/AIWIDT)+1.5
      ILINE(ICOL)=ALPHAX
  600 CONTINUE
      ICOLMX=1
      DO700ICOL=1,NUMCOL
      IF(ILINE(ICOL).EQ.ALPHAX)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)XLABLE,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
      AILABL(I)=AIMIN+(AIM1/ANUMLM)*DELAI
 1000 CONTINUE
      WRITE(IPR,910)(AILABL(I),I=1,NUMLAB)
C
  205 FORMAT(1H , 'THE FOLLOWING IS A PLOT OF X(I) (VERTICALLY) ',
     1'VERSUS I (HORIZONTALLY')
  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