da_put_att_cdf.inc
References to this file elsewhere.
1 subroutine da_put_att_cdf(file, var, att_name, text, debug)
2
3 !-----------------------------------------------------------------------
4 ! Purpose: TBD
5 !-----------------------------------------------------------------------
6
7 implicit none
8
9 #include "netcdf.inc"
10
11 character (len=80), intent(in) :: file
12 character (len=*), intent(in) :: var, att_name, text
13 logical, intent(in) :: debug
14
15 integer :: cdfid, status, varid, n, natts
16 character (len=256) :: loc_att_name
17
18 status = NF_OPEN(file, NF_WRITE, cdfid)
19
20 if (status == 0) then
21 if (debug) write(unit=stdout,fmt=*) ' open netcdf file ', trim(file)
22 else
23 write(unit=stdout,fmt=*) ' error openiing netcdf file ', trim(file)
24 stop
25 end if
26
27 status = NF_inQ_VARID(cdfid, var, varid)
28
29 status = NF_inQ_VARNATTS(cdfid, varid, natts)
30
31 do n=1, natts
32 status = NF_inQ_ATTNAME(cdfid, varid, n, loc_att_name)
33
34 write(unit=*, fmt='(a,i2,2a)') &
35 'loc_att_name(',n,')=', trim(loc_att_name)
36
37 if (trim(loc_att_name) == trim(att_name)) then
38 write(unit=*, fmt='(2a)') &
39 'att_name=', trim(att_name)
40
41 status = NF_PUT_ATT_TEXT(cdfid, varid, trim(att_name), len(text), trim(text))
42
43 if (status == 0) then
44 if (debug) then
45 write(unit=*, fmt='(4a)') &
46 'write ', trim(att_name), 'to netcdf file ', trim(file)
47 end if
48 else
49 write(unit=*, fmt='(a, i8)') &
50 'Status= ', status
51
52 write(unit=*, fmt='(4a)') &
53 'Failed to write ', trim(att_name), 'to netcdf file ', trim(file)
54
55 ! if (status /= NF_NOERR) call handle_err(status)
56 stop
57 end if
58
59 exit
60 end if
61 end do
62
63 status = NF_close(cdfid)
64
65 end subroutine da_put_att_cdf
66
67