diff --git a/stochastic_physics.F90 b/stochastic_physics.F90 index b413a4a..b177762 100644 --- a/stochastic_physics.F90 +++ b/stochastic_physics.F90 @@ -10,6 +10,7 @@ module stochastic_physics public :: init_stochastic_physics public :: run_stochastic_physics +public :: finalize_stochastic_physics contains @@ -345,4 +346,76 @@ subroutine run_stochastic_physics(levs, kdt, phour, blksz, xlat, xlon, sppt_wts, end subroutine run_stochastic_physics +subroutine finalize_stochastic_physics() +use stochy_data_mod, only : nshum,rpattern_shum,rpattern_sppt,nsppt,rpattern_skeb,nskeb,& + vfact_sppt,vfact_shum,vfact_skeb, skeb_vwts,skeb_vpts, & + rpattern_sfc, nlndp,gg_lats,gg_lons,sl,skebu_save,skebv_save,gis_stochy +use stochy_gg_def, only : wgt_a,sinlat_a,coslat_a,colrad_a,wgtcs_a,rcs2_a,lats_nodes_h,global_lats_h +use spectral_layout_mod, only : lat1s_a ,lon_dims_a +use stochy_layout_lag, only : lat1s_h +implicit none + + if (allocated(gg_lats)) deallocate (gg_lats) + if (allocated(gg_lons)) deallocate (gg_lons) + if (allocated(sl)) deallocate (sl) + if (nsppt > 0) then + if (allocated(rpattern_sppt)) deallocate(rpattern_sppt) + if (allocated(vfact_sppt)) deallocate(vfact_sppt) + endif + if (nshum > 0) then + if (allocated(rpattern_shum)) deallocate(rpattern_shum) + if (allocated(vfact_shum)) deallocate(vfact_shum) + endif + if (nskeb > 0) then + if (allocated(rpattern_skeb)) deallocate(rpattern_skeb) + if (allocated(skeb_vwts)) deallocate (skeb_vwts) + if (allocated(skeb_vpts)) deallocate (skeb_vpts) + if (allocated(skebu_save)) deallocate (skebu_save) + if (allocated(skebv_save)) deallocate (skebv_save) + if (allocated(vfact_skeb)) deallocate(vfact_skeb) + endif + if (nlndp > 0) then + if (allocated(rpattern_sfc)) deallocate(rpattern_sfc) + endif + +deallocate(lat1s_a) +deallocate(lon_dims_a) +deallocate(wgt_a) +deallocate(wgtcs_a) +deallocate(rcs2_a) +deallocate(colrad_a) +deallocate(sinlat_a) +deallocate(coslat_a) +deallocate(lat1s_h) +deallocate(gis_stochy%lonsperlat) +deallocate(gis_stochy%ls_node) +deallocate(gis_stochy%ls_nodes) +deallocate(gis_stochy%max_ls_nodes) +deallocate(gis_stochy%lats_nodes_a_fix) +deallocate(gis_stochy%lats_nodes_a) +deallocate(gis_stochy%global_lats_a) +deallocate(gis_stochy%lats_nodes_ext) +deallocate(gis_stochy%TRIE_LS_SIZE) +deallocate(gis_stochy%TRIO_LS_SIZE) +deallocate(gis_stochy%TRIEO_LS_SIZE) +deallocate(gis_stochy%LS_MAX_NODE_GLOBAL) +deallocate(gis_stochy%LS_NODE_GLOBAL) +deallocate(gis_stochy%epse) +deallocate(gis_stochy%epso) +deallocate(gis_stochy%epsedn) +deallocate(gis_stochy%epsodn) +deallocate(gis_stochy%kenorm_e) +deallocate(gis_stochy%kenorm_o) +deallocate(gis_stochy%snnp1ev) +deallocate(gis_stochy%snnp1od) +deallocate(gis_stochy%plnev_a) +deallocate(gis_stochy%plnod_a) +deallocate(gis_stochy%pddev_a) +deallocate(gis_stochy%pddod_a) +deallocate(gis_stochy%plnew_a) +deallocate(gis_stochy%plnow_a) + +end subroutine finalize_stochastic_physics + + end module stochastic_physics diff --git a/stochy_data_mod.F90 b/stochy_data_mod.F90 index d835ba4..6cbb864 100644 --- a/stochy_data_mod.F90 +++ b/stochy_data_mod.F90 @@ -337,6 +337,7 @@ subroutine init_stochdata(nlevs,delt,input_nml_file,fn_nml,nlunit,iret) if (is_master() .and. stochini) CLOSE(stochlun) deallocate(noise_e,noise_o) end subroutine init_stochdata + !>@brief This subroutine 'read_pattern' will read in the spectral coeffients from a previous run (stored in stoch_ini, !!turned on by setting STOCHINI=.true.) !>@details Data read in are flat binary, so the number of stochastic physics patterns running must match previous run