      SUBROUTINE CSD(Z,P,L,M,IWIN,DELT,STATE)
C
      REAL*8 TITLE(10)
      COMPLEX Z(1)
C
      COMMON/DEBUG1/ IAFM(5)
C
      COMMON/INPFFT/ICSD
C
      DIMENSION STORE(1024)
      DIMENSION F(10),AMP(10),STATE(7)
      DIMENSION P(1)
C
      DATA TWOPI /6.283185/
C
      DATA TITLE/'FIRST   ','SECOND  ','THIRD   ','FOURTH  ','FIFTH   ',
     1           'SIXTH   ','SEVENTH ','EIGTH   ','NINTH   ','TENTH   '/
C
      CALL FINDN(L,M,N,NS)
C
      L1=L+1
      LL=L+L
      IF(IAFM(4).EQ.0) GO TO 1975
    2 FORMAT(9H RECORD X)
      WRITE(6,2)
C     READ IN A SEQUENCE X (OR Y).
    1 FORMAT(1PE14.6,1PE13.6,1PE13.6,1PE13.6,1PE13.6,1PE13.6,1PE13.6
     &              ,1PE13.6,1PE13.6,1PE13.6)
      WRITE(6,1) (P(I),I=1,L)
 1975 CONTINUE
C     1. MAKE X INTO ZERO MEAN SEQUENCE AND STORE NEW X.
      CALL ZEROMN(P,L,SA)
      DO 88 I=1,L
   88 STORE(I)=P(I)
C     2. ADD ZERCES TO X TIL SEQUENCE LENGTH OF X BECOMES N.
      DO 99 I=L1,N
   99 P(I)=0.
      CALL AUTPOW(Z,P,L,N,SIG,M,NS,IWIN,DELT,DELF)
      CALL COMMAX(Z,NS,F,AMP,ICSD)
C
      DO 73 I=1,ICSD
      F(I)=F(I)*DELF
      WRITE(6,600) TITLE(I),F(I)
  600 FORMAT('0',10X,'*****  ',A8,'FREQUENCY = ',1PE13.6,' CPS  *****')
      F(I)=F(I)*TWOPI
   73 CONTINUE
C
      DO 50 J=1,ICSD
      FI=F(J)*DELT
      NT=TWOPI/FI
C     ARRANGE ZERO MEAN X AND Y ALTERNATELY,I.E., X1,Y1,X2,Y2,...,SL,YL.
      DO 44 I=1,L
      II=I+I
      P(II-1)=STORE(I)
      P(II)=SIN(FI*(I-1))
   44 CONTINUE
      LL1=LL+1
      N2=N+N
C     ADD ZEROES TO XY SEQUENCE TIL SEQUENCE LENGTH BECOMES 2*N.
      DO 111 I=LL1,N2
  111 P(I)=0.
C     COMPUTE CROSSCORRELATION
C
      CALL CROSS(Z,L,N)
      CALL PLTC(Z,1,NT,1,1,0,0)
      CALL COMMAX(Z,NT,TAW,AMPL,1)
C
      IF(TAW .EQ. 0.0) AMPL=REAL(Z(1))
C
      TAW=TAW*FI*360.0E0/TWOPI
C
      WRITE(6,601) TITLE(J),TAW,TITLE(J),AMPL
  601 FORMAT('0',20X,'PHASE ANGLE FOR ',A8,'MODE =',F8.4,' DEGREES',/
     1          ,20X,'AMPLITUDE   FOR ',A8,'MODE =',1PE13.6,/)
C
   50 CONTINUE
      RETURN
      END
