New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
trdmxl.F90 in branches/2017/dev_r7881_no_wrk_alloc/NEMOGCM/NEMO/OPA_SRC/TRD – NEMO

source: branches/2017/dev_r7881_no_wrk_alloc/NEMOGCM/NEMO/OPA_SRC/TRD/trdmxl.F90 @ 7910

Last change on this file since 7910 was 7910, checked in by timgraham, 7 years ago

All wrk_alloc removed

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