FUNCTION FSPAND(PTAUS,PRIPPLE,LDOUBLE,PTSTEP)

!        A.Bogatchev : 25-Oct-2007 removing of severe breaks of coding rools
! Computing the minimum length/order for a Dolph-Chebyshev filter
!     PTAUS   : stop-band edge period
!     PRIPPLE : target ripple-ratio
!     LDOUBLE : .T. if the filter is applied twice
!     PTSTEP  : time-step
! (result = time-span / time-step)

USE PARKIND1  ,ONLY : JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

IMPLICIT NONE

LOGICAL,INTENT(IN) :: LDOUBLE

REAL(KIND=JPRB),INTENT(IN) :: PRIPPLE
REAL(KIND=JPRB),INTENT(IN) :: PTAUS
REAL(KIND=JPRB),INTENT(IN) :: PTSTEP

REAL(KIND=JPRB) :: FSPAND

REAL(KIND=JPRB) :: Z, ZPI, ZRI, ZTS

REAL(KIND=JPRB) :: ACOSH
REAL(KIND=JPRB) :: ZHOOK_HANDLE

ACOSH(Z)= LOG(Z+SQRT(Z*Z-1))

#include "abor1.intfb.h"

IF (LHOOK) CALL DR_HOOK('FSPAND',0,ZHOOK_HANDLE)
IF ((PRIPPLE <= 0.0_JPRB).OR.(PTAUS <= 2.0_JPRB*PTSTEP).OR.(PTSTEP <= 0.0_JPRB))&
 & CALL ABOR1(' FSPAND : PROBLEMS WITH ARGUMENTS !')  

IF (LDOUBLE) THEN
  ZRI = 1.0_JPRB/SQRT(PRIPPLE)
ELSE
  ZRI = 1.0_JPRB/PRIPPLE
ENDIF

ZPI = 2.0_JPRB*ASIN(1.0_JPRB)
ZTS = 1.0_JPRB/COS(ZPI*PTSTEP/PTAUS)

FSPAND = ACOSH(ZRI)/ACOSH(ZTS)

IF (LHOOK) CALL DR_HOOK('FSPAND',1,ZHOOK_HANDLE)
END FUNCTION FSPAND
