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.
zdfgls.F90 in NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/ZDF – NEMO

source: NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/ZDF/zdfgls.F90 @ 12340

Last change on this file since 12340 was 12340, checked in by acc, 4 years ago

Branch 2019/dev_r11943_MERGE_2019. This commit introduces basic do loop macro
substitution to the 2019 option 1, merge branch. These changes have been SETTE
tested. The only addition is the do_loop_substitute.h90 file in the OCE directory but
the macros defined therein are used throughout the code to replace identifiable, 2D-
and 3D- nested loop opening and closing statements with single-line alternatives. Code
indents are also adjusted accordingly.

The following explanation is taken from comments in the new header file:

This header file contains preprocessor definitions and macros used in the do-loop
substitutions introduced between version 4.0 and 4.2. The primary aim of these macros
is to assist in future applications of tiling to improve performance. This is expected
to be achieved by alternative versions of these macros in selected locations. The
initial introduction of these macros simply replaces all identifiable nested 2D- and
3D-loops with single line statements (and adjusts indenting accordingly). Do loops
are identifiable if they comform to either:

DO jk = ....

DO jj = .... DO jj = ...

DO ji = .... DO ji = ...
. OR .
. .

END DO END DO

END DO END DO

END DO

and white-space variants thereof.

Additionally, only loops with recognised jj and ji loops limits are treated; these are:
Lower limits of 1, 2 or fs_2
Upper limits of jpi, jpim1 or fs_jpim1 (for ji) or jpj, jpjm1 or fs_jpjm1 (for jj)

The macro naming convention takes the form: DO_2D_BT_LR where:

B is the Bottom offset from the PE's inner domain;
T is the Top offset from the PE's inner domain;
L is the Left offset from the PE's inner domain;
R is the Right offset from the PE's inner domain

So, given an inner domain of 2,jpim1 and 2,jpjm1, a typical example would replace:

DO jj = 2, jpj

DO ji = 1, jpim1
.
.

END DO

END DO

with:

DO_2D_01_10
.
.
END_2D

similar conventions apply to the 3D loops macros. jk loop limits are retained
through macro arguments and are not restricted. This includes the possibility of
strides for which an extra set of DO_3DS macros are defined.

In the example definition below the inner PE domain is defined by start indices of
(kIs, kJs) and end indices of (kIe, KJe)

#define DO_2D_00_00 DO jj = kJs, kJe ; DO ji = kIs, kIe
#define END_2D END DO ; END DO

TO DO:


Only conventional nested loops have been identified and replaced by this step. There are constructs such as:

DO jk = 2, jpkm1

z2d(:,:) = z2d(:,:) + e3w(:,:,jk,Kmm) * z3d(:,:,jk) * wmask(:,:,jk)

END DO

which may need to be considered.

  • Property svn:keywords set to Id
File size: 54.4 KB
Line 
1MODULE zdfgls
2   !!======================================================================
3   !!                       ***  MODULE  zdfgls  ***
4   !! Ocean physics:  vertical mixing coefficient computed from the gls
5   !!                 turbulent closure parameterization
6   !!======================================================================
7   !! History :  3.0  !  2009-09  (G. Reffray)  Original code
8   !!            3.3  !  2010-10  (C. Bricaud)  Add in the reference
9   !!            4.0  !  2017-04  (G. Madec)  remove CPP keys & avm at t-point only
10   !!             -   !  2017-05  (G. Madec)  add top friction as boundary condition
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   zdf_gls       : update momentum and tracer Kz from a gls scheme
15   !!   zdf_gls_init  : initialization, namelist read, and parameters control
16   !!   gls_rst       : read/write gls restart in ocean restart file
17   !!----------------------------------------------------------------------
18   USE oce            ! ocean dynamics and active tracers
19   USE dom_oce        ! ocean space and time domain
20   USE domvvl         ! ocean space and time domain : variable volume layer
21   USE zdfdrg  , ONLY : r_z0_top , r_z0_bot   ! top/bottom roughness
22   USE zdfdrg  , ONLY : rCdU_top , rCdU_bot   ! top/bottom friction
23   USE sbc_oce        ! surface boundary condition: ocean
24   USE phycst         ! physical constants
25   USE zdfmxl         ! mixed layer
26   USE sbcwave , ONLY : hsw   ! significant wave height
27   !
28   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
29   USE lib_mpp        ! MPP manager
30   USE prtctl         ! Print control
31   USE in_out_manager ! I/O manager
32   USE iom            ! I/O manager library
33   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
34
35   IMPLICIT NONE
36   PRIVATE
37
38   PUBLIC   zdf_gls        ! called in zdfphy
39   PUBLIC   zdf_gls_init   ! called in zdfphy
40   PUBLIC   gls_rst        ! called in zdfphy
41
42   !
43   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   hmxl_n    !: now mixing length
44   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zwall   !: wall function
45   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_surf !: Squared surface velocity scale at T-points
46   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_top  !: Squared top     velocity scale at T-points
47   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ustar2_bot  !: Squared bottom  velocity scale at T-points
48
49   !                              !! ** Namelist  namzdf_gls  **
50   LOGICAL  ::   ln_length_lim     ! use limit on the dissipation rate under stable stratification (Galperin et al. 1988)
51   LOGICAL  ::   ln_sigpsi         ! Activate Burchard (2003) modification for k-eps closure & wave breaking mixing
52   INTEGER  ::   nn_bc_surf        ! surface boundary condition (=0/1)
53   INTEGER  ::   nn_bc_bot         ! bottom boundary condition (=0/1)
54   INTEGER  ::   nn_z0_met         ! Method for surface roughness computation
55   INTEGER  ::   nn_stab_func      ! stability functions G88, KC or Canuto (=0/1/2)
56   INTEGER  ::   nn_clos           ! closure 0/1/2/3 MY82/k-eps/k-w/gen
57   REAL(wp) ::   rn_clim_galp      ! Holt 2008 value for k-eps: 0.267
58   REAL(wp) ::   rn_epsmin         ! minimum value of dissipation (m2/s3)
59   REAL(wp) ::   rn_emin           ! minimum value of TKE (m2/s2)
60   REAL(wp) ::   rn_charn          ! Charnock constant for surface breaking waves mixing : 1400. (standard) or 2.e5 (Stacey value)
61   REAL(wp) ::   rn_crban          ! Craig and Banner constant for surface breaking waves mixing
62   REAL(wp) ::   rn_hsro           ! Minimum surface roughness
63   REAL(wp) ::   rn_frac_hs        ! Fraction of wave height as surface roughness (if nn_z0_met > 1)
64
65   REAL(wp) ::   rcm_sf        =  0.73_wp     ! Shear free turbulence parameters
66   REAL(wp) ::   ra_sf         = -2.0_wp      ! Must be negative -2 < ra_sf < -1
67   REAL(wp) ::   rl_sf         =  0.2_wp      ! 0 <rl_sf<vkarmn   
68   REAL(wp) ::   rghmin        = -0.28_wp
69   REAL(wp) ::   rgh0          =  0.0329_wp
70   REAL(wp) ::   rghcri        =  0.03_wp
71   REAL(wp) ::   ra1           =  0.92_wp
72   REAL(wp) ::   ra2           =  0.74_wp
73   REAL(wp) ::   rb1           = 16.60_wp
74   REAL(wp) ::   rb2           = 10.10_wp         
75   REAL(wp) ::   re2           =  1.33_wp         
76   REAL(wp) ::   rl1           =  0.107_wp
77   REAL(wp) ::   rl2           =  0.0032_wp
78   REAL(wp) ::   rl3           =  0.0864_wp
79   REAL(wp) ::   rl4           =  0.12_wp
80   REAL(wp) ::   rl5           = 11.9_wp
81   REAL(wp) ::   rl6           =  0.4_wp
82   REAL(wp) ::   rl7           =  0.0_wp
83   REAL(wp) ::   rl8           =  0.48_wp
84   REAL(wp) ::   rm1           =  0.127_wp
85   REAL(wp) ::   rm2           =  0.00336_wp
86   REAL(wp) ::   rm3           =  0.0906_wp
87   REAL(wp) ::   rm4           =  0.101_wp
88   REAL(wp) ::   rm5           = 11.2_wp
89   REAL(wp) ::   rm6           =  0.4_wp
90   REAL(wp) ::   rm7           =  0.0_wp
91   REAL(wp) ::   rm8           =  0.318_wp
92   REAL(wp) ::   rtrans        =  0.1_wp
93   REAL(wp) ::   rc02, rc02r, rc03, rc04                          ! coefficients deduced from above parameters
94   REAL(wp) ::   rsbc_tke1, rsbc_tke2, rfact_tke                  !     -           -           -        -
95   REAL(wp) ::   rsbc_psi1, rsbc_psi2, rfact_psi                  !     -           -           -        -
96   REAL(wp) ::   rsbc_zs1, rsbc_zs2                               !     -           -           -        -
97   REAL(wp) ::   rc0, rc2, rc3, rf6, rcff, rc_diff                !     -           -           -        -
98   REAL(wp) ::   rs0, rs1, rs2, rs4, rs5, rs6                     !     -           -           -        -
99   REAL(wp) ::   rd0, rd1, rd2, rd3, rd4, rd5                     !     -           -           -        -
100   REAL(wp) ::   rsc_tke, rsc_psi, rpsi1, rpsi2, rpsi3, rsc_psi0  !     -           -           -        -
101   REAL(wp) ::   rpsi3m, rpsi3p, rpp, rmm, rnn                    !     -           -           -        -
102   !
103   REAL(wp) ::   r2_3 = 2._wp/3._wp   ! constant=2/3
104
105   !! * Substitutions
106#  include "vectopt_loop_substitute.h90"
107#  include "do_loop_substitute.h90"
108   !!----------------------------------------------------------------------
109   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
110   !! $Id$
111   !! Software governed by the CeCILL license (see ./LICENSE)
112   !!----------------------------------------------------------------------
113CONTAINS
114
115   INTEGER FUNCTION zdf_gls_alloc()
116      !!----------------------------------------------------------------------
117      !!                ***  FUNCTION zdf_gls_alloc  ***
118      !!----------------------------------------------------------------------
119      ALLOCATE( hmxl_n(jpi,jpj,jpk) , ustar2_surf(jpi,jpj) ,                     &
120         &      zwall (jpi,jpj,jpk) , ustar2_top (jpi,jpj) , ustar2_bot(jpi,jpj) , STAT= zdf_gls_alloc )
121         !
122      CALL mpp_sum ( 'zdfgls', zdf_gls_alloc )
123      IF( zdf_gls_alloc /= 0 )   CALL ctl_stop( 'STOP', 'zdf_gls_alloc: failed to allocate arrays' )
124   END FUNCTION zdf_gls_alloc
125
126
127   SUBROUTINE zdf_gls( kt, Kbb, Kmm, p_sh2, p_avm, p_avt )
128      !!----------------------------------------------------------------------
129      !!                   ***  ROUTINE zdf_gls  ***
130      !!
131      !! ** Purpose :   Compute the vertical eddy viscosity and diffusivity
132      !!              coefficients using the GLS turbulent closure scheme.
133      !!----------------------------------------------------------------------
134      USE zdf_oce , ONLY : en, avtb, avmb   ! ocean vertical physics
135      !!
136      INTEGER                   , INTENT(in   ) ::   kt             ! ocean time step
137      INTEGER                   , INTENT(in   ) ::   Kbb, Kmm       ! ocean time level indices
138      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   p_sh2          ! shear production term
139      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   p_avm, p_avt   !  momentum and tracer Kz (w-points)
140      !
141      INTEGER  ::   ji, jj, jk    ! dummy loop arguments
142      INTEGER  ::   ibot, ibotm1  ! local integers
143      INTEGER  ::   itop, itopp1  !   -       -
144      REAL(wp) ::   zesh2, zsigpsi, zcoef, zex1 , zex2  ! local scalars
145      REAL(wp) ::   ztx2, zty2, zup, zdown, zcof, zdir  !   -      -
146      REAL(wp) ::   zratio, zrn2, zflxb, sh     , z_en  !   -      -
147      REAL(wp) ::   prod, buoy, diss, zdiss, sm         !   -      -
148      REAL(wp) ::   gh, gm, shr, dif, zsqen, zavt, zavm !   -      -
149      REAL(wp) ::   zmsku, zmskv                        !   -      -
150      REAL(wp), DIMENSION(jpi,jpj)     ::   zdep
151      REAL(wp), DIMENSION(jpi,jpj)     ::   zkar
152      REAL(wp), DIMENSION(jpi,jpj)     ::   zflxs       ! Turbulence fluxed induced by internal waves
153      REAL(wp), DIMENSION(jpi,jpj)     ::   zhsro       ! Surface roughness (surface waves)
154      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   eb          ! tke at time before
155      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   hmxl_b      ! mixing length at time before
156      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   eps         ! dissipation rate
157      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwall_psi   ! Wall function use in the wb case (ln_sigpsi)
158      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   psi         ! psi at time now
159      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zd_lw, zd_up, zdiag   ! lower, upper  and diagonal of the matrix
160      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zstt, zstm  ! stability function on tracer and momentum
161      !!--------------------------------------------------------------------
162      !
163      ! Preliminary computing
164
165      ustar2_surf(:,:) = 0._wp   ;         psi(:,:,:) = 0._wp   
166      ustar2_top (:,:) = 0._wp   ;   zwall_psi(:,:,:) = 0._wp
167      ustar2_bot (:,:) = 0._wp
168
169      ! Compute surface, top and bottom friction at T-points
170      DO_2D_00_00
171         !
172         ! surface friction
173         ustar2_surf(ji,jj) = r1_rau0 * taum(ji,jj) * tmask(ji,jj,1)
174         !   
175!!gm Rq we may add here r_ke0(_top/_bot) ?  ==>> think about that...
176       ! bottom friction (explicit before friction)
177       zmsku = ( 2._wp - umask(ji-1,jj,mbkt(ji,jj)) * umask(ji,jj,mbkt(ji,jj)) )
178       zmskv = ( 2._wp - vmask(ji,jj-1,mbkt(ji,jj)) * vmask(ji,jj,mbkt(ji,jj)) )     ! (CAUTION: CdU<0)
179       ustar2_bot(ji,jj) = - rCdU_bot(ji,jj) * SQRT(  ( zmsku*( uu(ji,jj,mbkt(ji,jj),Kbb)+uu(ji-1,jj,mbkt(ji,jj),Kbb) ) )**2  &
180          &                                         + ( zmskv*( vv(ji,jj,mbkt(ji,jj),Kbb)+vv(ji,jj-1,mbkt(ji,jj),Kbb) ) )**2  )
181      END_2D
182      IF( ln_isfcav ) THEN       !top friction
183         DO_2D_00_00
184            zmsku = ( 2. - umask(ji-1,jj,mikt(ji,jj)) * umask(ji,jj,mikt(ji,jj)) )
185            zmskv = ( 2. - vmask(ji,jj-1,mikt(ji,jj)) * vmask(ji,jj,mikt(ji,jj)) )     ! (CAUTION: CdU<0)
186            ustar2_top(ji,jj) = - rCdU_top(ji,jj) * SQRT(  ( zmsku*( uu(ji,jj,mikt(ji,jj),Kbb)+uu(ji-1,jj,mikt(ji,jj),Kbb) ) )**2  &
187               &                                         + ( zmskv*( vv(ji,jj,mikt(ji,jj),Kbb)+vv(ji,jj-1,mikt(ji,jj),Kbb) ) )**2  )
188         END_2D
189      ENDIF
190   
191      SELECT CASE ( nn_z0_met )      !==  Set surface roughness length  ==!
192      CASE ( 0 )                          ! Constant roughness         
193         zhsro(:,:) = rn_hsro
194      CASE ( 1 )             ! Standard Charnock formula
195         zhsro(:,:) = MAX( rsbc_zs1 * ustar2_surf(:,:) , rn_hsro )
196      CASE ( 2 )             ! Roughness formulae according to Rascle et al., Ocean Modelling (2008)
197!!gm faster coding : the 2 comment lines should be used
198!!gm         zcof = 2._wp * 0.6_wp / 28._wp
199!!gm         zdep(:,:)  = 30._wp * TANH(  zcof/ SQRT( MAX(ustar2_surf(:,:),rsmall) )  )       ! Wave age (eq. 10)
200         zdep (:,:) = 30.*TANH( 2.*0.3/(28.*SQRT(MAX(ustar2_surf(:,:),rsmall))) )         ! Wave age (eq. 10)
201         zhsro(:,:) = MAX(rsbc_zs2 * ustar2_surf(:,:) * zdep(:,:)**1.5, rn_hsro)          ! zhsro = rn_frac_hs * Hsw (eq. 11)
202      CASE ( 3 )             ! Roughness given by the wave model (coupled or read in file)
203         zhsro(:,:) = rn_frac_hs * hsw(:,:)   ! (rn_frac_hs=1.6 see Eq. (5) of Rascle et al. 2008 )
204      END SELECT
205      !
206      DO_3D_10_10( 2, jpkm1 )
207         eps(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / hmxl_n(ji,jj,jk)
208      END_3D
209
210      ! Save tke at before time step
211      eb    (:,:,:) = en    (:,:,:)
212      hmxl_b(:,:,:) = hmxl_n(:,:,:)
213
214      IF( nn_clos == 0 ) THEN    ! Mellor-Yamada
215         DO_3D_00_00( 2, jpkm1 )
216            zup   = hmxl_n(ji,jj,jk) * gdepw(ji,jj,mbkt(ji,jj)+1,Kmm)
217            zdown = vkarmn * gdepw(ji,jj,jk,Kmm) * ( -gdepw(ji,jj,jk,Kmm) + gdepw(ji,jj,mbkt(ji,jj)+1,Kmm) )
218            zcoef = ( zup / MAX( zdown, rsmall ) )
219            zwall (ji,jj,jk) = ( 1._wp + re2 * zcoef*zcoef ) * tmask(ji,jj,jk)
220         END_3D
221      ENDIF
222
223      !!---------------------------------!!
224      !!   Equation to prognostic k      !!
225      !!---------------------------------!!
226      !
227      ! Now Turbulent kinetic energy (output in en)
228      ! -------------------------------
229      ! Resolution of a tridiagonal linear system by a "methode de chasse"
230      ! computation from level 2 to jpkm1  (e(1) computed after and e(jpk)=0 ).
231      ! The surface boundary condition are set after
232      ! The bottom boundary condition are also set after. In standard e(bottom)=0.
233      ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
234      ! Warning : after this step, en : right hand side of the matrix
235
236      DO_3D_00_00( 2, jpkm1 )
237         !
238         buoy = - p_avt(ji,jj,jk) * rn2(ji,jj,jk)     ! stratif. destruction
239         !
240         diss = eps(ji,jj,jk)                         ! dissipation
241         !
242         zdir = 0.5_wp + SIGN( 0.5_wp, p_sh2(ji,jj,jk) + buoy )   ! zdir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
243         !
244         zesh2 = zdir*(p_sh2(ji,jj,jk)+buoy)+(1._wp-zdir)*p_sh2(ji,jj,jk)          ! production term
245         zdiss = zdir*(diss/en(ji,jj,jk))   +(1._wp-zdir)*(diss-buoy)/en(ji,jj,jk) ! dissipation term
246!!gm better coding, identical results
247!               zesh2 =   p_sh2(ji,jj,jk) + zdir*buoy               ! production term
248!               zdiss = ( diss - (1._wp-zdir)*buoy ) / en(ji,jj,jk) ! dissipation term
249!!gm
250         !
251         ! Compute a wall function from 1. to rsc_psi*zwall/rsc_psi0
252         ! Note that as long that Dirichlet boundary conditions are NOT set at the first and last levels (GOTM style)
253         ! there is no need to set a boundary condition for zwall_psi at the top and bottom boundaries.
254         ! Otherwise, this should be rsc_psi/rsc_psi0
255         IF( ln_sigpsi ) THEN
256            zsigpsi = MIN( 1._wp, zesh2 / eps(ji,jj,jk) )     ! 0. <= zsigpsi <= 1.
257            zwall_psi(ji,jj,jk) = rsc_psi /   & 
258               &     (  zsigpsi * rsc_psi + (1._wp-zsigpsi) * rsc_psi0 / MAX( zwall(ji,jj,jk), 1._wp )  )
259         ELSE
260            zwall_psi(ji,jj,jk) = 1._wp
261         ENDIF
262         !
263         ! building the matrix
264         zcof = rfact_tke * tmask(ji,jj,jk)
265         !                                        ! lower diagonal, in fact not used for jk = 2 (see surface conditions)
266         zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t(ji,jj,jk-1,Kmm) * e3w(ji,jj,jk,Kmm) )
267         !                                        ! upper diagonal, in fact not used for jk = ibotm1 (see bottom conditions)
268         zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t(ji,jj,jk  ,Kmm) * e3w(ji,jj,jk,Kmm) )
269         !                                        ! diagonal
270         zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk)  + rdt * zdiss * wmask(ji,jj,jk) 
271         !                                        ! right hand side in en
272         en(ji,jj,jk) = en(ji,jj,jk) + rdt * zesh2 * wmask(ji,jj,jk)
273      END_3D
274      !
275      zdiag(:,:,jpk) = 1._wp
276      !
277      ! Set surface condition on zwall_psi (1 at the bottom)
278      zwall_psi(:,:, 1 ) = zwall_psi(:,:,2)
279      zwall_psi(:,:,jpk) = 1._wp
280      !
281      ! Surface boundary condition on tke
282      ! ---------------------------------
283      !
284      SELECT CASE ( nn_bc_surf )
285      !
286      CASE ( 0 )             ! Dirichlet boundary condition (set e at k=1 & 2)
287      ! First level
288      en   (:,:,1) = MAX(  rn_emin , rc02r * ustar2_surf(:,:) * (1._wp + rsbc_tke1)**r2_3  )
289      zd_lw(:,:,1) = en(:,:,1)
290      zd_up(:,:,1) = 0._wp
291      zdiag(:,:,1) = 1._wp
292      !
293      ! One level below
294      en   (:,:,2) =  MAX(  rc02r * ustar2_surf(:,:) * (  1._wp + rsbc_tke1 * ((zhsro(:,:)+gdepw(:,:,2,Kmm))   &
295         &                 / zhsro(:,:) )**(1.5_wp*ra_sf)  )**(2._wp/3._wp)                      , rn_emin   )
296      zd_lw(:,:,2) = 0._wp 
297      zd_up(:,:,2) = 0._wp
298      zdiag(:,:,2) = 1._wp
299      !
300      !
301      CASE ( 1 )             ! Neumann boundary condition (set d(e)/dz)
302      !
303      ! Dirichlet conditions at k=1
304      en   (:,:,1) = MAX(  rc02r * ustar2_surf(:,:) * (1._wp + rsbc_tke1)**r2_3 , rn_emin  )
305      zd_lw(:,:,1) = en(:,:,1)
306      zd_up(:,:,1) = 0._wp
307      zdiag(:,:,1) = 1._wp
308      !
309      ! at k=2, set de/dz=Fw
310      !cbr
311      zdiag(:,:,2) = zdiag(:,:,2) +  zd_lw(:,:,2) ! Remove zd_lw from zdiag
312      zd_lw(:,:,2) = 0._wp
313      zkar (:,:)   = (rl_sf + (vkarmn-rl_sf)*(1.-EXP(-rtrans*gdept(:,:,1,Kmm)/zhsro(:,:)) ))
314      zflxs(:,:)   = rsbc_tke2 * ustar2_surf(:,:)**1.5_wp * zkar(:,:) &
315          &                    * (  ( zhsro(:,:)+gdept(:,:,1,Kmm) ) / zhsro(:,:)  )**(1.5_wp*ra_sf)
316!!gm why not   :                        * ( 1._wp + gdept(:,:,1,Kmm) / zhsro(:,:) )**(1.5_wp*ra_sf)
317      en(:,:,2) = en(:,:,2) + zflxs(:,:) / e3w(:,:,2,Kmm)
318      !
319      !
320      END SELECT
321
322      ! Bottom boundary condition on tke
323      ! --------------------------------
324      !
325      SELECT CASE ( nn_bc_bot )
326      !
327      CASE ( 0 )             ! Dirichlet
328         !                      ! en(ibot) = u*^2 / Co2 and hmxl_n(ibot) = rn_lmin
329         !                      ! Balance between the production and the dissipation terms
330         DO_2D_00_00
331!!gm This means that bottom and ocean w-level above have a specified "en" value.   Sure ????
332!!   With thick deep ocean level thickness, this may be quite large, no ???
333!!   in particular in ocean cavities where top stratification can be large...
334            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
335            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
336            !
337            z_en =  MAX( rc02r * ustar2_bot(ji,jj), rn_emin )
338            !
339            ! Dirichlet condition applied at:
340            !     Bottom level (ibot)      &      Just above it (ibotm1)   
341            zd_lw(ji,jj,ibot) = 0._wp   ;   zd_lw(ji,jj,ibotm1) = 0._wp
342            zd_up(ji,jj,ibot) = 0._wp   ;   zd_up(ji,jj,ibotm1) = 0._wp
343            zdiag(ji,jj,ibot) = 1._wp   ;   zdiag(ji,jj,ibotm1) = 1._wp
344            en   (ji,jj,ibot) = z_en    ;   en   (ji,jj,ibotm1) = z_en
345         END_2D
346         !
347         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
348            DO_2D_00_00
349               itop   = mikt(ji,jj)       ! k   top w-point
350               itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
351               !                                                ! mask at the ocean surface points
352               z_en = MAX( rc02r * ustar2_top(ji,jj), rn_emin ) * ( 1._wp - tmask(ji,jj,1) )
353               !
354 !!gm TO BE VERIFIED !!!
355               ! Dirichlet condition applied at:
356               !     top level (itop)         &      Just below it (itopp1)   
357               zd_lw(ji,jj,itop) = 0._wp   ;   zd_lw(ji,jj,itopp1) = 0._wp
358               zd_up(ji,jj,itop) = 0._wp   ;   zd_up(ji,jj,itopp1) = 0._wp
359               zdiag(ji,jj,itop) = 1._wp   ;   zdiag(ji,jj,itopp1) = 1._wp
360               en   (ji,jj,itop) = z_en    ;   en   (ji,jj,itopp1) = z_en
361            END_2D
362         ENDIF
363         !
364      CASE ( 1 )             ! Neumman boundary condition
365         !                     
366         DO_2D_00_00
367            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
368            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
369            !
370            z_en =  MAX( rc02r * ustar2_bot(ji,jj), rn_emin )
371            !
372            ! Bottom level Dirichlet condition:
373            !     Bottom level (ibot)      &      Just above it (ibotm1)   
374            !         Dirichlet            !         Neumann
375            zd_lw(ji,jj,ibot) = 0._wp   !   ! Remove zd_up from zdiag
376            zdiag(ji,jj,ibot) = 1._wp   ;   zdiag(ji,jj,ibotm1) = zdiag(ji,jj,ibotm1) + zd_up(ji,jj,ibotm1)
377            zd_up(ji,jj,ibot) = 0._wp   ;   zd_up(ji,jj,ibotm1) = 0._wp
378         END_2D
379         IF( ln_isfcav) THEN     ! top boundary   (ocean cavity)
380            DO_2D_00_00
381               itop   = mikt(ji,jj)       ! k   top w-point
382               itopp1 = mikt(ji,jj) + 1   ! k+1 1st w-point below the top one
383               !                                                ! mask at the ocean surface points
384               z_en = MAX( rc02r * ustar2_top(ji,jj), rn_emin ) * ( 1._wp - tmask(ji,jj,1) )
385               !
386               ! Bottom level Dirichlet condition:
387               !     Bottom level (ibot)      &      Just above it (ibotm1)   
388               !         Dirichlet            !         Neumann
389               zd_lw(ji,jj,itop) = 0._wp   !   ! Remove zd_up from zdiag
390               zdiag(ji,jj,itop) = 1._wp   ;   zdiag(ji,jj,itopp1) = zdiag(ji,jj,itopp1) + zd_up(ji,jj,itopp1)
391               zd_up(ji,jj,itop) = 0._wp   ;   zd_up(ji,jj,itopp1) = 0._wp
392            END_2D
393         ENDIF
394         !
395      END SELECT
396
397      ! Matrix inversion (en prescribed at surface and the bottom)
398      ! ----------------------------------------------------------
399      !
400      DO_3D_00_00( 2, jpkm1 )
401         zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
402      END_3D
403      DO_3D_00_00( 2, jpk )
404         zd_lw(ji,jj,jk) = en(ji,jj,jk) - zd_lw(ji,jj,jk) / zdiag(ji,jj,jk-1) * zd_lw(ji,jj,jk-1)
405      END_3D
406      DO_3DS_00_00( jpk-1, 2, -1 )
407         en(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * en(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
408      END_3D
409      !                                            ! set the minimum value of tke
410      en(:,:,:) = MAX( en(:,:,:), rn_emin )
411
412      !!----------------------------------------!!
413      !!   Solve prognostic equation for psi    !!
414      !!----------------------------------------!!
415
416      ! Set psi to previous time step value
417      !
418      SELECT CASE ( nn_clos )
419      !
420      CASE( 0 )               ! k-kl  (Mellor-Yamada)
421         DO_3D_00_00( 2, jpkm1 )
422            psi(ji,jj,jk)  = eb(ji,jj,jk) * hmxl_b(ji,jj,jk)
423         END_3D
424         !
425      CASE( 1 )               ! k-eps
426         DO_3D_00_00( 2, jpkm1 )
427            psi(ji,jj,jk)  = eps(ji,jj,jk)
428         END_3D
429         !
430      CASE( 2 )               ! k-w
431         DO_3D_00_00( 2, jpkm1 )
432            psi(ji,jj,jk)  = SQRT( eb(ji,jj,jk) ) / ( rc0 * hmxl_b(ji,jj,jk) )
433         END_3D
434         !
435      CASE( 3 )               ! generic
436         DO_3D_00_00( 2, jpkm1 )
437            psi(ji,jj,jk)  = rc02 * eb(ji,jj,jk) * hmxl_b(ji,jj,jk)**rnn 
438         END_3D
439         !
440      END SELECT
441      !
442      ! Now gls (output in psi)
443      ! -------------------------------
444      ! Resolution of a tridiagonal linear system by a "methode de chasse"
445      ! computation from level 2 to jpkm1  (e(1) already computed and e(jpk)=0 ).
446      ! zdiag : diagonal zd_up : upper diagonal zd_lw : lower diagonal
447      ! Warning : after this step, en : right hand side of the matrix
448
449      DO_3D_00_00( 2, jpkm1 )
450         !
451         ! psi / k
452         zratio = psi(ji,jj,jk) / eb(ji,jj,jk) 
453         !
454         ! psi3+ : stable : B=-KhN²<0 => N²>0 if rn2>0 zdir = 1 (stable) otherwise zdir = 0 (unstable)
455         zdir = 0.5_wp + SIGN( 0.5_wp, rn2(ji,jj,jk) )
456         !
457         rpsi3 = zdir * rpsi3m + ( 1._wp - zdir ) * rpsi3p
458         !
459         ! shear prod. - stratif. destruction
460         prod = rpsi1 * zratio * p_sh2(ji,jj,jk)
461         !
462         ! stratif. destruction
463         buoy = rpsi3 * zratio * (- p_avt(ji,jj,jk) * rn2(ji,jj,jk) )
464         !
465         ! shear prod. - stratif. destruction
466         diss = rpsi2 * zratio * zwall(ji,jj,jk) * eps(ji,jj,jk)
467         !
468         zdir = 0.5_wp + SIGN( 0.5_wp, prod + buoy )     ! zdir =1(=0) if shear(ji,jj,jk)+buoy >0(<0)
469         !
470         zesh2 = zdir * ( prod + buoy )          + (1._wp - zdir ) * prod                        ! production term
471         zdiss = zdir * ( diss / psi(ji,jj,jk) ) + (1._wp - zdir ) * (diss-buoy) / psi(ji,jj,jk) ! dissipation term
472         !                                                       
473         ! building the matrix
474         zcof = rfact_psi * zwall_psi(ji,jj,jk) * tmask(ji,jj,jk)
475         !                                               ! lower diagonal
476         zd_lw(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk  ) + p_avm(ji,jj,jk-1) ) / ( e3t(ji,jj,jk-1,Kmm) * e3w(ji,jj,jk,Kmm) )
477         !                                               ! upper diagonal
478         zd_up(ji,jj,jk) = zcof * ( p_avm(ji,jj,jk+1) + p_avm(ji,jj,jk  ) ) / ( e3t(ji,jj,jk  ,Kmm) * e3w(ji,jj,jk,Kmm) )
479         !                                               ! diagonal
480         zdiag(ji,jj,jk) = 1._wp - zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) + rdt * zdiss * wmask(ji,jj,jk)
481         !                                               ! right hand side in psi
482         psi(ji,jj,jk) = psi(ji,jj,jk) + rdt * zesh2 * wmask(ji,jj,jk)
483      END_3D
484      !
485      zdiag(:,:,jpk) = 1._wp
486
487      ! Surface boundary condition on psi
488      ! ---------------------------------
489      !
490      SELECT CASE ( nn_bc_surf )
491      !
492      CASE ( 0 )             ! Dirichlet boundary conditions
493         !
494         ! Surface value
495         zdep    (:,:)   = zhsro(:,:) * rl_sf ! Cosmetic
496         psi     (:,:,1) = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
497         zd_lw(:,:,1) = psi(:,:,1)
498         zd_up(:,:,1) = 0._wp
499         zdiag(:,:,1) = 1._wp
500         !
501         ! One level below
502         zkar    (:,:)   = (rl_sf + (vkarmn-rl_sf)*(1._wp-EXP(-rtrans*gdepw(:,:,2,Kmm)/zhsro(:,:) )))
503         zdep    (:,:)   = (zhsro(:,:) + gdepw(:,:,2,Kmm)) * zkar(:,:)
504         psi     (:,:,2) = rc0**rpp * en(:,:,2)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
505         zd_lw(:,:,2) = 0._wp
506         zd_up(:,:,2) = 0._wp
507         zdiag(:,:,2) = 1._wp
508         !
509      CASE ( 1 )             ! Neumann boundary condition on d(psi)/dz
510         !
511         ! Surface value: Dirichlet
512         zdep    (:,:)   = zhsro(:,:) * rl_sf
513         psi     (:,:,1) = rc0**rpp * en(:,:,1)**rmm * zdep(:,:)**rnn * tmask(:,:,1)
514         zd_lw(:,:,1) = psi(:,:,1)
515         zd_up(:,:,1) = 0._wp
516         zdiag(:,:,1) = 1._wp
517         !
518         ! Neumann condition at k=2
519         zdiag(:,:,2) = zdiag(:,:,2) +  zd_lw(:,:,2) ! Remove zd_lw from zdiag
520         zd_lw(:,:,2) = 0._wp
521         !
522         ! Set psi vertical flux at the surface:
523         zkar (:,:)   = rl_sf + (vkarmn-rl_sf)*(1._wp-EXP(-rtrans*gdept(:,:,1,Kmm)/zhsro(:,:) )) ! Lengh scale slope
524         zdep (:,:)   = ((zhsro(:,:) + gdept(:,:,1,Kmm)) / zhsro(:,:))**(rmm*ra_sf)
525         zflxs(:,:)   = (rnn + rsbc_tke1 * (rnn + rmm*ra_sf) * zdep(:,:))*(1._wp + rsbc_tke1*zdep(:,:))**(2._wp*rmm/3._wp-1_wp)
526         zdep (:,:)   = rsbc_psi1 * (zwall_psi(:,:,1)*p_avm(:,:,1)+zwall_psi(:,:,2)*p_avm(:,:,2)) * &
527            &           ustar2_surf(:,:)**rmm * zkar(:,:)**rnn * (zhsro(:,:) + gdept(:,:,1,Kmm))**(rnn-1.)
528         zflxs(:,:)   = zdep(:,:) * zflxs(:,:)
529         psi  (:,:,2) = psi(:,:,2) + zflxs(:,:) / e3w(:,:,2,Kmm)
530         !
531      END SELECT
532
533      ! Bottom boundary condition on psi
534      ! --------------------------------
535      !
536!!gm should be done for ISF (top boundary cond.)
537!!gm so, totally new staff needed      ===>>> think about that !
538!
539      SELECT CASE ( nn_bc_bot )     ! bottom boundary
540      !
541      CASE ( 0 )             ! Dirichlet
542         !                      ! en(ibot) = u*^2 / Co2 and hmxl_n(ibot) = vkarmn * r_z0_bot
543         !                      ! Balance between the production and the dissipation terms
544         DO_2D_00_00
545            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
546            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
547            zdep(ji,jj) = vkarmn * r_z0_bot
548            psi (ji,jj,ibot) = rc0**rpp * en(ji,jj,ibot)**rmm * zdep(ji,jj)**rnn
549            zd_lw(ji,jj,ibot) = 0._wp
550            zd_up(ji,jj,ibot) = 0._wp
551            zdiag(ji,jj,ibot) = 1._wp
552            !
553            ! Just above last level, Dirichlet condition again (GOTM like)
554            zdep(ji,jj) = vkarmn * ( r_z0_bot + e3t(ji,jj,ibotm1,Kmm) )
555            psi (ji,jj,ibotm1) = rc0**rpp * en(ji,jj,ibot  )**rmm * zdep(ji,jj)**rnn
556            zd_lw(ji,jj,ibotm1) = 0._wp
557            zd_up(ji,jj,ibotm1) = 0._wp
558            zdiag(ji,jj,ibotm1) = 1._wp
559         END_2D
560         !
561      CASE ( 1 )             ! Neumman boundary condition
562         !                     
563         DO_2D_00_00
564            ibot   = mbkt(ji,jj) + 1      ! k   bottom level of w-point
565            ibotm1 = mbkt(ji,jj)          ! k-1 bottom level of w-point but >=1
566            !
567            ! Bottom level Dirichlet condition:
568            zdep(ji,jj) = vkarmn * r_z0_bot
569            psi (ji,jj,ibot) = rc0**rpp * en(ji,jj,ibot)**rmm * zdep(ji,jj)**rnn
570            !
571            zd_lw(ji,jj,ibot) = 0._wp
572            zd_up(ji,jj,ibot) = 0._wp
573            zdiag(ji,jj,ibot) = 1._wp
574            !
575            ! Just above last level: Neumann condition with flux injection
576            zdiag(ji,jj,ibotm1) = zdiag(ji,jj,ibotm1) + zd_up(ji,jj,ibotm1) ! Remove zd_up from zdiag
577            zd_up(ji,jj,ibotm1) = 0.
578            !
579            ! Set psi vertical flux at the bottom:
580            zdep(ji,jj) = r_z0_bot + 0.5_wp*e3t(ji,jj,ibotm1,Kmm)
581            zflxb = rsbc_psi2 * ( p_avm(ji,jj,ibot) + p_avm(ji,jj,ibotm1) )   &
582               &  * (0.5_wp*(en(ji,jj,ibot)+en(ji,jj,ibotm1)))**rmm * zdep(ji,jj)**(rnn-1._wp)
583            psi(ji,jj,ibotm1) = psi(ji,jj,ibotm1) + zflxb / e3w(ji,jj,ibotm1,Kmm)
584         END_2D
585         !
586      END SELECT
587
588      ! Matrix inversion
589      ! ----------------
590      !
591      DO_3D_00_00( 2, jpkm1 )
592         zdiag(ji,jj,jk) = zdiag(ji,jj,jk) - zd_lw(ji,jj,jk) * zd_up(ji,jj,jk-1) / zdiag(ji,jj,jk-1)
593      END_3D
594      DO_3D_00_00( 2, jpk )
595         zd_lw(ji,jj,jk) = psi(ji,jj,jk) - zd_lw(ji,jj,jk) / zdiag(ji,jj,jk-1) * zd_lw(ji,jj,jk-1)
596      END_3D
597      DO_3DS_00_00( jpk-1, 2, -1 )
598         psi(ji,jj,jk) = ( zd_lw(ji,jj,jk) - zd_up(ji,jj,jk) * psi(ji,jj,jk+1) ) / zdiag(ji,jj,jk)
599      END_3D
600
601      ! Set dissipation
602      !----------------
603
604      SELECT CASE ( nn_clos )
605      !
606      CASE( 0 )               ! k-kl  (Mellor-Yamada)
607         DO_3D_00_00( 1, jpkm1 )
608            eps(ji,jj,jk) = rc03 * en(ji,jj,jk) * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / MAX( psi(ji,jj,jk), rn_epsmin)
609         END_3D
610         !
611      CASE( 1 )               ! k-eps
612         DO_3D_00_00( 1, jpkm1 )
613            eps(ji,jj,jk) = psi(ji,jj,jk)
614         END_3D
615         !
616      CASE( 2 )               ! k-w
617         DO_3D_00_00( 1, jpkm1 )
618            eps(ji,jj,jk) = rc04 * en(ji,jj,jk) * psi(ji,jj,jk) 
619         END_3D
620         !
621      CASE( 3 )               ! generic
622         zcoef = rc0**( 3._wp  + rpp/rnn )
623         zex1  =      ( 1.5_wp + rmm/rnn )
624         zex2  = -1._wp / rnn
625         DO_3D_00_00( 1, jpkm1 )
626            eps(ji,jj,jk) = zcoef * en(ji,jj,jk)**zex1 * psi(ji,jj,jk)**zex2
627         END_3D
628         !
629      END SELECT
630
631      ! Limit dissipation rate under stable stratification
632      ! --------------------------------------------------
633      DO_3D_00_00( 1, jpkm1 )
634         ! limitation
635         eps   (ji,jj,jk)  = MAX( eps(ji,jj,jk), rn_epsmin )
636         hmxl_n(ji,jj,jk)  = rc03 * en(ji,jj,jk) * SQRT( en(ji,jj,jk) ) / eps(ji,jj,jk)
637         ! Galperin criterium (NOTE : Not required if the proper value of C3 in stable cases is calculated)
638         zrn2 = MAX( rn2(ji,jj,jk), rsmall )
639         IF( ln_length_lim )   hmxl_n(ji,jj,jk) = MIN(  rn_clim_galp * SQRT( 2._wp * en(ji,jj,jk) / zrn2 ), hmxl_n(ji,jj,jk) )
640      END_3D
641
642      !
643      ! Stability function and vertical viscosity and diffusivity
644      ! ---------------------------------------------------------
645      !
646      SELECT CASE ( nn_stab_func )
647      !
648      CASE ( 0 , 1 )             ! Galperin or Kantha-Clayson stability functions
649         DO_3D_00_00( 2, jpkm1 )
650            ! zcof =  l²/q²
651            zcof = hmxl_b(ji,jj,jk) * hmxl_b(ji,jj,jk) / ( 2._wp*eb(ji,jj,jk) )
652            ! Gh = -N²l²/q²
653            gh = - rn2(ji,jj,jk) * zcof
654            gh = MIN( gh, rgh0   )
655            gh = MAX( gh, rghmin )
656            ! Stability functions from Kantha and Clayson (if C2=C3=0 => Galperin)
657            sh = ra2*( 1._wp-6._wp*ra1/rb1 ) / ( 1.-3.*ra2*gh*(6.*ra1+rb2*( 1._wp-rc3 ) ) )
658            sm = ( rb1**(-1._wp/3._wp) + ( 18._wp*ra1*ra1 + 9._wp*ra1*ra2*(1._wp-rc2) )*sh*gh ) / (1._wp-9._wp*ra1*ra2*gh)
659            !
660            ! Store stability function in zstt and zstm
661            zstt(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
662            zstm(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
663         END_3D
664         !
665      CASE ( 2, 3 )               ! Canuto stability functions
666         DO_3D_00_00( 2, jpkm1 )
667            ! zcof =  l²/q²
668            zcof = hmxl_b(ji,jj,jk)*hmxl_b(ji,jj,jk) / ( 2._wp * eb(ji,jj,jk) )
669            ! Gh = -N²l²/q²
670            gh = - rn2(ji,jj,jk) * zcof
671            gh = MIN( gh, rgh0   )
672            gh = MAX( gh, rghmin )
673            gh = gh * rf6
674            ! Gm =  M²l²/q² Shear number
675            shr = p_sh2(ji,jj,jk) / MAX( p_avm(ji,jj,jk), rsmall )
676            gm = MAX( shr * zcof , 1.e-10 )
677            gm = gm * rf6
678            gm = MIN ( (rd0 - rd1*gh + rd3*gh*gh) / (rd2-rd4*gh) , gm )
679            ! Stability functions from Canuto
680            rcff = rd0 - rd1*gh +rd2*gm + rd3*gh*gh - rd4*gh*gm + rd5*gm*gm
681            sm = (rs0 - rs1*gh + rs2*gm) / rcff
682            sh = (rs4 - rs5*gh + rs6*gm) / rcff
683            !
684            ! Store stability function in zstt and zstm
685            zstt(ji,jj,jk) = rc_diff * sh * tmask(ji,jj,jk)
686            zstm(ji,jj,jk) = rc_diff * sm * tmask(ji,jj,jk)
687         END_3D
688         !
689      END SELECT
690
691      ! Boundary conditions on stability functions for momentum (Neumann):
692      ! Lines below are useless if GOTM style Dirichlet conditions are used
693
694      zstm(:,:,1) = zstm(:,:,2)
695
696      ! default value, in case jpk > mbkt(ji,jj)+1. Not needed but avoid a bug when looking for undefined values (-fpe0)
697      zstm(:,:,jpk) = 0. 
698      DO_2D_00_00
699         zstm(ji,jj,mbkt(ji,jj)+1) = zstm(ji,jj,mbkt(ji,jj))
700      END_2D
701
702      zstt(:,:,  1) = wmask(:,:,  1)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0)
703      zstt(:,:,jpk) = wmask(:,:,jpk)  ! default value not needed but avoid a bug when looking for undefined values (-fpe0)
704
705!!gm should be done for ISF (top boundary cond.)
706!!gm so, totally new staff needed!!gm
707
708      ! Compute diffusivities/viscosities
709      ! The computation below could be restrained to jk=2 to jpkm1 if GOTM style Dirichlet conditions are used
710      !  -> yes BUT p_avm(:,:1) and p_avm(:,:jpk) are used when we compute zd_lw(:,:2) and zd_up(:,:jpkm1). These values are
711      !     later overwritten by surface/bottom boundaries conditions, so we don't really care of p_avm(:,:1) and p_avm(:,:jpk)
712      !     for zd_lw and zd_up but they have to be defined to avoid a bug when looking for undefined values (-fpe0)
713      DO_3D_00_00( 1, jpk )
714         zsqen = SQRT( 2._wp * en(ji,jj,jk) ) * hmxl_n(ji,jj,jk)
715         zavt  = zsqen * zstt(ji,jj,jk)
716         zavm  = zsqen * zstm(ji,jj,jk)
717         p_avt(ji,jj,jk) = MAX( zavt, avtb(jk) ) * wmask(ji,jj,jk) ! apply mask for zdfmxl routine
718         p_avm(ji,jj,jk) = MAX( zavm, avmb(jk) )                   ! Note that avm is not masked at the surface and the bottom
719      END_3D
720      p_avt(:,:,1) = 0._wp
721      !
722      IF(sn_cfctl%l_prtctl) THEN
723         CALL prt_ctl( tab3d_1=en   , clinfo1=' gls  - e: ', tab3d_2=p_avt, clinfo2=' t: ', kdim=jpk)
724         CALL prt_ctl( tab3d_1=p_avm, clinfo1=' gls  - m: ', kdim=jpk )
725      ENDIF
726      !
727   END SUBROUTINE zdf_gls
728
729
730   SUBROUTINE zdf_gls_init
731      !!----------------------------------------------------------------------
732      !!                  ***  ROUTINE zdf_gls_init  ***
733      !!                     
734      !! ** Purpose :   Initialization of the vertical eddy diffivity and
735      !!              viscosity computed using a GLS turbulent closure scheme
736      !!
737      !! ** Method  :   Read the namzdf_gls namelist and check the parameters
738      !!
739      !! ** input   :   Namlist namzdf_gls
740      !!
741      !! ** Action  :   Increase by 1 the nstop flag is setting problem encounter
742      !!
743      !!----------------------------------------------------------------------
744      INTEGER ::   jk    ! dummy loop indices
745      INTEGER ::   ios   ! Local integer output status for namelist read
746      REAL(wp)::   zcr   ! local scalar
747      !!
748      NAMELIST/namzdf_gls/rn_emin, rn_epsmin, ln_length_lim, &
749         &            rn_clim_galp, ln_sigpsi, rn_hsro,      &
750         &            rn_crban, rn_charn, rn_frac_hs,        &
751         &            nn_bc_surf, nn_bc_bot, nn_z0_met,      &
752         &            nn_stab_func, nn_clos
753      !!----------------------------------------------------------
754      !
755      READ  ( numnam_ref, namzdf_gls, IOSTAT = ios, ERR = 901)
756901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namzdf_gls in reference namelist' )
757
758      READ  ( numnam_cfg, namzdf_gls, IOSTAT = ios, ERR = 902 )
759902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namzdf_gls in configuration namelist' )
760      IF(lwm) WRITE ( numond, namzdf_gls )
761
762      IF(lwp) THEN                     !* Control print
763         WRITE(numout,*)
764         WRITE(numout,*) 'zdf_gls_init : GLS turbulent closure scheme'
765         WRITE(numout,*) '~~~~~~~~~~~~'
766         WRITE(numout,*) '   Namelist namzdf_gls : set gls mixing parameters'
767         WRITE(numout,*) '      minimum value of en                           rn_emin        = ', rn_emin
768         WRITE(numout,*) '      minimum value of eps                          rn_epsmin      = ', rn_epsmin
769         WRITE(numout,*) '      Limit dissipation rate under stable stratif.  ln_length_lim  = ', ln_length_lim
770         WRITE(numout,*) '      Galperin limit (Standard: 0.53, Holt: 0.26)   rn_clim_galp   = ', rn_clim_galp
771         WRITE(numout,*) '      TKE Surface boundary condition                nn_bc_surf     = ', nn_bc_surf
772         WRITE(numout,*) '      TKE Bottom boundary condition                 nn_bc_bot      = ', nn_bc_bot
773         WRITE(numout,*) '      Modify psi Schmidt number (wb case)           ln_sigpsi      = ', ln_sigpsi
774         WRITE(numout,*) '      Craig and Banner coefficient                  rn_crban       = ', rn_crban
775         WRITE(numout,*) '      Charnock coefficient                          rn_charn       = ', rn_charn
776         WRITE(numout,*) '      Surface roughness formula                     nn_z0_met      = ', nn_z0_met
777         WRITE(numout,*) '      Wave height frac. (used if nn_z0_met=2)       rn_frac_hs     = ', rn_frac_hs
778         WRITE(numout,*) '      Stability functions                           nn_stab_func   = ', nn_stab_func
779         WRITE(numout,*) '      Type of closure                               nn_clos        = ', nn_clos
780         WRITE(numout,*) '      Surface roughness (m)                         rn_hsro        = ', rn_hsro
781         WRITE(numout,*)
782         WRITE(numout,*) '   Namelist namdrg_top/_bot:   used values:'
783         WRITE(numout,*) '      top    ocean cavity roughness (m)             rn_z0(_top)   = ', r_z0_top
784         WRITE(numout,*) '      Bottom seafloor     roughness (m)             rn_z0(_bot)   = ', r_z0_bot
785         WRITE(numout,*)
786      ENDIF
787
788      !                                !* allocate GLS arrays
789      IF( zdf_gls_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_gls_init : unable to allocate arrays' )
790
791      !                                !* Check of some namelist values
792      IF( nn_bc_surf < 0   .OR. nn_bc_surf   > 1 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_bc_surf is 0 or 1' )
793      IF( nn_bc_surf < 0   .OR. nn_bc_surf   > 1 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_bc_surf is 0 or 1' )
794      IF( nn_z0_met  < 0   .OR. nn_z0_met    > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_z0_met is 0, 1, 2 or 3' )
795      IF( nn_z0_met == 3  .AND. .NOT.ln_wave     )   CALL ctl_stop( 'zdf_gls_init: nn_z0_met=3 requires ln_wave=T' )
796      IF( nn_stab_func < 0 .OR. nn_stab_func > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_stab_func is 0, 1, 2 and 3' )
797      IF( nn_clos      < 0 .OR. nn_clos      > 3 )   CALL ctl_stop( 'zdf_gls_init: bad flag: nn_clos is 0, 1, 2 or 3' )
798
799      SELECT CASE ( nn_clos )          !* set the parameters for the chosen closure
800      !
801      CASE( 0 )                              ! k-kl  (Mellor-Yamada)
802         !
803         IF(lwp) WRITE(numout,*) '   ==>>   k-kl closure chosen (i.e. closed to the classical Mellor-Yamada)'
804         IF(lwp) WRITE(numout,*)
805         rpp     = 0._wp
806         rmm     = 1._wp
807         rnn     = 1._wp
808         rsc_tke = 1.96_wp
809         rsc_psi = 1.96_wp
810         rpsi1   = 0.9_wp
811         rpsi3p  = 1._wp
812         rpsi2   = 0.5_wp
813         !
814         SELECT CASE ( nn_stab_func )
815         CASE( 0, 1 )   ;   rpsi3m = 2.53_wp       ! G88 or KC stability functions
816         CASE( 2 )      ;   rpsi3m = 2.62_wp       ! Canuto A stability functions
817         CASE( 3 )      ;   rpsi3m = 2.38          ! Canuto B stability functions (caution : constant not identified)
818         END SELECT
819         !
820      CASE( 1 )                              ! k-eps
821         !
822         IF(lwp) WRITE(numout,*) '   ==>>   k-eps closure chosen'
823         IF(lwp) WRITE(numout,*)
824         rpp     =  3._wp
825         rmm     =  1.5_wp
826         rnn     = -1._wp
827         rsc_tke =  1._wp
828         rsc_psi =  1.2_wp  ! Schmidt number for psi
829         rpsi1   =  1.44_wp
830         rpsi3p  =  1._wp
831         rpsi2   =  1.92_wp
832         !
833         SELECT CASE ( nn_stab_func )
834         CASE( 0, 1 )   ;   rpsi3m = -0.52_wp      ! G88 or KC stability functions
835         CASE( 2 )      ;   rpsi3m = -0.629_wp     ! Canuto A stability functions
836         CASE( 3 )      ;   rpsi3m = -0.566        ! Canuto B stability functions
837         END SELECT
838         !
839      CASE( 2 )                              ! k-omega
840         !
841         IF(lwp) WRITE(numout,*) '   ==>>   k-omega closure chosen'
842         IF(lwp) WRITE(numout,*)
843         rpp     = -1._wp
844         rmm     =  0.5_wp
845         rnn     = -1._wp
846         rsc_tke =  2._wp
847         rsc_psi =  2._wp
848         rpsi1   =  0.555_wp
849         rpsi3p  =  1._wp
850         rpsi2   =  0.833_wp
851         !
852         SELECT CASE ( nn_stab_func )
853         CASE( 0, 1 )   ;   rpsi3m = -0.58_wp       ! G88 or KC stability functions
854         CASE( 2 )      ;   rpsi3m = -0.64_wp       ! Canuto A stability functions
855         CASE( 3 )      ;   rpsi3m = -0.64_wp       ! Canuto B stability functions caution : constant not identified)
856         END SELECT
857         !
858      CASE( 3 )                              ! generic
859         !
860         IF(lwp) WRITE(numout,*) '   ==>>   generic closure chosen'
861         IF(lwp) WRITE(numout,*)
862         rpp     = 2._wp
863         rmm     = 1._wp
864         rnn     = -0.67_wp
865         rsc_tke = 0.8_wp
866         rsc_psi = 1.07_wp
867         rpsi1   = 1._wp
868         rpsi3p  = 1._wp
869         rpsi2   = 1.22_wp
870         !
871         SELECT CASE ( nn_stab_func )
872         CASE( 0, 1 )   ;   rpsi3m = 0.1_wp         ! G88 or KC stability functions
873         CASE( 2 )      ;   rpsi3m = 0.05_wp        ! Canuto A stability functions
874         CASE( 3 )      ;   rpsi3m = 0.05_wp        ! Canuto B stability functions caution : constant not identified)
875         END SELECT
876         !
877      END SELECT
878
879      !
880      SELECT CASE ( nn_stab_func )     !* set the parameters of the stability functions
881      !
882      CASE ( 0 )                             ! Galperin stability functions
883         !
884         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Galperin'
885         rc2     =  0._wp
886         rc3     =  0._wp
887         rc_diff =  1._wp
888         rc0     =  0.5544_wp
889         rcm_sf  =  0.9884_wp
890         rghmin  = -0.28_wp
891         rgh0    =  0.0233_wp
892         rghcri  =  0.02_wp
893         !
894      CASE ( 1 )                             ! Kantha-Clayson stability functions
895         !
896         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Kantha-Clayson'
897         rc2     =  0.7_wp
898         rc3     =  0.2_wp
899         rc_diff =  1._wp
900         rc0     =  0.5544_wp
901         rcm_sf  =  0.9884_wp
902         rghmin  = -0.28_wp
903         rgh0    =  0.0233_wp
904         rghcri  =  0.02_wp
905         !
906      CASE ( 2 )                             ! Canuto A stability functions
907         !
908         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Canuto A'
909         rs0 = 1.5_wp * rl1 * rl5*rl5
910         rs1 = -rl4*(rl6+rl7) + 2._wp*rl4*rl5*(rl1-(1._wp/3._wp)*rl2-rl3) + 1.5_wp*rl1*rl5*rl8
911         rs2 = -(3._wp/8._wp) * rl1*(rl6*rl6-rl7*rl7)
912         rs4 = 2._wp * rl5
913         rs5 = 2._wp * rl4
914         rs6 = (2._wp/3._wp) * rl5 * ( 3._wp*rl3*rl3 - rl2*rl2 ) - 0.5_wp * rl5*rl1 * (3._wp*rl3-rl2)   &
915            &                                                    + 0.75_wp * rl1 * ( rl6 - rl7 )
916         rd0 = 3._wp * rl5*rl5
917         rd1 = rl5 * ( 7._wp*rl4 + 3._wp*rl8 )
918         rd2 = rl5*rl5 * ( 3._wp*rl3*rl3 - rl2*rl2 ) - 0.75_wp*(rl6*rl6 - rl7*rl7 )
919         rd3 = rl4 * ( 4._wp*rl4 + 3._wp*rl8)
920         rd4 = rl4 * ( rl2 * rl6 - 3._wp*rl3*rl7 - rl5*(rl2*rl2 - rl3*rl3 ) ) + rl5*rl8 * ( 3._wp*rl3*rl3 - rl2*rl2 )
921         rd5 = 0.25_wp * ( rl2*rl2 - 3._wp *rl3*rl3 ) * ( rl6*rl6 - rl7*rl7 )
922         rc0 = 0.5268_wp
923         rf6 = 8._wp / (rc0**6._wp)
924         rc_diff = SQRT(2._wp) / (rc0**3._wp)
925         rcm_sf  =  0.7310_wp
926         rghmin  = -0.28_wp
927         rgh0    =  0.0329_wp
928         rghcri  =  0.03_wp
929         !
930      CASE ( 3 )                             ! Canuto B stability functions
931         !
932         IF(lwp) WRITE(numout,*) '   ==>>   Stability functions from Canuto B'
933         rs0 = 1.5_wp * rm1 * rm5*rm5
934         rs1 = -rm4 * (rm6+rm7) + 2._wp * rm4*rm5*(rm1-(1._wp/3._wp)*rm2-rm3) + 1.5_wp * rm1*rm5*rm8
935         rs2 = -(3._wp/8._wp) * rm1 * (rm6*rm6-rm7*rm7 )
936         rs4 = 2._wp * rm5
937         rs5 = 2._wp * rm4
938         rs6 = (2._wp/3._wp) * rm5 * (3._wp*rm3*rm3-rm2*rm2) - 0.5_wp * rm5*rm1*(3._wp*rm3-rm2) + 0.75_wp * rm1*(rm6-rm7)
939         rd0 = 3._wp * rm5*rm5
940         rd1 = rm5 * (7._wp*rm4 + 3._wp*rm8)
941         rd2 = rm5*rm5 * (3._wp*rm3*rm3 - rm2*rm2) - 0.75_wp * (rm6*rm6 - rm7*rm7)
942         rd3 = rm4 * ( 4._wp*rm4 + 3._wp*rm8 )
943         rd4 = rm4 * ( rm2*rm6 -3._wp*rm3*rm7 - rm5*(rm2*rm2 - rm3*rm3) ) + rm5 * rm8 * ( 3._wp*rm3*rm3 - rm2*rm2 )
944         rd5 = 0.25_wp * ( rm2*rm2 - 3._wp*rm3*rm3 ) * ( rm6*rm6 - rm7*rm7 )
945         rc0 = 0.5268_wp            !!       rc0 = 0.5540_wp (Warner ...) to verify !
946         rf6 = 8._wp / ( rc0**6._wp )
947         rc_diff = SQRT(2._wp)/(rc0**3.)
948         rcm_sf  =  0.7470_wp
949         rghmin  = -0.28_wp
950         rgh0    =  0.0444_wp
951         rghcri  =  0.0414_wp
952         !
953      END SELECT
954   
955      !                                !* Set Schmidt number for psi diffusion in the wave breaking case
956      !                                     ! See Eq. (13) of Carniel et al, OM, 30, 225-239, 2009
957      !                                     !  or Eq. (17) of Burchard, JPO, 31, 3133-3145, 2001
958      IF( ln_sigpsi ) THEN
959         ra_sf = -1.5 ! Set kinetic energy slope, then deduce rsc_psi and rl_sf
960         ! Verification: retrieve Burchard (2001) results by uncomenting the line below:
961         ! Note that the results depend on the value of rn_cm_sf which is constant (=rc0) in his work
962         ! ra_sf = -SQRT(2./3.*rc0**3./rn_cm_sf*rn_sc_tke)/vkarmn
963         rsc_psi0 = rsc_tke/(24.*rpsi2)*(-1.+(4.*rnn + ra_sf*(1.+4.*rmm))**2./(ra_sf**2.))
964      ELSE
965         rsc_psi0 = rsc_psi
966      ENDIF
967 
968      !                                !* Shear free turbulence parameters
969      !
970      ra_sf  = -4._wp*rnn*SQRT(rsc_tke) / ( (1._wp+4._wp*rmm)*SQRT(rsc_tke) &
971               &                              - SQRT(rsc_tke + 24._wp*rsc_psi0*rpsi2 ) )
972
973      IF ( rn_crban==0._wp ) THEN
974         rl_sf = vkarmn
975      ELSE
976         rl_sf = rc0 * SQRT(rc0/rcm_sf) * SQRT( ( (1._wp + 4._wp*rmm + 8._wp*rmm**2_wp) * rsc_tke        &
977            &                                            + 12._wp*rsc_psi0*rpsi2 - (1._wp + 4._wp*rmm)   &
978            &                                                     *SQRT(rsc_tke*(rsc_tke                 &
979            &                                                        + 24._wp*rsc_psi0*rpsi2)) )         &
980            &                                              /(12._wp*rnn**2.)                             )
981      ENDIF
982
983      !
984      IF(lwp) THEN                     !* Control print
985         WRITE(numout,*)
986         WRITE(numout,*) '   Limit values :'
987         WRITE(numout,*) '      Parameter  m = ', rmm
988         WRITE(numout,*) '      Parameter  n = ', rnn
989         WRITE(numout,*) '      Parameter  p = ', rpp
990         WRITE(numout,*) '      rpsi1    = ', rpsi1
991         WRITE(numout,*) '      rpsi2    = ', rpsi2
992         WRITE(numout,*) '      rpsi3m   = ', rpsi3m
993         WRITE(numout,*) '      rpsi3p   = ', rpsi3p
994         WRITE(numout,*) '      rsc_tke  = ', rsc_tke
995         WRITE(numout,*) '      rsc_psi  = ', rsc_psi
996         WRITE(numout,*) '      rsc_psi0 = ', rsc_psi0
997         WRITE(numout,*) '      rc0      = ', rc0
998         WRITE(numout,*)
999         WRITE(numout,*) '   Shear free turbulence parameters:'
1000         WRITE(numout,*) '      rcm_sf   = ', rcm_sf
1001         WRITE(numout,*) '      ra_sf    = ', ra_sf
1002         WRITE(numout,*) '      rl_sf    = ', rl_sf
1003      ENDIF
1004
1005      !                                !* Constants initialization
1006      rc02  = rc0  * rc0   ;   rc02r = 1. / rc02
1007      rc03  = rc02 * rc0
1008      rc04  = rc03 * rc0
1009      rsbc_tke1 = -3._wp/2._wp*rn_crban*ra_sf*rl_sf                      ! Dirichlet + Wave breaking
1010      rsbc_tke2 = rdt * rn_crban / rl_sf                                 ! Neumann + Wave breaking
1011      zcr = MAX(rsmall, rsbc_tke1**(1./(-ra_sf*3._wp/2._wp))-1._wp )
1012      rtrans = 0.2_wp / zcr                                              ! Ad. inverse transition length between log and wave layer
1013      rsbc_zs1  = rn_charn/grav                                          ! Charnock formula for surface roughness
1014      rsbc_zs2  = rn_frac_hs / 0.85_wp / grav * 665._wp                  ! Rascle formula for surface roughness
1015      rsbc_psi1 = -0.5_wp * rdt * rc0**(rpp-2._wp*rmm) / rsc_psi
1016      rsbc_psi2 = -0.5_wp * rdt * rc0**rpp * rnn * vkarmn**rnn / rsc_psi ! Neumann + NO Wave breaking
1017      !
1018      rfact_tke = -0.5_wp / rsc_tke * rdt                                ! Cst used for the Diffusion term of tke
1019      rfact_psi = -0.5_wp / rsc_psi * rdt                                ! Cst used for the Diffusion term of tke
1020      !
1021      !                                !* Wall proximity function
1022!!gm tmask or wmask ????
1023      zwall(:,:,:) = 1._wp * tmask(:,:,:)
1024
1025      !                                !* read or initialize all required files 
1026      CALL gls_rst( nit000, 'READ' )      ! (en, avt_k, avm_k, hmxl_n)
1027      !
1028      IF( lwxios ) THEN
1029         CALL iom_set_rstw_var_active('en')
1030         CALL iom_set_rstw_var_active('avt_k')
1031         CALL iom_set_rstw_var_active('avm_k')
1032         CALL iom_set_rstw_var_active('hmxl_n')
1033      ENDIF
1034      !
1035   END SUBROUTINE zdf_gls_init
1036
1037
1038   SUBROUTINE gls_rst( kt, cdrw )
1039      !!---------------------------------------------------------------------
1040      !!                   ***  ROUTINE gls_rst  ***
1041      !!                     
1042      !! ** Purpose :   Read or write TKE file (en) in restart file
1043      !!
1044      !! ** Method  :   use of IOM library
1045      !!                if the restart does not contain TKE, en is either
1046      !!                set to rn_emin or recomputed (nn_igls/=0)
1047      !!----------------------------------------------------------------------
1048      USE zdf_oce , ONLY : en, avt_k, avm_k   ! ocean vertical physics
1049      !!
1050      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
1051      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
1052      !
1053      INTEGER ::   jit, jk   ! dummy loop indices
1054      INTEGER ::   id1, id2, id3, id4
1055      INTEGER ::   ji, jj, ikbu, ikbv
1056      REAL(wp)::   cbx, cby
1057      !!----------------------------------------------------------------------
1058      !
1059      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
1060         !                                   ! ---------------
1061         IF( ln_rstart ) THEN                   !* Read the restart file
1062            id1 = iom_varid( numror, 'en'    , ldstop = .FALSE. )
1063            id2 = iom_varid( numror, 'avt_k' , ldstop = .FALSE. )
1064            id3 = iom_varid( numror, 'avm_k' , ldstop = .FALSE. )
1065            id4 = iom_varid( numror, 'hmxl_n', ldstop = .FALSE. )
1066            !
1067            IF( MIN( id1, id2, id3, id4 ) > 0 ) THEN        ! all required arrays exist
1068               CALL iom_get( numror, jpdom_autoglo, 'en'    , en    , ldxios = lrxios )
1069               CALL iom_get( numror, jpdom_autoglo, 'avt_k' , avt_k , ldxios = lrxios )
1070               CALL iom_get( numror, jpdom_autoglo, 'avm_k' , avm_k , ldxios = lrxios )
1071               CALL iom_get( numror, jpdom_autoglo, 'hmxl_n', hmxl_n, ldxios = lrxios )
1072            ELSE                       
1073               IF(lwp) WRITE(numout,*)
1074               IF(lwp) WRITE(numout,*) '   ==>>   previous run without GLS scheme, set en and hmxl_n to background values'
1075               en    (:,:,:) = rn_emin
1076               hmxl_n(:,:,:) = 0.05_wp
1077               ! avt_k, avm_k already set to the background value in zdf_phy_init
1078            ENDIF
1079         ELSE                                   !* Start from rest
1080            IF(lwp) WRITE(numout,*)
1081            IF(lwp) WRITE(numout,*) '   ==>>   start from rest, set en and hmxl_n by background values'
1082            en    (:,:,:) = rn_emin
1083            hmxl_n(:,:,:) = 0.05_wp
1084            ! avt_k, avm_k already set to the background value in zdf_phy_init
1085         ENDIF
1086         !
1087      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
1088         !                                   ! -------------------
1089         IF(lwp) WRITE(numout,*) '---- gls-rst ----'
1090         IF( lwxios ) CALL iom_swap(      cwxios_context         )
1091         CALL iom_rstput( kt, nitrst, numrow, 'en'    , en    , ldxios = lwxios )
1092         CALL iom_rstput( kt, nitrst, numrow, 'avt_k' , avt_k , ldxios = lwxios )
1093         CALL iom_rstput( kt, nitrst, numrow, 'avm_k' , avm_k , ldxios = lwxios )
1094         CALL iom_rstput( kt, nitrst, numrow, 'hmxl_n', hmxl_n, ldxios = lwxios )
1095         IF( lwxios ) CALL iom_swap(      cxios_context          )
1096         !
1097      ENDIF
1098      !
1099   END SUBROUTINE gls_rst
1100
1101   !!======================================================================
1102END MODULE zdfgls
1103
Note: See TracBrowser for help on using the repository browser.