| 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.1.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 | 17 | 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 | 17 | if(present(exit_code)) then | |
| 34 | ✗ | exit_code_ = exit_code | |
| 35 | else | ||
| 36 | 17 | exit_code_ = 1 | |
| 37 | end if | ||
| 38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if(present(block_stop)) then |
| 39 | ✗ | block_stop_ = block_stop | |
| 40 | else | ||
| 41 | 17 | block_stop_ = .false. | |
| 42 | end if | ||
| 43 | |||
| 44 |
1/2✓ Branch 4 taken 17 times.
✗ Branch 5 not taken.
|
17 | write(0,*) 'ERROR: ', trim(message) |
| 45 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | if(.not.block_stop_)then |
| 46 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if(.not.test_error_handling) then |
| 47 | ✗ | stop exit_code_ | |
| 48 | end if | ||
| 49 | end if | ||
| 50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | end subroutine stop_program |
| 51 | !############################################################################### | ||
| 52 | |||
| 53 | |||
| 54 | !############################################################################### | ||
| 55 | 34 | subroutine print_warning(message) | |
| 56 | !! Print a warning message | ||
| 57 | implicit none | ||
| 58 | character(len=*), intent(in) :: message | ||
| 59 | |||
| 60 | 34 | if(.not.suppress_warnings) then | |
| 61 |
1/2✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | write(0,*) 'WARNING: ', trim(message) |
| 62 | end if | ||
| 63 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 32 times.
|
34 | 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 |