NCEPLIBS-ncio  1.0.0
All Namespaces Files Functions
read_attribute_code.f90
1 
5  type(Dataset), intent(in) :: dset
6  character(len=*), intent(in), optional :: varname
7  character(len=*), intent(in) :: attname
8  integer, intent(out), optional :: errcode
9  integer ncerr, varid, nvar, nlen
10  logical return_errcode
11  ! check if use the errcode
12  if(present(errcode)) then
13  return_errcode=.true.
14  errcode = 0
15  else
16  return_errcode=.false.
17  endif
18  ! access attributes based on variable name
19  if(present(varname))then
20  nvar = get_nvar(dset,varname)
21  varid = dset%variables(nvar)%varid
22  else
23  varid = nf90_global
24  endif
25  ncerr = nf90_inquire_attribute(dset%ncid, varid, attname, len=nlen)
26  if (return_errcode) then
27  call nccheck(ncerr,halt=.false.)
28  errcode=ncerr
29  if (ncerr /= 0) return
30  else
31  call nccheck(ncerr)
32  endif
33  if (allocated(values)) deallocate(values)
34  allocate(values(nlen))
35  ncerr = nf90_get_att(dset%ncid, varid, trim(attname), values)
36  ! err check
37  if (return_errcode) then
38  call nccheck(ncerr,halt=.false.)
39  errcode=ncerr
40  else
41  call nccheck(ncerr)
42  endif