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=*), 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
19 ! not for update_bc
20 ! if (trace_use) call da_trace_entry("da_put_att_cdf")
21
22 status = NF_OPEN(file, NF_WRITE, cdfid)
23
24 if (status == 0) then
25 if (debug) write(unit=stdout,fmt=*) ' open netcdf file ', trim(file)
26 else
27 write(unit=stdout,fmt=*) ' error openiing netcdf file ', trim(file)
28 stop
29 end if
30
31 status = NF_inQ_VARID(cdfid, var, varid)
32
33 status = NF_inQ_VARNATTS(cdfid, varid, natts)
34
35 do n=1, natts
36 status = NF_inQ_ATTNAME(cdfid, varid, n, loc_att_name)
37
38 write(unit=stdout, fmt='(a,i2,2a)') &
39 'loc_att_name(',n,')=', trim(loc_att_name)
40
41 if (trim(loc_att_name) == trim(att_name)) then
42 write(unit=stdout, fmt='(2a)') &
43 'att_name=', trim(att_name)
44
45 status = NF_PUT_ATT_TEXT(cdfid, varid, trim(att_name), len(text), trim(text))
46
47 if (status == 0) then
48 if (debug) then
49 write(unit=stdout, fmt='(4a)') &
50 'write ', trim(att_name), 'to netcdf file ', trim(file)
51 end if
52 else
53 write(unit=stdout, fmt='(a, i8)') &
54 'Status= ', status
55
56 write(unit=stdout, fmt='(4a)') &
57 'Failed to write ', trim(att_name), 'to netcdf file ', trim(file)
58
59 ! if (status /= NF_NOERR) call handle_err(status)
60 stop
61 end if
62
63 exit
64 end if
65 end do
66
67 status = NF_close(cdfid)
68
69 !if (trace_use) call da_trace_exit("da_put_att_cdf")
70
71 end subroutine da_put_att_cdf
72
73