subroutine get_ncfile_dimension(filename, nlon, nlat, tdim, key_lon, key_lat, key_time, rc)
use netcdf
implicit none
character(len=*), intent(in) :: filename
integer, optional,intent(out) :: nlat, nlon, tdim
character(len=*), optional, intent(in) :: key_lon, key_lat, key_time
integer, optional, intent(out) :: rc
integer :: ncid , dimid
integer :: status
character(len=ESMF_MAXSTR) :: lon_name, lat_name, time_name
call check_nc_status(nf90_open(trim(fileName), NF90_NOWRITE, ncid), _RC)
if(present(key_lon)) then
lon_name=trim(key_lon)
call check_nc_status(nf90_inq_dimid(ncid, trim(lon_name), dimid), _RC)
call check_nc_status(nf90_inquire_dimension(ncid, dimid, len=nlon), _RC)
endif
if(present(key_lat)) then
lat_name=trim(key_lat)
call check_nc_status(nf90_inq_dimid(ncid, trim(lat_name), dimid), _RC)
call check_nc_status(nf90_inquire_dimension(ncid, dimid, len=nlat), _RC)
endif
if(present(key_time)) then
time_name=trim(key_time)
call check_nc_status(nf90_inq_dimid(ncid, trim(time_name), dimid), _RC)
call check_nc_status(nf90_inquire_dimension(ncid, dimid, len=tdim), _RC)
endif
call check_nc_status(nf90_close(ncid), _RC)
_RETURN(_SUCCESS)
end subroutine get_ncfile_dimension