subroutine dyn_variable_dump()
! Module(s) from CAM-SIMA.
use cam_abortutils, only: check_allocate, endrun
use cam_instance, only: atm_id
use physics_types, only: phys_state
! Module(s) from CESM Share.
use shr_pio_mod, only: shr_pio_getioformat, shr_pio_getiosys, shr_pio_getiotype
! Module(s) from external libraries.
use pio, only: file_desc_t, iosystem_desc_t, pio_createfile, pio_closefile, pio_clobber, pio_noerr
character(*), parameter :: subname = 'dyn_comp::dyn_variable_dump'
integer :: ierr
integer :: pio_ioformat, pio_iotype
real(kind_dyn_mpas), pointer :: surface_pressure(:)
type(file_desc_t), pointer :: pio_file
type(iosystem_desc_t), pointer :: pio_iosystem
nullify(pio_file)
nullify(pio_iosystem)
nullify(surface_pressure)
call mpas_dynamical_core % get_variable_pointer(surface_pressure, 'diag', 'surface_pressure')
surface_pressure(1:ncells_solve) = real(phys_state % ps(:), kind_dyn_mpas)
nullify(surface_pressure)
call mpas_dynamical_core % exchange_halo('surface_pressure')
allocate(pio_file, stat=ierr)
call check_allocate(ierr, subname, 'pio_file', 'dyn_comp', __LINE__)
pio_iosystem => shr_pio_getiosys(atm_id)
pio_ioformat = shr_pio_getioformat(atm_id)
pio_ioformat = ior(pio_ioformat, pio_clobber)
pio_iotype = shr_pio_getiotype(atm_id)
ierr = pio_createfile(pio_iosystem, pio_file, pio_iotype, 'dyn_variable_dump.nc', pio_ioformat)
if (ierr /= pio_noerr) then
call endrun('Failed to create file for variable dumping', subname, __LINE__)
end if
call mpas_dynamical_core % read_write_stream(pio_file, 'w', 'invariant+input+restart+output')
call pio_closefile(pio_file)
deallocate(pio_file)
nullify(pio_file)
nullify(pio_iosystem)
end subroutine dyn_variable_dump