anchor.diff:          allocate(inputwind(nx,ny,nz)) ! Can't be module level because nx,ny,nz could change between calls,
   
           inputwind=wind !make a copy so we always use the unsmoothed data when computing the smoothed data
  -        if (((windowsize*2+1)>nx).and.(ydim==3)) then
  -            write(*,*) "WARNING can not operate if windowsize*2+1 is larger than nx"
  -            write(*,*) "NX         = ", nx
  -            write(*,*) "windowsize = ", windowsize
  -            stop
  +        if (( ( (windowsize*2+1)>nz) .or. ((windowsize*2+1)>nx) ) .and. (ydim==3)) then
  +            write(*,*) "WARNING smoothing windowsize*2+1 is larger than nx or ny."
  +            write(*,*) "  This might lead to artifacts in the wind field especially near the borders."
  +            write(*,*) "  NX         = ", nx
  +            write(*,*) "  NY         = ", nz
  +            write(*,*) "  windowsize = ", windowsize
           endif
   
           !parallelize over a slower dimension (not the slowest because it is MUCH easier this way)
  
positive.code:                     ! if we are pinned to the top edge
                      if ((k-windowsize)<=1) then
                          starty=1
                          endy  =k+windowsize
                          rowsums=rowsums-inputwind(1:nx,j,starty)+inputwind(1:nx,j,endy)
                      ! if we are pinned to the bottom edge
                      else if ((k+windowsize)>nz) then
                          starty=k-windowsize
                          endy  =nz
                          rowsums=rowsums-inputwind(1:nx,j,starty-1)+inputwind(1:nx,j,endy)
                      ! if we are in the middle (this is the most common)
                      else
                          starty=k-windowsize
                          endy  =k+windowsize
                          rowsums=rowsums-inputwind(1:nx,j,starty-1)+inputwind(:,j,endy)
                      endif
                      rowmeans=rowsums/nrows
  
negative.code:                         ! if we are pinned to the left edge
                          if ((i-windowsize)<=1) then
                              startx=1
                              endx  =min(nx,i+windowsize)
                              cursum=cursum-rowmeans(startx)+rowmeans(endx)
                          ! if we are pinned to the right edge
                          else if ((i+windowsize)>nx) then
                              startx=max(2,i-windowsize)
                              endx  =nx
                              cursum=cursum-rowmeans(startx-1)+rowmeans(endx)
                          ! if we are in the middle (this is the most common)
                          else
                              startx=max(2,i-windowsize)
                              endx  =min(nx,i+windowsize)
                              cursum=cursum-rowmeans(startx-1)+rowmeans(endx)
                          endif
  
  