trdmxl.F90 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. MODULE trdmxl
  2. !!======================================================================
  3. !! *** MODULE trdmxl ***
  4. !! Ocean diagnostics: mixed layer T-S trends
  5. !!======================================================================
  6. !! History : OPA ! 1995-04 (J. Vialard) Original code
  7. !! ! 1997-02 (E. Guilyardi) Adaptation global + base cmo
  8. !! ! 1999-09 (E. Guilyardi) Re-writing + netCDF output
  9. !! NEMO 1.0 ! 2002-06 (G. Madec) F90: Free form and module
  10. !! - ! 2004-08 (C. Talandier) New trends organization
  11. !! 2.0 ! 2005-05 (C. Deltel) Diagnose trends of time averaged ML T & S
  12. !! 3.5 ! 2012-03 (G. Madec) complete reorganisation + change in the time averaging
  13. !!----------------------------------------------------------------------
  14. !!----------------------------------------------------------------------
  15. !! trd_mxl : T and S cumulated trends averaged over the mixed layer
  16. !! trd_mxl_zint : T and S trends vertical integration
  17. !! trd_mxl_init : initialization step
  18. !!----------------------------------------------------------------------
  19. USE oce ! ocean dynamics and tracers variables
  20. USE dom_oce ! ocean space and time domain variables
  21. USE trd_oce ! trends: ocean variables
  22. USE trdmxl_oce ! ocean variables trends
  23. USE ldftra_oce ! ocean active tracers lateral physics
  24. USE zdf_oce ! ocean vertical physics
  25. USE in_out_manager ! I/O manager
  26. USE phycst ! Define parameters for the routines
  27. USE dianam ! build the name of file (routine)
  28. USE ldfslp ! iso-neutral slopes
  29. USE zdfmxl ! mixed layer depth
  30. USE zdfddm ! ocean vertical physics: double diffusion
  31. USE ioipsl ! NetCDF library
  32. USE lbclnk ! ocean lateral boundary conditions (or mpp link)
  33. USE diadimg ! dimg direct access file format output
  34. USE trdmxl_rst ! restart for diagnosing the ML trends
  35. USE prtctl ! Print control
  36. USE restart ! for lrst_oce
  37. USE lib_mpp ! MPP library
  38. USE wrk_nemo ! Memory allocation
  39. USE iom
  40. IMPLICIT NONE
  41. PRIVATE
  42. PUBLIC trd_mxl ! routine called by step.F90
  43. PUBLIC trd_mxl_init ! routine called by opa.F90
  44. PUBLIC trd_mxl_zint ! routine called by tracers routines
  45. INTEGER :: nkstp ! current time step
  46. !!gm to be moved from trdmxl_oce
  47. ! REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: hml ! ML depth (sum of e3t over nmln-1 levels) [m]
  48. ! REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: tml , sml ! now ML averaged T & S
  49. ! REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: tmlb_nf, smlb_nf ! not filtered before ML averaged T & S
  50. !
  51. !
  52. ! REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: hmlb, hmln ! before, now, and after Mixed Layer depths [m]
  53. !
  54. ! REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: tb_mlb, tb_mln ! before (not filtered) tracer averaged over before and now ML
  55. !
  56. ! REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: tn_mln ! now tracer averaged over now ML
  57. !!gm end
  58. CHARACTER (LEN=40) :: clhstnam ! name of the trends NetCDF file
  59. INTEGER :: nh_t, nmoymltrd
  60. INTEGER :: nidtrd
  61. INTEGER, ALLOCATABLE, SAVE, DIMENSION(:) :: ndextrd1
  62. INTEGER :: ndimtrd1
  63. INTEGER :: ionce, icount
  64. !! * Substitutions
  65. # include "domzgr_substitute.h90"
  66. # include "ldftra_substitute.h90"
  67. # include "zdfddm_substitute.h90"
  68. !!----------------------------------------------------------------------
  69. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  70. !! $Id: trdmxl.F90 2750 2016-01-12 10:42:05Z ufla $
  71. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  72. !!----------------------------------------------------------------------
  73. CONTAINS
  74. INTEGER FUNCTION trd_mxl_alloc()
  75. !!----------------------------------------------------------------------
  76. !! *** ROUTINE trd_mxl_alloc ***
  77. !!----------------------------------------------------------------------
  78. ALLOCATE( ndextrd1(jpi*jpj) , STAT=trd_mxl_alloc )
  79. !
  80. IF( lk_mpp ) CALL mpp_sum ( trd_mxl_alloc )
  81. IF( trd_mxl_alloc /= 0 ) CALL ctl_warn('trd_mxl_alloc: failed to allocate array ndextrd1')
  82. END FUNCTION trd_mxl_alloc
  83. SUBROUTINE trd_tra_mxl( ptrdx, ptrdy, ktrd, kt, p2dt, kmxln )
  84. !!----------------------------------------------------------------------
  85. !! *** ROUTINE trd_tra_mng ***
  86. !!
  87. !! ** Purpose : Dispatch all trends computation, e.g. 3D output, integral
  88. !! constraints, barotropic vorticity, kinetic enrgy,
  89. !! potential energy, and/or mixed layer budget.
  90. !!----------------------------------------------------------------------
  91. REAL(wp), DIMENSION(:,:,:), INTENT(inout) :: ptrdx ! Temperature or U trend
  92. REAL(wp), DIMENSION(:,:,:), INTENT(inout) :: ptrdy ! Salinity or V trend
  93. INTEGER , INTENT(in ) :: ktrd ! tracer trend index
  94. INTEGER , INTENT(in ) :: kt ! time step index
  95. REAL(wp) , INTENT(in ) :: p2dt ! time step [s]
  96. REAL(wp), DIMENSION(:,:) , INTENT(in ) :: kmxln ! number of t-box for the vertical average
  97. !
  98. INTEGER :: ji, jj, jk ! dummy loop indices
  99. !!----------------------------------------------------------------------
  100. ! !==============================!
  101. IF ( kt /= nkstp ) THEN != 1st call at kt time step =!
  102. ! !==============================!
  103. nkstp = kt
  104. ! !== reset trend arrays to zero ==!
  105. tmltrd(:,:,:) = 0._wp ; smltrd(:,:,:) = 0._wp
  106. !
  107. wkx(:,:,:) = 0._wp !== now ML weights for vertical averaging ==!
  108. DO jk = 1, jpktrd ! initialize wkx with vertical scale factor in mixed-layer
  109. DO jj = 1,jpj
  110. DO ji = 1,jpi
  111. IF( jk - kmxln(ji,jj) < 0 ) wkx(ji,jj,jk) = fse3t(ji,jj,jk) * tmask(ji,jj,jk)
  112. END DO
  113. END DO
  114. END DO
  115. hmxl(:,:) = 0._wp ! NOW mixed-layer depth
  116. DO jk = 1, jpktrd
  117. hmxl(:,:) = hmxl(:,:) + wkx(:,:,jk)
  118. END DO
  119. DO jk = 1, jpktrd ! integration weights
  120. wkx(:,:,jk) = wkx(:,:,jk) / MAX( 1.e-20_wp, hmxl(:,:) ) * tmask(:,:,1)
  121. END DO
  122. !
  123. ! !== Vertically averaged T and S ==!
  124. tml(:,:) = 0._wp ; sml(:,:) = 0._wp
  125. DO jk = 1, jpktrd
  126. tml(:,:) = tml(:,:) + wkx(:,:,jk) * tsn(:,:,jk,jp_tem)
  127. sml(:,:) = sml(:,:) + wkx(:,:,jk) * tsn(:,:,jk,jp_sal)
  128. END DO
  129. !
  130. ENDIF
  131. ! mean now trends over the now ML
  132. tmltrd(:,:,ktrd) = tmltrd(:,:,ktrd) + ptrdx(:,:,jk) * wkx(:,:,jk) ! temperature
  133. smltrd(:,:,ktrd) = smltrd(:,:,ktrd) + ptrdy(:,:,jk) * wkx(:,:,jk) ! salinity
  134. !!gm to be put juste before the output !
  135. ! ! Lateral boundary conditions
  136. ! CALL lbc_lnk( tmltrd(:,:,jl), 'T', 1. )
  137. ! CALL lbc_lnk( smltrd(:,:,jl), 'T', 1. )
  138. !!gm end
  139. SELECT CASE( ktrd )
  140. CASE( jptra_npc ) ! non-penetrative convection: regrouped with zdf
  141. !!gm : to be completed !
  142. ! IF( ....
  143. !!gm end
  144. CASE( jptra_zdfp ) ! iso-neutral diffusion: "pure" vertical diffusion
  145. ! ! regroup iso-neutral diffusion in one term
  146. tmltrd(:,:,jpmxl_ldf) = tmltrd(:,:,jpmxl_ldf) + ( tmltrd(:,:,jpmxl_zdf) - tmltrd(:,:,jpmxl_zdfp) )
  147. smltrd(:,:,jpmxl_ldf) = smltrd(:,:,jpmxl_ldf) + ( smltrd(:,:,jpmxl_zdf) - smltrd(:,:,jpmxl_zdfp) )
  148. ! ! put in zdf the dia-neutral diffusion
  149. tmltrd(:,:,jpmxl_zdf) = tmltrd(:,:,jpmxl_zdfp)
  150. smltrd(:,:,jpmxl_zdf) = smltrd(:,:,jpmxl_zdfp)
  151. IF( ln_zdfnpc ) THEN
  152. tmltrd(:,:,jpmxl_zdf) = tmltrd(:,:,jpmxl_zdf) + tmltrd(:,:,jpmxl_npc)
  153. smltrd(:,:,jpmxl_zdf) = smltrd(:,:,jpmxl_zdf) + smltrd(:,:,jpmxl_npc)
  154. ENDIF
  155. !
  156. CASE( jptra_atf ) ! last trends of the current time step: perform the time averaging & output
  157. !
  158. ! after ML : zhmla NB will be swaped to provide hmln and hmlb
  159. !
  160. ! entrainement ent_1 : tb_mln - tb_mlb ==>> use previous timestep ztn_mla = tb_mln
  161. ! " " " tn_mln = tb_mlb (unfiltered tb!)
  162. ! NB: tn_mln itself comes from the 2 time step before (ta_mla)
  163. !
  164. ! atf trend : ztbf_mln - tb_mln ==>> use previous timestep tn_mla = tb_mln
  165. ! need to compute tbf_mln, using the current tb
  166. ! which is the before fitered tracer
  167. !
  168. ! entrainement ent_2 : zta_mla - zta_mln ==>> need to compute zta_mla and zta_mln
  169. !
  170. ! time averaging : mean: CALL trd_mean( kt, ptrd, ptrdm )
  171. ! and out put the starting mean value and the total trends
  172. ! (i.e. difference between starting and ending values)
  173. ! hat : CALL trd_hat ( kt, ptrd, ptrdm )
  174. ! and output the starting hat value and the total hat trends
  175. !
  176. ! swaps : hmlb <== hmln <== zhmla
  177. ! tb_mlb <== tn_mln <== zta_mla
  178. ! tb_mln <== ztn_mla ==>> now T over after h, need to be computed here
  179. ! to be used at next time step (unfiltered before)
  180. !
  181. END SELECT
  182. !
  183. END SUBROUTINE trd_tra_mxl
  184. SUBROUTINE trd_mean( kt, ptrd, ptrdm )
  185. !!----------------------------------------------------------------------
  186. !! *** ROUTINE trd_mean ***
  187. !!
  188. !! ** Purpose :
  189. !!----------------------------------------------------------------------
  190. REAL(wp), DIMENSION(:,:,:), INTENT(in ) :: ptrd ! trend at kt
  191. REAL(wp), DIMENSION(:,:,:), INTENT(inout) :: ptrdm ! cumulative trends at kt
  192. INTEGER , INTENT(in ) :: kt ! time step index
  193. !!----------------------------------------------------------------------
  194. !
  195. IF ( kt == nn_it000 ) ptrdm(:,:,:) = 0._wp
  196. !
  197. ptrdm(:,:,:) = ptrdm(:,:,:) + ptrd(:,:,:)
  198. !
  199. IF ( MOD( kt - nn_it000 + 1, nn_trd ) == 0 ) THEN
  200. !
  201. ! call iom put???? avec en argument le tableau de nom des trends?
  202. !
  203. ENDIF
  204. !
  205. END SUBROUTINE trd_mean
  206. SUBROUTINE trd_mxl_zint( pttrdmxl, pstrdmxl, ktrd, ctype )
  207. !!----------------------------------------------------------------------
  208. !! *** ROUTINE trd_mxl_zint ***
  209. !!
  210. !! ** Purpose : Compute the vertical average of the 3D fields given as arguments
  211. !! to the subroutine. This vertical average is performed from ocean
  212. !! surface down to a chosen control surface.
  213. !!
  214. !! ** Method/usage :
  215. !! The control surface can be either a mixed layer depth (time varying)
  216. !! or a fixed surface (jk level or bowl).
  217. !! Choose control surface with nn_ctls in namelist NAMTRD :
  218. !! nn_ctls = 0 : use mixed layer with density criterion
  219. !! nn_ctls = 1 : read index from file 'ctlsurf_idx'
  220. !! nn_ctls > 1 : use fixed level surface jk = nn_ctls
  221. !! Note: in the remainder of the routine, the volume between the
  222. !! surface and the control surface is called "mixed-layer"
  223. !!----------------------------------------------------------------------
  224. INTEGER , INTENT( in ) :: ktrd ! ocean trend index
  225. CHARACTER(len=2) , INTENT( in ) :: ctype ! 2D surface/bottom or 3D interior physics
  226. REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) :: pttrdmxl ! temperature trend
  227. REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT( in ) :: pstrdmxl ! salinity trend
  228. !
  229. INTEGER :: ji, jj, jk, isum
  230. REAL(wp), POINTER, DIMENSION(:,:) :: zvlmsk
  231. !!----------------------------------------------------------------------
  232. CALL wrk_alloc( jpi, jpj, zvlmsk )
  233. ! I. Definition of control surface and associated fields
  234. ! ------------------------------------------------------
  235. ! ==> only once per time step <==
  236. IF( icount == 1 ) THEN
  237. !
  238. !!gm BUG?
  239. !!gm CAUTION: double check the definition of nmln it is the nb of w-level, not t-level I guess
  240. ! ... Set nmxl(ji,jj) = index of first T point below control surf. or outside mixed-layer
  241. IF( nn_ctls == 0 ) THEN ! * control surface = mixed-layer with density criterion
  242. nmxl(:,:) = nmln(:,:) ! array nmln computed in zdfmxl.F90
  243. ELSEIF( nn_ctls == 1 ) THEN ! * control surface = read index from file
  244. nmxl(:,:) = nbol(:,:)
  245. ELSEIF( nn_ctls >= 2 ) THEN ! * control surface = model level
  246. nn_ctls = MIN( nn_ctls, jpktrd - 1 )
  247. nmxl(:,:) = nn_ctls + 1
  248. ENDIF
  249. END IF
  250. !
  251. CALL wrk_dealloc( jpi, jpj, zvlmsk )
  252. !
  253. END SUBROUTINE trd_mxl_zint
  254. SUBROUTINE trd_mxl( kt, p2dt )
  255. !!----------------------------------------------------------------------
  256. !! *** ROUTINE trd_mxl ***
  257. !!
  258. !! ** Purpose : Compute and cumulate the mixed layer trends over an analysis
  259. !! period, and write NetCDF (or dimg) outputs.
  260. !!
  261. !! ** Method/usage :
  262. !! The stored trends can be chosen twofold (according to the ln_trdmxl_instant
  263. !! logical namelist variable) :
  264. !! 1) to explain the difference between initial and final
  265. !! mixed-layer T & S (where initial and final relate to the
  266. !! current analysis window, defined by nn_trd in the namelist)
  267. !! 2) to explain the difference between the current and previous
  268. !! TIME-AVERAGED mixed-layer T & S (where time-averaging is
  269. !! performed over each analysis window).
  270. !!
  271. !! ** Consistency check :
  272. !! If the control surface is fixed ( nn_ctls > 1 ), the residual term (dh/dt
  273. !! entrainment) should be zero, at machine accuracy. Note that in the case
  274. !! of time-averaged mixed-layer fields, this residual WILL NOT BE ZERO
  275. !! over the first two analysis windows (except if restart).
  276. !! N.B. For ORCA2_LIM, use e.g. nn_trd=5, rn_ucf=1., nn_ctls=8
  277. !! for checking residuals.
  278. !! On a NEC-SX5 computer, this typically leads to:
  279. !! O(1.e-20) temp. residuals (tml_res) when ln_trdmxl_instant=.false.
  280. !! O(1.e-21) temp. residuals (tml_res) when ln_trdmxl_instant=.true.
  281. !!
  282. !! ** Action :
  283. !! At each time step, mixed-layer averaged trends are stored in the
  284. !! tmltrd(:,:,jpmxl_xxx) array (see trdmxl_oce.F90 for definitions of jpmxl_xxx).
  285. !! This array is known when trd_mxl is called, at the end of the stp subroutine,
  286. !! except for the purely vertical K_z diffusion term, which is embedded in the
  287. !! lateral diffusion trend.
  288. !!
  289. !! In I), this K_z term is diagnosed and stored, thus its contribution is removed
  290. !! from the lateral diffusion trend.
  291. !! In II), the instantaneous mixed-layer T & S are computed, and misc. cumulative
  292. !! arrays are updated.
  293. !! In III), called only once per analysis window, we compute the total trends,
  294. !! along with the residuals and the Asselin correction terms.
  295. !! In IV), the appropriate trends are written in the trends NetCDF file.
  296. !!
  297. !! References : Vialard et al.,2001, JPO.
  298. !!----------------------------------------------------------------------
  299. INTEGER , INTENT(in ) :: kt ! ocean time-step index
  300. REAL(wp), INTENT(in ) :: p2dt ! time step [s]
  301. !
  302. INTEGER :: ji, jj, jk, jl, ik, it, itmod
  303. LOGICAL :: lldebug = .TRUE.
  304. REAL(wp) :: zavt, zfn, zfn2
  305. ! ! z(ts)mltot : dT/dt over the anlysis window (including Asselin)
  306. ! ! z(ts)mlres : residual = dh/dt entrainment term
  307. REAL(wp), POINTER, DIMENSION(:,: ) :: ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf
  308. REAL(wp), POINTER, DIMENSION(:,: ) :: ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2
  309. REAL(wp), POINTER, DIMENSION(:,:,:) :: ztmltrd2, zsmltrd2 ! only needed for mean diagnostics
  310. #if defined key_dimgout
  311. INTEGER :: iyear,imon,iday
  312. CHARACTER(LEN=80) :: cltext, clmode
  313. #endif
  314. !!----------------------------------------------------------------------
  315. CALL wrk_alloc( jpi, jpj, ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf )
  316. CALL wrk_alloc( jpi, jpj, ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2 )
  317. CALL wrk_alloc( jpi, jpj, jpltrd, ztmltrd2, zsmltrd2 )
  318. ! ======================================================================
  319. ! II. Cumulate the trends over the analysis window
  320. ! ======================================================================
  321. ztmltrd2(:,:,:) = 0.e0 ; zsmltrd2(:,:,:) = 0.e0 ! <<< reset arrays to zero
  322. ztmltot2(:,:) = 0.e0 ; zsmltot2(:,:) = 0.e0
  323. ztmlres2(:,:) = 0.e0 ; zsmlres2(:,:) = 0.e0
  324. ztmlatf2(:,:) = 0.e0 ; zsmlatf2(:,:) = 0.e0
  325. ! II.1 Set before values of vertically average T and S
  326. ! ----------------------------------------------------
  327. IF( kt > nit000 ) THEN
  328. ! ... temperature ... ... salinity ...
  329. tmlb (:,:) = tml (:,:) ; smlb (:,:) = sml (:,:)
  330. tmlatfn(:,:) = tmltrd(:,:,jpmxl_atf) ; smlatfn(:,:) = smltrd(:,:,jpmxl_atf)
  331. END IF
  332. ! II.3 Initialize mixed-layer "before" arrays for the 1rst analysis window
  333. ! ------------------------------------------------------------------------
  334. IF( kt == 2 ) THEN ! i.e. ( .NOT. ln_rstart ).AND.( kt == nit000 + 1)
  335. !
  336. ! ... temperature ... ... salinity ...
  337. tmlbb (:,:) = tmlb (:,:) ; smlbb (:,:) = smlb (:,:)
  338. tmlbn (:,:) = tml (:,:) ; smlbn (:,:) = sml (:,:)
  339. tmlatfb(:,:) = tmlatfn(:,:) ; smlatfb(:,:) = smlatfn(:,:)
  340. tmltrd_csum_ub (:,:,:) = 0.e0 ; smltrd_csum_ub (:,:,:) = 0.e0
  341. tmltrd_atf_sumb(:,:) = 0.e0 ; smltrd_atf_sumb(:,:) = 0.e0
  342. hmxlbn(:,:) = hmxl(:,:)
  343. IF( ln_ctl ) THEN
  344. WRITE(numout,*) ' we reach kt == nit000 + 1 = ', nit000+1
  345. CALL prt_ctl(tab2d_1=tmlbb , clinfo1=' tmlbb - : ', mask1=tmask, ovlap=1)
  346. CALL prt_ctl(tab2d_1=tmlbn , clinfo1=' tmlbn - : ', mask1=tmask, ovlap=1)
  347. CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb - : ', mask1=tmask, ovlap=1)
  348. END IF
  349. !
  350. END IF
  351. IF( ( ln_rstart ) .AND. ( kt == nit000 ) .AND. ( ln_ctl ) ) THEN
  352. IF( ln_trdmxl_instant ) THEN
  353. WRITE(numout,*) ' restart from kt == nit000 = ', nit000
  354. CALL prt_ctl(tab2d_1=tmlbb , clinfo1=' tmlbb - : ', mask1=tmask, ovlap=1)
  355. CALL prt_ctl(tab2d_1=tmlbn , clinfo1=' tmlbn - : ', mask1=tmask, ovlap=1)
  356. CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb - : ', mask1=tmask, ovlap=1)
  357. ELSE
  358. WRITE(numout,*) ' restart from kt == nit000 = ', nit000
  359. CALL prt_ctl(tab2d_1=tmlbn , clinfo1=' tmlbn - : ', mask1=tmask, ovlap=1)
  360. CALL prt_ctl(tab2d_1=hmxlbn , clinfo1=' hmxlbn - : ', mask1=tmask, ovlap=1)
  361. CALL prt_ctl(tab2d_1=tml_sumb , clinfo1=' tml_sumb - : ', mask1=tmask, ovlap=1)
  362. CALL prt_ctl(tab2d_1=tmltrd_atf_sumb, clinfo1=' tmltrd_atf_sumb - : ', mask1=tmask, ovlap=1)
  363. CALL prt_ctl(tab3d_1=tmltrd_csum_ub , clinfo1=' tmltrd_csum_ub - : ', mask1=tmask, ovlap=1, kdim=1)
  364. END IF
  365. END IF
  366. ! II.4 Cumulated trends over the analysis period
  367. ! ----------------------------------------------
  368. !
  369. ! [ 1rst analysis window ] [ 2nd analysis window ]
  370. !
  371. ! o---[--o-----o-----o-----o--]-[--o-----o-----o-----o-----o--]---o-----o--> time steps
  372. ! nn_trd 2*nn_trd etc.
  373. ! 1 2 3 4 =5 e.g. =10
  374. !
  375. IF( ( kt >= 2 ).OR.( ln_rstart ) ) THEN
  376. !
  377. nmoymltrd = nmoymltrd + 1
  378. ! ... Cumulate over BOTH physical contributions AND over time steps
  379. DO jl = 1, jpltrd
  380. tmltrdm(:,:) = tmltrdm(:,:) + tmltrd(:,:,jl)
  381. smltrdm(:,:) = smltrdm(:,:) + smltrd(:,:,jl)
  382. END DO
  383. ! ... Special handling of the Asselin trend
  384. tmlatfm(:,:) = tmlatfm(:,:) + tmlatfn(:,:)
  385. smlatfm(:,:) = smlatfm(:,:) + smlatfn(:,:)
  386. ! ... Trends associated with the time mean of the ML T/S
  387. tmltrd_sum (:,:,:) = tmltrd_sum (:,:,:) + tmltrd (:,:,:) ! tem
  388. tmltrd_csum_ln(:,:,:) = tmltrd_csum_ln(:,:,:) + tmltrd_sum(:,:,:)
  389. tml_sum (:,:) = tml_sum (:,:) + tml (:,:)
  390. smltrd_sum (:,:,:) = smltrd_sum (:,:,:) + smltrd (:,:,:) ! sal
  391. smltrd_csum_ln(:,:,:) = smltrd_csum_ln(:,:,:) + smltrd_sum(:,:,:)
  392. sml_sum (:,:) = sml_sum (:,:) + sml (:,:)
  393. hmxl_sum (:,:) = hmxl_sum (:,:) + hmxl (:,:) ! rmxl
  394. !
  395. END IF
  396. ! ======================================================================
  397. ! III. Prepare fields for output (get here ONCE PER ANALYSIS PERIOD)
  398. ! ======================================================================
  399. ! Convert to appropriate physical units
  400. ! N.B. It may be useful to check IOIPSL time averaging with :
  401. ! tmltrd (:,:,:) = 1. ; smltrd (:,:,:) = 1.
  402. tmltrd(:,:,:) = tmltrd(:,:,:) * rn_ucf ! (actually needed for 1:jpltrd-1, but trdmxl(:,:,jpltrd)
  403. smltrd(:,:,:) = smltrd(:,:,:) * rn_ucf ! is no longer used, and is reset to 0. at next time step)
  404. ! define time axis
  405. it = kt
  406. itmod = kt - nit000 + 1
  407. MODULO_NTRD : IF( MOD( itmod, nn_trd ) == 0 ) THEN ! nitend MUST be multiple of nn_trd
  408. !
  409. ztmltot (:,:) = 0.e0 ; zsmltot (:,:) = 0.e0 ! reset arrays to zero
  410. ztmlres (:,:) = 0.e0 ; zsmlres (:,:) = 0.e0
  411. ztmltot2(:,:) = 0.e0 ; zsmltot2(:,:) = 0.e0
  412. ztmlres2(:,:) = 0.e0 ; zsmlres2(:,:) = 0.e0
  413. zfn = REAL( nmoymltrd, wp ) ; zfn2 = zfn * zfn
  414. ! III.1 Prepare fields for output ("instantaneous" diagnostics)
  415. ! -------------------------------------------------------------
  416. !-- Compute total trends
  417. ztmltot(:,:) = ( tml(:,:) - tmlbn(:,:) + tmlb(:,:) - tmlbb(:,:) ) / p2dt
  418. zsmltot(:,:) = ( sml(:,:) - smlbn(:,:) + smlb(:,:) - smlbb(:,:) ) / p2dt
  419. !-- Compute residuals
  420. ztmlres(:,:) = ztmltot(:,:) - ( tmltrdm(:,:) - tmlatfn(:,:) + tmlatfb(:,:) )
  421. zsmlres(:,:) = zsmltot(:,:) - ( smltrdm(:,:) - smlatfn(:,:) + smlatfb(:,:) )
  422. !-- Diagnose Asselin trend over the analysis window
  423. ztmlatf(:,:) = tmlatfm(:,:) - tmlatfn(:,:) + tmlatfb(:,:)
  424. zsmlatf(:,:) = smlatfm(:,:) - smlatfn(:,:) + smlatfb(:,:)
  425. !-- Lateral boundary conditions
  426. ! ... temperature ... ... salinity ...
  427. CALL lbc_lnk( ztmltot , 'T', 1. ) ; CALL lbc_lnk( zsmltot , 'T', 1. )
  428. CALL lbc_lnk( ztmlres , 'T', 1. ) ; CALL lbc_lnk( zsmlres , 'T', 1. )
  429. CALL lbc_lnk( ztmlatf , 'T', 1. ) ; CALL lbc_lnk( zsmlatf , 'T', 1. )
  430. ! III.2 Prepare fields for output ("mean" diagnostics)
  431. ! ----------------------------------------------------
  432. !-- Update the ML depth time sum (to build the Leap-Frog time mean)
  433. hmxl_sum(:,:) = hmxlbn(:,:) + 2 * ( hmxl_sum(:,:) - hmxl(:,:) ) + hmxl(:,:)
  434. !-- Compute temperature total trends
  435. tml_sum (:,:) = tmlbn(:,:) + 2 * ( tml_sum(:,:) - tml(:,:) ) + tml(:,:)
  436. ztmltot2(:,:) = ( tml_sum(:,:) - tml_sumb(:,:) ) / p2dt ! now in degC/s
  437. !-- Compute salinity total trends
  438. sml_sum (:,:) = smlbn(:,:) + 2 * ( sml_sum(:,:) - sml(:,:) ) + sml(:,:)
  439. zsmltot2(:,:) = ( sml_sum(:,:) - sml_sumb(:,:) ) / p2dt ! now in psu/s
  440. !-- Compute temperature residuals
  441. DO jl = 1, jpltrd
  442. ztmltrd2(:,:,jl) = tmltrd_csum_ub(:,:,jl) + tmltrd_csum_ln(:,:,jl)
  443. END DO
  444. ztmltrdm2(:,:) = 0.e0
  445. DO jl = 1, jpltrd
  446. ztmltrdm2(:,:) = ztmltrdm2(:,:) + ztmltrd2(:,:,jl)
  447. END DO
  448. ztmlres2(:,:) = ztmltot2(:,:) - &
  449. ( ztmltrdm2(:,:) - tmltrd_sum(:,:,jpmxl_atf) + tmltrd_atf_sumb(:,:) )
  450. !-- Compute salinity residuals
  451. DO jl = 1, jpltrd
  452. zsmltrd2(:,:,jl) = smltrd_csum_ub(:,:,jl) + smltrd_csum_ln(:,:,jl)
  453. END DO
  454. zsmltrdm2(:,:) = 0.
  455. DO jl = 1, jpltrd
  456. zsmltrdm2(:,:) = zsmltrdm2(:,:) + zsmltrd2(:,:,jl)
  457. END DO
  458. zsmlres2(:,:) = zsmltot2(:,:) - &
  459. ( zsmltrdm2(:,:) - smltrd_sum(:,:,jpmxl_atf) + smltrd_atf_sumb(:,:) )
  460. !-- Diagnose Asselin trend over the analysis window
  461. ztmlatf2(:,:) = ztmltrd2(:,:,jpmxl_atf) - tmltrd_sum(:,:,jpmxl_atf) + tmltrd_atf_sumb(:,:)
  462. zsmlatf2(:,:) = zsmltrd2(:,:,jpmxl_atf) - smltrd_sum(:,:,jpmxl_atf) + smltrd_atf_sumb(:,:)
  463. !-- Lateral boundary conditions
  464. ! ... temperature ... ... salinity ...
  465. CALL lbc_lnk( ztmltot2, 'T', 1. ) ; CALL lbc_lnk( zsmltot2, 'T', 1. )
  466. CALL lbc_lnk( ztmlres2, 'T', 1. ) ; CALL lbc_lnk( zsmlres2, 'T', 1. )
  467. DO jl = 1, jpltrd
  468. CALL lbc_lnk( ztmltrd2(:,:,jl), 'T', 1. ) ! \ these will be output
  469. CALL lbc_lnk( zsmltrd2(:,:,jl), 'T', 1. ) ! / in the NetCDF trends file
  470. END DO
  471. ! III.3 Time evolution array swap
  472. ! -------------------------------
  473. ! For T/S instantaneous diagnostics
  474. ! ... temperature ... ... salinity ...
  475. tmlbb (:,:) = tmlb (:,:) ; smlbb (:,:) = smlb (:,:)
  476. tmlbn (:,:) = tml (:,:) ; smlbn (:,:) = sml (:,:)
  477. tmlatfb(:,:) = tmlatfn(:,:) ; smlatfb(:,:) = smlatfn(:,:)
  478. ! For T mean diagnostics
  479. tmltrd_csum_ub (:,:,:) = zfn * tmltrd_sum(:,:,:) - tmltrd_csum_ln(:,:,:)
  480. tml_sumb (:,:) = tml_sum(:,:)
  481. tmltrd_atf_sumb(:,:) = tmltrd_sum(:,:,jpmxl_atf)
  482. ! For S mean diagnostics
  483. smltrd_csum_ub (:,:,:) = zfn * smltrd_sum(:,:,:) - smltrd_csum_ln(:,:,:)
  484. sml_sumb (:,:) = sml_sum(:,:)
  485. smltrd_atf_sumb(:,:) = smltrd_sum(:,:,jpmxl_atf)
  486. ! ML depth
  487. hmxlbn (:,:) = hmxl (:,:)
  488. IF( ln_ctl ) THEN
  489. IF( ln_trdmxl_instant ) THEN
  490. CALL prt_ctl(tab2d_1=tmlbb , clinfo1=' tmlbb - : ', mask1=tmask, ovlap=1)
  491. CALL prt_ctl(tab2d_1=tmlbn , clinfo1=' tmlbn - : ', mask1=tmask, ovlap=1)
  492. CALL prt_ctl(tab2d_1=tmlatfb , clinfo1=' tmlatfb - : ', mask1=tmask, ovlap=1)
  493. ELSE
  494. CALL prt_ctl(tab2d_1=tmlbn , clinfo1=' tmlbn - : ', mask1=tmask, ovlap=1)
  495. CALL prt_ctl(tab2d_1=hmxlbn , clinfo1=' hmxlbn - : ', mask1=tmask, ovlap=1)
  496. CALL prt_ctl(tab2d_1=tml_sumb , clinfo1=' tml_sumb - : ', mask1=tmask, ovlap=1)
  497. CALL prt_ctl(tab2d_1=tmltrd_atf_sumb, clinfo1=' tmltrd_atf_sumb - : ', mask1=tmask, ovlap=1)
  498. CALL prt_ctl(tab3d_1=tmltrd_csum_ub , clinfo1=' tmltrd_csum_ub - : ', mask1=tmask, ovlap=1, kdim=1)
  499. END IF
  500. END IF
  501. ! III.4 Convert to appropriate physical units
  502. ! -------------------------------------------
  503. ! ... temperature ... ... salinity ...
  504. ztmltot (:,:) = ztmltot(:,:) * rn_ucf/zfn ; zsmltot (:,:) = zsmltot(:,:) * rn_ucf/zfn
  505. ztmlres (:,:) = ztmlres(:,:) * rn_ucf/zfn ; zsmlres (:,:) = zsmlres(:,:) * rn_ucf/zfn
  506. ztmlatf (:,:) = ztmlatf(:,:) * rn_ucf/zfn ; zsmlatf (:,:) = zsmlatf(:,:) * rn_ucf/zfn
  507. tml_sum (:,:) = tml_sum (:,:) / (2*zfn) ; sml_sum (:,:) = sml_sum (:,:) / (2*zfn)
  508. ztmltot2(:,:) = ztmltot2(:,:) * rn_ucf/zfn2 ; zsmltot2(:,:) = zsmltot2(:,:) * rn_ucf/zfn2
  509. ztmltrd2(:,:,:) = ztmltrd2(:,:,:)* rn_ucf/zfn2 ; zsmltrd2(:,:,:) = zsmltrd2(:,:,:)* rn_ucf/zfn2
  510. ztmlatf2(:,:) = ztmlatf2(:,:) * rn_ucf/zfn2 ; zsmlatf2(:,:) = zsmlatf2(:,:) * rn_ucf/zfn2
  511. ztmlres2(:,:) = ztmlres2(:,:) * rn_ucf/zfn2 ; zsmlres2(:,:) = zsmlres2(:,:) * rn_ucf/zfn2
  512. hmxl_sum(:,:) = hmxl_sum(:,:) / (2*zfn) ! similar to tml_sum and sml_sum
  513. ! * Debugging information *
  514. IF( lldebug ) THEN
  515. !
  516. WRITE(numout,*)
  517. WRITE(numout,*) 'trd_mxl : write trends in the Mixed Layer for debugging process:'
  518. WRITE(numout,*) '~~~~~~~ '
  519. WRITE(numout,*) ' TRA kt = ', kt, 'nmoymltrd = ', nmoymltrd
  520. WRITE(numout,*)
  521. WRITE(numout,*) ' >>>>>>>>>>>>>>>>>> TRA TEMPERATURE <<<<<<<<<<<<<<<<<<'
  522. WRITE(numout,*) ' TRA ztmlres : ', SUM(ztmlres(:,:))
  523. WRITE(numout,*) ' TRA ztmltot : ', SUM(ztmltot(:,:))
  524. WRITE(numout,*) ' TRA tmltrdm : ', SUM(tmltrdm(:,:))
  525. WRITE(numout,*) ' TRA tmlatfb : ', SUM(tmlatfb(:,:))
  526. WRITE(numout,*) ' TRA tmlatfn : ', SUM(tmlatfn(:,:))
  527. DO jl = 1, jpltrd
  528. WRITE(numout,*) ' * TRA TREND INDEX jpmxl_xxx = jl = ', jl, &
  529. & ' tmltrd : ', SUM(tmltrd(:,:,jl))
  530. END DO
  531. WRITE(numout,*) ' TRA ztmlres (jpi/2,jpj/2) : ', ztmlres (jpi/2,jpj/2)
  532. WRITE(numout,*) ' TRA ztmlres2(jpi/2,jpj/2) : ', ztmlres2(jpi/2,jpj/2)
  533. WRITE(numout,*)
  534. WRITE(numout,*) ' >>>>>>>>>>>>>>>>>> TRA SALINITY <<<<<<<<<<<<<<<<<<'
  535. WRITE(numout,*) ' TRA zsmlres : ', SUM(zsmlres(:,:))
  536. WRITE(numout,*) ' TRA zsmltot : ', SUM(zsmltot(:,:))
  537. WRITE(numout,*) ' TRA smltrdm : ', SUM(smltrdm(:,:))
  538. WRITE(numout,*) ' TRA smlatfb : ', SUM(smlatfb(:,:))
  539. WRITE(numout,*) ' TRA smlatfn : ', SUM(smlatfn(:,:))
  540. DO jl = 1, jpltrd
  541. WRITE(numout,*) ' * TRA TREND INDEX jpmxl_xxx = jl = ', jl, &
  542. & ' smltrd : ', SUM(smltrd(:,:,jl))
  543. END DO
  544. WRITE(numout,*) ' TRA zsmlres (jpi/2,jpj/2) : ', zsmlres (jpi/2,jpj/2)
  545. WRITE(numout,*) ' TRA zsmlres2(jpi/2,jpj/2) : ', zsmlres2(jpi/2,jpj/2)
  546. !
  547. END IF
  548. !
  549. END IF MODULO_NTRD
  550. ! ======================================================================
  551. ! IV. Write trends in the NetCDF file
  552. ! ======================================================================
  553. !-- Write the trends for T/S instantaneous diagnostics
  554. IF( ln_trdmxl_instant ) THEN
  555. CALL iom_put( "mxl_depth", hmxl(:,:) )
  556. !................................. ( ML temperature ) ...................................
  557. !-- Output the fields
  558. CALL iom_put( "tml" , tml (:,:) )
  559. CALL iom_put( "tml_tot" , ztmltot(:,:) )
  560. CALL iom_put( "tml_res" , ztmlres(:,:) )
  561. DO jl = 1, jpltrd - 1
  562. CALL iom_put( trim("tml"//ctrd(jl,2)), tmltrd (:,:,jl) )
  563. END DO
  564. CALL iom_put( trim("tml"//ctrd(jpmxl_atf,2)), ztmlatf(:,:) )
  565. !.................................. ( ML salinity ) .....................................
  566. !-- Output the fields
  567. CALL iom_put( "sml" , sml (:,:) )
  568. CALL iom_put( "sml_tot", zsmltot(:,:) )
  569. CALL iom_put( "sml_res", zsmlres(:,:) )
  570. DO jl = 1, jpltrd - 1
  571. CALL iom_put( trim("sml"//ctrd(jl,2)), smltrd(:,:,jl) )
  572. END DO
  573. CALL iom_put( trim("sml"//ctrd(jpmxl_atf,2)), zsmlatf(:,:) )
  574. ELSE !-- Write the trends for T/S mean diagnostics
  575. CALL iom_put( "mxl_depth", hmxl_sum(:,:) )
  576. !................................. ( ML temperature ) ...................................
  577. !-- Output the fields
  578. CALL iom_put( "tml" , tml_sum (:,:) )
  579. CALL iom_put( "tml_tot" , ztmltot2(:,:) )
  580. CALL iom_put( "tml_res" , ztmlres2(:,:) )
  581. DO jl = 1, jpltrd - 1
  582. CALL iom_put( trim("tml"//ctrd(jl,2)), ztmltrd2(:,:,jl) )
  583. END DO
  584. CALL iom_put( trim("tml"//ctrd(jpmxl_atf,2)), ztmlatf2(:,:) )
  585. !.................................. ( ML salinity ) .....................................
  586. !-- Output the fields
  587. CALL iom_put( "sml" , sml_sum (:,:) )
  588. CALL iom_put( "sml_tot", zsmltot2(:,:) )
  589. CALL iom_put( "sml_res", zsmlres2(:,:) )
  590. DO jl = 1, jpltrd - 1
  591. CALL iom_put( trim("sml"//ctrd(jl,2)), zsmltrd2(:,:,jl) )
  592. END DO
  593. CALL iom_put( trim("sml"//ctrd(jpmxl_atf,2)), zsmlatf2(:,:) )
  594. !
  595. END IF
  596. !
  597. IF( MOD( itmod, nn_trd ) == 0 ) THEN
  598. !
  599. ! III.5 Reset cumulative arrays to zero
  600. ! -------------------------------------
  601. nmoymltrd = 0
  602. ! ... temperature ... ... salinity ...
  603. tmltrdm (:,:) = 0.e0 ; smltrdm (:,:) = 0.e0
  604. tmlatfm (:,:) = 0.e0 ; smlatfm (:,:) = 0.e0
  605. tml_sum (:,:) = 0.e0 ; sml_sum (:,:) = 0.e0
  606. tmltrd_csum_ln (:,:,:) = 0.e0 ; smltrd_csum_ln (:,:,:) = 0.e0
  607. tmltrd_sum (:,:,:) = 0.e0 ; smltrd_sum (:,:,:) = 0.e0
  608. hmxl_sum (:,:) = 0.e0
  609. !
  610. END IF
  611. ! ======================================================================
  612. ! V. Write restart file
  613. ! ======================================================================
  614. IF( lrst_oce ) CALL trd_mxl_rst_write( kt )
  615. CALL wrk_dealloc( jpi, jpj, ztmltot , zsmltot , ztmlres , zsmlres , ztmlatf , zsmlatf )
  616. CALL wrk_dealloc( jpi, jpj, ztmltot2, zsmltot2, ztmlres2, zsmlres2, ztmlatf2, zsmlatf2, ztmltrdm2, zsmltrdm2 )
  617. CALL wrk_dealloc( jpi, jpj, jpltrd, ztmltrd2, zsmltrd2 )
  618. !
  619. END SUBROUTINE trd_mxl
  620. SUBROUTINE trd_mxl_init
  621. !!----------------------------------------------------------------------
  622. !! *** ROUTINE trd_mxl_init ***
  623. !!
  624. !! ** Purpose : computation of vertically integrated T and S budgets
  625. !! from ocean surface down to control surface (NetCDF output)
  626. !!----------------------------------------------------------------------
  627. INTEGER :: jl ! dummy loop indices
  628. INTEGER :: inum ! logical unit
  629. INTEGER :: ios ! local integer
  630. REAL(wp) :: zjulian, zsto, zout
  631. CHARACTER (LEN=40) :: clop
  632. CHARACTER (LEN=12) :: clmxl, cltu, clsu
  633. !!
  634. NAMELIST/namtrd_mxl/ nn_trd , cn_trdrst_in , ln_trdmxl_restart, &
  635. & nn_ctls, cn_trdrst_out, ln_trdmxl_instant, rn_ucf, rn_rho_c
  636. !!----------------------------------------------------------------------
  637. !
  638. REWIND( numnam_ref ) ! Namelist namtrd_mxl in reference namelist : mixed layer trends diagnostic
  639. READ ( numnam_ref, namtrd_mxl, IOSTAT = ios, ERR = 901 )
  640. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrd_mxl in reference namelist', lwp )
  641. REWIND( numnam_cfg ) ! Namelist namtrd_mxl in configuration namelist : mixed layer trends diagnostic
  642. READ ( numnam_cfg, namtrd_mxl, IOSTAT = ios, ERR = 902 )
  643. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtrd_mxl in configuration namelist', lwp )
  644. IF(lwm) WRITE( numond, namtrd_mxl )
  645. !
  646. IF(lwp) THEN ! control print
  647. WRITE(numout,*)
  648. WRITE(numout,*) ' trd_mxl_init : Mixed-layer trends'
  649. WRITE(numout,*) ' ~~~~~~~~~~'
  650. WRITE(numout,*) ' Namelist namtrd : set trends parameters'
  651. WRITE(numout,*) ' frequency of trends diagnostics (glo) nn_trd = ', nn_trd
  652. WRITE(numout,*) ' density criteria used to defined the MLD rn_rho_c = ', rn_rho_c
  653. WRITE(numout,*) ' control surface type (mld) nn_ctls = ', nn_ctls
  654. WRITE(numout,*) ' restart for ML diagnostics ln_trdmxl_restart = ', ln_trdmxl_restart
  655. WRITE(numout,*) ' instantaneous or mean ML T/S ln_trdmxl_instant = ', ln_trdmxl_instant
  656. WRITE(numout,*) ' unit conversion factor rn_ucf = ', rn_ucf
  657. WRITE(numout,*) ' criteria to compute the MLD rn_rho_c = ', rn_rho_c
  658. ENDIF
  659. ! I.1 Check consistency of user defined preferences
  660. ! -------------------------------------------------
  661. IF ( rn_rho_c /= rho_c ) CALL ctl_warn( 'Unless you have good reason to do so, you should use the value ', &
  662. & 'defined in zdfmxl.F90 module to calculate the mixed layer depth' )
  663. IF( MOD( nitend, nn_trd ) /= 0 ) THEN
  664. WRITE(numout,cform_err)
  665. WRITE(numout,*) ' Your nitend parameter, nitend = ', nitend
  666. WRITE(numout,*) ' is no multiple of the trends diagnostics frequency '
  667. WRITE(numout,*) ' you defined, nn_trd = ', nn_trd
  668. WRITE(numout,*) ' This will not allow you to restart from this simulation. '
  669. WRITE(numout,*) ' You should reconsider this choice. '
  670. WRITE(numout,*)
  671. WRITE(numout,*) ' N.B. the nitend parameter is also constrained to be a '
  672. WRITE(numout,*) ' multiple of the nn_fsbc parameter '
  673. nstop = nstop + 1
  674. END IF
  675. IF( nn_cla == 1 ) CALL ctl_warn( ' You set n_cla = 1. Note that the Mixed-Layer diagnostics ', &
  676. & ' are not exact along the corresponding straits. ')
  677. ! ! allocate trdmxl arrays
  678. IF( trd_mxl_alloc() /= 0 ) CALL ctl_stop( 'STOP', 'trd_mxl_init : unable to allocate trdmxl arrays' )
  679. IF( trdmxl_oce_alloc() /= 0 ) CALL ctl_stop( 'STOP', 'trd_mxl_init : unable to allocate trdmxl_oce arrays' )
  680. nkstp = nit000 - 1 ! current time step indicator initialization
  681. ! I.2 Initialize arrays to zero or read a restart file
  682. ! ----------------------------------------------------
  683. nmoymltrd = 0
  684. ! ... temperature ... ... salinity ...
  685. tml (:,:) = 0.e0 ; sml (:,:) = 0.e0 ! inst.
  686. tmltrdm (:,:) = 0.e0 ; smltrdm (:,:) = 0.e0
  687. tmlatfm (:,:) = 0.e0 ; smlatfm (:,:) = 0.e0
  688. tml_sum (:,:) = 0.e0 ; sml_sum (:,:) = 0.e0 ! mean
  689. tmltrd_sum (:,:,:) = 0.e0 ; smltrd_sum (:,:,:) = 0.e0
  690. tmltrd_csum_ln (:,:,:) = 0.e0 ; smltrd_csum_ln (:,:,:) = 0.e0
  691. hmxl (:,:) = 0.e0
  692. hmxl_sum (:,:) = 0.e0
  693. IF( ln_rstart .AND. ln_trdmxl_restart ) THEN
  694. CALL trd_mxl_rst_read
  695. ELSE
  696. ! ... temperature ... ... salinity ...
  697. tmlb (:,:) = 0.e0 ; smlb (:,:) = 0.e0 ! inst.
  698. tmlbb (:,:) = 0.e0 ; smlbb (:,:) = 0.e0
  699. tmlbn (:,:) = 0.e0 ; smlbn (:,:) = 0.e0
  700. tml_sumb (:,:) = 0.e0 ; sml_sumb (:,:) = 0.e0 ! mean
  701. tmltrd_csum_ub (:,:,:) = 0.e0 ; smltrd_csum_ub (:,:,:) = 0.e0
  702. tmltrd_atf_sumb(:,:) = 0.e0 ; smltrd_atf_sumb(:,:) = 0.e0
  703. END IF
  704. icount = 1 ; ionce = 1 ! open specifier
  705. ! I.3 Read control surface from file ctlsurf_idx
  706. ! ----------------------------------------------
  707. IF( nn_ctls == 1 ) THEN
  708. CALL ctl_opn( inum, 'ctlsurf_idx', 'OLD', 'UNFORMATTED', 'SEQUENTIAL', -1, numout, lwp )
  709. READ ( inum, * ) nbol
  710. CLOSE( inum )
  711. END IF
  712. ! ======================================================================
  713. ! II. netCDF output initialization
  714. ! ======================================================================
  715. ! clmxl = legend root for netCDF output
  716. IF( nn_ctls == 0 ) THEN ! control surface = mixed-layer with density criterion
  717. clmxl = 'Mixed Layer ' ! (array nmln computed in zdfmxl.F90)
  718. ELSE IF( nn_ctls == 1 ) THEN ! control surface = read index from file
  719. clmxl = ' Bowl '
  720. ELSE IF( nn_ctls >= 2 ) THEN ! control surface = model level
  721. WRITE(clmxl,'(A10,I2,1X)') 'Levels 1 -', nn_ctls
  722. END IF
  723. ! II.3 Define the T grid trend file (nidtrd)
  724. ! ------------------------------------------
  725. !-- Define long and short names for the NetCDF output variables
  726. ! ==> choose them according to trdmxl_oce.F90 <==
  727. ctrd(jpmxl_xad,1) = " Zonal advection" ; ctrd(jpmxl_xad,2) = "_xad"
  728. ctrd(jpmxl_yad,1) = " Meridional advection" ; ctrd(jpmxl_yad,2) = "_yad"
  729. ctrd(jpmxl_zad,1) = " Vertical advection" ; ctrd(jpmxl_zad,2) = "_zad"
  730. ctrd(jpmxl_ldf,1) = " Lateral diffusion" ; ctrd(jpmxl_ldf,2) = "_ldf"
  731. ctrd(jpmxl_for,1) = " Forcing" ; ctrd(jpmxl_for,2) = "_for"
  732. ctrd(jpmxl_zdf,1) = " Vertical diff. (Kz)" ; ctrd(jpmxl_zdf,2) = "_zdf"
  733. ctrd(jpmxl_bbc,1) = " Geothermal flux" ; ctrd(jpmxl_bbc,2) = "_bbc"
  734. ctrd(jpmxl_bbl,1) = " Adv/diff. Bottom boundary layer" ; ctrd(jpmxl_bbl,2) = "_bbl"
  735. ctrd(jpmxl_dmp,1) = " Tracer damping" ; ctrd(jpmxl_dmp,2) = "_dmp"
  736. ctrd(jpmxl_npc,1) = " Non penetrative convec. adjust." ; ctrd(jpmxl_npc,2) = "_npc"
  737. ctrd(jpmxl_atf,1) = " Asselin time filter" ; ctrd(jpmxl_atf,2) = "_atf"
  738. !-- Define physical units
  739. IF ( rn_ucf == 1. ) THEN ; cltu = "degC/s" ; clsu = "p.s.u./s"
  740. ELSEIF ( rn_ucf == 3600.*24.) THEN ; cltu = "degC/day" ; clsu = "p.s.u./day"
  741. ELSE ; cltu = "unknown?" ; clsu = "unknown?"
  742. END IF
  743. !
  744. END SUBROUTINE trd_mxl_init
  745. !!======================================================================
  746. END MODULE trdmxl