Skip to content

Commit

Permalink
First pass removing 'error code returned' messages
Browse files Browse the repository at this point in the history
I created a new subroutine to standardize the error traceback in MARBL. When
first encountering an error, call LOG%log_error() and return; every subsequent
call should be to LOG%log_error_trace, which takes the name of the routine that
produced the error as an argument rather than a log message.

Note that this is just a wrapper script - log_error_trace creates the log
message

"Error reported from [routine name]"

and then calls LOG%log_error with that message.

I say "first pass" because I still need to adapt the errors from
add_diagnostics() and add_forcing_field(), where I want to include the name of
the diagnostic [or forcing] field that produced the error. I was originally
thinking that I should add an optional argument for field name, but instead I
might treat add_forcing_field([FIELDNAME]) as the routine name.
  • Loading branch information
mnlevy1981 committed Apr 5, 2016
1 parent 2703f18 commit e257a8c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 65 deletions.
4 changes: 1 addition & 3 deletions src/marbl_ciso_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ subroutine marbl_ciso_set_interior_forcing( &
! local variables
!-----------------------------------------------------------------------
character(*), parameter :: subname = 'marbl_ciso_mod:marbl_ciso_set_interior forcing'
character(len=char_len) :: log_message

logical (log_kind) :: zero_mask

Expand Down Expand Up @@ -645,8 +644,7 @@ subroutine marbl_ciso_set_interior_forcing( &
cell_radius, cell_permea, cell_eps_fix, marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from setup_cell_attributes"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace("setup_cell_attributes", subname)
return
end if

Expand Down
12 changes: 3 additions & 9 deletions src/marbl_co2calc_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ subroutine marbl_co2calc_surf( &
! local variable declarations
!---------------------------------------------------------------------------
character(*), parameter :: subname = 'marbl_co2calc:marbl_co2calc_surf'
character(len=char_len) :: log_message
integer(kind=int_kind) :: n
integer(kind=int_kind) :: k
real(kind=r8) :: mass_to_vol ! (mol/kg) -> (mmol/m^3)
Expand Down Expand Up @@ -201,8 +200,7 @@ subroutine marbl_co2calc_surf( &

if (present (marbl_status_log)) then
if (marbl_status_log%labort_marbl) then
log_message = "error code returned from comp_htotal"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace("comp_htotal()", subname)
return
end if
end if
Expand Down Expand Up @@ -306,7 +304,6 @@ subroutine marbl_comp_CO3terms(&
! local variable declarations
!---------------------------------------------------------------------------
character(*), parameter :: subname = 'marbl_co2calc:marbl_comp_CO3terms'
character(len=char_len) :: log_message
integer(kind=int_kind) :: c
real(kind=r8) :: mass_to_vol ! (mol/kg) -> (mmol/m^3)
real(kind=r8) :: vol_to_mass ! (mmol/m^3) -> (mol/kg)
Expand Down Expand Up @@ -372,8 +369,7 @@ subroutine marbl_comp_CO3terms(&
phlo, phhi, htotal, marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from comp_htotal"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace("comp_htotal()", subname)
return
end if

Expand Down Expand Up @@ -791,7 +787,6 @@ subroutine comp_htotal(num_elements, mask, temp, dic_in, ta_in, pt_in, sit_in, &
! local variable declarations
!---------------------------------------------------------------------------
character(*), parameter :: subname = 'marbl_co2calc:marbl_comp_htotal'
character(len=char_len) :: log_message
integer(kind=int_kind) :: c
real(kind=r8) :: mass_to_vol ! (mol/kg) -> (mmol/m^3)
real(kind=r8) :: vol_to_mass ! (mmol/m^3) -> (mol/kg)
Expand Down Expand Up @@ -869,8 +864,7 @@ subroutine comp_htotal(num_elements, mask, temp, dic_in, ta_in, pt_in, sit_in, &
marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from drtsafe"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace("drtsafe", subname)
return
end if

Expand Down
28 changes: 10 additions & 18 deletions src/marbl_interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ subroutine init(this, &
real (r8) , intent(in) :: gcm_zw(gcm_num_levels) ! thickness of layer k
real (r8) , intent(in) :: gcm_zt(gcm_num_levels) ! thickness of layer k

character(len=char_len) :: log_message
character(*), parameter :: subname = 'marbl_interface:marbl_init'
integer :: i
!--------------------------------------------------------------------

Expand All @@ -176,16 +176,14 @@ subroutine init(this, &

call marbl_init_nml(gcm_nl_buffer, this%statusLog)
if (this%statusLog%labort_marbl) then
call this%statusLog%log_error("error code returned from marbl_init_nml", &
"marbl_interface::marbl_init()")
call this%statusLog%log_error_trace("marbl_init_nml()", subname)
return
end if

if (gcm_ciso_on) then
call marbl_ciso_init_nml(gcm_nl_buffer, this%statusLog)
if (this%statusLog%labort_marbl) then
call this%statusLog%log_error("error code returned from marbl_ciso_init_nml", &
"marbl_interface::marbl_init()")
call this%statusLog%log_error_trace("marbl_ciso_init_nml()", subname)
return
end if
end if
Expand Down Expand Up @@ -246,8 +244,7 @@ subroutine init(this, &
this%statusLog)

if (this%statusLog%labort_marbl) then
call this%statusLog%log_error("error code returned from marbl_init_tracer_metadata", &
"marbl_interface::marbl_init()")
call this%statusLog%log_error_trace("marbl_init_tracer_metadata()", subname)
return
end if

Expand All @@ -257,8 +254,7 @@ subroutine init(this, &
this%statusLog)

if (this%statusLog%labort_marbl) then
call this%statusLog%log_error("error code returned from marbl_ciso_init_tracer_metadata", &
"marbl_interface::marbl_init()")
call this%statusLog%log_error_trace("marbl_ciso_init_tracer_metadata()", subname)
return
end if
end if
Expand All @@ -275,8 +271,7 @@ subroutine init(this, &
surface_forcing_fields = this%surface_forcing_fields, &
marbl_status_log = this%StatusLog)
if (this%statusLog%labort_marbl) then
log_message = "error code returned from marbl_init_surface_forcing_fields"
call this%statusLog%log_error(log_message, "marbl_interface::marbl_init()")
call this%statusLog%log_error_trace("marbl_init_surface_forcing_fields()", subname)
return
end if

Expand All @@ -292,8 +287,7 @@ subroutine init(this, &
tracer_metadata = this%tracer_metadata(ecosys_ind_beg:ecosys_ind_end), &
status_log = this%statusLog)
if (this%statusLog%labort_marbl) then
call this%statusLog%log_error("error code returned from this%restoring%init", &
"marbl_interface::marbl_init()")
call this%statusLog%log_error_trace("this%restoring%init()", subname)
return
end if

Expand All @@ -310,8 +304,7 @@ subroutine init(this, &
marbl_surface_forcing_diags = this%surface_forcing_diags, &
marbl_status_log = this%StatusLog)
if (this%statusLog%labort_marbl) then
call this%statusLog%log_error("error code returned from marbl_diagnostics_init", &
"marbl_interface::marbl_init()")
call this%statusLog%log_error_trace("marbl_diagnostics_init()", subname)
return
end if

Expand All @@ -328,7 +321,7 @@ subroutine set_interior_forcing(this)
implicit none

class(marbl_interface_class), intent(inout) :: this
character(len=char_len) :: log_message
character(*), parameter :: subname='marbl_interface:set_interior_forcing'

call this%restoring%restore_tracers( &
this%column_tracers, &
Expand All @@ -354,8 +347,7 @@ subroutine set_interior_forcing(this)
marbl_status_log = this%statusLog)

if (this%statusLog%labort_marbl) then
log_message = "error code returned from marbl_set_interior_forcing"
call this%statusLog%log_error(log_message, "marbl_interface::set_interior_forcing")
call this%statusLog%log_error_trace("marbl_set_interior_forcing()", subname)
return
end if

Expand Down
10 changes: 3 additions & 7 deletions src/marbl_interface_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ subroutine marbl_sfo_add(this, num_elements, field_name, sfo_id, &
type(marbl_single_sfo_type), dimension(:), pointer :: new_sfo
integer :: n, old_size
character(len=*), parameter :: subname = 'marbl_interface_types:marbl_sfo_add'
character(len=char_len) :: log_message

if (associated(this%sfo)) then
old_size = size(this%sfo)
Expand All @@ -477,8 +476,7 @@ subroutine marbl_sfo_add(this, num_elements, field_name, sfo_id, &
call new_sfo(sfo_id)%construct(num_elements, field_name, sfo_id, &
marbl_status_log)
if (marbl_status_log%labort_marbl) then
log_message = "error code returned from new_sfo%construct"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('new_sfo%construct()', subname)
return
end if

Expand Down Expand Up @@ -563,8 +561,7 @@ subroutine marbl_diagnostics_add(this, lname, sname, units, vgrid, &
call this%diags(id)%initialize(lname, sname, units, vgrid, truncate, &
this%num_elements, this%num_levels, marbl_status_log)
if (marbl_status_log%labort_marbl) then
log_message = "error code returned from this%diags%initialize"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('this%diags%initialize()', subname)
return
end if

Expand Down Expand Up @@ -873,8 +870,7 @@ subroutine marbl_forcing_fields_add(this, &
marbl_forcing_calendar_name=marbl_forcing_calendar_name, &
marbl_status_log = marbl_status_log)
if (marbl_status_log%labort_MARBL) then
log_message = "error code returned from this%forcing_fields%initialize"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('this%forcing_fields%initialize()', subname)
return
end if

Expand Down
13 changes: 13 additions & 0 deletions src/marbl_logging.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module marbl_logging
procedure, public :: log_namelist => marbl_log_namelist
procedure, public :: log_error => marbl_log_error
procedure, public :: log_noerror => marbl_log_noerror
procedure, public :: log_error_trace => marbl_log_error_trace
procedure, public :: erase => marbl_log_erase
end type marbl_log_type

Expand Down Expand Up @@ -215,6 +216,18 @@ subroutine marbl_log_noerror(this, StatusMsg, CodeLoc, ElemInd, lall_tasks)

end subroutine marbl_log_noerror

subroutine marbl_log_error_trace(this, RoutineName, CodeLoc, ElemInd)

class(marbl_log_type), intent(inout) :: this
character(len=*), intent(in) :: RoutineName, CodeLoc
integer, optional, intent(in) :: ElemInd
character(len=char_len) :: log_message

write(log_message, "(2A)") "Error reported from ", trim(RoutineName)
call this%log_error(log_message, CodeLoc, ElemInd)

end subroutine marbl_log_error_trace

subroutine marbl_log_erase(this)

class(marbl_log_type), intent(inout) :: this
Expand Down
47 changes: 19 additions & 28 deletions src/marbl_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,7 @@ subroutine marbl_init_nml(nl_buffer, marbl_status_log)
! FIXME #11: eliminate marbl_parms!
call marbl_params_init(nl_buffer, marbl_status_log)
if (marbl_status_log%labort_marbl) then
log_message = "error code returned from marbl_params_init"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('marbl_params_init', subname)
return
end if

Expand Down Expand Up @@ -1508,7 +1507,6 @@ subroutine marbl_init_tracer_metadata(marbl_tracer_metadata, marbl_status_log)
!-----------------------------------------------------------------------

character(*), parameter :: subname = 'marbl_mod:marbl_init_tracer_metadata'
character(len=char_len) :: log_message

integer (int_kind) :: non_living_biomass_ecosys_tracer_cnt ! number of non-autotroph ecosystem tracers
integer (int_kind) :: n ! index for looping over tracers
Expand All @@ -1532,25 +1530,25 @@ subroutine marbl_init_tracer_metadata(marbl_tracer_metadata, marbl_status_log)
call marbl_check_ecosys_tracer_count_consistency(non_living_biomass_ecosys_tracer_cnt, marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from marbl_check_ecosys_tracer_count_consistency"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace( &
'marbl_check_ecosys_tracer_count_consistency()', subname)
return
end if

call marbl_init_zooplankton_tracer_metadata(marbl_tracer_metadata, &
non_living_biomass_ecosys_tracer_cnt, n, marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from marbl_init_zooplankton_tracer_metadata"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('marbl_init_zooplankton_tracer_metadata()', &
subname)
return
end if

call marbl_init_autotroph_tracer_metadata(marbl_tracer_metadata, n, marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from marbl_init_autotroph_tracer_metadata"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('marbl_init_autortoph_tracer_metadata()', &
subname)
return
end if

Expand Down Expand Up @@ -1634,7 +1632,6 @@ subroutine marbl_set_interior_forcing( &
! local variables
!-----------------------------------------------------------------------
character(*), parameter :: subname = 'marbl_mod:marbl_set_interior_forcing'
character(len=char_len) :: log_message

integer (int_kind) :: auto_ind ! autotroph functional group index
integer (int_kind) :: auto_ind2 ! autotroph functional group index
Expand Down Expand Up @@ -1737,8 +1734,8 @@ subroutine marbl_set_interior_forcing( &
zsat_calcite(:), zsat_aragonite(:), marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from marbl_compute_carbonate_chemistry"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace(&
'marbl_check_ecosys_tracer_count_consistency()', subname)
return
end if

Expand Down Expand Up @@ -1810,8 +1807,8 @@ subroutine marbl_set_interior_forcing( &
other_remin(k), fesedflux(k), ciso_on, marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from marbl_compute_particulate_terms"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('marbl_compute_particulate_terms()', &
subname)
return
end if

Expand Down Expand Up @@ -1883,8 +1880,8 @@ subroutine marbl_set_interior_forcing( &
interior_forcing_diags, &
marbl_status_log)
if (marbl_status_log%labort_marbl) then
log_message = "error code returned from marbl_diagnostics_set_interior_forcing"
call marbl_status_log%log_error(log_message, "marbl_interface::set_interior_forcing")
call marbl_status_log%log_error_trace(&
'marbl_diagnostics_set_interior_foricng()', subname)
return
end if

Expand All @@ -1908,8 +1905,8 @@ subroutine marbl_set_interior_forcing( &
marbl_status_log = marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from marbl_ciso_set_interior_forcing"
call marbl_status_log%log_error(log_message, "marbl_interface::set_interior_forcing")
call marbl_status_log%log_error_trace(&
'marbl_ciso_set_interior_foricng()', subname)
return
end if
end if
Expand Down Expand Up @@ -2718,7 +2715,6 @@ subroutine marbl_set_surface_forcing( &
! local variables
!-----------------------------------------------------------------------
character(*), parameter :: subname = 'marbl_mod:marbl_set_surface_forcing'
character(len=char_len) :: log_message
integer (int_kind) :: n ! loop indices
integer (int_kind) :: auto_ind ! autotroph functional group index
real (r8) :: phlo(num_elements) ! lower bound for ph in solver
Expand Down Expand Up @@ -2909,8 +2905,7 @@ subroutine marbl_set_surface_forcing( &
marbl_status_log = marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from co2calc_surf"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('co2calc_surf()', subname)
return
end if

Expand Down Expand Up @@ -2969,8 +2964,7 @@ subroutine marbl_set_surface_forcing( &
marbl_status_log = marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from co2calc_surf"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('co2calc_surf()', subname)
return
end if

Expand Down Expand Up @@ -3876,7 +3870,6 @@ subroutine marbl_compute_carbonate_chemistry(domain, interior_forcing_input, &
! local variables
!-----------------------------------------------------------------------
character(*), parameter :: subname = 'marbl_mod:marbl_compute_carbonate_chemistry'
character(len=char_len) :: log_message
integer :: k
type(thermodynamic_coefficients_type), dimension(domain%km) :: co3_coeffs
logical(log_kind) , dimension(domain%km) :: mask
Expand Down Expand Up @@ -3942,8 +3935,7 @@ subroutine marbl_compute_carbonate_chemistry(domain, interior_forcing_input, &
marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from conp_CO3terms"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('marbl_comp_CO3terms()', subname)
return
end if

Expand All @@ -3969,8 +3961,7 @@ subroutine marbl_compute_carbonate_chemistry(domain, interior_forcing_input, &
hco3_alt_co2, co3_alt_co2, marbl_status_log)

if (marbl_status_log%labort_marbl) then
log_message = "error code returned from comp_CO3terms"
call marbl_status_log%log_error(log_message, subname)
call marbl_status_log%log_error_trace('marbl_comp_CO3terms()', subname)
return
end if

Expand Down

0 comments on commit e257a8c

Please sign in to comment.