NCEPLIBS-ncio  1.0.0
All Namespaces Files Functions
write_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
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  ! find the variable
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  ! varibale data into define mode
26  ncerr = nf90_redef(dset%ncid)
27  if (return_errcode) then
28  call nccheck(ncerr,halt=.false.)
29  errcode=ncerr
30  if (ncerr /= 0) return
31  else
32  call nccheck(ncerr)
33  endif
34  ! add attributes
35  ncerr = nf90_put_att(dset%ncid, varid, trim(attname), values)
36  if (return_errcode) then
37  call nccheck(ncerr,halt=.false.)
38  errcode=ncerr
39  ncerr = nf90_enddef(dset%ncid)
40  return
41  else
42  call nccheck(ncerr)
43  ncerr = nf90_enddef(dset%ncid)
44  call nccheck(ncerr)
45  endif