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
12 implicit none
13 type(GD_NC_VARIABLE), intent(in):: var
14 character(len = *), intent(in):: name
15 character(len = *), intent(out):: value
16 character(len = *), intent(in):: default
17 integer, intent(out):: stat
18 type(GD_NC_VARIABLE_ENTRY):: ent
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"
25 continue
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
31 varid = nf90_global
32 iname = 2
33 else
34 varid = ent%varid
35 iname = 1
36 endif
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
45
46
47 allocate(cbuf(attrlen))
48 stat = nf90_get_att(ent%fileid, varid, name(iname:), cbuf(1))
49 if (stat /= nf90_noerr) goto 900
50 do, i = 1, attrlen
51 value(i:i) = cbuf(i)
52 enddo
53 if (attrlen < len(value)) value(attrlen + 1: ) = ' '
55 deallocate(cbuf)
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
60 value = tochar(dbuf)
61 deallocate(dbuf)
62 else
63 allocate(ibuf(attrlen))
64 stat = nf90_get_att(ent%fileid, varid, name(iname:), ibuf)
65 if (stat /= nf90_noerr) goto 900
66 value = tochar(ibuf)
67 deallocate(ibuf)
68 endif
69 call endsub(subname)
70 return
71
72900 continue
73 value = default
74 call endsub(subname, "value := default")
75 return
integer, parameter, public gt_echarshort
character, parameter, public gt_plus
integer function, public vtable_lookup(var, entry)