Changeset 4659 for palm/trunk/UTIL/inifor/src/inifor_control.f90
- Timestamp:
- Aug 31, 2020 11:21:17 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/UTIL/inifor/src/inifor_control.f90
r4523 r4659 21 21 ! Current revisions: 22 22 ! ----------------- 23 ! 24 ! 23 ! 24 ! 25 25 ! Former revisions: 26 26 ! ----------------- 27 27 ! $Id$ 28 ! List warnings after successful run or abort 29 ! Produce failure exit code (1) on program abort for test automation 30 ! Improved code formatting 31 ! 32 ! 33 ! 4523 2020-05-07 15:58:16Z eckhard 28 34 ! respect integer working precision (iwp) specified in inifor_defs.f90 29 35 ! … … 87 93 88 94 USE inifor_defs, & 89 ONLY: COPYRIGHT, LNAME, LOG_FILE_NAME, VERSION, iwp, wp95 ONLY: COPYRIGHT, LNAME, LOG_FILE_NAME, PATH, VERSION, iwp, wp 90 96 USE inifor_util, & 91 ONLY: real_to_str, real_to_str_f 97 ONLY: real_to_str, real_to_str_f, str 92 98 93 99 IMPLICIT NONE 94 100 95 CHARACTER (LEN=5000) :: message = '' !< log message buffer 96 CHARACTER (LEN=5000) :: tip = '' !< optional log message buffer for tips on how to rectify encountered errors 97 INTEGER(iwp), SAVE :: u !< Fortran file unit for the log file 98 INTEGER(iwp), SAVE :: n_wrngs = 0 !< Fortran file unit for the log file 101 INTEGER(iwp), SAVE :: u !< Fortran file unit for the log file 102 INTEGER(iwp), PARAMETER :: n_max_wrngs = 512 !< Fortran file unit for the log file 103 INTEGER(iwp), SAVE :: n_wrngs = 0 !< Fortran file unit for the log file 104 CHARACTER (LEN=5000) :: message = '' !< log message buffer 105 CHARACTER (LEN=5000) :: tip = '' !< optional log message buffer for tips on how to rectify encountered errors 106 CHARACTER (LEN=5000), SAVE :: warnings(n_max_wrngs) !< log of warnings 99 107 100 108 CONTAINS … … 112 120 !> to it. 113 121 !------------------------------------------------------------------------------! 114 SUBROUTINE report( routine, message, debug)122 SUBROUTINE report( routine, message, debug ) 115 123 116 124 CHARACTER(LEN=*), INTENT(IN) :: routine !< name of calling subroutine of function … … 128 136 129 137 suppress_message = .FALSE. 130 IF ( PRESENT( debug) ) THEN138 IF ( PRESENT( debug ) ) THEN 131 139 IF ( .NOT. debug ) suppress_message = .TRUE. 132 140 ENDIF 133 141 134 142 IF ( .NOT. suppress_message ) THEN 135 WRITE(*, '(A)') "inifor: " // TRIM(message) // " [ " // TRIM(routine) // " ]" 136 WRITE(u, '(A)') TRIM(message) // " [ " // TRIM(routine) // " ]" 143 CALL write_to_sdtout_and_logfile( & 144 TRIM( message ) // " [ " // TRIM( routine ) // " ]" & 145 ) 137 146 ENDIF 138 147 139 148 END SUBROUTINE report 149 150 151 !------------------------------------------------------------------------------! 152 ! Description: 153 ! ------------ 154 !> This routine writes the given message to SDTOUT as well as to the INIFOR log 155 !> file. 156 !------------------------------------------------------------------------------! 157 SUBROUTINE write_to_sdtout_and_logfile( message ) 158 159 CHARACTER(LEN=*), INTENT(IN) :: message 160 161 WRITE(*, '(A)') "inifor: " // TRIM( message ) 162 WRITE(u, '(A)') TRIM( message ) 163 164 END SUBROUTINE write_to_sdtout_and_logfile 140 165 141 166 … … 150 175 !> continue. 151 176 !------------------------------------------------------------------------------! 152 SUBROUTINE warn( routine, message)177 SUBROUTINE warn( routine, message ) 153 178 154 179 CHARACTER(LEN=*), INTENT(IN) :: routine !< name of calling subroutine or function 155 180 CHARACTER(LEN=*), INTENT(IN) :: message !< log message 156 181 182 CALL cache_warning( routine, message ) 183 CALL report( routine, "WARNING: " // TRIM( message ) ) 184 185 END SUBROUTINE warn 186 187 188 SUBROUTINE cache_warning( routine, message ) 189 190 CHARACTER(LEN=*), INTENT(IN) :: routine !< name of calling subroutine or function 191 CHARACTER(LEN=*), INTENT(IN) :: message !< log message 192 157 193 n_wrngs = n_wrngs + 1 158 CALL report(routine, "WARNING: " // TRIM(message)) 159 160 END SUBROUTINE warn 194 warnings(n_wrngs) = " WARNING: " // TRIM( message ) // & 195 " [ " // TRIM( routine ) // " ]" 196 197 END SUBROUTINE cache_warning 198 199 200 !------------------------------------------------------------------------------! 201 ! Description: 202 ! ------------ 203 !> 204 !> This routine writes all warnings cached with cache_warning() to STDOUT 205 !> and the INIFOR log file. 206 !------------------------------------------------------------------------------! 207 SUBROUTINE report_warnings() 208 209 INTEGER(iwp) :: warning_idx 210 211 IF (n_wrngs > 0) THEN 212 message = 'Encountered the following '// TRIM( str( n_wrngs ) ) // " warning(s) during this run:" 213 CALL report( 'report_warnings', message ) 214 215 DO warning_idx = 1, n_wrngs 216 CALL write_to_sdtout_and_logfile( warnings(warning_idx) ) 217 ENDDO 218 ENDIF 219 220 END SUBROUTINE report_warnings 221 222 !------------------------------------------------------------------------------! 223 ! Description: 224 ! ------------ 225 !> 226 !> Report successful run. To be called at the end of the main loop. 227 !------------------------------------------------------------------------------! 228 SUBROUTINE report_success( output_file_name ) 229 230 CHARACTER(LEN=PATH), INTENT(IN) :: output_file_name 231 232 message = "Finished writing dynamic driver '" // TRIM( output_file_name ) 233 message = TRIM( message ) // "' successfully." 234 IF (n_wrngs > 0) THEN 235 message = TRIM( message ) // " Some warnings were encountered." 236 ENDIF 237 CALL report( 'main loop', message ) 238 239 END SUBROUTINE report_success 240 241 242 !------------------------------------------------------------------------------! 243 ! Description: 244 ! ------------ 245 !> 246 !> Report runtime statistics 247 !------------------------------------------------------------------------------! 248 SUBROUTINE report_runtime() 249 250 CALL log_runtime( 'report', 'void' ) 251 252 END SUBROUTINE report_runtime 161 253 162 254 … … 171 263 !> INIFOR from continueing. 172 264 !------------------------------------------------------------------------------! 173 SUBROUTINE inifor_abort( routine, message)265 SUBROUTINE inifor_abort( routine , message ) 174 266 175 267 CHARACTER(LEN=*), INTENT(IN) :: routine !< name of calling subroutine or function 176 268 CHARACTER(LEN=*), INTENT(IN) :: message !< log message 177 269 178 CALL report(routine, "ERROR: " // TRIM(message) // " Stopping.") 270 CALL report( routine, "ERROR: " // TRIM( message ) // " Stopping." ) 271 CALL report_warnings 179 272 CALL close_log 180 STOP273 CALL EXIT(1) 181 274 182 275 END SUBROUTINE inifor_abort … … 185 278 SUBROUTINE close_log() 186 279 187 CLOSE( u)280 CLOSE( u ) 188 281 189 282 END SUBROUTINE close_log … … 209 302 !> accumulates them in timing budgets. 210 303 !------------------------------------------------------------------------------! 211 SUBROUTINE log_runtime( mode, budget)304 SUBROUTINE log_runtime( mode, budget ) 212 305 213 306 CHARACTER(LEN=*), INTENT(IN) :: mode !< name of the calling mode … … 226 319 227 320 228 SELECT CASE( TRIM(mode))229 230 CASE( 'init')321 SELECT CASE( TRIM( mode ) ) 322 323 CASE( 'init' ) 231 324 CALL CPU_TIME(t0) 232 325 233 CASE( 'time')326 CASE( 'time' ) 234 327 235 328 CALL CPU_TIME(t1) 236 329 237 SELECT CASE( TRIM(budget))238 239 CASE( 'alloc')330 SELECT CASE( TRIM( budget ) ) 331 332 CASE( 'alloc' ) 240 333 t_alloc = t_alloc + t1 - t0 241 334 242 CASE( 'init')335 CASE( 'init' ) 243 336 t_init = t_init + t1 - t0 244 337 245 CASE( 'read')338 CASE( 'read' ) 246 339 t_read = t_read + t1 - t0 247 340 248 CASE( 'write')341 CASE( 'write' ) 249 342 t_write = t_write + t1 - t0 250 343 251 CASE( 'comp')344 CASE( 'comp' ) 252 345 t_comp = t_comp + t1 - t0 253 346 254 347 CASE DEFAULT 255 CALL inifor_abort('log_runtime', "Time Budget '" // TRIM(mode) // "' is not supported.") 348 CALL inifor_abort( & 349 'log_runtime', & 350 "Time Budget '" // TRIM( mode ) // "' is not supported." & 351 ) 256 352 257 353 END SELECT … … 259 355 t0 = t1 260 356 261 CASE( 'report')357 CASE( 'report' ) 262 358 t_total = t_init + t_read + t_write + t_comp 263 359 264 CALL report( 'log_runtime', " *** CPU time ***")265 266 CALL report( 'log_runtime', "Initialization: " // TRIM( real_to_str( t_init ) ) // &267 " s (" // TRIM( real_to_str( 100 * t_init / t_total, fmt ) ) // " %)" )268 269 CALL report( 'log_runtime', "(De-)Allocation: " // TRIM( real_to_str( t_alloc ) ) // &270 " s (" // TRIM( real_to_str( 100 * t_alloc / t_total, fmt ) ) // " %)" )271 272 CALL report( 'log_runtime', "Reading data: " // TRIM( real_to_str( t_read ) ) // &273 " s (" // TRIM( real_to_str( 100 * t_read / t_total, fmt ) ) // " %)" )274 275 CALL report( 'log_runtime', "Writing data: " // TRIM( real_to_str( t_write ) ) // &276 " s (" // TRIM( real_to_str( 100 * t_write / t_total, fmt ) ) // " %)" )277 278 CALL report( 'log_runtime', "Computation: " // TRIM( real_to_str( t_comp ) ) // &279 " s (" // TRIM( real_to_str( 100 * t_comp / t_total, fmt) ) // " %)" )280 281 CALL report( 'log_runtime', "Total: " // TRIM( real_to_str( t_total ) ) // &282 " s (" // TRIM( real_to_str( 100 * t_total / t_total, fmt ) ) // " %)")360 CALL report( 'log_runtime', "*** CPU time ***" ) 361 362 CALL report( 'log_runtime', "Initialization: " // TRIM( real_to_str( t_init ) ) // & 363 " s (" // TRIM( real_to_str( 100 * t_init / t_total, fmt ) ) // " %)" ) 364 365 CALL report( 'log_runtime', "(De-)Allocation: " // TRIM( real_to_str( t_alloc ) ) // & 366 " s (" // TRIM( real_to_str( 100 * t_alloc / t_total, fmt ) ) // " %)" ) 367 368 CALL report( 'log_runtime', "Reading data: " // TRIM( real_to_str( t_read ) ) // & 369 " s (" // TRIM( real_to_str( 100 * t_read / t_total, fmt ) ) // " %)" ) 370 371 CALL report( 'log_runtime', "Writing data: " // TRIM( real_to_str( t_write ) ) // & 372 " s (" // TRIM( real_to_str( 100 * t_write / t_total, fmt ) ) // " %)" ) 373 374 CALL report( 'log_runtime', "Computation: " // TRIM( real_to_str( t_comp ) ) // & 375 " s (" // TRIM( real_to_str( 100 * t_comp / t_total, fmt) ) // " %)" ) 376 377 CALL report( 'log_runtime', "Total: " // TRIM( real_to_str( t_total ) ) // & 378 " s (" // TRIM( real_to_str( 100 * t_total / t_total, fmt ) ) // " %)" ) 283 379 284 380 CASE DEFAULT 285 CALL inifor_abort( 'log_runtime', "Mode '" // TRIM(mode) // "' is not supported.")381 CALL inifor_abort( 'log_runtime', "Mode '" // TRIM(mode) // "' is not supported." ) 286 382 287 383 END SELECT … … 289 385 END SUBROUTINE log_runtime 290 386 387 291 388 END MODULE inifor_control
Note: See TracChangeset
for help on using the changeset viewer.