subroutine input_nc_check_dims(ncid, icheck, vname)
use netcdf, only : &
nf90_inq_dimid, nf90_inquire_dimension, nf90_inq_varid, nf90_get_var
! file and variable id to read from
integer, intent (in) :: ncid
! check if same as already set values
logical, intent (in) :: icheck
! name of variable being checked
character(len=*), intent(in) :: vname
! dimension ids to read length
integer :: lon_dimid, lat_dimid, rec_dimid
! variable ids to read time, lon/lat values
integer :: lon_varid, lat_varid, time_varid
integer :: nlo, nla, nre
! Get var ids of lon/lat and time
call input_nc_check_error( nf90_inq_dimid(ncid, trim(NC_LON_VNAME), lon_dimid) )
call input_nc_check_error( nf90_inquire_dimension(ncid, lon_dimid, len = nlo) )
call input_nc_check_error( nf90_inq_dimid(ncid, trim(NC_LAT_VNAME), lat_dimid) )
call input_nc_check_error( nf90_inquire_dimension(ncid, lat_dimid, len = nla) )
call input_nc_check_error( nf90_inq_dimid(ncid, trim(NC_TIME_VNAME), rec_dimid) )
call input_nc_check_error( nf90_inquire_dimension(ncid, rec_dimid, len = nre) )
! report dimensions
if (NC_DEBUG) call log_debug("input_nc_check_dims", &
'Number of nc_lons, nc_lats, timesteps:', ints=(/nlo, nla, nre/))
! check or assign
if (icheck) then
if (nlo /= nc_nlons) then
call log_error("input_nc_check_dims", vname//' has different number of nc_lons', &
ints=(/nlo, nc_nlons/))
endif
if (nla /= nc_nlats) then
call log_error("input_nc_check_dims", vname//' has different number of nc_lats', &
ints=(/nla, nc_nlats/))
endif
if (nre /= nc_nrecs) then
call log_error("input_nc_check_dims", vname//' has different number of time steps', &
ints=(/nre, nc_nrecs/))
endif
else
! assign
nc_nlons = nlo
nc_nlats = nla
nc_nrecs = nre
! allocate nc_lons, nc_lats, time
allocate(nc_lons(nc_nlons))
allocate(nc_lats(nc_nlats))
allocate(nc_time_ix(nc_nrecs))
! read time, nc_lons and nc_lats
call input_nc_check_error( nf90_inq_varid(ncid, trim(NC_LON_VNAME), lon_varid) )
call input_nc_check_error( nf90_get_var(ncid, lon_varid, nc_lons) )
call input_nc_check_error( nf90_inq_varid(ncid, trim(NC_LAT_VNAME), lat_varid) )
call input_nc_check_error( nf90_get_var(ncid, lat_varid, nc_lats) )
call input_nc_check_error( nf90_inq_varid(ncid, trim(NC_TIME_VNAME), time_varid) )
call input_nc_check_error( nf90_get_var(ncid, time_varid, nc_time_ix) )
endif
end subroutine input_nc_check_dims