module steepdip {            # Find N-D PEF coef locations for steep dip decon
use helix
use cartesian
contains
  function steepn( n, a, d, vel,tgap) result (aa) {
    type( filter)                       :: aa	            # needed by helicon
    integer, dimension (:), intent( in) :: n, a
    real,    dimension (:), intent( in) :: d
    real,                   intent( in) :: vel, tgap 
    integer, dimension (:), allocatable :: lag
    integer, dimension (size (a))       :: c
    real,    dimension (size (a) - 1)   :: x	  
    real                                :: t, t0
    integer                             :: i, h, na, nx, it  
    h= 0;  na= product( a);  nx= size( x);  it = nx +1;   allocate( lag( na))
    do i = 1, na { 
       call line2cart(  a, i, c)
       c (:nx) = c(:nx) - (a(:nx)+1)/2; c(it) = c(it) - 1
       x = d(:nx)*c(:nx)
       t0 = sqrt (dot_product (x,x)) / vel
       t = c(it)*d(it)
       if( t < max( t0, tgap)) cycle
       h = h + 1
       call cart2line( n, c+1, lag(h))
    }
    call allocatehelix( aa, h);
    aa%lag = lag( :h)-1;              deallocate( lag)
    aa%flt = 0.0
  }
}
