SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
modi_glt_vhdiff_r.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 !GLT_LIC The GELATO model is a seaice model used in stand-alone or embedded mode.
6 !GLT_LIC It has been developed by Meteo-France. The holder of GELATO is Meteo-France.
7 !GLT_LIC
8 !GLT_LIC This software is governed by the CeCILL-C license under French law and biding
9 !GLT_LIC by the rules of distribution of free software. See the CeCILL-C_V1-en.txt
10 !GLT_LIC (English) and CeCILL-C_V1-fr.txt (French) for details. The CeCILL is a free
11 !GLT_LIC software license, explicitly compatible with the GNU GPL
12 !GLT_LIC (see http://www.gnu.org/licenses/license-list.en.html#CeCILL)
13 !GLT_LIC
14 !GLT_LIC The CeCILL-C licence agreement grants users the right to modify and re-use the
15 !GLT_LIC software governed by this free software license. The exercising of this right
16 !GLT_LIC is conditional upon the obligation to make available to the community the
17 !GLT_LIC modifications made to the source code of the software so as to contribute to
18 !GLT_LIC its evolution.
19 !GLT_LIC
20 !GLT_LIC In consideration of access to the source code and the rights to copy, modify
21 !GLT_LIC and redistribute granted by the license, users are provided only with a limited
22 !GLT_LIC warranty and the software's author, the holder of the economic rights, and the
23 !GLT_LIC successive licensors only have limited liability. In this respect, the risks
24 !GLT_LIC associated with loading, using, modifying and/or developing or reproducing the
25 !GLT_LIC software by the user are brought to the user's attention, given its Free
26 !GLT_LIC Software status, which may make it complicated to use, with the result that its
27 !GLT_LIC use is reserved for developers and experienced professionals having in-depth
28 !GLT_LIC computer knowledge. Users are therefore encouraged to load and test the
29 !GLT_LIC suitability of the software as regards their requirements in conditions enabling
30 !GLT_LIC the security of their systems and/or data to be ensured and, more generally, to
31 !GLT_LIC use and operate it in the same conditions of security.
32 !GLT_LIC
33 !GLT_LIC The GELATO sofware is cureently distibuted with the SURFEX software, available at
34 !GLT_LIC http://www.cnrm.meteo.fr/surfex. The fact that you download the software deemed that
35 !GLT_LIC you had knowledge of the CeCILL-C license and that you accept its terms.
36 !GLT_LIC Attempts to use this software in a way not complying with CeCILL-C license
37 !GLT_LIC may lead to prosecution.
38 !GLT_LIC
39 !
40 !* Note that here, pent is the vertical profile (updated as
41 ! the routine is called); pvsp is the vertical salinity profile.
42 !* pswtra is the absorbed solar heat flux by level by level due to
43 ! solar irradiance transmission.
44 !* An enthalpy difference is returned, by levels (pdhmelt), in J.m-2.
45 ! It is set to zero if the sea ice does not melt, else it is positive
46 ! where there is melting
47 !
48 ! Modified: 11/2009 (D. Salas y Melia, Ouessant - storm outside)
49 ! sea ice specific heat is now a function of temperature and salinity
50 ! Modified: 02/2010 (D. Salas y Melia)
51 ! to make the routine shorter, ice only / ice+snow slabs are treated
52 ! through two routine CALL.
53 !
54 !THXS_SFX!MODULE modi_glt_vhdiff_r
55 !THXS_SFX!INTERFACE
56 !THXS_SFX!!
57 !THXS_SFX!SUBROUTINE glt_vhdiff_r &
58 !THXS_SFX! ( tpdom,pmlf,pderiv,tpsit,tpdia, &
59 !THXS_SFX! pnsftop,pswtra,pent,pvsp,pcondb,pqtopmelt,pdhmelt,gsmelt )
60 !THXS_SFX! USE modd_glt_param
61 !THXS_SFX! USE modd_types_glt
62 !THXS_SFX! TYPE(t_dom), DIMENSION(np), INTENT(in) :: &
63 !THXS_SFX! tpdom
64 !THXS_SFX! REAL, DIMENSION(np), INTENT(in) :: &
65 !THXS_SFX! pmlf
66 !THXS_SFX! REAL, DIMENSION(nt,np), INTENT(inout) :: &
67 !THXS_SFX! pderiv
68 !THXS_SFX! TYPE(t_sit), DIMENSION(nt,np), INTENT(inout) :: &
69 !THXS_SFX! tpsit
70 !THXS_SFX! TYPE(t_dia), DIMENSION(np), INTENT(inout) :: &
71 !THXS_SFX! tpdia
72 !THXS_SFX!! Note that this input pnsftop is improper (input is NS heat flux)
73 !THXS_SFX!! Output is top melt heat flux
74 !THXS_SFX! REAL, DIMENSION(nt,np), INTENT(inout) :: &
75 !THXS_SFX! pnsftop
76 !THXS_SFX! REAL, DIMENSION(nl,nt,np), INTENT(in) :: &
77 !THXS_SFX! pswtra
78 !THXS_SFX! REAL, DIMENSION(nl,nt,np), INTENT(inout) :: &
79 !THXS_SFX! pent
80 !THXS_SFX! REAL, DIMENSION(nl,nt,np), INTENT(inout) :: &
81 !THXS_SFX! pvsp
82 !THXS_SFX! REAL, DIMENSION(nt,np), INTENT(out) :: &
83 !THXS_SFX! pcondb,pqtopmelt
84 !THXS_SFX! REAL, DIMENSION(nl,nt,np), INTENT(out) :: &
85 !THXS_SFX! pdhmelt
86 !THXS_SFX! LOGICAL, DIMENSION(nt,np), INTENT(out) :: &
87 !THXS_SFX! gsmelt
88 !THXS_SFX!END SUBROUTINE glt_vhdiff_r
89 !THXS_SFX!!
90 !THXS_SFX!END INTERFACE
91 !THXS_SFX!END MODULE modi_glt_vhdiff_r
92 !
93 ! ---------------------- END MODULE modi_glt_vhdiff_r -----------------------
94 !
95 !
96 ! -----------------------------------------------------------------------
97 ! ------------------------ SUBROUTINE glt_vhdiff_r --------------------------
98 !
99 SUBROUTINE glt_vhdiff_r &
100  ( tpdom,pmlf,pderiv,tpsit,tpdia, &
101  pnsftop,pswtra,pent,pvsp,pcondb,pqtopmelt,pdhmelt,gsmelt )
102 !
104  USE modd_glt_param
105  USE modd_types_glt
106  USE modd_glt_vhd
109  USE modi_gltools_glterr
110  USE modi_glt_vhdslab_r
111  USE mode_glt_stats_r
112 !
113  IMPLICIT NONE
114 !
115 !
116 !
117 ! 1. Variables
118 ! ============
119 !
120 ! 1.1. Dummy arguments
121 ! --------------------
122  TYPE(t_dom), DIMENSION(np), INTENT(in) :: &
123  tpdom
124  REAL, DIMENSION(np), INTENT(in) :: &
125  pmlf
126  REAL, DIMENSION(nt,np), INTENT(inout) :: &
127  pderiv
128  TYPE(t_sit), DIMENSION(nt,np), INTENT(inout) :: &
129  tpsit
130  TYPE(t_dia), DIMENSION(np), INTENT(inout) :: &
131  tpdia
132  REAL, DIMENSION(nt,np), INTENT(inout) :: &
133  pnsftop
134  REAL, DIMENSION(nl,nt,np), INTENT(in) :: &
135  pswtra
136  REAL, DIMENSION(nl,nt,np), INTENT(inout) :: &
137  pent
138  REAL, DIMENSION(nl,nt,np), INTENT(inout) :: &
139  pvsp
140  REAL, DIMENSION(nt,np), INTENT(out) :: &
141  pcondb,pqtopmelt
142  REAL, DIMENSION(nl,nt,np), INTENT(out) :: &
143  pdhmelt
144  LOGICAL, DIMENSION(nt,np), INTENT(out) :: &
145  gsmelt
146 !
147 !
148 ! 1.2. Local variables
149 ! --------------------
150 !
151  LOGICAL :: &
152  llice,llsnw,llmelt,llconv,lltempcond
153  LOGICAL, DIMENSION(nt,np) :: &
154  omask
155  CHARACTER(80) :: &
156  ymess
157  INTEGER, PARAMETER :: &
158  nit=20
159  INTEGER :: &
160  jp,jk,jl,jit
161  INTEGER, DIMENSION(nt,np) :: &
162  icv,icount
163  LOGICAL, DIMENSION(nt,np) :: &
164  gmask
165  REAL :: &
166  zcva,zcvb,zdhmelt,zhs
167  REAL :: &
168  zcpsn,zrks,zfsi,zrkeq,zderiv, &
169  zinsftop,zicondb,zidhi,zidhs, &
170  ziswa,zinrg,ztsfa,zcondb,zqtopmelta
171  REAL, DIMENSION(nilay) :: &
172  zdzi
173  REAL, DIMENSION(0:nilay) :: &
174  ztsia
175  REAL, DIMENSION(nilay) :: &
176  zrkice,zvsp0
177  REAL, DIMENSION(np) :: &
178  zfsit
179  REAL, DIMENSION(nl) :: &
180  zvtpa,zdhmelta,zdh
181  REAL, DIMENSION(nt,np) :: &
182  ztsftrd,zderiv2,ztint,zwork
183  REAL, DIMENSION(nt,np) :: &
184  z1,z2,z3,z4,z5,z6,z7, &
185  zswtra_all,zcondb_all,zderiv_all,zdh_all,zqtopmelta_all, &
186  zdhmelt0,zdhmelt1,zdhmelt2,zdhmelt3,zdhmelt4,zdhmelt5, &
187  zei1,zes1,zei2,zes2
188  type(t_vtp), dimension(nl,nt,np) :: &
189  tzsil
190  REAL, DIMENSION(nl,nt,np) :: &
191  ztsi_m
192  REAL, DIMENSION(nl,nt,np) :: &
193  zvtptrd,zvtp,zdent,zdenti
194  REAL :: &
195  ztot_ice_snow, zfailures
196 !
197 !
198 !
199 ! 2. Initializations
200 ! ===================
201 !
202 ! 2.1. Parameter error checks
203 ! ----------------------------
204 !
205  IF ( nslay/=1 ) THEN
206  CALL gltools_glterr( 'vhdiff', &
207  'The number of snow layers should be equal to 1','STOP' )
208  ENDIF
209 !
210  IF ( nilay<3 ) THEN
211  CALL gltools_glterr( 'vhdiff', &
212  'The number of ice layers should be >= 3','STOP' )
213  ENDIF
214 !
215 !
216 ! 2.2. Allocations
217 ! -----------------
218 !
219 ! .. Note that for some platforms, these locally-allocated arrays need be
220 ! deallocated (in reverse order) after use.
221 !
222  ALLOCATE( zetai(0:nilay))
223  ALLOCATE( zinvetai(0:nilay) )
224  ALLOCATE( zetaik(0:nilay))
225  ALLOCATE( zetaikp1(0:nilay) )
226  ALLOCATE( zrhocpsi(nilay))
227  ALLOCATE( ztsib(0:nilay))
228  ALLOCATE( ztsi0(0:nilay) )
229  ALLOCATE( ztsi_m0(0:nilay) )
230  ALLOCATE( zkodzi(0:nilay+1) )
231 !
232 !
233 ! 2.3. Global initializations
234 ! ----------------------------
235 !
236 ! .. Temperature at snow/ice interface diagnostic
237 !
238  ztint(:,:) = xbig20
239 !
240 ! .. Sea ice and snow melting point
241 !
242  ztsi_m(:,:,:) = -mu * pvsp(:,:,:)
243 !
244 ! .. Surface flux derivative by T
245 !
246  zderiv2(:,:) = 0.
247 !
248 ! .. Save initial enthalpy (must be done before first operation on enthalpy)
249 !
250 ! zento(:,:,:) = pent(:,:,:)
251 !
252 ! .. Initialise enthalpy change due to heat diffusion
253 !
254  zdent(:,:,:) = 0.
255 !
256 ! .. Temperature trends
257 !
258  ztsftrd(:,:) = 0.
259  zvtptrd(:,:,:) = 0.
260 !
261 ! .. Output gltools_enthalpy used to melt ice
262 !
263  pdhmelt(:,:,:) = 0.
264 !
265 ! .. Output bottom heat flux
266 !
267  pcondb(:,:) = 0.
268 !
269 ! .. Output boolean indicating melting
270 !
271  gsmelt(:,:) = .false.
272 !
273 ! .. Constants used for bottom conduction flux
274 !
275 ! zg1 = 3.
276 ! zg2 = -1./3.
277  zg1 = 1.
278  zg2 = 0.
279 !
280 ! .. Initialize convergence boolean and loop counter
281 !
282  icv(:,:) = 0
283 !
284 ! .. Sea ice mask
285  omask(:,:) = .false.
286  WHERE( tpsit(:,:)%hsi>epsil1 )
287  omask(:,:) = .true.
288  ENDWHERE
289 !
290 ! .. Enthalpy may be greater than melting sea ice gltools_enthalpy, e.g. due to
291 ! transport: correct this, and collect the corresponding energy to melt ice or
292 ! snow.
293 !
294 ! Sea ice part
295 !write(noutlu,*)'dhmelt(1)=',sum(sum(pdhmelt(:,:,1),dim=1)*pfsi(:,1))/dtt
296 ! Note that pdhmelt is in J.m-2 and pent is in J.kg-1
297 !tzsil%vsp = 0.
298 !tzsil%ent = pent
299 !call glt_aventh(tpsit,tzsil,zei1,zes1)
300 !print*,'step 1', sum( sum( pdhmelt,dim=1 )*tpsit%fsi )/dtt
301  zdenti = pent(:,:,:)
302 !
303  DO jl=1,nilay
304  WHERE ( pent(jl,:,:)>cpsw*ztsi_m(jl,:,:) )
305  pdhmelt(jl,:,:) = pdhmelt(jl,:,:) + &
306  rhoice*tpsit(:,:)%hsi*sf3tinv(jl)*( pent(jl,:,:)-cpsw*ztsi_m(jl,:,:) )
307  pent(jl,:,:) = cpsw*ztsi_m(jl,:,:)
308  ENDWHERE
309  END DO
310 !write(noutlu,*)'dhmelt(2)=',sum(sum(pdhmelt(:,:,1),dim=1)*pfsi(:,1))/dtt
311 !print*,'step 2', sum( sum( pdhmelt,dim=1 )*tpsit%fsi )/dtt
312 !
313 ! Snow part
314 !print*,'enthalpy =',pent(nilay+1,:,:)
315 !print*,'xmhofusn0=',xmhofusn0
316  WHERE ( pent(nilay+1,:,:)>-xmhofusn0 )
317  pdhmelt(nilay+1,:,:) = pdhmelt(nilay+1,:,:) + &
318  tpsit(:,:)%rsn*tpsit(:,:)%hsn*( pent(nilay+1,:,:)+xmhofusn0 )
319  pent(nilay+1,:,:) = -xmhofusn0
320  ENDWHERE
321  zdenti = pent(:,:,:) - zdenti(:,:,:)
322 !tzsil%ent = pent
323 !call glt_aventh(tpsit,tzsil,zei2,zes2)
324 !print*,'delta enth (W) in vhdiff (part 1) =',sum(zei2+zes2-zei1-zes1)/dtt
325 !print*,'detail ='
326 !write(noutlu,*)'dhmelt(3)=',sum(sum(pdhmelt(:,:,1),dim=1)*pfsi(:,1))/dtt
327 zdhmelt0 = sum(pdhmelt,dim=1)/dtt
328 !
329 ! .. Compute temperature vertical profile from gltools_enthalpy
330 !
331  zvtp(:,:,:) = gltools_temper_r( pent(:,:,:),pvsp(:,:,:) )
332 !
333 !
334 ! 2.4. Grid point initializations
335 ! --------------------------------
336 !
337  DO jp=1,np
338 !
339 ! Sea water freezing point
340  zmlf = pmlf(jp)
341 !
342  DO jk = 1,nt
343 !
344 ! PREVIOUS ITERATION STUFF
345 ! -------------------------
346 ! Previous iteration temperature of the atmosphere / bare ice or snow interface
347  ztsfb = tpsit(jk,jp)%tsf
348 !
349 ! Previous iteration ice vertical temperature profile (downward)
350  DO jl=1,nilay
351  ztsib(jl) = zvtp(nilay+1-jl,jk,jp)
352  END DO
353 !
354 ! Previous iteration snow temperature (middle of the snow layer)
355  ztsib(0) = zvtp(nl,jk,jp)
356 !
357 ! INITIAL STUFF
358 ! --------------
359 ! Initial thermodynamical state of the ice slab
360  zfsi = tpsit(jk,jp)%fsi
361  zdzi(:) = tpsit(jk,jp)%hsi * sf3t(:)
362 !
363 ! Initial ice melting temperature (downward)
364  DO jl=1,nilay
365  ztsi_m0(jl) = ztsi_m(nilay+1-jl,jk,jp)
366  zvsp0(jl) = pvsp(nilay+1-jl,jk,jp)
367  END DO
368 !
369 ! Initial snow melting temperature
370  ztsi_m0(0) = 0.
371 !
372 ! Initial ice vertical temperature profile (downward)
373  ztsi0(:) = ztsib(:)
374 !
375 ! Initial temperature of the atmosphere / bare ice or snow interface
376  ztsf0 = ztsfb
377 !
378 ! Initial top conduction heat flux
379  znsftop0 = pnsftop(jk,jp)
380 !
381 ! Top conductive flux
382  zcondt_m = znsftop0
383 !
384 ! Initial snow caracteristics
385  zrks = 0.30 ! rkice * ( prsn(jk,jp)/rhow )**1.885
386  zcpsn = cpice0
387 !
388 ! CURRENT ITERATION STUFF
389 ! ------------------------
390 ! Current iteration vertical temperature profile (to compute sea ice spec. heat
391 ! at first iteration)
392 !
393  ztsia(:) = ztsi0(:)
394 !
395 ! .. Define booleans and associated parameters
396 !
397  llconv = .false.
398  llice = ( zfsi>epsil1 .AND. tpsit(jk,jp)%hsi>epsil1 )
399  llsnw = ( llice .AND. zfsi>epsil1 .AND. tpsit(jk,jp)%hsn>epsil1 )
400 !
401 ! Initialize iteration counter
402  jit = 0
403 !
404  DO WHILE ( icv(jk,jp)==0 .AND. jit<=nit )
405 !
406  jit = jit+1
407 !
408  llredo = .false.
409 !
410 10 CONTINUE
411 !
412 ! .. Prints
413 !
414  IF ( llredo .AND. lwg ) THEN
415  WRITE(noutlu,*) 'Sea ice concentr. = ',zfsi
416  WRITE(noutlu,*) 'Sea ice thickness = ',tpsit(jk,jp)%hsi
417  WRITE(noutlu,*) 'Snow thickness = ',tpsit(jk,jp)%hsn
418  WRITE(noutlu,*) 'Snow density = ',tpsit(jk,jp)%rsn
419  ENDIF
420 !
421 ! Current iteration excess gltools_enthalpy vertical profile (downward)
422  zdhmelta(:) = 0.
423 !
424 ! .. All necessary quantities are computed from the top to the bottom of
425 ! the ice-snow slab.
426 !
427  IF ( llice ) THEN
428 !
429 ! Update sea ice volumic specific heat
430 ! - in the case of pure ice ( ztsi_m0=0. ) ztsi0 and or ztsia may be =0
431  zrhocpsi(:) = rhocpice0
432  WHERE( ztsi_m0(1:nilay)<-epsil1 )
433  zrhocpsi(:) = zrhocpsi(:) - &
434  hofusn0*ztsi_m0(1:nilay) / ( ztsi0(1:nilay)*ztsia(1:nilay) )
435  ENDWHERE
436 !! write(noutlu,*)'zrhocpsi=',zrhocpsi
437 !! write(noutlu,*)'tsi_m0 =',ztsi_m0(1:nilay)
438 !! write(noutlu,*)'tsi0 =',ztsi0(1:nilay)
439 !! write(noutlu,*)'tsia =',ztsia(1:nilay)
440 !
441 ! Update sea ice conductivity
442  WHERE( ztsia(1:nilay)<xtempc )
443  zrkice(:) = rhoice/rhoice0 * &
444  ( xrki1 + xrki2*ztsia(1:nilay) + &
445  xrki3 * zvsp0(1:nilay) / ztsia(1:nilay) )
446  ELSEWHERE
447  zrkice(:) = rhoice/rhoice0 * &
448  ( xrki1 + xrki2*xtempc + xrki3 * zvsp0(:) / xtempc )
449  ENDWHERE
450  zetai(1:nilay) = dtt / ( zrhocpsi(:)*zdzi(:) )
451  zinvetai(1:nilay) = 1./zetai(1:nilay)
452 !
453  IF ( llsnw ) THEN
454 !IF ( tpsit(jk,jp)%rsn<epsil1 ) print*,'prsn,jk,jp=',tpsit(jk,jp)%rsn,jk,jp
455 !IF ( zcpsn<epsil1 ) print*,'zcpsn,jk,jp=',zcpsn,jk,jp
456 !IF ( tpsit(jk,jp)%hsn<epsil1 ) print*,'phsn,jk,jp=',tpsit(jk,jp)%hsn,jk,jp
457 !
458 ! - heat capacity factor
459  zetai(0) = dtt / ( tpsit(jk,jp)%rsn*zcpsn*tpsit(jk,jp)%hsn )
460  zinvetai(0) = 1./zetai(0)
461 ! - snow layer conductivity
462  zkodzi(0) = 2.*zrks / tpsit(jk,jp)%hsn
463 ! - equivalent conductivity at the ice-snow interface
464  zkodzi(1) = 2.*zrkice(1)*zrks / &
465  ( zrkice(1)*tpsit(jk,jp)%hsn + zrks*zdzi(1) )
466 !
467  ELSE
468 ! - heat capacity factor (unused -> "1" is just to avoid a division by 0)
469  zetai(0) = 1.
470  zinvetai(0) = 0.
471 ! - snow layer conductivity (unused)
472  zkodzi(0) = 0.
473 ! - top of the ice slab conductivity
474  zkodzi(1) = 2.*zrkice(1)/zdzi(1)
475  ENDIF
476 !
477 ! - effective conductivity (general case)
478  DO jl=2,nilay
479  zkodzi(jl) = 2.*zrkice(jl-1)*zrkice(jl) / &
480  ( zrkice(jl-1)*zdzi(jl) + zrkice(jl)*zdzi(jl-1) )
481  END DO
482 ! - effective conductivity (bottom of the ice slab)
483  zkodzi(nilay+1) = 2.*zrkice(nilay)/zdzi(nilay)
484 !
485 ! Derived coefficients
486  zetaik(:) = zetai(:)*zkodzi(0:nilay)
487  zetaikp1(:) = zetai(:)*zkodzi(1:nilay+1)
488  ENDIF
489 !
490 !
491 !
492 ! 3. Vertical heat diffusion in and ice (+snow) slab
493 ! ===================================================
494 !
495  IF ( llice ) THEN
496 !
497  zderiv = pderiv(jk,jp)
498 !
499  CALL glt_vhdslab_r &
500  ( jit,pnsftop(jk,jp),pswtra(:,jk,jp), &
501  zderiv,zcondb,ztsfa,zqtopmelta,zdh,ztsia,llmelt,osnow=llsnw )
502 !
503  pcondb(jk,jp) = zcondb
504  zderiv2(jk,jp) = zderiv
505  gsmelt(jk,jp) = llmelt
506  zdent(:,jk,jp) = zdh(:)
507 !
508  IF (lp4) THEN
509  WRITE(noutlu,*) ' Non-solar heat flux at the top:', &
510  pnsftop(jk,jp)
511  zswtra_all(jk,jp) = xswhdfr * sum(pswtra(:,jk,jp))
512  WRITE(noutlu,*) 'Absorbed solar heat flux:', &
513  zswtra_all(jk,jp) ! Difference de calcul avec modi_glt_vhdslab_r
514  zcondb_all(jk,jp) = zcondb
515  WRITE(noutlu,*) ' Cond. heat flux at the bottom:', &
516  zcondb_all(jk,jp)
517  zderiv_all(jk,jp) = zderiv*( ztsfa-ztsf0 )
518  WRITE(noutlu,*) &
519  ' Additional heat flux at the top dQ/dT*(Tnew-Told):', &
520  zderiv_all(jk,jp)
521  zdh_all(jk,jp) = &
522  ( rhoice*sum(zdh(1:nilay)*zdzi(nilay:1:-1))+ &
523  tpsit(jk,jp)%hsn*tpsit(jk,jp)%rsn*zdh(nilay+1) ) / dtt
524  WRITE(noutlu,*) ' Enthalpy change per time unit:', &
525  zdh_all(jk,jp)
526  zqtopmelta_all(jk,jp) = zqtopmelta
527  WRITE(noutlu,*) ' Top melting flux:', &
528  zqtopmelta_all(jk,jp)
529  WRITE(noutlu,*) 'Balance =', &
530  zdh_all(jk,jp) + zqtopmelta_all(jk,jp) - &
531  (zcondb_all(jk,jp) + zswtra_all(jk,jp) + pnsftop(jk,jp) + &
532  zderiv_all(jk,jp) )
533  ENDIF
534  ENDIF
535 !
536 !
537 !
538 ! 5. Update vertical temperature profile
539 ! ======================================
540 !
541 !
542 ! .. Control of the results
543 !
544  IF ( llice .OR. llsnw ) THEN
545 !
546 ! .. Error in heat conduction scheme
547  IF ( llredo ) THEN
548  CALL gltools_glterr( 'vhdiff (heat conduction scheme)', &
549  'Error in heat conduction scheme. ' // &
550  'See gltout for details','WARN' )
551  llredo=.false.
552  ztsfb = ztsf0
553  ztsfa = ztsf0
554  ztsib(:) = ztsi0(:)
555  ztsia(:) = ztsi0(:)
556  pcondb(jk,jp) = 0.
557  zderiv2(jk,jp) = 0.
558  goto 20
559  ENDIF
560 !
561 ! .. No convergence: oscillations
562  IF ( jit>nit ) THEN
563  IF (lp2) THEN
564  WRITE( ymess, &
565  fmt='("Vertical diffusion scheme did not converge &
566  & Error at jk=",I2," jp=",I6)' ) jk,jp
567  CALL gltools_glterr( 'vhdiff (heat conduction scheme)', ymess, 'WARN' )
568  ENDIF
569  llconv = .true.
570 !!! All temperatures are recomputed as the half sum of new and previous ones
571 !! ztsfa = 0.5*( ztsfa+ztsfb )
572 !! ztsia(:) = 0.5*( ztsia(:)+ztsib(:) )
573 !!! Recompute bottom heat flux
574 !! pcondb(jk,jp) = &
575 !! zkodzi(nilay+1)*( zg1*( zmlf-ztsia(nilay) )+ &
576 !! zg2*( zmlf-ztsia(nilay-1) ) )
577 !!! Recompute top melting flux
578 !! IF ( llsnw ) THEN
579 !! llmelt = ( ztsfa>=ztsi_m0(0) )
580 !! IF ( llmelt ) zcondt_m = -zkodzi(0)*( ztsia(0) - ztsfa )
581 !! ELSE
582 !! llmelt = ( ztsfa>=ztsi_m0(1) )
583 !! IF ( llmelt ) zcondt_m = -zkodzi(1)*( ztsia(1) - ztsfa )
584 !! ENDIF
585 !! lltempcond = ( llmelt .AND. ABS(znsftop0-zcondt_m)>epsil1 )
586 !!! Recompute top flux derivative zderiv2
587 !! IF ( lltempcond ) THEN
588 !! zderiv2(jk,jp) = 0.
589 !! ELSE
590 !! zderiv2(jk,jp) = pderiv(jk,jp)
591 !! ENDIF
592 !!! Recompute the part of the top non-solar flux is devoted to melting
593 !! zqtopmelta = znsftop0-zcondt_m
594  ENDIF
595 !
596 ! .. Detect unrealistic temperatures
597  IF ( ztsfa<=-51. .AND. .NOT.llredo ) THEN
598  IF(lwg) WRITE(noutlu,*) 'Error at ',jp, &
599  ' ztsfa(',jk,') =',ztsfa
600  llredo = .true.
601  goto 10
602  ENDIF
603  IF (zmlf<=-10. .and. .NOT.llredo) THEN
604  IF(lwg) WRITE(noutlu,*) 'Error at ',jp,' zmlf =',zmlf
605  llredo = .true.
606  goto 10
607  ENDIF
608  ENDIF
609 !
610 20 CONTINUE
611 !
612  IF ( .NOT.llice .AND. .NOT.llsnw ) THEN
613  zvtpa(:) = zmlf
614  ztsfa = zmlf
615  pcondb(jk,jp) = 0.
616  IF (lp4) &
617  WRITE(noutlu,*) 'no ice / snow: convergence at jk,jp=',jk,jp
618  icv(jk,jp) = -1 ! Will stop the loop
619  ENDIF
620 !
621  IF ( llice ) THEN
622 ! WHERE( ztsia(1:nilay)>ztsi_m0(1:nilay) )
623 ! zdhmelta(2:nilay+1) = dtt/zetai(1:nilay) * &
624 ! (ztsia(1:nilay)-ztsi_m0(1:nilay))
625 ! ztsia(1:nilay) = ztsi_m0(1:nilay)
626 ! ENDWHERE
627  IF ( llsnw ) THEN
628 ! IF ( ztsia(0)>ztsi_m0(0) ) THEN
629 ! zdhmelta(1) = dtt/zetai(0) * ( ztsia(0)-ztsi_m0(0) )
630 ! ztsia(0) = ztsi_m0(0)
631 ! ENDIF
632  zdhmelta(1) = zdhmelta(1) + dtt*zqtopmelta
633  ztsfa = amin1( ztsfa,ztsi_m0(0) )
634  ELSE
635  zdhmelta(2) = zdhmelta(2) + dtt*zqtopmelta
636  ztsfa = amin1( ztsfa,ztsi_m0(1) )
637  ENDIF
638  IF (lp5) THEN
639  WRITE(noutlu,*) 'ZDHMELTA (1) llsnow = true = ', zdhmelta
640  WRITE(noutlu,*) 'ZTSFA (1) llsnow = true = ', ztsfa
641  WRITE(noutlu,*) 'ZTSFB (1) llsnow = true = ', ztsfb
642  ENDIF
643 !
644 ! .. If the scheme has converged: prepare glt_output (downward / upward convention)
645  IF ( jit==1 ) THEN
646  zcvb = 0.
647  ELSE
648  zcvb = zcva
649  ENDIF
650  zcva = sum( (ztsia(1:nilay)-ztsib(1:nilay))*sf3t )
651  llconv = ( llconv .OR. abs(zcva)<0.001 )
652 ! This 0.01 threshold should be a parameter of the model
653  IF ( llconv ) THEN
654  IF ( jit>nit ) THEN
655  icv(jk,jp) = 0 ! Cases with sea ice/snow that did not converge
656  ELSE
657  icv(jk,jp) = 1 ! Cases with sea ice/snow that converged
658  ENDIF
659  IF (lp4) THEN
660  WRITE(noutlu,*) 'Scheme has converged at jk,jp=',jk,jp
661  WRITE(noutlu,*) ' (iteration #',jit,')'
662  WRITE(noutlu,*) 'Z DT =',zcva
663  ENDIF
664 ! Updated ice temperature
665  DO jl=1,nilay
666  zvtpa(jl) = ztsia(nilay+1-jl)
667  END DO
668 ! Updated snow temperature
669  IF ( llsnw ) THEN
670  zvtpa(nilay+1) = ztsia(0)
671  ELSE
672  zvtpa(nilay+1) = ztsia(1)
673  ENDIF
674 ! Compute in excess energy fluxes due to heat diffusion only
675  DO jl=1,nl
676  pdhmelt(jl,jk,jp) = pdhmelt(jl,jk,jp) + zdhmelta(nl+1-jl)
677  END DO
678 !write(noutlu,*)'dhmelt(4)=',sum(sum(pdhmelt(:,:,1),dim=1)*pfsi(:,1))/dtt
679 !
680 ! .. Compute the trend on surface temperature & vertical temperature profile
681 ! (non-solar only)
682  zvtptrd(:,jk,jp)=zvtpa(:)-zvtp(:,jk,jp)
683  ztsftrd(jk,jp)=ztsfa-ztsf0
684 !
685 ! .. Compute temperature at snow-ice interface (for AR5 diagnostics)
686 ! (already initialized at 1.e20, where there is no sea ice at the beginning
687 ! of this routine)
688  IF ( llice ) THEN
689  IF ( llsnw ) THEN
690  zhs = tpsit(jk,jp)%hsn
691  ztint(jk,jp) = &
692  ( zvtpa(nilay)*zrkice(1)*zhs + &
693  zvtpa(nilay+1)*zrks*zdzi(1) ) / &
694  ( zrks*zdzi(1) + zrkice(1)*zhs )
695  ELSE
696  ztint(jk,jp) = zvtpa(nilay+1)
697  ENDIF
698  ENDIF
699 !
700 ! .. If the scheme has not converged: prepare next iteration
701  ELSE
702  IF (lp4) THEN
703  WRITE(noutlu,*) 'Scheme has not converged yet at jk,jp=',jk,jp
704  WRITE(noutlu,*) ' (iteration #',jit,')'
705  WRITE(noutlu,*) 'Z DT =', &
706  zcva
707  ENDIF
708  IF (lp5) THEN
709  WRITE(noutlu,*) &
710  'Previous temperature profile (top -> bottom )=', ztsi0
711  WRITE(noutlu,*) &
712  'New temperature profile (top -> bottom ) =', ztsia
713  ENDIF
714 !
715 ! .. Update previous time step data for new iteration
716  IF ( zcva*zcvb < 0. ) THEN
717  ztsfa = 0.5*( ztsfa+ztsfb )
718  ztsia(:) = 0.5*( ztsia(:)+ztsib(:) )
719  ENDIF
720  ztsfb = ztsfa
721  ztsib(:) = ztsia(:)
722  ENDIF
723  ENDIF
724 !
725  END DO ! End of convergence boolean condition
726 !
727  END DO ! End of loop on categories
728 !
729  END DO ! End of loop on grid cells
730 !
731 ! .. Change sign of pcondb
732  IF (lp1) THEN
733  ztot_ice_snow= np*nt+sum(icv,mask=icv<0)
734  WRITE(noutlu,*)
735  WRITE(noutlu,*) ' ** WARNING **'
736  WRITE(noutlu,*) &
737  ' Total number of cases with ice/snow : ', &
738  ztot_ice_snow
739  WRITE(noutlu,*) &
740  ' Convergence failed on # of points : ', &
741  np*nt-sum(abs(icv))
742  IF ( ztot_ice_snow > 0) THEN
743  zfailures=100.*float(np*nt-sum(abs(icv)))/ztot_ice_snow
744  ELSE
745  zfailures=0.
746  ENDIF
747  WRITE(noutlu,fmt='(A,F6.2)') &
748  ' % of failure : ', &
749  zfailures
750  WRITE(noutlu,*)
751  ENDIF
752 !
753  pcondb(:,:) = -pcondb(:,:)
754 !
755 ! .. Update vertical temperature profile and surface temperature
756 !
757  tpsit(:,:)%tsf = tpsit(:,:)%tsf+ztsftrd(:,:)
758 !
759 ! .. Update sea ice and snow gltools_enthalpy (and save gltools_enthalpy after heat diffusion)
760 !
761 !print*,'temp avant=',zvtp(:,4,1)
762 !print*
763 !print*,'trend =',zvtptrd(:,4,1)
764 !print*
765 !print*,'temp apres=',zvtp(:,4,1)+zvtptrd(:,4,1)
766 ! pent(:,:,:) = glt_enthalpy3d( zvtp(:,:,:)+zvtptrd(:,:,:),pvsp=pvsp(:,:,:) )
767 ! zentns(:,:,:) = pent(:,:,:)
768  pent(:,:,:) = pent(:,:,:) + zdent(:,:,:)
769 !print*,'correct enth. change=',zdh
770 !print*,'from vhdiff: d(enth)=',zentns(:,4,1)-zento(:,4,1)
771 !
772 ! .. Take solar radiation into account (direct impact on gltools_enthalpy, doing that
773 ! on temperature leads to non-conservation)
774 !
775 ! tzsil%ent = pent
776 !call glt_aventh(tpsit,tzsil,zei1,zes1)
777 !print*,'delta enth (W) in vhdiff (after adding zdent)=', &
778 ! sum(zei1+zes1-zei2-zes2)/dtt
779 !
780 ! Sea ice part
781  DO jl=1,nilay
782  WHERE ( tpsit(:,:)%fsi>epsil1 .AND. tpsit(:,:)%hsi>epsil1 )
783  pent(jl,:,:) = pent(jl,:,:) + &
784  dtt * (1.-xswhdfr) * pswtra(jl,:,:) / &
785  ( rhoice*sf3tinv(jl)*tpsit(:,:)%hsi )
786  ENDWHERE
787  END DO
788 !
789 ! Snow part
790  WHERE ( tpsit(:,:)%fsi>epsil1 .AND. tpsit(:,:)%hsn>epsil1 )
791  pent(nilay+1,:,:) = pent(nilay+1,:,:) + &
792  dtt * (1.-xswhdfr) * pswtra(nilay+1,:,:) / &
793  ( tpsit(:,:)%rsn*tpsit(:,:)%hsn )
794  ENDWHERE
795 !
796 ! .. Add up excess energy due to solar radiation (in J.m-2)
797 !
798 zdhmelt1 = sum(pdhmelt,dim=1)/dtt
799 ! Sea ice part
800  WHERE( pent(nilay,:,:)>cpsw*ztsi_m(nilay,:,:) )
801  gsmelt(:,:) = .true.
802  ENDWHERE
803  DO jl=1,nilay
804  WHERE ( pent(jl,:,:)>cpsw*ztsi_m(jl,:,:) )
805  pdhmelt(jl,:,:) = pdhmelt(jl,:,:) + &
806  rhoice*tpsit(:,:)%hsi*sf3tinv(jl)*( pent(jl,:,:)-cpsw*ztsi_m(jl,:,:) )
807  pent(jl,:,:) = cpsw*ztsi_m(jl,:,:)
808  ENDWHERE
809  END DO
810 !write(noutlu,*)'dhmelt(5)=',sum(sum(pdhmelt(:,:,1),dim=1)*pfsi(:,1))/dtt
811 zdhmelt2 = sum(pdhmelt,dim=1)/dtt
812 !
813 ! Snow part
814  WHERE ( pent(nilay+1,:,:)>-xmhofusn0 )
815  gsmelt(:,:) = .true.
816  pdhmelt(nilay+1,:,:) = pdhmelt(nilay+1,:,:) + &
817  tpsit(:,:)%rsn*tpsit(:,:)%hsn*( pent(nilay+1,:,:)+xmhofusn0 )
818  pent(nilay+1,:,:) = -xmhofusn0
819  ENDWHERE
820 zdhmelt3 = sum(pdhmelt,dim=1)/dtt
821 !write(noutlu,*)'dhmelt(6)=',sum(sum(pdhmelt(:,:,1),dim=1)*pfsi(:,1))/dtt
822 !
823 ! In some cases, due to a negative qtopmelt, pdhmelt can be negative
824 ! at nilay level (without snow) or nilay+1 level (with snow)
825  WHERE( pdhmelt(nilay,:,:)<0. )
826  pcondb(:,:) = pcondb(:,:) + pdhmelt(nilay,:,:)/dtt
827  pdhmelt(nilay,:,:) = 0.
828  ENDWHERE
829  WHERE( pdhmelt(nilay+1,:,:)<0. )
830  pcondb(:,:) = pcondb(:,:) + pdhmelt(nilay+1,:,:)/dtt
831  pdhmelt(nilay+1,:,:) = 0.
832  ENDWHERE
833 zdhmelt4 = sum(pdhmelt,dim=1)/dtt
834 !
835 ! Save top melt flux (only the one affecting sea ice - for diagnostic)
836 !
837  pqtopmelt(:,:) = -zderiv2(:,:)*ztsftrd(:,:)
838  WHERE( .NOT. gsmelt(:,:) .OR. tpsit(:,:)%hsn>epsil1 .OR. pqtopmelt(:,:)<0. )
839  pqtopmelt(:,:) = 0.
840  ENDWHERE
841 !
842 ! Final update of the bottom conductive heat flux
843 !
844  pcondb(:,:) = pcondb(:,:) - zderiv2(:,:)*ztsftrd(:,:)
845 !
846 ! .. Save temperature at snow / ice interface
847 ! Weights for final computation of the average must be incremented
848 ! here, not where diagnostics are written.
849 ! The reason for this is that tpsit%fsi in the present routine would
850 ! not be consistent with total sea ice fraction in the diagnostics.
851 !
852 ! .. Total sea ice concentration
853 !
854  zfsit(:) = sum( tpsit(:,:)%fsi, mask=(omask), dim=1 )
855  tpdia(:)%tin = &
856  sum( (ztint(:,:)+t0deg)*tpsit(:,:)%fsi, mask=(omask), dim=1 )
857  tpdia(:)%tiw = tpdia(:)%tiw + zfsit(:)
858 !
859 !
860 !
861 ! 6. Final checks
862 ! ================
863 !
864 ! Compute the different terms of the energy balance (part of the physics)
865  zdent(:,:,:) = zdent(:,:,:)+zdenti(:,:,:) ! Total gltools_enthalpy variation
866  z1 = pnsftop(:,:)
867  z2 = - pcondb(:,:)
868  z3 = tpsit(:,:)%rsn*tpsit(:,:)%hsn*zdent(nilay+1,:,:)/dtt
869  z4 = sum( pswtra(:,:,:),dim=1 )
870  z5 = 0.
871  DO jl = 1,nilay
872  z5(:,:) = z5(:,:) + &
873  ( rhoice*sf3tinv(jl)*zdent(jl,:,:)*tpsit(:,:)%hsi/dtt )
874  END DO
875  z6 = sum( pdhmelt(:,:,:),dim=1 )/dtt
876  zwork = tpsit%fsi * ( z1 + z4 + z2 - z3 - z5 - z6 )
877 !
878 ! .. Finally, we collect the small imbalance due to rare cases of non
879 ! convergence of the vertical heat diffusion scheme, and put it in
880 ! the bottom conduction flux.
881 !
882  icount(:,:) = 0
883  WHERE( abs(zwork)>0.1 )
884  icount = 1
885  ENDWHERE
886  IF (lp1) THEN
887  WRITE(noutlu,*)
888  WRITE(noutlu,*) ' ** WARNING **'
889  WRITE(noutlu,*) &
890  ' The energy balance is not closed on # of points : ', &
891  sum(icount)
892  WRITE(noutlu,*) &
893  ' Total number of points : ', &
894  np*nt
895  WRITE(noutlu,fmt='(A,F6.2)') &
896  '% of failure: : ', &
897  100.*float(sum(icount))/float(np*nt)
898  WRITE(noutlu,*)
899  ENDIF
900 !
901  pcondb(:,:) = pcondb(:,:)+zwork(:,:)
902  z2 = - pcondb(:,:)
903 !
904  IF (lp1) THEN
905 !
906  ! print*,'condt=',glt_avg_r(tpdom,sum(tpsit%fsi*z1,dim=1),0)
907  ! print*,'condb=',glt_avg_r(tpdom,sum(tpsit%fsi*z2,dim=1),0)
908  ! print*,'dhsnow=',glt_avg_r(tpdom,sum(tpsit%fsi*z3,dim=1),0)
909  ! print*,'solar=',glt_avg_r(tpdom,sum(tpsit%fsi*z4,dim=1),0)
910  ! print*,'dhice=',glt_avg_r(tpdom,sum(tpsit%fsi*z5,dim=1),0)
911  ! print*,'dhmelt=',glt_avg_r(tpdom,sum(tpsit%fsi*z6,dim=1),0)
912  ! print*,'*****'
913  ! print*,'melt0=',glt_avg_r(tpdom,sum(tpsit%fsi*zdhmelt0,dim=1),0)
914  ! print*,'melt1=',glt_avg_r(tpdom,sum(tpsit%fsi*zdhmelt1,dim=1),0)
915  ! print*,'melt2=',glt_avg_r(tpdom,sum(tpsit%fsi*zdhmelt2,dim=1),0)
916  ! print*,'melt3=',glt_avg_r(tpdom,sum(tpsit%fsi*zdhmelt3,dim=1),0)
917  ! print*,'melt4=',glt_avg_r(tpdom,sum(tpsit%fsi*zdhmelt4,dim=1),0)
918 !
919  WRITE(noutlu,*)
920  WRITE(noutlu,*) &
921  'At the end of VHDIFF (vert. heat diffusion scheme), W/m2 of ice'
922 !
923 ! .. Print top flux integral
924 !
925  zinsftop = glt_avg_r( tpdom, sum( tpsit%fsi*z1, dim=1 ),0 )
926  WRITE(noutlu,fmt='(A,F8.2)') &
927  ' Top non-solar flux integral :', zinsftop
928 !
929 ! .. Print input solar energy
930 !
931  ziswa = glt_avg_r( tpdom, sum( tpsit%fsi*z4, dim=1 ),0 )
932  WRITE(noutlu,fmt='(A,F8.2)') &
933  ' Input solar energy :', ziswa
934 !
935 ! .. Print bottom flux integral
936 !
937  zicondb = glt_avg_r( tpdom, sum( tpsit%fsi*z2, dim=1 ),0 )
938  WRITE(noutlu,fmt='(A,F8.2)') &
939  ' Bottom flux integral:', zicondb
940 ! .. Total incoming energy
941 !
942  WRITE(noutlu,fmt='(A,F10.4)') &
943  ' ==> Total incoming energy :', &
944  zinsftop+ziswa+zicondb
945 !
946  WRITE(noutlu,*)
947 !
948 ! .. Print ice enthalpy change integral (non-solar + solar)
949 !
950  zidhi = glt_avg_r( tpdom, sum( tpsit%fsi*z5, dim=1 ),0 )
951  WRITE(noutlu,fmt='(A,F8.2)') &
952  ' Ice enthalpy change due to heat conduction :', zidhi
953 !
954 ! .. Print snow enthalpy change integral (non-solar + solar)
955 !
956  zidhs = glt_avg_r( tpdom, sum( tpsit%fsi*z3, dim=1 ),0 )
957  WRITE(noutlu,fmt='(A,F8.2)') &
958  ' Snow enthalpy change due to heat conduction :', zidhs
959 !
960 ! .. Print overwhelming energy due to melting
961 !
962  zdhmelt = glt_avg_r( tpdom, sum( tpsit%fsi*z6, dim=1 ),0 )
963  WRITE(noutlu,fmt='(A,F8.2)') &
964  ' Energy devoted to melting :', zdhmelt
965 !
966 ! .. Print snow + ice enthalpy change integral
967 !
968  WRITE(noutlu,fmt='(A,F10.4)') &
969  ' ==> Total energy change for sea ice / snow:', &
970  zidhi + zidhs + zdhmelt
971 !
972  WRITE(noutlu,*)
973 !
974 ! .. Energy variation of the whole system
975 !
976 ! = z1 + z4 + z2 - z5 - z3 - z6
977  zinrg = zinsftop + ziswa + zicondb - zidhi - zidhs - zdhmelt
978 !
979  WRITE(noutlu,fmt='(A,F10.4)') &
980  ' ==> Energy variation of the whole system :', zinrg
981 ! .. If the energy variation of the system is too large, issue a warning
982 !
983  IF ( abs(zinrg)>0.01 ) THEN
984  WRITE(noutlu,*)
985  WRITE(noutlu,*) ' ** WARNING **'
986  WRITE(noutlu,*) &
987  ' Heat conduction scheme not conservative'
988  WRITE(noutlu,*) &
989  ' ========================================='
990  ENDIF
991  ENDIF
992 !
993  IF (lp4) THEN
994  WRITE(noutlu,*) ' Non-solar heat flux at the top:', &
995  glt_avg_r( tpdom,sum( pnsftop(:,:)*tpsit%fsi, dim=1 ),0 )
996  WRITE(noutlu,*) ' Absorbed solar heat flux:', &
997  glt_avg_r( tpdom,sum( zswtra_all(:,:)*tpsit%fsi, dim=1 ),0 )
998  WRITE(noutlu,*) ' Cond. heat flux at the bottom:', &
999  glt_avg_r( tpdom,sum( zcondb_all(:,:)*tpsit%fsi, dim=1 ),0 )
1000  WRITE(noutlu,*) ' Additional heat flux at the top dQ/dT*(Tnew-Told):', &
1001  glt_avg_r( tpdom,sum( zderiv_all(:,:)*tpsit%fsi, dim=1 ),0 )
1002  WRITE(noutlu,*) ' Sum of the previous two form final condb:', &
1003  glt_avg_r( tpdom,sum( (zcondb_all(:,:)+zderiv_all(:,:) )*tpsit%fsi, dim=1 ),0 )
1004  WRITE(noutlu,*) ' Enthalpy change per time unit:', &
1005  glt_avg_r( tpdom,sum( zdh_all(:,:)*tpsit%fsi, dim=1 ),0 )
1006  WRITE(noutlu,*) ' Top melting flux:', &
1007  glt_avg_r( tpdom,sum( zqtopmelta_all(:,:)*tpsit%fsi, dim=1 ),0 )
1008  WRITE(noutlu,*) 'Imbalance =', &
1009  glt_avg_r( tpdom, &
1010  sum( tpsit%fsi*( zdh_all(:,:)+zqtopmelta_all(:,:) - &
1011  ( zcondb_all(:,:)+zswtra_all(:,:)+pnsftop(:,:)+zderiv_all(:,:) ) ), &
1012  dim=1 ),0 )
1013  ENDIF
1014 !
1015 ! .. Note that deallocations must be done in reverse order on some specific
1016 ! platforms (wrt allocations)
1017 !
1018  DEALLOCATE( zkodzi )
1019  DEALLOCATE( ztsi_m0 )
1020  DEALLOCATE( ztsi0 )
1021  DEALLOCATE( ztsib )
1022  DEALLOCATE( zrhocpsi )
1023  DEALLOCATE( zetaikp1 )
1024  DEALLOCATE( zetaik )
1025  DEALLOCATE( zinvetai )
1026  DEALLOCATE( zetai )
1027 !
1028  END SUBROUTINE glt_vhdiff_r
subroutine glt_vhdiff_r(tpdom, pmlf, pderiv, tpsit, tpdia, pnsftop, pswtra, pent, pvsp, pcondb, pqtopmelt, pdhmelt, gsmelt)
subroutine gltools_glterr(hroutine, hmess, hflag)
subroutine glt_vhdslab_r(kit, pnsftop, pswtra, pderiv, pcondb, ptsfa, pqtopmelt, pdh, ptsia, osmelt, osnow)