x_comp_check_field Subroutine

private subroutine x_comp_check_field(xstate, xfield, rc)

Arguments

Type IntentOptional Attributes Name
type(xdata_state), intent(in), pointer :: xstate
type(xdata_field), intent(inout), pointer :: xfield
integer, intent(out) :: rc

Source Code

  subroutine x_comp_check_field(xstate, xfield, rc)
    ! arguments
    type(xdata_state), pointer, intent(in)    :: xstate
    type(xdata_field), pointer, intent(inout) :: xfield
    integer, intent(out)                      :: rc
    ! local variables

    rc = ESMF_SUCCESS

    if (.not. associated(xstate)) then
      call ESMF_LogSetError(ESMF_RC_PTR_NOTALLOC, &
        msg='XDATA: xstate has not been associated', &
        line=__LINE__, file=__FILE__, rcToReturn=rc)
      return
    endif

    if (xfield%rlze) then
      if(xfield%fdim .eq. 3) then
        xfield%lsum(1)=sum(xfield%ptr3,xfield%ptr3.ne.filv)
        xfield%lsum(2)=count(xfield%ptr3.ne.filv)
        xfield%lmin(1)=minval(xfield%ptr3,xfield%ptr3.ne.filv)
        xfield%lmax(1)=maxval(xfield%ptr3,xfield%ptr3.ne.filv)
      elseif(xfield%fdim .eq. 2) then
        xfield%lsum(1)=sum(xfield%ptr2,xfield%ptr2.ne.filv)
        xfield%lsum(2)=count(xfield%ptr2.ne.filv)
        xfield%lmin(1)=minval(xfield%ptr2,xfield%ptr2.ne.filv)
        xfield%lmax(1)=maxval(xfield%ptr2,xfield%ptr2.ne.filv)
      else
        call ESMF_LogSetError(ESMF_RC_NOT_IMPL, &
          msg=trim(xstate%cname)//": field dimension - "//trim(xfield%stdn), &
          line=__LINE__, file=__FILE__, rcToReturn=rc)
        return
      endif
      call ESMF_VMReduce(vm=xstate%vm, sendData=xfield%lsum, &
        recvData=xfield%gsum, count=2, &
        reduceflag=ESMF_REDUCE_SUM, rootPet=xstate%outid, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      call ESMF_VMReduce(vm=xstate%vm, sendData=xfield%lmin, &
        recvData=xfield%gmin, count=1, &
        reduceflag=ESMF_REDUCE_MIN, rootPet=xstate%outid, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      call ESMF_VMReduce(vm=xstate%vm, sendData=xfield%lmax, &
        recvData=xfield%gmax, count=1, &
        reduceflag=ESMF_REDUCE_MAX, rootPet=xstate%outid, rc=rc)
      if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
        line=__LINE__, file=__FILE__)) return
      if (xstate%myid .eq. xstate%outid) then
        ! calculate average
        if(xfield%gsum(2) .lt. 1) then
          xfield%gavg = 0.0_ESMF_KIND_R8
        else
          xfield%gavg = xfield%gsum(1) / xfield%gsum(2)
        endif
        ! check
        if((xfield%gmin(1) .lt. xfield%minv) .or. &
           (xfield%gmax(1) .gt. xfield%maxv)) then
          xfield%okay = .false.
        else
          xfield%okay = .true.
        endif
      endif
    else
      xfield%gsum = (/filv, 0.0_ESMF_KIND_R8/)
      xfield%gmin = filv
      xfield%gmax = filv
      xfield%gavg = 0.0_ESMF_KIND_R8
      xfield%okay = .false.
    endif
  endsubroutine x_comp_check_field