anchor.diff:                  wsArray(loc) = wsArray(loc) - deltav
   
               end if
  +            
  +            ! make sure turbine flow-field velocity is non-negative
  +            if (wsArray(loc) .lt. 0.0_dp) then 
  +                wsArray(loc) = 0.0_dp
  +            end if
  +            
           end do
       end do
   
  
positive.code: ! implementation of the Bastankhah and Porte Agel (BPA) wake model for analysis
  subroutine porteagel_analyze(nTurbines, turbineXw, turbineYw, turbineZ, &
                               rotorDiameter, Ct, wind_speed, &
                               yawDeg, ky, kz, alpha, beta, I, wtVelocity)
  
      ! independent variables: turbineXw turbineYw turbineZ rotorDiameter
      !                        Ct yawDeg
  
negative.code:     end if
                               
  end subroutine overlap_area_func
  
  ! combine wakes using various methods
  subroutine wake_combination_func(Uinf, Ueffu, Ueffd, tmp, wake_combination_method, &
                                   deficit)
      ! combines wakes to calculate velocity at a given turbine
      ! Uinf      = Free stream velocity
      ! Ueffu     = Effective velocity as seen by the upstream rotor
      ! Ueffd     = Current effective velocity as seen by the downstream rotor
      ! tmp       =
      ! velocity  = new effective velocity at this turbine
       
      implicit none
          
      ! define precision to be the standard for a double precision ! on local system
      integer, parameter :: dp = kind(0.d0)
      
      ! in
      real(dp), intent(in) :: Uinf, Ueffu, Ueffd, tmp
      integer, intent(in) :: wake_combination_method
      
      ! out    
      real(dp), intent(out) :: deficit
      
      ! local
      real(dp), parameter :: pi = 3.141592653589793_dp
      
      intrinsic sqrt
      
      ! freestream linear superposition
      if (wake_combination_method == 0) then
          deficit = (Uinf - Ueffd) + tmp
  
      ! local velocity linear superposition
      else if (wake_combination_method == 1) then
          deficit = (Ueffu - Ueffd) + tmp
          
      ! sum of squares freestream superposition
      else if (wake_combination_method == 2) then 
          deficit = sqrt((Uinf - Ueffd)**2 + tmp**2)
      
      !sum of squares local velocity superposition
      else if (wake_combination_method == 3) then
          deficit = sqrt((Ueffu - Ueffd)**2 + tmp**2)
      
      ! error
      else
          print *, "Invalid wake combination method. Must be one of [0,1,2,3]."
          stop 1
      end if                       
      
  end subroutine wake_combination_func
  