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