ESMF_GetMeshFromUGridFile Subroutine

public subroutine ESMF_GetMeshFromUGridFile(filename, nodeCoords, elmtConn, elmtNums, startElmt, faceCoords, convertToDeg, rc)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
real(kind=ESMF_KIND_R8), pointer :: nodeCoords(:,:)
integer(kind=ESMF_KIND_I4), pointer :: elmtConn(:)
integer(kind=ESMF_KIND_I4), pointer :: elmtNums(:)
integer, intent(out) :: startElmt
real(kind=ESMF_KIND_R8), optional, pointer :: faceCoords(:,:)
logical, intent(in), optional :: convertToDeg
integer, intent(out), optional :: rc

Source Code

subroutine ESMF_GetMeshFromUGridFile (filename, nodeCoords, elmtConn, &
                                elmtNums, startElmt,  &
                                faceCoords, convertToDeg, rc)

    character(len=*), intent(in)   :: filename
    real(ESMF_KIND_R8), pointer    :: nodeCoords (:,:)
    integer(ESMF_KIND_I4), pointer :: elmtConn (:)
    integer(ESMF_KIND_I4), pointer :: elmtNums (:)
    integer,           intent(out) :: startElmt
    real(ESMF_KIND_R8), pointer, optional    :: faceCoords (:,:)
    logical, intent(in), optional  :: convertToDeg
    integer, intent(out), optional :: rc


    type(ESMF_VM) :: vm
    integer PetNo, PetCnt

    integer :: ncid, meshId
    integer :: ncStatus
    integer :: meshDim
    character(len=256) :: errmsg
    character(len=24) :: attbuf
    integer :: len
    logical :: convertToDegLocal
    logical :: faceCoordFlag
    integer :: localrc
    integer, parameter :: nf90_noerror = 0

#ifdef ESMF_NETCDF
    convertToDegLocal = .false.
    if (present(convertToDeg)) convertToDegLocal = convertToDeg

    ! Get VM information
    call ESMF_VMGetCurrent(vm, rc=rc)
    if (rc /= ESMF_SUCCESS) return
    ! set up local pet info
    call ESMF_VMGet(vm, localPet=PetNo, petCount=PetCnt, rc=rc)
    if (rc /= ESMF_SUCCESS) return

    call ESMF_UGridInq(filename, meshid=meshid, nodeCoordDim=meshDim, &
         faceCoordFlag=faceCoordFlag, rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
                  ESMF_CONTEXT, rcToReturn=rc)) return

    ncStatus = nf90_open (path=trim(filename), mode=nf90_nowrite, ncid=ncid)
    if (CDFCheckError (ncStatus, &
      ESMF_METHOD,  &
      ESMF_SRCLINE, trim(filename), &
      rc)) return

    if (meshDim == 2) then
       if (faceCoordFlag) then
          call ESMF_GetMesh2DFromUGrid (filename, ncid, meshId, nodeCoords, elmtConn, &
                                elmtNums, startElmt, faceCoords=faceCoords, &
                                convertToDeg=convertToDegLocal, rc=rc)
       else
          call ESMF_GetMesh2DFromUGrid (filename, ncid, meshId, nodeCoords, elmtConn, &
                                elmtNums, startElmt, convertToDeg=convertToDegLocal, rc=rc)
       endif
    elseif (meshDim == 3) then
       if (faceCoordFlag) then
          call ESMF_GetMesh3DFromUGrid (filename, ncid, meshId, nodeCoords, elmtConn, &
                                elmtNums, startElmt, faceCoords=faceCoords, &
                                rc=rc)
       else
          call ESMF_GetMesh3DFromUGrid (filename, ncid, meshId, nodeCoords, elmtConn, &
                                elmtNums, startElmt, rc=rc)
       endif                    
    else
       call ESMF_LogSetError(rcToCheck=ESMF_FAILURE, &
                 msg="- Only 2D or 3D mesh is supported currently", &
                 ESMF_CONTEXT, rcToReturn=rc)
       return
    endif
return

#else
    call ESMF_LogSetError(ESMF_RC_LIB_NOT_PRESENT, &
                 msg="- ESMF_NETCDF not defined when lib was compiled", &
                 ESMF_CONTEXT, rcToReturn=rc)
    return
#endif
end subroutine ESMF_GetMeshFromUGridFile