subroutine run_component_driver(filename, rc)
character(len=*), intent(in) :: filename
integer, intent(out) :: rc
integer :: status, root_id, user_RC, RUN_DT
integer :: NX, NY, phase
character(len=ESMF_MAXSTR) :: comp_name, shared_obj, restart_file
type(ESMF_Clock) :: clock
type(ESMF_TimeInterval) :: time_interval
type(ESMF_GridComp) :: temp_GC, GC
type(ESMF_State) :: import, export
type(ESMF_Config) :: config
type(ESMF_Time), allocatable :: start_time(:)
type(ESMF_Grid) :: grid
type(MAPL_MetaComp), pointer :: mapl_obj
real(kind=ESMF_KIND_R8), pointer :: lons_field_ptr(:,:), lats_field_ptr(:,:)
type(NetCDF4_fileFormatter) :: formatter
type(FileMetadata) :: basic_metadata
type(FileMetadataUtils) :: metadata
logical :: subset
! get attributes from config file
config = ESMF_ConfigCreate(_RC)
call ESMF_ConfigLoadFile(config, filename, _RC)
call get_config_attributes(config, comp_name, RUN_DT, restart_file, shared_obj, phase, subset, NX, NY, _RC)
! create a clock, set current time to required time consistent with checkpoints used
call formatter%open(restart_file, pFIO_Read, _RC)
call ESMF_TimeIntervalSet(time_interval, s=RUN_DT, _RC)
basic_metadata=formatter%read(_RC)
call metadata%create(basic_metadata,trim(restart_file))
call metadata%get_time_info(timeVector=start_time,_RC)
clock = ESMF_ClockCreate(time_interval, start_time(1), _RC)
call formatter%close(_RC)
! create MAPL_MetaComp object, add child
grid=grid_manager%make_grid(config, _RC)
temp_GC = ESMF_GridCompCreate(name=comp_name, _RC)
mapl_obj => null()
call MAPL_InternalStateCreate(temp_GC, mapl_obj, _RC)
call MAPL_InternalStateRetrieve(temp_GC, mapl_obj, _RC)
call MAPL_Set(mapl_obj, CF=config, _RC)
root_id = MAPL_AddChild(mapl_obj, grid=grid, name=comp_name, userRoutine="setservices_", sharedObj=shared_obj, _RC)
GC = mapl_obj%get_child_gridcomp(root_id)
import = mapl_obj%get_child_import_state(root_id)
export = mapl_obj%get_child_export_state(root_id)
! if subsetting, get appropriate lons and lats
if (subset .and. NX*NY == 1) then
call formatter%open(restart_file, pFIO_Read, _RC)
call ESMF_GridGetCoord(grid, coordDim=1, farrayPtr=lons_field_ptr, _RC)
call ESMF_GridGetCoord(grid, coordDim=2, farrayPtr=lats_field_ptr, _RC)
call formatter%get_var("lons", lons_field_ptr)
call formatter%get_var("lats", lats_field_ptr)
call ESMF_GridCompSet(GC, grid=grid, _RC)
call formatter%close(_RC)
else
call ESMF_GridCompSet(GC, grid=grid, _RC)
end if
call ESMF_GridCompInitialize(GC, importState=import, exportState=export, clock=clock, userRC=user_RC, _RC)
call ESMF_GridCompRun(GC, importState=import, exportState=export, clock=clock, phase=phase, userRC=user_RC, _RC)
call ESMF_GridCompFinalize(GC, importState=import, exportState=export, clock=clock, userRC=user_RC, _RC)
_RETURN(_SUCCESS)
end subroutine run_component_driver