6 use netcdf,
only: nf90_noerr, nf90_global, nf90_inquire_attribute, nf90_char, nf90_get_att, &
7 & nf90_double, nf90_float
9 use dc_string,
only: tochar
10 use dc_trace,
only: beginsub, endsub
14 character(len = *),
intent(in):: name
15 character(len = *),
intent(out):: value
16 character(len = *),
intent(in):: default
17 integer,
intent(out):: stat
19 character(len = 64):: buffer
20 double precision,
allocatable:: dbuf(:)
21 integer,
allocatable:: ibuf(:)
22 character,
allocatable:: cbuf(:)
23 integer:: xtype, attrlen, i, iname, varid
24 character(len = *),
parameter:: subname =
"GDNcAttrGetChar"
26 call beginsub(subname,
"var=%d name=%c default=%c", i=(/var%id/), &
27 & c1=trim(name), c2=trim(default))
29 if (stat /= nf90_noerr)
goto 900
37 stat = nf90_inquire_attribute(ent%fileid, varid, name(iname:), xtype=xtype, len=attrlen)
38 if (stat /= nf90_noerr)
goto 900
39 if (xtype == nf90_char .and. attrlen <= len(buffer))
then
40 stat = nf90_get_att(ent%fileid, varid, name(iname:), buffer)
41 if (stat /= nf90_noerr)
goto 900
42 value = buffer(1: attrlen)
44 else if (xtype == nf90_char)
then
47 allocate(cbuf(attrlen))
48 stat = nf90_get_att(ent%fileid, varid, name(iname:), cbuf(1))
49 if (stat /= nf90_noerr)
goto 900
53 if (attrlen < len(
value)) value(attrlen + 1: ) =
' '
56 else if (xtype == nf90_double .or. xtype == nf90_float)
then
57 allocate(dbuf(attrlen))
58 stat = nf90_get_att(ent%fileid, varid, name(iname:), dbuf)
59 if (stat /= nf90_noerr)
goto 900
63 allocate(ibuf(attrlen))
64 stat = nf90_get_att(ent%fileid, varid, name(iname:), ibuf)
65 if (stat /= nf90_noerr)
goto 900
74 call endsub(subname,
"value := default")