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 NEMO/branches/UKMO/NEMO_4.0_mirror_text_diagnostics/src/OCE/TRD – NEMO

source: NEMO/branches/UKMO/NEMO_4.0_mirror_text_diagnostics/src/OCE/TRD/trdmxl.F90 @ 10986

Last change on this file since 10986 was 10986, checked in by andmirek, 5 years ago

GMED 462 add flush

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