anchor.diff:          !$omp shared(input,inputtemp)
           allocate(rowsums(nx))
           allocate(rowmeans(nx))
  -        nrows = windowsize * 2 + 1
  -        ncols = windowsize * 2 + 1
  +        nrows = min(nx,windowsize * 2 + 1)
  +        ncols = min(ny,windowsize * 2 + 1)
           !$omp do schedule(static)
           do j=1,ny
   
  
positive.code:         allocate(inputtemp(nx,ny))
  
          inputtemp = input !make a copy so we always use the unsmoothed data when computing the smoothed data
          if ((windowsize*2+1)>nx) then
              write(*,*) "WARNING can not operate if windowsize*2+1 is larger than nx"
              write(*,*) "NX         = ", nx
              write(*,*) "windowsize = ", windowsize
              stop
          endif
  
          !parallelize over a slower dimension (not the slowest because it is MUCH easier this way)
          ! as long as the inner loops (the array operations) are over the fastest dimension we are mostly OK
  
negative.code: 
          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+1)>nx).and.(ydim==3)) then
              write(*,*) "WARNING can not operate if windowsize+1 is larger than nx"
              write(*,*) "NX         = ", nx
              write(*,*) "windowsize = ", windowsize
              print*, "Image = ",this_image()
              stop
          endif
  
  