test_pointlist_from_inputs Subroutine

subroutine test_pointlist_from_inputs(rc)

Arguments

Type IntentOptional Attributes Name
integer, intent(out) :: rc

Source Code

  subroutine test_pointlist_from_inputs(rc)
    integer, intent(out) :: rc

    integer :: localrc
    integer :: petCount,localPet

    type(ESMF_PointList) :: pointlist
    type(ESMF_VM) :: vm
    integer :: maxpts, mydims, mypts, myid
    real(ESMF_KIND_R8), dimension(3) :: mycoords1=(/11.0,13.0,17.0/)
    real(ESMF_KIND_R8), dimension(3) :: mycoords2=(/19.0,23.0,29.0/)
    real(ESMF_KIND_R8), dimension(3) :: mycoords3=(/31.0,37.0,41.0/)
    real(ESMF_KIND_R8), dimension(3) :: mycoords4=(/43.0,47.0,53.0/)

    ! get global VM
    call ESMF_VMGetGlobal(vm, rc=localrc)
    if (ESMF_LogFoundError(localrc, &
        ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return

    call ESMF_VMGet(vm, localPet=localPet, petCount=petCount, rc=localrc)
    if (ESMF_LogFoundError(localrc, &
        ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return

    !------------------------------------------------------------------------

    maxpts=-99
    mypts=-99
    mydims=-99
    myid=-99

    pointlist = ESMF_PointListCreate(maxpts=7,numdims=3, rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble creating pointlist'
       rc=ESMF_FAILURE
       return
    endif       

    call ESMF_PointListGet(pointlist, dims=mydims, numpts=mypts, maxpts=maxpts, rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble accessing pointlist data with get routine'
       rc=ESMF_FAILURE
       return
    endif       

    if (maxpts .ne. 7 .or. mypts .ne. 0 .or. mydims .ne. 3) then
       print*,'ERROR:  unexpected values for newly created pointlist:'
       print*,'maxpts should be: 7  got: ',maxpts
       print*,'numpts should be: 0  got: ',mypts
       print*,'dims should be: 3  got: ',mydims
       rc=ESMF_FAILURE
       return
    endif       

    call ESMF_PointListAdd(pointlist=pointlist,id=123,loc_coords=mycoords1,rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble adding point to pointlist'
       rc=ESMF_FAILURE
       return
    endif       
    call ESMF_PointListAdd(pointlist=pointlist,id=234,loc_coords=mycoords2,rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble adding point to pointlist'
       rc=ESMF_FAILURE
       return
    endif       
    call ESMF_PointListAdd(pointlist=pointlist,id=345,loc_coords=mycoords3,rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble adding point to pointlist'
       rc=ESMF_FAILURE
       return
    endif       
    call ESMF_PointListAdd(pointlist=pointlist,id=456,loc_coords=mycoords4,rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble adding point to pointlist'
       rc=ESMF_FAILURE
       return
    endif       

    call ESMF_PointListGet(pointlist, dims=mydims, numpts=mypts, maxpts=maxpts, rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble accessing pointlist data with get routine'
       rc=ESMF_FAILURE
       return
    endif       

    if (maxpts .ne. 7 .or. mypts .ne. 4 .or. mydims .ne. 3) then
       print*,'ERROR:  unexpected values for newly created pointlist:'
       print*,'maxpts should be: 7  got: ',maxpts
       print*,'numpts should be: 4  got: ',mypts
       print*,'dims should be: 3  got: ',mydims
       rc=ESMF_FAILURE
       return
    endif       

!    call ESMF_PointListPrint(pointlist)
!    if (localrc /= ESMF_SUCCESS) then
!       rc=ESMF_FAILURE
!       return
!    endif      

!    call ESMF_PointListWriteVTK(pointlist,"TestPointList")
!    if (localrc /= ESMF_SUCCESS) then
!       rc=ESMF_FAILURE
!       return
!    endif      


    !locations values are zero based
    call ESMF_PointListGetForLoc(pointlist,2,id=myid,rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble accessing pointlist data with get for location routine'
       rc=ESMF_FAILURE
       return
    endif       

    if (myid .ne. 345) then
       print*,'ERROR:  unexpected values for newly created pointlist:'
       print*,'id should be: 345  got: ',myid
       rc=ESMF_FAILURE
       return
    endif       

    call ESMF_PointListDestroy(pointlist,rc=localrc)
    if (localrc /= ESMF_SUCCESS) then
       print*,'ERROR:  trouble destroying pointlist'
       rc=ESMF_FAILURE
       return
    endif       

    rc=ESMF_SUCCESS

  end subroutine test_pointlist_from_inputs