Skip to content

Commit ccc5054

Browse files
authored
Refactor m_checker (#488)
1 parent 8956d74 commit ccc5054

File tree

11 files changed

+1593
-2083
lines changed

11 files changed

+1593
-2083
lines changed

src/common/m_checker_common.fpp

Lines changed: 478 additions & 0 deletions
Large diffs are not rendered by default.

src/common/m_helper.fpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ module m_helper
3636
f_create_bbox, &
3737
s_print_2D_array, &
3838
f_xor, &
39-
f_logical_to_int
39+
f_logical_to_int, &
40+
f_approx_equal, &
41+
f_is_default, &
42+
f_all_default
4043

4144
contains
4245

@@ -532,4 +535,56 @@ contains
532535
end if
533536
end function f_logical_to_int
534537

538+
!> This procedure checks if two floating point numbers of kind(0d0) are within tolerance.
539+
!! @param a First number.
540+
!! @param b Second number.
541+
!! @param tol_input Relative error (default = 1d-6).
542+
!! @return Result of the comparison.
543+
logical function f_approx_equal(a, b, tol_input) result(res)
544+
! Reference: https://floating-point-gui.de/errors/comparison/
545+
546+
real(kind(0d0)), intent(in) :: a, b
547+
real(kind(0d0)), optional, intent(in) :: tol_input
548+
real(kind(0d0)) :: tol
549+
550+
if (present(tol_input)) then
551+
if (tol_input <= 0d0) then
552+
call s_mpi_abort('tol_input must be positive. Exiting ...')
553+
end if
554+
tol = tol_input
555+
else
556+
tol = 1d-6
557+
end if
558+
559+
if (a == b) then
560+
res = .true.
561+
else if (a == 0d0 .or. b == 0d0 .or. (abs(a) + abs(b) < tiny(a))) then
562+
res = (abs(a - b) < (tol*tiny(a)))
563+
else
564+
res = (abs(a - b)/min(abs(a) + abs(b), huge(a)) < tol)
565+
end if
566+
end function f_approx_equal
567+
568+
!> Checks if a real(kind(0d0)) variable is of default value.
569+
!! @param var Variable to check.
570+
logical function f_is_default(var) result(res)
571+
real(kind(0d0)), intent(in) :: var
572+
573+
res = f_approx_equal(var, dflt_real)
574+
end function f_is_default
575+
576+
!> Checks if ALL elements of a real(kind(0d0)) array are of default value.
577+
!! @param var_array Array to check.
578+
logical function f_all_default(var_array) result(res)
579+
real(kind(0d0)), intent(in) :: var_array(:)
580+
logical :: res_array(size(var_array))
581+
integer :: i
582+
583+
do i = 1, size(var_array)
584+
res_array(i) = f_is_default(var_array(i))
585+
end do
586+
587+
res = all(res_array)
588+
end function f_all_default
589+
535590
end module m_helper

src/post_process/m_checker.f90

Lines changed: 118 additions & 430 deletions
Large diffs are not rendered by default.

src/post_process/m_start_up.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ module m_start_up
3131

3232
use m_compile_specific
3333

34+
use m_checker_common
35+
3436
use m_checker
3537
! ==========================================================================
3638

@@ -131,6 +133,7 @@ subroutine s_check_input_file
131133
'case_dir. Exiting ...')
132134
end if
133135

136+
call s_check_inputs_common()
134137
call s_check_inputs()
135138

136139
end subroutine s_check_input_file

0 commit comments

Comments
 (0)