anchor.diff:          if (.not.options%ideal) then
               call add_buffer_topo(domain%terrain,complex_terrain_firstpass,5)
               buffer=2
  -            call add_buffer_topo(real(real(complex_terrain_firstpass)),complex_terrain,0)
  +            call add_buffer_topo(real(real(complex_terrain_firstpass)),complex_terrain,0, debug=options%debug)
               buffer=buffer+original_buffer
           else
  -            call add_buffer_topo(domain%terrain,complex_terrain,0)
  +            call add_buffer_topo(domain%terrain,complex_terrain,0, debug=options%debug)
           endif
           
           nx=size(complex_terrain,1)
  
positive.code:                 end do
              end do
          endif
  !       allocate(real_terrain(nx,ny))
  !       real_terrain=buffer_topo
  !       call io_write2d("complex_terrain.nc","data",real_terrain)
  !       deallocate(real_terrain)
          
      end subroutine add_buffer_topo
      
  
negative.code:             buffer_topo(:,ny-pos) =buffer_topo(:,buffer+1)*(  weight) + buffer_topo(:,ny-buffer)*(1-weight)
          enddo
          
          ! smooth the outer most grid cells in all directions to minimize artifacts at the borders of real terrain
          ! smoothing effectively increases as it gets further from the real terrain border (window=min(j,smooth_window))
          if (smooth_window>0) then
              do j=1,buffer
                  window=min(j,smooth_window)
                  ! smooth the top and bottom borders
                  do i=1,nx
                      xs=max(1, i-window)
                      xe=min(nx,i+window)
  