-
Notifications
You must be signed in to change notification settings - Fork 0
/
nc_putAttr.F90
178 lines (144 loc) · 6.68 KB
/
nc_putAttr.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
!--------------------------------------------------------------------------------------------
subroutine nc_putAttr(ncid, nd, dimids, xtype, var_name, &
desc, units, coordinates, missing_value)
use netcdf
implicit none
integer, intent(in) :: ncid, nd, xtype
integer, dimension(6), intent(in) :: dimids
character(len=*), intent(in) :: var_name, desc, units, coordinates
real(kind=8), intent(in) :: missing_value
!--Variable id
integer :: varid, md
!--Return status
integer :: status
md = nd
if(md > 6) then
write(unit=0, fmt='(a, i6)') "We can only handle data up to 5d. but here nd = ", nd
endif
!--Always set the extra dimension unlimited.
! dimids(nd+1) = nf90_unlimited
status = nf90_def_var(ncid, trim(var_name), xtype, dimids(1:md), varid)
if(status /= nf90_noerr) then
write(unit=0, fmt='(a, i6)') "ncid: ", ncid
write(unit=0, fmt='(a, 6i6)') "dimids: ", dimids(1:md)
write(unit=0, fmt='(3a)') "Problem to def varid for: <", trim(var_name), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
! status = nf90_put_att(ncid, varid, "description", trim(desc))
status = nf90_put_att(ncid, varid, "long_name", trim(desc))
if(status /= nf90_noerr) then
write(unit=0, fmt='(3a)') "Problem to write attribute description: <", trim(desc), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
! status = nf90_put_att(ncid, varid, "long_name", trim(var_name))
! if(status /= nf90_noerr) then
! write(unit=0, fmt='(3a)') "Problem to write attribute long_name: <", trim(var_name), ">.", &
! "Error status: ", trim(nf90_strerror(status))
! write(unit=0, fmt='(3a, i4)') &
! "Stop in file: <", __FILE__, ">, line: ", __LINE__
! stop
! endif
status = nf90_put_att(ncid, varid, "units", trim(units))
if(status /= nf90_noerr) then
write(unit=0, fmt='(3a)') "Problem to write attribute units: <", trim(units), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
! status = nf90_put_att(ncid, varid, "_CoordinateAxisType", trim(coordinates))
status = nf90_put_att(ncid, varid, "_CoordinateAxes", trim(coordinates))
if(status /= nf90_noerr) then
write(unit=0, fmt='(3a)') "Problem to write attribute coordinates: <", trim(coordinates), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
status = nf90_put_att(ncid, varid, "_FillValue", missing_value)
if(status /= nf90_noerr) then
write(unit=0, fmt='(a, f12.2)') "Problem to write attribute missing_value: ", missing_value
write(unit=0, fmt='(3a)') "Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
end subroutine nc_putAttr
!--------------------------------------------------------------------------------------------
subroutine nc_putAttrInt(ncid, nd, dimids, xtype, var_name, &
desc, units, coordinates, missing_int)
use netcdf
implicit none
integer, intent(in) :: ncid, nd, xtype
integer, dimension(6), intent(in) :: dimids
character(len=*), intent(in) :: var_name, desc, units, coordinates
integer, intent(in) :: missing_int
!--Variable id
integer :: varid, md
!--Return status
integer :: status
md = nd
if(md > 6) then
write(unit=0, fmt='(a, i6)') "We can only handle data up to 5d. but here nd = ", nd
endif
!--Always set the extra dimension unlimited.
! dimids(nd+1) = nf90_unlimited
status = nf90_def_var(ncid, trim(var_name), xtype, dimids(1:md), varid)
if(status /= nf90_noerr) then
write(unit=0, fmt='(a, i6)') "ncid: ", ncid
write(unit=0, fmt='(a, 6i6)') "dimids: ", dimids(1:md)
write(unit=0, fmt='(3a)') "Problem to def varid for: <", trim(var_name), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
! status = nf90_put_att(ncid, varid, "description", trim(desc))
status = nf90_put_att(ncid, varid, "long_name", trim(desc))
if(status /= nf90_noerr) then
write(unit=0, fmt='(3a)') "Problem to write attribute description: <", trim(desc), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
! status = nf90_put_att(ncid, varid, "long_name", trim(var_name))
! if(status /= nf90_noerr) then
! write(unit=0, fmt='(3a)') "Problem to write attribute long_name: <", trim(var_name), ">.", &
! "Error status: ", trim(nf90_strerror(status))
! write(unit=0, fmt='(3a, i4)') &
! "Stop in file: <", __FILE__, ">, line: ", __LINE__
! stop
! endif
status = nf90_put_att(ncid, varid, "units", trim(units))
if(status /= nf90_noerr) then
write(unit=0, fmt='(3a)') "Problem to write attribute units: <", trim(units), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
! status = nf90_put_att(ncid, varid, "_CoordinateAxisType", trim(coordinates))
status = nf90_put_att(ncid, varid, "_CoordinateAxes", trim(coordinates))
if(status /= nf90_noerr) then
write(unit=0, fmt='(3a)') "Problem to write attribute coordinates: <", trim(coordinates), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
status = nf90_put_att(ncid, varid, "_FillValue", missing_int)
if(status /= nf90_noerr) then
write(unit=0, fmt='(a, f12.2)') "Problem to write attribute missing_int: ", missing_int
write(unit=0, fmt='(3a)') "Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
endif
end subroutine nc_putAttrInt