From e257a8c1cf04a6db233e0dbfe8a6304eca3647e9 Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Tue, 5 Apr 2016 15:42:14 -0600 Subject: [PATCH] First pass removing 'error code returned' messages 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. --- src/marbl_ciso_mod.F90 | 4 +-- src/marbl_co2calc_mod.F90 | 12 +++------ src/marbl_interface.F90 | 28 ++++++++------------- src/marbl_interface_types.F90 | 10 +++----- src/marbl_logging.F90 | 13 ++++++++++ src/marbl_mod.F90 | 47 ++++++++++++++--------------------- 6 files changed, 49 insertions(+), 65 deletions(-) diff --git a/src/marbl_ciso_mod.F90 b/src/marbl_ciso_mod.F90 index 0bd81d1f..e8f059e9 100644 --- a/src/marbl_ciso_mod.F90 +++ b/src/marbl_ciso_mod.F90 @@ -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 @@ -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 diff --git a/src/marbl_co2calc_mod.F90 b/src/marbl_co2calc_mod.F90 index d31ec57f..b48ecd84 100644 --- a/src/marbl_co2calc_mod.F90 +++ b/src/marbl_co2calc_mod.F90 @@ -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) @@ -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 @@ -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) @@ -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 @@ -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) @@ -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 diff --git a/src/marbl_interface.F90 b/src/marbl_interface.F90 index 275bec97..b25ae7e3 100644 --- a/src/marbl_interface.F90 +++ b/src/marbl_interface.F90 @@ -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 !-------------------------------------------------------------------- @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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, & @@ -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 diff --git a/src/marbl_interface_types.F90 b/src/marbl_interface_types.F90 index f35187bf..0813ff10 100644 --- a/src/marbl_interface_types.F90 +++ b/src/marbl_interface_types.F90 @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/src/marbl_logging.F90 b/src/marbl_logging.F90 index a286900a..e4b7bbaf 100644 --- a/src/marbl_logging.F90 +++ b/src/marbl_logging.F90 @@ -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 @@ -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 diff --git a/src/marbl_mod.F90 b/src/marbl_mod.F90 index 3dac0c4b..a35a175c 100644 --- a/src/marbl_mod.F90 +++ b/src/marbl_mod.F90 @@ -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 @@ -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 @@ -1532,8 +1530,8 @@ 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 @@ -1541,16 +1539,16 @@ subroutine marbl_init_tracer_metadata(marbl_tracer_metadata, marbl_status_log) 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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