anchor.diff:        !     print *, 'change in residual less than eps of previous residual. iteration:', eps, nit
         !     return
         ! This was not a good way of exiting the solver - it would occasionally leave after 2 or 3 iterations.
  -    endif
  +    end if
     end do
   
     print *,'warning: maximum iterations exceeded at time step ', n
  
positive.code:   do k = 1,layers
      u(:,:,k) = u(:,:,k)*hfacW*wetmask(:,:)
      v(:,:,k) = v(:,:,k)*hfacS*wetmask(:,:)
    enddo
  
    ! Wrap fields around for periodic simulations
    call wrap_fields_3D(u,nx,ny,layers)
  
negative.code:   do k = 1,layers
      u(:,:,k) = u(:,:,k)*hfacW*wetmask(:,:)
      v(:,:,k) = v(:,:,k)*hfacS*wetmask(:,:)
    end do
  
    ! Wrap fields around for periodic simulations
    call wrap_fields_3D(u,nx,ny,layers)
  