trdmxl_trc.F90 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  1. MODULE trdmxl_trc
  2. !!======================================================================
  3. !! *** MODULE trdmxl_trc ***
  4. !! Ocean diagnostics: mixed layer passive tracer trends
  5. !!======================================================================
  6. !! History : 9.0 ! 06-08 (C. Deltel) Original code (from trdmxl.F90)
  7. !! ! 07-04 (C. Deltel) Bug fix : add trcrad trends
  8. !! ! 07-06 (C. Deltel) key_gyre : do not call lbc_lnk
  9. !!----------------------------------------------------------------------
  10. #if defined key_top && ( defined key_trdmxl_trc || defined key_esopa )
  11. !!----------------------------------------------------------------------
  12. !! 'key_trdmxl_trc' mixed layer trend diagnostics
  13. !!----------------------------------------------------------------------
  14. !! trd_mxl_trc : passive tracer cumulated trends averaged over ML
  15. !! trd_mxl_trc_zint : passive tracer trends vertical integration
  16. !! trd_mxl_trc_init : initialization step
  17. !!----------------------------------------------------------------------
  18. USE trc ! tracer definitions (trn, trb, tra, etc.)
  19. USE trc_oce, ONLY : nn_dttrc ! frequency of step on passive tracers
  20. USE dom_oce ! domain definition
  21. USE zdfmxl , ONLY : nmln ! number of level in the mixed layer
  22. USE zdf_oce , ONLY : avt ! vert. diffusivity coef. at w-point for temp
  23. # if defined key_zdfddm
  24. USE zdfddm , ONLY : avs ! salinity vertical diffusivity coeff. at w-point
  25. # endif
  26. USE trcnam_trp ! passive tracers transport namelist variables
  27. USE trdtrc_oce ! definition of main arrays used for trends computations
  28. USE in_out_manager ! I/O manager
  29. USE dianam ! build the name of file (routine)
  30. USE ldfslp ! iso-neutral slopes
  31. USE ioipsl ! NetCDF library
  32. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  33. USE lib_mpp ! MPP library
  34. USE trdmxl_trc_rst ! restart for diagnosing the ML trends
  35. USE prtctl ! print control
  36. USE sms_pisces ! PISCES bio-model
  37. USE wrk_nemo ! Memory allocation
  38. IMPLICIT NONE
  39. PRIVATE
  40. PUBLIC trd_mxl_trc
  41. PUBLIC trd_mxl_trc_alloc
  42. PUBLIC trd_mxl_bio
  43. PUBLIC trd_mxl_trc_init
  44. PUBLIC trd_mxl_trc_zint
  45. PUBLIC trd_mxl_bio_zint
  46. CHARACTER (LEN=40) :: clhstnam ! name of the trends NetCDF file
  47. INTEGER :: nmoymltrd
  48. INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) :: ndextrd1
  49. INTEGER, DIMENSION(jptra) :: nidtrd, nh_t
  50. INTEGER :: ndimtrd1
  51. INTEGER, SAVE :: ionce, icount
  52. #if defined key_pisces_reduced
  53. INTEGER :: nidtrdbio, nh_tb
  54. INTEGER, SAVE :: ioncebio, icountbio
  55. INTEGER, SAVE :: nmoymltrdbio
  56. #endif
  57. LOGICAL :: llwarn = .TRUE. ! this should always be .TRUE.
  58. LOGICAL :: lldebug = .TRUE.
  59. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) :: ztmltrd2 !
  60. #if defined key_pisces_reduced
  61. REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: ztmltrdbio2 ! only needed for mean diagnostics in trd_mxl_bio()
  62. #endif
  63. !! * Substitutions
  64. # include "top_substitute.h90"
  65. # include "zdfddm_substitute.h90"
  66. !!----------------------------------------------------------------------
  67. !! NEMO/TOP 3.3 , NEMO Consortium (2010)
  68. !! $Id: trdmxl_trc.F90 2355 2015-05-20 07:11:50Z ufla $
  69. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  70. !!----------------------------------------------------------------------
  71. CONTAINS
  72. INTEGER FUNCTION trd_mxl_trc_alloc()
  73. !!----------------------------------------------------------------------
  74. !! *** ROUTINE trd_mxl_trc_alloc ***
  75. !!----------------------------------------------------------------------
  76. ALLOCATE( ztmltrd2(jpi,jpj,jpltrd_trc,jptra) , &
  77. #if defined key_pisces_reduced
  78. & ztmltrdbio2(jpi,jpj,jpdiabio) , &
  79. #endif
  80. & ndextrd1(jpi*jpj) , STAT=trd_mxl_trc_alloc)
  81. !
  82. IF( lk_mpp ) CALL mpp_sum ( trd_mxl_trc_alloc )
  83. IF( trd_mxl_trc_alloc /=0 ) CALL ctl_warn('trd_mxl_trc_alloc: failed to allocate arrays')
  84. !
  85. END FUNCTION trd_mxl_trc_alloc
  86. SUBROUTINE trd_mxl_trc_zint( ptrc_trdmxl, ktrd, ctype, kjn )
  87. !!----------------------------------------------------------------------
  88. !! *** ROUTINE trd_mxl_trc_zint ***
  89. !!
  90. !! ** Purpose : Compute the vertical average of the 3D fields given as arguments
  91. !! to the subroutine. This vertical average is performed from ocean
  92. !! surface down to a chosen control surface.
  93. !!
  94. !! ** Method/usage :
  95. !! The control surface can be either a mixed layer depth (time varying)
  96. !! or a fixed surface (jk level or bowl).
  97. !! Choose control surface with nctls_trc in namelist NAMTRD :
  98. !! nctls_trc = -2 : use isopycnal surface
  99. !! nctls_trc = -1 : use euphotic layer with light criterion
  100. !! nctls_trc = 0 : use mixed layer with density criterion
  101. !! nctls_trc = 1 : read index from file 'ctlsurf_idx'
  102. !! nctls_trc > 1 : use fixed level surface jk = nctls_trc
  103. !! Note: in the remainder of the routine, the volume between the
  104. !! surface and the control surface is called "mixed-layer"
  105. !!----------------------------------------------------------------------
  106. !!
  107. INTEGER, INTENT( in ) :: ktrd, kjn ! ocean trend index and passive tracer rank
  108. CHARACTER(len=2), INTENT( in ) :: ctype ! surface/bottom (2D) or interior (3D) physics
  109. REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) :: ptrc_trdmxl ! passive tracer trend
  110. !
  111. INTEGER :: ji, jj, jk, isum
  112. REAL(wp), POINTER, DIMENSION(:,:) :: zvlmsk
  113. !!----------------------------------------------------------------------
  114. CALL wrk_alloc( jpi, jpj, zvlmsk )
  115. ! I. Definition of control surface and integration weights
  116. ! --------------------------------------------------------
  117. ONCE_PER_TIME_STEP : IF( icount == 1 ) THEN
  118. !
  119. tmltrd_trc(:,:,:,:) = 0.e0 ! <<< reset trend arrays to zero
  120. ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
  121. SELECT CASE ( nn_ctls_trc ) ! choice of the control surface
  122. CASE ( -2 ) ; STOP 'trdmxl_trc : not ready ' ! -> isopycnal surface (see ???)
  123. #if defined key_pisces || defined key_pisces_reduced
  124. CASE ( -1 ) ; nmld_trc(:,:) = neln(:,:) ! -> euphotic layer with light criterion
  125. #endif
  126. CASE ( 0 ) ; nmld_trc(:,:) = nmln(:,:) ! -> ML with density criterion (see zdfmxl)
  127. CASE ( 1 ) ; nmld_trc(:,:) = nbol_trc(:,:) ! -> read index from file
  128. CASE ( 2: ) ; nn_ctls_trc = MIN( nn_ctls_trc, jpktrd_trc - 1 )
  129. nmld_trc(:,:) = nn_ctls_trc + 1 ! -> model level
  130. END SELECT
  131. ! ... Compute ndextrd1 and ndimtrd1 ??? role de jpktrd_trc
  132. IF( ionce == 1 ) THEN
  133. !
  134. isum = 0 ; zvlmsk(:,:) = 0.e0
  135. IF( jpktrd_trc < jpk ) THEN ! description ???
  136. DO jj = 1, jpj
  137. DO ji = 1, jpi
  138. IF( nmld_trc(ji,jj) <= jpktrd_trc ) THEN
  139. zvlmsk(ji,jj) = tmask(ji,jj,1)
  140. ELSE
  141. isum = isum + 1
  142. zvlmsk(ji,jj) = 0.e0
  143. ENDIF
  144. END DO
  145. END DO
  146. ENDIF
  147. IF( isum > 0 ) THEN ! index of ocean points (2D only)
  148. WRITE(numout,*)' tmltrd_trc : Number of invalid points nmld_trc > jpktrd', isum
  149. CALL wheneq( jpi*jpj, zvlmsk(:,:) , 1, 1., ndextrd1, ndimtrd1 )
  150. ELSE
  151. CALL wheneq( jpi*jpj, tmask(:,:,1), 1, 1., ndextrd1, ndimtrd1 )
  152. ENDIF
  153. ionce = 0 ! no more pass here
  154. !
  155. ENDIF ! ionce == 1
  156. ! ... Weights for vertical averaging
  157. wkx_trc(:,:,:) = 0.e0
  158. DO jk = 1, jpktrd_trc ! initialize wkx_trc with vertical scale factor in mixed-layer
  159. DO jj = 1, jpj
  160. DO ji = 1, jpi
  161. IF( jk - nmld_trc(ji,jj) < 0 ) wkx_trc(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
  162. END DO
  163. END DO
  164. END DO
  165. rmld_trc(:,:) = 0.e0
  166. DO jk = 1, jpktrd_trc ! compute mixed-layer depth : rmld_trc
  167. rmld_trc(:,:) = rmld_trc(:,:) + wkx_trc(:,:,jk)
  168. END DO
  169. DO jk = 1, jpktrd_trc ! compute integration weights
  170. wkx_trc(:,:,jk) = wkx_trc(:,:,jk) / MAX( 1., rmld_trc(:,:) )
  171. END DO
  172. icount = 0 ! <<< flag = off : control surface & integr. weights
  173. ! ! computed only once per time step
  174. ENDIF ONCE_PER_TIME_STEP
  175. ! II. Vertical integration of trends in the mixed-layer
  176. ! -----------------------------------------------------
  177. SELECT CASE ( ctype )
  178. CASE ( '3D' ) ! mean passive tracer trends in the mixed-layer
  179. DO jk = 1, jpktrd_trc
  180. tmltrd_trc(:,:,ktrd,kjn) = tmltrd_trc(:,:,ktrd,kjn) + ptrc_trdmxl(:,:,jk) * wkx_trc(:,:,jk)
  181. END DO
  182. CASE ( '2D' ) ! forcing at upper boundary of the mixed-layer
  183. tmltrd_trc(:,:,ktrd,kjn) = tmltrd_trc(:,:,ktrd,kjn) + ptrc_trdmxl(:,:,1) * wkx_trc(:,:,1) ! non penetrative
  184. END SELECT
  185. !
  186. CALL wrk_dealloc( jpi, jpj, zvlmsk )
  187. !
  188. END SUBROUTINE trd_mxl_trc_zint
  189. SUBROUTINE trd_mxl_bio_zint( ptrc_trdmxl, ktrd )
  190. !!----------------------------------------------------------------------
  191. !! *** ROUTINE trd_mxl_bio_zint ***
  192. !!
  193. !! ** Purpose : Compute the vertical average of the 3D fields given as arguments
  194. !! to the subroutine. This vertical average is performed from ocean
  195. !! surface down to a chosen control surface.
  196. !!
  197. !! ** Method/usage :
  198. !! The control surface can be either a mixed layer depth (time varying)
  199. !! or a fixed surface (jk level or bowl).
  200. !! Choose control surface with nctls in namelist NAMTRD :
  201. !! nctls_trc = 0 : use mixed layer with density criterion
  202. !! nctls_trc = 1 : read index from file 'ctlsurf_idx'
  203. !! nctls_trc > 1 : use fixed level surface jk = nctls_trc
  204. !! Note: in the remainder of the routine, the volume between the
  205. !! surface and the control surface is called "mixed-layer"
  206. !!----------------------------------------------------------------------
  207. !!
  208. INTEGER , INTENT(in) :: ktrd ! bio trend index
  209. REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in) :: ptrc_trdmxl ! passive trc trend
  210. #if defined key_pisces_reduced
  211. !
  212. INTEGER :: ji, jj, jk, isum
  213. REAL(wp), POINTER, DIMENSION(:,:) :: zvlmsk
  214. !!----------------------------------------------------------------------
  215. CALL wrk_alloc( jpi, jpj, zvlmsk )
  216. ! I. Definition of control surface and integration weights
  217. ! --------------------------------------------------------
  218. ! ==> only once per time step <==
  219. IF( icountbio == 1 ) THEN
  220. !
  221. tmltrd_bio(:,:,:) = 0.e0 ! <<< reset trend arrays to zero
  222. ! ... Set nmld(ji,jj) = index of first T point below control surf. or outside mixed-layer
  223. SELECT CASE ( nn_ctls_trc ) ! choice of the control surface
  224. CASE ( -2 ) ; STOP 'trdmxl_trc : not ready ' ! -> isopycnal surface (see ???)
  225. CASE ( -1 ) ; nmld_trc(:,:) = neln(:,:) ! -> euphotic layer with light criterion
  226. CASE ( 0 ) ; nmld_trc(:,:) = nmln(:,:) ! -> ML with density criterion (see zdfmxl)
  227. CASE ( 1 ) ; nmld_trc(:,:) = nbol_trc(:,:) ! -> read index from file
  228. CASE ( 2: ) ; nn_ctls_trc = MIN( nn_ctls_trc, jpktrd_trc - 1 )
  229. nmld_trc(:,:) = nn_ctls_trc + 1 ! -> model level
  230. END SELECT
  231. ! ... Compute ndextrd1 and ndimtrd1 only once
  232. IF( ioncebio == 1 ) THEN
  233. !
  234. ! Check of validity : nmld_trc(ji,jj) <= jpktrd_trc
  235. isum = 0
  236. zvlmsk(:,:) = 0.e0
  237. IF( jpktrd_trc < jpk ) THEN
  238. DO jj = 1, jpj
  239. DO ji = 1, jpi
  240. IF( nmld_trc(ji,jj) <= jpktrd_trc ) THEN
  241. zvlmsk(ji,jj) = tmask(ji,jj,1)
  242. ELSE
  243. isum = isum + 1
  244. zvlmsk(ji,jj) = 0.
  245. END IF
  246. END DO
  247. END DO
  248. END IF
  249. ! Index of ocean points (2D only)
  250. IF( isum > 0 ) THEN
  251. WRITE(numout,*)' tmltrd_trc : Number of invalid points nmld_trc > jpktrd', isum
  252. CALL wheneq( jpi*jpj, zvlmsk(:,:) , 1, 1., ndextrd1, ndimtrd1 )
  253. ELSE
  254. CALL wheneq( jpi*jpj, tmask(:,:,1), 1, 1., ndextrd1, ndimtrd1 )
  255. END IF
  256. ioncebio = 0 ! no more pass here
  257. !
  258. END IF ! ( ioncebio == 1 )
  259. ! ... Weights for vertical averaging
  260. wkx_trc(:,:,:) = 0.e0
  261. DO jk = 1, jpktrd_trc ! initialize wkx_trc with vertical scale factor in mixed-layer
  262. DO jj = 1,jpj
  263. DO ji = 1,jpi
  264. IF( jk - nmld_trc(ji,jj) < 0. ) wkx_trc(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
  265. END DO
  266. END DO
  267. END DO
  268. rmld_trc(:,:) = 0.
  269. DO jk = 1, jpktrd_trc ! compute mixed-layer depth : rmld_trc
  270. rmld_trc(:,:) = rmld_trc(:,:) + wkx_trc(:,:,jk)
  271. END DO
  272. DO jk = 1, jpktrd_trc ! compute integration weights
  273. wkx_trc(:,:,jk) = wkx_trc(:,:,jk) / MAX( 1., rmld_trc(:,:) )
  274. END DO
  275. icountbio = 0 ! <<< flag = off : control surface & integr. weights
  276. ! ! computed only once per time step
  277. END IF ! ( icountbio == 1 )
  278. ! II. Vertical integration of trends in the mixed-layer
  279. ! -----------------------------------------------------
  280. DO jk = 1, jpktrd_trc
  281. tmltrd_bio(:,:,ktrd) = tmltrd_bio(:,:,ktrd) + ptrc_trdmxl(:,:,jk) * wkx_trc(:,:,jk)
  282. END DO
  283. CALL wrk_dealloc( jpi, jpj, zvlmsk )
  284. #endif
  285. !
  286. END SUBROUTINE trd_mxl_bio_zint
  287. SUBROUTINE trd_mxl_trc( kt )
  288. !!----------------------------------------------------------------------
  289. !! *** ROUTINE trd_mxl_trc ***
  290. !!
  291. !! ** Purpose : Compute and cumulate the mixed layer trends over an analysis
  292. !! period, and write NetCDF (or dimg) outputs.
  293. !!
  294. !! ** Method/usage :
  295. !! The stored trends can be chosen twofold (according to the ln_trdmxl_trc_instant
  296. !! logical namelist variable) :
  297. !! 1) to explain the difference between initial and final
  298. !! mixed-layer T & S (where initial and final relate to the
  299. !! current analysis window, defined by ntrc_trc in the namelist)
  300. !! 2) to explain the difference between the current and previous
  301. !! TIME-AVERAGED mixed-layer T & S (where time-averaging is
  302. !! performed over each analysis window).
  303. !!
  304. !! ** Consistency check :
  305. !! If the control surface is fixed ( nctls_trc > 1 ), the residual term (dh/dt
  306. !! entrainment) should be zero, at machine accuracy. Note that in the case
  307. !! of time-averaged mixed-layer fields, this residual WILL NOT BE ZERO
  308. !! over the first two analysis windows (except if restart).
  309. !! N.B. For ORCA2_LIM, use e.g. ntrc_trc=5, rn_ucf_trc=1., nctls_trc=8
  310. !! for checking residuals.
  311. !! On a NEC-SX5 computer, this typically leads to:
  312. !! O(1.e-20) temp. residuals (tml_res) when ln_trdmxl_trc_instant=.false.
  313. !! O(1.e-21) temp. residuals (tml_res) when ln_trdmxl_trc_instant=.true.
  314. !!
  315. !! ** Action :
  316. !! At each time step, mixed-layer averaged trends are stored in the
  317. !! tmltrd(:,:,jpmxl_xxx) array (see trdmxl_oce.F90 for definitions of jpmxl_xxx).
  318. !! This array is known when trd_mld is called, at the end of the stp subroutine,
  319. !! except for the purely vertical K_z diffusion term, which is embedded in the
  320. !! lateral diffusion trend.
  321. !!
  322. !! In I), this K_z term is diagnosed and stored, thus its contribution is removed
  323. !! from the lateral diffusion trend.
  324. !! In II), the instantaneous mixed-layer T & S are computed, and misc. cumulative
  325. !! arrays are updated.
  326. !! In III), called only once per analysis window, we compute the total trends,
  327. !! along with the residuals and the Asselin correction terms.
  328. !! In IV), the appropriate trends are written in the trends NetCDF file.
  329. !!
  330. !! References :
  331. !! - Vialard & al.
  332. !! - See NEMO documentation (in preparation)
  333. !!----------------------------------------------------------------------
  334. !
  335. INTEGER, INTENT(in) :: kt ! ocean time-step index
  336. !
  337. INTEGER :: ji, jj, jk, jl, ik, it, itmod, jn
  338. REAL(wp) :: zavt, zfn, zfn2
  339. !
  340. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmltot ! d(trc)/dt over the anlysis window (incl. Asselin)
  341. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmlres ! residual = dh/dt entrainment term
  342. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmlatf ! for storage only
  343. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmlrad ! for storage only (for trb<0 corr in trcrad)
  344. !
  345. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmltot2 ! -+
  346. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmlres2 ! | working arrays to diagnose the trends
  347. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmltrdm2 ! | associated with the time meaned ML
  348. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmlatf2 ! | passive tracers
  349. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmlrad2 ! | (-> for trb<0 corr in trcrad)
  350. !
  351. CHARACTER (LEN=10) :: clvar
  352. #if defined key_dimgout
  353. INTEGER :: iyear,imon,iday
  354. CHARACTER(LEN=80) :: cltext, clmode
  355. #endif
  356. !!----------------------------------------------------------------------
  357. ! Set-up pointers into sub-arrays of workspaces
  358. CALL wrk_alloc( jpi, jpj, jptra, ztmltot , ztmlres , ztmlatf , ztmlrad )
  359. CALL wrk_alloc( jpi, jpj, jptra, ztmltot2, ztmlres2, ztmlatf2, ztmlrad2, ztmltrdm2 )
  360. IF( nn_dttrc /= 1 ) CALL ctl_stop( " Be careful, trends diags never validated " )
  361. ! ======================================================================
  362. ! I. Diagnose the purely vertical (K_z) diffusion trend
  363. ! ======================================================================
  364. ! ... These terms can be estimated by flux computation at the lower boundary of the ML
  365. ! (we compute (-1/h) * K_z * d_z( tracer ))
  366. IF( ln_trcldf_iso ) THEN
  367. !
  368. DO jj = 1,jpj
  369. DO ji = 1,jpi
  370. ik = nmld_trc(ji,jj)
  371. zavt = fsavs(ji,jj,ik)
  372. DO jn = 1, jptra
  373. IF( ln_trdtrc(jn) ) &
  374. tmltrd_trc(ji,jj,jpmxl_trc_zdf,jn) = - zavt / fse3w(ji,jj,ik) * tmask(ji,jj,ik) &
  375. & * ( trn(ji,jj,ik-1,jn) - trn(ji,jj,ik,jn) ) &
  376. & / MAX( 1., rmld_trc(ji,jj) ) * tmask(ji,jj,1)
  377. END DO
  378. END DO
  379. END DO
  380. DO jn = 1, jptra
  381. ! ... Remove this K_z trend from the iso-neutral diffusion term (if any)
  382. IF( ln_trdtrc(jn) ) &
  383. tmltrd_trc(:,:,jpmxl_trc_ldf,jn) = tmltrd_trc(:,:,jpmxl_trc_ldf,jn) - tmltrd_trc(:,:,jpmxl_trc_zdf,jn)
  384. END DO
  385. !
  386. ENDIF
  387. IF ( cp_cfg .NE. 'gyre' ) THEN ! other than GYRE configuration
  388. ! GYRE : for diagnostic fields, are needed if cyclic B.C. are present, but not for purely MPI comm.
  389. ! therefore we do not call lbc_lnk in GYRE config. (closed basin, no cyclic B.C.)
  390. DO jn = 1, jptra
  391. IF( ln_trdtrc(jn) ) THEN
  392. DO jl = 1, jpltrd_trc
  393. CALL lbc_lnk( tmltrd_trc(:,:,jl,jn), 'T', 1. ) ! lateral boundary conditions
  394. END DO
  395. ENDIF
  396. END DO
  397. ENDIF
  398. ! ======================================================================
  399. ! II. Cumulate the trends over the analysis window
  400. ! ======================================================================
  401. ztmltrd2(:,:,:,:) = 0.e0 ; ztmltot2(:,:,:) = 0.e0 ! <<< reset arrays to zero
  402. ztmlres2(:,:,:) = 0.e0 ; ztmlatf2(:,:,:) = 0.e0
  403. ztmlrad2(:,:,:) = 0.e0
  404. ! II.1 Set before values of vertically averages passive tracers
  405. ! -------------------------------------------------------------
  406. IF( kt > nittrc000 ) THEN
  407. DO jn = 1, jptra
  408. IF( ln_trdtrc(jn) ) THEN
  409. tmlb_trc (:,:,jn) = tml_trc (:,:,jn)
  410. tmlatfn_trc(:,:,jn) = tmltrd_trc(:,:,jpmxl_trc_atf,jn)
  411. tmlradn_trc(:,:,jn) = tmltrd_trc(:,:,jpmxl_trc_radb,jn)
  412. ENDIF
  413. END DO
  414. ENDIF
  415. ! II.2 Vertically averaged passive tracers
  416. ! ----------------------------------------
  417. tml_trc(:,:,:) = 0.e0
  418. DO jk = 1, jpktrd_trc ! - 1 ???
  419. DO jn = 1, jptra
  420. IF( ln_trdtrc(jn) ) &
  421. tml_trc(:,:,jn) = tml_trc(:,:,jn) + wkx_trc(:,:,jk) * trn(:,:,jk,jn)
  422. END DO
  423. END DO
  424. ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window
  425. ! ------------------------------------------------------------------------
  426. IF( kt == nittrc000 + nn_dttrc ) THEN ! i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1) ???
  427. !
  428. DO jn = 1, jptra
  429. IF( ln_trdtrc(jn) ) THEN
  430. tmlbb_trc (:,:,jn) = tmlb_trc (:,:,jn) ; tmlbn_trc (:,:,jn) = tml_trc (:,:,jn)
  431. tmlatfb_trc(:,:,jn) = tmlatfn_trc(:,:,jn) ; tmlradb_trc(:,:,jn) = tmlradn_trc(:,:,jn)
  432. tmltrd_csum_ub_trc (:,:,:,jn) = 0.e0 ; tmltrd_atf_sumb_trc (:,:,jn) = 0.e0
  433. tmltrd_rad_sumb_trc (:,:,jn) = 0.e0
  434. ENDIF
  435. END DO
  436. rmldbn_trc(:,:) = rmld_trc(:,:)
  437. !
  438. ENDIF
  439. ! II.4 Cumulated trends over the analysis period
  440. ! ----------------------------------------------
  441. !
  442. ! [ 1rst analysis window ] [ 2nd analysis window ]
  443. !
  444. ! o---[--o-----o-----o-----o--]-[--o-----o-----o-----o-----o--]---o-----o--> time steps
  445. ! ntrd 2*ntrd etc.
  446. ! 1 2 3 4 =5 e.g. =10
  447. !
  448. IF( ( kt >= 2 ).OR.( ln_rsttr ) ) THEN ! ???
  449. !
  450. nmoymltrd = nmoymltrd + 1
  451. ! ... Cumulate over BOTH physical contributions AND over time steps
  452. DO jn = 1, jptra
  453. IF( ln_trdtrc(jn) ) THEN
  454. DO jl = 1, jpltrd_trc
  455. tmltrdm_trc(:,:,jn) = tmltrdm_trc(:,:,jn) + tmltrd_trc(:,:,jl,jn)
  456. END DO
  457. ENDIF
  458. END DO
  459. DO jn = 1, jptra
  460. IF( ln_trdtrc(jn) ) THEN
  461. ! ... Special handling of the Asselin trend
  462. tmlatfm_trc(:,:,jn) = tmlatfm_trc(:,:,jn) + tmlatfn_trc(:,:,jn)
  463. tmlradm_trc(:,:,jn) = tmlradm_trc(:,:,jn) + tmlradn_trc(:,:,jn)
  464. ! ... Trends associated with the time mean of the ML passive tracers
  465. tmltrd_sum_trc (:,:,:,jn) = tmltrd_sum_trc (:,:,:,jn) + tmltrd_trc (:,:,:,jn)
  466. tmltrd_csum_ln_trc(:,:,:,jn) = tmltrd_csum_ln_trc(:,:,:,jn) + tmltrd_sum_trc(:,:,:,jn)
  467. tml_sum_trc (:,:,jn) = tml_sum_trc (:,:,jn) + tml_trc (:,:,jn)
  468. ENDIF
  469. ENDDO
  470. rmld_sum_trc (:,:) = rmld_sum_trc (:,:) + rmld_trc (:,:)
  471. !
  472. ENDIF
  473. ! ======================================================================
  474. ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
  475. ! ======================================================================
  476. ! Convert to appropriate physical units
  477. tmltrd_trc(:,:,:,:) = tmltrd_trc(:,:,:,:) * rn_ucf_trc
  478. itmod = kt - nittrc000 + 1
  479. it = kt
  480. MODULO_NTRD : IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN ! nitend MUST be multiple of nn_trd_trc
  481. !
  482. ztmltot (:,:,:) = 0.e0 ! reset arrays to zero
  483. ztmlres (:,:,:) = 0.e0
  484. ztmltot2(:,:,:) = 0.e0
  485. ztmlres2(:,:,:) = 0.e0
  486. zfn = FLOAT( nmoymltrd ) ; zfn2 = zfn * zfn
  487. ! III.1 Prepare fields for output ("instantaneous" diagnostics)
  488. ! -------------------------------------------------------------
  489. DO jn = 1, jptra
  490. IF( ln_trdtrc(jn) ) THEN
  491. !-- Compute total trends (use rdttrc instead of rdt ???)
  492. IF ( ln_trcadv_muscl .OR. ln_trcadv_muscl2 ) THEN ! EULER-FORWARD schemes
  493. ztmltot(:,:,jn) = ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) )/rdt
  494. ELSE ! LEAP-FROG schemes
  495. ztmltot(:,:,jn) = ( tml_trc(:,:,jn) - tmlbn_trc(:,:,jn) + tmlb_trc(:,:,jn) - tmlbb_trc(:,:,jn))/(2.*rdt)
  496. ENDIF
  497. !-- Compute residuals
  498. ztmlres(:,:,jn) = ztmltot(:,:,jn) - ( tmltrdm_trc(:,:,jn) - tmlatfn_trc(:,:,jn) + tmlatfb_trc(:,:,jn) &
  499. & - tmlradn_trc(:,:,jn) + tmlradb_trc(:,:,jn) )
  500. !-- Diagnose Asselin trend over the analysis window
  501. ztmlatf(:,:,jn) = tmlatfm_trc(:,:,jn) - tmlatfn_trc(:,:,jn) + tmlatfb_trc(:,:,jn)
  502. ztmlrad(:,:,jn) = tmlradm_trc(:,:,jn) - tmlradn_trc(:,:,jn) + tmlradb_trc(:,:,jn)
  503. !-- Lateral boundary conditions
  504. IF ( cp_cfg .NE. 'gyre' ) THEN
  505. CALL lbc_lnk( ztmltot(:,:,jn) , 'T', 1. ) ; CALL lbc_lnk( ztmlres(:,:,jn) , 'T', 1. )
  506. CALL lbc_lnk( ztmlatf(:,:,jn) , 'T', 1. ) ; CALL lbc_lnk( ztmlrad(:,:,jn) , 'T', 1. )
  507. ENDIF
  508. #if defined key_diainstant
  509. STOP 'tmltrd_trc : key_diainstant was never checked within trdmxl. Comment this to proceed.'
  510. #endif
  511. ENDIF
  512. END DO
  513. ! III.2 Prepare fields for output ("mean" diagnostics)
  514. ! ----------------------------------------------------
  515. !-- Update the ML depth time sum (to build the Leap-Frog time mean)
  516. rmld_sum_trc(:,:) = rmldbn_trc(:,:) + 2 * ( rmld_sum_trc(:,:) - rmld_trc(:,:) ) + rmld_trc(:,:)
  517. !-- Compute passive tracer total trends
  518. DO jn = 1, jptra
  519. IF( ln_trdtrc(jn) ) THEN
  520. tml_sum_trc(:,:,jn) = tmlbn_trc(:,:,jn) + 2 * ( tml_sum_trc(:,:,jn) - tml_trc(:,:,jn) ) + tml_trc(:,:,jn)
  521. ztmltot2 (:,:,jn) = ( tml_sum_trc(:,:,jn) - tml_sumb_trc(:,:,jn) ) / ( 2.*rdt ) ! now tracer unit is /sec
  522. ENDIF
  523. END DO
  524. !-- Compute passive tracer residuals
  525. DO jn = 1, jptra
  526. IF( ln_trdtrc(jn) ) THEN
  527. !
  528. DO jl = 1, jpltrd_trc
  529. ztmltrd2(:,:,jl,jn) = tmltrd_csum_ub_trc(:,:,jl,jn) + tmltrd_csum_ln_trc(:,:,jl,jn)
  530. END DO
  531. ztmltrdm2(:,:,jn) = 0.e0
  532. DO jl = 1, jpltrd_trc
  533. ztmltrdm2(:,:,jn) = ztmltrdm2(:,:,jn) + ztmltrd2(:,:,jl,jn)
  534. END DO
  535. ztmlres2(:,:,jn) = ztmltot2(:,:,jn) - &
  536. & ( ztmltrdm2(:,:,jn) - tmltrd_sum_trc(:,:,jpmxl_trc_atf ,jn) + tmltrd_atf_sumb_trc(:,:,jn) &
  537. & - tmltrd_sum_trc(:,:,jpmxl_trc_radb,jn) + tmltrd_rad_sumb_trc(:,:,jn) )
  538. !
  539. !-- Diagnose Asselin trend over the analysis window
  540. ztmlatf2(:,:,jn) = ztmltrd2(:,:,jpmxl_trc_atf ,jn) - tmltrd_sum_trc(:,:,jpmxl_trc_atf ,jn) &
  541. & + tmltrd_atf_sumb_trc(:,:,jn)
  542. ztmlrad2(:,:,jn) = ztmltrd2(:,:,jpmxl_trc_radb,jn) - tmltrd_sum_trc(:,:,jpmxl_trc_radb,jn) &
  543. & + tmltrd_rad_sumb_trc(:,:,jn)
  544. !-- Lateral boundary conditions
  545. IF ( cp_cfg .NE. 'gyre' ) THEN ! other than GYRE configuration
  546. CALL lbc_lnk( ztmltot2(:,:,jn), 'T', 1. )
  547. CALL lbc_lnk( ztmlres2(:,:,jn), 'T', 1. )
  548. DO jl = 1, jpltrd_trc
  549. CALL lbc_lnk( ztmltrd2(:,:,jl,jn), 'T', 1. ) ! will be output in the NetCDF trends file
  550. END DO
  551. ENDIF
  552. ENDIF
  553. END DO
  554. ! * Debugging information *
  555. IF( lldebug ) THEN
  556. !
  557. WRITE(numout,*) 'trd_mxl_trc : write trends in the Mixed Layer for debugging process:'
  558. WRITE(numout,*) '~~~~~~~~~~~ '
  559. WRITE(numout,*)
  560. WRITE(numout,*) 'TRC kt = ', kt, ' nmoymltrd = ', nmoymltrd
  561. DO jn = 1, jptra
  562. IF( ln_trdtrc(jn) ) THEN
  563. WRITE(numout, *)
  564. WRITE(numout, *) '>>>>>>>>>>>>>>>>>> TRC TRACER jn =', jn, ' <<<<<<<<<<<<<<<<<<'
  565. WRITE(numout, *)
  566. WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmlres : ', SUM2D(ztmlres(:,:,jn))
  567. !CD??? PREVOIR: z2d = ztmlres(:,:,jn) ; CALL prt_ctl(tab2d_1=z2d, clinfo1=' ztmlres - : ')
  568. WRITE(numout,98) 'TRC jn =', jn, ' SUM ABS(ztmlres): ', SUM2D(ABS(ztmlres(:,:,jn)))
  569. WRITE(numout, '(3x,a)') ' -->>>------------------- ztmlres is computed from ------------- '
  570. WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltot : ', SUM2D(+ztmltot (:,:,jn))
  571. WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrdm_trc: ', SUM2D(+tmltrdm_trc(:,:,jn))
  572. WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlatfn_trc: ', SUM2D(-tmlatfn_trc(:,:,jn))
  573. WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlatfb_trc: ', SUM2D(+tmlatfb_trc(:,:,jn))
  574. WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlradn_trc: ', SUM2D(-tmlradn_trc(:,:,jn))
  575. WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlradb_trc: ', SUM2D(+tmlradb_trc(:,:,jn))
  576. WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
  577. WRITE(numout, *)
  578. WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmlres2 : ', SUM2D(ztmlres2(:,:,jn))
  579. WRITE(numout,98) 'TRC jn =', jn, ' SUM ABS(ztmlres2):', SUM2D(ABS(ztmlres2(:,:,jn)))
  580. WRITE(numout, '(3x,a)') ' -->>>------------------- ztmlres2 is computed from ------------ '
  581. WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltot2 : ', SUM2D(+ztmltot2(:,:,jn))
  582. WRITE(numout,98) 'TRC jn =', jn, ' SUM +ztmltrdm2 : ', SUM2D(+ztmltrdm2(:,:,jn))
  583. WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmltrd_sum_trc : ', SUM2D(-tmltrd_sum_trc(:,:,jpmxl_trc_atf,jn))
  584. WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrd_atf_sumb_trc : ', SUM2D(+tmltrd_atf_sumb_trc(:,:,jn))
  585. WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmltrd_sum_trc : ', SUM2D(-tmltrd_sum_trc(:,:,jpmxl_trc_radb,jn))
  586. WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmltrd_rad_sumb_trc : ', SUM2D(+tmltrd_rad_sumb_trc(:,:,jn) )
  587. WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
  588. WRITE(numout, *)
  589. WRITE(numout,98) 'TRC jn =', jn, ' SUM ztmltot : ', SUM2D(ztmltot (:,:,jn))
  590. WRITE(numout, '(3x,a)') ' -->>>------------------- ztmltot is computed from ------------- '
  591. WRITE(numout,98) 'TRC jn =', jn, ' SUM +tml_trc : ', SUM2D(tml_trc (:,:,jn))
  592. WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlbn_trc : ', SUM2D(tmlbn_trc (:,:,jn))
  593. WRITE(numout,98) 'TRC jn =', jn, ' SUM +tmlb_trc : ', SUM2D(tmlb_trc (:,:,jn))
  594. WRITE(numout,98) 'TRC jn =', jn, ' SUM -tmlbb_trc : ', SUM2D(tmlbb_trc (:,:,jn))
  595. WRITE(numout, '(3x,a)') ' --<<<----------------------------------------------------------- '
  596. WRITE(numout, *)
  597. WRITE(numout,98) 'TRC jn =', jn, ' SUM tmltrdm_trc : ', SUM2D(tmltrdm_trc(:,:,jn))
  598. WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlatfb_trc : ', SUM2D(tmlatfb_trc(:,:,jn))
  599. WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlatfn_trc : ', SUM2D(tmlatfn_trc(:,:,jn))
  600. WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlradb_trc : ', SUM2D(tmlradb_trc(:,:,jn))
  601. WRITE(numout,98) 'TRC jn =', jn, ' SUM tmlradn_trc : ', SUM2D(tmlradn_trc(:,:,jn))
  602. WRITE(numout, *)
  603. DO jl = 1, jpltrd_trc
  604. WRITE(numout,97) 'TRC jn =', jn, ' TREND INDEX jpmxl_trc_xxx = ', jl, &
  605. & ' SUM tmltrd_trc : ', SUM2D(tmltrd_trc(:,:,jl,jn))
  606. END DO
  607. WRITE(numout,*)
  608. WRITE(numout,*) ' *********************** ZTMLRES, ZTMLRES2 *********************** '
  609. WRITE(numout,*)
  610. WRITE(numout,*) 'TRC ztmlres (jpi/2,jpj/2,:) : ', ztmlres (jpi/2,jpj/2,jn)
  611. WRITE(numout,*)
  612. WRITE(numout,*) 'TRC ztmlres2(jpi/2,jpj/2,:) : ', ztmlres2(jpi/2,jpj/2,jn)
  613. WRITE(numout,*)
  614. WRITE(numout,*) ' *********************** ZTMLRES *********************** '
  615. WRITE(numout,*)
  616. WRITE(numout,*) '...................................................'
  617. WRITE(numout,*) 'TRC jn =', jn, ' ztmlres (1:10,1:5,jn) : '
  618. DO jj = 5, 1, -1
  619. WRITE(numout,99) jj, ( ztmlres (ji,jj,jn), ji=1,10 )
  620. END DO
  621. WRITE(numout,*)
  622. WRITE(numout,*) ' *********************** ZTMLRES2 *********************** '
  623. WRITE(numout,*)
  624. WRITE(numout,*) '...................................................'
  625. WRITE(numout,*) 'TRC jn =', jn, ' ztmlres2 (1:10,1:5,jn) : '
  626. DO jj = 5, 1, -1
  627. WRITE(numout,99) jj, ( ztmlres2 (ji,jj,jn), ji=1,10 )
  628. END DO
  629. !
  630. ENDIF
  631. !
  632. END DO
  633. 97 FORMAT(a10, i3, 2x, a30, i3, a20, 2x, g20.10)
  634. 98 FORMAT(a10, i3, 2x, a30, 2x, g20.10)
  635. 99 FORMAT('TRC jj =', i3,' : ', 10(g10.3,2x))
  636. WRITE(numout,*)
  637. !
  638. ENDIF
  639. ! III.3 Time evolution array swap
  640. ! -------------------------------
  641. ! ML depth
  642. rmldbn_trc(:,:) = rmld_trc(:,:)
  643. rmld_sum_trc(:,:) = rmld_sum_trc(:,:) / (2*zfn) ! similar to tml_sum and sml_sum
  644. DO jn = 1, jptra
  645. IF( ln_trdtrc(jn) ) THEN
  646. ! For passive tracer instantaneous diagnostics
  647. tmlbb_trc (:,:,jn) = tmlb_trc (:,:,jn) ; tmlbn_trc (:,:,jn) = tml_trc (:,:,jn)
  648. tmlatfb_trc(:,:,jn) = tmlatfn_trc(:,:,jn) ; tmlradb_trc(:,:,jn) = tmlradn_trc(:,:,jn)
  649. ! For passive tracer mean diagnostics
  650. tmltrd_csum_ub_trc (:,:,:,jn) = zfn * tmltrd_sum_trc(:,:,:,jn) - tmltrd_csum_ln_trc(:,:,:,jn)
  651. tml_sumb_trc (:,:,jn) = tml_sum_trc(:,:,jn)
  652. tmltrd_atf_sumb_trc(:,:,jn) = tmltrd_sum_trc(:,:,jpmxl_trc_atf ,jn)
  653. tmltrd_rad_sumb_trc(:,:,jn) = tmltrd_sum_trc(:,:,jpmxl_trc_radb,jn)
  654. ! III.4 Convert to appropriate physical units
  655. ! -------------------------------------------
  656. ztmltot (:,:,jn) = ztmltot (:,:,jn) * rn_ucf_trc/zfn ! instant diags
  657. ztmlres (:,:,jn) = ztmlres (:,:,jn) * rn_ucf_trc/zfn
  658. ztmlatf (:,:,jn) = ztmlatf (:,:,jn) * rn_ucf_trc/zfn
  659. ztmlrad (:,:,jn) = ztmlrad (:,:,jn) * rn_ucf_trc/zfn
  660. tml_sum_trc (:,:,jn) = tml_sum_trc (:,:,jn) / (2*zfn) ! mean diags
  661. ztmltot2 (:,:,jn) = ztmltot2 (:,:,jn) * rn_ucf_trc/zfn2
  662. ztmltrd2 (:,:,:,jn) = ztmltrd2 (:,:,:,jn) * rn_ucf_trc/zfn2
  663. ztmlatf2 (:,:,jn) = ztmlatf2 (:,:,jn) * rn_ucf_trc/zfn2
  664. ztmlrad2 (:,:,jn) = ztmlrad2 (:,:,jn) * rn_ucf_trc/zfn2
  665. ztmlres2 (:,:,jn) = ztmlres2 (:,:,jn) * rn_ucf_trc/zfn2
  666. ENDIF
  667. END DO
  668. !
  669. ENDIF MODULO_NTRD
  670. ! ======================================================================
  671. ! IV. Write trends in the NetCDF file
  672. ! ======================================================================
  673. ! IV.1 Code for dimg mpp output
  674. ! -----------------------------
  675. # if defined key_dimgout
  676. STOP 'Not implemented'
  677. # else
  678. ! IV.2 Code for IOIPSL/NetCDF output
  679. ! ----------------------------------
  680. IF( lwp .AND. MOD( itmod , nn_trd_trc ) == 0 ) THEN
  681. WRITE(numout,*) ' '
  682. WRITE(numout,*) 'trd_mxl_trc : write passive tracer trends in the NetCDF file :'
  683. WRITE(numout,*) '~~~~~~~~~~~ '
  684. WRITE(numout,*) ' ', trim(clhstnam), ' at kt = ', kt
  685. WRITE(numout,*) ' N.B. nmoymltrd = ', nmoymltrd
  686. WRITE(numout,*) ' '
  687. ENDIF
  688. NETCDF_OUTPUT : IF( ln_trdmxl_trc_instant ) THEN ! <<< write the trends for passive tracer instant. diags
  689. !
  690. DO jn = 1, jptra
  691. !
  692. IF( ln_trdtrc(jn) ) THEN
  693. CALL histwrite( nidtrd(jn), "mxl_depth", it, rmld_trc(:,:), ndimtrd1, ndextrd1 )
  694. !-- Output the fields
  695. clvar = trim(ctrcnm(jn))//"ml" ! e.g. detml, zooml, nh4ml, etc.
  696. CALL histwrite( nidtrd(jn), trim(clvar) , it, tml_trc(:,:,jn), ndimtrd1, ndextrd1 )
  697. CALL histwrite( nidtrd(jn), trim(clvar)//"_tot" , it, ztmltot(:,:,jn), ndimtrd1, ndextrd1 )
  698. CALL histwrite( nidtrd(jn), trim(clvar)//"_res" , it, ztmlres(:,:,jn), ndimtrd1, ndextrd1 )
  699. DO jl = 1, jpltrd_trc - 2
  700. CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)), &
  701. & it, tmltrd_trc(:,:,jl,jn), ndimtrd1, ndextrd1 )
  702. END DO
  703. CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_radb,2)), & ! now trcrad : jpltrd_trc - 1
  704. & it, ztmlrad(:,:,jn), ndimtrd1, ndextrd1 )
  705. CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_atf,2)), & ! now Asselin : jpltrd_trc
  706. & it, ztmlatf(:,:,jn), ndimtrd1, ndextrd1 )
  707. ENDIF
  708. END DO
  709. IF( kt == nitend ) THEN
  710. DO jn = 1, jptra
  711. IF( ln_trdtrc(jn) ) CALL histclo( nidtrd(jn) )
  712. END DO
  713. ENDIF
  714. ELSE ! <<< write the trends for passive tracer mean diagnostics
  715. DO jn = 1, jptra
  716. !
  717. IF( ln_trdtrc(jn) ) THEN
  718. CALL histwrite( nidtrd(jn), "mxl_depth", it, rmld_sum_trc(:,:), ndimtrd1, ndextrd1 )
  719. !-- Output the fields
  720. clvar = trim(ctrcnm(jn))//"ml" ! e.g. detml, zooml, nh4ml, etc.
  721. CALL histwrite( nidtrd(jn), trim(clvar) , it, tml_sum_trc(:,:,jn), ndimtrd1, ndextrd1 )
  722. CALL histwrite( nidtrd(jn), trim(clvar)//"_tot" , it, ztmltot2(:,:,jn), ndimtrd1, ndextrd1 )
  723. CALL histwrite( nidtrd(jn), trim(clvar)//"_res" , it, ztmlres2(:,:,jn), ndimtrd1, ndextrd1 )
  724. DO jl = 1, jpltrd_trc - 2
  725. CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)), &
  726. & it, ztmltrd2(:,:,jl,jn), ndimtrd1, ndextrd1 )
  727. END DO
  728. CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_radb,2)), & ! now trcrad : jpltrd_trc - 1
  729. & it, ztmlrad2(:,:,jn), ndimtrd1, ndextrd1 )
  730. CALL histwrite( nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_atf,2)), & ! now Asselin : jpltrd_trc
  731. & it, ztmlatf2(:,:,jn), ndimtrd1, ndextrd1 )
  732. ENDIF
  733. !
  734. END DO
  735. IF( kt == nitend ) THEN
  736. DO jn = 1, jptra
  737. IF( ln_trdtrc(jn) ) CALL histclo( nidtrd(jn) )
  738. END DO
  739. ENDIF
  740. !
  741. ENDIF NETCDF_OUTPUT
  742. ! Compute the control surface (for next time step) : flag = on
  743. icount = 1
  744. # endif /* key_dimgout */
  745. IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN
  746. !
  747. ! Reset cumulative arrays to zero
  748. ! -------------------------------
  749. nmoymltrd = 0
  750. tmltrdm_trc (:,:,:) = 0.e0 ; tmlatfm_trc (:,:,:) = 0.e0
  751. tmlradm_trc (:,:,:) = 0.e0 ; tml_sum_trc (:,:,:) = 0.e0
  752. tmltrd_csum_ln_trc (:,:,:,:) = 0.e0 ; tmltrd_sum_trc (:,:,:,:) = 0.e0
  753. rmld_sum_trc (:,:) = 0.e0
  754. !
  755. ENDIF
  756. ! ======================================================================
  757. ! V. Write restart file
  758. ! ======================================================================
  759. IF( lrst_trc ) CALL trd_mxl_trc_rst_write( kt ) ! this must be after the array swap above (III.3)
  760. CALL wrk_dealloc( jpi, jpj, jptra, ztmltot , ztmlres , ztmlatf , ztmlrad )
  761. CALL wrk_dealloc( jpi, jpj, jptra, ztmltot2, ztmlres2, ztmlatf2, ztmlrad2, ztmltrdm2 )
  762. !
  763. END SUBROUTINE trd_mxl_trc
  764. SUBROUTINE trd_mxl_bio( kt )
  765. !!----------------------------------------------------------------------
  766. !! *** ROUTINE trd_mld ***
  767. !!
  768. !! ** Purpose : Compute and cumulate the mixed layer biological trends over an analysis
  769. !! period, and write NetCDF (or dimg) outputs.
  770. !!
  771. !! ** Method/usage :
  772. !! The stored trends can be chosen twofold (according to the ln_trdmxl_trc_instant
  773. !! logical namelist variable) :
  774. !! 1) to explain the difference between initial and final
  775. !! mixed-layer T & S (where initial and final relate to the
  776. !! current analysis window, defined by ntrd in the namelist)
  777. !! 2) to explain the difference between the current and previous
  778. !! TIME-AVERAGED mixed-layer T & S (where time-averaging is
  779. !! performed over each analysis window).
  780. !!
  781. !! ** Consistency check :
  782. !! If the control surface is fixed ( nctls > 1 ), the residual term (dh/dt
  783. !! entrainment) should be zero, at machine accuracy. Note that in the case
  784. !! of time-averaged mixed-layer fields, this residual WILL NOT BE ZERO
  785. !! over the first two analysis windows (except if restart).
  786. !! N.B. For ORCA2_LIM, use e.g. ntrd=5, ucf=1., nctls=8
  787. !! for checking residuals.
  788. !! On a NEC-SX5 computer, this typically leads to:
  789. !! O(1.e-20) temp. residuals (tml_res) when ln_trdmxl_trc_instant=.false.
  790. !! O(1.e-21) temp. residuals (tml_res) when ln_trdmxl_trc_instant=.true.
  791. !!
  792. !! ** Action :
  793. !! At each time step, mixed-layer averaged trends are stored in the
  794. !! tmltrd(:,:,jpmxl_xxx) array (see trdmxl_oce.F90 for definitions of jpmxl_xxx).
  795. !! This array is known when trd_mld is called, at the end of the stp subroutine,
  796. !! except for the purely vertical K_z diffusion term, which is embedded in the
  797. !! lateral diffusion trend.
  798. !!
  799. !! In I), this K_z term is diagnosed and stored, thus its contribution is removed
  800. !! from the lateral diffusion trend.
  801. !! In II), the instantaneous mixed-layer T & S are computed, and misc. cumulative
  802. !! arrays are updated.
  803. !! In III), called only once per analysis window, we compute the total trends,
  804. !! along with the residuals and the Asselin correction terms.
  805. !! In IV), the appropriate trends are written in the trends NetCDF file.
  806. !!
  807. !! References :
  808. !! - Vialard & al.
  809. !! - See NEMO documentation (in preparation)
  810. !!----------------------------------------------------------------------
  811. INTEGER, INTENT( in ) :: kt ! ocean time-step index
  812. #if defined key_pisces_reduced
  813. INTEGER :: jl, it, itmod
  814. LOGICAL :: llwarn = .TRUE., lldebug = .TRUE.
  815. REAL(wp) :: zfn, zfn2
  816. #if defined key_dimgout
  817. INTEGER :: iyear,imon,iday
  818. CHARACTER(LEN=80) :: cltext, clmode
  819. #endif
  820. !!----------------------------------------------------------------------
  821. ! ... Warnings
  822. IF( nn_dttrc /= 1 ) CALL ctl_stop( " Be careful, trends diags never validated " )
  823. ! ======================================================================
  824. ! II. Cumulate the trends over the analysis window
  825. ! ======================================================================
  826. ztmltrdbio2(:,:,:) = 0.e0 ! <<< reset arrays to zero
  827. ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window
  828. ! ------------------------------------------------------------------------
  829. IF( kt == nittrc000 + nn_dttrc ) THEN ! i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)
  830. !
  831. tmltrd_csum_ub_bio (:,:,:) = 0.e0
  832. !
  833. END IF
  834. ! II.4 Cumulated trends over the analysis period
  835. ! ----------------------------------------------
  836. !
  837. ! [ 1rst analysis window ] [ 2nd analysis window ]
  838. !
  839. !
  840. ! o---[--o-----o-----o-----o--]-[--o-----o-----o-----o-----o--]---o-----o--> time steps
  841. ! ntrd 2*ntrd etc.
  842. ! 1 2 3 4 =5 e.g. =10
  843. !
  844. IF( ( kt >= 2 ).OR.( ln_rsttr ) ) THEN
  845. !
  846. nmoymltrdbio = nmoymltrdbio + 1
  847. ! ... Trends associated with the time mean of the ML passive tracers
  848. tmltrd_sum_bio (:,:,:) = tmltrd_sum_bio (:,:,:) + tmltrd_bio (:,:,:)
  849. tmltrd_csum_ln_bio(:,:,:) = tmltrd_csum_ln_bio(:,:,:) + tmltrd_sum_bio(:,:,:)
  850. !
  851. END IF
  852. ! ======================================================================
  853. ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
  854. ! ======================================================================
  855. ! Convert to appropriate physical units
  856. tmltrd_bio(:,:,:) = tmltrd_bio(:,:,:) * rn_ucf_trc
  857. MODULO_NTRD : IF( MOD( kt, nn_trd_trc ) == 0 ) THEN ! nitend MUST be multiple of ntrd
  858. !
  859. zfn = float(nmoymltrdbio) ; zfn2 = zfn * zfn
  860. ! III.1 Prepare fields for output ("instantaneous" diagnostics)
  861. ! -------------------------------------------------------------
  862. #if defined key_diainstant
  863. STOP 'tmltrd_bio : key_diainstant was never checked within trdmxl. Comment this to proceed.'
  864. #endif
  865. ! III.2 Prepare fields for output ("mean" diagnostics)
  866. ! ----------------------------------------------------
  867. ztmltrdbio2(:,:,:) = tmltrd_csum_ub_bio(:,:,:) + tmltrd_csum_ln_bio(:,:,:)
  868. !-- Lateral boundary conditions
  869. IF ( cp_cfg .NE. 'gyre' ) THEN ! other than GYRE configuration
  870. ! ES_B27_CD_WARN : lbc inutile GYRE, cf. + haut
  871. DO jn = 1, jpdiabio
  872. CALL lbc_lnk( ztmltrdbio2(:,:,jn), 'T', 1. )
  873. ENDDO
  874. ENDIF
  875. IF( lldebug ) THEN
  876. !
  877. WRITE(numout,*) 'trd_mxl_bio : write trends in the Mixed Layer for debugging process:'
  878. WRITE(numout,*) '~~~~~~~~~~~ '
  879. WRITE(numout,*) 'TRC kt = ', kt, 'nmoymltrdbio = ', nmoymltrdbio
  880. WRITE(numout,*)
  881. DO jl = 1, jpdiabio
  882. IF( ln_trdmxl_trc_instant ) THEN
  883. WRITE(numout,97) 'TRC jl =', jl, ' bio TREND INDEX = ', jl, &
  884. & ' SUM tmltrd_bio : ', SUM2D(tmltrd_bio(:,:,jl))
  885. ELSE
  886. WRITE(numout,97) 'TRC jl =', jl, ' bio TREND INDEX = ', jl, &
  887. & ' SUM ztmltrdbio2 : ', SUM2D(ztmltrdbio2(:,:,jl))
  888. endif
  889. END DO
  890. 97 FORMAT(a10, i3, 2x, a30, i3, a20, 2x, g20.10)
  891. 98 FORMAT(a10, i3, 2x, a30, 2x, g20.10)
  892. 99 FORMAT('TRC jj =', i3,' : ', 10(g10.3,2x))
  893. WRITE(numout,*)
  894. !
  895. ENDIF
  896. ! III.3 Time evolution array swap
  897. ! -------------------------------
  898. ! For passive tracer mean diagnostics
  899. tmltrd_csum_ub_bio (:,:,:) = zfn * tmltrd_sum_bio(:,:,:) - tmltrd_csum_ln_bio(:,:,:)
  900. ! III.4 Convert to appropriate physical units
  901. ! -------------------------------------------
  902. ztmltrdbio2 (:,:,:) = ztmltrdbio2 (:,:,:) * rn_ucf_trc/zfn2
  903. END IF MODULO_NTRD
  904. ! ======================================================================
  905. ! IV. Write trends in the NetCDF file
  906. ! ======================================================================
  907. ! IV.1 Code for dimg mpp output
  908. ! -----------------------------
  909. # if defined key_dimgout
  910. STOP 'Not implemented'
  911. # else
  912. ! IV.2 Code for IOIPSL/NetCDF output
  913. ! ----------------------------------
  914. ! define time axis
  915. itmod = kt - nittrc000 + 1
  916. it = kt
  917. IF( lwp .AND. MOD( itmod , nn_trd_trc ) == 0 ) THEN
  918. WRITE(numout,*) ' '
  919. WRITE(numout,*) 'trd_mxl_bio : write ML bio trends in the NetCDF file :'
  920. WRITE(numout,*) '~~~~~~~~~~~ '
  921. WRITE(numout,*) ' ', TRIM(clhstnam), ' at kt = ', kt
  922. WRITE(numout,*) ' N.B. nmoymltrdbio = ', nmoymltrdbio
  923. WRITE(numout,*) ' '
  924. END IF
  925. ! 2. Start writing data
  926. ! ---------------------
  927. NETCDF_OUTPUT : IF( ln_trdmxl_trc_instant ) THEN ! <<< write the trends for passive tracer instant. diags
  928. !
  929. DO jl = 1, jpdiabio
  930. CALL histwrite( nidtrdbio,TRIM("ML_"//ctrd_bio(jl,2)) , &
  931. & it, tmltrd_bio(:,:,jl), ndimtrd1, ndextrd1 )
  932. END DO
  933. IF( kt == nitend ) CALL histclo( nidtrdbio )
  934. ELSE ! <<< write the trends for passive tracer mean diagnostics
  935. DO jl = 1, jpdiabio
  936. CALL histwrite( nidtrdbio, TRIM("ML_"//ctrd_bio(jl,2)) , &
  937. & it, ztmltrdbio2(:,:,jl), ndimtrd1, ndextrd1 )
  938. END DO
  939. IF( kt == nitend ) CALL histclo( nidtrdbio )
  940. !
  941. END IF NETCDF_OUTPUT
  942. ! Compute the control surface (for next time step) : flag = on
  943. icountbio = 1
  944. # endif /* key_dimgout */
  945. IF( MOD( itmod, nn_trd_trc ) == 0 ) THEN
  946. !
  947. ! III.5 Reset cumulative arrays to zero
  948. ! -------------------------------------
  949. nmoymltrdbio = 0
  950. tmltrd_csum_ln_bio (:,:,:) = 0.e0
  951. tmltrd_sum_bio (:,:,:) = 0.e0
  952. END IF
  953. ! ======================================================================
  954. ! Write restart file
  955. ! ======================================================================
  956. ! restart write is done in trd_mxl_trc_write which is called by trd_mxl_bio (Marina)
  957. !
  958. #endif
  959. END SUBROUTINE trd_mxl_bio
  960. REAL FUNCTION sum2d( ztab )
  961. !!----------------------------------------------------------------------
  962. !! CD ??? prevoir d'utiliser plutot prtctl
  963. !!----------------------------------------------------------------------
  964. REAL(wp), DIMENSION(jpi,jpj), INTENT( in ) :: ztab
  965. !!----------------------------------------------------------------------
  966. sum2d = SUM( ztab(2:jpi-1,2:jpj-1) )
  967. END FUNCTION sum2d
  968. SUBROUTINE trd_mxl_trc_init
  969. !!----------------------------------------------------------------------
  970. !! *** ROUTINE trd_mxl_init ***
  971. !!
  972. !! ** Purpose : computation of vertically integrated T and S budgets
  973. !! from ocean surface down to control surface (NetCDF output)
  974. !!
  975. !! ** Method/usage :
  976. !!
  977. !!----------------------------------------------------------------------
  978. INTEGER :: inum ! logical unit
  979. INTEGER :: ilseq, jl, jn, iiter
  980. REAL(wp) :: zjulian, zsto, zout
  981. CHARACTER (LEN=40) :: clop
  982. CHARACTER (LEN=15) :: csuff
  983. CHARACTER (LEN=12) :: clmxl
  984. CHARACTER (LEN=16) :: cltrcu
  985. CHARACTER (LEN=10) :: clvar
  986. !!----------------------------------------------------------------------
  987. ! ======================================================================
  988. ! I. initialization
  989. ! ======================================================================
  990. IF(lwp) THEN
  991. WRITE(numout,*)
  992. WRITE(numout,*) ' trd_mxl_trc_init : Mixed-layer trends for passive tracers '
  993. WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
  994. WRITE(numout,*)
  995. ENDIF
  996. ! I.1 Check consistency of user defined preferences
  997. ! -------------------------------------------------
  998. IF( ( lk_trdmxl_trc ) .AND. ( MOD( nitend-nittrc000+1, nn_trd_trc ) /= 0 ) ) THEN
  999. WRITE(numout,cform_err)
  1000. WRITE(numout,*) ' Your nitend parameter, nitend = ', nitend
  1001. WRITE(numout,*) ' is no multiple of the trends diagnostics frequency '
  1002. WRITE(numout,*) ' you defined, nn_trd_trc = ', nn_trd_trc
  1003. WRITE(numout,*) ' This will not allow you to restart from this simulation. '
  1004. WRITE(numout,*) ' You should reconsider this choice. '
  1005. WRITE(numout,*)
  1006. WRITE(numout,*) ' N.B. the nitend parameter is also constrained to be a '
  1007. WRITE(numout,*) ' multiple of the sea-ice frequency parameter (typically 5) '
  1008. nstop = nstop + 1
  1009. ENDIF
  1010. ! * Debugging information *
  1011. IF( lldebug ) THEN
  1012. WRITE(numout,*) ' ln_trcadv_muscl = ' , ln_trcadv_muscl
  1013. WRITE(numout,*) ' ln_trdmxl_trc_instant = ', ln_trdmxl_trc_instant
  1014. ENDIF
  1015. IF( ( ln_trcadv_muscl .OR. ln_trcadv_muscl2 ) .AND. .NOT. ln_trdmxl_trc_instant ) THEN
  1016. WRITE(numout,cform_err)
  1017. WRITE(numout,*) ' Currently, you can NOT use simultaneously tracer MUSCL '
  1018. WRITE(numout,*) ' advection and window averaged diagnostics of ML trends. '
  1019. WRITE(numout,*) ' WHY? Everything in trdmxl_trc is coded for leap-frog, and '
  1020. WRITE(numout,*) ' MUSCL scheme is Euler forward for passive tracers (note '
  1021. WRITE(numout,*) ' that MUSCL is leap-frog for active tracers T/S). '
  1022. WRITE(numout,*) ' In particuliar, entrainment trend would be FALSE. However '
  1023. WRITE(numout,*) ' this residual is correct for instantaneous ML diagnostics.'
  1024. WRITE(numout,*)
  1025. nstop = nstop + 1
  1026. ENDIF
  1027. ! I.2 Initialize arrays to zero or read a restart file
  1028. ! ----------------------------------------------------
  1029. nmoymltrd = 0
  1030. rmld_trc (:,:) = 0.e0 ; tml_trc (:,:,:) = 0.e0 ! inst.
  1031. tmltrdm_trc (:,:,:) = 0.e0 ; tmlatfm_trc (:,:,:) = 0.e0
  1032. tmlradm_trc (:,:,:) = 0.e0
  1033. tml_sum_trc (:,:,:) = 0.e0 ; tmltrd_sum_trc (:,:,:,:) = 0.e0 ! mean
  1034. tmltrd_csum_ln_trc (:,:,:,:) = 0.e0 ; rmld_sum_trc (:,:) = 0.e0
  1035. #if defined key_pisces_reduced
  1036. nmoymltrdbio = 0
  1037. tmltrd_sum_bio (:,:,:) = 0.e0 ; tmltrd_csum_ln_bio (:,:,:) = 0.e0
  1038. DO jl = 1, jp_pisces_trd
  1039. ctrd_bio(jl,1) = ctrbil(jl) ! long name
  1040. ctrd_bio(jl,2) = ctrbio(jl) ! short name
  1041. ENDDO
  1042. #endif
  1043. IF( ln_rsttr .AND. ln_trdmxl_trc_restart ) THEN
  1044. CALL trd_mxl_trc_rst_read
  1045. ELSE
  1046. tmlb_trc (:,:,:) = 0.e0 ; tmlbb_trc (:,:,:) = 0.e0 ! inst.
  1047. tmlbn_trc (:,:,:) = 0.e0
  1048. tml_sumb_trc (:,:,:) = 0.e0 ; tmltrd_csum_ub_trc (:,:,:,:) = 0.e0 ! mean
  1049. tmltrd_atf_sumb_trc(:,:,:) = 0.e0 ; tmltrd_rad_sumb_trc(:,:,:) = 0.e0
  1050. #if defined key_pisces_reduced
  1051. tmltrd_csum_ub_bio (:,:,:) = 0.e0
  1052. #endif
  1053. ENDIF
  1054. icount = 1 ; ionce = 1 ! open specifier
  1055. #if defined key_pisces_reduced
  1056. icountbio = 1 ; ioncebio = 1 ! open specifier
  1057. #endif
  1058. ! I.3 Read control surface from file ctlsurf_idx
  1059. ! ----------------------------------------------
  1060. IF( nn_ctls_trc == 1 ) THEN
  1061. CALL ctl_opn( inum, 'ctlsurf_idx', 'OLD', 'UNFORMATTED', 'SEQUENTIAL', -1, numout, lwp )
  1062. READ ( inum ) nbol_trc
  1063. CLOSE( inum )
  1064. ENDIF
  1065. ! ======================================================================
  1066. ! II. netCDF output initialization
  1067. ! ======================================================================
  1068. #if defined key_dimgout
  1069. ???
  1070. #else
  1071. ! clmxl = legend root for netCDF output
  1072. IF( nn_ctls_trc == 0 ) THEN ! control surface = mixed-layer with density criterion
  1073. clmxl = 'Mixed Layer '
  1074. ELSE IF( nn_ctls_trc == 1 ) THEN ! control surface = read index from file
  1075. clmxl = ' Bowl '
  1076. ELSE IF( nn_ctls_trc >= 2 ) THEN ! control surface = model level
  1077. WRITE(clmxl,'(A10,I2,1X)') 'Levels 1 -', nn_ctls_trc
  1078. ENDIF
  1079. ! II.1 Define frequency of output and means
  1080. ! -----------------------------------------
  1081. IF( ln_mskland ) THEN ; clop = "only(x)" ! put 1.e+20 on land (very expensive!!)
  1082. ELSE ; clop = "x" ! no use of the mask value (require less cp time)
  1083. ENDIF
  1084. # if defined key_diainstant
  1085. IF( .NOT. ln_trdmxl_trc_instant ) THEN
  1086. STOP 'trd_mxl_trc : this was never checked. Comment this line to proceed...'
  1087. ENDIF
  1088. zsto = nn_trd_trc * rdt
  1089. clop = "inst("//TRIM(clop)//")"
  1090. # else
  1091. IF( ln_trdmxl_trc_instant ) THEN
  1092. zsto = rdt ! inst. diags : we use IOIPSL time averaging
  1093. ELSE
  1094. zsto = nn_trd_trc * rdt ! mean diags : we DO NOT use any IOIPSL time averaging
  1095. ENDIF
  1096. clop = "ave("//TRIM(clop)//")"
  1097. # endif
  1098. zout = nn_trd_trc * rdt
  1099. iiter = ( nittrc000 - 1 ) / nn_dttrc
  1100. IF(lwp) WRITE (numout,*) ' netCDF initialization'
  1101. ! II.2 Compute julian date from starting date of the run
  1102. ! ------------------------------------------------------
  1103. CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )
  1104. zjulian = zjulian - adatrj ! set calendar origin to the beginning of the experiment
  1105. IF(lwp) WRITE(numout,*)' '
  1106. IF(lwp) WRITE(numout,*)' Date 0 used :', nittrc000 &
  1107. & ,' YEAR ', nyear, ' MONTH ', nmonth,' DAY ', nday &
  1108. & ,'Julian day : ', zjulian
  1109. ! II.3 Define the T grid trend file (nidtrd)
  1110. ! ------------------------------------------
  1111. !-- Define long and short names for the NetCDF output variables
  1112. ! ==> choose them according to trdmxl_trc_oce.F90 <==
  1113. ctrd_trc(jpmxl_trc_xad ,1) = " Zonal advection" ; ctrd_trc(jpmxl_trc_xad ,2) = "_xad"
  1114. ctrd_trc(jpmxl_trc_yad ,1) = " Meridional advection" ; ctrd_trc(jpmxl_trc_yad ,2) = "_yad"
  1115. ctrd_trc(jpmxl_trc_zad ,1) = " Vertical advection" ; ctrd_trc(jpmxl_trc_zad ,2) = "_zad"
  1116. ctrd_trc(jpmxl_trc_ldf ,1) = " Lateral diffusion" ; ctrd_trc(jpmxl_trc_ldf ,2) = "_ldf"
  1117. ctrd_trc(jpmxl_trc_zdf ,1) = " Vertical diff. (Kz)" ; ctrd_trc(jpmxl_trc_zdf ,2) = "_zdf"
  1118. ctrd_trc(jpmxl_trc_bbl ,1) = " Adv/diff. Bottom boundary layer" ; ctrd_trc(jpmxl_trc_bbl ,2) = "_bbl"
  1119. ctrd_trc(jpmxl_trc_dmp ,1) = " Tracer damping" ; ctrd_trc(jpmxl_trc_dmp ,2) = "_dmp"
  1120. ctrd_trc(jpmxl_trc_sbc ,1) = " Surface boundary cond." ; ctrd_trc(jpmxl_trc_sbc ,2) = "_sbc"
  1121. ctrd_trc(jpmxl_trc_sms, 1) = " Sources minus sinks" ; ctrd_trc(jpmxl_trc_sms ,2) = "_sms"
  1122. ctrd_trc(jpmxl_trc_radb ,1) = " Correct negative concentrations" ; ctrd_trc(jpmxl_trc_radb ,2) = "_radb"
  1123. ctrd_trc(jpmxl_trc_radn ,1) = " Correct negative concentrations" ; ctrd_trc(jpmxl_trc_radn ,2) = "_radn"
  1124. ctrd_trc(jpmxl_trc_atf ,1) = " Asselin time filter" ; ctrd_trc(jpmxl_trc_atf ,2) = "_atf"
  1125. DO jn = 1, jptra
  1126. !-- Create a NetCDF file and enter the define mode
  1127. IF( ln_trdtrc(jn) ) THEN
  1128. csuff="ML_"//ctrcnm(jn)
  1129. CALL dia_nam( clhstnam, nn_trd_trc, csuff )
  1130. CALL histbeg( clhstnam, jpi, glamt, jpj, gphit, &
  1131. & 1, jpi, 1, jpj, iiter, zjulian, rdt, nh_t(jn), nidtrd(jn), domain_id=nidom, snc4chunks=snc4set )
  1132. !-- Define the ML depth variable
  1133. CALL histdef(nidtrd(jn), "mxl_depth", clmxl//" Mixed Layer Depth", "m", &
  1134. & jpi, jpj, nh_t(jn), 1 , 1, 1 , -99 , 32, clop, zsto, zout )
  1135. ENDIF
  1136. END DO
  1137. #if defined key_pisces_reduced
  1138. !-- Create a NetCDF file and enter the define mode
  1139. CALL dia_nam( clhstnam, nn_trd_trc, 'trdbio' )
  1140. CALL histbeg( clhstnam, jpi, glamt, jpj, gphit, &
  1141. & 1, jpi, 1, jpj, iiter, zjulian, rdt, nh_tb, nidtrdbio, domain_id=nidom, snc4chunks=snc4set )
  1142. #endif
  1143. !-- Define physical units
  1144. IF( rn_ucf_trc == 1. ) THEN
  1145. cltrcu = "(mmole-N/m3)/sec" ! all passive tracers have the same unit
  1146. ELSEIF ( rn_ucf_trc == 3600.*24.) THEN ! ??? trop long : seulement (mmole-N/m3)
  1147. cltrcu = "(mmole-N/m3)/day" ! ??? apparait dans les sorties netcdf
  1148. ELSE
  1149. cltrcu = "unknown?"
  1150. ENDIF
  1151. !-- Define miscellaneous passive tracer mixed-layer variables
  1152. IF( jpltrd_trc /= jpmxl_trc_atf .OR. jpltrd_trc - 1 /= jpmxl_trc_radb ) THEN
  1153. STOP 'Error : jpltrd_trc /= jpmxl_trc_atf .OR. jpltrd_trc - 1 /= jpmxl_trc_radb' ! see below
  1154. ENDIF
  1155. DO jn = 1, jptra
  1156. !
  1157. IF( ln_trdtrc(jn) ) THEN
  1158. clvar = trim(ctrcnm(jn))//"ml" ! e.g. detml, zooml, no3ml, etc.
  1159. CALL histdef(nidtrd(jn), trim(clvar), clmxl//" "//trim(ctrcnm(jn))//" Mixed Layer ", &
  1160. & "mmole-N/m3", jpi, jpj, nh_t(jn), 1 , 1, 1 , -99 , 32, clop, zsto, zout )
  1161. CALL histdef(nidtrd(jn), trim(clvar)//"_tot" , clmxl//" "//trim(ctrcnm(jn))//" Total trend ", &
  1162. & cltrcu, jpi, jpj, nh_t(jn), 1 , 1, 1 , -99 , 32, clop, zout, zout )
  1163. CALL histdef(nidtrd(jn), trim(clvar)//"_res" , clmxl//" "//trim(ctrcnm(jn))//" dh/dt Entrainment (Resid.)", &
  1164. & cltrcu, jpi, jpj, nh_t(jn), 1 , 1, 1 , -99 , 32, clop, zout, zout )
  1165. DO jl = 1, jpltrd_trc - 2 ! <== only true if jpltrd_trc == jpmxl_trc_atf
  1166. CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jl,2)), clmxl//" "//clvar//ctrd_trc(jl,1), &
  1167. & cltrcu, jpi, jpj, nh_t(jn), 1 , 1, 1 , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
  1168. END DO ! if zsto=rdt above
  1169. CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_radb,2)), clmxl//" "//clvar//ctrd_trc(jpmxl_trc_radb,1), &
  1170. & cltrcu, jpi, jpj, nh_t(jn), 1 , 1, 1 , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
  1171. CALL histdef(nidtrd(jn), trim(clvar)//trim(ctrd_trc(jpmxl_trc_atf,2)), clmxl//" "//clvar//ctrd_trc(jpmxl_trc_atf,1), &
  1172. & cltrcu, jpi, jpj, nh_t(jn), 1 , 1, 1 , -99 , 32, clop, zout, zout ) ! IOIPSL: NO time mean
  1173. !
  1174. ENDIF
  1175. END DO
  1176. #if defined key_pisces_reduced
  1177. DO jl = 1, jp_pisces_trd
  1178. CALL histdef(nidtrdbio, TRIM("ML_"//ctrd_bio(jl,2)), TRIM(clmxl//" ML_"//ctrd_bio(jl,1)) , &
  1179. & cltrcu, jpi, jpj, nh_tb, 1 , 1, 1 , -99 , 32, clop, zsto, zout ) ! IOIPSL: time mean
  1180. END DO ! if zsto=rdt above
  1181. #endif
  1182. !-- Leave IOIPSL/NetCDF define mode
  1183. DO jn = 1, jptra
  1184. IF( ln_trdtrc(jn) ) CALL histend( nidtrd(jn), snc4set )
  1185. END DO
  1186. #if defined key_pisces_reduced
  1187. !-- Leave IOIPSL/NetCDF define mode
  1188. CALL histend( nidtrdbio, snc4set )
  1189. IF(lwp) WRITE(numout,*)
  1190. IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization for ML bio trends'
  1191. #endif
  1192. #endif /* key_dimgout */
  1193. END SUBROUTINE trd_mxl_trc_init
  1194. #else
  1195. !!----------------------------------------------------------------------
  1196. !! Default option : Empty module
  1197. !!----------------------------------------------------------------------
  1198. CONTAINS
  1199. SUBROUTINE trd_mxl_trc( kt ) ! Empty routine
  1200. INTEGER, INTENT( in) :: kt
  1201. WRITE(*,*) 'trd_mxl_trc: You should not have seen this print! error?', kt
  1202. END SUBROUTINE trd_mxl_trc
  1203. SUBROUTINE trd_mxl_bio( kt )
  1204. INTEGER, INTENT( in) :: kt
  1205. WRITE(*,*) 'trd_mxl_bio: You should not have seen this print! error?', kt
  1206. END SUBROUTINE trd_mxl_bio
  1207. SUBROUTINE trd_mxl_trc_zint( ptrc_trdmxl, ktrd, ctype, kjn )
  1208. INTEGER , INTENT( in ) :: ktrd, kjn ! ocean trend index and passive tracer rank
  1209. CHARACTER(len=2) , INTENT( in ) :: ctype ! surface/bottom (2D) or interior (3D) physics
  1210. REAL, DIMENSION(:,:,:), INTENT( in ) :: ptrc_trdmxl ! passive trc trend
  1211. WRITE(*,*) 'trd_mxl_trc_zint: You should not have seen this print! error?', ptrc_trdmxl(1,1,1)
  1212. WRITE(*,*) ' " " : You should not have seen this print! error?', ctype
  1213. WRITE(*,*) ' " " : You should not have seen this print! error?', ktrd
  1214. WRITE(*,*) ' " " : You should not have seen this print! error?', kjn
  1215. END SUBROUTINE trd_mxl_trc_zint
  1216. SUBROUTINE trd_mxl_trc_init ! Empty routine
  1217. WRITE(*,*) 'trd_mxl_trc_init: You should not have seen this print! error?'
  1218. END SUBROUTINE trd_mxl_trc_init
  1219. #endif
  1220. !!======================================================================
  1221. END MODULE trdmxl_trc