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.
sbcisf.F90 in branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90 @ 6012

Last change on this file since 6012 was 6012, checked in by mathiot, 8 years ago

merge MetO branch with dev_r5151_UKMO_ISF

  • Property svn:keywords set to Id
File size: 40.7 KB
Line 
1MODULE sbcisf
2   !!======================================================================
3   !!                       ***  MODULE  sbcisf  ***
4   !! Surface module :  update surface ocean boundary condition under ice
5   !!                   shelf
6   !!======================================================================
7   !! History :  3.2   !  2011-02  (C.Harris  ) Original code isf cav
8   !!            X.X   !  2006-02  (C. Wang   ) Original code bg03
9   !!            3.4   !  2013-03  (P. Mathiot) Merging + parametrization
10   !!----------------------------------------------------------------------
11
12   !!----------------------------------------------------------------------
13   !!   sbc_isf        : update sbc under ice shelf
14   !!----------------------------------------------------------------------
15   USE oce             ! ocean dynamics and tracers
16   USE dom_oce         ! ocean space and time domain
17   USE phycst          ! physical constants
18   USE eosbn2          ! equation of state
19   USE sbc_oce         ! surface boundary condition: ocean fields
20   USE zdfbfr          !
21   !
22   USE in_out_manager  ! I/O manager
23   USE iom             ! I/O manager library
24   USE fldread         ! read input field at current time step
25   USE lbclnk          !
26   USE wrk_nemo        ! Memory allocation
27   USE timing          ! Timing
28   USE lib_fortran     ! glob_sum
29
30   IMPLICIT NONE
31   PRIVATE
32
33   PUBLIC   sbc_isf, sbc_isf_div, sbc_isf_alloc  ! routine called in sbcmod and divhor
34
35   ! public in order to be able to output then
36
37   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   risf_tsc_b, risf_tsc  !: before and now T & S isf contents [K.m/s & PSU.m/s] 
38   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   qisf                  !: net heat flux from ice shelf      [W/m2]
39   REAL(wp), PUBLIC ::   rn_hisf_tbl                 !: thickness of top boundary layer [m]
40   INTEGER , PUBLIC ::   nn_isf                      !: flag to choose between explicit/param/specified 
41   INTEGER , PUBLIC ::   nn_isfblk                   !: flag to choose the bulk formulation to compute the ice shelf melting
42   INTEGER , PUBLIC ::   nn_gammablk                 !: flag to choose how the exchange coefficient is computed
43   REAL(wp), PUBLIC ::   rn_gammat0                  !: temperature exchange coeficient []
44   REAL(wp), PUBLIC ::   rn_gammas0                  !: salinity    exchange coeficient []
45
46   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rzisf_tbl              !:depth of calving front (shallowest point) nn_isf ==2/3
47   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rhisf_tbl, rhisf_tbl_0 !:thickness of tbl  [m]
48   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  r1_hisf_tbl            !:1/thickness of tbl
49   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ralpha                 !:proportion of bottom cell influenced by tbl
50   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  risfLeff               !:effective length (Leff) BG03 nn_isf==2
51   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ttbl, stbl, utbl, vtbl !:top boundary layer variable at T point
52   INTEGER,    PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)      ::  misfkt, misfkb         !:Level of ice shelf base
53
54   REAL(wp), PUBLIC, SAVE ::   rcpi     = 2000.0_wp     ! specific heat of ice shelf             [J/kg/K]
55   REAL(wp), PUBLIC, SAVE ::   rkappa   = 1.54e-6_wp    ! heat diffusivity through the ice-shelf [m2/s]
56   REAL(wp), PUBLIC, SAVE ::   rhoisf   = 920.0_wp      ! volumic mass of ice shelf              [kg/m3]
57   REAL(wp), PUBLIC, SAVE ::   tsurf    = -20.0_wp      ! air temperature on top of ice shelf    [C]
58   REAL(wp), PUBLIC, SAVE ::   rlfusisf = 0.334e6_wp    ! latent heat of fusion of ice shelf     [J/kg]
59
60!: Variable used in fldread to read the forcing file (nn_isf == 4 .OR. nn_isf == 3)
61   CHARACTER(len=100), PUBLIC           :: cn_dirisf  = './' !: Root directory for location of ssr files
62   TYPE(FLD_N)       , PUBLIC           :: sn_fwfisf         !: information about the isf melting file to be read
63   TYPE(FLD), ALLOCATABLE, DIMENSION(:) :: sf_fwfisf
64   TYPE(FLD_N)       , PUBLIC           :: sn_rnfisf         !: information about the isf melting param.   file to be read
65   TYPE(FLD), ALLOCATABLE, DIMENSION(:) :: sf_rnfisf           
66   TYPE(FLD_N)       , PUBLIC           :: sn_depmax_isf     !: information about the grounding line depth file to be read
67   TYPE(FLD_N)       , PUBLIC           :: sn_depmin_isf     !: information about the calving   line depth file to be read
68   TYPE(FLD_N)       , PUBLIC           :: sn_Leff_isf       !: information about the effective length     file to be read
69   
70   !! * Substitutions
71#  include "domzgr_substitute.h90"
72   !!----------------------------------------------------------------------
73   !! NEMO/OPA 3.7 , LOCEAN-IPSL (2015)
74   !! $Id$
75   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
76   !!----------------------------------------------------------------------
77CONTAINS
78 
79  SUBROUTINE sbc_isf(kt)
80      !!---------------------------------------------------------------------
81      !!                  ***  ROUTINE sbc_isf  ***
82      !!
83      !! ** Purpose : Compute Salt and Heat fluxes related to ice_shelf
84      !!              melting and freezing
85      !!
86      !! ** Method  :  4 parameterizations are available according to nn_isf
87      !!               nn_isf = 1 : Realistic ice_shelf formulation
88      !!                        2 : Beckmann & Goose parameterization
89      !!                        3 : Specified runoff in deptht (Mathiot & al. )
90      !!                        4 : specified fwf and heat flux forcing beneath the ice shelf
91      !!----------------------------------------------------------------------
92      INTEGER, INTENT( in ) :: kt                   ! ocean time step
93      !
94      INTEGER               :: ji, jj               ! loop index
95      REAL(wp), DIMENSION (:,:), POINTER :: zt_frz, zdep ! freezing temperature (zt_frz) at depth (zdep)
96      !!---------------------------------------------------------------------
97      !
98      !                                         ! ====================== !
99      IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
100         !                                      ! ====================== !
101         CALL sbc_isf_init
102      !                                         ! ---------------------------------------- !
103      ELSE                                      !          Swap of forcing fields          !
104         !                                      ! ---------------------------------------- !
105         fwfisf_b  (:,:  ) = fwfisf  (:,:  )    ! Swap the ocean forcing fields except at nit000
106         risf_tsc_b(:,:,:) = risf_tsc(:,:,:)    ! where before fields are set at the end of the routine
107         !
108      END IF
109
110      IF( MOD( kt-1, nn_fsbc) == 0 ) THEN
111         ! allocation
112         CALL wrk_alloc( jpi,jpj, zt_frz, zdep  )
113
114         ! compute salt and heat flux
115         SELECT CASE ( nn_isf )
116         CASE ( 1 )    ! realistic ice shelf formulation
117            ! compute T/S/U/V for the top boundary layer
118            CALL sbc_isf_tbl(tsn(:,:,:,jp_tem),ttbl(:,:),'T')
119            CALL sbc_isf_tbl(tsn(:,:,:,jp_sal),stbl(:,:),'T')
120            CALL sbc_isf_tbl(un(:,:,:)        ,utbl(:,:),'U')
121            CALL sbc_isf_tbl(vn(:,:,:)        ,vtbl(:,:),'V')
122            ! iom print
123            CALL iom_put('ttbl',ttbl(:,:))
124            CALL iom_put('stbl',stbl(:,:))
125            CALL iom_put('utbl',utbl(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:))
126            CALL iom_put('vtbl',vtbl(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:))
127            ! compute fwf and heat flux
128            CALL sbc_isf_cav (kt)
129
130         CASE ( 2 )    ! Beckmann and Goosse parametrisation
131            stbl(:,:)   = soce
132            CALL sbc_isf_bg03(kt)
133
134         CASE ( 3 )    ! specified runoff in depth (Mathiot et al., XXXX in preparation)
135            CALL fld_read ( kt, nn_fsbc, sf_rnfisf   )
136            fwfisf(:,:) = - sf_rnfisf(1)%fnow(:,:,1)         ! fwf  flux from the isf (fwfisf <0 mean melting)
137            qisf(:,:)   = fwfisf(:,:) * rlfusisf             ! heat flux
138            stbl(:,:)   = soce
139
140         CASE ( 4 )    ! specified fwf and heat flux forcing beneath the ice shelf
141            CALL fld_read ( kt, nn_fsbc, sf_fwfisf   )
142            fwfisf(:,:) = - sf_fwfisf(1)%fnow(:,:,1)           ! fwf  flux from the isf (fwfisf <0 mean melting)
143            qisf(:,:)   = fwfisf(:,:) * rlfusisf               ! heat flux
144            stbl(:,:)   = soce
145
146         END SELECT
147
148         ! compute tsc due to isf
149         ! isf melting implemented as a volume flux and we assume that melt water is at 0 PSU.
150         ! WARNING water add at temp = 0C, need to add a correction term (fwfisf * tfreez / rau0).
151         ! compute freezing point beneath ice shelf (or top cell if nn_isf = 3)
152         DO jj = 1,jpj
153            DO ji = 1,jpi
154               zdep(ji,jj)=fsdepw_n(ji,jj,misfkt(ji,jj))
155            END DO
156         END DO
157         CALL eos_fzp( stbl(:,:), zt_frz(:,:), zdep(:,:) )
158         
159         risf_tsc(:,:,jp_tem) = qisf(:,:) * r1_rau0_rcp - fwfisf(:,:) * zt_frz(:,:) * r1_rau0 !
160         risf_tsc(:,:,jp_sal) = 0.0_wp
161
162         ! lbclnk
163         CALL lbc_lnk(risf_tsc(:,:,jp_tem),'T',1.)
164         CALL lbc_lnk(risf_tsc(:,:,jp_sal),'T',1.)
165         CALL lbc_lnk(fwfisf(:,:)         ,'T',1.)
166         CALL lbc_lnk(qisf(:,:)           ,'T',1.)
167
168         IF( kt == nit000 ) THEN                         !   set the forcing field at nit000 - 1    !
169            IF( ln_rstart .AND.    &                     ! Restart: read in restart file
170                 & iom_varid( numror, 'fwf_isf_b', ldstop = .FALSE. ) > 0 ) THEN
171               IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
172               CALL iom_get( numror, jpdom_autoglo, 'fwf_isf_b', fwfisf_b(:,:) )   ! before salt content isf_tsc trend
173               CALL iom_get( numror, jpdom_autoglo, 'isf_sc_b', risf_tsc_b(:,:,jp_sal) )   ! before salt content isf_tsc trend
174               CALL iom_get( numror, jpdom_autoglo, 'isf_hc_b', risf_tsc_b(:,:,jp_tem) )   ! before salt content isf_tsc trend
175            ELSE
176               fwfisf_b(:,:)    = fwfisf(:,:)
177               risf_tsc_b(:,:,:)= risf_tsc(:,:,:)
178            END IF
179         END IF
180         !
181         ! output
182         CALL iom_put('qisf'  , qisf)
183         CALL iom_put('fwfisf', fwfisf)
184
185         ! deallocation
186         CALL wrk_dealloc( jpi,jpj, zt_frz, zdep  )
187      END IF
188     
189  END SUBROUTINE sbc_isf
190
191
192  INTEGER FUNCTION sbc_isf_alloc()
193      !!----------------------------------------------------------------------
194      !!               ***  FUNCTION sbc_isf_rnf_alloc  ***
195      !!----------------------------------------------------------------------
196      sbc_isf_alloc = 0       ! set to zero if no array to be allocated
197      IF( .NOT. ALLOCATED( qisf ) ) THEN
198         ALLOCATE(  risf_tsc(jpi,jpj,jpts), risf_tsc_b(jpi,jpj,jpts), qisf(jpi,jpj)   , &
199               &    rhisf_tbl(jpi,jpj)    , r1_hisf_tbl(jpi,jpj), rzisf_tbl(jpi,jpj)  , &
200               &    ttbl(jpi,jpj)         , stbl(jpi,jpj)       , utbl(jpi,jpj)       , &
201               &    vtbl(jpi, jpj)        , risfLeff(jpi,jpj)   , rhisf_tbl_0(jpi,jpj), &
202               &    ralpha(jpi,jpj)       , misfkt(jpi,jpj)     , misfkb(jpi,jpj)     , &
203               &    STAT= sbc_isf_alloc )
204         !
205         IF( lk_mpp             )   CALL mpp_sum ( sbc_isf_alloc )
206         IF( sbc_isf_alloc /= 0 )   CALL ctl_warn('sbc_isf_alloc: failed to allocate arrays.')
207         !
208      END IF
209  END FUNCTION
210
211  SUBROUTINE sbc_isf_init
212      !!---------------------------------------------------------------------
213      !!                  ***  ROUTINE sbc_isf_init  ***
214      !!
215      !! ** Purpose : Initialisation of variables for iceshelf fluxes formulation
216      !!
217      !! ** Method  :  4 parameterizations are available according to nn_isf
218      !!               nn_isf = 1 : Realistic ice_shelf formulation
219      !!                        2 : Beckmann & Goose parameterization
220      !!                        3 : Specified runoff in deptht (Mathiot & al. )
221      !!                        4 : specified fwf and heat flux forcing beneath the ice shelf
222      !!----------------------------------------------------------------------
223      INTEGER               :: ji, jj, jk           ! loop index
224      INTEGER               :: ik                   ! current level index
225      INTEGER               :: ikt, ikb             ! top and bottom level of the isf boundary layer
226      INTEGER               :: inum, ierror
227      INTEGER               :: ios                  ! Local integer output status for namelist read
228      REAL(wp)              :: zhk
229      CHARACTER(len=256)    :: cvarzisf, cvarhisf   ! name for isf file
230      CHARACTER(LEN=32 )    :: cvarLeff             ! variable name for efficient Length scale
231      !!----------------------------------------------------------------------
232      NAMELIST/namsbc_isf/ nn_isfblk, rn_hisf_tbl, rn_gammat0, rn_gammas0, nn_gammablk, nn_isf, &
233                         & sn_fwfisf, sn_rnfisf, sn_depmax_isf, sn_depmin_isf, sn_Leff_isf
234      !!----------------------------------------------------------------------
235
236      REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs
237      READ  ( numnam_ref, namsbc_isf, IOSTAT = ios, ERR = 901)
238901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_isf in reference namelist', lwp )
239
240      REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
241      READ  ( numnam_cfg, namsbc_isf, IOSTAT = ios, ERR = 902 )
242902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_isf in configuration namelist', lwp )
243      IF(lwm) WRITE ( numond, namsbc_isf )
244
245      IF ( lwp ) WRITE(numout,*)
246      IF ( lwp ) WRITE(numout,*) 'sbc_isf: heat flux of the ice shelf'
247      IF ( lwp ) WRITE(numout,*) '~~~~~~~~~'
248      IF ( lwp ) WRITE(numout,*) 'sbcisf :' 
249      IF ( lwp ) WRITE(numout,*) '~~~~~~~~'
250      IF ( lwp ) WRITE(numout,*) '        nn_isf      = ', nn_isf
251      IF ( lwp ) WRITE(numout,*) '        nn_isfblk   = ', nn_isfblk
252      IF ( lwp ) WRITE(numout,*) '        rn_hisf_tbl = ', rn_hisf_tbl
253      IF ( lwp ) WRITE(numout,*) '        nn_gammablk = ', nn_gammablk 
254      IF ( lwp ) WRITE(numout,*) '        rn_gammat0  = ', rn_gammat0 
255      IF ( lwp ) WRITE(numout,*) '        rn_gammas0  = ', rn_gammas0 
256      IF ( lwp ) WRITE(numout,*) '        rn_tfri2    = ', rn_tfri2 
257      !
258      ! Allocate public variable
259      IF ( sbc_isf_alloc()  /= 0 )         CALL ctl_stop( 'STOP', 'sbc_isf : unable to allocate arrays' )
260      !
261      ! initialisation
262      qisf(:,:)        = 0._wp  ; fwfisf  (:,:) = 0._wp
263      risf_tsc(:,:,:)  = 0._wp  ; fwfisf_b(:,:) = 0._wp
264      !
265      ! define isf tbl tickness, top and bottom indice
266      SELECT CASE ( nn_isf )
267      CASE ( 1 ) 
268         rhisf_tbl(:,:) = rn_hisf_tbl
269         misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
270
271      CASE ( 2 , 3 )
272         ALLOCATE( sf_rnfisf(1), STAT=ierror )
273         ALLOCATE( sf_rnfisf(1)%fnow(jpi,jpj,1), sf_rnfisf(1)%fdta(jpi,jpj,1,2) )
274         CALL fld_fill( sf_rnfisf, (/ sn_rnfisf /), cn_dirisf, 'sbc_isf_init', 'read fresh water flux isf data', 'namsbc_isf' )
275
276         !  read effective lenght (BG03)
277         IF (nn_isf == 2) THEN
278            CALL iom_open( sn_Leff_isf%clname, inum )
279            cvarLeff = TRIM(sn_Leff_isf%clvar)
280            CALL iom_get( inum, jpdom_data, cvarLeff, risfLeff , 1)
281            CALL iom_close(inum)
282            !
283            risfLeff = risfLeff*1000.0_wp           !: convertion in m
284         END IF
285
286         ! read depth of the top and bottom of the isf top boundary layer (in this case, isf front depth and grounding line depth)
287         CALL iom_open( sn_depmax_isf%clname, inum )
288         cvarhisf = TRIM(sn_depmax_isf%clvar)
289         CALL iom_get( inum, jpdom_data, cvarhisf, rhisf_tbl, 1) !: depth of deepest point of the ice shelf base
290         CALL iom_close(inum)
291         !
292         CALL iom_open( sn_depmin_isf%clname, inum )
293         cvarzisf = TRIM(sn_depmin_isf%clvar)
294         CALL iom_get( inum, jpdom_data, cvarzisf, rzisf_tbl, 1) !: depth of shallowest point of the ice shelves base
295         CALL iom_close(inum)
296         !
297         rhisf_tbl(:,:) = rhisf_tbl(:,:) - rzisf_tbl(:,:)        !: tickness isf boundary layer
298
299         !! compute first level of the top boundary layer
300         DO ji = 1, jpi
301            DO jj = 1, jpj
302                ik = 2
303                DO WHILE ( ik <= mbkt(ji,jj) .AND. fsdepw(ji,jj,ik) < rzisf_tbl(ji,jj) ) ;  ik = ik + 1 ;  END DO
304                misfkt(ji,jj) = ik-1
305            END DO
306         END DO
307
308      CASE ( 4 ) 
309         ! as in nn_isf == 1
310         rhisf_tbl(:,:) = rn_hisf_tbl
311         misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
312         
313         ! load variable used in fldread (use for temporal interpolation of isf fwf forcing)
314         ALLOCATE( sf_fwfisf(1), STAT=ierror )
315         ALLOCATE( sf_fwfisf(1)%fnow(jpi,jpj,1), sf_fwfisf(1)%fdta(jpi,jpj,1,2) )
316         CALL fld_fill( sf_fwfisf, (/ sn_fwfisf /), cn_dirisf, 'sbc_isf_init', 'read fresh water flux isf data', 'namsbc_isf' )
317
318      END SELECT
319         
320      rhisf_tbl_0(:,:) = rhisf_tbl(:,:)
321
322      ! compute bottom level of isf tbl and thickness of tbl below the ice shelf
323      DO jj = 1,jpj
324         DO ji = 1,jpi
325            ikt = misfkt(ji,jj)
326            ikb = misfkt(ji,jj)
327            ! thickness of boundary layer at least the top level thickness
328            rhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3t_n(ji,jj,ikt))
329
330            ! determine the deepest level influenced by the boundary layer
331            DO jk = ikt+1, mbkt(ji,jj)
332               IF ( (SUM(fse3t_n(ji,jj,ikt:jk-1)) < rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
333            END DO
334            rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(fse3t_n(ji,jj,ikt:ikb))) ! limit the tbl to water thickness.
335            misfkb(ji,jj) = ikb                                                   ! last wet level of the tbl
336            r1_hisf_tbl(ji,jj) = 1._wp / rhisf_tbl(ji,jj)
337
338            zhk           = SUM( fse3t(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj) ! proportion of tbl cover by cell from ikt to ikb - 1
339            ralpha(ji,jj) = rhisf_tbl(ji,jj) * (1._wp - zhk ) / fse3t(ji,jj,ikb)  ! proportion of bottom cell influenced by boundary layer
340         END DO
341      END DO
342
343  END SUBROUTINE sbc_isf_init
344
345  SUBROUTINE sbc_isf_bg03(kt)
346      !!---------------------------------------------------------------------
347      !!                  ***  ROUTINE sbc_isf_bg03  ***
348      !!
349      !! ** Purpose : add net heat and fresh water flux from ice shelf melting
350      !!          into the adjacent ocean
351      !!
352      !! ** Method  :   See reference
353      !!
354      !! ** Reference : Beckmann and Goosse (2003), "A parameterization of ice shelf-ocean
355      !!         interaction for climate models", Ocean Modelling 5(2003) 157-170.
356      !!         (hereafter BG)
357      !! History :
358      !!         06-02  (C. Wang) Original code
359      !!----------------------------------------------------------------------
360      INTEGER, INTENT ( in ) :: kt
361      !
362      INTEGER  :: ji, jj, jk ! dummy loop index
363      INTEGER  :: ik         ! current level
364      REAL(wp) :: zt_sum     ! sum of the temperature between 200m and 600m
365      REAL(wp) :: zt_ave     ! averaged temperature between 200m and 600m
366      REAL(wp) :: zt_frz     ! freezing point temperature at depth z
367      REAL(wp) :: zpress     ! pressure to compute the freezing point in depth
368      !!----------------------------------------------------------------------
369
370      IF ( nn_timing == 1 ) CALL timing_start('sbc_isf_bg03')
371      !
372      DO ji = 1, jpi
373         DO jj = 1, jpj
374            ik = misfkt(ji,jj)
375            !! Initialize arrays to 0 (each step)
376            zt_sum = 0.e0_wp
377            IF ( ik > 1 ) THEN
378               ! 1. -----------the average temperature between 200m and 600m ---------------------
379               DO jk = misfkt(ji,jj),misfkb(ji,jj)
380                  ! freezing point temperature  at ice shelf base BG eq. 2 (JMM sign pb ??? +7.64e-4 !!!)
381                  ! after verif with UNESCO, wrong sign in BG eq. 2
382                  ! Calculate freezing temperature
383                  CALL eos_fzp(stbl(ji,jj), zt_frz, zpress) 
384                  zt_sum = zt_sum + (tsn(ji,jj,jk,jp_tem)-zt_frz) * fse3t(ji,jj,jk) * tmask(ji,jj,jk)  ! sum temp
385               END DO
386               zt_ave = zt_sum/rhisf_tbl(ji,jj) ! calcul mean value
387               ! 2. ------------Net heat flux and fresh water flux due to the ice shelf
388               ! For those corresponding to zonal boundary   
389               qisf(ji,jj) = - rau0 * rcp * rn_gammat0 * risfLeff(ji,jj) * e1t(ji,jj) * zt_ave  &
390                           & * r1_e1e2t(ji,jj) * tmask(ji,jj,jk)
391             
392               fwfisf(ji,jj) = qisf(ji,jj) / rlfusisf          !fresh water flux kg/(m2s)                 
393               fwfisf(ji,jj) = fwfisf(ji,jj) * ( soce / stbl(ji,jj) )
394               !add to salinity trend
395            ELSE
396               qisf(ji,jj) = 0._wp ; fwfisf(ji,jj) = 0._wp
397            END IF
398         END DO
399      END DO
400      !
401      IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_bg03')
402      !
403  END SUBROUTINE sbc_isf_bg03
404
405  SUBROUTINE sbc_isf_cav( kt )
406      !!---------------------------------------------------------------------
407      !!                     ***  ROUTINE sbc_isf_cav  ***
408      !!
409      !! ** Purpose :   handle surface boundary condition under ice shelf
410      !!
411      !! ** Method  : -
412      !!
413      !! ** Action  :   utau, vtau : remain unchanged
414      !!                taum, wndm : remain unchanged
415      !!                qns        : update heat flux below ice shelf
416      !!                emp, emps  : update freshwater flux below ice shelf
417      !!---------------------------------------------------------------------
418      INTEGER, INTENT(in)          ::   kt         ! ocean time step
419      !
420      INTEGER  ::   ji, jj     ! dummy loop indices
421      INTEGER  ::   nit
422      REAL(wp) ::   zlamb1, zlamb2, zlamb3
423      REAL(wp) ::   zeps1,zeps2,zeps3,zeps4,zeps6,zeps7
424      REAL(wp) ::   zaqe,zbqe,zcqe,zaqer,zdis,zsfrz,zcfac
425      REAL(wp) ::   zeps = 1.e-20_wp       
426      REAL(wp) ::   zerr
427      REAL(wp), DIMENSION(:,:), POINTER ::   zfrz
428      REAL(wp), DIMENSION(:,:), POINTER ::   zgammat, zgammas 
429      REAL(wp), DIMENSION(:,:), POINTER ::   zfwflx, zhtflx, zhtflx_b
430      LOGICAL  ::   lit
431      !!---------------------------------------------------------------------
432      ! coeficient for linearisation of potential tfreez
433      ! Crude approximation for pressure (but commonly used)
434      zlamb1 =-0.0573_wp
435      zlamb2 = 0.0832_wp
436      zlamb3 =-7.53e-08_wp * grav * rau0
437      IF( nn_timing == 1 )  CALL timing_start('sbc_isf_cav')
438      !
439      CALL wrk_alloc( jpi,jpj, zfrz  , zgammat, zgammas  )
440      CALL wrk_alloc( jpi,jpj, zfwflx, zhtflx , zhtflx_b )
441
442      ! initialisation
443      zgammat(:,:) = rn_gammat0 ; zgammas (:,:) = rn_gammas0
444      zhtflx (:,:) = 0.0_wp     ; zhtflx_b(:,:) = 0.0_wp   
445      zfwflx (:,:) = 0.0_wp
446
447      ! compute ice shelf melting
448      nit = 1 ; lit = .TRUE.
449      DO WHILE ( lit )    ! maybe just a constant number of iteration as in blk_core is fine
450         SELECT CASE ( nn_isfblk )
451         CASE ( 1 )   !  ISOMIP formulation (2 equations) for volume flux (Hunter et al., 2006)
452            ! Calculate freezing temperature
453            CALL eos_fzp( stbl(:,:), zfrz(:,:), risfdep(:,:) )
454
455            ! compute gammat every where (2d)
456            CALL sbc_isf_gammats(zgammat, zgammas, zhtflx, zfwflx)
457           
458            ! compute upward heat flux zhtflx and upward water flux zwflx
459            DO jj = 1, jpj
460               DO ji = 1, jpi
461                  zhtflx(ji,jj) =   zgammat(ji,jj)*rcp*rau0*(ttbl(ji,jj)-zfrz(ji,jj))
462                  zfwflx(ji,jj) = - zhtflx(ji,jj)/rlfusisf
463               END DO
464            END DO
465
466            ! Compute heat flux and upward fresh water flux
467            qisf  (:,:) = - zhtflx(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:)
468            fwfisf(:,:) =   zfwflx(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:)
469
470         CASE ( 2 )  ! ISOMIP+ formulation (3 equations) for volume flux (Asay-Davis et al., 2015)
471            ! compute gammat every where (2d)
472            CALL sbc_isf_gammats(zgammat, zgammas, zhtflx, zfwflx)
473
474            ! compute upward heat flux zhtflx and upward water flux zwflx
475            ! Resolution of a 2d equation from equation 21, 22 and 23 to find Sb (Asay-Davis et al., 2015)
476            DO jj = 1, jpj
477               DO ji = 1, jpi
478                  ! compute coeficient to solve the 2nd order equation
479                  zeps1 = rcp*rau0*zgammat(ji,jj)
480                  zeps2 = rlfusisf*rau0*zgammas(ji,jj)
481                  zeps3 = rhoisf*rcpi*rkappa/MAX(risfdep(ji,jj),zeps)
482                  zeps4 = zlamb2+zlamb3*risfdep(ji,jj)
483                  zeps6 = zeps4-ttbl(ji,jj)
484                  zeps7 = zeps4-tsurf
485                  zaqe  = zlamb1 * (zeps1 + zeps3)
486                  zaqer = 0.5_wp/MIN(zaqe,-zeps)
487                  zbqe  = zeps1*zeps6+zeps3*zeps7-zeps2
488                  zcqe  = zeps2*stbl(ji,jj)
489                  zdis  = zbqe*zbqe-4.0_wp*zaqe*zcqe               
490
491                  ! Presumably zdis can never be negative because gammas is very small compared to gammat
492                  ! compute s freeze
493                  zsfrz=(-zbqe-SQRT(zdis))*zaqer
494                  IF ( zsfrz < 0.0_wp ) zsfrz=(-zbqe+SQRT(zdis))*zaqer
495
496                  ! compute t freeze (eq. 22)
497                  zfrz(ji,jj)=zeps4+zlamb1*zsfrz
498 
499                  ! zfwflx is upward water flux
500                  ! zhtflx is upward heat flux (out of ocean)
501                  ! compute the upward water and heat flux (eq. 28 and eq. 29)
502                  zfwflx(ji,jj) = rau0 * zgammas(ji,jj) * (zsfrz-stbl(ji,jj)) / MAX(zsfrz,zeps)
503                  zhtflx(ji,jj) = zgammat(ji,jj) * rau0 * rcp * (ttbl(ji,jj) - zfrz(ji,jj) ) 
504               END DO
505            END DO
506
507            ! compute heat and water flux
508            qisf  (:,:) = - zhtflx(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:)
509            fwfisf(:,:) =   zfwflx(:,:) * (1._wp - tmask(:,:,1)) * ssmask(:,:)
510
511         END SELECT
512
513         ! define if we need to iterate (nn_gammablk 0/1 do not need iteration)
514         IF ( nn_gammablk <  2 ) THEN ; lit = .FALSE.
515         ELSE                           
516            ! check total number of iteration
517            IF (nit >= 100) THEN ; CALL ctl_stop( 'STOP', 'sbc_isf_hol99 : too many iteration ...' )
518            ELSE                 ; nit = nit + 1
519            END IF
520
521            ! compute error between 2 iterations
522            ! if needed save gammat and compute zhtflx_b for next iteration
523            zerr = MAXVAL(ABS(zhtflx-zhtflx_b))
524            IF ( zerr <= 0.01_wp ) THEN ; lit = .FALSE.
525            ELSE                        ; zhtflx_b(:,:) = zhtflx(:,:)
526            END IF
527         END IF
528      END DO
529      !
530      CALL iom_put('isfgammat', zgammat)
531      CALL iom_put('isfgammas', zgammas)
532      !
533      CALL wrk_dealloc( jpi,jpj, zfrz  , zgammat, zgammas  )
534      CALL wrk_dealloc( jpi,jpj, zfwflx, zhtflx , zhtflx_b )
535      !
536      IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_cav')
537      !
538   END SUBROUTINE sbc_isf_cav
539
540   SUBROUTINE sbc_isf_gammats(pgt, pgs, pqhisf, pqwisf )
541      !!----------------------------------------------------------------------
542      !! ** Purpose    : compute the coefficient echange for heat flux
543      !!
544      !! ** Method     : gamma assume constant or depends of u* and stability
545      !!
546      !! ** References : Holland and Jenkins, 1999, JPO, p1787-1800, eq 14
547      !!                Jenkins et al., 2010, JPO, p2298-2312
548      !!---------------------------------------------------------------------
549      REAL(wp), DIMENSION(:,:), INTENT(out) :: pgt, pgs
550      REAL(wp), DIMENSION(:,:), INTENT(in ) :: pqhisf, pqwisf
551      !
552      INTEGER  :: ikt                       
553      INTEGER  :: ji, jj                     ! loop index
554      REAL(wp), DIMENSION(:,:), POINTER :: zustar           ! U, V at T point and friction velocity
555      REAL(wp) :: zdku, zdkv                 ! U, V shear
556      REAL(wp) :: zPr, zSc, zRc              ! Prandtl, Scmidth and Richardson number
557      REAL(wp) :: zmob, zmols                ! Monin Obukov length, coriolis factor at T point
558      REAL(wp) :: zbuofdep, zhnu             ! Bouyancy length scale, sublayer tickness
559      REAL(wp) :: zhmax                      ! limitation of mol
560      REAL(wp) :: zetastar                   ! stability parameter
561      REAL(wp) :: zgmolet, zgmoles, zgturb   ! contribution of modelecular sublayer and turbulence
562      REAL(wp) :: zcoef                      ! temporary coef
563      REAL(wp) :: zdep
564      REAL(wp) :: zeps = 1.0e-20_wp   
565      REAL(wp), PARAMETER :: zxsiN = 0.052_wp   ! dimensionless constant
566      REAL(wp), PARAMETER :: znu   = 1.95e-6_wp ! kinamatic viscosity of sea water (m2.s-1)
567      REAL(wp), DIMENSION(2) :: zts, zab
568      !!---------------------------------------------------------------------
569      CALL wrk_alloc( jpi,jpj, zustar )
570      !
571      SELECT CASE ( nn_gammablk )
572      CASE ( 0 ) ! gamma is constant (specified in namelist)
573         !! ISOMIP formulation (Hunter et al, 2006)
574         pgt(:,:) = rn_gammat0
575         pgs(:,:) = rn_gammas0
576
577      CASE ( 1 ) ! gamma is assume to be proportional to u*
578         !! Jenkins et al., 2010, JPO, p2298-2312
579         !! Adopted by Asay-Davis et al. (2015)
580
581         !! compute ustar (eq. 24)
582         zustar(:,:) = SQRT( rn_tfri2 * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + rn_tfeb2) )
583
584         !! Compute gammats
585         pgt(:,:) = zustar(:,:) * rn_gammat0
586         pgs(:,:) = zustar(:,:) * rn_gammas0
587     
588      CASE ( 2 ) ! gamma depends of stability of boundary layer
589         !! Holland and Jenkins, 1999, JPO, p1787-1800, eq 14
590         !! as MOL depends of flux and flux depends of MOL, best will be iteration (TO DO)
591         !! compute ustar
592         zustar(:,:) = SQRT( rn_tfri2 * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + rn_tfeb2) )
593
594         !! compute Pr and Sc number (can be improved)
595         zPr =   13.8_wp
596         zSc = 2432.0_wp
597
598         !! compute gamma mole
599         zgmolet = 12.5_wp * zPr ** (2.0/3.0) - 6.0_wp
600         zgmoles = 12.5_wp * zSc ** (2.0/3.0) - 6.0_wp
601
602         !! compute gamma
603         DO ji=2,jpi
604            DO jj=2,jpj
605               ikt = mikt(ji,jj)
606
607               IF (zustar(ji,jj) == 0._wp) THEN           ! only for kt = 1 I think
608                  pgt = rn_gammat0
609                  pgs = rn_gammas0
610               ELSE
611                  !! compute Rc number (as done in zdfric.F90)
612                  zcoef = 0.5_wp / fse3w(ji,jj,ikt)
613                  !                                            ! shear of horizontal velocity
614                  zdku = zcoef * (  un(ji-1,jj  ,ikt  ) + un(ji,jj,ikt  )  &
615                     &             -un(ji-1,jj  ,ikt+1) - un(ji,jj,ikt+1)  )
616                  zdkv = zcoef * (  vn(ji  ,jj-1,ikt  ) + vn(ji,jj,ikt  )  &
617                     &             -vn(ji  ,jj-1,ikt+1) - vn(ji,jj,ikt+1)  )
618                  !                                            ! richardson number (minimum value set to zero)
619                  zRc = rn2(ji,jj,ikt+1) / MAX( zdku*zdku + zdkv*zdkv, zeps )
620
621                  !! compute bouyancy
622                  zts(jp_tem) = ttbl(ji,jj)
623                  zts(jp_sal) = stbl(ji,jj)
624                  zdep        = fsdepw(ji,jj,ikt)
625                  !
626                  CALL eos_rab( zts, zdep, zab )
627                  !
628                  !! compute length scale
629                  zbuofdep = grav * ( zab(jp_tem) * pqhisf(ji,jj) - zab(jp_sal) * pqwisf(ji,jj) )  !!!!!!!!!!!!!!!!!!!!!!!!!!!!
630
631                  !! compute Monin Obukov Length
632                  ! Maximum boundary layer depth
633                  zhmax = fsdept(ji,jj,mbkt(ji,jj)) - fsdepw(ji,jj,mikt(ji,jj)) - 0.001_wp
634                  ! Compute Monin obukhov length scale at the surface and Ekman depth:
635                  zmob   = zustar(ji,jj) ** 3 / (vkarmn * (zbuofdep + zeps))
636                  zmols  = SIGN(1._wp, zmob) * MIN(ABS(zmob), zhmax) * tmask(ji,jj,ikt)
637
638                  !! compute eta* (stability parameter)
639                  zetastar = 1._wp / ( SQRT(1._wp + MAX(zxsiN * zustar(ji,jj) / ( ABS(ff(ji,jj)) * zmols * zRc ), 0.0_wp)))
640
641                  !! compute the sublayer thickness
642                  zhnu = 5 * znu / zustar(ji,jj)
643
644                  !! compute gamma turb
645                  zgturb = 1._wp / vkarmn * LOG(zustar(ji,jj) * zxsiN * zetastar * zetastar / ( ABS(ff(ji,jj)) * zhnu )) &
646                  &      + 1._wp / ( 2 * zxsiN * zetastar ) - 1._wp / vkarmn
647
648                  !! compute gammats
649                  pgt(ji,jj) = zustar(ji,jj) / (zgturb + zgmolet)
650                  pgs(ji,jj) = zustar(ji,jj) / (zgturb + zgmoles)
651               END IF
652            END DO
653         END DO
654         CALL lbc_lnk(pgt(:,:),'T',1.)
655         CALL lbc_lnk(pgs(:,:),'T',1.)
656      END SELECT
657      CALL wrk_dealloc( jpi,jpj, zustar )
658      !
659   END SUBROUTINE sbc_isf_gammats
660
661   SUBROUTINE sbc_isf_tbl( pvarin, pvarout, cd_ptin )
662      !!----------------------------------------------------------------------
663      !!                  ***  SUBROUTINE sbc_isf_tbl  ***
664      !!
665      !! ** Purpose : compute mean T/S/U/V in the boundary layer at T- point
666      !!
667      !!----------------------------------------------------------------------
668      REAL(wp), DIMENSION(:,:,:), INTENT( in  ) :: pvarin
669      REAL(wp), DIMENSION(:,:)  , INTENT( out ) :: pvarout
670      CHARACTER(len=1),           INTENT( in  ) :: cd_ptin ! point of variable in/out
671      !
672      REAL(wp) :: ze3, zhk
673      REAL(wp), DIMENSION(:,:), POINTER :: zhisf_tbl ! thickness of the tbl
674
675      INTEGER :: ji, jj, jk                  ! loop index
676      INTEGER :: ikt, ikb                    ! top and bottom index of the tbl
677      !!----------------------------------------------------------------------
678      ! allocation
679      CALL wrk_alloc( jpi,jpj, zhisf_tbl)
680     
681      ! initialisation
682      pvarout(:,:)=0._wp
683   
684      SELECT CASE ( cd_ptin )
685      CASE ( 'U' ) ! compute U in the top boundary layer at T- point
686         DO jj = 1,jpj
687            DO ji = 1,jpi
688               ikt = miku(ji,jj) ; ikb = miku(ji,jj)
689               ! thickness of boundary layer at least the top level thickness
690               zhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3u_n(ji,jj,ikt))
691
692               ! determine the deepest level influenced by the boundary layer
693               DO jk = ikt+1, mbku(ji,jj)
694                  IF ( (SUM(fse3u_n(ji,jj,ikt:jk-1)) < zhisf_tbl(ji,jj)) .AND. (umask(ji,jj,jk) == 1) ) ikb = jk
695               END DO
696               zhisf_tbl(ji,jj) = MIN(zhisf_tbl(ji,jj), SUM(fse3u_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
697
698               ! level fully include in the ice shelf boundary layer
699               DO jk = ikt, ikb - 1
700                  ze3 = fse3u_n(ji,jj,jk)
701                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) / zhisf_tbl(ji,jj) * ze3
702               END DO
703
704               ! level partially include in ice shelf boundary layer
705               zhk = SUM( fse3u_n(ji, jj, ikt:ikb - 1)) / zhisf_tbl(ji,jj)
706               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
707            END DO
708         END DO
709         DO jj = 2,jpj
710            DO ji = 2,jpi
711               pvarout(ji,jj) = 0.5_wp * (pvarout(ji,jj) + pvarout(ji-1,jj))
712            END DO
713         END DO
714         CALL lbc_lnk(pvarout,'T',-1.)
715     
716      CASE ( 'V' ) ! compute V in the top boundary layer at T- point
717         DO jj = 1,jpj
718            DO ji = 1,jpi
719               ikt = mikv(ji,jj) ; ikb = mikv(ji,jj)
720               ! thickness of boundary layer at least the top level thickness
721               zhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3v_n(ji,jj,ikt))
722
723               ! determine the deepest level influenced by the boundary layer
724               DO jk = ikt+1, mbkv(ji,jj)
725                  IF ( (SUM(fse3v_n(ji,jj,ikt:jk-1)) < zhisf_tbl(ji,jj)) .AND. (vmask(ji,jj,jk) == 1) ) ikb = jk
726               END DO
727               zhisf_tbl(ji,jj) = MIN(zhisf_tbl(ji,jj), SUM(fse3v_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
728
729               ! level fully include in the ice shelf boundary layer
730               DO jk = ikt, ikb - 1
731                  ze3 = fse3v_n(ji,jj,jk)
732                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) / zhisf_tbl(ji,jj) * ze3
733               END DO
734
735               ! level partially include in ice shelf boundary layer
736               zhk = SUM( fse3v_n(ji, jj, ikt:ikb - 1)) / zhisf_tbl(ji,jj)
737               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
738            END DO
739         END DO
740         DO jj = 2,jpj
741            DO ji = 2,jpi
742               pvarout(ji,jj) = 0.5_wp * (pvarout(ji,jj) + pvarout(ji,jj-1))
743            END DO
744         END DO
745         CALL lbc_lnk(pvarout,'T',-1.)
746
747      CASE ( 'T' ) ! compute T in the top boundary layer at T- point
748         DO jj = 1,jpj
749            DO ji = 1,jpi
750               ikt = misfkt(ji,jj)
751               ikb = misfkb(ji,jj)
752
753               ! level fully include in the ice shelf boundary layer
754               DO jk = ikt, ikb - 1
755                  ze3 = fse3t_n(ji,jj,jk)
756                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) * r1_hisf_tbl(ji,jj) * ze3
757               END DO
758
759               ! level partially include in ice shelf boundary layer
760               zhk = SUM( fse3t_n(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)
761               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
762            END DO
763         END DO
764      END SELECT
765
766      ! mask mean tbl value
767      pvarout(:,:) = pvarout(:,:) * ssmask(:,:)
768
769      ! deallocation
770      CALL wrk_dealloc( jpi,jpj, zhisf_tbl )     
771      !
772   END SUBROUTINE sbc_isf_tbl
773     
774
775   SUBROUTINE sbc_isf_div( phdivn )
776      !!----------------------------------------------------------------------
777      !!                  ***  SUBROUTINE sbc_isf_div  ***
778      !!       
779      !! ** Purpose :   update the horizontal divergence with the runoff inflow
780      !!
781      !! ** Method  :   
782      !!                CAUTION : risf_tsc(:,:,jp_sal) is negative (outflow) increase the
783      !!                          divergence and expressed in m/s
784      !!
785      !! ** Action  :   phdivn   decreased by the runoff inflow
786      !!----------------------------------------------------------------------
787      REAL(wp), DIMENSION(:,:,:), INTENT( inout ) ::   phdivn   ! horizontal divergence
788      !
789      INTEGER  ::   ji, jj, jk   ! dummy loop indices
790      INTEGER  ::   ikt, ikb 
791      REAL(wp) ::   zhk
792      REAL(wp) ::   zfact     ! local scalar
793      !!----------------------------------------------------------------------
794      !
795      zfact   = 0.5_wp
796      !
797      IF ( lk_vvl ) THEN     ! need to re compute level distribution of isf fresh water
798         DO jj = 1,jpj
799            DO ji = 1,jpi
800               ikt = misfkt(ji,jj)
801               ikb = misfkt(ji,jj)
802               ! thickness of boundary layer at least the top level thickness
803               rhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3t(ji,jj,ikt))
804
805               ! determine the deepest level influenced by the boundary layer
806               DO jk = ikt+1, mbkt(ji,jj)
807                  IF ( (SUM(fse3t(ji,jj,ikt:jk-1)) <  rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
808               END DO
809               rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(fse3t(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
810               misfkb(ji,jj) = ikb                                                  ! last wet level of the tbl
811               r1_hisf_tbl(ji,jj) = 1._wp / rhisf_tbl(ji,jj)
812
813               zhk           = SUM( fse3t(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj) ! proportion of tbl cover by cell from ikt to ikb - 1
814               ralpha(ji,jj) = rhisf_tbl(ji,jj) * (1._wp - zhk ) / fse3t(ji,jj,ikb)  ! proportion of bottom cell influenced by boundary layer
815            END DO
816         END DO
817      END IF 
818      !
819      !==   ice shelf melting distributed over several levels   ==!
820      DO jj = 1,jpj
821         DO ji = 1,jpi
822               ikt = misfkt(ji,jj)
823               ikb = misfkb(ji,jj)
824               ! level fully include in the ice shelf boundary layer
825               DO jk = ikt, ikb - 1
826                  phdivn(ji,jj,jk) = phdivn(ji,jj,jk) + ( fwfisf(ji,jj) + fwfisf_b(ji,jj) ) &
827                    &              * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact
828               END DO
829               ! level partially include in ice shelf boundary layer
830               phdivn(ji,jj,ikb) = phdivn(ji,jj,ikb) + ( fwfisf(ji,jj) &
831                    &            + fwfisf_b(ji,jj) ) * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact * ralpha(ji,jj) 
832         END DO
833      END DO
834      !
835   END SUBROUTINE sbc_isf_div
836   !!======================================================================
837END MODULE sbcisf
Note: See TracBrowser for help on using the repository browser.