      CHARACTER *1T
      DOUBLE PRECISION U,V,W,X,Y,Z,A0,E0,E8,FP,FS,SR,TQ,T0,
     &B(16),C(16),D(16),E(30),F(16),R(15),S(15),DB(16),TB(16)
C    **************************************************************
      PRINT *, "** ANTIMETRICAL ELLIPTIC FILTERS * TYPES A,B AND C **"
C    **************************************************************
      DBN=.23025851;PI=3.1415927
   10 PRINT *, ;PRINT *;PRINT *
      PRINT *, "REJECTION,RIPPLE(DB),HALF-DEGREE(2-15),TYPE(A,B OR C)"
      READ *, AS,AP,M,T
      IF(AS.LE.AP)STOP;N=2*M
C    *=============================================================
      EAS=EXP(DBN*AS)-1
      EAP=EXP(DBN*AP)-1
      V=SQRT(EAS/EAP)+SQRT(EAS/EAP-1)
      U=PI*PI/(2*DLOG(V+V))
      V=V/(SQRT(EAS)+SQRT(EAS+1))
      W=U*DLOG(V+SQRT(V*V+1))/PI
      W=SIN(W)/COS(W);A0=W;W=W*W
      Y=DEXP(-U);Z=Y;K=M-1
      DO 20 J=1,N
   20 E(J)=1
      DO 22 J=1,1024
      IF(K.NE.M)GO TO 21
      X=((1-Z)/(1+Z))**2
      A0=A0*(W+X)/(1+W*X)
   21 E(K)=E(K)*(1-Z)/(1+Z)
      Z=Z*Y;IF(Z.LT..25E-18)GO TO 23;K=K-1
   22 IF(K.EQ.0)K=N
   23 E(M)=0;E(N)=E(N)*E(N)
      PRINT *, ;PRINT *, "U =",U,"  A0=",A0;PRINT *, "EP=",E(N)
      DO 24 J=1,M-1
      E(J)=-E(J)*E(N-J)
      PRINT *, "E =",-E(J)
   24 E(N-J)=-E(J)
C    *-------------------------------------------------------------
      X=DSQRT(A0*A0+1/(A0*A0)+E(N)*E(N)+1/(E(N)*E(N)))
      DO 25 J=1,M-1,2;K=(J+1)/2
      Y=A0*E(J);Y=Y+1/Y
      Z=E(N)*E(J)
      R(K)=E(M-J)*(1/Z-Z)/Y;S(K)=-X/Y
      PRINT *, "RE=",R(K),"  SE=",S(K)
      R(M-K+1)=R(K)
   25 S(M-K+1)=-S(K)
      IF(K+K.EQ.M)GO TO 30
      R(K+1)=-A0;S(K+1)=0
      PRINT *, "RE=",-A0
C    *=============================================================
   30 PRINT *, ;IT=2;IF(T.EQ."A")IT=1
      E8=-E(1);IF(T.EQ."A")E8=E(N)
      EO=E(N);IF(T.EQ."C")EO=-E(1)
      FP=DSQRT((E(N)+EO)/(1+E(N)*E8))
      FS=DSQRT((1+E(N)*EO)/(E(N)+E8))
      D(1)=0;DO 31 J=IT,M
      D(J)=(E(2*J-1)+E8)/(1+E(2*J-1)*EO)
   31 F(J)=SQRT(1/D(J))
C    *-------------------------------------------------------------
      SR=0;TQ=0;T0=0;B(1)=0;I=1
      DO 32 J=1,M
      W=(A0**2+E(2*J-1)**2)/(1+(A0*E(2*J-1))**2)
      X=(1+EO*E8)*S(J)+EO+E8*W
      Y=EO**2+2*EO*S(J)+W
      Z=1+2*E8*S(J)+E8**2*W
      U=DSQRT(Y/Z);V=X/Z
      R(J)=DSQRT((U-V)/2);S(J)=DSQRT((U+V)/2)
      PRINT *, "RF=",-R(J)/FP,"  SF=",S(J)/FP
C    *
      SR=SR+R(J)/U
      I=-I;W=I*R(J)/S(J)
      TQ=(TQ+W)/(1-TQ*W)
      IF(T.NE."A")GO TO 32
      U=(F(2)-S(J))/R(J);V=(F(2)+S(J))/R(J)
      W=I*(V-U)/(1+U*V)
      T0=(T0+W)/(1-T0*W)
   32 B(1)=B(1)+R(J)
C    *=============================================================
      IF(T.EQ."A")T0=T0/(1+DSQRT(1+T0*T0))
      DO 40 K=IT,M
      DB(K)=0;TB(K)=T0;I=1
      DO 40 J=1,M
      DB(K)=DB(K)+1/(R(J)+(F(K)-S(J))**2/R(J))
     &           +1/(R(J)+(F(K)+S(J))**2/R(J))
      I=-I;W=(F(K)-I*S(J))/R(J)
   40 TB(K)=(TB(K)+W)/(1-TB(K)*W)
C    *=============================================================
      D(M+1)=D(M);F(M+1)=F(M);DB(M+1)=DB(M);TB(M+1)=TB(M);C(1)=0
      DO 50 J=1,M+1-IT,2
   50 TB(M+1-J)=-1/TB(M+1-J)
      DO 51 J=IT,M+1
      B(J)=(1+TB(J)**2)*DB(J)/(4*D(J))-TB(J)*F(J)/2
   51 C(J)=TB(J)/F(J)
C    *=============================================================
      DO 60 L=1,2
      DO 60 K=L+2,M+1,2
      DO 60 J=L,K-2,2
      U=C(J)-C(K)
      V=1/(U/(B(J)*(D(K)-D(J)))-1)
      B(K)=(B(K)-B(J))*V*V-B(J)*(V+V+1)
   60 C(K)=U*V
C    *=============================================================
      W=1;IF(T.NE."C")W=((1-TQ*T0)/(TQ+T0))**2
      DO 70 J=1,M+1,2;B(J)=B(J)*W
   70 C(J)=C(J)*W;PRINT *, 
      PRINT *, "LOAD RESISTANCE=",SNGL(W),"   (",SNGL(1/W),"  )"
      PRINT *, ;PRINT *, "                     L  ( C )        C  ( L )
     &          PEAK"
      IF(T.NE."A")
     &PRINT *, "          1                 ",SNGL(FP/B(1))
      V=0;DO 71 J=IT,M;V=V+C(J)
   71 PRINT *, J,SNGL(FP*C(J)),SNGL(FP/B(J)),SNGL(F(J)/FP)
      PRINT *, M+1,SNGL(FP*C(M+1)),"  STOPBAND EDGE=",SNGL(FS/FP)
      PRINT *
      PRINT *, "TESTS",SNGL(B(M)/B(M+1)-1),SNGL((W+1)*SR-V-C(M+1))
      GO TO 10
      STOP
      END
