1414
1515contains
1616
17+ ! Do our best to portably flush anything that might be buffered in the Fortran I/O library
18+ subroutine flush_all ()
19+ flush output_unit
20+ flush error_unit
21+ end subroutine
22+
1723 module procedure prif_register_stop_callback
1824 type (callback_entry), pointer :: new_entry
1925 allocate (new_entry)
2531 end procedure
2632
2733 module procedure prif_stop
34+
35+ call flush_all()
36+
2837 call prif_sync_all
2938 call run_callbacks(.false. _c_bool, quiet, stop_code_int, stop_code_char)
3039
3544 end if
3645
3746 contains
38-
3947 subroutine prif_stop_integer (quiet , stop_code )
4048 ! ! synchronize, stop the executing image, and provide the stop_code, or 0 if not present, as the process exit status
4149 logical (c_bool), intent (in ) :: quiet
@@ -45,17 +53,17 @@ subroutine prif_stop_integer(quiet, stop_code)
4553 if (present (stop_code)) then
4654 if (.not. quiet) then
4755 write (output_unit, * ) " STOP " , stop_code
48- flush output_unit
4956 end if
5057 exit_code = stop_code
5158 else
5259 if (.not. quiet) then
5360 write (output_unit, * ) " STOP"
54- flush output_unit
5561 end if
5662 exit_code = 0_c_int
5763 end if
5864
65+ call flush_all()
66+
5967 call caf_decaffeinate(exit_code)
6068
6169 end subroutine prif_stop_integer
@@ -67,16 +75,20 @@ subroutine prif_stop_character(quiet, stop_code)
6775
6876 if (.not. quiet) then
6977 write (output_unit, * ) " STOP '" // stop_code // " '"
70- flush output_unit
7178 end if
7279
80+ call flush_all()
81+
7382 call caf_decaffeinate(exit_code= 0_c_int ) ! does not return
7483
7584 end subroutine prif_stop_character
7685
7786 end procedure prif_stop
7887
7988 module procedure prif_error_stop
89+
90+ call flush_all()
91+
8092 call run_callbacks(.true. _c_bool, quiet, stop_code_int, stop_code_char)
8193 if (present (stop_code_char)) then
8294 call prif_error_stop_character(quiet, stop_code_char)
@@ -92,9 +104,10 @@ subroutine prif_error_stop_character(quiet, stop_code)
92104
93105 if (.not. quiet) then
94106 write (error_unit, * ) " ERROR STOP '" // stop_code // " '"
95- flush error_unit
96107 end if
97108
109+ call flush_all()
110+
98111 call caf_decaffeinate(1_c_int ) ! does not return
99112 end subroutine
100113
@@ -107,17 +120,17 @@ subroutine prif_error_stop_integer(quiet, stop_code)
107120 if (present (stop_code)) then
108121 if (.not. quiet) then
109122 write (error_unit,' (A, I0)' ) " ERROR STOP " , stop_code
110- flush error_unit
111123 end if
112124 exit_code = stop_code
113125 else
114126 if (.not. quiet) then
115127 write (error_unit,' (a)' ) " ERROR STOP"
116- flush error_unit
117128 end if
118129 exit_code = 1_c_int
119130 end if
120131
132+ call flush_all()
133+
121134 call caf_decaffeinate(exit_code) ! does not return
122135 end subroutine
123136
0 commit comments