ooo_write.F90 29 KB

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