anchor.diff:          logical, intent(in) :: reverse
           integer :: nx,ny,nz,i,j,k
           integer :: uk, vi !store a separate value of i for v and of k for u to we can handle nx+1, ny+1
  -        integer :: step, dpos, npos, nextd, nextn, top
  -        real :: dweight, nweight, curdir, curnsq, speed
  +        integer :: step, dpos, npos, spos, nexts, nextd, nextn, top, bottom
  +        real :: dweight, nweight, sweight, curspd, curdir, curnsq, wind_first, wind_second
       
           nx=size(domain%lat,1)
           ny=size(domain%lat,2)
  
positive.code:                             dpos=step
                          endif
                      end do
                      npos=1
                      curnsq = calc_stability(domain%th(i,j,k), domain%th(i,top,k),  &
                                              domain%pii(i,j,k),domain%pii(i,top,k), &
                                              domain%z(i,j,k),  domain%z(i,top,k),   &
                                              domain%qv(i,j,k), domain%qv(i,top,k),  &
                                              domain%cloud(i,j,k)+domain%ice(i,j,k)+domain%qrain(i,j,k)+domain%qsnow(i,j,k))
                      curnsq = log(curnsq)
                      do step=1,n_nsq_values
                          if (curnsq>nsq_values(step)) then
  
negative.code:         
          ! allocate the (LARGE) look up tables for both U and V
          if (reverse) then
              allocate(rev_u_LUT(n_spd_values,n_dir_values,n_nsq_values,nxu,nz,ny))
              allocate(rev_v_LUT(n_spd_values,n_dir_values,n_nsq_values,nx,nz,nyv))
              u_LUT=>rev_u_LUT
              v_LUT=>rev_v_LUT
          else
              allocate(hi_u_LUT(n_spd_values,n_dir_values,n_nsq_values,nxu,nz,ny))
              allocate(hi_v_LUT(n_spd_values,n_dir_values,n_nsq_values,nx,nz,nyv))
              u_LUT=>hi_u_LUT
              v_LUT=>hi_v_LUT
          endif
  