SUBROUTINE PLOTSP(Y,N,IDF)
C
C     THIS ROUTINE YIELDS A ONE-PAGE PLOT OF THE SPECTRUM, ALONG WITH UPPER
C     AND LOWER LIMITS OF THE SPECTRUM. 
C     THE CONVENTION HAS BEEN FOLLOWED THAT IF THE INTEGER INPUT PARAMETER IDF
C     HAS THE VALUE 0, THEN NO CONFIDENCE LIMITS WILL BE COMPUTED AND ONLY THE
C     SPECTRUM ITSELF WILL BE PLOTTED OUT.
C     MULTIPLE PLOT POINTS ARE NOT INDICATED.
C     THE FIRST POINT WILL BE PLOTTED ON THE LEFT VERTICAL AXIS
C     THE LAST POINT WILL BE PLOTTED ON THE RIGHT VERTICAL AXIS
C     THERE IS NO RESTRICTION ON THE MAXIMUM VALUE OF N FOR THIS ROUTINE.
C     PRINTING--YES 
C     SUBROUTINES NEEDED--CHSPPF.
C     WRITTEN BY JAMES J. FILLIBEN, STATISTICAL ENGINEERING LABORATORY (205.03) 
C     NATIONAL BUREAU OF STANDARDS, WASHINGTON, D.C. 20234     JUN 1972
C                                                      UPDATED FEB 1975
C     UPDATED         --NOVEMBER  1975. 
C     UPDATED         --FEBRUARY  1976. 
C
C---------------------------------------------------------------------
C
      CHARACTER*4 IGRAPH
      CHARACTER*4 BLANK,HYPHEN,ALPHAI,ALPHAX,DOT
C
      DIMENSION Y(1)
      DIMENSION YLABLE(11)
      COMMON /BLOCK1/ IGRAPH(55,130)
C
      DATA BLANK,HYPHEN,ALPHAI/' ','-','I'/
      DATA ALPHAX/'X'/
      DATA DOT/'.'/ 
C
      IPR=6
C
C     CHECK THE INPUT ARGUMENTS FOR ERRORS
C
      IF(N.LT.1)GOTO50
      IF(N.EQ.1)GOTO55
      HOLD=Y(1)
      DO60I=2,N
      IF(Y(I).NE.HOLD)GOTO90
   60 CONTINUE
      WRITE(IPR, 9)HOLD
      GOTO90
   50 WRITE(IPR,15) 
      WRITE(IPR,47)N
      RETURN
   55 WRITE(IPR,18) 
      RETURN
   90 CONTINUE
    9 FORMAT(1H ,   '***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUME
     1NT (A VECTOR) TO THE PLOTSP SUBROUTINE HAS ALL ELEMENTS = ',
     1E15.8,' *****')
   15 FORMAT(1H ,   '***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO THE
     1 PLOTSP SUBROUTINE IS NON-POSITIVE *****')
   18 FORMAT(1H ,   '***** NON-FATAL DIAGNOSTIC--THE SECOND INPUT ARGUME
     1NT TO THE PLOTSP SUBROUTINE HAS THE VALUE 1 *****')
   47 FORMAT(1H , '***** THE VALUE OF THE ARGUMENT IS ',I8   ,' *****')
C
C-----START POINT-----------------------------------------------------
C
      AN=N
C
C     DETERMINE THE MINIMUM AND MAXIMUM OF THE SPECTRUM
C
      SPMIN=Y(1)
      SPMAX=Y(1)
      DO100I=2,N
      IF(Y(I).LT.SPMIN)SPMIN=Y(I)
      IF(Y(I).GT.SPMAX)SPMAX=Y(I)
  100 CONTINUE
C
C     COMPUTE THE MAXIMUM VALUE OF THE UPPER CONFIDENCE LIMIT
C     AND THE MINIMUM VALUE OF THE LOWER CONFIDENCE LIMIT--THESE TWO VALUES
C     WILL DEFINE THE RANGE OF VALUES TO BE LISTED ON THE VERTICAL AXIS
C
      IF(IDF.EQ.0)GOTO150
      DF=IDF
      CALL CHSPPF(.975,IDF,PP975)
      CALL CHSPPF(.025,IDF,PP025)
      YMAX=DF*SPMAX/PP025
      YMIN=DF*SPMIN/PP975
      GOTO160
  150 YMIN=SPMIN
      YMAX=SPMAX
C
C     DETERMINE THE 11 VALUES TO BE LISTED ON THE LEFT VERTICAL AXIS
C
  160 DO200I=1,11
      YLABLE(I)=YMAX-((FLOAT(I-1))/10.0)*(YMAX-YMIN)
  200 CONTINUE
C
C     BLANK OUT THE GRAPH
      DO250I=1,55
      DO260J=1,130
      IGRAPH(I,J)=BLANK
  260 CONTINUE
  250 CONTINUE
C
C     PRODUCE THE Y AXIS
      DO300I=5,55
      IGRAPH(I,10)=ALPHAI
      IGRAPH(I,130)=ALPHAI
  300 CONTINUE
      DO350I=5,55,5 
      IGRAPH(I,10)=HYPHEN
      IGRAPH(I,130)=HYPHEN
  350 CONTINUE
C
C     PRODUCE THE X AXIS
      DO400J=10,130 
      IGRAPH(55,J)=HYPHEN
      IGRAPH(5,J)=HYPHEN
  400 CONTINUE
      DO450J=10,130,10
      IGRAPH(55,J)=ALPHAI
      IGRAPH(5,J)=ALPHAI
  450 CONTINUE
C
C     DETERMINE THE (X,Y) PLOT POSITIONS
      RATIOY=50.0/(YMAX-YMIN) 
      RATIOX=240.0
      DO600I=1,N
      AI=I
      XI  =(AI-1.0)/(2.0*(AN-1.0))
      MX=RATIOX*XI+0.5
      MX=MX+10
      IF(IDF.EQ.0)GOTO650
      SUPPER=DF*Y(I)/PP025
      SLOWER=DF*Y(I)/PP975
      MY=RATIOY*(SUPPER-YMIN)+0.5
      MY=55-MY
      IGRAPH(MY,MX)=DOT
      MY=RATIOY*(SLOWER-YMIN)+0.5
      MY=55-MY
      IGRAPH(MY,MX)=DOT
  650 MY=RATIOY*(Y(I)-YMIN)+0.5
      MY=55-MY
      IGRAPH(MY,MX)=ALPHAX
  600 CONTINUE
C
C     WRITE OUT THE GRAPH
      WRITE(IPR,998)
      DO700I=5,55
      IFLAG=I-(I/5)*5
      K=I/5
      IF(IFLAG.NE.0)WRITE(IPR,705)(IGRAPH(I,J),J=1,130)
      IF(IFLAG.EQ.0)WRITE(IPR,706)YLABLE(K),(IGRAPH(I,J),J=10,130)
  700 CONTINUE
      WRITE(IPR,740)
      WRITE(IPR,745)
  705 FORMAT(1H ,130A1)
  706 FORMAT(1H ,F9.2,130A1)
  740 FORMAT(1H ,    'FREQ   .000      .042      .083      .125      .16
     17      .208      .250      .292      .333      .375      .417
     1 .458      .500')
  745 FORMAT(1H ,    'PERIOD INF       24.0      12.0      8.00      6.0
     10      4.80      4.00      3.43      3.00      2.67      2.40
     1 2.18      2.00')
  998 FORMAT(1H1)
      RETURN
      END