Skip to content

Commit

Permalink
Diag mediator deallocates memory at end(). #62
Browse files Browse the repository at this point in the history
  • Loading branch information
nichannah committed Jul 17, 2015
1 parent b690e3b commit d485907
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
5 changes: 3 additions & 2 deletions config_src/coupled_driver/ocean_model_MOM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module ocean_model_mod
use MOM, only : initialize_MOM, step_MOM, MOM_control_struct, MOM_end
use MOM, only : calculate_surface_state
use MOM_constants, only : CELSIUS_KELVIN_OFFSET
use MOM_diag_mediator, only : enable_averaging, disable_averaging
use MOM_diag_mediator, only : diag_ctrl, enable_averaging, disable_averaging
use MOM_diag_mediator, only : diag_mediator_close_registration, diag_mediator_end
use MOM_domains, only : pass_vector, AGRID, BGRID_NE, CGRID_NE
use MOM_error_handler, only : MOM_error, FATAL, WARNING, is_root_pe
Expand Down Expand Up @@ -494,6 +494,7 @@ subroutine ocean_model_end(Ocean_sfc, Ocean_state, Time)
type(ocean_public_type), intent(inout) :: Ocean_sfc
type(ocean_state_type), pointer :: Ocean_state
type(time_type), intent(in) :: Time

! This subroutine terminates the model run, saving the ocean state in a
! restart file and deallocating any data associated with the ocean.

Expand All @@ -504,7 +505,7 @@ subroutine ocean_model_end(Ocean_sfc, Ocean_state, Time)
! (in) Time - The model time, used for writing restarts.

call ocean_model_save_restart(Ocean_state, Time)
call diag_mediator_end(Time)
call diag_mediator_end(Time, Ocean_state%MOM_CSp%diag)
call MOM_end(Ocean_state%MOM_CSp)
if (Ocean_state%use_ice_shelf) call ice_shelf_end(Ocean_state%Ice_shelf_CSp)
end subroutine ocean_model_end
Expand Down
2 changes: 1 addition & 1 deletion config_src/ice_solo_driver/ice_shelf_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ program SHELF_main
close(unit)
endif

call diag_mediator_end(Time, end_diag_manager=.true.)
call diag_mediator_end(Time, ice_shelf_CSp%diag, end_diag_manager=.true.)
call cpu_clock_end(termClock)

call io_infra_end ; call MOM_infra_end
Expand Down
2 changes: 1 addition & 1 deletion config_src/solo_driver/MOM_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ program MOM_main
endif

call callTree_waypoint("End MOM_main")
call diag_mediator_end(Time, end_diag_manager=.true.)
call diag_mediator_end(Time, MOM_CSp%diag, end_diag_manager=.true.)
call cpu_clock_end(termClock)

call io_infra_end ; call MOM_infra_end
Expand Down
31 changes: 27 additions & 4 deletions src/framework/MOM_diag_mediator.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module MOM_diag_mediator
use MOM_string_functions, only : lowercase
use MOM_time_manager, only : time_type
use MOM_remapping, only : remapping_CS, remapping_core, initialize_remapping, dzFromH1H2
use MOM_regridding, only : regridding_CS, initialize_regridding, setCoordinateResolution, buildGridZStarColumn, setRegriddingMinimumThickness
use MOM_regridding, only : regridding_CS, initialize_regridding, setCoordinateResolution
use MOM_regridding, only : buildGridZStarColumn, setRegriddingMinimumThickness

use diag_manager_mod, only : diag_manager_init, diag_manager_end
use diag_manager_mod, only : send_data, diag_axis_init
Expand Down Expand Up @@ -1596,14 +1597,36 @@ subroutine diag_mediator_close_registration()

end subroutine diag_mediator_close_registration

subroutine diag_mediator_end(time, end_diag_manager)
type(time_type), intent(in) :: time
logical, optional, intent(in) :: end_diag_manager !< If true, call diag_manager_end()
subroutine diag_mediator_end(time, diag_cs, end_diag_manager)
type(time_type), intent(in) :: time
type(diag_ctrl), intent(inout) :: diag_cs
logical, optional, intent(in) :: end_diag_manager !< If true, call diag_manager_end()

if (doc_unit > -1) then
close(doc_unit) ; doc_unit = -3
endif

deallocate(diag_cs%diags)

if (allocated(diag_cs%zi_remap)) deallocate(diag_cs%zi_remap)
if (allocated(diag_cs%zl_remap)) deallocate(diag_cs%zl_remap)

if (allocated(diag_cs%zi_u)) deallocate(diag_cs%zi_u)
if (allocated(diag_cs%zi_v)) deallocate(diag_cs%zi_v)
if (allocated(diag_cs%zi_T)) deallocate(diag_cs%zi_T)
deallocate(diag_cs%mask3dTL)
deallocate(diag_cs%mask3dBuL)
deallocate(diag_cs%mask3dCuL)
deallocate(diag_cs%mask3dCvL)
deallocate(diag_cs%mask3dTi)
deallocate(diag_cs%mask3dBui)
deallocate(diag_cs%mask3dCui)
deallocate(diag_cs%mask3dCvi)

#if defined(DEBUG) || defined(__DO_SAFETY_CHECKS__)
deallocate(diag_cs%h_old)
#endif

if (present(end_diag_manager)) then
if (end_diag_manager) call diag_manager_end(time)
endif
Expand Down

0 comments on commit d485907

Please sign in to comment.