Skip to content

Commit b2f6678

Browse files
Merge pull request #5 from marshallward/no_more_pointers
Redefine ~500 pointers as local or stack variables
2 parents 7b96ac1 + 8a73a35 commit b2f6678

86 files changed

Lines changed: 1425 additions & 2188 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ALE/coord_hycom.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ end subroutine set_hycom_params
9898
subroutine build_hycom1_column(CS, eqn_of_state, nz, depth, h, T, S, p_col, &
9999
z_col, z_col_new, zScale, h_neglect, h_neglect_edge)
100100
type(hycom_CS), intent(in) :: CS !< Coordinate control structure
101-
type(EOS_type), pointer :: eqn_of_state !< Equation of state structure
101+
type(EOS_type), intent(in) :: eqn_of_state !< Equation of state structure
102102
integer, intent(in) :: nz !< Number of levels
103103
real, intent(in) :: depth !< Depth of ocean bottom (positive [H ~> m or kg m-2])
104104
real, dimension(nz), intent(in) :: T !< Temperature of column [degC]

src/ALE/coord_rho.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ subroutine build_rho_column(CS, nz, depth, h, T, S, eqn_of_state, z_interface, &
9595
real, dimension(nz), intent(in) :: h !< Layer thicknesses [H ~> m or kg m-2]
9696
real, dimension(nz), intent(in) :: T !< Temperature for source column [degC]
9797
real, dimension(nz), intent(in) :: S !< Salinity for source column [ppt]
98-
type(EOS_type), pointer :: eqn_of_state !< Equation of state structure
98+
type(EOS_type), intent(in) :: eqn_of_state !< Equation of state structure
9999
real, dimension(CS%nk+1), &
100100
intent(inout) :: z_interface !< Absolute positions of interfaces
101101
real, optional, intent(in) :: z_rigid_top !< The height of a rigid top (positive upward in the same
@@ -208,7 +208,7 @@ subroutine build_rho_column_iteratively(CS, remapCS, nz, depth, h, T, S, eqn_of_
208208
real, dimension(nz), intent(in) :: h !< Layer thicknesses in Z coordinates [Z ~> m]
209209
real, dimension(nz), intent(in) :: T !< T for column [degC]
210210
real, dimension(nz), intent(in) :: S !< S for column [ppt]
211-
type(EOS_type), pointer :: eqn_of_state !< Equation of state structure
211+
type(EOS_type), intent(in) :: eqn_of_state !< Equation of state structure
212212
real, dimension(nz+1), intent(inout) :: zInterface !< Absolute positions of interfaces
213213
real, optional, intent(in) :: h_neglect !< A negligibly small width for the
214214
!! purpose of cell reconstructions

src/ALE/coord_slight.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ subroutine build_slight_column(CS, eqn_of_state, H_to_pres, H_subroundoff, &
181181
nz, depth, h_col, T_col, S_col, p_col, z_col, z_col_new, &
182182
h_neglect, h_neglect_edge)
183183
type(slight_CS), intent(in) :: CS !< Coordinate control structure
184-
type(EOS_type), pointer :: eqn_of_state !< Equation of state structure
184+
type(EOS_type), intent(in) :: eqn_of_state !< Equation of state structure
185185
real, intent(in) :: H_to_pres !< A conversion factor from thicknesses to
186186
!! scaled pressure [R L2 T-2 H-1 ~> Pa m-1 or Pa m2 kg-1]
187187
real, intent(in) :: H_subroundoff !< GV%H_subroundoff

src/core/MOM.F90

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ module MOM
227227
type(diag_ctrl) :: diag !< structure to regulate diagnostic output timing
228228
type(vertvisc_type) :: visc !< structure containing vertical viscosities,
229229
!! bottom drag viscosities, and related fields
230-
type(MEKE_type), pointer :: MEKE => NULL() !< structure containing fields
231-
!! related to the Mesoscale Eddy Kinetic Energy
230+
type(MEKE_type) :: MEKE !< Fields related to the Mesoscale Eddy Kinetic Energy
232231
logical :: adiabatic !< If true, there are no diapycnal mass fluxes, and no calls
233232
!! to routines to calculate or apply diapycnal fluxes.
234233
logical :: diabatic_first !< If true, apply diabatic and thermodynamic processes before time
@@ -347,21 +346,19 @@ module MOM
347346
!< Pointer to the control structure used for the unsplit RK2 dynamics
348347
type(MOM_dyn_split_RK2_CS), pointer :: dyn_split_RK2_CSp => NULL()
349348
!< Pointer to the control structure used for the mode-split RK2 dynamics
350-
type(thickness_diffuse_CS), pointer :: thickness_diffuse_CSp => NULL()
349+
type(thickness_diffuse_CS) :: thickness_diffuse_CSp
351350
!< Pointer to the control structure used for the isopycnal height diffusive transport.
352351
!! This is also common referred to as Gent-McWilliams diffusion
353-
type(mixedlayer_restrat_CS), pointer :: mixedlayer_restrat_CSp => NULL()
352+
type(mixedlayer_restrat_CS) :: mixedlayer_restrat_CSp
354353
!< Pointer to the control structure used for the mixed layer restratification
355-
type(set_visc_CS), pointer :: set_visc_CSp => NULL()
354+
type(set_visc_CS) :: set_visc_CSp
356355
!< Pointer to the control structure used to set viscosities
357356
type(diabatic_CS), pointer :: diabatic_CSp => NULL()
358357
!< Pointer to the control structure for the diabatic driver
359-
type(MEKE_CS), pointer :: MEKE_CSp => NULL()
358+
type(MEKE_CS) :: MEKE_CSp
360359
!< Pointer to the control structure for the MEKE updates
361-
type(VarMix_CS), pointer :: VarMix => NULL()
362-
!< Pointer to the control structure for the variable mixing module
363-
type(Barotropic_CS), pointer :: Barotropic_CSp => NULL()
364-
!< Pointer to the control structure for the barotropic module
360+
type(VarMix_CS) :: VarMix
361+
!< Control structure for the variable mixing module
365362
type(tracer_registry_type), pointer :: tracer_Reg => NULL()
366363
!< Pointer to the MOM tracer registry
367364
type(tracer_advect_CS), pointer :: tracer_adv_CSp => NULL()
@@ -388,7 +385,7 @@ module MOM
388385
! Pointers to control structures used for diagnostics
389386
type(sum_output_CS), pointer :: sum_output_CSp => NULL()
390387
!< Pointer to the globally summed output control structure
391-
type(diagnostics_CS), pointer :: diagnostics_CSp => NULL()
388+
type(diagnostics_CS) :: diagnostics_CSp
392389
!< Pointer to the MOM diagnostics control structure
393390
type(offline_transport_CS), pointer :: offline_CSp => NULL()
394391
!< Pointer to the offline tracer transport control structure
@@ -637,7 +634,7 @@ subroutine step_MOM(forces_in, fluxes_in, sfc_state, Time_start, time_int_in, CS
637634
CS%time_in_cycle = 0.0
638635
do j=js,je ; do i=is,ie ; CS%ssh_rint(i,j) = 0.0 ; enddo ; enddo
639636

640-
if (associated(CS%VarMix)) then
637+
if (CS%VarMix%use_variable_mixing) then
641638
call enable_averages(cycle_time, Time_start + real_to_time(US%T_to_s*cycle_time), CS%diag)
642639
call calc_resoln_function(h, CS%tv, G, GV, US, CS%VarMix)
643640
call calc_depth_function(G, CS%VarMix)
@@ -1033,7 +1030,7 @@ subroutine step_MOM_dynamics(forces, p_surf_begin, p_surf_end, dt, dt_thermo, &
10331030

10341031
call enable_averages(dt_thermo, Time_local+real_to_time(US%T_to_s*(dt_thermo-dt)), CS%diag)
10351032
call cpu_clock_begin(id_clock_thick_diff)
1036-
if (associated(CS%VarMix)) &
1033+
if (CS%VarMix%use_variable_mixing) &
10371034
call calc_slope_functions(h, CS%tv, dt, G, GV, US, CS%VarMix, OBC=CS%OBC)
10381035
call thickness_diffuse(h, CS%uhtr, CS%vhtr, CS%tv, dt_thermo, G, GV, US, &
10391036
CS%MEKE, CS%VarMix, CS%CDp, CS%thickness_diffuse_CSp)
@@ -1112,7 +1109,7 @@ subroutine step_MOM_dynamics(forces, p_surf_begin, p_surf_end, dt, dt_thermo, &
11121109

11131110
if (CS%debug) call hchksum(h,"Pre-thickness_diffuse h", G%HI, haloshift=0, scale=GV%H_to_m)
11141111

1115-
if (associated(CS%VarMix)) &
1112+
if (CS%VarMix%use_variable_mixing) &
11161113
call calc_slope_functions(h, CS%tv, dt, G, GV, US, CS%VarMix, OBC=CS%OBC)
11171114
call thickness_diffuse(h, CS%uhtr, CS%vhtr, CS%tv, dt, G, GV, US, &
11181115
CS%MEKE, CS%VarMix, CS%CDp, CS%thickness_diffuse_CSp)
@@ -1563,7 +1560,7 @@ subroutine step_offline(forces, fluxes, sfc_state, Time_start, time_interval, CS
15631560

15641561
! Perform offline diffusion if requested
15651562
if (.not. skip_diffusion) then
1566-
if (associated(CS%VarMix)) then
1563+
if (CS%VarMix%use_variable_mixing) then
15671564
call pass_var(CS%h, G%Domain)
15681565
call calc_resoln_function(CS%h, CS%tv, G, GV, US, CS%VarMix)
15691566
call calc_depth_function(G, CS%VarMix)
@@ -1589,7 +1586,7 @@ subroutine step_offline(forces, fluxes, sfc_state, Time_start, time_interval, CS
15891586
call offline_redistribute_residual(CS%offline_CSp, CS%h, uhtr, vhtr, adv_converged)
15901587
! Perform offline diffusion if requested
15911588
if (.not. skip_diffusion) then
1592-
if (associated(CS%VarMix)) then
1589+
if (CS%VarMix%use_variable_mixing) then
15931590
call pass_var(CS%h, G%Domain)
15941591
call calc_resoln_function(CS%h, CS%tv, G, GV, US, CS%VarMix)
15951592
call calc_depth_function(G, CS%VarMix)
@@ -2333,7 +2330,10 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
23332330
! Use the Wright equation of state by default, unless otherwise specified
23342331
! Note: this line and the following block ought to be in a separate
23352332
! initialization routine for tv.
2336-
if (use_EOS) call EOS_init(param_file, CS%tv%eqn_of_state, US)
2333+
if (use_EOS) then
2334+
allocate(CS%tv%eqn_of_state)
2335+
call EOS_init(param_file, CS%tv%eqn_of_state, US)
2336+
endif
23372337
if (use_temperature) then
23382338
allocate(CS%tv%TempxPmE(isd:ied,jsd:jed), source=0.0)
23392339
if (use_geothermal) then
@@ -2351,10 +2351,10 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
23512351
CS%dyn_split_RK2_CSp, restart_CSp, CS%uh, CS%vh)
23522352
elseif (CS%use_RK2) then
23532353
call register_restarts_dyn_unsplit_RK2(HI, GV, param_file, &
2354-
CS%dyn_unsplit_RK2_CSp, restart_CSp)
2354+
CS%dyn_unsplit_RK2_CSp)
23552355
else
23562356
call register_restarts_dyn_unsplit(HI, GV, param_file, &
2357-
CS%dyn_unsplit_CSp, restart_CSp)
2357+
CS%dyn_unsplit_CSp)
23582358
endif
23592359

23602360
! This subroutine calls user-specified tracer registration routines.
@@ -2662,14 +2662,14 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
26622662
endif
26632663
elseif (CS%use_RK2) then
26642664
call initialize_dyn_unsplit_RK2(CS%u, CS%v, CS%h, Time, G, GV, US, &
2665-
param_file, diag, CS%dyn_unsplit_RK2_CSp, restart_CSp, &
2666-
CS%ADp, CS%CDp, MOM_internal_state, CS%MEKE, CS%OBC, &
2665+
param_file, diag, CS%dyn_unsplit_RK2_CSp, &
2666+
CS%ADp, CS%CDp, MOM_internal_state, CS%OBC, &
26672667
CS%update_OBC_CSp, CS%ALE_CSp, CS%set_visc_CSp, CS%visc, dirs, &
26682668
CS%ntrunc, cont_stencil=CS%cont_stencil)
26692669
else
26702670
call initialize_dyn_unsplit(CS%u, CS%v, CS%h, Time, G, GV, US, &
2671-
param_file, diag, CS%dyn_unsplit_CSp, restart_CSp, &
2672-
CS%ADp, CS%CDp, MOM_internal_state, CS%MEKE, CS%OBC, &
2671+
param_file, diag, CS%dyn_unsplit_CSp, &
2672+
CS%ADp, CS%CDp, MOM_internal_state, CS%OBC, &
26732673
CS%update_OBC_CSp, CS%ALE_CSp, CS%set_visc_CSp, CS%visc, dirs, &
26742674
CS%ntrunc, cont_stencil=CS%cont_stencil)
26752675
endif
@@ -3595,7 +3595,6 @@ subroutine MOM_end(CS)
35953595
endif
35963596

35973597
call MOM_diagnostics_end(CS%diagnostics_CSp, CS%ADp, CS%CDp)
3598-
deallocate(CS%diagnostics_CSp)
35993598

36003599
if (CS%offline_tracer_mode) call offline_transport_end(CS%offline_CSp)
36013600

@@ -3613,25 +3612,9 @@ subroutine MOM_end(CS)
36133612
endif
36143613

36153614
call thickness_diffuse_end(CS%thickness_diffuse_CSp, CS%CDp)
3616-
deallocate(CS%thickness_diffuse_CSp)
3617-
3618-
if (associated(CS%VarMix)) then
3619-
call VarMix_end(CS%VarMix)
3620-
deallocate(CS%VarMix)
3621-
endif
3622-
3623-
if (associated(CS%mixedlayer_restrat_CSp)) &
3624-
deallocate(CS%mixedlayer_restrat_CSp)
3625-
3626-
if (associated(CS%set_visc_CSp)) &
3627-
call set_visc_end(CS%visc, CS%set_visc_CSp)
3628-
3629-
if (associated(CS%MEKE_CSp)) deallocate(CS%MEKE_CSp)
3630-
3631-
if (associated(CS%MEKE)) then
3632-
call MEKE_end(CS%MEKE)
3633-
deallocate(CS%MEKE)
3634-
endif
3615+
call VarMix_end(CS%VarMix)
3616+
call set_visc_end(CS%visc, CS%set_visc_CSp)
3617+
call MEKE_end(CS%MEKE)
36353618

36363619
if (associated(CS%tv%internal_heat)) deallocate(CS%tv%internal_heat)
36373620
if (associated(CS%tv%TempxPmE)) deallocate(CS%tv%TempxPmE)

src/core/MOM_CoriolisAdv.F90

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ subroutine CorAdCalc(u, v, h, uh, vh, CAu, CAv, OBC, AD, G, GV, US, CS)
134134
type(ocean_OBC_type), pointer :: OBC !< Open boundary control structure
135135
type(accel_diag_ptrs), intent(inout) :: AD !< Storage for acceleration diagnostics
136136
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
137-
type(CoriolisAdv_CS), pointer :: CS !< Control structure for MOM_CoriolisAdv
137+
type(CoriolisAdv_CS), intent(in) :: CS !< Control structure for MOM_CoriolisAdv
138138

139139
! Local variables
140140
real, dimension(SZIB_(G),SZJB_(G)) :: &
@@ -245,8 +245,6 @@ subroutine CorAdCalc(u, v, h, uh, vh, CAu, CAv, OBC, AD, G, GV, US, CS)
245245
! v(is-1:ie+2,js-1:je+1), u(is-1:ie+1,js-1:je+2), h(is-1:ie+2,js-1:je+2),
246246
! uh(is-1,ie,js:je+1) and vh(is:ie+1,js-1:je).
247247

248-
if (.not.associated(CS)) call MOM_error(FATAL, &
249-
"MOM_CoriolisAdv: Module must be initialized before it is used.")
250248
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec
251249
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB ; nz = GV%ke
252250
vol_neglect = GV%H_subroundoff * (1e-4 * US%m_to_L)**2
@@ -1034,7 +1032,7 @@ subroutine gradKE(u, v, h, KE, KEx, KEy, k, OBC, G, GV, US, CS)
10341032
integer, intent(in) :: k !< Layer number to calculate for
10351033
type(ocean_OBC_type), pointer :: OBC !< Open boundary control structure
10361034
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
1037-
type(CoriolisAdv_CS), pointer :: CS !< Control structure for MOM_CoriolisAdv
1035+
type(CoriolisAdv_CS), intent(in) :: CS !< Control structure for MOM_CoriolisAdv
10381036
! Local variables
10391037
real :: um, up, vm, vp ! Temporary variables [L T-1 ~> m s-1].
10401038
real :: um2, up2, vm2, vp2 ! Temporary variables [L2 T-2 ~> m2 s-2].
@@ -1113,7 +1111,7 @@ subroutine CoriolisAdv_init(Time, G, GV, US, param_file, diag, AD, CS)
11131111
type(param_file_type), intent(in) :: param_file !< Runtime parameter handles
11141112
type(diag_ctrl), target, intent(inout) :: diag !< Diagnostics control structure
11151113
type(accel_diag_ptrs), target, intent(inout) :: AD !< Strorage for acceleration diagnostics
1116-
type(CoriolisAdv_CS), pointer :: CS !< Control structure fro MOM_CoriolisAdv
1114+
type(CoriolisAdv_CS), intent(inout) :: CS !< Control structure fro MOM_CoriolisAdv
11171115
! Local variables
11181116
! This include declares and sets the variable "version".
11191117
#include "version_variable.h"
@@ -1125,12 +1123,6 @@ subroutine CoriolisAdv_init(Time, G, GV, US, param_file, diag, AD, CS)
11251123
isd = G%isd ; ied = G%ied ; jsd = G%jsd ; jed = G%jed ; nz = GV%ke
11261124
IsdB = G%IsdB ; IedB = G%IedB ; JsdB = G%JsdB ; JedB = G%JedB
11271125

1128-
if (associated(CS)) then
1129-
call MOM_error(WARNING, "CoriolisAdv_init called with associated control structure.")
1130-
return
1131-
endif
1132-
allocate(CS)
1133-
11341126
CS%diag => diag ; CS%Time => Time
11351127

11361128
! Read all relevant parameters and write them to the model log.

0 commit comments

Comments
 (0)