logical function compare_real_2d(label, got, exp, tol)
implicit none
character(len=*), intent(in) :: label
real, intent(in) :: got(:,:), exp(:,:)
real, intent(in) :: tol
real :: max_abs
integer :: imax(2)
max_abs = maxval(abs(got - exp))
compare_real_2d = max_abs <= tol
if ((.not. compare_real_2d) .and. myid == 0) then
imax = maxloc(abs(got - exp))
write(*,'(A,1X,A,1X,ES12.4,1X,A,I0,A,I0,1X,A,ES12.4,1X,A,ES12.4)') &
'FAIL', trim(label), max_abs, 'idx', imax(1), ',', imax(2), 'got', got(imax(1),imax(2)), 'exp', exp(imax(1),imax(2))
end if
end function compare_real_2d