recursive subroutine ESMF_CompSet(compp, name, vm, vm_info, grid, gridList, &
mesh, meshList, locstream, locstreamList, xgrid, xgridList, clock, &
dirPath, configFile, config, rc)
!
! !ARGUMENTS:
type(ESMF_CompClass), pointer :: compp
character(len=*), intent(in), optional :: name
type(ESMF_VM), intent(in), optional :: vm
type(ESMF_Pointer), intent(in), optional :: vm_info
type(ESMF_Grid), intent(in), optional :: grid
type(ESMF_Grid), intent(in), optional :: gridList(:)
type(ESMF_Mesh), intent(in), optional :: mesh
type(ESMF_Mesh), intent(in), optional :: meshList(:)
type(ESMF_LocStream), intent(in), optional :: locstream
type(ESMF_LocStream), intent(in), optional :: locstreamList(:)
type(ESMF_XGrid), intent(in), optional :: xgrid
type(ESMF_XGrid), intent(in), optional :: xgridList(:)
type(ESMF_Clock), intent(in), optional :: clock
character(len=*), intent(in), optional :: dirPath
character(len=*), intent(in), optional :: configFile
type(ESMF_Config), intent(in), optional :: config
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Sets or resets information about the component. When the caller
! only wants to set a single value specify the argument by name.
! All the arguments after the component input are optional
! to facilitate this.
!
!EOPI
!------------------------------------------------------------------------------
integer :: localrc ! local return code
type(ESMF_Status) :: baseStatus
character(len=ESMF_MAXPATHLEN) :: fullpath ! config file + dirPath
character(len=ESMF_MAXSTR) :: msgbuf
! Initialize return code; assume not implemented until success is certain
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! Test incoming compp object
if (.not.associated(compp)) then
call ESMF_LogSetError(ESMF_RC_OBJ_BAD, &
msg="Not a valid pointer to ESMF Component object", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Check init status of arguments
ESMF_INIT_CHECK_DEEP(ESMF_CompClassGetInit, compp, rc)
call ESMF_BaseGetStatus(compp%base, baseStatus, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
if (baseStatus /= ESMF_STATUS_READY) then
call ESMF_LogSetError(ESMF_RC_OBJ_BAD, &
msg="uninitialized or destroyed Component object", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
if (present(name)) then
call ESMF_SetName(compp%base, name, "Component", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
if (present(vm)) then
compp%vm = vm
compp%compStatus%vmIsPresent = .true.
endif
if (present(vm_info)) then
compp%vm_info = vm_info
endif
if (present(grid).and.present(gridList)) then
call ESMF_LogSetError(ESMF_RC_ARG_INCOMP, &
msg="The 'grid' and 'gridList' arguments are mutually exclusive.", &
ESMF_CONTEXT, rcToReturn=rc)
return
else if (present(grid)) then
if (allocated(compp%gridList)) deallocate(compp%gridList)
allocate(compp%gridList(1))
compp%gridList(1) = grid
compp%compStatus%gridIsPresent = .true.
else if (present(gridList)) then
if (allocated(compp%gridList)) deallocate(compp%gridList)
allocate(compp%gridList(size(gridList)))
compp%gridList = gridList
if (size(gridList)>0) then
compp%compStatus%gridIsPresent = .true.
else
compp%compStatus%gridIsPresent = .false.
endif
endif
if (present(mesh).and.present(meshList)) then
call ESMF_LogSetError(ESMF_RC_ARG_INCOMP, &
msg="The 'mesh' and 'meshList' arguments are mutually exclusive.", &
ESMF_CONTEXT, rcToReturn=rc)
return
else if (present(mesh)) then
if (allocated(compp%meshList)) deallocate(compp%meshList)
allocate(compp%meshList(1))
compp%meshList(1) = mesh
compp%compStatus%meshIsPresent = .true.
else if (present(meshList)) then
if (allocated(compp%meshList)) deallocate(compp%meshList)
allocate(compp%meshList(size(meshList)))
compp%meshList = meshList
if (size(meshList)>0) then
compp%compStatus%meshIsPresent = .true.
else
compp%compStatus%meshIsPresent = .false.
endif
endif
if (present(locstream).and.present(locstreamList)) then
call ESMF_LogSetError(ESMF_RC_ARG_INCOMP, &
msg="The 'locstream' and 'locstreamList' arguments are mutually exclusive.", &
ESMF_CONTEXT, rcToReturn=rc)
return
else if (present(locstream)) then
if (allocated(compp%locstreamList)) deallocate(compp%locstreamList)
allocate(compp%locstreamList(1))
compp%locstreamList(1) = locstream
compp%compStatus%locstreamIsPresent = .true.
else if (present(locstreamList)) then
if (allocated(compp%locstreamList)) deallocate(compp%locstreamList)
allocate(compp%locstreamList(size(locstreamList)))
compp%locstreamList = locstreamList
if (size(locstreamList)>0) then
compp%compStatus%locstreamIsPresent = .true.
else
compp%compStatus%locstreamIsPresent = .false.
endif
endif
if (present(xgrid).and.present(xgridList)) then
call ESMF_LogSetError(ESMF_RC_ARG_INCOMP, &
msg="The 'xgrid' and 'xgridList' arguments are mutually exclusive.", &
ESMF_CONTEXT, rcToReturn=rc)
return
else if (present(xgrid)) then
if (allocated(compp%xgridList)) deallocate(compp%xgridList)
allocate(compp%xgridList(1))
compp%xgridList(1) = xgrid
compp%compStatus%xgridIsPresent = .true.
else if (present(xgridList)) then
if (allocated(compp%xgridList)) deallocate(compp%xgridList)
allocate(compp%xgridList(size(xgridList)))
compp%xgridList = xgridList
if (size(xgridList)>0) then
compp%compStatus%xgridIsPresent = .true.
else
compp%compStatus%xgridIsPresent = .false.
endif
endif
if (present(clock)) then
compp%clock = clock
compp%compStatus%clockIsPresent = .true.
endif
if (present(dirPath)) then
compp%dirPath = dirPath
endif
! config handling
if (present(config)) then
compp%config = config
compp%compStatus%configIsPresent = .true.
if (present(configFile)) then
! a config object gets priority over a name if both are specified.
call ESMF_LogWrite("Ignoring configFile because config object given.", &
ESMF_LOGMSG_WARNING)
endif
else if (present(configFile)) then
! name of a specific config file. open it and store the config object.
compp%configFile = configFile
compp%compStatus%configFileIsPresent = .true.
compp%config = ESMF_ConfigCreate(rc=localrc)
compp%compStatus%configIsPresent = .true.
call ESMF_ConfigLoadFile(compp%config, configFile, rc=localrc)
if (localrc /= ESMF_SUCCESS) then
! try again with the dirPath concatinated on front
fullpath = trim(compp%dirPath) // '/' // trim(configFile)
call ESMF_ConfigLoadFile(compp%config, fullpath, rc=localrc)
! TODO: construct a msg string and then call something here.
! if (ESMF_LogFoundError(status, msgstr, rc)) return
if (localrc /= ESMF_SUCCESS) then
write(msgbuf, *) &
"ERROR: loading config file, unable to open either", &
" name = ", trim(configFile), " or name = ", trim(fullpath)
call ESMF_LogSetError(ESMF_RC_ARG_VALUE, &
msg=msgbuf, &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
endif
endif
! Return successfully
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_CompSet