source: dynamico_lmdz/simple_physics/phyparam/physics/logging.F90 @ 4235

Last change on this file since 4235 was 4235, checked in by dubos, 5 years ago

simple_physics : DYNAMICO driver

File size: 3.7 KB
Line 
1MODULE logging
2
3  ! see also use_logging.h
4  ! macro LOGBUF accumulates log output into logging_buffer
5
6  IMPLICIT NONE
7  SAVE
8  PRIVATE
9
10  INTERFACE  ! Explicit interfaces for plugins
11
12     ! Plugin that typically prints all lines in the loggin buffer 'buf' and prepends tags (log level, timestamp, ...)
13     SUBROUTINE plugin(lev, tag, buf)
14       INTEGER, INTENT(IN) :: lev
15       CHARACTER(*), INTENT(IN) :: tag, buf(:)
16     END SUBROUTINE plugin
17
18     ! Plugin that writes into string 'line' information about the gridpoint of index 'index'
19     SUBROUTINE plugin_log_gridpoint(index, line)
20       INTEGER, INTENT(IN) :: index ! index of gridpoint
21       CHARACTER(*), INTENT(OUT) :: line
22     END SUBROUTINE plugin_log_gridpoint
23
24  END INTERFACE
25
26
27  ! This module provides a default implementations of plugins but the top-level driver is welcome to override them.
28  ! Note F2003/F2008: pgfortran (F2003) accepts to initialize pointers only to NULL()
29  ! => plugins are initialzed to NULL() and set to default values in flush_log and log_gridpoint
30#ifndef XCODEML
31  ! Note F2003/F2008: XCodeML cannot parse procedure pointers
32  PROCEDURE(plugin), POINTER, PUBLIC :: flush_plugin => NULL()
33  PROCEDURE(plugin_log_gridpoint), POINTER, PUBLIC :: log_gridpoint_plugin => NULL()
34#endif
35
36  INTEGER, PARAMETER :: linesize=10000, logging_bufsize=100
37  CHARACTER(linesize) :: logging_buf(logging_bufsize)
38
39  INTEGER :: logging_lineno=0
40
41  ! messages with a log level > max_log_level are not printed
42  INTEGER, PARAMETER, PUBLIC :: log_level_fatal=1, log_level_error=2, log_level_warn=3, log_level_info=4, log_level_dbg=5
43  INTEGER, PUBLIC :: max_log_level = log_level_info
44  CHARACTER(3), DIMENSION(log_level_dbg), PUBLIC :: dbtag = (/ 'FAT', 'ERR', 'WRN', 'INF', 'DBG' /)
45
46  PUBLIC :: logging_buf, logging_bufsize, logging_lineno, flush_log, log_gridpoint, &
47       missing_plugin
48
49CONTAINS
50
51  SUBROUTINE missing_plugin(name, mod)
52    CHARACTER(*), INTENT(IN) :: name, mod
53    WRITE(logging_buf(1),*) 'WARNING : plugin ', name, ' not provided by the driver program'
54    WRITE(logging_buf(2),*) '        see ', mod
55    logging_lineno=2
56    CALL flush_log(log_level_warn, 'missing_plugin')
57  END SUBROUTINE missing_plugin
58
59  SUBROUTINE flush_log(lev,tag)
60    INTEGER, INTENT(IN) :: lev
61    CHARACTER(*), INTENT(IN) :: tag
62#ifndef XCODEML
63    IF(.NOT.ASSOCIATED(flush_plugin)) THEN
64       flush_plugin => default_flush_plugin
65       WRITE(*,*) 'WARNING : plugin flush_plugin not provided by the driver program'
66       WRITE(*,*) '        see logging.F90'
67    END IF
68    IF(logging_lineno>0 .AND. lev<=max_log_level) CALL flush_plugin(lev, TRIM(tag), logging_buf(1:logging_lineno))
69    logging_lineno=0
70#endif
71  END SUBROUTINE flush_log
72
73  SUBROUTINE default_flush_plugin(lev, tag, buf)
74    INTEGER, INTENT(IN) :: lev
75    CHARACTER(*), INTENT(IN) :: tag, buf(:)
76    CHARACTER(100) :: prefix
77    INTEGER :: i
78    WRITE(prefix,*) '[', dbtag(lev), ' ', tag, ']'
79    DO i=1, SIZE(buf)
80       WRITE(*,*) TRIM(prefix), TRIM(buf(i))
81    END DO
82  END SUBROUTINE default_flush_plugin
83
84  SUBROUTINE log_gridpoint(index)
85    INTEGER, INTENT(IN) :: index
86    logging_lineno = logging_lineno+1
87#ifndef XCODEML
88    IF(.NOT.ASSOCIATED(log_gridpoint_plugin)) THEN
89       log_gridpoint_plugin => default_log_gridpoint
90       WRITE(*,*) 'WARNING : plugin log_gridpoint_plugin not provided by the driver program'
91       WRITE(*,*) '        see logging.F90'
92    END IF
93    CALL log_gridpoint_plugin(index, logging_buf(logging_lineno))
94#endif
95  END SUBROUTINE log_gridpoint
96
97  SUBROUTINE default_log_gridpoint(index, line)
98    INTEGER, INTENT(IN) :: index ! index of gridpoint
99    CHARACTER(*), INTENT(OUT) :: line
100    line=' '
101  END SUBROUTINE default_log_gridpoint
102
103END MODULE logging
Note: See TracBrowser for help on using the repository browser.