logical function compare_real_3d(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(3)
max_abs = maxval(abs(got - exp))
compare_real_3d = max_abs <= tol
if ((.not. compare_real_3d) .and. myid == 0) then
imax = maxloc(abs(got - exp))
write(*,'(A,1X,A,1X,ES12.4,1X,A,I0,A,I0,A,I0,1X,A,ES12.4,1X,A,ES12.4,1X,A,ES12.4)') &
'FAIL', trim(label), max_abs, 'idx', imax(1), ',', imax(2), ',', imax(3), &
'got', got(imax(1),imax(2),imax(3)), 'exp', exp(imax(1),imax(2),imax(3)), 'tol', tol
end if
end function compare_real_3d