FV3 Bundle
ncdc_climsg.F90
Go to the documentation of this file.
1 module ncdc_climsg
2  use ncd_kinds, only: i_long
3  use netcdf, only: nf90_noerr, nf90_strerror
4 
5 #ifdef USE_MPI
6  use ncdc_state, only: cur_proc
7 #endif
8 
9  implicit none
10 
11 #ifdef QUIET
12  logical :: ncdc_enable_info = .false.
13  logical :: ncdc_enable_warn = .false.
14 #else
15  logical :: ncdc_enable_info = .true.
16  logical :: ncdc_enable_warn = .true.
17 #endif
18 
19  contains
20  subroutine ncdc_check(status)
21  integer(i_long), intent(in) :: status
22 
23  if(status /= nf90_noerr) then
24  call ncdc_error(trim(nf90_strerror(status)))
25  end if
26  end subroutine ncdc_check
27 
28  subroutine ncdc_error(err)
29  character(len=*), intent(in) :: err
30 #ifdef ERROR_TRACEBACK
31  integer(i_long) :: div0
32 #endif
33 #ifdef USE_MPI
34  write(*, "(A, I0, A)") &
35 #else
36  write(*, "(A)") &
37 #endif
38 #ifdef USE_MPI
39  "[PROC ", cur_proc, "]" // &
40 #endif
41  " ** ERROR: " // err
42 #ifdef ERROR_TRACEBACK
43  write(*, "(A)") " ** Failed to concatenate NetCDF4."
44  write(*, "(A)") " (Traceback requested, triggering div0 error...)"
45  div0 = 1 / 0
46  write(*, "(A)") " Couldn't trigger traceback, ending gracefully."
47  write(*, "(A)") " (Ensure floating point exceptions are enabled,"
48  write(*, "(A)") " and that you have debugging (-g) and tracebacks"
49  write(*, "(A)") " compiler flags enabled!)"
50  stop 1
51 #else
52  write(*,"(A)") " ** Failed to concatenate NetCDF4."
53  stop " ** Failed to concatenate NetCDF4."
54 #endif
55  end subroutine ncdc_error
56 
57  subroutine ncdc_warning(warn)
58  character(len=*), intent(in) :: warn
59  if (ncdc_enable_warn) &
60 #ifdef USE_MPI
61  write(*, "(A, I0, A)") &
62 #else
63  write(*, "(A)") &
64 #endif
65 #ifdef USE_MPI
66  "[PROC ", cur_proc, "]" // &
67 #endif
68  " ** WARNING: " // warn
69  end subroutine ncdc_warning
70 
71  subroutine ncdc_info(ifo)
72  character(len=*), intent(in) :: ifo
73  if (ncdc_enable_info) &
74 #ifdef USE_MPI
75  write(*, "(A, I0, A)") &
76 #else
77  write(*, "(A)") &
78 #endif
79 #ifdef USE_MPI
80  "[PROC ", cur_proc, "]" // &
81 #endif
82  " ** INFO: " // ifo
83  end subroutine ncdc_info
84 
85 #ifdef _DEBUG_MEM_
86  subroutine ncdc_debug(dbg)
87  character(len=*), intent(in) :: dbg
88  write(*, "(A, A)") "D: ", dbg
89  end subroutine ncdc_debug
90 #endif
91 end module ncdc_climsg
integer, parameter, public i_long
Definition: ncd_kinds.F90:47
subroutine ncdc_error(err)
Definition: ncdc_climsg.F90:29
subroutine ncdc_info(ifo)
Definition: ncdc_climsg.F90:72
subroutine ncdc_warning(warn)
Definition: ncdc_climsg.F90:58
subroutine ncdc_check(status)
Definition: ncdc_climsg.F90:21