subroutine dyn_readnl(namelist_path)
! Module(s) from CAM-SIMA.
use cam_abortutils, only: endrun
use cam_control_mod, only: initial_run
use cam_instance, only: atm_id
use cam_logfile, only: debug_output, debugout_debug, debugout_info, iulog
use spmd_utils, only: mpicom
use string_utils, only: stringify
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
character(*), intent(in) :: namelist_path
character(*), parameter :: subname = 'dyn_comp::dyn_readnl'
character(len_cs) :: cam_calendar
integer :: log_unit(2)
integer :: start_date_time(6), & ! YYYY, MM, DD, hh, mm, ss.
stop_date_time(6), & ! YYYY, MM, DD, hh, mm, ss.
run_duration(4), & ! DD, hh, mm, ss.
sec_since_midnight ! Second(s) since midnight.
type(iosystem_desc_t), pointer :: pio_iosystem
call dyn_debug_print(debugout_debug, subname // ' entered')
nullify(pio_iosystem)
! Get free units for MPAS so it can write its own log files, e.g., "log.atmosphere.0000.{out,err}".
log_unit(1) = shr_file_getunit()
log_unit(2) = shr_file_getunit()
call dyn_debug_print(debugout_info, 'Initializing MPAS dynamical core (Phase 1/4)')
! Initialize MPAS framework with the supplied MPI communicator group, procedure pointer to terminate the model,
! log level, and units.
call mpas_dynamical_core % init_phase1(mpicom, endrun, debug_output, iulog, log_unit)
cam_calendar = timemgr_get_calendar_cf()
call get_start_date(start_date_time(1), start_date_time(2), start_date_time(3), sec_since_midnight)
start_date_time(4:6) = sec_to_hour_min_sec(sec_since_midnight)
call get_stop_date(stop_date_time(1), stop_date_time(2), stop_date_time(3), sec_since_midnight)
stop_date_time(4:6) = sec_to_hour_min_sec(sec_since_midnight)
call get_run_duration(run_duration(1), sec_since_midnight)
run_duration(2:4) = sec_to_hour_min_sec(sec_since_midnight)
call dyn_debug_print(debugout_info, 'Reading namelist')
! Read MPAS-related namelist variables from `namelist_path`, e.g., "atm_in".
call mpas_dynamical_core % read_namelist(namelist_path, &
cam_calendar, start_date_time, stop_date_time, run_duration, initial_run)
pio_iosystem => shr_pio_getiosys(atm_id)
call dyn_debug_print(debugout_info, 'Initializing MPAS dynamical core (Phase 2/4)')
! Initialize MPAS framework with the supplied PIO system descriptor.
call mpas_dynamical_core % init_phase2(pio_iosystem)
nullify(pio_iosystem)
call dyn_debug_print(debugout_debug, subname // ' completed')
contains
!> Convert second(s) to hour(s), minute(s), and second(s).
!> (KCW, 2024-02-07)
pure function sec_to_hour_min_sec(sec) result(hour_min_sec)
integer, intent(in) :: sec
integer :: hour_min_sec(3)
! These are all intended to be integer arithmetics.
hour_min_sec(1) = sec / 3600
hour_min_sec(2) = sec / 60 - hour_min_sec(1) * 60
hour_min_sec(3) = sec - hour_min_sec(1) * 3600 - hour_min_sec(2) * 60
end function sec_to_hour_min_sec
end subroutine dyn_readnl