Skip to content

Commit

Permalink
Move use statements to the smallest scope possible
Browse files Browse the repository at this point in the history
... Also for kind and length parameters.
  • Loading branch information
kuanchihwang committed Jan 2, 2025
1 parent a9c253f commit 155ef57
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/dynamics/mpas/driver/dyn_mpas_subdriver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module dyn_mpas_subdriver
#endif
! Module(s) from MPAS.
use mpas_derived_types, only: core_type, domain_type
use mpas_kind_types, only: rkind, r4kind, r8kind, strkind
use mpas_kind_types, only: rkind, strkind

implicit none

Expand Down Expand Up @@ -1897,6 +1897,7 @@ subroutine dyn_mpas_check_variable_status(self, var_is_present, var_is_tkr_compa
use mpas_derived_types, only: field0dchar, field1dchar, &
field0dinteger, field1dinteger, field2dinteger, field3dinteger, &
field0dreal, field1dreal, field2dreal, field3dreal, field4dreal, field5dreal
use mpas_kind_types, only: r4kind, r8kind
use mpas_pool_routines, only: mpas_pool_get_field

class(mpas_dynamical_core_type), intent(in) :: self
Expand Down
14 changes: 11 additions & 3 deletions src/dynamics/mpas/dyn_comp.F90
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module dyn_comp
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8, &
len_cs => shr_kind_cs
! Module(s) from MPAS.
use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind, mpas_dynamical_core_type

Expand Down Expand Up @@ -99,6 +96,7 @@ subroutine dyn_readnl(namelist_path)
use time_manager, only: get_start_date, get_stop_date, get_run_duration, timemgr_get_calendar_cf
! Module(s) from CESM Share.
use shr_file_mod, only: shr_file_getunit
use shr_kind_mod, only: len_cs => shr_kind_cs
use shr_pio_mod, only: shr_pio_getiosys
! Module(s) from external libraries.
use pio, only: iosystem_desc_t
Expand Down Expand Up @@ -312,6 +310,8 @@ subroutine check_topography_data(pio_file)
use cam_field_read, only: cam_read_field
use cam_logfile, only: debug_output, debugout_none
use dynconst, only: constant_g => gravit
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8
! Module(s) from external libraries.
use pio, only: file_desc_t, pio_file_is_open

Expand Down Expand Up @@ -376,6 +376,9 @@ end subroutine check_topography_data
!> Set analytic initial condition for MPAS.
!> (KCW, 2024-05-22)
subroutine set_analytic_initial_condition()
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8

character(*), parameter :: subname = 'dyn_comp::set_analytic_initial_condition'
integer, allocatable :: global_grid_index(:)
real(kind_r8), allocatable :: buffer_2d_real(:, :), buffer_3d_real(:, :, :)
Expand Down Expand Up @@ -845,6 +848,8 @@ subroutine dyn_exchange_constituent_states(direction, exchange, conversion)
! Module(s) from CCPP.
use cam_ccpp_cap, only: cam_constituents_array
use ccpp_kinds, only: kind_phys
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8

character(*), intent(in) :: direction
logical, intent(in) :: exchange
Expand Down Expand Up @@ -1156,6 +1161,9 @@ end subroutine dyn_variable_dump
!> Helper function for reversing the order of elements in `array`.
!> (KCW, 2024-07-17)
pure function reverse(array)
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8

real(kind_r8), intent(in) :: array(:)
real(kind_r8) :: reverse(size(array))

Expand Down
16 changes: 10 additions & 6 deletions src/dynamics/mpas/dyn_coupling.F90
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
module dyn_coupling
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8, &
len_cx => shr_kind_cx
! Module(s) from MPAS.
use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind

implicit none

private
Expand All @@ -18,6 +12,10 @@ module dyn_coupling
subroutine dynamics_to_physics_coupling()
! Module(s) from CAM-SIMA.
use dyn_comp, only: dyn_debug_print, dyn_exchange_constituent_states, ncells_solve
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8
! Module(s) from MPAS.
use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind

character(*), parameter :: subname = 'dyn_coupling::dynamics_to_physics_coupling'
integer :: column_index
Expand Down Expand Up @@ -308,6 +306,8 @@ subroutine set_physics_state_external()
use geopotential_temp, only: geopotential_temp_run
use qneg, only: qneg_run
use static_energy, only: update_dry_static_energy_run
! Module(s) from CESM Share.
use shr_kind_mod, only: len_cx => shr_kind_cx

character(*), parameter :: subname = 'dyn_coupling::dynamics_to_physics_coupling::set_physics_state_external'
character(len_cx) :: cerr
Expand Down Expand Up @@ -411,6 +411,10 @@ end subroutine dynamics_to_physics_coupling
subroutine physics_to_dynamics_coupling()
! Module(s) from CAM-SIMA.
use dyn_comp, only: dyn_exchange_constituent_states
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8
! Module(s) from MPAS.
use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind

character(*), parameter :: subname = 'dyn_coupling::physics_to_dynamics_coupling'
integer, pointer :: index_qv
Expand Down
21 changes: 14 additions & 7 deletions src/dynamics/mpas/dyn_grid.F90
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
module dyn_grid
! Module(s) from CAM-SIMA.
use cam_grid_support, only: max_hcoordname_len
use cam_map_utils, only: kind_imap => imap
use physics_column_type, only: kind_pcol
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8
! Module(s) from MPAS.
use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind

implicit none

Expand Down Expand Up @@ -115,6 +109,10 @@ subroutine init_reference_pressure()
use std_atm_profile, only: std_atm_pres
use string_utils, only: stringify
use vert_coord, only: pver, pverp
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8
! Module(s) from MPAS.
use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind

character(*), parameter :: subname = 'dyn_grid::init_reference_pressure'
! Number of pure pressure levels at model top.
Expand Down Expand Up @@ -221,10 +219,14 @@ subroutine init_physics_grid()
use cam_abortutils, only: check_allocate
use dyn_comp, only: mpas_dynamical_core, ncells_global, ncells_solve, sphere_radius
use dynconst, only: constant_pi => pi, rad_to_deg
use physics_column_type, only: physics_column_t
use physics_column_type, only: kind_pcol, physics_column_t
use physics_grid, only: phys_grid_init
use spmd_utils, only: iam
use string_utils, only: stringify
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8
! Module(s) from MPAS.
use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind

character(*), parameter :: subname = 'dyn_grid::init_physics_grid'
character(max_hcoordname_len), allocatable :: dyn_attribute_name(:)
Expand Down Expand Up @@ -311,12 +313,17 @@ subroutine define_cam_grid()
use cam_abortutils, only: check_allocate
use cam_grid_support, only: cam_grid_attribute_register, cam_grid_register, &
horiz_coord_create, horiz_coord_t
use cam_map_utils, only: kind_imap => imap
use dyn_comp, only: dyn_debug_print, mpas_dynamical_core, &
ncells_global, nedges_global, nvertices_global, &
ncells_solve, nedges_solve, nvertices_solve, &
sphere_radius
use dynconst, only: constant_pi => pi, rad_to_deg
use string_utils, only: stringify
! Module(s) from CESM Share.
use shr_kind_mod, only: kind_r8 => shr_kind_r8
! Module(s) from MPAS.
use dyn_mpas_subdriver, only: kind_dyn_mpas => mpas_dynamical_core_real_kind

character(*), parameter :: subname = 'dyn_grid::define_cam_grid'
integer :: i
Expand Down
7 changes: 4 additions & 3 deletions src/dynamics/mpas/stepon.F90
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module stepon
! Module(s) from CCPP.
use ccpp_kinds, only: kind_phys

implicit none

private
Expand Down Expand Up @@ -31,6 +28,8 @@ subroutine stepon_timestep_init(dtime_phys, cam_runtime_opts, phys_state, phys_t
use physics_types, only: physics_state, physics_tend
use runtime_obj, only: runtime_options
use time_manager, only: get_step_size
! Module(s) from CCPP.
use ccpp_kinds, only: kind_phys

real(kind_phys), intent(out) :: dtime_phys
type(runtime_options), intent(in) :: cam_runtime_opts
Expand Down Expand Up @@ -69,6 +68,8 @@ subroutine stepon_run3(dtime_phys, cam_runtime_opts, cam_out, phys_state, dyn_in
use dyn_comp, only: dyn_export_t, dyn_import_t, dyn_run
use physics_types, only: physics_state
use runtime_obj, only: runtime_options
! Module(s) from CCPP.
use ccpp_kinds, only: kind_phys

real(kind_phys), intent(in) :: dtime_phys
type(runtime_options), intent(in) :: cam_runtime_opts
Expand Down

0 comments on commit 155ef57

Please sign in to comment.