num_fields Function

public recursive function num_fields(state, rc) result(n)

Arguments

Type IntentOptional Attributes Name
type(ESMF_State), intent(inout) :: state
integer, intent(out), optional :: rc

Return Value integer


Calls

proc~~num_fields~~CallsGraph proc~num_fields num_fields proc~num_fields->proc~num_fields anyexceptions anyexceptions proc~num_fields->anyexceptions assert_that assert_that proc~num_fields->assert_that esmf_stateget esmf_stateget proc~num_fields->esmf_stateget sourcelocation sourcelocation proc~num_fields->sourcelocation

Source Code

   recursive function num_fields(state, rc) result(n)
      integer :: n
      type(ESMF_State), intent(inout) :: state
      integer, optional, intent(out) :: rc

      integer :: status
      integer :: itemCount, i
      character(ESMF_MAXSTR), allocatable :: itemNameList(:)
      type(ESMF_StateItem_Flag) :: itemType
      type(ESMF_State) :: substate

      n = 0 ! default

      call ESMF_StateGet(state, itemCount=itemCount, _RC)
      allocate(itemNameList(itemCount))
      call ESMF_StateGet(state, itemNameList=itemNameList, _RC)

      do i = 1, itemCount
         call ESMF_StateGet(state, itemName=trim(itemNameList(i)), itemType=itemType, _RC)
         if (itemType == ESMF_STATEITEM_FIELD) then
            n = n + 1
         elseif (itemType == ESMF_STATEITEM_STATE) then
            call ESMF_StateGet(state, trim(itemNameList(i)), substate, _RC)
            n = n + num_fields(substate, _RC)
         end if
      end do

      return
   end function num_fields