1 | MODULE ooo_write |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE ooo_write *** |
---|
4 | !!====================================================================== |
---|
5 | USE netcdf |
---|
6 | USE obs_utils, ONLY: chkerr |
---|
7 | USE ooo_netcdf, ONLY: date_format, inst_converter, yyyymmdd_to_ref_date |
---|
8 | USE ooo_data |
---|
9 | IMPLICIT NONE |
---|
10 | PRIVATE |
---|
11 | |
---|
12 | PUBLIC ooo_wri_init |
---|
13 | PUBLIC ooo_wri_default |
---|
14 | PUBLIC ooo_wri_extra |
---|
15 | |
---|
16 | ! Type kinds for class 4 data. |
---|
17 | INTEGER, PARAMETER :: clsp = SELECTED_REAL_KIND( 6, 37) !: single precision |
---|
18 | INTEGER, PARAMETER :: cldp = SELECTED_REAL_KIND(12,307) !: double precision |
---|
19 | |
---|
20 | ! Missinge data indicators |
---|
21 | INTEGER, PARAMETER :: climdi = -99999 !: Integers |
---|
22 | REAL(clsp), PARAMETER :: clrmdi = 99999 !: Reals |
---|
23 | |
---|
24 | INTERFACE ooo_wri_extra |
---|
25 | MODULE PROCEDURE ooo_wri_extra_3d_index, ooo_wri_extra_4d, ooo_wri_extra_4d_index |
---|
26 | END INTERFACE |
---|
27 | |
---|
28 | CONTAINS |
---|
29 | |
---|
30 | SUBROUTINE ooo_wri_extra_3d_index(cdfilename, cdvarname, ndeps, nvars, & |
---|
31 | & nobs, kstart, kcount, pdata) |
---|
32 | !!---------------------------------------------------------------------- |
---|
33 | !! *** ROUTINE ooo_wri_extra_3d *** |
---|
34 | !! |
---|
35 | !! ** Purpose : Write 3d variables to class 4 file. |
---|
36 | !! |
---|
37 | !!---------------------------------------------------------------------- |
---|
38 | INTEGER, INTENT(IN) :: & |
---|
39 | & nobs, & !: number of observations/profiles |
---|
40 | & nvars, & !: number of physical parameters |
---|
41 | & ndeps !: number of depths |
---|
42 | CHARACTER(len=*), INTENT(IN) :: & |
---|
43 | & cdfilename, & !: netcdf file name |
---|
44 | & cdvarname !: netcdf variable name |
---|
45 | INTEGER, DIMENSION(3), INTENT(IN) :: & |
---|
46 | & kstart, & !: start indices |
---|
47 | & kcount !: count indices |
---|
48 | REAL(KIND=cldp), DIMENSION(ndeps, nvars, nobs), INTENT(IN) :: & |
---|
49 | & pdata !: 3d data |
---|
50 | INTEGER :: & |
---|
51 | & ncid, & !: |
---|
52 | & dimid, & !: |
---|
53 | & varid !: |
---|
54 | CHARACTER(len=16), PARAMETER :: cpname = 'ooo_wri_extra_3d' |
---|
55 | ! Open netcdf file |
---|
56 | CALL chkerr(nf90_open(trim(cdfilename), nf90_write, ncid), cpname, __LINE__ ) |
---|
57 | ! Write data |
---|
58 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cdvarname), varid),cpname, __LINE__ ) |
---|
59 | CALL chkerr(nf90_put_var(ncid, varid, pdata, kstart, kcount),cpname, __LINE__ ) |
---|
60 | ! Close netcdf file |
---|
61 | CALL chkerr(nf90_close(ncid), cpname, __LINE__ ) |
---|
62 | END SUBROUTINE ooo_wri_extra_3d_index |
---|
63 | |
---|
64 | SUBROUTINE ooo_wri_extra_4d_index(cdfilename, cdvarname, ndeps, nfcst, & |
---|
65 | & nvars, nobs, kstart, kcount, pdata) |
---|
66 | !!---------------------------------------------------------------------- |
---|
67 | !! *** ROUTINE ooo_wri_extra_4d *** |
---|
68 | !! |
---|
69 | !! ** Purpose : Write 4d variables to class 4 file. |
---|
70 | !! |
---|
71 | !!---------------------------------------------------------------------- |
---|
72 | INTEGER, INTENT(IN) :: & |
---|
73 | & nobs, & !: number of observations/profiles |
---|
74 | & nvars, & !: number of physical parameters |
---|
75 | & ndeps, & !: number of depths |
---|
76 | & nfcst !: number of forecasts |
---|
77 | CHARACTER(len=*), INTENT(IN) :: & |
---|
78 | & cdfilename, & !: netcdf file name |
---|
79 | & cdvarname !: netcdf variable name |
---|
80 | INTEGER, DIMENSION(4), INTENT(IN) :: & |
---|
81 | & kstart, & !: start indices |
---|
82 | & kcount !: count indices |
---|
83 | REAL(KIND=cldp), DIMENSION(ndeps, nvars, nobs), INTENT(IN) :: & |
---|
84 | & pdata !: slice of 4d data |
---|
85 | INTEGER :: & |
---|
86 | & ncid, & !: |
---|
87 | & dimid, & !: |
---|
88 | & varid !: |
---|
89 | CHARACTER(len=22), PARAMETER :: cpname = 'ooo_wri_extra_4d_index' |
---|
90 | ! Open netcdf file |
---|
91 | CALL chkerr(nf90_open(trim(cdfilename), nf90_write, ncid), cpname, __LINE__ ) |
---|
92 | ! Write data |
---|
93 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cdvarname), varid),cpname, __LINE__ ) |
---|
94 | CALL chkerr(nf90_put_var(ncid, varid, pdata, kstart, kcount),cpname, __LINE__ ) |
---|
95 | ! Close netcdf file |
---|
96 | CALL chkerr(nf90_close(ncid), cpname, __LINE__ ) |
---|
97 | END SUBROUTINE ooo_wri_extra_4d_index |
---|
98 | |
---|
99 | SUBROUTINE ooo_wri_extra_4d(cdfilename, cdvarname, ndeps, nfcst, & |
---|
100 | & nvars, nobs, pdata) |
---|
101 | !!---------------------------------------------------------------------- |
---|
102 | !! *** ROUTINE ooo_wri_extra_4d *** |
---|
103 | !! |
---|
104 | !! ** Purpose : Write 4d variables to class 4 file. |
---|
105 | !! |
---|
106 | !!---------------------------------------------------------------------- |
---|
107 | INTEGER, INTENT(IN) :: & |
---|
108 | & nobs, & !: number of observations/profiles |
---|
109 | & nvars, & !: number of physical parameters |
---|
110 | & ndeps, & !: number of depths |
---|
111 | & nfcst !: number of forecasts |
---|
112 | CHARACTER(len=*), INTENT(IN) :: & |
---|
113 | & cdfilename, & !: netcdf file name |
---|
114 | & cdvarname !: netcdf variable name |
---|
115 | REAL(KIND=cldp), DIMENSION(ndeps, nfcst, nvars, nobs), INTENT(IN) :: & |
---|
116 | & pdata !: 4d data |
---|
117 | INTEGER :: & |
---|
118 | & ncid, & !: |
---|
119 | & dimid, & !: |
---|
120 | & varid !: |
---|
121 | CHARACTER(len=16), PARAMETER :: cpname = 'ooo_wri_extra_4d' |
---|
122 | ! Open netcdf file |
---|
123 | CALL chkerr(nf90_open(trim(cdfilename), nf90_write, ncid), cpname, __LINE__ ) |
---|
124 | ! Write data |
---|
125 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cdvarname), varid),cpname, __LINE__ ) |
---|
126 | CALL chkerr(nf90_put_var(ncid, varid, pdata),cpname, __LINE__ ) |
---|
127 | ! Close netcdf file |
---|
128 | CALL chkerr(nf90_close(ncid), cpname, __LINE__ ) |
---|
129 | END SUBROUTINE ooo_wri_extra_4d |
---|
130 | |
---|
131 | SUBROUTINE ooo_wri_default(cdfilename, nobs, nvars, nfcst, ndeps, & |
---|
132 | & cdtyp, cdwmo, cunit, cvnam, & |
---|
133 | & plam, pphi, pdep, ptim, pob, plead, & |
---|
134 | & kqc, pmjuld) |
---|
135 | !!---------------------------------------------------------------------- |
---|
136 | !! *** ROUTINE ooo_wri_default *** |
---|
137 | !! |
---|
138 | !! ** Purpose : Write standard variables to class 4 file. |
---|
139 | !! ** Method : Write the following variables; |
---|
140 | !! observation type |
---|
141 | !! observation wmo id |
---|
142 | !! variable units |
---|
143 | !! variable names |
---|
144 | !! observation latitudes |
---|
145 | !! observation longitudes |
---|
146 | !! observation depths |
---|
147 | !! observation times |
---|
148 | !! observation values |
---|
149 | !! observation qc flags |
---|
150 | !! model julian days |
---|
151 | !! |
---|
152 | !! ** Returns : |
---|
153 | !!---------------------------------------------------------------------- |
---|
154 | INTEGER, INTENT(IN) :: & |
---|
155 | & nfcst, & !: number of forecasts |
---|
156 | & nobs, & !: number of observations/profiles |
---|
157 | & nvars, & !: number of physical parameters |
---|
158 | & ndeps !: number of depths |
---|
159 | CHARACTER(len=*), INTENT(IN) :: & |
---|
160 | & cdfilename !: file name |
---|
161 | CHARACTER(LEN=128), DIMENSION(nobs), INTENT(IN) :: & |
---|
162 | & cdtyp !: Instrument type |
---|
163 | CHARACTER(LEN=8), DIMENSION(nobs), INTENT(IN) :: & |
---|
164 | & cdwmo ! WMO number |
---|
165 | CHARACTER(LEN=128), DIMENSION(nobs) :: & |
---|
166 | & cdpad !: Instrument type (padded) |
---|
167 | CHARACTER(LEN=8), DIMENSION(nvars), INTENT(IN) :: & |
---|
168 | & cunit, & !: variable units (e.g. psu) |
---|
169 | & cvnam !: variable names (e.g. vosaline) |
---|
170 | REAL(KIND=cldp), DIMENSION(nfcst), INTENT(IN) :: & |
---|
171 | & plead !: Leadtime |
---|
172 | REAL(KIND=cldp), DIMENSION(nobs), INTENT(IN) :: & |
---|
173 | & pphi, & !: Latitude |
---|
174 | & plam !: Longitude |
---|
175 | REAL(KIND=cldp), DIMENSION(ndeps, nobs), INTENT(IN) :: & |
---|
176 | & pdep !: Depth |
---|
177 | REAL(KIND=cldp), DIMENSION(ndeps, nvars, nobs), INTENT(IN) :: & |
---|
178 | & pob !: T observation |
---|
179 | REAL(KIND=cldp), DIMENSION(nobs), INTENT(IN) :: & |
---|
180 | & ptim !: Time |
---|
181 | INTEGER(KIND=2), DIMENSION(ndeps, nvars, nobs), INTENT(IN) :: & |
---|
182 | & kqc !: Observation QC |
---|
183 | REAL, INTENT(IN) :: & |
---|
184 | & pmjuld !: Model Julian Day |
---|
185 | CHARACTER(len=128) :: & |
---|
186 | & cvar !: variable name placeholder |
---|
187 | INTEGER :: & |
---|
188 | & ncid, & !: |
---|
189 | & dimid, & !: |
---|
190 | & varid !: |
---|
191 | CHARACTER(len=15), PARAMETER :: cpname = 'ooo_wri_default' |
---|
192 | ! Open netcdf file |
---|
193 | CALL chkerr(nf90_open(trim(cdfilename), nf90_write, ncid), cpname, __LINE__ ) |
---|
194 | ! longitude |
---|
195 | cvar = 'longitude' |
---|
196 | WRITE(*,*) TRIM(cvar) |
---|
197 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
198 | CALL chkerr(nf90_put_var(ncid, varid, plam),cpname, __LINE__ ) |
---|
199 | ! latitude |
---|
200 | cvar = 'latitude' |
---|
201 | WRITE(*,*) TRIM(cvar) |
---|
202 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
203 | CALL chkerr(nf90_put_var(ncid, varid, pphi),cpname, __LINE__ ) |
---|
204 | ! depth |
---|
205 | cvar = 'depth' |
---|
206 | WRITE(*,*) TRIM(cvar) |
---|
207 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
208 | CALL chkerr(nf90_put_var(ncid, varid, pdep),cpname, __LINE__ ) |
---|
209 | ! varname |
---|
210 | cvar = 'varname' |
---|
211 | WRITE(*,*) TRIM(cvar) |
---|
212 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
213 | CALL chkerr(nf90_put_var(ncid, varid, cvnam),cpname, __LINE__ ) |
---|
214 | ! unitname |
---|
215 | cvar = 'unitname' |
---|
216 | WRITE(*,*) TRIM(cvar) |
---|
217 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
218 | CALL chkerr(nf90_put_var(ncid, varid, cunit),cpname, __LINE__ ) |
---|
219 | ! leadtime |
---|
220 | cvar = 'leadtime' |
---|
221 | WRITE(*,*) TRIM(cvar) |
---|
222 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
223 | CALL chkerr(nf90_put_var(ncid, varid, plead),cpname, __LINE__ ) |
---|
224 | ! observation |
---|
225 | cvar = 'observation' |
---|
226 | WRITE(*,*) TRIM(cvar) |
---|
227 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
228 | CALL chkerr(nf90_put_var(ncid, varid, pob),cpname, __LINE__ ) |
---|
229 | ! qc |
---|
230 | cvar = 'qc' |
---|
231 | WRITE(*,*) TRIM(cvar) |
---|
232 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
233 | CALL chkerr(nf90_put_var(ncid, varid, kqc),cpname, __LINE__ ) |
---|
234 | ! juld |
---|
235 | cvar = 'juld' |
---|
236 | WRITE(*,*) TRIM(cvar) |
---|
237 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
238 | CALL chkerr(nf90_put_var(ncid, varid, ptim),cpname, __LINE__ ) |
---|
239 | ! type |
---|
240 | cvar = 'type' |
---|
241 | WRITE(*,*) TRIM(cvar) |
---|
242 | CALL inst_converter(cdtyp,nobs,cdpad) |
---|
243 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
244 | CALL chkerr(nf90_put_var(ncid, varid, cdpad),cpname, __LINE__ ) |
---|
245 | ! id |
---|
246 | cvar = 'id' |
---|
247 | WRITE(*,*) TRIM(cvar) |
---|
248 | CALL chkerr(nf90_inq_varid(ncid,TRIM(cvar), varid),cpname, __LINE__ ) |
---|
249 | CALL chkerr(nf90_put_var(ncid, varid, cdwmo),cpname, __LINE__ ) |
---|
250 | ! Close netcdf file |
---|
251 | CALL chkerr(nf90_close(ncid), cpname, __LINE__ ) |
---|
252 | END SUBROUTINE ooo_wri_default |
---|
253 | |
---|
254 | SUBROUTINE ooo_wri_init(cconf, csys, ckind, cversion, ccont, & |
---|
255 | & cinst, cdate, nproc, nobs, nvars, & |
---|
256 | & ndeps, nfcst, cdfilename) |
---|
257 | !!---------------------------------------------------------------------- |
---|
258 | !! *** ROUTINE ooo_wri_init *** |
---|
259 | !! |
---|
260 | !! ** Purpose : Initialise a class 4 file. |
---|
261 | !! |
---|
262 | !! ** Method : |
---|
263 | !! ** Returns : cdfilename |
---|
264 | !!---------------------------------------------------------------------- |
---|
265 | CHARACTER(len=*), INTENT(IN) :: & |
---|
266 | & cconf, & !: model configuration e.g. orca025 |
---|
267 | & csys, & !: model system e.g. FOAM |
---|
268 | & ckind, & !: observation kind e.g. profile |
---|
269 | & cversion, & !: model version e.g. 12.0 |
---|
270 | & ccont, & !: contact email |
---|
271 | & cinst, & !: institution description |
---|
272 | & cdate !: e.g. yyyymmdd |
---|
273 | INTEGER, INTENT(IN) :: & |
---|
274 | & nproc, & !: processor number |
---|
275 | & nobs, & !: number of observations/profiles |
---|
276 | & nvars, & !: number of physical parameters |
---|
277 | & ndeps, & !: number of depths |
---|
278 | & nfcst !: number of forecast days |
---|
279 | CHARACTER(len=128), INTENT(OUT) :: & |
---|
280 | & cdfilename !: e.g. orca025 |
---|
281 | CHARACTER(len=4) :: & |
---|
282 | & cproc !: character representation of nproc |
---|
283 | CHARACTER(len=128) :: & |
---|
284 | & cattnam, & !: attribute placeholder |
---|
285 | & cattval, & !: attribute placeholder |
---|
286 | & cvar, & !: variable name placeholder |
---|
287 | & cqcdes, & !: quality control description |
---|
288 | & cqcval !: quality control values |
---|
289 | INTEGER :: & |
---|
290 | & istat, & !: status of netcdf operation |
---|
291 | & ncid, & !: netcdf file id placeholder |
---|
292 | & dimid_d, & !: netcdf dimension id placeholder |
---|
293 | & dimid_f, & !: netcdf dimension id placeholder |
---|
294 | & dimid_o, & !: netcdf dimension id placeholder |
---|
295 | & dimid_v, & !: netcdf dimension id placeholder |
---|
296 | & dimid_s, & !: netcdf dimension id placeholder |
---|
297 | & dimid_l, & !: netcdf dimension id placeholder |
---|
298 | & varid !: netcdf variable id placeholder |
---|
299 | INTEGER, DIMENSION(2) :: & |
---|
300 | & qc_flags !: quality control flags |
---|
301 | CHARACTER(len=23) :: & |
---|
302 | & ref_date !: reference date holder |
---|
303 | INTEGER, DIMENSION(2) :: & |
---|
304 | & dim2a, & !: 2 dimensional settings |
---|
305 | & dim2b, & !: |
---|
306 | & dim2c, & !: |
---|
307 | & dim2d !: |
---|
308 | INTEGER, DIMENSION(3) :: & |
---|
309 | & dim3a !: 3 dimensional settings |
---|
310 | INTEGER, DIMENSION(4) :: & |
---|
311 | & dim4a !: 4 dimensional settings |
---|
312 | CHARACTER(len=12), PARAMETER :: cpname = 'ooo_wri_init' |
---|
313 | ! Global att variables |
---|
314 | CHARACTER(len=40) :: date_str |
---|
315 | CHARACTER(len=6) :: noon |
---|
316 | |
---|
317 | WRITE(cproc, FMT="(I4.4)") nproc |
---|
318 | cdfilename = 'class4' |
---|
319 | cdfilename = TRIM(cdfilename)//'_'//TRIM(cdate) |
---|
320 | cdfilename = TRIM(cdfilename)//'_'//TRIM(csys) |
---|
321 | cdfilename = TRIM(cdfilename)//'_'//TRIM(cconf) |
---|
322 | cdfilename = TRIM(cdfilename)//'_'//TRIM(cversion) |
---|
323 | cdfilename = TRIM(cdfilename)//'_'//TRIM(ckind) |
---|
324 | cdfilename = TRIM(cdfilename)//'_'//TRIM(cproc) |
---|
325 | cdfilename = TRIM(cdfilename)//'.nc' |
---|
326 | ! QC attribute string settings |
---|
327 | IF (ckind .EQ. 'profile') THEN |
---|
328 | cqcval = '0 - good data. 9 - bad data.' |
---|
329 | cqcdes = '' |
---|
330 | qc_flags = (/0, 9/) |
---|
331 | ELSE IF (ckind .EQ. 'SST') THEN |
---|
332 | cqcval = '0 - good data. 1 - bad data.' |
---|
333 | cqcdes = 'In situ qc flag set to 0 if prob. of gross error < 0.5, & |
---|
334 | &1 otherwise. AATSR qc flag set to 0 for best_quality, 1 otherwise.' |
---|
335 | qc_flags = (/0, 1/) |
---|
336 | ELSE IF (ckind .EQ. 'SLA') THEN |
---|
337 | cqcval = '0 - good data. 9 - bad data.' |
---|
338 | cqcdes = '' |
---|
339 | qc_flags = (/0, 9/) |
---|
340 | ELSE |
---|
341 | cqcval = '' |
---|
342 | cqcdes = '' |
---|
343 | qc_flags = (/0, 9/) |
---|
344 | END IF |
---|
345 | ! Check cdfilename exists |
---|
346 | istat = nf90_open(TRIM(cdfilename), nf90_nowrite, ncid) |
---|
347 | IF (istat /= nf90_noerr) THEN |
---|
348 | WRITE(*, *) TRIM(cdfilename) |
---|
349 | CALL chkerr( nf90_create(TRIM(cdfilename), nf90_clobber, ncid), cpname, __LINE__ ) |
---|
350 | !! Global Dimension section |
---|
351 | ! Partially hardwired for now |
---|
352 | CALL date_format(date_str) |
---|
353 | noon = '120000' ! hhmmss |
---|
354 | ref_date = '' |
---|
355 | CALL yyyymmdd_to_ref_date(TRIM(cdate), noon, ref_date) |
---|
356 | |
---|
357 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'title', & |
---|
358 | & 'Forecast class 4 file'), cpname, __LINE__ ) |
---|
359 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'version', & |
---|
360 | & TRIM(cversion)), cpname, __LINE__ ) |
---|
361 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'creation_date', & |
---|
362 | & TRIM(date_str) ), cpname, __LINE__ ) |
---|
363 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'validity_time', & |
---|
364 | & TRIM(ref_date) ), cpname, __LINE__ ) |
---|
365 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'contact', & |
---|
366 | & TRIM(ccont) ), cpname, __LINE__ ) |
---|
367 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'obs_type', & |
---|
368 | & TRIM(ckind) ), cpname, __LINE__ ) |
---|
369 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'system', & |
---|
370 | & TRIM(csys)), cpname, __LINE__ ) |
---|
371 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'configuration', & |
---|
372 | & TRIM(cconf) ), cpname, __LINE__ ) |
---|
373 | CALL chkerr( nf90_put_att(ncid, nf90_global, 'institution', & |
---|
374 | & TRIM(cinst) ), cpname, __LINE__ ) |
---|
375 | |
---|
376 | !! Define Dimensions |
---|
377 | CALL chkerr(nf90_def_dim(ncid, 'numdeps', ndeps, dimid_d), cpname, __LINE__ ) |
---|
378 | CALL chkerr(nf90_def_dim(ncid, 'numfcsts', nfcst, dimid_f), cpname, __LINE__ ) |
---|
379 | CALL chkerr(nf90_def_dim(ncid, 'numvars', nvars, dimid_v), cpname, __LINE__ ) |
---|
380 | CALL chkerr(nf90_def_dim(ncid, 'numobs', nobs, dimid_o), cpname, __LINE__ ) |
---|
381 | CALL chkerr(nf90_def_dim(ncid, 'string_length8', 8, dimid_s), cpname, __LINE__ ) |
---|
382 | CALL chkerr(nf90_def_dim(ncid, 'string_length128', 128, dimid_l), cpname, __LINE__ ) |
---|
383 | !! Define possible dimension permutations |
---|
384 | ! 2d |
---|
385 | dim2a(:) = (/ dimid_d, dimid_o /) !: (/ ndeps, nobs /) |
---|
386 | dim2b(:) = (/ dimid_s, dimid_o /) !: (/ 8, nobs /) |
---|
387 | dim2c(:) = (/ dimid_s, dimid_v /) !: (/ 8, nvars /) |
---|
388 | dim2d(:) = (/ dimid_l, dimid_o /) !: (/ 128, nobs /) |
---|
389 | ! 3d |
---|
390 | dim3a(:) = (/ dimid_d, dimid_v, dimid_o/) !: (/ ndeps, nvars, nobs /) |
---|
391 | ! 4d |
---|
392 | dim4a(:) = (/ dimid_d, dimid_f, dimid_v, dimid_o /) !: (/ ndeps, nfcst, nvars, nobs /) |
---|
393 | |
---|
394 | !! Create the variables |
---|
395 | ! Forecast day |
---|
396 | cvar = 'leadtime' |
---|
397 | WRITE(*,*) TRIM(cvar) |
---|
398 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dimid_f, varid), cpname, __LINE__ ) |
---|
399 | cattnam = 'long_name' |
---|
400 | cattval = 'Model forecast day offset' |
---|
401 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
402 | cattnam = 'units' |
---|
403 | cattval = 'Hours' |
---|
404 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
405 | cattnam = 'comment' |
---|
406 | cattval = 'Hours between forecast production and validity time' |
---|
407 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
408 | |
---|
409 | ! longitude |
---|
410 | cvar = 'longitude' |
---|
411 | WRITE(*,*) TRIM(cvar) |
---|
412 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dimid_o, varid), cpname, __LINE__ ) |
---|
413 | cattnam = 'long_name' |
---|
414 | cattval = 'Longitudes' |
---|
415 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
416 | cattnam = 'units' |
---|
417 | cattval = 'Degrees' |
---|
418 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
419 | |
---|
420 | ! latitude |
---|
421 | cvar = 'latitude' |
---|
422 | WRITE(*,*) TRIM(cvar) |
---|
423 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dimid_o, varid), cpname, __LINE__ ) |
---|
424 | cattnam = 'long_name' |
---|
425 | cattval = 'Latitudes' |
---|
426 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
427 | cattnam = 'units' |
---|
428 | cattval = 'Degrees' |
---|
429 | |
---|
430 | ! depth |
---|
431 | cvar = 'depth' |
---|
432 | WRITE(*,*) TRIM(cvar) |
---|
433 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim2a, varid), cpname, __LINE__ ) |
---|
434 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
435 | cattnam = 'long_name' |
---|
436 | cattval = 'Depths' |
---|
437 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
438 | cattnam = 'units' |
---|
439 | cattval = 'metre' |
---|
440 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
441 | |
---|
442 | ! varname |
---|
443 | cvar = 'varname' |
---|
444 | WRITE(*,*) TRIM(cvar) |
---|
445 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_char, dim2c, varid), cpname, __LINE__ ) |
---|
446 | cattnam = 'long_name' |
---|
447 | cattval = 'Variable name' |
---|
448 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
449 | |
---|
450 | ! unitname |
---|
451 | cvar = 'unitname' |
---|
452 | WRITE(*,*) TRIM(cvar) |
---|
453 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_char, dim2c, varid), cpname, __LINE__ ) |
---|
454 | cattnam = 'long_name' |
---|
455 | cattval = 'Unit name' |
---|
456 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
457 | |
---|
458 | ! observation |
---|
459 | cvar = 'observation' |
---|
460 | WRITE(*,*) TRIM(cvar) |
---|
461 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ ) |
---|
462 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
463 | cattnam = 'long_name' |
---|
464 | cattval = 'Observation value' |
---|
465 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
466 | |
---|
467 | ! forecast |
---|
468 | cvar = 'forecast' |
---|
469 | WRITE(*,*) TRIM(cvar) |
---|
470 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim4a, varid), cpname, __LINE__ ) |
---|
471 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
472 | cattnam = 'long_name' |
---|
473 | cattval = 'Model forecast counterpart of obs. value' |
---|
474 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
475 | cattnam = 'comment' |
---|
476 | cattval = 'Model daily mean valid at noon used for calculation' |
---|
477 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
478 | |
---|
479 | ! persistence |
---|
480 | cvar = 'persistence' |
---|
481 | WRITE(*,*) TRIM(cvar) |
---|
482 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim4a, varid), cpname, __LINE__ ) |
---|
483 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
484 | cattnam = 'long_name' |
---|
485 | cattval = 'Model persistence counterpart of obs. value' |
---|
486 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
487 | cattnam = 'comment' |
---|
488 | cattval = 'Model daily mean valid at noon used for calculation' |
---|
489 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
490 | |
---|
491 | ! climatology |
---|
492 | cvar = 'climatology' |
---|
493 | WRITE(*,*) TRIM(cvar) |
---|
494 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ ) |
---|
495 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
496 | cattnam = 'long_name' |
---|
497 | cattval = 'Climatological value' |
---|
498 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
499 | cattnam = 'comment' |
---|
500 | cattval = 'Levitus monthly fields interpolated to the correct day' |
---|
501 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
502 | |
---|
503 | ! daym2 |
---|
504 | cvar = 'best_estimate' |
---|
505 | WRITE(*,*) TRIM(cvar) |
---|
506 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ ) |
---|
507 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
508 | cattnam = 'long_name' |
---|
509 | cattval = 'Best estimate' |
---|
510 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
511 | cattnam = 'comment' |
---|
512 | cattval = 'FOAM daym2 field' |
---|
513 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
514 | |
---|
515 | ! daym1 |
---|
516 | cvar = 'nrt_analysis' |
---|
517 | WRITE(*,*) TRIM(cvar) |
---|
518 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ ) |
---|
519 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
520 | cattnam = 'long_name' |
---|
521 | cattval = 'Near real time analysis' |
---|
522 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
523 | cattnam = 'comment' |
---|
524 | cattval = 'FOAM daym1 field' |
---|
525 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
526 | |
---|
527 | ! optional fields |
---|
528 | IF (TRIM(ckind) .EQ. 'SLA') THEN |
---|
529 | ! mdt |
---|
530 | cvar = 'mdt_reference' |
---|
531 | WRITE(*,*) TRIM(cvar) |
---|
532 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ ) |
---|
533 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
534 | cattnam = 'long_name' |
---|
535 | cattval = 'Mean dynamic topography' |
---|
536 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
537 | cattnam = 'comment' |
---|
538 | cattval = 'MDT reference field' |
---|
539 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
540 | |
---|
541 | ! altbias |
---|
542 | cvar = 'altimeter_bias' |
---|
543 | WRITE(*,*) TRIM(cvar) |
---|
544 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dim3a, varid), cpname, __LINE__ ) |
---|
545 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
546 | cattnam = 'long_name' |
---|
547 | cattval = 'Altimeter bias' |
---|
548 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
549 | ENDIF |
---|
550 | |
---|
551 | ! qc |
---|
552 | cvar = 'qc' |
---|
553 | WRITE(*,*) TRIM(cvar) |
---|
554 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_short, dim3a, varid), cpname, __LINE__ ) |
---|
555 | CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', NF90_FILL_SHORT), cpname, __LINE__ ) |
---|
556 | cattnam = 'long_name' |
---|
557 | cattval = 'Quality flags' |
---|
558 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
559 | cattnam = 'flag_value' |
---|
560 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), qc_flags), cpname, __LINE__ ) |
---|
561 | cattnam = 'flag_meaning' |
---|
562 | cattval = cqcval |
---|
563 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
564 | cattnam = 'comment' |
---|
565 | cattval = cqcdes |
---|
566 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
567 | |
---|
568 | ! ! juld |
---|
569 | cvar = 'juld' |
---|
570 | WRITE(*,*) TRIM(cvar) |
---|
571 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_double, dimid_o, varid), cpname, __LINE__ ) |
---|
572 | ! CALL chkerr(nf90_put_att(ncid, varid, '_FillValue', clrmdi), cpname, __LINE__ ) |
---|
573 | cattnam = 'long_name' |
---|
574 | cattval = 'Observation time in Julian days' |
---|
575 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
576 | cattnam = 'units' |
---|
577 | CALL yyyymmdd_to_ref_date('19500101', '000000', ref_date) |
---|
578 | cattval = 'Days since '//ref_date |
---|
579 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
580 | |
---|
581 | ! modeljuld |
---|
582 | cvar = 'modeljuld' |
---|
583 | WRITE(*,*) TRIM(cvar) |
---|
584 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_float, dimid_f, varid), cpname, __LINE__ ) |
---|
585 | cattnam = 'long_name' |
---|
586 | cattval = 'Model field date in Julian days' |
---|
587 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
588 | cattnam = 'units' |
---|
589 | cattval = 'Days since '//ref_date |
---|
590 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
591 | |
---|
592 | ! type |
---|
593 | cvar = 'type' |
---|
594 | WRITE(*,*) TRIM(cvar) |
---|
595 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_char, dim2d, varid), cpname, __LINE__ ) |
---|
596 | cattnam = 'long_name' |
---|
597 | cattval = 'Observation type' |
---|
598 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
599 | |
---|
600 | ! id |
---|
601 | cvar = 'id' |
---|
602 | WRITE(*,*) TRIM(cvar) |
---|
603 | CALL chkerr(nf90_def_var(ncid, TRIM(cvar), nf90_char, dim2b, varid), cpname, __LINE__ ) |
---|
604 | cattnam = 'long_name' |
---|
605 | cattval = 'Observation id' |
---|
606 | CALL chkerr(nf90_put_att(ncid, varid, TRIM(cattnam), TRIM(cattval)), cpname, __LINE__ ) |
---|
607 | |
---|
608 | ! Close netcdf file |
---|
609 | CALL chkerr(nf90_close(ncid), cpname, __LINE__ ) |
---|
610 | ELSE |
---|
611 | WRITE(*, *) cdfilename, 'already exists.' |
---|
612 | ! Close netcdf file |
---|
613 | CALL chkerr(nf90_close(ncid), cpname, __LINE__ ) |
---|
614 | END IF |
---|
615 | END SUBROUTINE ooo_wri_init |
---|
616 | |
---|
617 | |
---|
618 | END MODULE ooo_write |
---|