subroutine ESMF_GridspecQueryTileGlobal(filename, isGlobal, rc)
character(len=*), intent(in) :: filename
logical, intent(out) :: isGlobal
integer, intent(out), optional :: rc
#ifdef ESMF_NETCDF
integer :: ncid, nvars, attlen, i
integer :: ncStatus
integer :: nx, ny
integer :: ndims, dimids(2)
real(ESMF_KIND_R8), allocatable :: supergrid(:,:)
real(ESMF_KIND_R8) :: minlon, maxlon
character(len=128) :: attstr
if (present(rc)) rc=ESMF_SUCCESS
ncStatus = nf90_open(path=filename, mode=nf90_nowrite, ncid=ncid)
if (CDFCheckError (ncStatus, &
ESMF_METHOD, &
ESMF_SRCLINE, &
trim(filename), &
rc)) return
ncStatus = nf90_inquire(ncid, nVariables=nvars)
if (CDFCheckError (ncStatus, &
ESMF_METHOD, &
ESMF_SRCLINE, &
trim(filename), &
rc)) return
do i=1,nvars
! Check its standard_name attribute
ncStatus = nf90_inquire_attribute(ncid, i, 'standard_name', len=attlen)
if (ncStatus == nf90_noerr) then
ncStatus = nf90_get_att(ncid, i, 'standard_name', values=attstr)
if (attstr(1:attlen) .eq. 'geographic_longitude') then
! read the longitude variable
! First find the dimension of this variable
ncStatus = nf90_inquire_variable(ncid, i, ndims=ndims, dimids=dimids)
if (ndims /= 2) then
call ESMF_LogSetError(rcToCheck=ESMF_FAILURE, &
msg="- The longitude variable should have dimension 2", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! find out the dimenison size
ncStatus = nf90_inquire_dimension(ncid, dimids(1), len=nx)
if (CDFCheckError (ncStatus, &
ESMF_METHOD, &
ESMF_SRCLINE, &
"contact dimension inquire", &
rc)) return
ncStatus = nf90_inquire_dimension(ncid, dimids(2), len=ny)
if (CDFCheckError (ncStatus, &
ESMF_METHOD, &
ESMF_SRCLINE, &
"contact dimension inquire", &
rc)) return
allocate(supergrid(nx,ny))
ncStatus = nf90_get_var(ncid, i, supergrid)
if (CDFCheckError (ncStatus, &
ESMF_METHOD, &
ESMF_SRCLINE, &
"contact dimension inquire", &
rc)) return
minlon = minval(supergrid)
maxlon = maxval(supergrid)
if (maxlon-minlon == 360.0) then
isGlobal = .true.
else
isGlobal = .false.
endif
deallocate(supergrid)
goto 20
endif
endif
enddo
20 continue
ncStatus = nf90_close(ncid)
if (CDFCheckError (ncStatus, &
ESMF_METHOD, &
ESMF_SRCLINE, &
"close tile file", &
rc)) return
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_GridSpecQueryTileGlobal