subroutine MAPL_CapGridCompCreate(cap, cap_rc, name, final_file, unusable, n_run_phases, root_set_services, root_dso, rc)
use mapl_StubComponent
type(MAPL_CapGridComp), intent(out), target :: cap
character(*), intent(in) :: cap_rc, name
character(len=*), optional, intent(in) :: final_file
class(KeywordEnforcer), optional, intent(in) :: unusable
procedure(), optional :: root_set_services
character(len=*), optional, intent(in) :: root_dso
integer, optional, intent(in) :: n_run_phases
integer, optional, intent(out) :: rc
type(MAPL_CapGridComp_Wrapper) :: cap_wrapper
type(MAPL_MetaComp), pointer :: meta => null()
integer :: status
character(*), parameter :: cap_name = "CAP"
type(StubComponent) :: stub_component
_UNUSED_DUMMY(unusable)
cap%cap_rc_file = cap_rc
if (present(root_set_services)) cap%root_set_services => root_set_services
if (present(root_dso)) cap%root_dso = root_dso
if (present(root_dso) .and. present(root_set_services)) then
_FAIL("can only specify a setservice pointer or a dso to use")
end if
if (present(final_file)) then
allocate(cap%final_file, source=final_file)
end if
cap%n_run_phases = 1
if (present(n_run_phases)) cap%n_run_phases = n_run_phases
cap%config = ESMF_ConfigCreate(_RC)
call ESMF_ConfigLoadFile(cap%config, cap%cap_rc_file,_RC)
allocate(cap%name, source=name)
cap%gc = ESMF_GridCompCreate(name=cap_name, config=cap%config, _RC)
meta => null()
call MAPL_InternalStateCreate(cap%gc, meta, _RC)
call MAPL_Set(meta, CF=cap%config, _RC)
call MAPL_Set(meta, name=cap_name, component=stub_component, _RC)
cap_wrapper%ptr => cap
call ESMF_UserCompSetInternalState(cap%gc, internal_cap_name, cap_wrapper, status)
_VERIFY(status)
_RETURN(_SUCCESS)
end subroutine MAPL_CapGridCompCreate