Line | Branch | Exec | Source |
---|---|---|---|
1 | module raffle__io_utils | ||
2 | !! Module for handling errors and io calls in the program. | ||
3 | !! | ||
4 | !! This module provides the expected procedure for stopping a program. | ||
5 | !! If in testing mode, the stop can be suppressed. | ||
6 | implicit none | ||
7 | logical :: test_error_handling = .false. | ||
8 | |||
9 | logical :: suppress_warnings = .false. | ||
10 | character(len=*), parameter :: raffle__version__ = "1.0.1" | ||
11 | |||
12 | private | ||
13 | |||
14 | public :: raffle__version__ | ||
15 | public :: test_error_handling, suppress_warnings | ||
16 | public :: stop_program, print_warning | ||
17 | public :: print_version, print_build_info | ||
18 | |||
19 | |||
20 | contains | ||
21 | |||
22 | !############################################################################### | ||
23 | 12 | subroutine stop_program(message, exit_code, block_stop) | |
24 | !! Stop the program and print an error message. | ||
25 | implicit none | ||
26 | character(len=*), intent(in) :: message | ||
27 | integer, intent(in), optional :: exit_code | ||
28 | logical, intent(in), optional :: block_stop | ||
29 | |||
30 | integer :: exit_code_ | ||
31 | logical :: block_stop_ | ||
32 | |||
33 | 12 | if(present(exit_code)) then | |
34 | 1 | exit_code_ = exit_code | |
35 | else | ||
36 | 11 | exit_code_ = 1 | |
37 | end if | ||
38 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
|
12 | if(present(block_stop)) then |
39 | 2 | block_stop_ = block_stop | |
40 | else | ||
41 | 10 | block_stop_ = .false. | |
42 | end if | ||
43 | |||
44 |
1/2✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
12 | write(0,*) 'ERROR: ', trim(message) |
45 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if(.not.block_stop_)then |
46 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if(.not.test_error_handling) then |
47 | ✗ | stop exit_code_ | |
48 | end if | ||
49 | end if | ||
50 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
|
12 | end subroutine stop_program |
51 | !############################################################################### | ||
52 | |||
53 | |||
54 | !############################################################################### | ||
55 | 36 | subroutine print_warning(message) | |
56 | !! Print a warning message | ||
57 | implicit none | ||
58 | character(len=*), intent(in) :: message | ||
59 | |||
60 | 36 | if(.not.suppress_warnings) then | |
61 |
1/2✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | write(0,*) 'WARNING: ', trim(message) |
62 | end if | ||
63 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 32 times.
|
36 | end subroutine print_warning |
64 | !############################################################################### | ||
65 | |||
66 | |||
67 | !############################################################################### | ||
68 | 2 | subroutine print_version() | |
69 | !! Print the version number of the program. | ||
70 | implicit none | ||
71 | |||
72 | 2 | write(*,'("version: ",A)') raffle__version__ | |
73 | 2 | end subroutine print_version | |
74 | !############################################################################### | ||
75 | |||
76 | |||
77 | !############################################################################### | ||
78 | 1 | subroutine print_build_info() | |
79 | !! Print the build information of the program. | ||
80 | implicit none | ||
81 | |||
82 | 1 | write(*,'("RAFFLE: pseudoRandom Approach For Finding Local Energy minima")') | |
83 | 1 | call print_version() | |
84 | 1 | write(*,'(" (build ",A,1X,A,")")') __DATE__, __TIME__ | |
85 | |||
86 | 1 | end subroutine print_build_info | |
87 | !############################################################################### | ||
88 | |||
89 | end module raffle__io_utils | ||
90 |