ESMF_InfoGetArrayLGAlloc Subroutine

private subroutine ESMF_InfoGetArrayLGAlloc(info, key, values, keywordEnforcer, itemCount, attnestflag, scalarToArray, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Info), intent(in) :: info
character(len=*), intent(in) :: key
logical, intent(out), dimension(:), allocatable :: values
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
integer, intent(out), optional :: itemCount
type(ESMF_AttNest_Flag), intent(in), optional :: attnestflag
logical, intent(in), optional :: scalarToArray
integer, intent(out), optional :: rc

Source Code

subroutine ESMF_InfoGetArrayLGAlloc(info, key, values, keywordEnforcer, itemCount, attnestflag, scalarToArray, rc)
  type(ESMF_Info), intent(in) :: info
  character(len=*), intent(in) :: key
  logical, dimension(:),  allocatable, intent(out) :: values
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
  integer, intent(out), optional :: itemCount
  type(ESMF_AttNest_Flag), intent(in), optional :: attnestflag
  logical, intent(in), optional :: scalarToArray
  integer, intent(out), optional :: rc

  integer :: localrc
  integer(C_INT) :: recursive, local_itemCount, expected_size, local_scalarToArray
  integer :: ii
  logical :: is_array
  logical(C_BOOL), dimension(:), allocatable :: local_values

  localrc = ESMF_FAILURE
  if (present(rc)) rc = ESMF_FAILURE
  recursive = 0 !false

  if (present(attnestflag)) then
    if (attnestflag%value==ESMF_ATTNEST_ON%value) recursive = 1 !true
  end if

  local_scalarToArray = 0 !false
  if (present(scalarToArray)) then
    if (scalarToArray) local_scalarToArray = 1 !true
  end if

  ! Set the value to a negative one to indicate we are doing an allocatable call
  ! into the storage layer, and the size should not be checked.
  expected_size = -1

  ! Get the array size from the info store
  call ESMF_InfoGetArrayMeta(info, key, is_array, local_itemcount, attnestflag=attnestflag, &
    rc=localrc)
  if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return

  ! Allocate the outgoing storage array and call into C to fill the array
  allocate(values(local_itemCount))

  ! Store boolean integers for transfer from C
  allocate(local_values(SIZE(values)))

  call c_info_get_array_LG(&
    info%ptr, &
    trim(key)//C_NULL_CHAR, &
    local_values, &
    local_itemCount, &
    localrc, &
    recursive, &
    local_scalarToArray, &
    expected_size)
  if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return

  ! Transfer to logical storage from boolean integers
  do ii=1,SIZE(values)
    values(ii) = local_values(ii)
  enddo
  deallocate(local_values)

  if (present(itemCount)) itemCount = local_itemCount
  if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_InfoGetArrayLGAlloc