trcdia.F90 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. MODULE trcdia
  2. !!======================================================================
  3. !! *** MODULE trcdia ***
  4. !! TOP : Output of passive tracers
  5. !!======================================================================
  6. !! History : OPA ! 1995-01 (M. Levy) Original code
  7. !! - ! 1998-01 (C. Levy) NETCDF format using ioipsl interface
  8. !! - ! 1999-01 (M.A. Foujols) adapted for passive tracer
  9. !! - ! 1999-09 (M.A. Foujols) split into three parts
  10. !! NEMO 1.0 ! 2005-03 (O. Aumont, A. El Moussaoui) F90
  11. !! ! 2008-05 (C. Ethe re-organization)
  12. !!----------------------------------------------------------------------
  13. #if defined key_top
  14. !!----------------------------------------------------------------------
  15. !! 'key_top' TOP models
  16. !!----------------------------------------------------------------------
  17. !! trc_dia : main routine of output passive tracer
  18. !! trcdit_wr : outputs of concentration fields
  19. !! trcdii_wr : outputs of additional 2D/3D diagnostics
  20. !! trcdib_wr : outputs of biological fields
  21. !!----------------------------------------------------------------------
  22. USE dom_oce ! ocean space and time domain variables
  23. USE oce_trc
  24. USE trc
  25. USE par_trc
  26. USE dianam ! build name of file (routine)
  27. USE ioipsl ! I/O manager
  28. USE iom ! I/O manager
  29. USE lib_mpp ! MPP library
  30. IMPLICIT NONE
  31. PRIVATE
  32. PUBLIC trc_dia ! called by XXX module
  33. INTEGER :: nit5 !: id for tracer output file
  34. INTEGER :: ndepit5 !: id for depth mesh
  35. INTEGER :: nhorit5 !: id for horizontal mesh
  36. INTEGER :: ndimt50 !: number of ocean points in index array
  37. INTEGER :: ndimt51 !: number of ocean points in index array
  38. REAL(wp) :: zjulian !: ???? not DOCTOR !
  39. INTEGER , ALLOCATABLE, SAVE, DIMENSION (:) :: ndext50 !: integer arrays for ocean 3D index
  40. INTEGER , ALLOCATABLE, SAVE, DIMENSION (:) :: ndext51 !: integer arrays for ocean surface index
  41. INTEGER :: nitd !: id for additional array output file
  42. INTEGER :: ndepitd !: id for depth mesh
  43. INTEGER :: nhoritd !: id for horizontal mesh
  44. INTEGER :: nitb !: id. for additional array output file
  45. INTEGER :: ndepitb !: id for depth mesh
  46. INTEGER :: nhoritb !: id for horizontal mesh
  47. !! * Substitutions
  48. # include "top_substitute.h90"
  49. !!----------------------------------------------------------------------
  50. !! NEMO/TOP 3.3 , NEMO Consortium (2010)
  51. !! $Id: trcdia.F90 4292 2013-11-20 16:28:04Z cetlod $
  52. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  53. !!----------------------------------------------------------------------
  54. CONTAINS
  55. SUBROUTINE trc_dia( kt )
  56. !!---------------------------------------------------------------------
  57. !! *** ROUTINE trc_dia ***
  58. !!
  59. !! ** Purpose : output passive tracers fields
  60. !!---------------------------------------------------------------------
  61. INTEGER, INTENT(in) :: kt ! ocean time-step
  62. !
  63. INTEGER :: ierr ! local integer
  64. !!---------------------------------------------------------------------
  65. !
  66. IF( kt == nittrc000 ) THEN
  67. ALLOCATE( ndext50(jpij*jpk), ndext51(jpij), STAT=ierr )
  68. IF( ierr > 0 ) THEN
  69. CALL ctl_stop( 'STOP', 'trc_diat: unable to allocate arrays' ) ; RETURN
  70. ENDIF
  71. ENDIF
  72. !
  73. IF( .NOT.lk_iomput ) THEN
  74. CALL trcdit_wr( kt ) ! outputs for tracer concentration
  75. IF( ln_diatrc ) CALL trcdii_wr( kt ) ! outputs for additional arrays
  76. IF( ln_diabio ) CALL trcdib_wr( kt ) ! outputs for biological trends
  77. ENDIF
  78. !
  79. END SUBROUTINE trc_dia
  80. SUBROUTINE trcdit_wr( kt )
  81. !!----------------------------------------------------------------------
  82. !! *** ROUTINE trcdit_wr ***
  83. !!
  84. !! ** Purpose : Standard output of passive tracer : concentration fields
  85. !!
  86. !! ** Method : At the beginning of the first time step (nittrc000), define all
  87. !! the NETCDF files and fields for concentration of passive tracer
  88. !!
  89. !! At each time step call histdef to compute the mean if necessary
  90. !! Each nwritetrc time step, output the instantaneous or mean fields
  91. !!
  92. !!----------------------------------------------------------------------
  93. INTEGER, INTENT(in) :: kt ! ocean time-step
  94. !
  95. INTEGER :: jn
  96. LOGICAL :: ll_print = .FALSE.
  97. CHARACTER (len=40) :: clhstnam, clop
  98. INTEGER :: inum = 11 ! temporary logical unit
  99. CHARACTER (len=20) :: cltra, cltrau
  100. CHARACTER (len=80) :: cltral
  101. REAL(wp) :: zsto, zout, zdt
  102. INTEGER :: iimi, iima, ijmi, ijma, ipk, it, itmod, iiter
  103. !!----------------------------------------------------------------------
  104. ! Initialisation
  105. ! --------------
  106. ! local variable for debugging
  107. ll_print = .FALSE. ! change it to true for more control print
  108. ll_print = ll_print .AND. lwp
  109. ! Define frequency of output and means
  110. zdt = rdt
  111. IF( ln_mskland ) THEN ; clop = "only(x)" ! put 1.e+20 on land (very expensive!!)
  112. ELSE ; clop = "x" ! no use of the mask value (require less cpu time)
  113. ENDIF
  114. # if defined key_diainstant
  115. zsto = nn_writetrc * rdt
  116. clop = "inst("//TRIM(clop)//")"
  117. # else
  118. zsto = zdt
  119. clop = "ave("//TRIM(clop)//")"
  120. # endif
  121. zout = nn_writetrc * zdt
  122. ! Define indices of the horizontal output zoom and vertical limit storage
  123. iimi = 1 ; iima = jpi
  124. ijmi = 1 ; ijma = jpj
  125. ipk = jpk
  126. ! define time axis
  127. itmod = kt - nittrc000 + 1
  128. it = kt
  129. iiter = ( nittrc000 - 1 ) / nn_dttrc
  130. ! Define NETCDF files and fields at beginning of first time step
  131. ! --------------------------------------------------------------
  132. IF(ll_print)WRITE(numout,*)'trcdit_wr kt=',kt
  133. IF( kt == nittrc000 ) THEN
  134. IF(lwp) THEN ! control print
  135. WRITE(numout,*)
  136. WRITE(numout,*) ' frequency of outputs for passive tracers nn_writetrc = ', nn_writetrc
  137. DO jn = 1, jptra
  138. IF( ln_trc_wri(jn) ) WRITE(numout,*) ' ouput tracer nb : ', jn, ' short name : ', ctrcnm(jn)
  139. END DO
  140. WRITE(numout,*) ' '
  141. ENDIF
  142. ! Compute julian date from starting date of the run
  143. CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )
  144. zjulian = zjulian - adatrj ! set calendar origin to the beginning of the experiment
  145. IF(lwp)WRITE(numout,*)' '
  146. IF(lwp)WRITE(numout,*)' Date 0 used :', nittrc000 &
  147. & ,' YEAR ', nyear, ' MONTH ', nmonth, ' DAY ', nday &
  148. & ,'Julian day : ', zjulian
  149. IF(lwp) WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma, &
  150. & ' limit storage in depth = ', ipk
  151. IF( lk_offline .AND. lwp ) THEN
  152. CALL dia_nam( clhstnam, nn_writetrc,' ' )
  153. CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, narea )
  154. WRITE(inum,*) clhstnam
  155. CLOSE(inum)
  156. ENDIF
  157. ! Define the NETCDF files for passive tracer concentration
  158. CALL dia_nam( clhstnam, nn_writetrc, 'ptrc_T' )
  159. IF(lwp)WRITE(numout,*)" Name of NETCDF file ", clhstnam
  160. ! Horizontal grid : glamt and gphit
  161. CALL histbeg( clhstnam, jpi, glamt, jpj, gphit, &
  162. & iimi, iima-iimi+1, ijmi, ijma-ijmi+1, &
  163. & iiter, zjulian, zdt, nhorit5, nit5 , domain_id=nidom, snc4chunks=snc4set)
  164. ! Vertical grid for tracer : gdept
  165. CALL histvert( nit5, 'deptht', 'Vertical T levels', 'm', ipk, gdept_1d, ndepit5)
  166. ! Index of ocean points in 3D and 2D (surface)
  167. CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndext50, ndimt50 )
  168. CALL wheneq( jpi*jpj , tmask, 1, 1., ndext51, ndimt51 )
  169. ! Declare all the output fields as NETCDF variables
  170. DO jn = 1, jptra
  171. IF( ln_trc_wri(jn) ) THEN
  172. cltra = TRIM( ctrcnm(jn) ) ! short title for tracer
  173. cltral = TRIM( ctrcln(jn) ) ! long title for tracer
  174. cltrau = TRIM( ctrcun(jn) ) ! UNIT for tracer
  175. CALL histdef( nit5, cltra, cltral, cltrau, jpi, jpj, nhorit5, &
  176. & ipk, 1, ipk, ndepit5, 32, clop, zsto, zout )
  177. ENDIF
  178. END DO
  179. ! end netcdf files header
  180. CALL histend( nit5, snc4set )
  181. IF(lwp) WRITE(numout,*)
  182. IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdit_wr'
  183. IF( ll_print ) CALL FLUSH(numout )
  184. ENDIF
  185. ! Start writing the tracer concentrations
  186. ! ---------------------------------------
  187. IF( lwp .AND. MOD( itmod, nn_writetrc ) == 0 ) THEN
  188. WRITE(numout,*) 'trcdit_wr : write NetCDF passive tracer concentrations at ', kt, 'time-step'
  189. WRITE(numout,*) '~~~~~~~~~ '
  190. ENDIF
  191. DO jn = 1, jptra
  192. cltra = TRIM( ctrcnm(jn) ) ! short title for tracer
  193. IF( ln_trc_wri(jn) ) CALL histwrite( nit5, cltra, it, trn(:,:,:,jn), ndimt50, ndext50 )
  194. END DO
  195. ! close the file
  196. ! --------------
  197. IF( kt == nitend ) CALL histclo( nit5 )
  198. !
  199. END SUBROUTINE trcdit_wr
  200. SUBROUTINE trcdii_wr( kt )
  201. !!----------------------------------------------------------------------
  202. !! *** ROUTINE trcdii_wr ***
  203. !!
  204. !! ** Purpose : output of passive tracer : additional 2D and 3D arrays
  205. !!
  206. !! ** Method : At the beginning of the first time step (nittrc000), define all
  207. !! the NETCDF files and fields for concentration of passive tracer
  208. !!
  209. !! At each time step call histdef to compute the mean if necessary
  210. !! Each nn_writedia time step, output the instantaneous or mean fields
  211. !!
  212. !!----------------------------------------------------------------------
  213. INTEGER, INTENT(in) :: kt ! ocean time-step
  214. !!
  215. LOGICAL :: ll_print = .FALSE.
  216. CHARACTER (len=40) :: clhstnam, clop
  217. CHARACTER (len=20) :: cltra, cltrau
  218. CHARACTER (len=80) :: cltral
  219. INTEGER :: jl
  220. INTEGER :: iimi, iima, ijmi, ijma, ipk, it, itmod, iiter
  221. REAL(wp) :: zsto, zout, zdt
  222. !!----------------------------------------------------------------------
  223. ! Initialisation
  224. ! --------------
  225. ! local variable for debugging
  226. ll_print = .FALSE.
  227. ll_print = ll_print .AND. lwp
  228. !
  229. ! Define frequency of output and means
  230. zdt = rdt
  231. IF( ln_mskland ) THEN ; clop = "only(x)" ! put 1.e+20 on land (very expensive!!)
  232. ELSE ; clop = "x" ! no use of the mask value (require less cpu time)
  233. ENDIF
  234. # if defined key_diainstant
  235. zsto = nn_writedia * zdt
  236. clop = "inst("//TRIM(clop)//")"
  237. # else
  238. zsto = zdt
  239. clop = "ave("//TRIM(clop)//")"
  240. # endif
  241. zout = nn_writedia * zdt
  242. ! Define indices of the horizontal output zoom and vertical limit storage
  243. iimi = 1 ; iima = jpi
  244. ijmi = 1 ; ijma = jpj
  245. ipk = jpk
  246. ! define time axis
  247. itmod = kt - nittrc000 + 1
  248. it = kt
  249. iiter = ( nittrc000 - 1 ) / nn_dttrc
  250. ! 1. Define NETCDF files and fields at beginning of first time step
  251. ! -----------------------------------------------------------------
  252. IF( ll_print ) WRITE(numout,*) 'trcdii_wr kt=', kt
  253. IF( kt == nittrc000 ) THEN
  254. ! Define the NETCDF files for additional arrays : 2D or 3D
  255. ! Define the T grid file for tracer auxiliary files
  256. CALL dia_nam( clhstnam, nn_writedia, 'diad_T' )
  257. IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
  258. ! Define a netcdf FILE for 2d and 3d arrays
  259. CALL histbeg( clhstnam, jpi, glamt, jpj, gphit, &
  260. & iimi, iima-iimi+1, ijmi, ijma-ijmi+1, &
  261. & iiter, zjulian, zdt, nhoritd, nitd , domain_id=nidom, snc4chunks=snc4set )
  262. ! Vertical grid for 2d and 3d arrays
  263. CALL histvert( nitd, 'deptht', 'Vertical T levels','m', ipk, gdept_1d, ndepitd)
  264. ! Declare all the output fields as NETCDF variables
  265. ! more 3D horizontal arrays
  266. DO jl = 1, jpdia3d
  267. cltra = TRIM( ctrc3d(jl) ) ! short title for 3D diagnostic
  268. cltral = TRIM( ctrc3l(jl) ) ! long title for 3D diagnostic
  269. cltrau = TRIM( ctrc3u(jl) ) ! UNIT for 3D diagnostic
  270. CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd, &
  271. & ipk, 1, ipk, ndepitd, 32, clop, zsto, zout )
  272. END DO
  273. ! more 2D horizontal arrays
  274. DO jl = 1, jpdia2d
  275. cltra = TRIM( ctrc2d(jl) ) ! short title for 2D diagnostic
  276. cltral = TRIM( ctrc2l(jl) ) ! long title for 2D diagnostic
  277. cltrau = TRIM( ctrc2u(jl) ) ! UNIT for 2D diagnostic
  278. CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd, &
  279. & 1, 1, 1, -99, 32, clop, zsto, zout )
  280. END DO
  281. ! TODO: more 2D vertical sections arrays : I or J indice fixed
  282. ! CLOSE netcdf Files
  283. CALL histend( nitd, snc4set )
  284. IF(lwp) WRITE(numout,*)
  285. IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdii_wr'
  286. IF( ll_print ) CALL FLUSH(numout )
  287. !
  288. ENDIF
  289. ! 2. Start writing data
  290. ! ---------------------
  291. IF( lwp .AND. MOD( itmod, nn_writedia ) == 0 ) THEN
  292. WRITE(numout,*) 'trcdii_wr : write NetCDF additional arrays at ', kt, 'time-step'
  293. WRITE(numout,*) '~~~~~~ '
  294. ENDIF
  295. ! more 3D horizontal arrays
  296. DO jl = 1, jpdia3d
  297. cltra = TRIM( ctrc3d(jl) ) ! short title for 3D diagnostic
  298. CALL histwrite( nitd, cltra, it, trc3d(:,:,:,jl), ndimt50 ,ndext50)
  299. END DO
  300. ! more 2D horizontal arrays
  301. DO jl = 1, jpdia2d
  302. cltra = TRIM( ctrc2d(jl) ) ! short title for 2D diagnostic
  303. CALL histwrite(nitd, cltra, it, trc2d(:,:,jl), ndimt51 ,ndext51)
  304. END DO
  305. ! Closing all files
  306. ! -----------------
  307. IF( kt == nitend ) CALL histclo(nitd)
  308. !
  309. END SUBROUTINE trcdii_wr
  310. SUBROUTINE trcdib_wr( kt )
  311. !!----------------------------------------------------------------------
  312. !! *** ROUTINE trcdib_wr ***
  313. !!
  314. !! ** Purpose : output of passive tracer : biological fields
  315. !!
  316. !! ** Method : At the beginning of the first time step (nittrc000), define all
  317. !! the NETCDF files and fields for concentration of passive tracer
  318. !!
  319. !! At each time step call histdef to compute the mean if necessary
  320. !! Each nn_writebio time step, output the instantaneous or mean fields
  321. !!
  322. !!----------------------------------------------------------------------
  323. INTEGER, INTENT( in ) :: kt ! ocean time-step
  324. !!
  325. LOGICAL :: ll_print = .FALSE.
  326. CHARACTER (len=40) :: clhstnam, clop
  327. CHARACTER (len=20) :: cltra, cltrau
  328. CHARACTER (len=80) :: cltral
  329. INTEGER :: ji, jj, jk, jl
  330. INTEGER :: iimi, iima, ijmi, ijma, ipk, it, itmod, iiter
  331. REAL(wp) :: zsto, zout, zdt
  332. !!----------------------------------------------------------------------
  333. ! Initialisation
  334. ! --------------
  335. ! local variable for debugging
  336. ll_print = .FALSE.
  337. ll_print = ll_print .AND. lwp
  338. ! Define frequency of output and means
  339. zdt = rdt
  340. IF( ln_mskland ) THEN ; clop = "only(x)" ! put 1.e+20 on land (very expensive!!)
  341. ELSE ; clop = "x" ! no use of the mask value (require less cpu time)
  342. ENDIF
  343. # if defined key_diainstant
  344. zsto = nn_writebio * zdt
  345. clop = "inst("//TRIM(clop)//")"
  346. # else
  347. zsto = zdt
  348. clop = "ave("//TRIM(clop)//")"
  349. # endif
  350. zout = nn_writebio * zdt
  351. ! Define indices of the horizontal output zoom and vertical limit storage
  352. iimi = 1 ; iima = jpi
  353. ijmi = 1 ; ijma = jpj
  354. ipk = jpk
  355. ! define time axis
  356. itmod = kt - nittrc000 + 1
  357. it = kt
  358. iiter = ( nittrc000 - 1 ) / nn_dttrc
  359. ! Define NETCDF files and fields at beginning of first time step
  360. ! --------------------------------------------------------------
  361. IF(ll_print) WRITE(numout,*)'trcdib_wr kt=',kt
  362. IF( kt == nittrc000 ) THEN
  363. ! Define the NETCDF files for biological trends
  364. CALL dia_nam(clhstnam,nn_writebio,'biolog')
  365. IF(lwp)WRITE(numout,*) " Name of NETCDF file for biological trends ", clhstnam
  366. ! Horizontal grid : glamt and gphit
  367. CALL histbeg( clhstnam, jpi, glamt, jpj, gphit, &
  368. & iimi, iima-iimi+1, ijmi, ijma-ijmi+1, &
  369. & iiter, zjulian, zdt, nhoritb, nitb , domain_id=nidom, snc4chunks=snc4set )
  370. ! Vertical grid for biological trends
  371. CALL histvert(nitb, 'deptht', 'Vertical T levels', 'm', ipk, gdept_1d, ndepitb)
  372. ! Declare all the output fields as NETCDF variables
  373. ! biological trends
  374. DO jl = 1, jpdiabio
  375. cltra = TRIM( ctrbio(jl) ) ! short title for biological diagnostic
  376. cltral = TRIM( ctrbil(jl) ) ! long title for biological diagnostic
  377. cltrau = TRIM( ctrbiu(jl) ) ! UNIT for biological diagnostic
  378. CALL histdef( nitb, cltra, cltral, cltrau, jpi, jpj, nhoritb, &
  379. & ipk, 1, ipk, ndepitb, 32, clop, zsto, zout)
  380. END DO
  381. ! CLOSE netcdf Files
  382. CALL histend( nitb, snc4set )
  383. IF(lwp) WRITE(numout,*)
  384. IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdib_wr'
  385. IF(ll_print) CALL FLUSH(numout )
  386. !
  387. ENDIF
  388. ! Start writing data
  389. ! ------------------
  390. ! biological trends
  391. IF( lwp .AND. MOD( itmod, nn_writebio ) == 0 ) THEN
  392. WRITE(numout,*) 'trcdit_wr : write NetCDF biological trends at ', kt, 'time-step'
  393. WRITE(numout,*) '~~~~~~ '
  394. ENDIF
  395. DO jl = 1, jpdiabio
  396. cltra = TRIM( ctrbio(jl) ) ! short title for biological diagnostic
  397. CALL histwrite(nitb, cltra, it, trbio(:,:,:,jl), ndimt50,ndext50)
  398. END DO
  399. ! Closing all files
  400. ! -----------------
  401. IF( kt == nitend ) CALL histclo( nitb )
  402. !
  403. END SUBROUTINE trcdib_wr
  404. #else
  405. !!----------------------------------------------------------------------
  406. !! Dummy module : No passive tracer
  407. !!----------------------------------------------------------------------
  408. CONTAINS
  409. SUBROUTINE trc_dia( kt ) ! Empty routine
  410. INTEGER, INTENT(in) :: kt
  411. END SUBROUTINE trc_dia
  412. #endif
  413. !!======================================================================
  414. END MODULE trcdia