SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
snowcro.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 ! ##########################################################################
6  SUBROUTINE snowcro(HSNOWRES, TPTIME, OGLACIER, HIMPLICIT_WIND, &
7  ppew_a_coef, ppew_b_coef, &
8  ppet_a_coef, ppeq_a_coef, ppet_b_coef, ppeq_b_coef, &
9  psnowswe,psnowrho,psnowheat,psnowalb, &
10  psnowgran1,psnowgran2,psnowhist,psnowage, &
11  ptstep,pps,psr,prr,ppsn3l, &
12  pta,ptg,psw_rad,pqa,pvmod,plw_rad, prhoa, &
13  puref,pexns,pexna,pdircoszw, &
14  pzref,pz0,pz0eff,pz0h,palb, &
15  psoilcond,pd_g, &
16  psnowliq,psnowtemp,psnowdz, &
17  pthrufal,pgrndflux,pevapcor,prnsnow,phsnow,pgfluxsnow, &
18  phpsnow,ples3l,plel3l,pevap,psndrift,pri, &
19  pemisnow,pcdsnow,pustar,pchsnow,psnowhmass,pqs, &
20  ppermsnowfrac,pzenith,pxlat,pxlon, &
21  osnowdrift,osnowdrift_sublim,osnow_abs_zenith, &
22  hsnowmetamo,hsnowrad)
23 ! ##########################################################################
24 !
25 !!**** *SNOWCRO*
26 !!
27 !! PURPOSE
28 !! -------
29 !
30 ! Detailed snowpack scheme Crocus, computationnally based on the
31 ! 3-Layer snow scheme option (Boone and Etchevers 1999)
32 ! For shallow snow cover, Default method of Douville et al. (1995)
33 ! used with this option: Model "turns on" when snow sufficiently
34 ! deep/above some preset critical snow depth.
35 !
36 !
37 !
38 !
39 !!** METHOD
40 !! ------
41 !
42 ! Direct calculation
43 !
44 !! EXTERNAL
45 !! --------
46 !
47 ! None
48 !!
49 !! IMPLICIT ARGUMENTS
50 !! ------------------
51 !!
52 !!
53 !!
54 !! REFERENCE
55 !! ---------
56 !!
57 !! ISBA: Belair (1995)
58 !! ISBA: Noilhan and Planton (1989)
59 !! ISBA: Noilhan and Mahfouf (1996)
60 !! ISBA-ES: Boone and Etchevers (2001)
61 !! Crocus : Brun et al., 1989 (J. Glaciol.)
62 !! Crocus : Brun et al., 1992 (J. Glaciol.)
63 !! Crocus : Vionnet et al., in prep (Geosci. Mod. Devel. Discuss.)
64 !!
65 !!
66 !! AUTHOR
67 !! ------
68 !! A. Boone * Meteo-France *
69 !! V. Vionnet * Meteo-France *
70 !! E. Brun * Meteo-France *
71 !!
72 !! MODIFICATIONS
73 !! -------------
74 !! Original 7/99
75 !! Modified by A.Boone 05/02 (code, not physics)
76 !! Modified by A.Boone 11/04 i) maximum density limit imposed (although
77 !! rarely if ever reached), ii) check to
78 !! see if upermost layer completely sublimates
79 !! during a timestep (as snowpack becomes vanishly
80 !! thin), iii) impose maximum grain size limit
81 !! in radiation transmission computation.
82 !!
83 !! Modified by B. Decharme (03/2009): Consistency with Arpege permanent
84 !! snow/ice treatment (LGLACIER for alb)
85 !! Modified by A. Boone (04/2010): Implicit coupling and replace Qsat and DQsat
86 !! by Qsati and DQsati, respectively.
87 !! Modified by E. Brun, V. Vionnet, S. Morin (05/2011):
88 !! Addition of Crocus processes and
89 !! parametrizations to
90 !! the SNOW-3L code. This includes the dynamic handling
91 !! of snow layers and the inclusion of snow metamorphism
92 !! rules similar to the original Crocus implementation.
93 !! Modified by B. Decharme (09/2012): New wind implicitation
94 !!
95 !! Modified by M. Lafaysse (07/2012) :
96 !! * Albedo and roughness parametrizations
97 !! for surface ice over glaciers
98 !! MODIF 2012-10-03 : don't modify roughness if implicit coupling
99 !! (test PPEW_A_COEF == 0. )
100 !! * SNOWCROALB is now called by SNOWCRORAD to remove duplicated code
101 !! * Parameters for albedo are moved to modd_snow_par
102 !! * PSNOWAGE is stored as an age
103 !! (days since snowfall) and not as a date
104 !! to allow spinup simulations
105 !! * New rules for optimal discretization of very thick snowpacks
106 !! * Optional outputs for debugging
107 !!
108 !! Modified by E. Brun and M. Lafaysse (07/2012) :
109 !! * Implement sublimation in SNOWDRIFT
110 !! * Flag in namelist to activate SNOWDRIFT and SNOWDRIFT_SUBLIM
111 !! Modified by E. Brun and M. Lafaysse (08/2012) :
112 !! * XUEPSI replaced by 0 in the if statement of case 1.3.3.2 (SNOWCROMETAMO)
113 !! * If SNOWDRIFT is activated the wind do not modify grain types during snowfall
114 !! (redundant with snowdrift)
115 !! Modified by E. Brun (24/09/2012) :
116 !! * Correction coupling coefficient for specific humidity in SNOWCROEBUD
117 !! * PSFCFRZ(:) = 1.0 for systematic solid/vapor latent fluxes in SNOWCROEBUD
118 !! Modified by C. Carmagnola (3/2013):
119 !! * Dendricity and size replaced by the optical diameter
120 !! * Test of different evolution laws for the optical diameter
121 !!
122 !! Modified by B. Decharme (08/2013): Qsat as argument (needed for coupling with atm)
123 !! add PSNDRIFT
124 !!
125 !!
126 !-------------------------------------------------------------------------------
127 !
128 !* 0. DECLARATIONS
129 ! ------------
130 !
132 !
133 USE modd_csts, ONLY : xtt, xrholw, xlmtt,xlstt,xlvtt, xcl, xci, xpi, xrholi
134 USE modd_snow_par, ONLY : xz0icez0snow, xrhothreshold_ice
136 USE modd_const_tartes, ONLY: npnimp, xpsnowg0, xpsnowy0, xpsnoww0, xpsnowb0
137 !
138 USE mode_snow3l
139 USE mode_tartes, ONLY : snowcro_tartes
140 !
141 USE mode_crodebug
142 !
143 USE modi_abor1_sfx
144 !
145 USE yomhook ,ONLY : lhook, dr_hook
146 USE parkind1 ,ONLY : jprb
147 !
148 ! this module is not used anymore
149 ! USE MODI_GREGODSTRATI
150 !
151 IMPLICIT NONE
152 !
153 !
154 !* 0.1 declarations of arguments
155 !
156 REAL, INTENT(IN) :: ptstep
157 ! PTSTEP = time step of the integration
158 TYPE(date_time), INTENT(IN) :: tptime ! current date and time
159 !
160  CHARACTER(LEN=*), INTENT(IN) :: hsnowres
161 ! HSNOWRES = ISBA-SNOW3L turbulant exchange option
162 ! 'DEF' = Default: Louis (ISBA: Noilhan and Mahfouf 1996)
163 ! 'RIL' = Limit Richarson number under very stable
164 ! conditions (currently testing)
165 LOGICAL, INTENT(IN) :: oglacier ! True = Over permanent snow and ice,
166 ! initialise WGI=WSAT,
167 ! Hsnow>=10m and allow 0.8<SNOALB<0.85
168  ! False = No specific treatment
169 !
170  CHARACTER(LEN=*), INTENT(IN) :: himplicit_wind ! wind implicitation option
171 ! ! 'OLD' = direct
172 ! ! 'NEW' = Taylor serie, order 1
173 !
174 REAL, DIMENSION(:), INTENT(IN) :: pps, pta, psw_rad, pqa, pvmod, plw_rad, psr, prr
175 ! PSW_RAD = incoming solar radiation (W/m2)
176 ! PLW_RAD = atmospheric infrared radiation (W/m2)
177 ! PRR = rain rate [kg/(m2 s)]
178 ! PSR = snow rate (SWE) [kg/(m2 s)]
179 ! PTA = atmospheric temperature at level za (K)
180 ! PVMOD = modulus of the wind parallel to the orography (m/s)
181 ! PPS = surface pressure
182 ! PQA = atmospheric specific humidity
183 ! at level za
184 !
185 REAL, DIMENSION(:), INTENT(IN) :: ptg, psoilcond, pd_g, ppsn3l
186 ! PTG = Surface soil temperature (effective
187 ! temperature the of layer lying below snow)
188 ! PSOILCOND = soil thermal conductivity [W/(m K)]
189 ! PD_G = Assumed first soil layer thickness (m)
190 ! Used to calculate ground/snow heat flux
191 ! PPSN3L = snow fraction
192 !
193 REAL, DIMENSION(:), INTENT(IN) :: pzref, puref, pexns, pexna, pdircoszw, prhoa, pz0, pz0eff, &
194  palb, pz0h, ppermsnowfrac
195 ! PZ0EFF = roughness length for momentum
196 ! PZ0 = grid box average roughness length
197 ! PZ0H = grid box average roughness length for heat
198 ! PZREF = reference height of the first
199 ! atmospheric level
200 ! PUREF = reference height of the wind
201 ! PRHOA = air density
202 ! PEXNS = Exner function at surface
203 ! PEXNA = Exner function at lowest atmos level
204 ! PDIRCOSZW = Cosinus of the angle between the
205 ! normal to the surface and the vertical
206 ! PALB = soil/vegetation albedo
207 ! PPERMSNOWFRAC = fraction of permanet snow/ice
208 !
209 REAL, DIMENSION(:), INTENT(IN) :: ppew_a_coef, ppew_b_coef, &
210  ppet_a_coef, ppeq_a_coef, ppet_b_coef, &
211  ppeq_b_coef
212 ! PPEW_A_COEF = wind coefficient (m2s/kg)
213 ! PPEW_B_COEF = wind coefficient (m/s)
214 ! PPET_A_COEF = A-air temperature coefficient
215 ! PPET_B_COEF = B-air temperature coefficient
216 ! PPEQ_A_COEF = A-air specific humidity coefficient
217 ! PPEQ_B_COEF = B-air specific humidity coefficient
218 !
219 REAL, DIMENSION(:), INTENT(INOUT) :: psnowalb
220 ! PSNOWALB = Prognostic surface snow albedo
221 ! (does not include anything but
222 ! the actual snow cover)
223 !
224 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowheat, psnowrho, psnowswe
225 ! PSNOWHEAT = Snow layer(s) heat content (J/m2)
226 ! PSNOWRHO = Snow layer(s) averaged density (kg/m3)
227 ! PSNOWSWE = Snow layer(s) liquid Water Equivalent (SWE:kg m-2)
228 !
229 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowgran1, psnowgran2, psnowhist
230 ! PSNOWGRAN1 = Snow layers grain feature 1
231 ! PSNOWGRAN2 = Snow layer grain feature 2
232 ! PSNOWHIST = Snow layer grain historical
233 ! parameter (only for non
234 ! dendritic snow)
235 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowage ! Snow grain age
236 !
237 REAL, DIMENSION(:,:), INTENT(OUT) :: psnowliq, psnowtemp, psnowdz
238 ! PSNOWLIQ = Snow layer(s) liquid water content (m)
239 ! PSNOWTEMP = Snow layer(s) temperature (m)
240 ! PSNOWDZ = Snow layer(s) thickness (m)
241 !
242 REAL, DIMENSION(:), INTENT(OUT) :: pthrufal, pgrndflux, pevapcor
243 ! PTHRUFAL = rate that liquid water leaves snow pack:
244 ! paritioned into soil infiltration/runoff
245 ! by ISBA [kg/(m2 s)]
246 ! PGRNDFLUX = soil/snow interface heat flux (W/m2)
247 ! PEVAPCOR = evaporation/sublimation correction term:
248 ! extract any evaporation exceeding the
249 ! actual snow cover (as snow vanishes)
250 ! and apply it as a surface soil water
251 ! sink. [kg/(m2 s)]
252 !
253 REAL, DIMENSION(:), INTENT(OUT) :: prnsnow, phsnow, pgfluxsnow, ples3l, plel3l, &
254  phpsnow, pcdsnow, pustar, pevap, psndrift
255 ! PLES3L = evaporation heat flux from snow (W/m2)
256 ! PLEL3L = sublimation (W/m2)
257 ! PHPSNOW = heat release from rainfall (W/m2)
258 ! PRNSNOW = net radiative flux from snow (W/m2)
259 ! PHSNOW = sensible heat flux from snow (W/m2)
260 ! PGFLUXSNOW = net heat flux from snow (W/m2)
261 ! PCDSNOW = drag coefficient for momentum over snow
262 ! PUSTAR = friction velocity over snow (m/s)
263 ! PEVAP = total evaporative flux (kg/m2/s)
264 ! PSNDRIFT = blowing snow sublimation (kg/m2/s)
265 !
266 REAL, DIMENSION(:), INTENT(OUT) :: pchsnow, pemisnow, psnowhmass
267 ! PEMISNOW = snow surface emissivity
268 ! PCHSNOW = drag coefficient for heat over snow
269 ! PSNOWHMASS = heat content change due to mass
270 ! changes in snowpack (J/m2): for budget
271 ! calculations only.
272 !
273 REAL, DIMENSION(:), INTENT(OUT) :: pri, pqs
274 ! PRI = Ridcharson number
275 ! PQS = surface humidity
276 !
277 REAL, DIMENSION(:), INTENT(IN) :: pzenith ! solar zenith angle
278 REAL, DIMENSION(:), INTENT(IN) :: pxlat,pxlon ! LAT/LON after packing
279 !
280 LOGICAL, INTENT(IN) :: osnowdrift, osnowdrift_sublim ! activate snowdrift, sublimation during drift
281 LOGICAL, INTENT(IN) :: osnow_abs_zenith ! activate parametrization of solar absorption for polar regions
282  CHARACTER(3), INTENT(IN) :: hsnowmetamo, hsnowrad
283  !-----------------------
284  ! Metamorphism scheme
285  ! HSNOWMETAMO=B92 Brun et al 1992
286  ! HSNOWMETAMO=C13 Carmagnola et al 2014
287  ! HSNOWMETAMO=T07 Taillandier et al 2007
288  ! HSNOWMETAMO=F06 Flanner et al 2006
289  !-----------------------
290  ! Radiative transfer scheme
291  ! HSNOWMETAMO=B92 Brun et al 1992
292  ! HSNOWMETAMO=TAR TARTES (Libois et al 2013)
293  ! HSNOWMETAMO=TA1 TARTES with constant impurities
294  ! HSNOWMETAMO=TA2 TARTES with constant impurities as function of ageing
295  !-----------------------
296 !* 0.2 declarations of local variables
297 !
298 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2),NPNIMP) :: zsnowimp_density !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
299 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2),NPNIMP) :: zsnowimp_content !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
300 !
301 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowtemp, zscap, zsnowdzn, zscond, zradsink
302 ! ZSNOWTEMP = Snow layer(s) averaged temperature (K)
303 ! ZSCAP = Snow layer(s) heat capacity [J/(K m3)]
304 ! ZSNOWDZN = Updated snow layer thicknesses (m)
305 ! ZSCOND = Snow layer(s) thermal conducivity [W/(m K)]
306 ! ZRADSINK = Snow solar Radiation source terms (W/m2)
307 !
308 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zwholdmax
309 !
310 !For now these values are constant
311 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowg0 ! asymmetry parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit) (npoints,nlayer)
312 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowy0 ! Value of y of snow grains at nr=1.3 (no unit
313 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnoww0 ! Value of W of snow grains at nr=1.3 (no unit)
314 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowb0 ! absorption enhancement parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit)
315 !
316 !spectral albedo (3 bands for now) :: ready to output if necessary
317 REAL, DIMENSION(SIZE(PSNOWRHO,1),3) :: zspectralalbedo
318 !
319 REAL, DIMENSION(SIZE(PTA)) :: zsnowbis
320 ! ZSNOWBIS = Total snow depth after snowfall
321 !
322 REAL, DIMENSION(SIZE(PTA)) :: zsnow, zsfcfrz, ztsterm1, ztsterm2, zct, zra, zsnowflux, zsnowtempo1
323 ! ZSNOW = Total snow depth (m)
324 ! ZCT = inverse of the product of snow heat capacity
325 ! and layer thickness [(m2 K)/J]
326 ! ZRA = Surface aerodynamic resistance
327 ! ZTSTERM1,ZTSTERM2 = Surface energy budget coefficients
328 ! ZSNOWFLUX = heat flux between 1st and 2nd snow layers:
329 ! used during surface melting (W/m2)
330 ! ZSNOWTEMPO1= value of uppermost snow temperature
331 ! before time integration (K)
332 !
333 REAL, DIMENSION(SIZE(PTA)) :: zrsra, zdqsat, zqsat, zradxs, zliqheatxs, zlwupsnow
334 ! ZRSRA = air density over aerodynamic resistance
335 ! ZDQSAT = derrivative of saturation specific humidity
336 ! ZQSAT = saturation specific humidity
337 ! ZRADXS = shortwave radiation absorbed by soil surface
338 ! (for thin snow sover) (W m-2)
339 ! ZLIQHEATXS = excess snowpack heating for vanishingly thin
340 ! snow cover: add energy to snow/ground heat
341 ! flux (W m-2)
342 ! ZLWUPSNOW = upwelling longwave raaditive flux (W m-2)
343 !
344 REAL, DIMENSION(SIZE(PTA)) :: zustar2_ic, zta_ic, zqa_ic, &
345  zpet_a_coef_t, zpeq_a_coef_t, zpet_b_coef_t, zpeq_b_coef_t
346 ! ZUSTAR2_IC = implicit lowest atmospheric level friction (m2/s2)
347 ! ZTA_IC = implicit lowest atmospheric level air temperature
348 ! ZQA_IC = implicit lowest atmospheric level specific humidity
349 ! ZPET_A_COEF_T = transformed A-air temperature coefficient
350 ! ZPET_B_COEF_T = transformed B-air temperature coefficient
351 ! ZPEQ_A_COEF_T = transformed A-air specific humidity coefficient
352 ! ZPEQ_B_COEF_T = transformed B-air specific humidity coefficient
353 !
354 REAL, DIMENSION(SIZE(PTA)) :: zsnowrhof, zsnowdzf, zsnowgran1f, zsnowgran2f, zsnowhistf
355 REAL, DIMENSION(SIZE(PTA)) :: zsnowagef
356 
357 ! New roughness lengths in case of glaciers without snow.
358 REAL, DIMENSION(SIZE(PTA)) :: zz0_snowice, zz0h_snowice, zz0eff_snowice
359 !
360 !To control and print eneregy balance
361 REAL , DIMENSION(SIZE(PTA)) :: zsummass_ini,zsumheat_ini,zsummass_fin,zsumheat_fin
362 !
363 REAL, DIMENSION(SIZE(PTA)) :: zmassbalance, zenergybalance, zevapcor2
364 !
365 INTEGER, DIMENSION(SIZE(PTA)) :: inlvls_use ! varying number of effective layers
366 !
367 LOGICAL, DIMENSION(SIZE(PTA)) :: gsnowfall,gmodif_maillage
368 ! GSNOWFALL = FLAG if snowfall exceed PSNOW/10, used for
369 ! grid updating.
370 !
371 REAL :: ztstepdays ! time step in days
372 !
373 LOGICAL :: gcond_grain, gcond_yen
374 !
375 LOGICAL :: gcroinfoprint ! print daily informations
376 LOGICAL :: gcrodebugprint, gcrodebugdetailsprint, gcrodebugprintatm ! print diagnostics for debugging
377 LOGICAL :: gcrodebugprintbalance
378 !
379 INTEGER :: jj,jst ! looping indexes
380 INTEGER :: iprint ! gridpoint number to be printed
381 INTEGER :: idebug
382 !
383 REAL(KIND=JPRB) :: zhook_handle
384 !
385 IF (lhook) CALL dr_hook('SNOWCRO',0,zhook_handle)
386 !
387 !***************************************PRINT IN**********************************************
388 ! Look if we have to print snow profiles for debugging
389 gcroinfoprint = lcrodailyinfo .AND. (tptime%TIME ==0.0)
390 !***************************************PRINT OUT*********************************************
391 !***************************************DEBUG IN**********************************************
392 gcrodebugprintbalance = ( tptime%TDATE%YEAR*10000 + tptime%TDATE%MONTH*100 + tptime%TDATE%DAY &
393  >= ntimecrodebug ) .AND. &
394  ( tptime%TIME/3600. >= nhourcrodebug ) .AND. &
395  ( tptime%TDATE%YEAR*10000 + tptime%TDATE%MONTH*100 + tptime%TDATE%DAY &
396  < nendcrodebug )
397 !
398 IF (lcrodebug) THEN
399  gcrodebugprint = gcrodebugprintbalance
400  gcrodebugdetailsprint = lcrodebugdetails .AND. gcrodebugprint
401  gcrodebugprintatm = lcrodebugatm .AND. gcrodebugprint
402 ELSE
403  gcrodebugprint = .false.
404  gcrodebugdetailsprint = .false.
405  gcrodebugprintatm = .false.
406 END IF
407 
408 !
409 ! Look if we have to compute and print energy balance control
410 gcrodebugprintbalance = lcontrolbalance .AND. gcrodebugprintbalance
411 !
412 IF ( lcrodebug .OR. gcroinfoprint .OR. gcrodebugprintbalance ) THEN
413  !
414  IF ( xlatcrodebug >= -90 .AND. xloncrodebug >= -180. ) THEN
415  CALL getpoint_crodebug(pxlat,pxlon,idebug)
416  ELSE
417  idebug = npointcrodebug
418  END IF
419  !
420  ! For parallel runs : we just want to do this for the thread where there is this point.
421  IF ( xlatcrodebug >= -90 .AND. xloncrodebug >= -180. ) THEN
422  IF ( abs( pxlat(idebug)-xlatcrodebug ) + abs(pxlon(idebug) - xloncrodebug) > 0.1 ) THEN
423  gcrodebugprint = .false.
424  gcrodebugdetailsprint = .false.
425  gcrodebugprintatm = .false.
426  END IF
427  END IF
428  !
429 END IF
430 !***************************************DEBUG OUT*********************************************
431 !
432 IF ( hsnowrad=="TAR" .OR. hsnowrad=="TA1" .OR. hsnowrad=="TA2" ) THEN
433  !For now fix constant values
434  zsnowg0 = xpsnowg0
435  zsnowy0 = xpsnowy0
436  zsnoww0 = xpsnoww0
437  zsnowb0 = xpsnowb0
438  !
439  zsnowimp_density = 1500.
440  ! ZSNOWIMP_CONTENT=25.0E-9
441  !
442 END IF
443 !
444 zustar2_ic = 0.0
445 zta_ic = 0.0
446 zqa_ic = 0.0
447 !
448 gcond_grain = .true.
449 gcond_yen = .true.!FALSE. !(if TRUE : use of the Yen (1981) thermal conductivity paramztrization ;
450 ! otherwise, use the default ISBA-ES thermal conductivity parametrization)
451 !
452 pgrndflux = 0.
453 psnowhmass = 0.
454 phsnow = 0.
455 prnsnow = 0.
456 ples3l = 0.
457 plel3l = 0.
458 phpsnow = 0.
459 pevapcor = 0.
460 pthrufal = 0.
461 !
462 ! pour imprimer des diagnostics sur un des points
463 iprint = 1
464 !
465 ! - - ---------------------------------------------------
466 !
467 ! 0. Initialization
468 ! --------------
469 ! NOTE that snow layer thickness is used throughout this code: SWE
470 ! is only used to diagnose the thickness at the beginning of this routine
471 ! and it is updated at the end of this routine.
472 !
473 ! Initialization of the actual number of snow layers, total snow depth
474 ! and layer thicknesses
475 !
476 zsnowtemp(:,:) = 0.
477 !
478 gsnowfall(:) = .false.
479 inlvls_use(:) = 0
480 DO jst = 1,SIZE(psnowswe(:,:),2)
481  DO jj = 1,SIZE(zsnow)
482  IF ( psnowswe(jj,jst)>0. ) THEN
483  psnowdz(jj,jst) = psnowswe(jj,jst) / psnowrho(jj,jst)
484  inlvls_use(jj) = jst
485  ELSE
486  psnowdz(jj,jst) = 0.
487  ENDIF
488  ENDDO ! end loop snow layers
489 ENDDO ! end loop grid points
490 ! Incrementation of snow layers age
491 ztstepdays = ptstep/86400. ! time step in days
492 WHERE ( psnowswe>0 ) psnowage = psnowage + ztstepdays
493 !
494 !***************************************PRINT IN**********************************************
495 !
496 !Compute total SWE and heat for energy control
497 IF ( gcrodebugprintbalance ) THEN
498  DO jj = 1,SIZE(zsnow)
499  zsummass_ini(jj) = sum(psnowswe(jj,1:inlvls_use(jj)))
500  zsumheat_ini(jj) = sum(psnowheat(jj,1:inlvls_use(jj)))
501  ENDDO ! end loop grid points
502 ENDIF
503 !
504 ! Print of some simulation characteristics
505 IF(gcroinfoprint) THEN
506  CALL snowcroprintdate()
507  WRITE(*,fmt="(A12,I3,A12,I4)") 'nlayer:',inlvls_use(idebug), ' nbpoints:', SIZE(zsnow)
508 ! WRITE(*,*) 'PZ0H: ', PZ0H(IDEBUG)
509  WRITE(*,*) 'Snow fraction =',ppsn3l(idebug)
510 ENDIF
511 !
512 !***************************************PRINT OUT*********************************************
513 !***************************************DEBUG IN**********************************************
514 IF (gcrodebugprint) THEN
515  CALL snowcroprintdate()
516  CALL snowcroprintprofile("crocus initialization",inlvls_use(idebug),lprintgran, &
517  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
518  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:),&
519  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:),&
520  hsnowmetamo)
521 END IF
522 !
523 IF (gcrodebugprintatm) THEN
524  CALL snowcroprintatm("forcing data :",pta(idebug),pqa(idebug),pvmod(idebug), &
525  prr(idebug),psr(idebug),psw_rad(idebug),plw_rad(idebug), &
526  ptg(idebug),psoilcond(idebug),pd_g(idebug),ppsn3l(idebug) )
527 END IF
528 !***************************************DEBUG OUT********************************************
529 !
530 !* 1. Snow total depth
531 ! ----------------
532 !
533 zsnow(:) = 0.
534 DO jj = 1,SIZE(zsnow)
535  zsnow(jj) = sum(psnowdz(jj,1:inlvls_use(jj)))
536 ENDDO
537 !
538 zsnowbis(:) = zsnow(:)
539 !
540 !* 2. Snowfall
541 ! --------
542 ! Calculate uppermost density and thickness changes due to snowfall,
543 ! and add heat content of falling snow
544 !
545  CALL snownlfall_upgrid(tptime, oglacier, &
546  ptstep,psr,pta,pvmod,zsnowbis,psnowrho,psnowdz, &
547  psnowheat,psnowhmass,psnowalb,ppermsnowfrac, &
548  psnowgran1,psnowgran2,gsnowfall,zsnowdzn, &
549  zsnowrhof,zsnowdzf,zsnowgran1f,zsnowgran2f, zsnowhistf, &
550  zsnowagef,gmodif_maillage,inlvls_use,osnowdrift,pz0eff,puref,&
551  hsnowmetamo)
552 !
553 !***************************************DEBUG IN**********************************************
554 IF (gcrodebugdetailsprint) THEN
555  CALL snowcroprintprofile("after SNOWFALL_UPGRID",inlvls_use(idebug),lprintgran, &
556  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
557  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:),&
558  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:),&
559  hsnowmetamo )
560 ENDIF
561 !***************************************DEBUG OUT**********************************************
562 !
563 zsnow(:) = zsnowbis(:)
564 !
565 !* 3. Update grid/discretization
566 ! --------------------------
567 ! Reset grid to conform to model specifications:
568 !
569 DO jj=1,SIZE(zsnow)
570  !
571  IF ( gmodif_maillage(jj) ) THEN
572  CALL snownlgridfresh_1d(jj,zsnow(jj),psnowdz(jj,:),zsnowdzn(jj,:),psnowrho(jj,:), &
573  psnowheat(jj,:),psnowgran1(jj,:),psnowgran2(jj,:), &
574  psnowhist(jj,:),psnowage(jj,:),gsnowfall(jj),zsnowrhof(jj), &
575  zsnowdzf(jj),psnowhmass(jj),zsnowgran1f(jj),zsnowgran2f(jj), &
576  zsnowhistf(jj),zsnowagef(jj),inlvls_use(jj),hsnowmetamo )
577  ENDIF
578  !
579 ENDDO
580 !
581 !***************************************DEBUG IN**********************************************
582 IF (gcrodebugdetailsprint) THEN
583  CALL snowcroprintprofile("after SNOWNLGRIDFRESH_1D",inlvls_use(idebug),lprintgran, &
584  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
585  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:),&
586  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:),&
587  hsnowmetamo )
588 ENDIF
589 !***************************************DEBUG OUT**********************************************
590 !
591 !* 4. Liquid water content and snow temperature
592 ! -----------------------------------------
593 !
594 ! First diagnose snow temperatures and liquid
595 ! water portion of the snow from snow heat content:
596 ! update some snow layers parameters after new discretization
597 !
598 DO jj = 1,SIZE(zsnow)
599  !
600  ! active layers
601  DO jst=1,inlvls_use(jj)
602  psnowswe(jj,jst) = psnowdz(jj,jst) * psnowrho(jj,jst)
603 !
604  zscap(jj,jst) = psnowrho(jj,jst) * xci
605 !
606  zsnowtemp(jj,jst) = xtt + &
607  ( ( psnowheat(jj,jst)/psnowdz(jj,jst) + xlmtt*psnowrho(jj,jst) )/zscap(jj,jst) )
608 !
609  psnowliq(jj,jst) = max( 0.0, zsnowtemp(jj,jst)-xtt ) * zscap(jj,jst) * &
610  psnowdz(jj,jst) / (xlmtt*xrholw)
611 !
612  zsnowtemp(jj,jst) = min( xtt, zsnowtemp(jj,jst) )
613  ENDDO ! end loop active snow layers
614  !
615  ! unactive layers
616  DO jst = inlvls_use(jj)+1,SIZE(psnowswe,2)
617  psnowswe(jj,jst) = 0.0
618  psnowrho(jj,jst) = 999.
619  psnowdz(jj,jst) = 0.
620  psnowgran1(jj,jst) = 0.
621  psnowgran2(jj,jst) = 0.
622  psnowhist(jj,jst) = 0.
623  psnowage(jj,jst) = 0.
624  psnowheat(jj,jst) = 0.
625  zsnowtemp(jj,jst) = xtt
626  psnowliq(jj,jst) = 0.
627  ENDDO ! end loop unactive snow layers
628  !
629 ENDDO ! end loop grid points
630 !
631 !***************************************DEBUG IN**********************************************
632 IF (gcrodebugdetailsprint) THEN
633  CALL snowcroprintprofile("after liquid water/temperature diagnostic", &
634  inlvls_use(idebug),lprintgran, &
635  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
636  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:),&
637  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:),&
638  hsnowmetamo )
639 ENDIF
640 !***************************************DEBUG OUT**********************************************
641 !
642 ! 4.BIS Snow metamorphism
643 ! -----------------
644 !
645  CALL snowcrometamo(psnowdz,psnowgran1,psnowgran2,psnowhist,zsnowtemp, &
646  psnowliq,ptstep,psnowswe,inlvls_use,psnowage,hsnowmetamo )
647 !
648 !***************************************DEBUG IN**********************************************
649 IF (gcrodebugdetailsprint) THEN
650  CALL snowcroprintprofile("after SNOWCROMETAMO", inlvls_use(idebug),lprintgran, &
651  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
652  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:),&
653  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:),&
654  hsnowmetamo )
655 ENDIF
656 !***************************************DEBUG OUT**********************************************
657 !
658 !* 5. Snow Compaction
659 ! ---------------
660 ! Calculate snow density: compaction/aging: density increases
661 !
662  CALL snowcrocompactn(ptstep,psnowrho,psnowdz,zsnowtemp,zsnow, &
663  psnowgran1,psnowgran2,psnowhist,psnowliq,inlvls_use,pdircoszw,&
664  hsnowmetamo)
665 !
666 !***************************************DEBUG IN**********************************************
667 IF (gcrodebugdetailsprint) THEN
668  CALL snowcroprintprofile("after SNOWCROCOMPACTN", inlvls_use(idebug),lprintgran, &
669  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
670  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:),&
671  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:),&
672  hsnowmetamo )
673 ENDIF
674 !***************************************DEBUG OUT**********************************************
675 !
676 !* 5.1 Snow Compaction and Metamorphism due to snow drift
677 ! ---------------
678 psndrift(:) = 0.0
679 IF (osnowdrift) THEN
680  CALL snowdrift(ptstep, pvmod, psnowrho,psnowdz, zsnow, &
681  psnowgran1,psnowgran2,psnowhist,inlvls_use,pta,pqa,pps,prhoa,&
682  pz0eff,puref,osnowdrift_sublim,hsnowmetamo,psndrift)
683 ENDIF
684 !***************************************DEBUG IN**********************************************
685 IF (gcrodebugdetailsprint) THEN
686  CALL snowcroprintprofile("after SNOWDRIFT", inlvls_use(idebug),lprintgran, &
687  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
688  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:),&
689  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:),&
690  hsnowmetamo )
691 ENDIF
692 !***************************************DEBUG OUT**********************************************
693 !
694 ! Update snow heat content (J/m2) using dry density instead of total density:
695 !
696 DO jj = 1,SIZE(zsnow)
697  DO jst = 1,inlvls_use(jj)
698  zscap(jj,jst) = ( psnowrho(jj,jst) - &
699  psnowliq(jj,jst) * xrholw / max( psnowdz(jj,jst),xsnowdzmin) ) * xci
700  psnowheat(jj,jst) = psnowdz(jj,jst) * &
701  ( zscap(jj,jst)*(zsnowtemp(jj,jst)-xtt) - xlmtt*psnowrho(jj,jst) ) + &
702  xlmtt * xrholw * psnowliq(jj,jst)
703  ENDDO ! end loop snow layers
704 ENDDO ! end loop grid points
705 !
706 !***************************************DEBUG IN**********************************************
707 IF (gcrodebugdetailsprint) THEN
708  CALL snowcroprintprofile("after update snow heat content", inlvls_use(idebug),lprintgran,&
709  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
710  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
711  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
712  hsnowmetamo )
713 ENDIF
714 !***************************************DEBUG OUT********************************************
715 !
716 !* 6. Solar radiation transmission
717 ! -----------------------------
718 !
719 ! Heat source (-sink) term due to shortwave
720 ! radiation transmission within the snowpack:
721 !
722 SELECT CASE (hsnowrad)
723  CASE ("TA1")
724  zsnowimp_content(:,:,1) = 0.0
725  CASE ("TA2")
726  zsnowimp_content(:,:,1) = 100.0e-9
727  CASE ("TAR")
728  zsnowimp_content(:,:,1) = 2. * psnowage(:,:) * 1e-9
729  CASE default
730 END SELECT
731 !
732 SELECT CASE (hsnowrad)
733  CASE ("B92")
734  CALL snowcrorad(tptime,oglacier, &
735  psw_rad,psnowalb,psnowdz,psnowrho, &
736  palb,zradsink,zradxs, &
737  psnowgran1, psnowgran2, psnowage,pps, &
738  pzenith, ppermsnowfrac,inlvls_use, &
739  osnow_abs_zenith,hsnowmetamo)
740  !
741  CASE ("TAR","TA1","TA2")
742  CALL snowcro_tartes(psnowgran1,psnowgran2,psnowrho,psnowdz,zsnowg0,zsnowy0,zsnoww0, &
743  zsnowb0,zsnowimp_density,zsnowimp_content,palb,psw_rad,pzenith, &
744  inlvls_use,psnowalb,zradsink,zradxs,gcrodebugdetailsprint,hsnowmetamo)
745  !
746  CASE default
747  CALL abor1_sfx("UNKNOWN CSNOWRAD OPTION")
748  !
749 END SELECT
750 !
751 !***************************************DEBUG IN**********************************************
752 IF (gcrodebugdetailsprint) THEN
753  CALL snowcroprintprofile("after SNOWCRORAD", inlvls_use(idebug),lprintgran, &
754  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
755  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
756  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
757  hsnowmetamo)
758 ENDIF
759 !***************************************DEBUG OUT********************************************
760 !
761 !* 7. Heat transfer and surface energy budget
762 ! ---------------------------------------
763 ! Snow thermal conductivity:
764 !
765  CALL snowcrothrm(psnowrho,zscond,zsnowtemp,pps,psnowliq,gcond_grain,gcond_yen)
766 !
767 !***************************************DEBUG IN**********************************************
768 IF (gcrodebugdetailsprint) THEN
769  CALL snowcroprintprofile("after SNOWCROTHRM", inlvls_use(idebug),lprintgran, &
770  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
771  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
772  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
773  hsnowmetamo)
774 ENDIF
775 !***************************************DEBUG OUT********************************************
776 !
777 ! Precipitation heating term:
778 ! Rainfall renders it's heat to the snow when it enters
779 ! the snowpack:
780 !
781 phpsnow(:) = prr(:) * xcl * ( max( xtt,pta(:) ) - xtt ) ! (W/m2)
782 !
783 ! Surface Energy Budget calculations using ISBA linearized form
784 ! and standard ISBA turbulent transfer formulation
785 !
786 IF ( all(ppew_a_coef==0.) ) THEN
787  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
788  ! Modif Matthieu Lafaysse for glaciers
789  ! For surface ice, modify roughness lengths
790  ! Only if not implicit coupling
791  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
792  WHERE( psnowrho(:,1)>xrhothreshold_ice )
793  zz0_snowice = pz0 * xz0icez0snow
794  zz0h_snowice = pz0h * xz0icez0snow
795  zz0eff_snowice = pz0eff * xz0icez0snow
796  ELSEWHERE
797  zz0_snowice = pz0
798  zz0h_snowice = pz0h
799  zz0eff_snowice = pz0eff
800  ENDWHERE
801 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
802 ELSE
803  zz0_snowice = pz0
804  zz0h_snowice = pz0h
805  zz0eff_snowice = pz0eff
806 END IF
807 
808  CALL snowcroebud(hsnowres, himplicit_wind, &
809  ppew_a_coef, ppew_b_coef, &
810  ppet_a_coef, ppeq_a_coef, ppet_b_coef, ppeq_b_coef, &
811  xsnowdzmin, &
812  pzref,zsnowtemp(:,1),psnowrho(:,1),psnowliq(:,1),zscap(:,1), &
813  zscond(:,1),zscond(:,2), &
814  puref,pexns,pexna,pdircoszw,pvmod, &
815  plw_rad,psw_rad,pta,pqa,pps,ptstep, &
816  psnowdz(:,1),psnowdz(:,2),psnowalb,zz0_snowice, &
817  zz0eff_snowice,zz0h_snowice, &
818  zsfcfrz,zradsink(:,1),phpsnow, &
819  zct,pemisnow,prhoa,ztsterm1,ztsterm2,zra,pcdsnow,pchsnow, &
820  zqsat, zdqsat, zrsra, zustar2_ic, pri, &
821  zpet_a_coef_t,zpeq_a_coef_t,zpet_b_coef_t,zpeq_b_coef_t )
822 !
823 !***************************************DEBUG IN**********************************************
824 IF (gcrodebugdetailsprint) THEN
825  CALL snowcroprintprofile("after SNOWCROEBUD", inlvls_use(idebug),lprintgran, &
826  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
827  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
828  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
829  hsnowmetamo)
830 ENDIF
831 !***************************************DEBUG OUT********************************************
832 !
833 ! Heat transfer: simple diffusion along the thermal gradient
834 !
835 zsnowtempo1(:) = zsnowtemp(:,1) ! save surface snow temperature before update
836 !
837  CALL snowcrosolvt(ptstep,xsnowdzmin,psnowdz,zscond,zscap,ptg, &
838  psoilcond,pd_g,zradsink,zct,ztsterm1,ztsterm2, &
839  zpet_a_coef_t,zpeq_a_coef_t,zpet_b_coef_t,zpeq_b_coef_t, &
840  zta_ic,zqa_ic,pgrndflux, zsnowtemp ,zsnowflux, &
841  inlvls_use )
842 !
843 !***************************************DEBUG IN**********************************************
844 IF (gcrodebugdetailsprint) THEN
845  CALL snowcroprintprofile("after SNOWCROSOLVT", inlvls_use(idebug),lprintgran, &
846  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
847  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
848  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
849  hsnowmetamo)
850 ENDIF
851 !***************************************DEBUG OUT********************************************
852 !
853 !* 8. Surface fluxes
854 ! --------------
855 !
856  CALL snowcroflux(zsnowtemp(:,1),psnowdz(:,1),pexns,pexna, &
857  zustar2_ic, &
858  ptstep,psnowalb,psw_rad,pemisnow,zlwupsnow,plw_rad, &
859  zta_ic,zsfcfrz,zqa_ic,phpsnow, &
860  zsnowtempo1,zsnowflux,zct,zradsink(:,1), &
861  zqsat,zdqsat,zrsra, &
862  prnsnow,phsnow,pgfluxsnow,ples3l,plel3l,pevap, &
863  pustar )
864 !
865 !***************************************DEBUG IN**********************************************
866 IF (gcrodebugdetailsprint) THEN
867  CALL snowcroprintprofile("after SNOWCROFLUX", inlvls_use(idebug),lprintgran, &
868  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
869  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
870  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
871  hsnowmetamo)
872 ENDIF
873 !***************************************DEBUG OUT********************************************
874 !
875 !* 9. Snow melt
876 ! ---------
877 !
878 ! First Test to see if snow pack vanishes during this time step:
879 !
880  CALL snowcrogone(ptstep,plel3l,ples3l,psnowrho, &
881  psnowheat,zradsink,pevapcor,pthrufal,pgrndflux, &
882  pgfluxsnow,psnowdz,psnowliq,zsnowtemp,zradxs, &
883  prr,inlvls_use )
884 !
885 !***************************************DEBUG IN**********************************************
886 IF (gcrodebugdetailsprint) THEN
887  CALL snowcroprintprofile("after SNOWCROGONE", inlvls_use(idebug),lprintgran, &
888  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
889  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
890  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
891  hsnowmetamo)
892 ENDIF
893 !***************************************DEBUG OUT********************************************
894 !
895 ! Add radiation not absorbed by snow to soil/vegetation interface flux
896 ! (for thin snowpacks):
897 !
898 pgrndflux(:) = pgrndflux(:) + zradxs(:)
899 !
900 ! Second Test to see if one or several snow layers vanishe during this time
901 ! step. In such a case, the concerned snow layers are agregated to neighbours
902 
903  CALL snowcrolayer_gone(ptstep,zscap,zsnowtemp,psnowdz, &
904  psnowrho,psnowliq,psnowgran1,psnowgran2, &
905  psnowhist,psnowage,ples3l, inlvls_use )
906 !
907 !***************************************DEBUG IN**********************************************
908 IF (gcrodebugdetailsprint) THEN
909  CALL snowcroprintprofile("after SNOWCROLAYER_GONE", inlvls_use(idebug),lprintgran, &
910  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
911  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
912  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
913  hsnowmetamo)
914 ENDIF
915 !***************************************DEBUG OUT********************************************
916 !
917 ! For partial melt: transform excess heat content into snow liquid:
918 !
919  CALL snowcromelt(zscap,zsnowtemp,psnowdz,psnowrho,psnowliq,inlvls_use)
920 !
921 !***************************************DEBUG IN**********************************************
922 IF (gcrodebugdetailsprint) THEN
923  CALL snowcroprintprofile("after SNOWCROMELT", inlvls_use(idebug),lprintgran, &
924  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
925  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
926  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
927  hsnowmetamo)
928 ENDIF
929 !***************************************DEBUG OUT********************************************
930 !
931 !* 10. Snow water flow and refreezing
932 ! ------------------------------
933 ! Liquid water vertical transfer and possible snowpack runoff
934 ! And refreezing/freezing of meltwater/rainfall (ripening of the snow)
935 !
936  CALL snowcrorefrz(ptstep,prr,psnowrho,zsnowtemp,psnowdz,psnowliq,pthrufal, &
937  zscap,plel3l,inlvls_use )
938 !
939 !***************************************DEBUG IN**********************************************
940 IF (gcrodebugdetailsprint) THEN
941  CALL snowcroprintprofile("after SNOWCROREFRZ", inlvls_use(idebug),lprintgran, &
942  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
943  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
944  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
945  hsnowmetamo)
946 ENDIF
947 !***************************************DEBUG OUT********************************************
948 !
949 !* 11. Snow Evaporation/Sublimation mass updates:
950 ! ------------------------------------------
951 !
952  CALL snowcroevapn(ples3l,ptstep,zsnowtemp(:,1),psnowrho(:,1), &
953  psnowdz(:,1),pevapcor,psnowhmass )
954 !
955 !***************************************DEBUG IN**********************************************
956 IF (gcrodebugdetailsprint) THEN
957  CALL snowcroprintprofile("after SNOWCROEVAPN", inlvls_use(idebug),lprintgran, &
958  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
959  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
960  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
961  hsnowmetamo)
962 ENDIF
963 !***************************************DEBUG OUT********************************************
964 !
965 ! If all snow in uppermost layer evaporates/sublimates, re-distribute
966 ! grid (below could be evoked for vanishingly thin snowpacks):
967 !
968  CALL snowcroevapgone(psnowheat,psnowdz,psnowrho,zsnowtemp,psnowliq,psnowgran1, &
969  psnowgran2,psnowhist,psnowage,inlvls_use,hsnowmetamo )
970 !
971 !***************************************DEBUG IN**********************************************
972 IF (gcrodebugdetailsprint) THEN
973  CALL snowcroprintprofile("after SNOWCROEVAPGONE", inlvls_use(idebug),lprintgran, &
974  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:), &
975  psnowliq(idebug,:),psnowheat(idebug,:),psnowgran1(idebug,:), &
976  psnowgran2(idebug,:),psnowhist(idebug,:),psnowage(idebug,:), &
977  hsnowmetamo)
978 ENDIF
979 !***************************************DEBUG OUT********************************************
980 !
981 !* 12. Update surface albedo:
982 ! ----------------------
983 ! Snow clear sky albedo:
984 !
985 IF ( hsnowrad=='B92' ) THEN
986  CALL snowcroalb(tptime,oglacier, &
987  psnowalb,zspectralalbedo,psnowdz(:,1),psnowrho(:,1:2), &
988  ppermsnowfrac,psnowgran1(:,1),psnowgran2(:,1), &
989  psnowage(:,1),psnowgran1(:,2),psnowgran2(:,2),psnowage(:,2), &
990  pps, pzenith, inlvls_use, hsnowmetamo)
991  !the albedo is not updated in the case of TARTES scheme
992 ENDIF
993 !
994 !* 13. Update snow heat content:
995 ! -------------------------
996 ! Update the heat content (variable stored each time step)
997 ! using current snow temperature and liquid water content:
998 !
999 ! First, make check to make sure heat content not too large
1000 ! (this can result due to signifigant heating of thin snowpacks):
1001 ! add any excess heat to ground flux:
1002 !
1003 DO jj = 1,SIZE(zsnow)
1004 ! active layers
1005  DO jst = 1,inlvls_use(jj)
1006  zwholdmax(jj,jst) = snowcrohold( psnowrho(jj,jst),psnowliq(jj,jst),psnowdz(jj,jst) )
1007  zliqheatxs(jj) = max( 0.0, (psnowliq(jj,jst) - zwholdmax(jj,jst)) * xrholw ) * xlmtt/ptstep
1008  psnowliq(jj,jst) = psnowliq(jj,jst) - zliqheatxs(jj)*ptstep/(xrholw*xlmtt)
1009  psnowliq(jj,jst) = max( 0.0, psnowliq(jj,jst) )
1010  pgrndflux(jj) = pgrndflux(jj) + zliqheatxs(jj)
1011  psnowtemp(jj,jst) = zsnowtemp(jj,jst)
1012 ! Heat content using total density
1013  zscap(jj,jst) = psnowrho(jj,jst) * xci
1014  psnowheat(jj,jst) = psnowdz(jj,jst) * &
1015  ( zscap(jj,jst)*(psnowtemp(jj,jst)-xtt) - xlmtt*psnowrho(jj,jst) ) + &
1016  xlmtt * xrholw * psnowliq(jj,jst)
1017 !
1018  psnowswe(jj,jst) = psnowdz(jj,jst) * psnowrho(jj,jst)
1019  ENDDO ! end loop active snow layers
1020 !
1021 ! unactive layers
1022  DO jst = inlvls_use(jj)+1,SIZE(psnowswe,2)
1023  psnowswe(jj,jst) = 0.
1024  psnowheat(jj,jst) = 0.
1025  psnowrho(jj,jst) = 999.
1026  psnowtemp(jj,jst) = 0.
1027  psnowdz(jj,jst) = 0.
1028  ENDDO ! end loop unactive snow layers
1029 !
1030 ENDDO ! end loop grid points
1031 !
1032 ! print some final diagnostics
1033 ! ! ! IF (INLVLS_USE(I)>0) THEN
1034 ! ! ! WRITE(*,FMT="(I4,2I4,F4.0,A7,F5.2,A10,F7.1,A11,F6.2,A13,F6.2)") &
1035 ! ! ! TPTIME%TDATE%YEAR,TPTIME%TDATE%MONTH,TPTIME%TDATE%DAY,TPTIME%TIME/3600.,&
1036 ! ! ! 'HTN= ',SUM(PSNOWDZ(I,1:INLVLS_USE(I))), 'FLUX Sol=', PGRNDFLUX(I),&
1037 ! ! ! 'Tsurf_sol=',PTG(I)-273.16, 'Tbase_neige=',PSNOWTEMP(I,INLVLS_USE(I))-273.16
1038 ! ! ! ENDIF
1039 !
1040 !***************************************DEBUG IN*********************************************
1041 IF (gcrodebugprint) THEN
1042  CALL snowcroprintdate()
1043  CALL snowcroprintprofile("CROCUS : end of time step",inlvls_use(idebug),lprintgran, &
1044  psnowdz(idebug,:),psnowrho(idebug,:),psnowtemp(idebug,:),psnowliq(idebug,:), &
1045  psnowheat(idebug,:),psnowgran1(idebug,:),psnowgran2(idebug,:), &
1046  psnowhist(idebug,:),psnowage(idebug,:), hsnowmetamo)
1047 END IF
1048 !***************************************DEBUG OUT********************************************
1049 !***************************************PRINT IN*********************************************
1050 ! check suspect low temperature
1051 DO jj = 1,SIZE(zsnow)
1052 !IF(INLVLS_USE(JJ)>0) WRITE(*,*) 'SOL:',JJ,INLVLS_USE(JJ),PGRNDFLUX(JJ),PTG(JJ),&
1053 ! PSNOWTEMP(jj,INLVLS_USE(JJ)),PSNOWTEMP(jj,1),PZENITH(JJ)
1054  DO jst = 1,inlvls_use(jj)
1055  IF ( psnowtemp(jj,jst) < 100. ) THEN
1056  WRITE(*,*) 'pb tempe snow :',psnowtemp(jj,jst)
1057  WRITE(*,fmt='("DATE:",2(I2.2,"/"),I4.4,F3.0)') &
1058  tptime%TDATE%DAY,tptime%TDATE%MONTH,tptime%TDATE%YEAR,tptime%TIME/3600.
1059  WRITE(*,*) 'point',jj,"/",SIZE(zsnow)
1060  WRITE(*,*) 'layer',jst
1061  WRITE(*,*) 'pressure',pps(jj)
1062  WRITE(*,*) 'slope',acos(pdircoszw(jj))*(180./xpi),"deg"
1063  WRITE(*,*) 'XLAT=',pxlat(jj),'XLON=',pxlon(jj)
1064  WRITE(*,*) 'solar radiation=',psw_rad(jj)
1065  WRITE(*,*) 'INLVLS_USE(JJ):',inlvls_use(jj)
1066  WRITE(*,*) psnowdz(jj,1:inlvls_use(jj))
1067  WRITE(*,*) psnowrho(jj,1:inlvls_use(jj))
1068  WRITE(*,*) psnowtemp(jj,1:inlvls_use(jj))
1069  CALL abor1_sfx('SNOWCRO: erreur tempe snow')
1070  ENDIF
1071  ENDDO
1072 ENDDO
1073 !***************************************PRINT OUT*********************************************
1074 !***************************************DEBUG IN*********************************************
1075 !Control and print energy balance
1076 IF (gcrodebugprintbalance) THEN
1077  !
1078  zsummass_fin(idebug) = sum( psnowswe(idebug,1:inlvls_use(idebug)) )
1079  zsumheat_fin(idebug) = sum( psnowheat(idebug,1:inlvls_use(idebug)) )
1080  !
1081  CALL get_balance(zsummass_ini(idebug),zsumheat_ini(idebug),zsummass_fin(idebug), &
1082  zsumheat_fin(idebug),psr(idebug),prr(idebug),pthrufal(idebug), &
1083  pevap(idebug),pevapcor(idebug),pgrndflux(idebug),phsnow(idebug),&
1084  prnsnow(idebug),plel3l(idebug),ples3l(idebug),phpsnow(idebug), &
1085  psnowhmass(idebug),psnowdz(idebug,1),ptstep, &
1086  zmassbalance(idebug),zenergybalance(idebug),zevapcor2(idebug) )
1087  !
1088  CALL snowcroprintbalance(zsummass_ini(idebug),zsumheat_ini(idebug),zsummass_fin(idebug), &
1089  zsumheat_fin(idebug),psr(idebug),prr(idebug),pthrufal(idebug), &
1090  pevap(idebug),pevapcor(idebug),pgrndflux(idebug),phsnow(idebug),&
1091  prnsnow(idebug),plel3l(idebug),ples3l(idebug),phpsnow(idebug), &
1092  psnowhmass(idebug),psnowdz(idebug,1),ptstep, &
1093  zmassbalance(idebug),zenergybalance(idebug),zevapcor2(idebug))
1094  !
1095 ENDIF
1096 !
1097 IF (lpstopbalance) THEN
1098  !
1099  ! bilan pour tous points pour test eventuel sur depassement seuil des residus
1100  DO jj=1, SIZE(zsnow)
1101  !
1102  zsummass_fin(jj) = sum( psnowswe(jj,1:inlvls_use(jj)) )
1103  zsumheat_fin(jj) = sum( psnowheat(jj,1:inlvls_use(jj)) )
1104  !
1105  CALL get_balance(zsummass_ini(jj),zsumheat_ini(jj),zsummass_fin(jj), &
1106  zsumheat_fin(jj),psr(jj),prr(jj),pthrufal(jj), &
1107  pevap(jj),pevapcor(jj),pgrndflux(jj),phsnow(jj), &
1108  prnsnow(jj),plel3l(jj),ples3l(jj),phpsnow(jj), &
1109  psnowhmass(jj),psnowdz(jj,1),ptstep, &
1110  zmassbalance(jj),zenergybalance(jj),zevapcor2(jj) )
1111  !
1112  ENDDO ! end loop grid points
1113  !
1114  CALL snowcrostopbalance(zmassbalance(:),zenergybalance(:))
1115  !
1116 END IF
1117 !***************************************DEBUG OUT********************************************
1118 !
1119 pqs(:) = zqsat(:)
1120 !
1121 IF (lhook) CALL dr_hook('SNOWCRO',1,zhook_handle)
1122 !
1123  CONTAINS
1124 !
1125 !####################################################################
1126 !####################################################################
1127 !####################################################################
1128  SUBROUTINE snowcrocompactn(PTSTEP,PSNOWRHO,PSNOWDZ, &
1129  psnowtemp,psnow,psnowgran1,psnowgran2,psnowhist, &
1130  psnowliq,inlvls_use,pdircoszw,hsnowmetamo )
1131 !
1132 !! PURPOSE
1133 !! -------
1134 ! Snow compaction due to overburden and settling.
1135 ! Mass is unchanged: layer thickness is reduced
1136 ! in proportion to density increases. Method
1137 ! directly inherited from Crocus v2.4 and
1138 ! coarsely described in Brun et al., J. Glac 1989 and 1992
1139 !
1140 ! de/e = -sigma/eta * dt
1141 !
1142 ! where e is layer thickness, sigma is the vertical stress, dt is the
1143 ! time step and eta is the snow viscosity
1144 ! * sigma is currently calculated taking into account only the overburden
1145 ! (a term representing "metamorphism stress" in fresh snow may be added
1146 ! in the future)
1147 ! * eta is computed as a function of snowtype, density and temperature
1148 !
1149 ! The local slope is taken into account, through the variable PDIRCOSZW
1150 ! which is directly the cosine of the local slope
1151 !
1152 !
1153 ! HISTORY:
1154 ! Basic structure from ISBA-ES model (Boone and Etchevers, 2001)
1155 ! Implementation of Crocus laws : E. Brun, S. Morin, J.-M. Willemet July 2010.
1156 ! Implementation of slope effect on settling : V. Vionnet, S. Morin May 2011
1157 !
1158 !
1159 USE modd_csts, ONLY : xtt, xg
1160 USE modd_snow_par, ONLY : xrhosmax_es
1161 USE modd_snow_metamo
1162 !
1163 IMPLICIT NONE
1164 !
1165 !* 0.1 declarations of arguments
1166 !
1167 REAL, INTENT(IN) :: ptstep ! Time step UNIT : s
1168 REAL, DIMENSION(:), INTENT(IN) :: pdircoszw ! cosine of local slope
1169 !
1170 REAL, DIMENSION(:,:), INTENT(IN) :: psnowtemp ! Snow temperature UNIT : K
1171 !
1172 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowrho, psnowdz ! Density UNIT : kg m-3, Layer thickness UNIT : m
1173 !
1174 REAL, DIMENSION(:), INTENT(OUT) :: psnow ! Snowheight UNIT : m
1175 !
1176 REAL, DIMENSION(:,:), INTENT(IN) :: psnowgran1, psnowgran2, psnowhist, &!Snowtype variables
1177  psnowliq ! Snow liquid water content UNIT ???
1178 INTEGER, DIMENSION(:), INTENT(IN) :: inlvls_use ! Number of snow layers used
1179  CHARACTER(3), INTENT(IN) :: hsnowmetamo ! metamorphism scheme
1180 !
1181 !* 0.2 declarations of local variables
1182 !
1183 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowrho2, &! work snow density UNIT : kg m-3
1184  zviscosity, &! Snow viscosity UNIT : N m-2 s (= Pa s)
1185  zsmass !, & ! overburden mass for a given layer UNIT : kg m-2
1186 ! ZWSNOWDZ ! mass of each snow layer UNIT : kg m-2
1187 !
1188 INTEGER :: jj,jst ! looping indexes
1189 !
1190 REAL(KIND=JPRB) :: zhook_handle
1191 !
1192 !-------------------------------------------------------------------------------
1193 !
1194 ! 1. Cumulative snow mass (kg/m2):
1195 ! --------------------------------
1196 !
1197 IF (lhook) CALL dr_hook('SNOWCROCOMPACTN',0,zhook_handle)
1198 !
1199 DO jj = 1,SIZE(psnow)
1200  zsmass(jj,1) = 0.0
1201  DO jst = 2,inlvls_use(jj)
1202  zsmass(jj,jst) = zsmass(jj,jst-1) + psnowdz(jj,jst-1) * psnowrho(jj,jst-1)
1203  ENDDO
1204  zsmass(jj,1) = 0.5 * psnowdz(jj,1) * psnowrho(jj,1) ! overburden of half the mass of the uppermost layer applied to itself
1205 ENDDO
1206 
1207 !
1208 ! 2. Compaction/Settling
1209 ! ----------------------
1210 !
1211 DO jj = 1,SIZE(psnow)
1212  !
1213  DO jst = 1,inlvls_use(jj)
1214  !
1215  ! Snow viscosity basic equation (depend on temperature and density only):
1216  zviscosity(jj,jst) = xvvisc1 * &
1217  exp( xvvisc3*psnowrho(jj,jst) + xvvisc4*abs(xtt-psnowtemp(jj,jst)) ) * &
1218  psnowrho(jj,jst) / xvro11
1219  !
1220  ! Equations below apply changes to the basic viscosity value, based on snow microstructure properties
1221  IF ( psnowliq(jj,jst)>0.0 ) THEN
1222  zviscosity(jj,jst) = zviscosity(jj,jst) / &
1223  ( xvvisc5 + xvvisc6*psnowliq(jj,jst)/psnowdz(jj,jst) )
1224  ENDIF
1225  !
1226  IF( psnowliq(jj,jst)/psnowdz(jj,jst)<=0.01 .AND. psnowhist(jj,jst)>=nvhis2 ) THEN
1227  zviscosity(jj,jst) = zviscosity(jj,jst) * xvvisc7
1228  ENDIF
1229  !
1230  IF ( psnowhist(jj,jst)==nvhis1 ) THEN
1231  !
1232  IF ( hsnowmetamo=="B92" ) THEN
1233  !
1234  IF ( psnowgran1(jj,jst)>=0. .AND. psnowgran1(jj,jst)<xvgran6 ) THEN
1235  zviscosity(jj,jst) = zviscosity(jj,jst) * &
1236  min( 4., exp( min( xvdiam1, &
1237  psnowgran2(jj,jst) -xvdiam4 ) / xvdiam6 ) )
1238  ENDIF
1239  !
1240  ELSEIF ( psnowgran1(jj,jst)>=xvdiam6*(4.-psnowgran2(jj,jst)) .AND. psnowgran2(jj,jst)<xvgran6/xvgran1 ) THEN
1241  zviscosity(jj,jst) = zviscosity(jj,jst) * &
1242  min( 4., exp( min( xvdiam1, &
1243  (xvdiam6*(4.-psnowgran2(jj,jst)))-xvdiam4 ) / xvdiam6 ) )
1244  ENDIF
1245  !
1246  ENDIF
1247  !
1248  ! Calculate new snow snow density: compaction from weight/over-burden
1249  zsnowrho2(jj,jst) = psnowrho(jj,jst) + psnowrho(jj,jst) * ptstep * &
1250  ( xg*pdircoszw(jj)*zsmass(jj,jst)/zviscosity(jj,jst) )
1251  !
1252  ! Calculate new grid thickness in response to density change
1253  psnowdz(jj,jst) = psnowdz(jj,jst) * ( psnowrho(jj,jst)/zsnowrho2(jj,jst) )
1254  !
1255  ! Update density (kg m-3):
1256  psnowrho(jj,jst) = zsnowrho2(jj,jst)
1257  !
1258  ENDDO ! end loop snow layers
1259  !
1260 ENDDO ! end loop grid points
1261 !
1262 !
1263 ! 3. Update total snow depth:
1264 ! -----------------------------------------------
1265 !
1266 DO jj = 1,SIZE(psnowdz,1)
1267  psnow(jj) = sum( psnowdz(jj,1:inlvls_use(jj)) )
1268 ENDDO
1269 !
1270 IF (lhook) CALL dr_hook('SNOWCROCOMPACTN',1,zhook_handle)
1271 
1272 !
1273 !-------------------------------------------------------------------------------
1274 !
1275 END SUBROUTINE snowcrocompactn
1276 
1277 
1278 !####################################################################
1279 !####################################################################
1280 !####################################################################
1281 SUBROUTINE snowcrometamo(PSNOWDZ,PSNOWGRAN1, PSNOWGRAN2, &
1282  psnowhist, psnowtemp, psnowliq, ptstep, &
1283  psnowswe,inlvls_use, psnowage, hsnowmetamo)
1284 !
1285 
1286 !**** *METAMO* - METAMORPHOSE DES GRAINS
1287 ! - SNOW METAMORPHISM
1288 ! OBJET.
1289 ! ------
1290 ! METAMORPHOSE DU MANTEAU NEIGEUX.
1291 ! EVOLUTION DU TYPE DE GRAINS
1292 ! MISE A JOUR DES VARIABLES HISTORIQUES.
1293 ! METAMORPHISM OF THE SNOW GRAINS,
1294 ! HISTORICAL VARIABLES
1295 
1296 !** INTERFACE.
1297 ! ----------
1298 ! FORMALISME ADOPTE POUR LA REPRESENTATION DES GRAINS :
1299 ! FORMALISM FOR THE REPRESENTATION OF GRAINS
1300 ! -----------------------------------------------------
1301 
1302 
1303 ! 1 - -1 NEIGE FRAICHE
1304 ! / \ | -------------
1305 ! / \ | DENDRICITE DECRITE EN TERME
1306 ! / \ | DENDRICITY DE DENDRICITE ET
1307 ! / \ | SPHERICITE
1308 ! 2---------3 - 0 DESCRIBED WITH
1309 ! SPHERICITY AND
1310 ! |---------| DENDRICITY
1311 ! 0 1
1312 ! SPHERICITE
1313 ! SPHERICITY
1314 
1315 ! 4---------5 -
1316 ! | | |
1317 ! | | | DIAMETRE (OU TAILLE)
1318 ! | | | DIAMETER (OR SIZE )
1319 ! | | |
1320 ! | | | NEIGE NON DENDRITIQUE
1321 ! 6---------7 - ---------------------
1322 
1323 ! SPHERICITE ET TAILLE
1324 ! SPHERICITY AND SIZE
1325 
1326 ! LES VARIABLES DU MODELE :
1327 ! -------------------------
1328 ! CAS DENDRITIQUE CAS NON DENDRITIQUE
1329 !
1330 ! SGRAN1(JST) : DENDRICITE SGRAN1(JST) : SPHERICITE
1331 ! SGRAN2(JST) : SPHERICITE SGRAN2(JST) : TAILLE (EN METRE)
1332 ! SIZE
1333 
1334 !
1335 ! CAS DENDRITIQUE/ DENDRITIC CASE
1336 ! -------------------------------
1337 ! SGRAN1(JST) VARIE DE -XVGRAN1 (-99 PAR DEFAUT) (ETOILE) A 0
1338 ! (DENDRICITY) >D OU LA DIVISION PAR -XVGRAN1 POUR OBTENIR DES VALEURS
1339 ! ENTRE 1 ET 0
1340 ! VARIES FROM -XVGRAN1 (DEFAULT -99) (FRESH SNOW) TO 0
1341 ! DIVISION BY -XVGRAN1 TO OBTAIN VALUES BETWEEN 0 AND 1
1342 
1343 ! SGRAN2(JST) VARIE DE 0 (CAS COMPLETEMENT ANGULEUX) A XVGRAN1
1344 ! (SPHERICITY) (99 PAR DEFAUT)
1345 ! >D OU LA DIVISION PAR XVGRAN1 POUR OBTENIR DES VALEURS
1346 ! ENTRE 0 ET 1
1347 ! VARIES FROM 0 (SPHERICITY=0) TO XVGRAN1
1348 
1349 
1350 ! CAS NON DENDRITIQUE / NON DENDRITIC CASE
1351 ! ---------------------------------------
1352 
1353 ! SGRAN1(JST) VARIE DE 0 (CAS COMPLETEMENT ANGULEUX) A XVGRAN1
1354 ! (SPHERICITY) (99 PAR DEFAUT) (CAS SPHERIQUE)
1355 ! >D OU LA DIVISION PAR XVGRAN1 POUR OBTENIR DES VALEURS
1356 ! ENTRE 0 ET 1
1357 ! VARIES FROM 0 TO 99
1358 
1359 ! SGRAN2(JST) EST SUPERIEUR A XVDIAM1-SPHERICITE (3.E-4 M) ET NE FAIT QUE CROITRE
1360 ! (SIZE) IS GREATER THAN XVDIAM1-SPHERICITE (3.E-4 M) ALWAYS INCREASE
1361 
1362 
1363 ! EXEMPLES : POINTS CARACTERISTIQUES DE LA FIGURE
1364 ! --------
1365 
1366 ! SGRAN1 SGRAN2 DENDRICITE SPHERICITE TAILLE
1367 ! DENDRICITY SPHERICITY SIZE
1368 ! --------------------------------------------------------------
1369 ! (M)
1370 ! 1 -XVGRAN1 VNSPH3 1 0.5
1371 ! 2 0 0 0 0
1372 ! 3 0 XVGRAN1 0 1
1373 ! 4 0 XVDIAM1 0 4.E-4
1374 ! 5 XVGRAN1 XVDIAM1-XVSPHE1 1 3.E-4
1375 ! 6 0 -- 0 --
1376 ! 7 XVGRAN1 -- 1 --
1377 
1378 ! PAR DEFAUT : XVGRAN1 =99 VNSPH3=50 XVSPHE1=1. XVDIAM1=4.E-4
1379 
1380 
1381 ! METHODE.
1382 ! --------
1383 ! EVOLUTION DES TYPES DE GRAINS : SELON LES LOIS DECRITES
1384 ! DANS BRUN ET AL (1992)
1385 ! PLUSIEURS CAS SONT A DISTINGUER
1386 ! 1.2 NEIGE HUMIDE
1387 ! 1.3 METAMORPHOSE NEIGE SECHE
1388 ! 1.3.1 FAIBLE GRADIENT
1389 ! 1.3.2 GRADIENT MOYEN
1390 ! 1.3.3 FORT GRADIENT
1391 ! DANS CHAQUE CAS ON SEPARE NEIGE DENDRITIQUE ET NON DENDRITIQUE
1392 ! LE PASSAGE DENDRITIQUE => NON DENDRITIQUE SE FAIT LORSQUE
1393 ! SGRAN1 DEVIENT > 0
1394 
1395 ! TASSEMENT : LOIS DE VISCOSITE ADAPTEE SELON LE TYPE DE GRAINS
1396 
1397 ! VARIABLES HISTORIQUES (CAS NON DENDRITIQUE SEULEMENT)
1398 
1399 ! MSHIST DEFAUT
1400 ! 0 CAS NORMAL
1401 ! NVHIS1 1 GRAINS ANGULEUX
1402 ! NVHIS2 2 GRAINS AYANT ETE EN PRESENCE D EAU LIQUIDE
1403 ! MAIS N'AYANT PAS EU DE CARATERE ANGULEUX
1404 ! NVHIS3 3 GRAINS AYANT ETE EN PRESENCE D EAU LIQUIDE
1405 ! AYANT EU AUPARAVANT UN CARACTERE ANGULEUX
1406 
1407 ! GRAIN METAMORPHISM ACCORDING TO BRUN ET AL (1992)
1408 ! THE DIFFERENT CASES ARE :
1409 ! 1.2 WET SNOW
1410 ! 1.3 DRY SNOW
1411 ! 1.3.1. LOW TEMPERATURE GRADIENT
1412 ! 1.3.2. MODERATE TEMPERATURE GRADIENT
1413 ! 1.3.3. HIGH TEMPERATURE GRADIENTi
1414 ! THE CASE OF DENTRITIC OR NON DENDRITIC SNOW IS TREATED SEPARATELY
1415 ! THE LIMIT DENTRITIC ==> NON DENDRITIC IS REACHED WHEN SGRAN1>0
1416 
1417 ! SNOW SETTLING : VISCOSITY DEPENDS ON THE GRAIN TYPES
1418 
1419 ! HISTORICAL VARIABLES (NON DENDRITIC CASE)
1420 ! MSHIST DEFAUT
1421 ! 0 CAS NORMAL
1422 ! NVHIS1 1 FACETED CRISTAL
1423 ! NVHIS2 2 LIQUID WATER AND NO FACETED CRISTALS BEFORE
1424 ! NVHIS3 3 LIQUID WATER AND FACETED CRISTALS BEFORE
1425 
1426 ! EXTERNES.
1427 ! ---------
1428 
1429 ! REFERENCES.
1430 ! -----------
1431 
1432 ! AUTEURS.
1433 ! --------
1434 ! ERIC BRUN ET AL. - JOURNAL OF GLACIOLOGY 1989/1992.
1435 
1436 ! MODIFICATIONS.
1437 ! --------------
1438 ! 08/95: YANNICK DANIELOU - CODAGE A LA NORME DOCTOR.
1439 ! 09/96: ERIC MARTIN - CORRECTION COMMENTAIRES
1440 ! 03/06: JM Willemet - F90 and SI units
1441 ! 08/06: JM Willemet - new formulation for TEL (Mwat/(Mice+Mwat) instead of Mwat/Mice.
1442 ! Threshold on the diameter increasing of the wet grains.
1443 ! 01/07 : JM Willemet - CORRECTION DES COUCHES SATUREES SUBISSANT DU TASSEMENT
1444 ! CORRECTION ON THE SATURATED LAYERS WHICH ARE SETTLED
1445 ! 12/12: CM Carmagnola - Dendricity and size replaced by the optical diameter
1446 ! - Test of different evolution laws for the optical diameter
1447 ! 08/13: M Lafaysse - Simplification of historical parameter computation (logicals GNONDENDRITIC, GFACETED, GSPHE_LW)
1448  !
1449 USE modd_snow_metamo
1450 USE modd_csts, ONLY : xtt, xpi, xrholw, xrholi
1451 USE modd_surf_par, ONLY : xundef
1452 !
1453 USE mode_snow3l
1454 !
1455 IMPLICIT NONE
1456 !
1457 ! 0.1 declarations of arguments
1458 !
1459 REAL, DIMENSION(:,:), INTENT(IN) :: psnowdz, psnowtemp, psnowliq, psnowswe
1460 !
1461 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowgran1, psnowgran2, psnowhist
1462 !
1463 REAL, INTENT(IN) :: ptstep
1464 !
1465 INTEGER, DIMENSION(:), INTENT(IN) :: inlvls_use
1466 !
1467 REAL, DIMENSION(:,:), INTENT(IN) :: psnowage
1468 !
1469  CHARACTER(3), INTENT(IN) :: hsnowmetamo ! metamorphism scheme
1470 !
1471 ! 0.2 declaration of local variables
1472 !
1473 REAL :: zgradt, ztelm, zvdent, zdent, zsphe, zvap, zdangl, &
1474  zsize, zssa, zssa0, zssa_t, zssa_t_dt, za, zb, zc, &
1475  za2, zb2, zc2, zoptd, zoptr, zoptr0, zdrdt
1476 REAL :: zvdent1, zvdent2, zvsphe, zcoef_sph
1477 REAL :: zdenom1, zdenom2, zfact1, zfact2
1478 INTEGER :: inlvls
1479 INTEGER :: jst,jj !Loop controls
1480 INTEGER :: idrho, idgrad, idtemp !Indices for values from Flanner 2006
1481 LOGICAL :: gnondendritic ,gfaceted, gsphe_lw
1482 LOGICAL :: gcond_b92, gcond_c13, gcond_sph
1483 !
1484 REAL(KIND=JPRB) :: zhook_handle
1485 !
1486 ! INITIALISATION
1487 ! --------------
1488 !
1489 IF (lhook) CALL dr_hook('SNOWCROMETAMO',0,zhook_handle)
1490 !
1491 inlvls = SIZE(psnowgran1(:,:),2) ! total snow layers
1492 !
1493 !* 1. METAMORPHOSES DANS LES STRATES. / METAMORPHISM
1494 ! -----------------------------------------------
1495 DO jj = 1,SIZE(psnowrho,1)
1496  !
1497  DO jst = 1,inlvls_use(jj)
1498  !
1499  ! 1.1 INITIALISATION: GRADIENT DE TEMPERATURE / TEMPERATURE GRADIENT
1500  IF ( jst==inlvls_use(jj) ) THEN
1501  zgradt = abs(psnowtemp(jj,jst) - psnowtemp(jj,jst-1))*2. / (psnowdz(jj,jst-1) + psnowdz(jj,jst))
1502  ELSEIF ( jst==1 ) THEN
1503  zgradt = abs(psnowtemp(jj,jst+1) - psnowtemp(jj,jst) )*2. / (psnowdz(jj,jst) + psnowdz(jj,jst+1))
1504  ELSE
1505  zgradt = abs(psnowtemp(jj,jst+1) - psnowtemp(jj,jst-1))*2. / &
1506  (psnowdz(jj,jst-1) + psnowdz(jj,jst)*2. + psnowdz(jj,jst+1))
1507  ENDIF
1508  !
1509  IF ( psnowliq(jj,jst)>xuepsi ) THEN
1510  ! 1.2 METAMORPHOSE HUMIDE. / WET SNOW METAMORPHISM
1511  !
1512  ! TENEUR EN EAU LIQUIDE / LIQUID WATER CONTENT
1513  ztelm = xupourc * psnowliq(jj,jst) * xrholw / psnowswe(jj,jst)
1514  !
1515  ! VITESSES DE DIMINUTION DE LA DENDRICITE / RATE OF THE DENDRICITY DECREASE
1516  zvdent1 = max( xvdent2 * ztelm**nvdent1, xvdent1 * exp(xvvap1/xtt) )
1517  zvdent2 = zvdent1
1518  ! CONDITION POUR LE CAS NON DENDRITIQUE NON SPHERIQUE
1519  gcond_b92 = ( psnowgran1(jj,jst)<xvgran1-xuepsi )
1520  gcond_c13 = .true. ! CONDITION POUR LE CALCUL DE SNOWGRAN1
1521  ! X COEF
1522  zvsphe = xvsphe1
1523  ! FOR C13
1524  zcoef_sph = 2.
1525  !
1526  ELSEIF ( zgradt<xvgrat1 ) THEN
1527  ! 1.3.1 METAMORPHOSE SECHE FAIBLE/ DRY LOW GRADIENT (0-5 DEG/M).
1528  !
1529  zvap = exp( xvvap1/psnowtemp(jj,jst) )
1530  !
1531  ! VITESSES DE DIMINUTION DE LA DENDRICITE / RATE OF THE DENDRICITY DECREASE
1532  zvdent1 = xvdent1 * zvap
1533  zvdent2 = xvsphe2 * zvap
1534  ! CONDITION POUR LE CAS NON DENDRITIQUE SPHERICITE NON LIMITEE
1535  gcond_b92 = ( psnowhist(jj,jst)/=nvhis1 .OR. psnowgran2(jj,jst)<xvdiam2 )
1536  gcond_c13 = ( hsnowmetamo=='C13' ) ! CONDITION POUR LE CALCUL DE SNOWGRAN1
1537  ! X COEF
1538  zvsphe = xvsphe1
1539  ! FOR C13
1540  zcoef_sph = 2.
1541  !
1542  ELSE
1543  ! 1.3.2 METAMORPHOSE SECHE GRADIENT MOYEN / DRY MODERATE (5-15).
1544  ! 1.3.3 METAMORPHOSE SECHE FORT / DRY HIGH GRADIENT
1545  !
1546  zvap = exp( xvvap1/psnowtemp(jj,jst) ) * (zgradt)**xvvap2
1547  !
1548  ! VITESSES DE DIMINUTION DE LA DENDRICITE / RATE OF THE DENDRICITY DECREASE
1549  zvdent1 = xvdent1 * zvap
1550  zvdent2 = - xvdent1 * zvap
1551  ! CONDITION POUR LE CAS NON DENDRITIQUE NON COMPLETEMENT ANGULEUX
1552  gcond_b92 = ( zgradt<xvgrat2 .OR. psnowgran1(jj,jst)>0. )
1553  gcond_c13 = ( hsnowmetamo=='C13' ) ! CONDITION POUR LE CALCUL DE SNOWGRAN1
1554  ! X COEF
1555  zvsphe = xundef
1556  ! FOR C13
1557  zcoef_sph = 3.
1558  !
1559  ENDIF
1560  !
1561  IF ( hsnowmetamo=="B92" ) THEN
1562  !
1563  !------------------------------------------------
1564  ! BRUN et al. 1992 (B92)
1565  !
1566  ! -> Wet snow and dry snow
1567  ! -> Evolution of dendricity, sphericity and size
1568  !------------------------------------------------
1569  !
1570  IF ( psnowgran1(jj,jst)<-xuepsi ) THEN
1571  ! 1.2.1 CAS DENDRITIQUE/DENDRITIC CASE.
1572  !
1573  ! / CALCUL NOUVELLE DENDRICITE ET SPHERICITE.
1574  zdent = - psnowgran1(jj,jst)/xvgran1 - zvdent1 * ptstep
1575  zsphe = psnowgran2(jj,jst)/xvgran1 + zvdent2 * ptstep
1576  CALL set_thresh(zgradt,psnowliq(jj,jst),zsphe)
1577  IF( zdent<=xuepsi ) THEN
1578  ! EVOLUTION DE SGRAN1 ET SGRAN2 ET TEST PASSAGE DENDRITIQUE > NON DENDRITIQUE.
1579  psnowgran1(jj,jst) = zsphe * xvgran1
1580  psnowgran2(jj,jst) = xvdiam1 - xvdiam5 * min( zsphe, zvsphe )
1581  ELSE
1582  psnowgran1(jj,jst) = -zdent * xvgran1
1583  psnowgran2(jj,jst) = zsphe * xvgran1
1584  ENDIF
1585  !
1586  ELSEIF ( gcond_b92 ) THEN
1587  ! 1.2.2 CAS NON DENDRITIQUE ET
1588  ! NON COMPLETEMENT SPHERIQUE / NON DENDRITIC AND NOT COMPLETELY SPHERIC CASE
1589  ! OU SPHERICITE NON LIMITEE
1590  ! OU NON COMPLETEMENT ANGULEUX
1591  !
1592  ! . EVOLUTION DE LA SPHERICITE SEULEMENT / EVOLUTION OF SPHERICITY ONLY (NOT SIZE)
1593  zsphe = psnowgran1(jj,jst)/xvgran1 + zvdent2 * ptstep
1594  CALL set_thresh(zgradt,psnowliq(jj,jst),zsphe)
1595  psnowgran1(jj,jst) = zsphe * xvgran1
1596  !
1597  ELSEIF ( psnowliq(jj,jst)>xuepsi ) THEN
1598  ! 1.2.3 CAS NON DENDRITIQUE ET SPHERIQUE/NON DENDRITIC AND SPHERIC EN METAMORPHOSE HUMIDE
1599  !
1600  ! EVOLUTION DE LA TAILLE SEULEMENT/EVOLUTION OF SIZE ONLY
1601  CALL get_gran(ptstep,ztelm,psnowgran2(jj,jst))
1602  !
1603  ELSEIF ( zgradt<xvgrat1 ) THEN
1604  ! 1.2.4. CAS HISTORIQUE=2 OU 3 ET GROS GRAINS SPHERICITE LIMITEE / CASE HISTORY=2 OR 3 AND BIG GRAINS LIMITED SPHERICITY
1605  !
1606  zsphe = psnowgran1(jj,jst)/xvgran1 + &
1607  zvdent2 * ptstep * exp( min( 0., xvdiam3-psnowgran2(jj,jst) ) / xvdiam6 )
1608  zsphe = min( zsphe, xvsphe3 )
1609  CALL set_thresh(zgradt,psnowliq(jj,jst),zsphe)
1610  psnowgran1(jj,jst) = zsphe * xvgran1
1611  !
1612  ELSE
1613  ! 1.2.5. CAS NON DENDRITIQUE ET ANGULEUX/DENDRITIC AND SPERICITY=0.
1614  !
1615  zdangl = snow3l_marbouty(psnowrho(jj,jst),psnowtemp(jj,jst),zgradt)
1616  psnowgran2(jj,jst) = psnowgran2(jj,jst) + zdangl * xvfi * ptstep
1617  !
1618  ENDIF
1619  !
1620  ELSE
1621  !
1622  !------------------------------------------------
1623  ! CARMAGNOLA et al. 2013 (C13)
1624  !
1625  ! -> Wet snow
1626  ! -> Evolution of optical diameter and sphericity
1627  !------------------------------------------------
1628  !
1629  ! SPHERICITY
1630  zsphe = psnowgran2(jj,jst) + zvdent2 * ptstep
1631  CALL set_thresh(zgradt,psnowliq(jj,jst),zsphe)
1632  IF ( psnowliq(jj,jst)>xuepsi .OR. zgradt<xvgrat1 ) THEN
1633  gcond_sph = ( zsphe < 1.-xuepsi )
1634  ELSE
1635  gcond_sph = ( zsphe > xuepsi )
1636  ENDIF
1637  !
1638  IF ( gcond_c13 .AND. psnowgran1(jj,jst)<xvdiam6*(4.-zsphe)-xuepsi ) THEN
1639  ! 1.1.1 CAS DENDRITIQUE/DENDRITIC CASE.
1640  !
1641  IF ( gcond_sph ) THEN
1642  psnowgran1(jj,jst) = psnowgran1(jj,jst) + xvdiam6 * ptstep * &
1643  ( zvdent2*(psnowgran1(jj,jst)/xvdiam6-1.)/(zsphe-3.) - &
1644  zvdent1*(zsphe-3.) )
1645  ELSE
1646  psnowgran1(jj,jst) = psnowgran1(jj,jst) + xvdiam6 * ptstep * zvdent1 * zcoef_sph
1647  ENDIF
1648  !
1649  ELSEIF ( gcond_c13 .AND. gcond_sph ) THEN
1650  ! 1.2.2 CAS NON DENDRITIQUE ET
1651  ! NON COMPLETEMENT SPHERIQUE / NON DENDRITIC AND NOT COMPLETELY SPHERIC CASE
1652  ! OU NON COMPLETEMENT ANGULEUX
1653  !
1654  psnowgran1(jj,jst) = psnowgran1(jj,jst) - xvdiam6 * ptstep * zvdent2 * 2.* zsphe
1655  !
1656  ELSEIF ( psnowliq(jj,jst)>xuepsi ) THEN
1657  ! 1.2.3 CAS NON DENDRITIQUE ET SPHERIQUE/NON DENDRITIC AND SPHERIC EN METAMORPHOSE HUMIDE
1658  !
1659  ! NON DENDRITIC AND SPHERIC: EVOLUTION OF SIZE ONLY
1660  CALL get_gran(ptstep,ztelm,psnowgran1(jj,jst))
1661  !
1662  ELSEIF ( gcond_c13 .AND. zgradt>=xvgrat2 ) THEN
1663  !
1664  zdangl = snow3l_marbouty(psnowrho(jj,jst),psnowtemp(jj,jst),zgradt)
1665  psnowgran1(jj,jst) = psnowgran1(jj,jst) + 0.5 * zdangl * xvfi * ptstep
1666  !
1667  ENDIF
1668  !
1669  psnowgran2(jj,jst) = zsphe
1670  !
1671  !---------------------------------
1672  ! TAILLANDIER et al. 2007 (T07)
1673  !
1674  ! -> Dry snow
1675  ! -> Evolution of optical diameter
1676  !---------------------------------
1677  !
1678  IF ( psnowliq(jj,jst)<=xuepsi .AND. hsnowmetamo=='T07' ) THEN
1679  !
1680  ! WRITE(*,*) csnowmetamo,': you are using T07 formulation!!'
1681  !
1682  ! Coefficients from Taillander et al. 2007
1683  zssa0 = 6./( xrholi*xvdiam6 ) * 10.
1684  !
1685  za = 0.659*zssa0 - 27.2 * ( psnowtemp(jj,jst)-273.15-2.03 ) ! TG conditions
1686  zb = 0.0961*zssa0 - 3.44 * ( psnowtemp(jj,jst)-273.15+1.90 )
1687  zc = -0.341*zssa0 - 27.2 * ( psnowtemp(jj,jst)-273.15-2.03 )
1688  za2 = 0.629*zssa0 - 15.0 * ( psnowtemp(jj,jst)-273.15-11.2 ) ! ET conditions
1689  zb2 = 0.0760*zssa0 - 1.76 * ( psnowtemp(jj,jst)-273.15-2.96 )
1690  zc2 = -0.371*zssa0 - 15.0 * ( psnowtemp(jj,jst)-273.15-11.2 )
1691  !
1692  ! Compute SSA (method from Jacobi, 2010)
1693 ! ZSSA = 6./(XRHOLI*PSNOWGRAN1(JJ,JST))*10.
1694 ! ZSSA_t = (0.5+0.5*TANH(0.5*(ZGRADT-10.)))*(ZA-ZB*LOG(PSNOWAGE(JJ,JST)*24+EXP(ZC/ZB))) + &
1695 ! (0.5-0.5*TANH(0.5*(ZGRADT-10.)))*(ZA2-ZB2*LOG(PSNOWAGE(JJ,JST)*24+EXP(ZC2/ZB2)))
1696 !
1697 ! ZSSA_t_dt = (0.5+0.5*TANH(0.5*(ZGRADT-10.)))*(ZA-ZB*LOG(PSNOWAGE(JJ,JST)*24+PTSTEP/3600.+EXP(ZC/ZB))) + &
1698 ! (0.5-0.5*TANH(0.5*(ZGRADT-10.)))*(ZA2-ZB2*LOG(PSNOWAGE(JJ,JST)*24+PTSTEP/3600.+EXP(ZC2/ZB2)))
1699 !
1700 ! ZSSA = ZSSA + (ZSSA_t_dt-ZSSA_t)
1701 !
1702 ! ZSSA = MAX(ZSSA,8.*10.)
1703 !
1704 ! PSNOWGRAN1(JJ,JST) = 6./(XRHOLI*ZSSA)*10.
1705  !
1706  ! Compute SSA (rate equation with Taylor series)
1707  zssa = 6./( xrholi*psnowgran1(jj,jst) ) * 10.
1708  !
1709  zdenom1 = (psnowage(jj,jst)*24.) + exp(zc/zb)
1710  zdenom2 = (psnowage(jj,jst)*24.) + exp(zc2/zb2)
1711  zfact1 = 0.5 + 0.5*tanh( 0.5*(zgradt-10.) )
1712  zfact2 = 0.5 - 0.5*tanh( 0.5*(zgradt-10.) )
1713  zssa = zssa + (ptstep/3600.) * ( zfact1 * (-zb/zdenom1) + zfact2 * (-zb2/zdenom2) + &
1714  (ptstep/3600.) * ( zfact1 * (zb/zdenom1**2.) + zfact2 * (zb2/zdenom2**2.) ) * 1./2. )
1715  !ZSSA = ZSSA + (PTSTEP/3600.) * ( ZFACT1 * ZB /ZDENOM1 * ( 1./ZDENOM1 * (PTSTEP/3600.) * 1./2. - 1. ) + &
1716  ! ZFACT2 * ZB2/ZDENOM2 * ( 1./ZDENOM2 * (PTSTEP/3600.) * 1./2. - 1. ) )
1717  !
1718  zssa = max( zssa, 8.*10. )
1719  !
1720  psnowgran1(jj,jst) = 6./( xrholi*zssa ) * 10.
1721  !
1722  !---------------------------------
1723  ! FLANNER et al. 2006 (F06)
1724  !
1725  ! -> Dry snow
1726  ! -> Evolution of optical diameter
1727  !---------------------------------
1728  ELSEIF ( psnowliq(jj,jst)<=xuepsi .AND. hsnowmetamo=='F06' )THEN
1729  !
1730  ! WRITE(*,*) CSNOWMETAMO,': you are using F06 formulation!!'
1731  !
1732  ! XDRDT0(dens,gradT,T), XTAU(dens,gradT,T), XKAPPA(dens,gradT,T)
1733  ! dens: [1-8 <-> 50.-400. kg/m3]
1734  ! gradT: [1-31 <-> 0.-300. K/m]
1735  ! T: [1-11 <-> 223.15-273.15 K]
1736  !
1737  ! Select indices of density, temperature gradient and temperature
1738  idrho = min( abs( int( (psnowrho(jj,jst)-25.)/50. ) + 1 ), 8 )
1739  idgrad = min( abs( int( (zgradt-5.)/10.+2. ) ), 31 )
1740  idtemp = min( abs( int( (psnowtemp(jj,jst)-225.65 )/5.+2. ) ), 11 )
1741  IF ( psnowtemp(jj,jst)<221. ) idtemp = 1
1742  !
1743  ! Compute SSA
1744  zoptr0 = xvdiam6/2. * 10.**6.
1745  zoptr = psnowgran1(jj,jst)/2. * 10.**6.
1746  zdrdt = xdrdt0(idrho,idgrad,idtemp) * &
1747  ( xtau(idrho,idgrad,idtemp) / &
1748  ( zoptr - zoptr0 + xtau(idrho,idgrad,idtemp) ) )**(1./xkappa(idrho,idgrad,idtemp))
1749  zoptr = zoptr + zdrdt * ptstep/3600.
1750  zoptr = min( zoptr, 3./(xrholi*2.) * 10.**6.)
1751  !
1752  psnowgran1(jj,jst) = zoptr * 2./10.**6.
1753  !
1754  ENDIF
1755  !
1756  ENDIF
1757  !
1758  ENDDO
1759  !
1760 ENDDO
1761 
1762 !* 2. MISE A JOUR VARIABLES HISTORIQUES (CAS NON DENDRITIQUE).
1763 ! UPDATE OF THE HISTORICAL VARIABLES
1764 ! --------------------------------------------------------
1765 DO jj = 1,SIZE(psnowrho,1)
1766  !
1767  DO jst = 1,inlvls_use(jj)
1768  !
1769  IF ( hsnowmetamo=='B92' ) THEN
1770  !
1771  !non dendritic
1772  gnondendritic = ( psnowgran1(jj,jst)>=0. )
1773  IF ( gnondendritic ) THEN
1774  !faceted crystals
1775  gfaceted = ( psnowgran1(jj,jst)<xvsphe4 .AND. psnowhist(jj,jst)==0. )
1776  !spheric and liquid water
1777  gsphe_lw = ( xvgran1-psnowgran1(jj,jst)<xvsphe4 .AND. psnowliq(jj,jst)/psnowdz(jj,jst)>xvtelv1 )
1778  END IF
1779  !
1780  ELSE
1781  !
1782  !non dendritic
1783  gnondendritic = ( psnowgran1(jj,jst)>=xvdiam6*(4.-psnowgran2(jj,jst))-xuepsi )
1784  IF ( gnondendritic ) THEN
1785  !faceted crystals
1786  gfaceted = ( psnowgran2(jj,jst)<xvsphe4/xvgran1 .AND. psnowhist(jj,jst)==0. )
1787  !spheric and liquid water
1788  gsphe_lw = ( xvsphe1-psnowgran2(jj,jst)<xvsphe4/xvgran1 .AND. psnowliq(jj,jst)/psnowdz(jj,jst)>xvtelv1 )
1789  END IF
1790  !
1791  ENDIF
1792  !
1793  IF ( gnondendritic ) THEN
1794  !
1795  IF ( gfaceted ) THEN
1796  !
1797  psnowhist(jj,jst) = nvhis1
1798  !
1799  ELSEIF ( gsphe_lw ) THEN
1800  !
1801  IF (psnowhist(jj,jst)==0.) psnowhist(jj,jst) = nvhis2
1802  IF (psnowhist(jj,jst)==nvhis1) psnowhist(jj,jst) = nvhis3
1803  !
1804  ELSEIF ( psnowtemp(jj,jst) < xtt ) THEN
1805  !
1806  IF(psnowhist(jj,jst)==nvhis2) psnowhist(jj,jst) = nvhis4
1807  IF(psnowhist(jj,jst)==nvhis3) psnowhist(jj,jst) = nvhis5
1808  !
1809  ENDIF
1810  !
1811  ENDIF
1812  !
1813  ENDDO
1814  !
1815 ENDDO
1816 !
1817 IF (lhook) CALL dr_hook('SNOWCROMETAMO',1,zhook_handle)
1818 !
1819 END SUBROUTINE snowcrometamo
1820 !
1821 !####################################################################
1822 !####################################################################
1823 SUBROUTINE set_thresh(PGRADT,PSNOWLIQ,PSPHE)
1824 !
1825 USE modd_snow_metamo, ONLY : xuepsi, xvgrat1
1826 !
1827 IMPLICIT NONE
1828 !
1829 REAL, INTENT(IN) :: pgradt
1830 REAL, INTENT(IN) :: psnowliq
1831 REAL, INTENT(INOUT) :: psphe
1832 !
1833 IF ( psnowliq>xuepsi .OR. pgradt<xvgrat1 ) THEN
1834  psphe = min(1.,psphe)
1835 ELSE
1836  psphe = max(0.,psphe)
1837 ENDIF
1838 !
1839 END SUBROUTINE set_thresh
1840 !####################################################################
1841 !####################################################################
1842 SUBROUTINE get_gran(PTSTEP,PTELM,PGRAN)
1843 !
1844 USE modd_csts, ONLY : xpi
1845 USE modd_snow_metamo, ONLY : xvtail1, xvtail2, nvdent1
1846 !
1847 IMPLICIT NONE
1848 !
1849 REAL, INTENT(IN) :: ptstep, ptelm
1850 REAL, INTENT(INOUT) :: pgran
1851 !
1852 REAL(KIND=JPRB) :: zhook_handle
1853 !
1854 IF (lhook) CALL dr_hook('SNOWCRO:GET_GRAN',0,zhook_handle)
1855 !
1856 pgran = 2. * ( 3./(4.*xpi) * &
1857  ( 4. * xpi/3. * (pgran/2.)**3 + &
1858  ( xvtail1 + xvtail2 * ptelm**nvdent1 ) * ptstep ) )**(1./3.)
1859 !
1860 IF (lhook) CALL dr_hook('SNOWCRO:GET_GRAN',1,zhook_handle)
1861 !
1862 END SUBROUTINE get_gran
1863 !
1864 !####################################################################
1865 !####################################################################
1866 !####################################################################
1867 !
1868 SUBROUTINE snowcroalb(TPTIME,OGLACIER, &
1869  palbedosc,pspectralalbedo,psnowdz, &
1870  psnowrho,ppermsnowfrac, &
1871  psnowgran1_top,psnowgran2_top,psnowage_top, &
1872  psnowgran1_bot,psnowgran2_bot,psnowage_bot, &
1873  pps, pzenith, knlvls_use ,hsnowmetamo )
1874 !
1875 !! PURPOSE
1876 !! -------
1877 ! Calculate the snow surface albedo. Use the method of original
1878 ! Crocus which considers a specified spectral distribution of solar
1879 ! solar radiation (to be replaced by an input forcing when available)
1880 ! In addition to original crocus, the top 2 surface snow layers are
1881 ! considered in the calculation, using an arbitrary weighting, in order
1882 ! to avoid time discontinuities due to layers agregation
1883 ! Ageing depends on the presence of permanent snow cover
1884 !
1885 USE modd_snow_par, ONLY : xansmax, xansmin,xaglamin, xaglamax, &
1886  xvrpre1,xvrpre2,xvaging_noglacier, &
1887  xvaging_glacier, xvspec1,xvspec2, &
1888  xvspec3, xvw1,xvw2,xvd1,xvd2
1889 
1890 USE modd_type_date_surf, ONLY : date_time
1891 !
1892 USE mode_snow3l
1893 !
1894 IMPLICIT NONE
1895 !
1896 !* 0.1 declarations of arguments
1897 !
1898 TYPE(date_time), INTENT(IN) :: tptime ! current date and time
1899 LOGICAL, INTENT(IN) :: oglacier ! True = Over permanent snow and ice,
1900 ! initialise WGI=WSAT,
1901 ! Hsnow>=10m and allow 0.8<SNOALB<0.85
1902  ! False = No specific treatment
1903 REAL, DIMENSION(:), INTENT(IN) :: psnowdz,ppermsnowfrac
1904 !
1905 REAL,DIMENSION(:,:), INTENT(IN) :: psnowrho ! For now only the 2 first layers are required
1906 !
1907 REAL, DIMENSION(:), INTENT(INOUT) :: palbedosc
1908 !
1909 REAL, DIMENSION(:,:), INTENT(OUT) :: pspectralalbedo ! Albedo in the different spectral bands
1910 !
1911 REAL, DIMENSION(:), INTENT(IN) :: psnowgran1_top,psnowgran2_top,psnowage_top, &
1912  psnowgran1_bot,psnowgran2_bot,psnowage_bot, pps
1913 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use
1914 !
1915 REAL, DIMENSION(:), INTENT(IN) :: pzenith ! solar zenith angle for future use
1916 !
1917  CHARACTER(3),INTENT(IN) :: hsnowmetamo ! metamorphism scheme
1918 !
1919 !* 0.2 declarations of local variables
1920 !
1921 REAL, DIMENSION(SIZE(PSNOWRHO,1),3) :: zalb_top, zalb_bot
1922 !
1923 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zansmin, zansmax, zmin, zmax
1924 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zfac_top, zfac_bot
1925 !
1926 REAL, DIMENSION(SIZE(PALBEDOSC)) :: zvage1
1927 !
1928 !REAL :: ZAGE_NOW
1929 !
1930 INTEGER :: jj ! looping indexes
1931 !
1932 REAL(KIND=JPRB) :: zhook_handle
1933 !-------------------------------------------------------------------------------
1934 !
1935 IF (lhook) CALL dr_hook('SNOWCROALB',0,zhook_handle)
1936 !
1937 ! 0. Initialize:
1938 ! ------------------
1939 !
1940 ! PRINT*,XVAGING_NOGLACIER,XVAGING_GLACIER
1941 IF ( oglacier ) THEN
1942  zansmin(:) = xaglamin * ppermsnowfrac(:) + xansmin * (1.0-ppermsnowfrac(:))
1943  zansmax(:) = xaglamax * ppermsnowfrac(:) + xansmax * (1.0-ppermsnowfrac(:))
1944  zvage1(:) = xvaging_glacier * ppermsnowfrac(:) + xvaging_noglacier * (1.0-ppermsnowfrac(:))
1945 ELSE
1946  zansmin(:) = xansmin
1947  zansmax(:) = xansmax
1948  zvage1(:) = xvaging_noglacier
1949 ENDIF
1950 !
1951 ! ! ! ! ! ! date computation for ageing effects
1952 ! ! ! ! ! CALL GREGODSTRATI(TPTIME%TDATE%YEAR,TPTIME%TDATE%MONTH,TPTIME%TDATE%DAY, &
1953 ! ! ! ! ! TPTIME%TIME,ZAGE_NOW)
1954 !
1955 ! coherence control
1956 ! to remove when initialization routines will be updated
1957 IF ( minval(psnowage_bot)<0. ) THEN
1958  CALL abor1_sfx('FATAL ERROR in SNOWCRO: Snow layer age inconsistent : check initialization routine. !')
1959 END IF
1960 !
1961 ! ! ! ! ! ! should be moved with other time controls to not compute MAXVAL(PSNOWAGE_TOP) at each time step
1962 ! ! ! ! ! IF ((ZAGE_NOW - MAXVAL(PSNOWAGE_TOP))<-0.001) THEN
1963 ! ! ! ! ! WRITE(*,*),"ZAGE_NOW=",ZAGE_NOW
1964 ! ! ! ! ! WRITE(*,*),"MAXVAL(PSNOWAGE_TOP)=",MAXVAL(PSNOWAGE_TOP)
1965 ! ! ! ! ! CALL ABOR1_SFX(&
1966 ! ! ! ! ! 'FATAL ERROR in SNOWCRO: Snow layer date inconsistent with the current day !')
1967 ! ! ! ! ! END IF
1968 !
1969 DO jj=1, SIZE(palbedosc)
1970  !
1971  IF ( knlvls_use(jj)==0 ) THEN
1972  ! case with no snow on the ground
1973  palbedosc(jj) = zansmin(jj)
1974  ELSE
1975  !
1976  CALL get_alb(jj,psnowrho(jj,1),pps(jj),zvage1(jj),psnowgran1_top(jj),&
1977  psnowgran2_top(jj),psnowage_top(jj),zalb_top(jj,:),hsnowmetamo)
1978  !
1979 ! IF (KNLVLS_USE(JJ)>=1) THEN
1980  IF ( knlvls_use(jj)>=2 ) THEN !modif ML
1981  ! second surface layer when it exists
1982  !
1983  CALL get_alb(jj,psnowrho(jj,2),pps(jj),zvage1(jj),psnowgran1_bot(jj),&
1984  psnowgran2_bot(jj),min(365.,psnowage_bot(jj)),zalb_bot(jj,:),hsnowmetamo)
1985  !
1986  ELSE
1987  ! when it does not exist, the second surface layer gets top layer albedo
1988  zalb_bot(jj,1) = zalb_top(jj,1)
1989  zalb_bot(jj,2) = zalb_top(jj,2)
1990  zalb_bot(jj,3) = zalb_top(jj,3)
1991  ENDIF
1992  !
1993  ! computation of spectral albedo over 3 bands taking into account the respective
1994  ! depths of top layers
1995  zmin(jj) = min( 1., psnowdz(jj)/xvd1 )
1996  zmax(jj) = max( 0., (psnowdz(jj)-xvd1)/xvd2 )
1997  zfac_top(jj) = xvw1 * zmin(jj) + xvw2 * min( 1., zmax(jj) )
1998  zfac_bot(jj) = xvw1 * ( 1. - zmin(jj) ) + xvw2 * ( 1. - min( 1., zmax(jj) ) )
1999  pspectralalbedo(jj,1) = zfac_top(jj) * zalb_top(jj,1) + zfac_bot(jj) * zalb_bot(jj,1)
2000  pspectralalbedo(jj,2) = zfac_top(jj) * zalb_top(jj,2) + zfac_bot(jj) * zalb_bot(jj,2)
2001  pspectralalbedo(jj,3) = zfac_top(jj) * zalb_top(jj,3) + zfac_bot(jj) * zalb_bot(jj,3)
2002  !
2003  ! arbitrarily specified spectral distribution
2004  ! to be changed when solar radiation distribution is an input variable
2005  palbedosc(jj) = xvspec1 * pspectralalbedo(jj,1) + &
2006  xvspec2 * pspectralalbedo(jj,2) + &
2007  xvspec3 * pspectralalbedo(jj,3)
2008  !
2009  ENDIF ! end case with snow on the ground
2010  !
2011 ENDDO ! end loop grid points
2012 !
2013 IF (lhook) CALL dr_hook('SNOWCROALB',1,zhook_handle)
2014 !-------------------------------------------------------------------------------
2015 !
2016 END SUBROUTINE snowcroalb
2017 !####################################################################
2018 SUBROUTINE get_alb(KJ,PSNOWRHO_IN,PPS_IN,PVAGE1,PSNOWGRAN1,PSNOWGRAN2,PSNOWAGE,PALB,&
2019  hsnowmetamo)
2020 !
2021 USE modd_snow_par, ONLY : xalbice1, xalbice2, xalbice3, &
2022  xrhothreshold_ice, &
2023  xvalb2, xvalb3, xvalb4, xvalb5, &
2024  xvalb6, xvalb7, xvalb8, xvalb9, &
2025  xvalb10, xvalb11, xvdiop1, &
2026  xvrpre1, xvrpre2, xvpres1
2027 !
2028 USE mode_snow3l, ONLY : get_diam
2029 !
2030 IMPLICIT NONE
2031 !
2032 INTEGER, INTENT(IN) :: kj
2033 REAL, INTENT(IN) :: psnowrho_in, pps_in
2034 REAL, INTENT(IN) :: pvage1
2035 REAL, INTENT(IN) :: psnowgran1, psnowgran2, psnowage
2036 REAL, DIMENSION(3), INTENT(OUT) :: palb
2037 !
2038  CHARACTER(3),INTENT(IN)::hsnowmetamo
2039 !
2040 REAL :: zdiam, zdiam_sqrt
2041 !
2042 REAL(KIND=JPRB) :: zhook_handle
2043 !
2044 IF (lhook) CALL dr_hook('SNOWCRO:GET_ALB',0,zhook_handle)
2045 !
2046 IF ( psnowrho_in<xrhothreshold_ice ) THEN
2047  ! Normal case (snow)
2048  CALL get_diam(psnowgran1,psnowgran2,zdiam,hsnowmetamo)
2049  zdiam_sqrt = sqrt(zdiam)
2050  palb(1) = min( xvalb2 - xvalb3*zdiam_sqrt, xvalb4 )
2051  palb(2) = max( 0.3, xvalb5 - xvalb6*zdiam_sqrt )
2052  zdiam = min( zdiam, xvdiop1 )
2053  zdiam_sqrt = sqrt(zdiam)
2054  palb(3) = max( 0., xvalb7*zdiam - xvalb8*zdiam_sqrt + xvalb9 )
2055  ! AGE CORRECTION ONLY FOR VISIBLE BAND
2056 
2057 ! ! ! ! ! PALB(1)=MAX(XVALB11,PALB(1)-MIN(MAX(PPS_IN/XVPRES1,XVRPRE1), &
2058 ! ! ! ! ! XVRPRE2)*XVALB10*MIN(365.,ZAGE_NOW-PSNOWAGE)/PVAGE1)
2059 
2060  palb(1) = max( xvalb11, palb(1) - min( max(pps_in/xvpres1,xvrpre1), xvrpre2 ) * &
2061  xvalb10 * psnowage / pvage1 )
2062 ELSE
2063  ! Prescribed spectral albedo for surface ice
2064  palb(1) = xalbice1
2065  palb(2) = xalbice2
2066  palb(3) = xalbice3
2067 ENDIF
2068 !
2069 IF (lhook) CALL dr_hook('SNOWCRO:GET_ALB',1,zhook_handle)
2070 !
2071 END SUBROUTINE get_alb
2072 !
2073 !####################################################################
2074 !####################################################################
2075 SUBROUTINE snowcrorad(TPTIME, OGLACIER, &
2076  psw_rad, psnowalb, psnowdz, &
2077  psnowrho, palb, pradsink, pradxs, &
2078  psnowgran1, psnowgran2, psnowage,pps, &
2079  pzenith, ppermsnowfrac,knlvls_use, &
2080  osnow_abs_zenith,hsnowmetamo)
2081 !
2082 !! PURPOSE
2083 !! -------
2084 ! Calculate the transmission of shortwave (solar) radiation
2085 ! through the snowpack (using a form of Beer's Law: exponential
2086 ! decay of radiation with increasing snow depth).
2087 ! Needs a first calculation of the albedo to stay coherent with
2088 ! ISBA-ES ==> make sure to keep SNOWCRORAD coherent with SNOWCROALB
2089 !
2090 USE modd_snow_par, ONLY : xwcrn, xansmax, xansmin, xans_todry, &
2091  xsnowdmin, xans_t, xaglamin, xaglamax, &
2092  xd1, xd2, xd3, xx, xvspec1, xvspec2, xvspec3, &
2093  xvbeta1, xvbeta2, xvbeta3, xvbeta4, xvbeta5
2094 USE modd_type_date_surf, ONLY : date_time
2095 !
2096 USE mode_snow3l, ONLY : get_diam
2097 !
2098 IMPLICIT NONE
2099 !
2100 !* 0.1 declarations of arguments
2101 !
2102 TYPE(date_time), INTENT(IN) :: tptime ! current date and time
2103 LOGICAL, INTENT(IN) :: oglacier ! True = Over permanent snow and ice,
2104 ! initialise WGI=WSAT,
2105 ! Hsnow>=10m and allow 0.8<SNOALB<0.85
2106  ! False = No specific treatment
2107 !
2108 REAL, DIMENSION(:), INTENT(IN) :: psw_rad, psnowalb, palb,ppermsnowfrac
2109 !
2110 REAL, DIMENSION(:,:), INTENT(IN) :: psnowrho, psnowdz
2111 !
2112 LOGICAL, INTENT(IN) :: osnow_abs_zenith ! parametrization for polar regions (not physic but better results)
2113 ! ! default FALSE
2114  CHARACTER(3), INTENT(IN) :: hsnowmetamo
2115 !
2116 REAL, DIMENSION(:), INTENT(OUT) :: pradxs
2117 !
2118 REAL, DIMENSION(:,:), INTENT(OUT) :: pradsink
2119 !
2120 REAL, DIMENSION(:,:), INTENT(IN) :: psnowgran1, psnowgran2, psnowage
2121 REAL, DIMENSION(:), INTENT(IN) :: pps
2122 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use
2123 REAL, DIMENSION(:), INTENT(IN) :: pzenith
2124 !
2125 !* 0.2 declarations of local variables
2126 !
2127 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zradtot
2128 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zalb_new
2129 REAL, DIMENSION(SIZE(PSNOWRHO,1),3) :: zalb !albedo 3 bands
2130 REAL, DIMENSION(SIZE(PSNOWRHO,2)) :: zdiam
2131 REAL, DIMENSION(SIZE(PSNOWRHO,2),3) :: zbeta
2132 REAL, DIMENSION(3) :: zopticalpath, zfact
2133 REAL :: zprojlat
2134 !
2135 INTEGER :: jj,jst,jb ! looping indexes
2136 !
2137 REAL(KIND=JPRB) :: zhook_handle
2138 !-------------------------------------------------------------------------------
2139 IF (lhook) CALL dr_hook('SNOWCRORAD',0,zhook_handle)
2140 !
2141 ! 0. Initialization:
2142 ! ------------------
2143 !
2144 pradsink(:,:) = 0.
2145 !
2146 ! 1. Computation of the new albedo (see SNOWCROALB):
2147 ! -----------------------------------
2148 !
2149  CALL snowcroalb(tptime,oglacier, &
2150  zalb_new,zalb,psnowdz(:,1),psnowrho(:,1:2), &
2151  ppermsnowfrac,psnowgran1(:,1),psnowgran2(:,1), &
2152  psnowage(:,1),psnowgran1(:,2),psnowgran2(:,2),psnowage(:,2), &
2153  pps, pzenith, knlvls_use, hsnowmetamo )
2154 !
2155 DO jj = 1,SIZE(psw_rad)
2156  !
2157  DO jst = 1,knlvls_use(jj)
2158  CALL get_diam(psnowgran1(jj,jst),psnowgran2(jj,jst),zdiam(jst),hsnowmetamo)
2159  ENDDO ! end loop snow layers
2160  !
2161  ! 2. Extinction of net shortwave radiation
2162  ! ----------------------------------------
2163  ! First calculates extinction coefficients fn of grain size and density
2164  ! then calculates exctinction in the layer and increases optical path length
2165  !
2166  ! Coefficient for taking into account the increase of path length of rays
2167  ! in snow due to zenithal angle
2168  zprojlat = 1. / max( xuepsi, cos(pzenith(jj)) )
2169  !
2170  pradsink(jj,:) = -psw_rad(jj) * ( 1.-psnowalb(jj) ) / ( 1.-zalb_new(jj) )
2171  !
2172  ! Initialize optical depth
2173  zopticalpath(1) = 0.
2174  zopticalpath(2) = 0.
2175  zopticalpath(3) = 0.
2176  !
2177  DO jst = 1,knlvls_use(jj)
2178  !
2179  zbeta(jst,1) = max( xvbeta1 * psnowrho(jj,jst) / sqrt(zdiam(jst)), xvbeta2 )
2180  zbeta(jst,2) = max( xvbeta3 * psnowrho(jj,jst) / sqrt(zdiam(jst)), xvbeta4 )
2181  zbeta(jst,3) = xvbeta5
2182  !
2183  zfact(:) = 0.
2184  DO jb = 1,3
2185  zopticalpath(jb) = zopticalpath(jb) + zbeta(jst,jb) * psnowdz(jj,jst)
2186  IF (osnow_abs_zenith) THEN
2187  !This formulation is incorrect but it compensate partly the fact that the albedo formulation does not account for zenithal angle
2188  zfact(jb) = (1.-zalb(jj,jb)) * exp( -zopticalpath(jb)*zprojlat)
2189  ELSE
2190  zfact(jb) = (1.-zalb(jj,jb)) * exp( -zopticalpath(jb) )
2191  ENDIF
2192  ENDDO
2193  !
2194  pradsink(jj,jst) = pradsink(jj,jst) * &
2195  ( xvspec1*zfact(1) + xvspec2*zfact(2) + xvspec3*zfact(3) )
2196  !
2197  ENDDO ! end loop snow layers
2198  !
2199  ! For thin snow packs, radiation might reach base of
2200  ! snowpack and the reflected energy can be absorbed by the bottom of snow layer:
2201  ! THIS PROCESS IS NOT SIMULATED
2202  !
2203  ! 4. Excess radiation not absorbed by snowpack (W/m2)JJ
2204  ! ----------------------------------------------------
2205  !
2206  pradxs(jj) = -pradsink( jj,knlvls_use(jj) )
2207  !
2208 ENDDO !end loop grid points
2209 !
2210 IF (lhook) CALL dr_hook('SNOWCRORAD',1,zhook_handle)
2211 !-------------------------------------------------------------------------------
2212 !
2213 END SUBROUTINE snowcrorad
2214 !####################################################################
2215 !####################################################################
2216 !####################################################################
2217 SUBROUTINE snowcrothrm(PSNOWRHO,PSCOND,PSNOWTEMP,PPS,PSNOWLIQ, &
2218  ocond_grain,ocond_yen )
2219 !
2220 !! PURPOSE
2221 !! -------
2222 ! Calculate snow thermal conductivity from
2223 ! Sun et al. 1999, J. of Geophys. Res., 104, 19587-19579
2224 ! (vapor) and Anderson, 1976, NOAA Tech. Rep. NWS 19 (snow).
2225 !
2226 ! Upon activation of flag OCOND_YEN, use the Yen (1981) formula for thermal conductivity
2227 ! This formula was originally used in Crocus.
2228 !
2229 USE modd_csts, ONLY : xp00, xcondi, xrholw
2230 USE modd_snow_par, ONLY : xsnowthrmcond1, xsnowthrmcond2, xsnowthrmcond_avap, &
2231  xsnowthrmcond_bvap, xsnowthrmcond_cvap, xvrkz6
2232 !
2233 IMPLICIT NONE
2234 !
2235 !* 0.1 declarations of arguments
2236 !
2237 REAL, DIMENSION(:), INTENT(IN) :: pps
2238 REAL, DIMENSION(:,:), INTENT(IN) :: psnowtemp, psnowrho, psnowliq
2239 REAL, DIMENSION(:,:), INTENT(OUT) :: pscond
2240 LOGICAL, INTENT(IN) :: ocond_grain, ocond_yen
2241 !
2242 !* 0.2 declarations of local variables
2243 !
2244 INTEGER :: jj, jst ! looping indexes
2245 !
2246 REAL(KIND=JPRB) :: zhook_handle
2247 !-------------------------------------------------------------------------------
2248 IF (lhook) CALL dr_hook('SNOWCROTHRM',0,zhook_handle)
2249 !
2250 ! 1. Snow thermal conductivity
2251 ! ----------------------------
2252 !
2253 DO jst = 1,SIZE(psnowrho(:,:),2)
2254  !
2255  DO jj = 1,SIZE(psnowrho(:,:),1)
2256  !
2257  IF ( ocond_yen ) THEN
2258  pscond(jj,jst) = xcondi * exp( xvrkz6 * log( psnowrho(jj,jst)/xrholw ) )
2259  ELSE
2260  pscond(jj,jst) = ( xsnowthrmcond1 + &
2261  xsnowthrmcond2 * psnowrho(jj,jst) * psnowrho(jj,jst) ) + &
2262  max( 0.0, ( xsnowthrmcond_avap + &
2263  ( xsnowthrmcond_bvap/(psnowtemp(jj,jst) + xsnowthrmcond_cvap) ) ) &
2264  * (xp00/pps(jj)) )
2265  ENDIF
2266  !
2267  ! Snow thermal conductivity is set to be above 0.04 W m-1 K-1
2268  IF ( ocond_grain ) THEN
2269  pscond(jj,jst) = max( 0.04, pscond(jj,jst) )
2270  ! Snow thermal conductivity is annihilated in presence of liquid water
2271  IF( psnowliq(jj,jst)>xuepsi ) pscond(jj,jst) = 0.01 * pscond(jj,jst)
2272  ENDIF
2273  !
2274  ENDDO ! end loop JST
2275  !
2276 ENDDO ! end loop JST
2277 !
2278 IF (lhook) CALL dr_hook('SNOWCROTHRM',1,zhook_handle)
2279 !
2280 END SUBROUTINE snowcrothrm
2281 !####################################################################
2282 !####################################################################
2283 !####################################################################
2284 SUBROUTINE snowcroebud(HSNOWRES, HIMPLICIT_WIND, &
2285  ppew_a_coef, ppew_b_coef, &
2286  ppet_a_coef, ppeq_a_coef, ppet_b_coef, ppeq_b_coef, &
2287  psnowdzmin, &
2288  pzref,pts,psnowrho,psnowliq,pscap,pscond1,pscond2, &
2289  puref,pexns,pexna,pdircoszw,pvmod, &
2290  plw_rad,psw_rad,pta,pqa,pps,ptstep, &
2291  psnowdz1,psnowdz2,palbt,pz0,pz0eff,pz0h, &
2292  psfcfrz,pradsink,phpsnow, &
2293  pct,pemist,prhoa,ptsterm1,ptsterm2,pra,pcdsnow,pchsnow, &
2294  pqsat,pdqsat,prsra,pustar2_ic, pri, &
2295  ppet_a_coef_t,ppeq_a_coef_t,ppet_b_coef_t,ppeq_b_coef_t )
2296 !
2297 !! PURPOSE
2298 !! -------
2299 ! Calculate surface energy budget linearization (terms) and turbulent
2300 ! exchange coefficients/resistance between surface and atmosphere.
2301 ! (Noilhan and Planton 1989; Giordani 1993; Noilhan and Mahfouf 1996)
2302 !
2303 !! MODIFICATIONS
2304 !! -------------
2305 !! Original A. Boone
2306 !! Modified by E. Brun (24/09/2012) :
2307 !! * Correction coupling coefficient for specific humidity in SNOWCROEBUD
2308 !! * PSFCFRZ(:) = 1.0 for systematic solid/vapor latent fluxes in SNOWCROEBUD
2309 !! Modified by B. Decharme 09/12 new wind implicitation
2310 !
2311 USE modd_surf_par, ONLY : xundef
2312 USE modd_csts, ONLY : xcpd, xrholw, xstefan, xlvtt, xlstt, xrholw
2313 USE modd_snow_par, ONLY : x_ri_max, xemissn
2314 !
2315 USE mode_thermos
2316 !
2317 USE modi_surface_ri
2318 USE modi_surface_aero_cond
2319 USE modi_surface_cd
2320 !
2321 IMPLICIT NONE
2322 !
2323 !* 0.1 declarations of arguments
2324 !
2325 REAL, INTENT(IN) :: ptstep, psnowdzmin
2326 !
2327  CHARACTER(LEN=*), INTENT(IN) :: hsnowres ! type of sfc resistance
2328 ! DEFAULT=Louis (1979), standard ISBA
2329 ! method. Option to limit Ri number
2330 ! for very stable conditions
2331 !
2332  CHARACTER(LEN=*), INTENT(IN) :: himplicit_wind ! wind implicitation option
2333 ! ! 'OLD' = direct
2334 ! ! 'NEW' = Taylor serie, order 1
2335 !
2336 REAL, DIMENSION(:), INTENT(IN) :: ppew_a_coef, ppew_b_coef, &
2337  ppet_a_coef, ppeq_a_coef, ppet_b_coef, &
2338  ppeq_b_coef
2339 ! PPEW_A_COEF = wind coefficient (m2s/kg)
2340 ! PPEW_B_COEF = wind coefficient (m/s)
2341 ! PPET_A_COEF = A-air temperature coefficient
2342 ! PPET_B_COEF = B-air temperature coefficient
2343 ! PPEQ_A_COEF = A-air specific humidity coefficient
2344 ! PPEQ_B_COEF = B-air specific humidity coefficient
2345 !
2346 REAL, DIMENSION(:), INTENT(IN) :: pzref, pts, psnowdz1, psnowdz2, &
2347  pradsink, psnowrho, psnowliq, pscap, &
2348  pscond1, pscond2, &
2349  pz0, phpsnow, &
2350  palbt, pz0eff, pz0h
2351 !
2352 REAL, DIMENSION(:), INTENT(IN) :: psw_rad, plw_rad, pta, pqa, pps, prhoa
2353 !
2354 REAL, DIMENSION(:), INTENT(IN) :: puref, pexns, pexna, pdircoszw, pvmod
2355 !
2356 REAL, DIMENSION(:), INTENT(OUT) :: ptsterm1, ptsterm2, pemist, pra, &
2357  pct, psfcfrz, pcdsnow, pchsnow, &
2358  pqsat, pdqsat, prsra
2359 !
2360 REAL, DIMENSION(:), INTENT(OUT) :: pustar2_ic, &
2361  ppet_a_coef_t, ppeq_a_coef_t, &
2362  ppet_b_coef_t, ppeq_b_coef_t
2363 !
2364 REAL, DIMENSION(:), INTENT(OUT) :: pri
2365 !
2366 !* 0.2 declarations of local variables
2367 !
2368 REAL, DIMENSION(SIZE(PTS)) :: zac, zri, &
2369  zsconda, za, zb, zc, &
2370  zcdn, zsnowdzm1, zsnowdzm2, &
2371  zvmod, zustar2, zts3, zlvt, &
2372  z_ccoef
2373 REAL, DIMENSION(SIZE(PTS)) :: zsnowevapx, zdenom, znumer
2374 !
2375 INTEGER :: jj ! looping indexes
2376 !
2377 REAL(KIND=JPRB) :: zhook_handle
2378 !-------------------------------------------------------------------------------
2379 !
2380 ! 1. New saturated specific humidity and derrivative:
2381 ! ---------------------------------------------------
2382 !
2383 IF (lhook) CALL dr_hook('SNOWCROEBUD',0,zhook_handle)
2384 !
2385 zri(:) = xundef
2386 !
2387 pqsat(:) = qsati(pts(:),pps(:))
2388 pdqsat(:) = dqsati(pts(:),pps(:),pqsat(:))
2389 !
2390 ! 2. Surface properties:
2391 ! ----------------------
2392 ! It might be of interest to use snow-specific roughness
2393 ! or a temperature dependence on emissivity:
2394 ! but for now, use ISBA defaults.
2395 !
2396 pemist(:) = xemissn
2397 !
2398 ! 2. Computation of resistance and drag coefficient
2399 ! -------------------------------------------------
2400 !
2401  CALL surface_ri(pts, pqsat, pexns, pexna, pta, pqa, &
2402  pzref, puref, pdircoszw, pvmod, zri )
2403 !
2404 ! Simple adaptation of method by Martin and Lejeune (1998)
2405 ! to apply a lower limit to turbulent transfer coef
2406 ! by defining a maximum Richarson number for stable
2407 ! conditions:
2408 !
2409 IF ( hsnowres=='RIL' ) THEN
2410  DO jj=1,SIZE(zri)
2411  zri(jj) = min( x_ri_max, zri(jj) )
2412  ENDDO
2413 ENDIF
2414 !
2415 pri(:) = zri(:)
2416 !
2417 ! Surface aerodynamic resistance for heat transfers
2418 !
2419  CALL surface_aero_cond(zri, pzref, puref, pvmod, pz0, pz0h, zac, pra, pchsnow)
2420 !
2421 prsra(:) = prhoa(:) / pra(:)
2422 !
2423 ! For atmospheric model coupling:
2424 !
2425  CALL surface_cd(zri, pzref, puref, pz0eff, pz0h, pcdsnow, zcdn)
2426 !
2427 !
2428 ! Modify flux-form implicit coupling coefficients:
2429 ! - wind components:
2430 !
2431 znumer(:) = pcdsnow(:)*pvmod(:)
2432 zdenom(:) = prhoa(:) * pcdsnow(:) * pvmod(:) * ppew_a_coef(:)
2433 IF(himplicit_wind=='OLD')THEN
2434 ! old implicitation
2435  zustar2(:) = ( znumer(:) * ppew_b_coef(:) ) / ( 1.0 - zdenom(:) )
2436 ELSE
2437 ! new implicitation
2438  zustar2(:) = ( znumer(:) * ( 2.*ppew_b_coef(:) - pvmod(:) ) ) / ( 1.0 - 2.0*zdenom(:) )
2439 ENDIF
2440 !
2441 zvmod(:) = prhoa(:)*ppew_a_coef(:)*zustar2(:) + ppew_b_coef(:)
2442 zvmod(:) = max( zvmod(:),0. )
2443 !
2444 WHERE ( ppew_a_coef(:)/= 0. )
2445  zustar2(:) = max( ( zvmod(:) - ppew_b_coef(:) ) / (prhoa(:)*ppew_a_coef(:)), 0. )
2446 ENDWHERE
2447 !
2448 ! implicit wind friction
2449 zustar2(:) = max( zustar2(:),0. )
2450 !
2451 pustar2_ic(:) = zustar2(:)
2452 !
2453 ! 3. Calculate linearized surface energy budget components:
2454 ! ---------------------------------------------------------
2455 ! To prevent numerical difficulties for very thin snow
2456 ! layers, limit the grid "thinness": this is important as
2457 ! layers become vanishing thin:
2458 !
2459 zsnowdzm1(:) = max( psnowdz1(:), psnowdzmin )
2460 zsnowdzm2(:) = max( psnowdz2(:), psnowdzmin )
2461 !
2462 ! Surface thermal inertia:
2463 !
2464 pct(:) = 1.0 / ( pscap(:)*zsnowdzm1(:) )
2465 !
2466 ! Fraction of surface frozen (sublimation) with the remaining
2467 ! fraction being liquid (evaporation):
2468 !
2469 psfcfrz(:) = 1.0
2470 !
2471 ! Thermal conductivity between uppermost and lower snow layers:
2472 !
2473 zsconda(:) = ( zsnowdzm1(:)*pscond1(:) + zsnowdzm2(:)*pscond2(:) ) / &
2474  ( zsnowdzm1(:) + zsnowdzm2(:) )
2475 !
2476 ! Transform implicit coupling coefficients:
2477 ! Note, surface humidity is 100% over snow.
2478 !
2479 ! - specific humidity:
2480 !
2481 z_ccoef(:) = 1.0 - ppeq_a_coef(:) * prsra(:)
2482 !
2483 ppeq_a_coef_t(:) = - ppeq_a_coef(:) * prsra(:) * pdqsat(:) / z_ccoef(:)
2484 !
2485 ppeq_b_coef_t(:) = ( ppeq_b_coef(:) &
2486  - ppeq_a_coef(:) * prsra(:) * (pqsat(:) - pdqsat(:)*pts(:)) ) / z_ccoef(:)
2487 !
2488 ! - air temperature:
2489 ! (assumes A and B correspond to potential T):
2490 !
2491 z_ccoef(:) = ( 1.0 - ppet_a_coef(:) * prsra(:) ) / pexna(:)
2492 !
2493 ppet_a_coef_t(:) = - ppet_a_coef(:) * prsra(:) / ( pexns(:) * z_ccoef(:) )
2494 !
2495 ppet_b_coef_t(:) = ppet_b_coef(:) / z_ccoef(:)
2496 !
2497 !
2498 ! Energy budget solution terms:
2499 !
2500 zts3(:) = pemist(:) * xstefan * pts(:)**3
2501 zlvt(:) = (1.-psfcfrz(:))*xlvtt + psfcfrz(:)*xlstt
2502 !
2503 za(:) = 1./ptstep + pct(:) * &
2504  ( 4. * zts3(:) + prsra(:) * zlvt(:) * ( pdqsat(:) - ppeq_a_coef_t(:) ) &
2505  + prsra(:) * xcpd * ( (1./pexns(:))-(ppet_a_coef_t(:)/pexna(:)) ) &
2506  + ( 2*zsconda(:) / ( zsnowdzm2(:)+zsnowdzm1(:) ) ) )
2507 !
2508 zb(:) = 1./ptstep + pct(:) * &
2509  ( 3. * zts3(:) + prsra(:) * zlvt(:) * pdqsat(:) )
2510 !
2511 zc(:) = pct(:) * ( - prsra(:) * zlvt(:) * ( pqsat(:) - ppeq_b_coef_t(:) ) &
2512  + prsra(:) * xcpd * ppet_b_coef_t(:) / pexna(:) &
2513  + psw_rad(:) * (1. - palbt(:)) + pemist(:) * plw_rad(:) &
2514  + phpsnow(:) + pradsink(:) )
2515 !
2516 !
2517 ! Coefficients needed for implicit solution
2518 ! of linearized surface energy budget:
2519 !
2520 ptsterm2(:) = 2. * zsconda(:) * pct(:) / ( za(:) * (zsnowdzm2(:)+zsnowdzm1(:) ) )
2521 !
2522 ptsterm1(:) = ( pts(:)*zb(:) + zc(:) ) / za(:)
2523 !
2524 IF (lhook) CALL dr_hook('SNOWCROEBUD',1,zhook_handle)
2525 !
2526 END SUBROUTINE snowcroebud
2527 !####################################################################
2528 !####################################################################
2529 !####################################################################
2530 SUBROUTINE snowcrosolvt(PTSTEP,PSNOWDZMIN, &
2531  psnowdz,pscond,pscap,ptg, &
2532  psoilcond,pd_g, &
2533  pradsink,pct,pterm1,pterm2, &
2534  ppet_a_coef_t,ppeq_a_coef_t, &
2535  ppet_b_coef_t,ppeq_b_coef_t, &
2536  pta_ic, pqa_ic, &
2537  pgbas,psnowtemp,psnowflux, &
2538  knlvls_use )
2539 !
2540 !! PURPOSE
2541 !! -------
2542 ! This subroutine solves the 1-d diffusion of 'ZSNOWTEMP' using a
2543 ! layer averaged set of equations which are time differenced
2544 ! using the backward-difference scheme (implicit).
2545 ! The eqs are solved rapidly by taking advantage of the
2546 ! fact that the matrix is tridiagonal. This is a very
2547 ! general routine and can be used for the 1-d diffusion of any
2548 ! quantity as long as the diffusity is not a function of the
2549 ! quantity being diffused. Aaron Boone 8-98. Soln to the eq:
2550 !
2551 ! c dQ d k dQ dS
2552 ! -- = -- -- - --
2553 ! dt dx dx dx
2554 !
2555 ! where k = k(x) (thermal conductivity), c = c(x) (heat capacity)
2556 ! as an eg. for temperature/heat eq. S is a sink (-source) term.
2557 ! Diffusivity is k/c
2558 !
2559 !! MODIFICATIONS
2560 !! -------------
2561 !! Original A. Boone
2562 !! 05/2011: Brun Special treatment to tackle the variable number
2563 !! of snow layers
2564 !
2565 USE modd_csts, ONLY : xtt
2566 !
2568 !
2569 IMPLICIT NONE
2570 !
2571 !* 0.1 declarations of arguments
2572 !
2573 REAL, INTENT(IN) :: ptstep, psnowdzmin
2574 !
2575 REAL, DIMENSION(:), INTENT(IN) :: ptg, psoilcond, pd_g, &
2576  pct, pterm1, pterm2
2577 
2578 !
2579 REAL, DIMENSION(:,:), INTENT(IN) :: psnowdz, pscond, pscap, &
2580  pradsink
2581 !
2582 REAL, DIMENSION(:), INTENT(IN) :: ppet_a_coef_t, ppeq_a_coef_t, &
2583  ppet_b_coef_t, ppeq_b_coef_t
2584 !
2585 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowtemp
2586 !
2587 REAL, DIMENSION(:), INTENT(OUT) :: pgbas, psnowflux, pta_ic, pqa_ic
2588 !
2589 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use
2590 !
2591 !* 0.2 declarations of local variables
2592 !
2593 REAL, DIMENSION(SIZE(PSNOWDZ,1),SIZE(PSNOWDZ,2)) :: zsnowtemp, zdterm, zcterm, &
2594  zfrcv, zamtrx, zbmtrx, &
2595  zcmtrx
2596 !
2597 REAL, DIMENSION(SIZE(PSNOWDZ,1),SIZE(PSNOWDZ,2)) :: zwork1, zwork2, zdzdif, &
2598  zsnowdzm
2599 !
2600 REAL, DIMENSION(SIZE(PSNOWDZ,1),SIZE(PSNOWDZ,2)-1) :: zsnowtemp_m, &
2601  zfrcv_m, zamtrx_m, &
2602  zbmtrx_m, zcmtrx_m
2603 !
2604 REAL, DIMENSION(SIZE(PTG)) :: zgbas, zsnowtemp_delta
2605 !
2606 INTEGER :: jj, jst ! looping indexes
2607 INTEGER :: inlvls
2608 !
2609 REAL(KIND=JPRB) :: zhook_handle
2610 !-------------------------------------------------------------------------------
2611 IF (lhook) CALL dr_hook('SNOWCROSOLVT',0,zhook_handle)
2612 !
2613 ! 0. Initialize:
2614 ! ------------------
2615 !
2616 zsnowtemp(:,:) = psnowtemp(:,:)
2617 inlvls = SIZE(psnowdz(:,:),2)
2618 !
2619 ! 1. Calculate tri-diagnoal matrix coefficients:
2620 ! ----------------------------------------------
2621 ! For heat transfer, assume a minimum grid
2622 ! thickness (to prevent numerical
2623 ! problems for very thin snow cover):
2624 !
2625 DO jj=1,SIZE(ptg)
2626  !
2627  DO jst = knlvls_use(jj),1,-1
2628  !
2629  zsnowdzm(jj,jst) = max( psnowdz(jj,jst), psnowdzmin )
2630  !
2631  zwork1(jj,jst) = zsnowdzm(jj,jst) * pscond(jj,jst)
2632  !
2633  IF ( jst<knlvls_use(jj) ) THEN
2634  !
2635  zdzdif(jj,jst) = zsnowdzm(jj,jst) + zsnowdzm(jj,jst+1)
2636  !
2637  zwork2(jj,jst) = zsnowdzm(jj,jst+1) * pscond(jj,jst+1)
2638  !
2639  ELSE
2640  !
2641  zdzdif(jj,jst) = zsnowdzm(jj,jst) + pd_g(jj)
2642  !
2643  zwork2(jj,jst) = pd_g(jj) * psoilcond(jj)
2644  !
2645  ENDIF
2646  !
2647  zdterm(jj,jst) = 2.0 * ( zwork1(jj,jst) + zwork2(jj,jst) ) / zdzdif(jj,jst)**2
2648  !
2649  zcterm(jj,jst) = pscap(jj,jst) * zsnowdzm(jj,jst) / ptstep
2650  !
2651  ENDDO
2652  !
2653 ENDDO
2654 !
2655 ! 2. Set up tri-diagonal matrix
2656 ! -----------------------------
2657 !
2658 zamtrx(:,:) = 0.
2659 zbmtrx(:,:) = 0.
2660 zcmtrx(:,:) = 0.
2661 zfrcv(:,:) = 0.
2662 ! Upper BC
2663 !
2664 zamtrx(:,1) = 0.0
2665 zbmtrx(:,1) = 1. / ( pct(:)*ptstep )
2666 zcmtrx(:,1) = - pterm2(:) * zbmtrx(:,1)
2667 zfrcv(:,1) = pterm1(:) * zbmtrx(:,1)
2668 !
2669 DO jj = 1,SIZE(ptg)
2670  !
2671  DO jst = 2,knlvls_use(jj)
2672  !
2673  ! Interior Grid & Lower BC
2674  zamtrx(jj,jst) = -zdterm(jj,jst-1)
2675  zbmtrx(jj,jst) = zcterm(jj,jst) + zdterm(jj,jst-1) + zdterm(jj,jst)
2676  zfrcv(jj,jst) = zcterm(jj,jst)*psnowtemp(jj,jst) - (pradsink(jj,jst-1)-pradsink(jj,jst))
2677  !
2678  IF ( jst<knlvls_use(jj) ) THEN
2679  zcmtrx(jj,jst) = -zdterm(jj,jst)
2680  ELSE
2681  zcmtrx(jj,jst) = 0.0
2682  zfrcv(jj,jst) = zfrcv(jj,jst) + zdterm(jj,jst)*ptg(jj)
2683  ENDIF
2684  !
2685  ENDDO
2686  !
2687 ENDDO
2688 !
2689 ! 4. Compute solution vector
2690 ! --------------------------
2691 !
2692  CALL tridiag_ground_snowcro(zamtrx,zbmtrx,zcmtrx,zfrcv,zsnowtemp,knlvls_use,0)
2693 !
2694 ! Heat flux between surface and 2nd snow layers: (W/m2)
2695 !
2696 psnowflux(:) = zdterm(:,1) * ( zsnowtemp(:,1) - zsnowtemp(:,2) )
2697 !
2698 ! 5. Snow melt case
2699 ! -----------------
2700 ! If melting in uppermost layer, assume surface layer
2701 ! temperature at freezing point and re-evaluate lower
2702 ! snowpack temperatures. This is done as it is most likely
2703 ! most signigant melting will occur within a time step in surface layer.
2704 ! Surface energy budget (and fluxes) will
2705 ! be re-calculated (outside of this routine):
2706 !
2707 zamtrx_m(:,1) = 0.0
2708 zbmtrx_m(:,1) = zcterm(:,2) + zdterm(:,1) + zdterm(:,2)
2709 zcmtrx_m(:,1) = -zdterm(:,2)
2710 zfrcv_m(:,1) = zcterm(:,2)*psnowtemp(:,2) - (pradsink(:,1)-pradsink(:,2)) + zdterm(:,1)*xtt
2711 !
2712 DO jj = 1,SIZE(ptg)
2713  DO jst = 2,knlvls_use(jj)-1
2714  zamtrx_m(jj,jst) = zamtrx(jj,jst+1)
2715  zbmtrx_m(jj,jst) = zbmtrx(jj,jst+1)
2716  zcmtrx_m(jj,jst) = zcmtrx(jj,jst+1)
2717  zfrcv_m(jj,jst) = zfrcv(jj,jst+1)
2718  zsnowtemp_m(jj,jst) = psnowtemp(jj,jst+1)
2719  ENDDO
2720 ENDDO
2721 !
2722  CALL tridiag_ground_snowcro(zamtrx_m,zbmtrx_m,zcmtrx_m,zfrcv_m,zsnowtemp_m,knlvls_use,1)
2723 !
2724 ! If melting for 2 consecuative time steps, then replace current T-profile
2725 ! with one assuming T=Tf in surface layer:
2726 !
2727 zsnowtemp_delta(:) = 0.0
2728 !
2729 WHERE( zsnowtemp(:,1)>xtt .AND. psnowtemp(:,1)>=xtt )
2730  psnowflux(:) = zdterm(:,1) * ( xtt-zsnowtemp_m(:,1) )
2731  zsnowtemp_delta(:) = 1.0
2732 END WHERE
2733 !
2734 DO jj = 1,SIZE(ptg)
2735  DO jst = 2,knlvls_use(jj)
2736  zsnowtemp(jj,jst) = zsnowtemp_delta(jj) * zsnowtemp_m(jj,jst-1) + &
2737  (1.0-zsnowtemp_delta(jj)) * zsnowtemp(jj,jst)
2738  ENDDO
2739 ENDDO
2740 !
2741 ! 6. Lower boundary flux:
2742 ! -----------------------
2743 ! NOTE: evaluate this term assuming the snow layer
2744 ! can't exceed the freezing point as this adjustment
2745 ! is made in melting routine. Then must adjust temperature
2746 ! to conserve energy:
2747 !
2748 DO jj=1, SIZE(ptg)
2749  zgbas(jj) = zdterm(jj,knlvls_use(jj)) * ( zsnowtemp(jj,knlvls_use(jj)) - ptg(jj) )
2750  pgbas(jj) = zdterm(jj,knlvls_use(jj)) * ( min( xtt, zsnowtemp(jj,knlvls_use(jj)) ) - ptg(jj) )
2751  zsnowtemp(jj,knlvls_use(jj)) = zsnowtemp(jj,knlvls_use(jj)) + &
2752  ( zgbas(jj)-pgbas(jj) ) / zcterm(jj,knlvls_use(jj))
2753 ENDDO
2754 !
2755 ! 7. Update temperatute profile in time:
2756 ! --------------------------------------
2757 !
2758 DO jj=1, SIZE(ptg)
2759  psnowtemp(jj,1:knlvls_use(jj)) = zsnowtemp(jj,1:knlvls_use(jj))
2760 ENDDO
2761 !
2762 !
2763 ! 8. Compute new (implicit) air T and specific humidity
2764 ! -----------------------------------------------------
2765 !
2766 pta_ic(:) = ppet_b_coef_t(:) + ppet_a_coef_t(:) * psnowtemp(:,1)
2767 !
2768 pqa_ic(:) = ppeq_b_coef_t(:) + ppeq_a_coef_t(:) * psnowtemp(:,1)
2769 !
2770 IF (lhook) CALL dr_hook('SNOWCROSOLVT',1,zhook_handle)
2771 !
2772 END SUBROUTINE snowcrosolvt
2773 !####################################################################
2774 !####################################################################
2775 !####################################################################
2776 SUBROUTINE snowcromelt(PSCAP,PSNOWTEMP,PSNOWDZ, &
2777  psnowrho,psnowliq,knlvls_use )
2778 !
2779 !! PURPOSE
2780 !! -------
2781 ! Calculate snow melt (resulting from surface fluxes, ground fluxes,
2782 ! or internal shortwave radiation absorbtion). It is used to
2783 ! augment liquid water content, maintain temperatures
2784 ! at or below freezing, and possibly reduce the mass
2785 ! or compact the layer(s).
2786 !
2787 USE modd_csts,ONLY : xtt, xlmtt, xrholw, xrholi
2788 !
2789 USE mode_snow3l
2790 !
2791 IMPLICIT NONE
2792 !
2793 !* 0.1 declarations of arguments
2794 !
2795 REAL, DIMENSION(:,:), INTENT(IN) :: pscap
2796 !
2797 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowdz, psnowtemp, psnowrho, &
2798  psnowliq
2799 !
2800 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use
2801 !
2802 !* 0.2 declarations of local variables
2803 !
2804 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zphase, zcmprsfact, &
2805  zsnowlwe, &
2806  zsnowmelt, zsnowtemp
2807 !
2808 INTEGER :: jj, jst ! looping indexes
2809 !
2810 REAL(KIND=JPRB) :: zhook_handle
2811 !-------------------------------------------------------------------------------
2812 IF (lhook) CALL dr_hook('SNOWCROMELT',0,zhook_handle)
2813 !
2814 ! 0. Initialize:
2815 ! ---------------------------
2816 !
2817 DO jj = 1,SIZE(psnowdz,1)
2818  DO jst = 1,knlvls_use(jj)
2819  zphase(jj,jst) = 0.0
2820  zcmprsfact(jj,jst) = 0.0
2821  zsnowlwe(jj,jst) = 0.0
2822  zsnowmelt(jj,jst) = 0.0
2823  zsnowtemp(jj,jst) = 0.0
2824  ENDDO
2825 ENDDO
2826 !
2827 ! 1. Determine amount of melt in each layer:
2828 ! ------------------------------------------
2829 !
2830 DO jj = 1,SIZE(psnowdz,1)
2831  !
2832  DO jst = 1,knlvls_use(jj)
2833  !
2834  ! total liquid equivalent water content of snow(m):
2835  zsnowlwe(jj,jst) = psnowrho(jj,jst) * psnowdz(jj,jst) / xrholw
2836  !
2837  ! melt snow if excess energy and snow available:
2838  ! phase change(j/m2)
2839  zphase(jj,jst) = min( pscap(jj,jst) * max(0.0,psnowtemp(jj,jst)-xtt) * psnowdz(jj,jst), &
2840  max(0.0,zsnowlwe(jj,jst)-psnowliq(jj,jst)) * xlmtt * xrholw )
2841  !
2842  ! update snow liq water content and temperature if melting:
2843  ! liquid water available for next layer from melting of snow
2844  ! which is assumed to be leaving the current layer(m):
2845  zsnowmelt(jj,jst) = zphase(jj,jst) / (xlmtt*xrholw)
2846  !
2847  ! cool off snow layer temperature due to melt:
2848  zsnowtemp(jj,jst) = psnowtemp(jj,jst) - zphase(jj,jst) / (pscap(jj,jst)*psnowdz(jj,jst))
2849  !
2850  ! difference with isba_es: zmeltxs should never be different of 0.
2851  ! because of the introduction of the tests in llayergone
2852  psnowtemp(jj,jst) = zsnowtemp(jj,jst)
2853  !
2854  ! the control below should be suppressed after further tests
2855  IF (psnowtemp(jj,jst)-xtt > xuepsi) THEN
2856  WRITE(*,*) 'pb dans MELT PSNOWTEMP(JJ,JST) >XTT:', jj,jst, psnowtemp(jj,jst)
2857  CALL abor1_sfx('SNOWCRO: pb dans MELT')
2858  ENDIF
2859  !
2860  ! Loss of snowpack depth: (m) and liquid equiv (m):
2861  ! Compression factor for melt loss: this decreases
2862  ! layer thickness and increases density thereby leaving
2863  ! total SWE constant.
2864  !
2865  ! Difference with ISBA_ES: All melt is considered to decrease the depth
2866  ! without consideration to the irreducible content
2867  !
2868  zcmprsfact(jj,jst) = ( zsnowlwe(jj,jst) - (psnowliq(jj,jst)+zsnowmelt(jj,jst)) ) &
2869  / ( zsnowlwe(jj,jst) - psnowliq(jj,jst) )
2870  psnowdz(jj,jst) = psnowdz(jj,jst) * zcmprsfact(jj,jst)
2871  psnowrho(jj,jst) = zsnowlwe(jj,jst) * xrholw / psnowdz(jj,jst)
2872  !
2873  ! 2. Add snow melt to current snow liquid water content:
2874  ! ------------------------------------------------------
2875  !
2876  psnowliq(jj,jst) = psnowliq(jj,jst) + zsnowmelt(jj,jst)
2877  !
2878  ENDDO ! loop JST active snow layers
2879 ENDDO ! loop JJ grid points
2880 !
2881 IF (lhook) CALL dr_hook('SNOWCROMELT',1,zhook_handle)
2882 !
2883 END SUBROUTINE snowcromelt
2884 !####################################################################
2885 !####################################################################
2886 !####################################################################
2887 SUBROUTINE snowcrorefrz(PTSTEP,PRR, &
2888  psnowrho,psnowtemp,psnowdz,psnowliq, &
2889  pthrufal, pscap, plel3l,knlvls_use )
2890 !
2891 !! PURPOSE
2892 !! -------
2893 ! Calculate any freezing/refreezing of liquid water in the snowpack.
2894 ! Also, calculate liquid water transmission and snow runoff.
2895 ! Refreezing causes densification of a layer.
2896 !
2897 USE modd_csts, ONLY : xtt, xlmtt, xrholw, xci,xrholi
2898 USE modd_snow_par, ONLY : xsnowdmin
2899 !
2900 USE mode_snow3l
2901 !
2902 IMPLICIT NONE
2903 !
2904 !* 0.1 declarations of arguments
2905 !
2906 REAL, INTENT(IN) :: ptstep
2907 !
2908 REAL, DIMENSION(:), INTENT(IN) :: prr
2909 !
2910 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowdz, psnowtemp, psnowliq, psnowrho
2911 !
2912 REAL, DIMENSION(:), INTENT(INOUT) :: pthrufal
2913 !
2914 ! modifs_EB layers
2915 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use
2916 REAL, DIMENSION(:,:), INTENT(IN) :: pscap
2917 REAL, DIMENSION(:), INTENT(IN) :: plel3l
2918 !
2919 !* 0.2 declarations of local variables
2920 !
2921 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zphase, &
2922  zsnowliq, zsnowrho, &
2923  zwholdmax, zsnowdz, &
2924  zsnowtemp
2925 !
2926 REAL, DIMENSION(SIZE(PSNOWRHO,1),0:SIZE(PSNOWRHO,2)) :: zflowliq
2927 !
2928 REAL :: zdenom, znumer
2929 !
2930 INTEGER :: jj, jst ! looping indexes
2931 INTEGER :: inlvls ! maximum snow layers number
2932 !
2933 REAL(KIND=JPRB) :: zhook_handle
2934 !
2935 !-------------------------------------------------------------------------------
2936 IF (lhook) CALL dr_hook('SNOWCROREFRZ',0,zhook_handle)
2937 !
2938 ! 0. Initialize:
2939 ! --------------
2940 !
2941 inlvls = SIZE(psnowdz,2)
2942 !
2943 DO jj=1,SIZE(psnowdz,1)
2944  DO jst=1,knlvls_use(jj)
2945  zsnowrho(jj,jst) = psnowrho(jj,jst)
2946  zsnowtemp(jj,jst) = psnowtemp(jj,jst)
2947  zwholdmax(jj,jst) = snowcrohold( psnowrho(jj,jst),psnowliq(jj,jst),psnowdz(jj,jst) )
2948  ENDDO
2949 ENDDO
2950 !
2951 DO jj = 1,SIZE(psnowdz,1) ! loop JJ grid points
2952  !
2953  ! 1. Increases Liquid Water of top layer from rain
2954  ! ---------------------------------------------
2955  !
2956  ! Rainfall (m) initialises the liquid flow whih feeds the top layer
2957  ! and evaporation/condensation are taken into account
2958  !
2959  IF ( knlvls_use(jj)>0. ) THEN
2960  zflowliq(jj,0) = prr(jj) * ptstep / xrholw
2961  zflowliq(jj,0) = max(0., zflowliq(jj,0) - plel3l(jj)*ptstep/(xlvtt*xrholw))
2962  ELSE
2963  zflowliq(jj,0) = 0
2964  ENDIF
2965  !
2966  DO jst=1,knlvls_use(jj) ! loop JST active snow layers
2967  !
2968  ! 2. Increases Liquid Water from the upper layers flow (or rain for top layer)
2969  ! -----------------------------
2970  psnowliq(jj,jst) = psnowliq(jj,jst) + zflowliq(jj,jst-1)
2971  !
2972  ! 3. Freezes liquid water in any cold layers
2973  ! ---------------------------------------
2974  !
2975  ! Calculate the maximum possible refreezing
2976  zphase(jj,jst) = min( pscap(jj,jst)* max(0.0, xtt - zsnowtemp(jj,jst)) * psnowdz(jj,jst), &
2977  psnowliq(jj,jst) * xlmtt * xrholw )
2978  !
2979  ! Reduce liquid content if freezing occurs:
2980  zsnowliq(jj,jst) = psnowliq(jj,jst) - zphase(jj,jst)/(xlmtt*xrholw)
2981  !
2982  ! Warm layer and reduce liquid if freezing occurs:
2983  zsnowdz(jj,jst) = max(xsnowdmin/inlvls, psnowdz(jj,jst))
2984  !
2985  !
2986  ! Difference with ISBA-ES: a possible cooling of current refreezing water
2987  ! is taken into account to calculate temperature change
2988  znumer = ( zsnowrho(jj,jst) * zsnowdz(jj,jst) - ( psnowliq(jj,jst) - zflowliq(jj,jst-1) ) * xrholw )
2989  zdenom = ( zsnowrho(jj,jst) * zsnowdz(jj,jst) - ( zsnowliq(jj,jst) - zflowliq(jj,jst-1) ) * xrholw )
2990  !
2991  psnowtemp(jj,jst) = xtt + ( zsnowtemp(jj,jst)-xtt )*znumer/zdenom + zphase(jj,jst)/( xci*zdenom )
2992  !
2993  ! 4. Calculate flow from the excess of holding capacity
2994  ! --------------------------------------------------------------
2995  !
2996  ! Any water in excess of the maximum holding space for liquid water
2997  ! amount is drained into next layer down.
2998  zflowliq(jj,jst) = max( 0., zsnowliq(jj,jst)-zwholdmax(jj,jst) )
2999  !
3000  zsnowliq(jj,jst) = zsnowliq(jj,jst) - zflowliq(jj,jst)
3001  !
3002  ! 5. Density is adjusted to conserve the mass
3003  ! --------------------------------------------------------------
3004  znumer = ( zsnowrho(jj,jst) * psnowdz(jj,jst) - ( zflowliq(jj,jst) - zflowliq(jj,jst-1) ) * xrholw )
3005  !
3006  zsnowrho(jj,jst) = znumer / zsnowdz(jj,jst)
3007  !
3008  ! keeps snow denisty below ice density
3009  IF ( zsnowrho(jj,jst)>xrholi ) THEN
3010  psnowdz(jj,jst) = psnowdz(jj,jst) * zsnowrho(jj,jst) / xrholi
3011  zsnowrho(jj,jst) = xrholi
3012  ENDIF
3013  !
3014  ! 6. Update thickness and density and any freezing:
3015  ! ----------------------------------------------
3016  psnowrho(jj,jst) = zsnowrho(jj,jst)
3017  psnowliq(jj,jst) = zsnowliq(jj,jst)
3018  !
3019  ENDDO ! loop JST active snow layers
3020  !
3021  ! Any remaining throughflow after freezing is available to
3022  ! the soil for infiltration or surface runoff (m).
3023  ! I.E. This is the amount of water leaving the snowpack:
3024  ! Rate water leaves the snowpack [kg/(m2 s)]:
3025  !
3026  pthrufal(jj) = pthrufal(jj) + zflowliq(jj,knlvls_use(jj)) * xrholw / ptstep
3027  !
3028 ENDDO ! loop JJ grid points
3029 !
3030 IF (lhook) CALL dr_hook('SNOWCROREFRZ',1,zhook_handle)
3031 !
3032 END SUBROUTINE snowcrorefrz
3033 !####################################################################
3034 SUBROUTINE get_rho(PRHO_IN,PDZ,PSNOWLIQ,PFLOWLIQ,PRHO_OUT)
3035 !
3036 USE modd_csts, ONLY : xrholw
3037 !
3038 IMPLICIT NONE
3039 !
3040 REAL, INTENT(IN) :: prho_in, pdz, psnowliq,pflowliq
3041 REAL, INTENT(OUT) :: prho_out
3042 !
3043 REAL(KIND=JPRB) :: zhook_handle
3044 !
3045 IF (lhook) CALL dr_hook('SNOWCRO:GET_RHO',0,zhook_handle)
3046 !
3047 prho_out = ( prho_in * pdz - ( psnowliq - pflowliq ) * xrholw )
3048 !
3049 IF (lhook) CALL dr_hook('SNOWCRO:GET_RHO',1,zhook_handle)
3050 !
3051 END SUBROUTINE get_rho
3052 !####################################################################
3053 !####################################################################
3054 SUBROUTINE snowcroflux(PSNOWTEMP,PSNOWDZ,PEXNS,PEXNA, &
3055  pustar2_ic, &
3056  ptstep,palbt,psw_rad,pemist,plwupsnow, &
3057  plw_rad,pta,psfcfrz,pqa,phpsnow, &
3058  psnowtempo1,psnowflux,pct,pradsink, &
3059  pqsat,pdqsat,prsra, &
3060  prn,ph,pgflux,ples3l,plel3l,pevap, &
3061  pustar )
3062 !
3063 !! PURPOSE
3064 !! -------
3065 ! Calculate the surface fluxes (atmospheric/surface).
3066 ! (Noilhan and Planton 1989; Noilhan and Mahfouf 1996)
3067 !
3068 USE modd_csts,ONLY : xtt
3069 !
3070 USE mode_thermos
3071 !
3072 IMPLICIT NONE
3073 !
3074 !* 0.1 declarations of arguments
3075 !
3076 REAL, INTENT(IN) :: ptstep
3077 !
3078 REAL, DIMENSION(:), INTENT(IN) :: psnowdz, psnowtempo1, psnowflux, pct, &
3079  pradsink, pexns, pexna
3080 !
3081 REAL, DIMENSION(:), INTENT(IN) :: palbt, psw_rad, pemist, plw_rad, &
3082  pta, psfcfrz, pqa, &
3083  phpsnow, pqsat, pdqsat, prsra, &
3084  pustar2_ic
3085 !
3086 REAL, DIMENSION(:), INTENT(INOUT) :: psnowtemp
3087 !
3088 REAL, DIMENSION(:), INTENT(OUT) :: prn, ph, pgflux, ples3l, plel3l, &
3089  pevap, plwupsnow, pustar
3090 !
3091 !* 0.2 declarations of local variables
3092 !
3093 REAL, DIMENSION(SIZE(PSNOWDZ)) :: zevapc, zsnowtemp
3094 REAL :: zsmsnow, zgflux
3095 !
3096 INTEGER :: jj
3097 !
3098 REAL(KIND=JPRB) :: zhook_handle
3099 !-------------------------------------------------------------------------------
3100 IF (lhook) CALL dr_hook('SNOWCROFLUX',0,zhook_handle)
3101 !
3102 ! 0. Initialize:
3103 ! --------------
3104 !
3105 ! 1. Flux calculations when melt not occuring at surface (W/m2):
3106 ! --------------------------------------------------------------
3107 !
3108 DO jj = 1,SIZE(palbt)
3109  !
3110  CALL get_flux(palbt(jj),pemist(jj),psw_rad(jj),plw_rad(jj), &
3111  pexns(jj),pexna(jj),pta(jj),pqa(jj),prsra(jj), &
3112  pqsat(jj),pdqsat(jj),psfcfrz(jj),phpsnow(jj), &
3113  psnowtemp(jj),psnowtempo1(jj), &
3114  prn(jj),ph(jj),zevapc(jj), &
3115  ples3l(jj),plel3l(jj),zgflux )
3116  !
3117  IF ( psnowtemp(jj)>xtt ) THEN
3118  !
3119  IF ( psnowtempo1(jj)<xtt ) THEN
3120  !
3121  ! 2. Initial melt adjustment
3122  ! --------------------------
3123  ! If energy avalabile to melt snow, then recalculate fluxes
3124  ! at the freezing point and add residual heat to layer
3125  ! average heat.
3126  !
3127  ! A) If temperature change is > 0 and passes freezing point this timestep,
3128  ! then recalculate fluxes at freezing point and excess energy
3129  ! will be used outside of this routine to change snow heat content:
3130  !
3131  ! WRITE (*,*) 'attention test LFLUX traitement XTT supprime!'
3132  !
3133  CALL get_flux(palbt(jj),pemist(jj),psw_rad(jj),plw_rad(jj), &
3134  pexns(jj),pexna(jj), pta(jj),pqa(jj),prsra(jj), &
3135  pqsat(jj),pdqsat(jj),psfcfrz(jj),phpsnow(jj), &
3136  xtt,psnowtempo1(jj), &
3137  prn(jj),ph(jj),zevapc(jj), &
3138  ples3l(jj),plel3l(jj),pgflux(jj) )
3139  !
3140  zsmsnow = zgflux - pgflux(jj)
3141  !
3142  ! This will be used to change heat content of snow:
3143  zsnowtemp(jj) = psnowtemp(jj) - zsmsnow * ptstep * pct(jj)
3144  !
3145  ELSE
3146  !
3147  ! 3. Ongoing melt adjustment: explicit solution
3148  ! ---------------------------------------------
3149  ! If temperature change is 0 and at freezing point this timestep,
3150  ! then recalculate fluxes and surface temperature *explicitly*
3151  ! as this is *exact* for snow at freezing point (Brun, Martin)
3152  !
3153  CALL get_flux(palbt(jj),pemist(jj),psw_rad(jj),plw_rad(jj), &
3154  pexns(jj),pexna(jj), pta(jj),pqa(jj),prsra(jj), &
3155  pqsat(jj),pdqsat(jj),psfcfrz(jj),phpsnow(jj), &
3156  xtt,xtt, &
3157  prn(jj),ph(jj),zevapc(jj), &
3158  ples3l(jj),plel3l(jj),pgflux(jj) )
3159  !
3160  zsnowtemp(jj) = xtt + ptstep * pct(jj) * ( pgflux(jj) + pradsink(jj) - psnowflux(jj) )
3161  !
3162  ENDIF
3163  !
3164  ELSE
3165  !
3166  zsnowtemp(jj) = psnowtemp(jj)
3167  !
3168  pgflux(jj) = zgflux
3169  !
3170  ENDIF
3171  !
3172 ENDDO
3173 !
3174 ! 4. Update surface temperature:
3175 ! ------------------------------
3176 !
3177 psnowtemp(:) = zsnowtemp(:)
3178 !
3179 ! 5. Final evaporative flux (kg/m2/s)
3180 !
3181 pevap(:) = zevapc(:)
3182  !WRITE(*,*) 'Flux surface:',PGFLUX(1),PRN(1),PH(1), ZLE(1), PHPSNOW(1)
3183 !
3184 ! 5. Friction velocity
3185 ! --------------------
3186 !
3187 pustar(:) = sqrt(pustar2_ic(:))
3188 !
3189 IF (lhook) CALL dr_hook('SNOWCROFLUX',1,zhook_handle)
3190 !
3191 END SUBROUTINE snowcroflux
3192 !####################################################################
3193 SUBROUTINE get_flux(PALBT,PEMIST,PSW_RAD,PLW_RAD,PEXNS,PEXNA, &
3194  pta,pqa,prsra,pqsat,pdqsat,psfcfrz,phpsnow, &
3195  psnowtemp,psnowtempo1, &
3196  prn,ph,pevapc,ples3l,plel3l,pgflux )
3197 !
3198 USE modd_csts,ONLY : xstefan, xcpd, xlstt, xlvtt
3199 !
3200 IMPLICIT NONE
3201 !
3202 REAL, INTENT(IN) :: palbt, pemist
3203 REAL, INTENT(IN) :: psw_rad, plw_rad
3204 REAL, INTENT(IN) :: pexns, pexna
3205 REAL, INTENT(IN) :: pta, pqa, prsra, pqsat, pdqsat, psfcfrz, phpsnow
3206 REAL, INTENT(IN) :: psnowtemp,psnowtempo1
3207 REAL, INTENT(OUT):: prn, ph, pevapc, ples3l, plel3l, pgflux
3208 !
3209 REAL :: zle, zdeltat, zlwupsnow, zsnowto3
3210 !
3211 REAL(KIND=JPRB) :: zhook_handle
3212 !
3213 IF (lhook) CALL dr_hook('SNOWCRO:GET_FLUX',0,zhook_handle)
3214 !
3215 zsnowto3 = psnowtempo1**3 ! to save some CPU time, store this
3216 !
3217 zdeltat = psnowtemp - psnowtempo1 ! surface T time change:
3218 !
3219 zlwupsnow = pemist * xstefan * zsnowto3 * ( psnowtempo1 + 4.*zdeltat )
3220 !
3221 prn = ( 1.-palbt )*psw_rad + pemist*plw_rad - zlwupsnow
3222 !
3223 ph = prsra * xcpd * ( psnowtemp/pexns - pta/pexna )
3224 !
3225 pevapc = prsra * ( (pqsat - pqa) + pdqsat*zdeltat )
3226 !
3227 ples3l = psfcfrz * xlstt * pevapc
3228 !
3229 plel3l = (1.-psfcfrz) * xlvtt * pevapc
3230 !
3231 zle = ples3l + plel3l
3232 !
3233 pgflux = prn - ph - zle + phpsnow
3234 !
3235 IF (lhook) CALL dr_hook('SNOWCRO:GET_FLUX',1,zhook_handle)
3236 !
3237 END SUBROUTINE get_flux
3238 !
3239 !####################################################################
3240 !####################################################################
3241 SUBROUTINE snowcroevapn(PLES3L,PTSTEP,PSNOWTEMP,PSNOWRHO, &
3242  psnowdz,pevapcor,psnowhmass )
3243 !
3244 !! PURPOSE
3245 !! -------
3246 ! Remove mass from uppermost snow layer in response to
3247 ! evaporation (liquid) and sublimation.
3248 !
3249 !! MODIFICATIONS
3250 !! -------------
3251 !! Original A. Boone
3252 !! 05/2011: E. Brun Takes only into account sublimation and solid
3253 !! condensation. Evaporation and liquid condensation
3254 !! are taken into account in SNOWCROREFRZ
3255 !
3256 USE modd_csts, ONLY : xlstt, xlmtt, xci, xtt
3257 !
3258 IMPLICIT NONE
3259 !
3260 !* 0.1 declarations of arguments
3261 !
3262 REAL, INTENT(IN) :: ptstep
3263 !
3264 REAL, DIMENSION(:), INTENT(IN) :: psnowtemp
3265 !
3266 REAL, DIMENSION(:), INTENT(IN) :: ples3l ! (W/m2)
3267 !
3268 REAL, DIMENSION(:), INTENT(INOUT) :: psnowrho, psnowdz, psnowhmass, &
3269  pevapcor
3270 !
3271 !* 0.2 declarations of local variables
3272 !
3273 REAL, DIMENSION(SIZE(PLES3L)) :: zsnowevaps, zsnowevap, zsnowevapx, &
3274  zsnowdz, zevapcor
3275 ! ZEVAPCOR = for vanishingy thin snow cover,
3276 ! allow any excess evaporation
3277 ! to be extracted from the soil
3278 ! to maintain an accurate water
3279 ! balance [kg/(m2 s)]
3280 !
3281 REAL(KIND=JPRB) :: zhook_handle
3282 !-------------------------------------------------------------------------------
3283 IF (lhook) CALL dr_hook('SNOWCROEVAPN',0,zhook_handle)
3284 !
3285 ! 0. Initialize:
3286 ! --------------
3287 !
3288 zevapcor(:) = 0.0
3289 zsnowevaps(:) = 0.0
3290 zsnowevap(:) = 0.0
3291 zsnowevapx(:) = 0.0
3292 zsnowdz(:) = 0.0
3293 !
3294 WHERE ( psnowdz>0.0 )
3295  !
3296  ! 1. Sublimation/condensation of snow ice
3297  ! ----------------------------------------
3298  ! Reduce layer thickness and total snow depth
3299  ! if sublimation: add to correction term if potential
3300  ! sublimation exceeds available snow cover.
3301  !
3302  zsnowevaps(:) = ples3l(:) * ptstep / ( xlstt*psnowrho(:) )
3303  zsnowdz(:) = psnowdz(:) - zsnowevaps(:)
3304  psnowdz(:) = max( 0.0, zsnowdz(:) )
3305  zevapcor(:) = zevapcor(:) + max(0.0,-zsnowdz(:)) * psnowrho(:) / ptstep
3306  !
3307  ! Total heat content change due to snowfall and sublimation (added here):
3308  ! (for budget calculations):
3309  !
3310  psnowhmass(:) = psnowhmass(:) &
3311  - ples3l(:) * (ptstep/xlstt) * ( xci * (psnowtemp(:)-xtt) - xlmtt )
3312  !
3313 END WHERE
3314 !
3315 ! 3. Update evaporation correction term:
3316 ! --------------------------------------
3317 !
3318 pevapcor(:) = pevapcor(:) + zevapcor(:)
3319 !
3320 IF (lhook) CALL dr_hook('SNOWCROEVAPN',1,zhook_handle)
3321 !
3322 !-------------------------------------------------------------------------------
3323 !
3324 END SUBROUTINE snowcroevapn
3325 !####################################################################
3326 !####################################################################
3327 !####################################################################
3328 SUBROUTINE snowcrogone(PTSTEP,PLEL3L,PLES3L,PSNOWRHO, &
3329  psnowheat,pradsink_2d,pevapcor,pthrufal,pgrndflux, &
3330  pgfluxsnow,psnowdz,psnowliq,psnowtemp,pradxs, &
3331  prr,knlvls_use )
3332 !
3333 !! PURPOSE
3334 !! -------
3335 ! Account for the case when the last trace of snow melts
3336 ! during a time step: ensure mass and heat balance of
3337 ! snow AND underlying surface.
3338 ! Original A. Boone
3339 ! 05/2011: E. Brun Takes into account sublimation and PGRNDFLUX
3340 ! Adds rain and evaporation/liquid condensation
3341 ! in PTHRUFAL
3342 !
3343 USE modd_csts,ONLY : xtt, xlstt, xlvtt
3344 !
3345 IMPLICIT NONE
3346 !
3347 !* 0.1 declarations of arguments
3348 !
3349 REAL, INTENT(IN) :: ptstep
3350 !
3351 REAL, DIMENSION(:), INTENT(IN) :: plel3l, ples3l, pgfluxsnow,prr
3352 !
3353 REAL, DIMENSION(:,:), INTENT(IN) :: pradsink_2d
3354 !
3355 REAL, DIMENSION(:,:), INTENT(IN) :: psnowrho, psnowheat
3356 !
3357 REAL, DIMENSION(:), INTENT(INOUT) :: pgrndflux, pradxs
3358 !
3359 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowdz, psnowliq, psnowtemp
3360 !
3361 REAL, DIMENSION(:), INTENT(OUT) :: pthrufal ! melt water [kg/(m2 s)]
3362 !
3363 REAL, DIMENSION(:), INTENT(OUT) :: pevapcor ! [kg/(m2 s)]
3364 ! PEVAPCOR = for vanishingy thin snow cover,
3365 ! allow any excess evaporation
3366 ! to be extracted from the soil
3367 ! to maintain an accurate water
3368 ! balance.
3369 !
3370 INTEGER, DIMENSION(:), INTENT(INOUT) :: knlvls_use
3371 !
3372 !* 0.2 declarations of local variables
3373 !
3374 REAL, DIMENSION(SIZE(PLES3L)) :: zradsink
3375 REAL, DIMENSION(SIZE(PLES3L)) :: zsnowheatc
3376 INTEGER, DIMENSION(SIZE(PLES3L)) :: isnowgone_delta
3377 !
3378 INTEGER :: jj
3379 !
3380 REAL(KIND=JPRB) :: zhook_handle
3381 !-------------------------------------------------------------------------------
3382 IF (lhook) CALL dr_hook('SNOWCROGONE',0,zhook_handle)
3383 !
3384 ! 0. Initialize:
3385 ! --------------
3386 !
3387 pevapcor(:) = 0.0
3388 pthrufal(:) = 0.0
3389 !
3390 DO jj = 1,SIZE(zradsink)
3391  zradsink(jj) = pradsink_2d(jj,inlvls_use(jj))
3392  zsnowheatc(jj) = sum(psnowheat(jj,1:inlvls_use(jj))) !total heat content (J m-2)
3393 END DO
3394 !
3395 isnowgone_delta(:) = 1
3396 !
3397 ! 1. Simple test to see if snow vanishes:
3398 ! ---------------------------------------
3399 ! If so, set thicknesses (and therefore mass and heat) and liquid content
3400 ! to zero, and adjust fluxes of water, evaporation and heat into underlying
3401 ! surface.
3402 !
3403 ! takes into account the heat content corresponding to the occasional
3404 ! sublimation and then PGRNDFLUX
3405 !
3406 zsnowheatc(:) = zsnowheatc(:) + max( 0., ples3l(:)*ptstep/xlstt ) * xlmtt
3407 !
3408 WHERE ( pgfluxsnow(:)+zradsink(:)-pgrndflux(:) >= (-zsnowheatc(:)/ptstep) )
3409  pgrndflux(:) = pgfluxsnow(:) + (zsnowheatc(:)/ptstep)
3410  pevapcor(:) = ples3l(:)/xlstt
3411  pradxs(:) = 0.0
3412  isnowgone_delta(:) = 0 ! FLAG...if=0 then snow vanishes, else=1
3413 END WHERE
3414 !
3415 ! 2. Final update of snow state and computation of corresponding flow
3416 ! Only if snow vanishes
3417 ! -----------------------------
3418 !
3419 pthrufal(:) = 0.
3420 !
3421 DO jj=1, SIZE(zradsink)
3422  !
3423  IF(isnowgone_delta(jj) == 0 ) THEN
3424  pthrufal(jj) = pthrufal(jj) + &
3425  sum( psnowrho(jj,1:inlvls_use(jj))*psnowdz(jj,1:inlvls_use(jj)) ) / ptstep
3426 ! takes into account rain and condensation/evaporation
3427  pthrufal(jj) = pthrufal(jj) + prr(jj) - plel3l(jj)/xlvtt
3428  psnowtemp(jj,:) = xtt
3429  psnowdz(jj,:) = 0.
3430  psnowliq(jj,:) = 0.
3431  inlvls_use(jj) = 0
3432  ENDIF
3433  !
3434 ENDDO
3435 !
3436 IF (lhook) CALL dr_hook('SNOWCROGONE',1,zhook_handle)
3437 !
3438 END SUBROUTINE snowcrogone
3439 !####################################################################
3440 !####################################################################
3441 !####################################################################
3442 SUBROUTINE snowcroevapgone(PSNOWHEAT,PSNOWDZ,PSNOWRHO,PSNOWTEMP,PSNOWLIQ, &
3443  psnowgran1,psnowgran2,psnowhist,psnowage,knlvls_use,&
3444  hsnowmetamo)
3445 !
3446 !! PURPOSE
3447 !! -------
3448 !
3449 ! If all snow in uppermost layer evaporates/sublimates, re-distribute
3450 ! grid (below assumes very thin snowpacks so layer-thicknesses are
3451 ! constant).
3452 ! Original A. Boone
3453 ! 05/2011: E. Brun Takes into account previous changes in the energy
3454 ! content
3455 !
3456 !
3457 USE modd_csts, ONLY : xtt, xrholw, xlmtt, xci
3458 USE modd_snow_par, ONLY : xrhosmin_es, xsnowdmin, xrhosmax_es
3459 USE mode_snow3l
3460 USE modd_snow_metamo
3462 !
3463 IMPLICIT NONE
3464 !
3465 !* 0.1 declarations of arguments
3466 !
3467 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowrho ! snow density profile (kg/m3)
3468 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowdz ! snow layer thickness profile (m)
3469 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowheat ! snow heat content/enthalpy (J/m2)
3470 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowgran1 ! snow grain parameter 1 (-)
3471 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowgran2 ! snow grain parameter 2 (-)
3472 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowhist ! snow grain historical variable (-)
3473 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowage ! Snow grain age
3474 !
3475 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowtemp ! snow temperature profile (K)
3476 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowliq ! snow liquid water profile (m)
3477 !
3478 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use
3479  CHARACTER(3), INTENT(IN) :: hsnowmetamo ! metamorphism scheme
3480 !
3481 !* 0.2 declarations of local variables
3482 !
3483 REAL, DIMENSION(SIZE(PSNOWDZ,1)) :: zsnowheat_1d ! total heat content (J/m2)
3484 REAL, DIMENSION(SIZE(PSNOWDZ,1)) :: zsnowrho_1d ! total snowpack average density (kg/m3)
3485 REAL, DIMENSION(SIZE(PSNOWDZ,1)) :: zsnow ! total snow depth (m)
3486 REAL, DIMENSION(SIZE(PSNOWDZ,1)) :: zscap ! Snow layer heat capacity (J/K/m3)
3487 REAL, DIMENSION(SIZE(PSNOWDZ,1)) :: zndent ! Number of dendritic layers (-)
3488 REAL, DIMENSION(SIZE(PSNOWDZ,1)) :: znvieu ! Number of non dendritic layers (-)
3489 REAL, DIMENSION(SIZE(PSNOWDZ,1)) :: zsnowage_1d ! total snowpack average
3490 !age (days)
3491 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowgran1n, &
3492  zsnowgran2n,zsnowhistn
3493 !
3494 LOGICAL :: gdendritic
3495 !
3496 INTEGER :: jj, jst ! loop control
3497 !
3498 REAL(KIND=JPRB) :: zhook_handle
3499 !-------------------------------------------------------------------------------
3500 IF (lhook) CALL dr_hook('SNOWCROEVAPGONE',0,zhook_handle)
3501 !
3502 ! Initialize:
3503 !
3504 zsnowheat_1d(:) = 0.
3505 zsnow(:) = 0.
3506 zsnowrho_1d(:) = 0.
3507 zndent(:) = 0.
3508 znvieu(:) = 0.
3509 zsnowage_1d(:) = 0.
3510 zscap(:) = 0.
3511 !
3512 ! First, determine where uppermost snow layer has completely
3513 ! evaporated/sublimated (as it becomes thin):
3514 DO jj = 1,SIZE(psnowrho,1)
3515  !
3516  IF ( psnowdz(jj,1)==0.0 ) THEN
3517  !
3518  DO jst = 2,knlvls_use(jj)
3519  !
3520  zsnowheat_1d(jj) = zsnowheat_1d(jj) + psnowdz(jj,jst) * &
3521  ( psnowrho(jj,jst)*xci * (zsnowtemp(jj,jst)-xtt) &
3522  - xlmtt * psnowrho(jj,jst) ) &
3523  + xlmtt * xrholw * psnowliq(jj,jst)
3524  zsnow(jj) = zsnow(jj) + psnowdz(jj,jst)
3525  zsnowrho_1d(jj) = zsnowrho_1d(jj) + psnowdz(jj,jst) * psnowrho(jj,jst)
3526  zsnowage_1d(jj) = zsnowage_1d(jj) + psnowdz(jj,jst) * psnowrho(jj,jst) * psnowage(jj,jst)
3527  !
3528  ! snow grains
3529  IF ( hsnowmetamo=='B92' ) THEN
3530  gdendritic = ( psnowgran1(jj,jst)<-xepsi )
3531  ELSE
3532  gdendritic = ( psnowgran1(jj,jst)<xvdiam6*(4.-psnowgran2(jj,jst))-xuepsi )
3533  ENDIF
3534  !
3535  IF ( gdendritic ) THEN ! Dendritic snow
3536  zndent(jj) = zndent(jj) + 1.0
3537  ELSE ! Non dendritic snow
3538  znvieu(jj) = znvieu(jj) + 1.0
3539  ENDIF
3540  !
3541  ENDDO
3542  !
3543  ENDIF
3544  !
3545 END DO
3546 !
3547 zsnowrho_1d(:) = zsnowrho_1d(:) / max( xsnowdmin, zsnow(:) )
3548 zsnowage_1d(:) = zsnowage_1d(:) / max( xsnowdmin, zsnow(:) * zsnowrho_1d(:) )
3549 zsnowrho_1d(:) = max( xrhosmin_es, min( xrhosmax_es, zsnowrho_1d(:) ) )
3550 !
3551 ! Where uppermost snow layer has vanished, redistribute vertical
3552 ! snow mass and heat profiles (and associated quantities):
3553 !
3554  CALL snow3lavgrain(psnowgran1,psnowgran2,psnowhist, &
3555  zsnowgran1n,zsnowgran2n,zsnowhistn,zndent,znvieu,&
3556  hsnowmetamo)
3557 !
3558 DO jj=1,SIZE(psnowrho,1)
3559  !
3560  IF( zsnow(jj)/=0.0 ) THEN
3561  !
3562  psnowdz(jj,1:knlvls_use(jj)) = zsnow(jj) / knlvls_use(jj)
3563  psnowheat(jj,1:knlvls_use(jj)) = zsnowheat_1d(jj) / knlvls_use(jj)
3564  psnowrho(jj,1:knlvls_use(jj)) = zsnowrho_1d(jj)
3565  !
3566  zscap(jj) = zsnowrho_1d(jj) * xci
3567  !
3568  DO jst = 1,knlvls_use(jj)
3569  !
3570  psnowtemp(jj,jst) = xtt + ( ( (psnowheat(jj,jst)/psnowdz(jj,jst)) &
3571  + xlmtt*psnowrho(jj,jst) ) / zscap(jj) )
3572  psnowtemp(jj,jst) = min( xtt, psnowtemp(jj,jst) )
3573  !
3574  psnowliq(jj,jst) = max( 0.0, psnowtemp(jj,jst)-xtt ) * zscap(jj) * &
3575  psnowdz(jj,jst) / (xlmtt*xrholw)
3576  !
3577  ENDDO
3578  !
3579  ENDIF
3580  !
3581 ENDDO
3582 !
3583 IF (lhook) CALL dr_hook('SNOWCROEVAPGONE',1,zhook_handle)
3584 !
3585 END SUBROUTINE snowcroevapgone
3586 !
3587 !####################################################################
3588 !####################################################################
3589 !####################################################################
3590 SUBROUTINE snownlfall_upgrid(TPTIME, OGLACIER,PTSTEP,PSR,PTA,PVMOD, &
3591  psnow,psnowrho,psnowdz,psnowheat,psnowhmass, &
3592  psnowalb,ppermsnowfrac,psnowgran1,psnowgran2, &
3593  gsnowfall,psnowdzn,psnowrhof,psnowdzf, &
3594  psnowgran1f,psnowgran2f,psnowhistf,psnowagef, &
3595  omodif_grid,knlvls_use,osnowdrift,pz0eff,puref,&
3596  hsnowmetamo)
3597 !
3598 !! PURPOSE
3599 !! -------
3600 ! Adds new snowfall and updates the vertical grid in order to keep an
3601 ! optimal discertisation
3602 !
3603 !! AUTHOR
3604 !! ------
3605 !! E. Brun * Meteo-France *
3606 !!
3607 !
3608 !!
3609 !! MODIFICATIONS
3610 !! ------
3611 !!
3612 !! 2014-02-05 V. Vionnet: wind speed in the parameterization for new snow
3613 !! density and characteristic of grains of new snow
3614 !! are taken at a reference height
3615 !! 2014-06-03 M. Lafaysse : threshold on PZ0EFF
3616 !!
3617 USE modd_type_date_surf, ONLY: date_time
3618 USE modd_csts, ONLY : xlmtt, xtt, xci
3619 USE modd_snow_metamo, ONLY : xnden1, xnden2, xnden3, xgran, &
3620  xnsph1, xnsph2, xnsph3, xnsph4
3621 !
3622 USE modd_snow_par, ONLY : xrhosmin_es, xsnowdmin, xansmax, xaglamax, xsnowcritd, &
3623  xdzmin_top, xdzmin_top_bis, xdzmin_bot, xsplit_coef, &
3624  xagreg_coef_1, xagreg_coef_2, xdz1, xdz2, xdz3, xdz3_bis,&
3625  xdz4, xdz5, xdz_base, xdz_internal, xscale_cm, &
3626  xdzmax_internal, xdzmin_top_extrem, xsnowfall_threshold, &
3627  xratio_newlayer, xdepth_threshold1, xdepth_threshold2, &
3628  xdepth_surface, xdiff_1, xdiff_max, xscale_diff, &
3629  xsnowfall_a_sn, xsnowfall_b_sn, xsnowfall_c_sn
3630 !
3631 USE mode_snow3l
3632 !
3633 IMPLICIT NONE
3634 !
3635 !* 0.1 declarations of arguments
3636 !
3637 TYPE(date_time), INTENT(IN) :: tptime ! current date and time
3638 LOGICAL, INTENT(IN) :: oglacier ! True = Over permanent snow and ice,
3639 ! initialise WGI=WSAT,
3640 ! Hsnow>=10m and allow 0.8<SNOALB<0.85
3641  ! False = No specific treatment
3642 !
3643 REAL, INTENT(IN) :: ptstep
3644 !
3645 REAL, DIMENSION(:), INTENT(IN) :: psr, pta, pvmod, ppermsnowfrac
3646 !
3647 REAL, DIMENSION(:),INTENT(IN) :: pz0eff,puref
3648 !
3649 REAL, DIMENSION(:), INTENT(INOUT) :: psnow, psnowalb
3650 !
3651 REAL, DIMENSION(:,:), INTENT(IN) :: psnowrho, psnowdz, psnowheat
3652 !
3653 REAL, DIMENSION(:), INTENT(OUT) :: psnowhmass
3654 !
3655 REAL, DIMENSION(:,:), INTENT(IN) :: psnowgran1, psnowgran2
3656 !
3657 LOGICAL, DIMENSION(:), INTENT(INOUT) :: gsnowfall
3658 !
3659 ! Fresh snow characteristics
3660 REAL, DIMENSION(:), INTENT(OUT) :: psnowrhof, psnowdzf
3661 REAL, DIMENSION(:), INTENT(OUT) :: psnowgran1f, psnowgran2f, psnowhistf
3662 REAL, DIMENSION(:), INTENT(OUT) :: psnowagef
3663 ! New vertical grid
3664 REAL, DIMENSION(:,:), INTENT(OUT) :: psnowdzn
3665 !
3666 LOGICAL, DIMENSION(:), INTENT(OUT) :: omodif_grid
3667 !
3668 INTEGER, DIMENSION(:), INTENT(INOUT) :: knlvls_use
3669 
3670 LOGICAL,INTENT(IN) :: osnowdrift ! if snowdrift then grain types are not modified by wind
3671  CHARACTER(3), INTENT(IN) :: hsnowmetamo ! metamorphism scheme
3672 !* 0.2 declarations of local variables
3673 !
3674 !
3675 LOGICAL, DIMENSION(SIZE(PTA)) :: gagreg_surf
3676 !
3677 REAL, DIMENSION(SIZE(PTA)) :: zsnowfall, zsnowtemp, zscap, zansmax
3678 !
3679 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zdzopt
3680 !
3681 REAL :: zz0eff
3682 !
3683 REAL :: zage_now
3684 REAL :: zsnow_upper, zsnow_upper2 ! snow depth treatednormally (<= XDEPTH_SURFACE)
3685 REAL :: zcoef_depth !coefficient for repartition of deep snow above 3 meters
3686 REAL :: zthickness_intermediate, zthickness2
3687 REAL :: zpenalty, zdiftype_inf, zdiftype_sup, zcritsize, zcritsize_inf, zcritsize_sup
3688 REAL :: zsnow2l, zcoef
3689 !
3690 INTEGER :: inb_deep_layer, inb_upper_layer !separation between deep and upper layers
3691  ! if snow depth below XDEPTH_SURFACE then INB_DEEP_LAYER=0
3692 INTEGER :: inb_min_layers ! why this test ?
3693 INTEGER :: inb_intermediate ! number of intermediate layers (constant optimal gridding)
3694 INTEGER :: iend_intermediate ! layer indice for bottom of intermediate layers
3695 INTEGER :: jstdeep, jstend
3696 INTEGER :: jst_1, jj_a_agreg_sup, jj_a_agreg_inf, jj_a_dedoub
3697 INTEGER :: inlvls, inlvlsmin, inlvlsmax, jj, jst
3698 !
3699 ! Coefficient to adjust wind speed at the height used in the parameterization
3700 ! for:
3701 ! - density of new snow
3702 ! - sphericity and dendricity of new snow
3703 ! Default values : 10 m for new snow (Pahaut, 1976) and 5 m for characteristics
3704 ! of snow grains (Guyomarc'h et Merindol, 1998)
3705 REAL, PARAMETER :: pphref_wind_rho = 10.
3706 REAL, PARAMETER :: pphref_wind_grain = 5.
3707 REAL, PARAMETER :: pphref_wind_min = min(pphref_wind_rho,pphref_wind_grain)*0.5
3708 REAL, DIMENSION(SIZE(PTA)) :: zwind_rho
3709 REAL, DIMENSION(SIZE(PTA)) :: zwind_grain
3710 !
3711 REAL(KIND=JPRB) :: zhook_handle
3712 !
3713 !* 1.0 Initialization and snowage calculation for the present date
3714 !
3715 IF (lhook) CALL dr_hook('SNOWNLFALL_UPGRID',0,zhook_handle)
3716 !
3717 inlvls = SIZE (psnowrho(:,:),2)
3718 inlvlsmax = SIZE (psnowrho(:,:),2)
3719 inlvlsmin = 3
3720 !
3721 zsnowtemp(:) = xtt
3722 zsnowfall(:) = 0.0 !Matthieu Lafaysse 21/09/2012
3723 !
3724 gsnowfall(:) =.false.
3725 gagreg_surf(:) =.false.
3726 !
3727 psnowhmass(:) = 0.0
3728 psnowrhof(:) = 0.0
3729 psnowdzf(:) = 0.0
3730 psnowgran1f(:) = 0.0
3731 psnowgran2f(:) = 0.0
3732 psnowhistf(:) = 0.0
3733 psnowdzn(:,:) = psnowdz(:,:)
3734 !
3735 omodif_grid(:) = .false.
3736 !
3737 !************************************************************************************
3738 !* 1.1 Calculation of the optimal vertical grid size ZDZOPT
3739 ! as a function of maximum number of layers and of current
3740 ! snow depth (modified 05/06/2012 by Matthieu Lafaysse)
3741 !
3742 ! KNLVLS_USE(JJ) > INB_MIN_LAYERS =>
3743 ! KNLVLS_USE(JJ) > 2 + INLVLSMAX/3 =>
3744 ! ( KNLVLS_USE(JJ) + INLVLSMAX ) / 6 > (2 + INLVLSMAX/3 + INLVLSMAX) / 6 =>
3745 ! INB_DEEP_LAYER > (2 + 4*INLVLSMAX/3 ) / 6 >= 1
3746 inb_min_layers = 2 + inlvlsmax/3
3747 !
3748 DO jj = 1,SIZE(psnow(:))
3749  !
3750  IF ( psnow(jj)>xdepth_threshold2 .AND. knlvls_use(jj)>inb_min_layers ) THEN
3751  ! for very thick snowpack with enough snow layers
3752  ! special treatment
3753  ! we put the highest thickness in the lowest layers
3754  ! about 1/3 of layers for all snow except XDEPTH_SURFACE=3 first meters
3755  !
3756  !number of "deep layers"
3757  inb_deep_layer = ( knlvls_use(jj) + inlvlsmax ) / 6
3758  !
3759  !number of "upper layers"
3760  inb_upper_layer = knlvls_use(jj) - inb_deep_layer
3761  !
3762  !thickness of "upper layers"
3763  zsnow_upper = xdepth_surface
3764  !
3765  !Arithmetic serie : 1+2+3+...+INB_DEEP_LAYER=INB_DEEP_LAYER*(INB_DEEP_LAYER+1)/2
3766  zcoef_depth = ( psnow(jj) - xdepth_surface ) * 2. / ( (inb_deep_layer+1) * inb_deep_layer )
3767  !
3768  ! deep layers optimal thickness :
3769  ! increasing thickness with depth
3770  DO jstdeep = 1,inb_deep_layer
3771  jst = inb_upper_layer + jstdeep
3772  zdzopt(jj,jst) = zcoef_depth * jstdeep
3773  !This sum is equal to PSNOW(JJ)-XDEPTH_SURFACE
3774  ENDDO
3775  !
3776  ELSE
3777  !
3778  inb_upper_layer = knlvls_use(jj)
3779  !
3780  zsnow_upper = psnow(jj)
3781  !
3782  END IF
3783  !
3784  !on force le ZDZOPT des 3 premières couches à ZSNOW_UPPER/3 maximum, chacune.
3785  ! => si on n'a qu'une couche, ZDZOPT(1) = ZSNOW_UPPER/3
3786  ! quel que soit INB_UPPER_LAYER
3787  !
3788  zsnow_upper2 = zsnow_upper / max( inlvlsmin, inb_upper_layer )
3789  !
3790  zdzopt(jj,1) = min( xdz1, zsnow_upper2 )
3791  IF ( knlvls_use(jj)>=2 ) zdzopt(jj,2) = min( xdz2, zsnow_upper2 )
3792  IF ( knlvls_use(jj)>=3 ) zdzopt(jj,3) = min( xdz3, zsnow_upper2 )
3793  !
3794  IF ( inb_upper_layer>0 ) THEN
3795  !
3796  zsnow_upper2 = zsnow_upper / inb_upper_layer
3797  !
3798  ! dans ce cas, à partir de la 3ème couche, on prend la fraction du nombre de
3799  ! couches supérieures total, pour les couches jusqu'à 5
3800  !
3801  !ML : replace > by >= on 12-12-20 because the last layer was not initialised in case of thick snowpacks
3802  IF ( inb_upper_layer>=3 ) zdzopt(jj,3) = min( xdz3_bis, zsnow_upper2 )
3803  IF ( inb_upper_layer>=4 ) zdzopt(jj,4) = min( xdz4 , zsnow_upper2 )
3804  IF ( inb_upper_layer>=5 ) zdzopt(jj,5) = min( xdz5 , zsnow_upper2 )
3805  !
3806  IF ( inb_upper_layer==knlvls_use(jj) ) THEN
3807  ! si on n'a pas de couches profondes
3808  !
3809  ! dans ce cas, on reprend ZSNOW_UPPER/3 maximum pour la dernière couche
3810  !
3811  ! last layer of' upper layers' : normal case : thin layer
3812  zdzopt(jj,inb_upper_layer) = min( xdz_base, zsnow_upper/max(inlvlsmin,inb_upper_layer) )
3813  !
3814  ! ZTHICKNESS_INTERMEDIATE contient ce qu'il reste d'épaisseur disponible
3815  ! dans les couches supérieures
3816  !remaining snow for remaining layers
3817  zthickness_intermediate = zsnow_upper - sum(zdzopt(jj,1:5)) - zdzopt(jj,inb_upper_layer)
3818 
3819  IF ( zsnow_upper<=xdepth_threshold1 .OR. inb_upper_layer<8 ) THEN
3820  inb_intermediate = inb_upper_layer - 6
3821  iend_intermediate = inb_upper_layer - 1
3822  ELSE
3823  ! si INB_UPPER_LAYER>=8, les avant et avant-dernière couches ne sont pas
3824  ! considérées commes intermédiaires
3825  inb_intermediate = inb_upper_layer - 8
3826  iend_intermediate = inb_upper_layer - 3
3827  ! dans ce cas, on garde un peu d'épaisseur pour les deux couches restantes
3828  IF ( inb_intermediate>0 ) THEN
3829  zthickness_intermediate = zthickness_intermediate * inb_intermediate / float(inb_intermediate+1)
3830  END IF
3831  END IF
3832  !
3833  ELSE
3834  ! si on a des couches profondes, les couches intermédiaires sont celles
3835  ! qui restent quand on a enlevé les 5 premières des couches supérieures
3836  !
3837  ! case with very thick snowpacks :
3838  ! the last layer of upper layers is not an exception
3839  zthickness_intermediate = zsnow_upper - sum(zdzopt(jj,1:5))
3840  inb_intermediate = inb_upper_layer - 5
3841  iend_intermediate = inb_upper_layer
3842  !
3843  END IF
3844  !
3845  ! For thick snowpack : add maximum value of optimal thickness to avoid too
3846  ! large differencies between layers
3847  IF ( inb_intermediate>0 ) THEN
3848  !
3849  zthickness2 = max( xdz_internal, zthickness_intermediate/inb_intermediate )
3850  !
3851  jstend = min( iend_intermediate,10 )
3852  DO jst = 6,jstend
3853  zdzopt(jj,jst) = min( xdzmax_internal(jst-5), zthickness2 )
3854  END DO
3855  !
3856  IF ( iend_intermediate>10 ) THEN
3857  DO jst = 11,iend_intermediate
3858  zdzopt(jj,jst) = zthickness2
3859  END DO
3860  END IF
3861  !
3862  END IF
3863  !
3864  IF ( zsnow_upper>=xdepth_threshold1 .AND. inb_upper_layer>=8 ) THEN
3865  !Linear interpolation of optimal thickness between layers N-3 and N :
3866  zdzopt(jj,inb_upper_layer-2) = 0.34*zdzopt(jj,inb_upper_layer) + &
3867  0.66*zdzopt(jj,inb_upper_layer-3)
3868  zdzopt(jj,inb_upper_layer-1) = 0.66*zdzopt(jj,inb_upper_layer) + &
3869  0.34*zdzopt(jj,inb_upper_layer-3)
3870  ENDIF
3871  !
3872  END IF
3873  !
3874 END DO
3875 !
3876 !************************************************************************************
3877 !This was the initial code for optimal layers until may 2012
3878 !
3879 ! ! ! ! !
3880 ! ! ! ! ! !* 1.1 Calculation of the optimal vertical grid size
3881 ! ! ! ! ! ! as a function of maximum number of layers and of current
3882 ! ! ! ! ! ! snow depth
3883 ! ! ! ! ! !
3884 ! ! ! ! ! DO JJ=1, SIZE(PSNOW(:))
3885 ! ! ! ! ! ZDZOPT(JJ,1) = MIN(XDZ1,PSNOW(JJ)/MAX(INLVLSMIN,KNLVLS_USE(JJ)))
3886 ! ! ! ! ! ZDZOPT(JJ,2) = MIN(XDZ2,PSNOW(JJ)/MAX(INLVLSMIN,KNLVLS_USE(JJ)))
3887 ! ! ! ! ! ZDZOPT(JJ,3) = MIN(XDZ3,PSNOW(JJ)/MAX(INLVLSMIN,KNLVLS_USE(JJ)))
3888 ! ! ! ! ! IF (KNLVLS_USE(JJ)>3) ZDZOPT(JJ,3) = MIN(XDZ3_BIS,PSNOW(JJ)/KNLVLS_USE(JJ))
3889 ! ! ! ! ! IF (KNLVLS_USE(JJ)>4) ZDZOPT(JJ,4) = MIN(XDZ4,PSNOW(JJ)/KNLVLS_USE(JJ))
3890 ! ! ! ! ! IF (KNLVLS_USE(JJ)>5) ZDZOPT(JJ,5) = MIN(XDZ5,PSNOW(JJ)/KNLVLS_USE(JJ))
3891 ! ! ! ! ! IF (KNLVLS_USE(JJ)>0) ZDZOPT(JJ,KNLVLS_USE(JJ))= &
3892 ! ! ! ! ! MIN(XDZ_BASE,PSNOW(JJ)/MAX(INLVLSMIN,KNLVLS_USE(JJ)))
3893 ! ! ! ! ! DO JST=6,KNLVLS_USE(JJ)-1,1
3894 ! ! ! ! ! ZDZOPT(JJ,JST) = MAX(XDZ_INTERNAL,(PSNOW(JJ) - SUM(ZDZOPT(JJ,1:5))- &
3895 ! ! ! ! ! ZDZOPT(JJ,KNLVLS_USE(JJ))) /(KNLVLS_USE(JJ)-6))
3896 ! ! ! ! ! END DO
3897 ! ! ! ! ! END DO
3898 ! ! ! ! ! !
3899 ! ! ! ! !
3900 !
3901 !************************************************************************************
3902 !
3903 !* 2.0 Fresh snow characteristics
3904 !
3905 !
3906 !
3907 ! Heat content of newly fallen snow (J/m2):
3908 ! NOTE for now we assume the snowfall has
3909 ! the temperature of the snow surface upon reaching the snow.
3910 ! This is done as opposed to using the air temperature since
3911 ! this flux is quite small and has little to no impact
3912 ! on the time scales of interest. If we use the above assumption
3913 ! then, then the snowfall advective heat flux is zero.
3914 !!
3915 DO jj = 1,SIZE(psnow(:))
3916  !
3917  IF ( psr(jj)>0.0 ) THEN
3918  !
3919  ! newly fallen snow characteristics:
3920  IF ( knlvls_use(jj)>0 ) THEN !Case of new snowfall on a previously snow-free surface
3921  zscap(jj) = xci*psnowrho(jj,1)
3922  zsnowtemp(jj) = xtt + ( psnowheat(jj,1) + xlmtt*psnowrho(jj,1)*psnowdz(jj,1) ) / &
3923  ( zscap(jj) * max( xsnowdmin/inlvls, psnowdz(jj,1) ) )
3924  ELSE ! case with bare ground
3925  zsnowtemp(jj) = pta(jj)
3926  ENDIF
3927  zsnowtemp(jj) = min( xtt, zsnowtemp(jj) )
3928  !
3929  !
3930  ! Wind speeds at reference heights for new snow density and charactristics of
3931  ! grains of new snow
3932  ! Computed from PVMOD at PUREF (m) assuming a log profile in the SBL
3933  ! and a roughness length equal to PZ0EFF
3934  !
3935  zz0eff=min(pz0eff(jj),puref(jj)*0.5,pphref_wind_min)
3936 
3937  zwind_rho(jj) = pvmod(jj)*log(pphref_wind_rho/zz0eff)/ &
3938  log(puref(jj)/zz0eff)
3939  zwind_grain(jj) = pvmod(jj)*log(pphref_wind_grain/zz0eff)/ &
3940  log(puref(jj)/zz0eff)
3941 
3942  psnowhmass(jj) = psr(jj) * ( xci * ( zsnowtemp(jj)-xtt ) - xlmtt ) * ptstep
3943  !
3944  psnowrhof(jj) = max( xrhosmin_es, xsnowfall_a_sn + &
3945  xsnowfall_b_sn * ( pta(jj)-xtt ) + &
3946  xsnowfall_c_sn * min( pvmod(jj), sqrt(zwind_rho(jj) ) ) )
3947  zsnowfall(jj) = psr(jj) * ptstep / psnowrhof(jj) ! snowfall thickness (m)
3948  psnow(jj) = psnow(jj) + zsnowfall(jj)
3949  psnowdzf(jj) = zsnowfall(jj)
3950  !
3951  IF ( hsnowmetamo=='B92' ) THEN
3952  !
3953  IF ( osnowdrift ) THEN
3954  psnowgran1f(jj) = -xgran
3955  psnowgran2f(jj) = xnsph3
3956  ELSE
3957  psnowgran1f(jj) = max( min( xnden1*zwind_grain(jj)-xnden2, xnden3 ), -xgran )
3958  psnowgran2f(jj) = min( max( xnsph1*zwind_grain(jj)+xnsph2, xnsph3 ), xnsph4 )
3959  END IF
3960  !
3961  ELSE
3962  !
3963  IF ( osnowdrift ) THEN
3964  psnowgran1f(jj) = xvdiam6
3965  psnowgran2f(jj) = xnsph3/xgran
3966  ELSE
3967  psnowgran2f(jj) = min( max( xnsph1*zwind_grain(jj)+xnsph2, xnsph3 ), xnsph4 ) / xgran
3968  zcoef = max( min( xnden1*zwind_grain(jj)-xnden2, xnden3 ), -xgran ) / ( -xgran )
3969  psnowgran1f(jj) = xvdiam6 * &
3970  ( zcoef + ( 1.- zcoef ) * &
3971  ( 3.*psnowgran2f(jj) + 4.*(1.-psnowgran2f(jj)) ) )
3972  END IF
3973  !
3974  ENDIF
3975  !
3976  psnowhistf(jj) = 0.0
3977  psnowagef(jj) = 0.0
3978  gsnowfall(jj) = .true.
3979  omodif_grid(jj) = .true.
3980  !
3981  ENDIF
3982  !
3983 ENDDO
3984 !
3985 ! intialize the albedo:
3986 ! penser a changer 0.000001 par XUEPSI
3987 IF(oglacier)THEN
3988  zansmax(:) = xaglamax * ppermsnowfrac(:) + xansmax * (1.0-ppermsnowfrac(:))
3989 ELSE
3990  zansmax(:) = xansmax
3991 ENDIF
3992 !
3993 WHERE( gsnowfall(:) .AND. abs(psnow(:)-zsnowfall(:))< 0.000001 )
3994  psnowalb(:) = zansmax(:)
3995 END WHERE
3996 !
3997 ! Computation of the new grid size
3998 ! It starts with successive exclusive cases
3999 ! Each case is described inside the corresponding condition
4000 !
4001 ! cases with fresh snow
4002 !
4003 DO jj=1,SIZE(psnow(:)) ! grid point loop
4004  !
4005  IF( .NOT.gsnowfall(jj) .AND. psnow(jj)>=xsnowcritd .AND. knlvls_use(jj)>=inlvlsmin ) THEN
4006  !
4007  ! no fresh snow + deep enough snowpack + enough snow layers ==> no change
4008  !
4009  ELSEIF( psnow(jj)<xsnowcritd .OR. knlvls_use(jj)<inlvlsmin .OR. psnow(jj)==zsnowfall(jj) ) THEN
4010  !
4011  ! too shallow snowpack or too few layers or only fresh snow
4012  ! ==> uniform grid and identical snow layers / number depends on snow depth
4013  omodif_grid(jj) = .true.
4014  knlvls_use(jj) = max( inlvlsmin, min( inlvlsmax, int(psnow(jj)*xscale_cm) ) )
4015  psnowdzn(jj,1:knlvls_use(jj)) = psnow(jj) / knlvls_use(jj)
4016  !
4017  ELSE
4018  !
4019  ! fresh snow over snow covered ground + enough snow layers
4020  omodif_grid(jj) = .true.
4021  zdiftype_sup = snow3ldiftyp( psnowgran1(jj,1),psnowgran1f(jj), &
4022  psnowgran2(jj,1),psnowgran2f(jj),hsnowmetamo )
4023  !
4024  IF ( ( zdiftype_sup<xdiff_1 .AND. psnowdz(jj,1)< zdzopt(jj,1) ) .OR. &
4025  ( psr(jj)<xsnowfall_threshold .AND. psnowdz(jj,1)<2.*zdzopt(jj,1) ) .OR. &
4026  psnowdz(jj,1)<xdzmin_top_extrem ) THEN
4027  !
4028  ! Fresh snow is similar to a shallow surface layer (< ZDZOPT)
4029  ! or snowfall is very low and the surface layer not too deep (< 2*ZDZOPT) [NEW CONDITION 11/2012]
4030  ! or the surface layer is extremely thin (< XDZMIN_TOP_EXTREM) [NEW CONDITION 11/2012]
4031  ! The two new conditions are necessary for forcings with very low precipitation
4032  ! (e.g. ERA interim reanalyses, or climate models)
4033  ! ==> fresh snow is agregated to the surface layer
4034  psnowdzn(jj,1) = psnowdz(jj,1) + psnowdzf(jj)
4035  DO jst = knlvls_use(jj),2,-1
4036  psnowdzn(jj,jst) = psnowdz(jj,jst)
4037  ENDDO
4038  !
4039  ELSEIF ( knlvls_use(jj)<inlvlsmax ) THEN
4040  !
4041  ! fresh snow is too different from the surface or the surface is too deep
4042  ! and there is room for extra layers ==> we create a new layer
4043  knlvls_use(jj)=knlvls_use(jj)+1
4044  !
4045  IF ( psnowdzf(jj)>xratio_newlayer*psnowdz(jj,2) ) THEN
4046  !
4047  ! Snowfall is sufficient to create a new layer not lower than 1/10 of the second layer
4048  psnowdzn(jj,1) = psnowdzf(jj)
4049  DO jst = knlvls_use(jj),2,-1
4050  psnowdzn(jj, jst) = psnowdz(jj,jst-1)
4051  ENDDO
4052  !
4053  ELSE
4054  ! The ratio would be lower than 1/10 : [NEW : 11/2012]
4055  ! aggregate a part of the old layer with fresh snow to limit the ratio to 1/10.
4056  zsnow2l = psnowdzf(jj) + psnowdz(jj,1)
4057  psnowdzn(jj,1) = xratio_newlayer * zsnow2l
4058  psnowdzn(jj,2) = (1.-xratio_newlayer) * zsnow2l
4059  DO jst = knlvls_use(jj),3,-1
4060  psnowdzn(jj,jst) = psnowdz(jj,jst-1)
4061  ENDDO
4062  !
4063  ENDIF
4064  !
4065  ELSE
4066  !
4067  ! fresh snow is too different from the surface or the surface is too deep
4068  ! and there is no room for extra layers
4069  ! ==> we agregate internal most similar snowlayers and create a new surface layer
4070  jj_a_agreg_sup = 1
4071  jj_a_agreg_inf = 2
4072  !
4073  DO jst = 1,knlvls_use(jj)
4074  !
4075  IF ( jst>1 ) THEN
4076  !
4077  zcritsize_sup = xscale_diff * ( psnowdz(jj,jst) /zdzopt(jj,jst) + &
4078  psnowdz(jj,jst-1)/zdzopt(jj,jst-1) )
4079  zdiftype_sup = snow3ldiftyp( psnowgran1(jj,jst-1),psnowgran1(jj,jst), &
4080  psnowgran2(jj,jst-1),psnowgran2(jj,jst), &
4081  hsnowmetamo )
4082  !
4083  IF ( zdiftype_sup+zcritsize_sup<zpenalty ) THEN
4084  zpenalty = zdiftype_sup + zcritsize_sup
4085  jj_a_agreg_sup = jst - 1
4086  jj_a_agreg_inf = jst
4087  ENDIF
4088  !
4089  ENDIF
4090  !
4091  IF ( jst<knlvls_use(jj) ) THEN
4092  !
4093  zcritsize_inf = xscale_diff * ( psnowdz(jj,jst) /zdzopt(jj,jst) + &
4094  psnowdz(jj,jst+1)/zdzopt(jj,jst+1) )
4095  !
4096  IF ( jst==1 ) THEN
4097  zdiftype_inf = snow3ldiftyp( psnowgran1(jj,1),psnowgran1f(jj), &
4098  psnowgran2(jj,1),psnowgran2f(jj), &
4099  hsnowmetamo)
4100  !
4101  zpenalty = zdiftype_inf + zcritsize_inf
4102  ELSE
4103  zdiftype_inf = snow3ldiftyp( psnowgran1(jj,jst+1),psnowgran1(jj,jst), &
4104  psnowgran2(jj,jst+1),psnowgran2(jj,jst), &
4105  hsnowmetamo)
4106  !
4107  IF ( zdiftype_inf+zcritsize_inf<zpenalty ) THEN
4108  zpenalty = zdiftype_inf + zcritsize_inf
4109  jj_a_agreg_sup = jst
4110  jj_a_agreg_inf = jst + 1
4111  ENDIF
4112  ENDIF
4113  !
4114  ENDIF
4115  !
4116  ENDDO
4117  !
4118  ! agregation of the similar layers and shift of upper layers
4119  psnowdzn(jj,jj_a_agreg_inf) = psnowdz(jj,jj_a_agreg_inf) + psnowdz(jj,jj_a_agreg_sup)
4120  DO jst = jj_a_agreg_sup,2,-1
4121  psnowdzn(jj,jst) = psnowdz(jj,jst-1)
4122  ENDDO
4123  psnowdzn(jj,1) = psnowdzf(jj)
4124  !
4125  ! Limit the ratio between the new layer and the one beneath (ratio 1/10)
4126  ! [NEW : 11/2012]
4127  IF( psnowdzn(jj,1)<xratio_newlayer*psnowdzn(jj,2) ) THEN
4128  zsnow2l = psnowdzn(jj,1) + psnowdzn(jj,2)
4129  psnowdzn(jj,1) = xratio_newlayer * zsnow2l
4130  psnowdzn(jj,2) = (1.-xratio_newlayer) * zsnow2l
4131  ENDIF
4132  !
4133  ENDIF
4134  !
4135  ENDIF ! end of the case with fresh snow
4136  !
4137 ENDDO ! end loop grid points
4138 !
4139 ! cases with no fresh snow and no previous grid resize
4140 !
4141 IF ( inlvlsmin==inlvlsmax ) THEN ! specific case with INLSVSMIN = INLVLSMAX (INLVLS)
4142  !
4143  ! check if surface layer depth is too small
4144  ! in such a case looks for an other layer to be split
4145  DO jj = 1,SIZE(psnow(:)) ! loop grid points
4146  !
4147  IF ( .NOT.omodif_grid(jj) .AND. psnowdz(jj,1)<xdzmin_top ) THEN
4148  omodif_grid(jj) = .true.
4149  CALL get_snowdzn_deb(inlvls,psnowdz(jj,:),zdzopt(jj,:),psnowdzn(jj,:))
4150  gagreg_surf(jj) = .true.
4151  ENDIF
4152  ! check if bottom layer depth is too small
4153  ! in such a case agregation with upper layer and
4154  ! looks for an other layer to be splitted
4155  IF( .NOT.omodif_grid(jj) .AND. psnowdz(jj,inlvls)<xdzmin_top ) THEN
4156  omodif_grid(jj) = .true.
4157  CALL get_snowdzn_end(inlvls,psnowdz(jj,:),zdzopt(jj,:),psnowdzn(jj,:))
4158  ENDIF
4159  !
4160  ENDDO ! end grid points loop
4161  !
4162 ENDIF ! end specific case INLSVSMIN = INLVLSMAX
4163 !
4164 ! case without new snowfall and INVLS > INLVLSMIN
4165 !
4166 DO jj=1,SIZE(psnow(:))
4167  !
4168  ! check if surface layer depth is too small
4169  ! in such a case agregation with layer beneath
4170  ! in case of reaching INLVLSMIN, looks for an other layer to be splitted
4171  IF( .NOT.gsnowfall(jj) .AND. psnow(jj)>xsnowcritd .AND. &
4172  .NOT.omodif_grid(jj) .AND. psnowdz(jj,1)<xdzmin_top_bis ) THEN ! case shallow surface layer
4173  !
4174  omodif_grid(jj) = .true.
4175  !
4176  IF( knlvls_use(jj)>inlvlsmin ) THEN ! case minimum not reached
4177  knlvls_use(jj) = knlvls_use(jj) - 1
4178  psnowdzn(jj,1) = psnowdz(jj,1) + psnowdz(jj,2)
4179  DO jst = 2,knlvls_use(jj)
4180  psnowdzn(jj,jst) = psnowdz(jj,jst+1)
4181  ENDDO
4182  ELSE ! case minimum reached
4183  CALL get_snowdzn_deb(knlvls_use(jj),psnowdz(jj,:),zdzopt(jj,:),psnowdzn(jj,:))
4184  ENDIF ! end case minimum reached end case shallow surface layer
4185  !
4186  gagreg_surf(jj) = .true.
4187  !
4188  ENDIF
4189  !
4190  ! check if bottom layer depth is too small
4191  ! in such a case agregation with above layer
4192  ! in case of reaching INLVLSMIN, looks for an other layer to be splitted
4193  ! case shallow bottom layer
4194  IF( .NOT.gsnowfall(jj) .AND. psnow(jj)> xsnowcritd .AND. &
4195  .NOT.omodif_grid(jj) .AND. psnowdz(jj,knlvls_use(jj))<xdzmin_top .AND. &
4196  .NOT.gagreg_surf(jj) ) THEN
4197  !
4198  omodif_grid(jj) = .true.
4199  !
4200  IF ( knlvls_use(jj)>inlvlsmin ) THEN ! case minimum not reached
4201  knlvls_use(jj) = knlvls_use(jj) - 1
4202  psnowdzn(jj,knlvls_use(jj)) = psnowdz(jj,knlvls_use(jj)) + psnowdz(jj,knlvls_use(jj)+1)
4203  ELSE ! case minimum reached
4204  CALL get_snowdzn_end(knlvls_use(jj),psnowdz(jj,:),zdzopt(jj,:),psnowdzn(jj,:))
4205  ENDIF ! end case minimum reached end case shallow surface layer
4206  !
4207  ENDIF
4208  !
4209 ENDDO ! end grid points loop
4210 !
4211 ! case whithout new snow fall and without a previous grid resize
4212 ! looks for a shallow layer to be splitted according to its depth and to
4213 ! the optimal grid size
4214 DO jj = 1,SIZE(psnow(:))
4215  !
4216  IF ( .NOT.omodif_grid(jj) .AND. inlvls_use(jj)<inlvls-3 )THEN
4217  !
4218  DO jst = 1,inlvls-4
4219  !
4220  IF ( jst<=knlvls_use(jj) .AND. .NOT.omodif_grid(jj) ) THEN
4221  !
4222  IF( psnowdz(jj,jst) > &
4223  ( xsplit_coef - float( inlvls-knlvls_use(jj) )/max( 1., float( inlvls-inlvlsmin ) ) ) &
4224  * zdzopt(jj,jst) ) THEN
4225  !
4226  DO jst_1 = knlvls_use(jj)+1,jst+2,-1
4227  psnowdzn(jj,jst_1) = psnowdz(jj,jst_1-1)
4228  zdzopt(jj,jst_1) = zdzopt(jj,jst_1-1)
4229  ENDDO
4230  !
4231  ! generale case : old layer divided in two equal layers
4232  IF ( jst/=1 .OR. psnowdz(jj,jst)<3.*zdzopt(jj,1) ) THEN
4233  psnowdzn(jj,jst+1) = 0.5*psnowdz(jj,jst)
4234  psnowdzn(jj,jst) = psnowdzn(jj,jst+1)
4235  ELSE
4236  ! if thick surface layer : force the surface layer to this value to avoid successive resizing
4237  ! [NEW : 11/2012]
4238  psnowdzn(jj,1) = 1.5 * zdzopt(jj,1)
4239  psnowdzn(jj,2) = psnowdz(jj,jst) - psnowdzn(jj,1)
4240  ENDIF
4241  !
4242  knlvls_use(jj) = knlvls_use(jj) + 1
4243  omodif_grid(jj) = .true.
4244  !
4245  ENDIF
4246  !
4247  ENDIF
4248  !
4249  ENDDO
4250  !
4251  ENDIF
4252  !
4253 ENDDO
4254 !
4255 ! case whithout new snow fall and without a previous grid resize
4256 ! looks for a deep layer to be agregated to the layer beneath if similar
4257 ! according to its depth and to the optimal grid size
4258 !
4259 !NB : allow these changes for 5 layers and more [NEW] (before : 6 layers)
4260 !
4261 DO jj = 1,SIZE(psnow(:))
4262  !
4263  IF ( .NOT.omodif_grid(jj) ) THEN
4264  !
4265  DO jst = 2,inlvls
4266  !
4267  IF ( jst<=knlvls_use(jj)-1 .AND. knlvls_use(jj)>inlvlsmin+1 .AND. .NOT.omodif_grid(jj) ) THEN
4268  !
4269  zdiftype_inf = snow3ldiftyp( psnowgran1(jj,jst+1),psnowgran1(jj, jst), &
4270  psnowgran2(jj,jst+1),psnowgran2(jj, jst), &
4271  hsnowmetamo)
4272  zdiftype_inf = max( xdiff_1, min( xdiff_max, zdiftype_inf ) )
4273  !
4274  IF( psnowdz(jj,jst) < zdzopt(jj,jst) * xagreg_coef_1 / zdiftype_inf .AND. &
4275  psnowdz(jj,jst) + psnowdz(jj,jst+1) < &
4276  xagreg_coef_2 * max( zdzopt(jj,jst),zdzopt(jj,jst+1) ) ) THEN
4277  !
4278  psnowdzn(jj,jst) = psnowdz(jj,jst) + psnowdz(jj,jst+1)
4279  zdzopt(jj,jst) = zdzopt(jj,jst+1)
4280  DO jst_1 = jst+1,knlvls_use(jj)-1
4281  psnowdzn(jj,jst_1) = psnowdz(jj,jst_1+1)
4282  zdzopt(jj,jst_1) = zdzopt(jj,jst_1+1)
4283  ENDDO
4284  knlvls_use(jj) = knlvls_use(jj)-1
4285  omodif_grid(jj)=.true.
4286  !
4287  ENDIF
4288  !
4289  ENDIF
4290  !
4291  ENDDO
4292  !
4293  ENDIF
4294  !
4295 ENDDO
4296 !
4297 ! [NEW : 11/2012]
4298 ! In case of very low snow fall checks if a new internal snow layer is too shallow
4299 ! even if a the grid has already been resized in this time step
4300 ! starts from bottom to INLVS_USE-3 until old and new grid differ
4301 DO jj = 1,SIZE(psnow(:))
4302  !
4303  IF ( .NOT.gsnowfall(jj) .OR. knlvls_use(jj)<inlvlsmin+3 ) cycle ! go to next point
4304  !
4305  IF( abs( psnowdzn(jj,knlvls_use(jj)) - psnowdz(jj,knlvls_use(jj)) ) > xuepsi ) cycle ! go to next point
4306  !
4307  ! bottom layer
4308  IF( psnowdzn(jj,knlvls_use(jj))<xdzmin_top ) THEN ! case shallow bottom layer
4309  !
4310  knlvls_use(jj) = knlvls_use(jj)-1
4311  psnowdzn(jj,knlvls_use(jj)) = psnowdzn(jj,knlvls_use(jj)) + psnowdzn(jj,knlvls_use(jj)+1)
4312  psnowdzn(jj,knlvls_use(jj)+1) = 0.
4313  !
4314  ELSE
4315  !
4316  ! internal layer
4317  DO jst = knlvls_use(jj)-1,4,-1
4318  !
4319  IF ( abs( psnowdzn(jj,jst) - psnowdz(jj,jst) ) > xuepsi ) EXIT ! old/new grid differ ==> go to next grid point
4320  !
4321  IF ( psnowdzn(jj,jst)> 0.001 ) cycle
4322  !
4323  ! If an internal layer is too shallow, it is merged with the upper layer
4324  psnowdzn(jj,jst-1) = psnowdzn(jj,jst) + psnowdzn(jj,jst-1)
4325  knlvls_use(jj) = knlvls_use(jj) - 1
4326  !
4327  ! shifts the lower layers
4328  DO jst_1 = jst,inlvls_use(jj)
4329  psnowdzn(jj,jst_1) = psnowdz(jj,jst_1+1)
4330  zdzopt(jj,jst_1) = zdzopt(jj,jst_1+1)
4331  ENDDO
4332  psnowdzn(jj,inlvls_use(jj)+1) = 0.
4333  !
4334  EXIT ! goto to next grid point
4335  !
4336  ENDDO ! end loop internal layers
4337  !
4338  ENDIF
4339  !
4340 ENDDO ! end grid loops for checking shallow layers
4341 !
4342 !final check of the consistensy of the new grid size
4343 !
4344 DO jj = 1,SIZE(psnow(:))
4345  !
4346  IF ( abs( sum( psnowdzn(jj,1:knlvls_use(jj)) ) - psnow(jj) ) > xuepsi ) THEN
4347  !
4348  WRITE(*,*) 'error in grid resizing', jj, knlvls_use(jj), sum( psnowdzn(jj,1:knlvls_use(jj)) ), &
4349  psnow(jj), sum( psnowdzn(jj,1:inlvls_use(jj)) )-psnow(jj), &
4350  zsnowfall(jj)
4351  WRITE( *,*) 'JJ , PSNOWDZ(JJ):',jj , psnowdz(jj,:)
4352  WRITE( *,*) 'JJ , PSNOWDZN(JJ):',jj , psnowdzn(jj,:)
4353  !
4354  CALL abor1_sfx("SNOWCRO: error in grid resizing")
4355  !
4356  ENDIF
4357  !
4358 ENDDO
4359 !
4360 IF (lhook) CALL dr_hook('SNOWNLFALL_UPGRID',1,zhook_handle)
4361 !
4362 END SUBROUTINE snownlfall_upgrid
4363 
4364 !###############################################################################
4365 SUBROUTINE get_snowdzn_deb(KNLVLS,PSNOWDZ,PDZOPT,PSNOWDZN)
4366 !
4367 USE modd_snow_par, ONLY : xdzmin_top, xdzmin_bot
4368 !
4369 IMPLICIT NONE
4370 !
4371 INTEGER, INTENT(IN) :: knlvls
4372 REAL, DIMENSION(:), INTENT(IN) :: psnowdz, pdzopt
4373 REAL, DIMENSION(:), INTENT(OUT) :: psnowdzn
4374 !
4375 REAL :: zpenalty, zcritsize
4376 INTEGER :: jj_a_dedoub, jst
4377 !
4378 REAL(KIND=JPRB) :: zhook_handle
4379 !
4380 IF (lhook) CALL dr_hook('SNOWCRO:GET_SNOWDZN_DEB',0,zhook_handle)
4381 !
4382 zpenalty = psnowdz(2) / pdzopt(2)
4383 IF( psnowdz(2)<xdzmin_top ) zpenalty = 0.
4384 jj_a_dedoub = 2
4385 !
4386 DO jst = 3,knlvls
4387  zcritsize = psnowdz(jst) / pdzopt(jst)
4388  IF ( jst==knlvls .AND. psnowdz(jst)<xdzmin_bot ) zcritsize = 0.
4389  IF ( zcritsize>zpenalty ) THEN
4390  zpenalty = zcritsize
4391  jj_a_dedoub = jst
4392  ENDIF
4393 ENDDO
4394 !
4395 IF ( jj_a_dedoub==2 ) THEN ! case splitted layer == 2
4396  psnowdzn(1) = 0.5 * ( psnowdz(1) + psnowdz(2) )
4397  psnowdzn(2) = psnowdzn(1)
4398 ELSE ! case splitted layer =/ 2
4399  psnowdzn(1) = psnowdz(1) + psnowdz(2)
4400  DO jst = 2,jj_a_dedoub-2
4401  psnowdzn(jst) = psnowdz(jst+1)
4402  ENDDO
4403  psnowdzn(jj_a_dedoub-1) = 0.5 * psnowdz(jj_a_dedoub)
4404  psnowdzn(jj_a_dedoub) = psnowdzn(jj_a_dedoub-1)
4405 ENDIF ! end case splitted layer =/ 2
4406 !
4407 IF (lhook) CALL dr_hook('SNOWCRO:GET_SNOWDZN_DEB',1,zhook_handle)
4408 !
4409 END SUBROUTINE get_snowdzn_deb
4410 !
4411 !###############################################################################
4412 SUBROUTINE get_snowdzn_end(KNLVLS,PSNOWDZ,PDZOPT,PSNOWDZN)
4413 !
4414 USE modd_snow_par, ONLY : xdzmin_top, xdzmin_bot
4415 !
4416 IMPLICIT NONE
4417 !
4418 INTEGER, INTENT(IN) :: knlvls
4419 REAL, DIMENSION(:), INTENT(IN) :: psnowdz, pdzopt
4420 REAL, DIMENSION(:), INTENT(OUT) :: psnowdzn
4421 !
4422 REAL :: zpenalty, zcritsize
4423 INTEGER :: jj_a_dedoub, jst
4424 !
4425 REAL(KIND=JPRB) :: zhook_handle
4426 !
4427 IF (lhook) CALL dr_hook('SNOWCRO:GET_SNOWDZN_END',0,zhook_handle)
4428 !
4429 zpenalty = psnowdz(knlvls-2) / pdzopt(knlvls-2)
4430 jj_a_dedoub = knlvls - 2
4431 !
4432 DO jst = max(1,knlvls-3),1,-1
4433  zcritsize = psnowdz(jst) / pdzopt(jst)
4434  IF ( jst==1 .AND. psnowdz(jst)<xdzmin_bot ) zcritsize = 0.
4435  IF ( zcritsize>zpenalty ) THEN
4436  zpenalty = zcritsize
4437  jj_a_dedoub = jst
4438  ENDIF
4439 ENDDO
4440 !
4441 IF ( jj_a_dedoub==knlvls-1 ) THEN ! case splitted layer == 2
4442  psnowdzn(knlvls) = 0.5 * (psnowdz(knlvls-1)+psnowdz(knlvls))
4443  psnowdzn(knlvls-1) = psnowdzn(knlvls)
4444 ELSE ! case splitted layer =/ 2
4445  psnowdzn(knlvls) = psnowdz(knlvls-1) + psnowdz(knlvls)
4446  DO jst = knlvls-1,jj_a_dedoub+2,-1
4447  psnowdzn(jst) = psnowdz(jst-1)
4448  ENDDO
4449  psnowdzn(jj_a_dedoub+1) = 0.5 * psnowdz(jj_a_dedoub)
4450  psnowdzn(jj_a_dedoub ) = psnowdzn(jj_a_dedoub+1)
4451 ENDIF ! end case splitted layer =/ 2
4452 !
4453 IF (lhook) CALL dr_hook('SNOWCRO:GET_SNOWDZN_END',1,zhook_handle)
4454 !
4455 END SUBROUTINE get_snowdzn_end
4456 !
4457 !###############################################################################
4458 !################################################################################
4459 !################################################################################
4460 !
4461 SUBROUTINE snownlgridfresh_1d (KJ,PSNOW,PSNOWDZ,PSNOWDZN, &
4462  psnowrho,psnowheat,psnowgran1,psnowgran2, &
4463  psnowhist,psnowage,gsnowfall, &
4464  psnowrhof, psnowdzf,psnowheatf,psnowgran1f, &
4465  psnowgran2f, psnowhistf,psnowagef, &
4466  knlvls_use, hsnowmetamo )
4467 !
4468 !! PURPOSE
4469 !! -------
4470 ! Snow mass,heat and characteristics redistibution in case of
4471 ! grid resizing. Total mass and heat content of the overall snowpack
4472 ! unchanged/conserved within this routine.
4473 ! Grain size and type of mixed layers is deduced from the conservation
4474 ! of the average optical size
4475 !
4476 !! AUTHOR
4477 !! ------
4478 !! E. Brun * Meteo-France *
4479 !!
4480 !
4481 USE modd_snow_par, ONLY : xd1,xd2,xd3,xx,xvalb5,xvalb6
4482 USE mode_snow3l, ONLY : get_mass_heat
4483 !
4484 IMPLICIT NONE
4485 !
4486 !
4487 !* 0.1 declarations of arguments
4488 !
4489 INTEGER, INTENT(IN) :: kj
4490 REAL, INTENT(IN) :: psnow
4491 !
4492 REAL, DIMENSION(:), INTENT(INOUT) :: psnowheat, psnowrho, psnowdz, &
4493  psnowdzn, psnowgran1, psnowgran2, &
4494  psnowhist
4495 REAL, DIMENSION(:), INTENT(INOUT) :: psnowage
4496 REAL, INTENT(IN) :: psnowrhof, psnowdzf,psnowheatf, &
4497  psnowgran1f,psnowgran2f, psnowhistf
4498 REAL, INTENT(IN) :: psnowagef
4499 !
4500 INTEGER, INTENT(IN) :: knlvls_use
4501 !
4502 LOGICAL, INTENT(IN) :: gsnowfall
4503 !
4504  CHARACTER(3),INTENT(IN) :: hsnowmetamo
4505 !
4506 !* 0.2 declarations of local variables
4507 !
4508 REAL, DIMENSION(SIZE(PSNOWRHO,1)+1) :: zsnowrhoo,zsnowgran1o,zsnowgran2o, &
4509  zsnowheato,zsnowhisto,zsnowdzo, &
4510  zsnowztop_old,zsnowzbot_old
4511 REAL,DIMENSION(SIZE(PSNOWRHO,1)+1) :: zsnowageo
4512 !
4513 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zsnowrhon,zsnowgran1n,zsnowgran2n, &
4514  zsnowheatn,zsnowhistn, &
4515  zsnowztop_new,zsnowzbot_new
4516 REAL,DIMENSION(SIZE(PSNOWRHO,1)) ::zsnowagen
4517 !
4518 REAL :: zmastotn, zmastoto, zsnowhean, zsnowheao
4519 REAL :: zpsnow_old, zpsnow_new
4520 !
4521 INTEGER :: inlvls_old, inlvls_new
4522 INTEGER :: jst
4523 !
4524 LOGICAL :: gdiam
4525 !
4526 REAL(KIND=JPRB) :: zhook_handle
4527 !-------------------------------------------------------------------------------
4528 IF (lhook) CALL dr_hook('SNOWNLGRIDFRESH_1D',0,zhook_handle)
4529 !
4530 ! 0. Initialization:
4531 ! ------------------
4532 !
4533 ! starts by checking the consistency between both vertical grid sizes
4534 inlvls_new = knlvls_use
4535 inlvls_old = -1
4536 !
4537 zpsnow_new = 0.
4538 zpsnow_old = 0.
4539 !
4540 DO jst = 1,inlvls_new
4541  zpsnow_new = zpsnow_new + psnowdzn(jst)
4542 ENDDO
4543 !
4544 IF ( abs( zpsnow_new - psnowdzf )<xuepsi ) THEN
4545  inlvls_old = 0
4546 ELSE
4547  DO jst = 1,SIZE(psnowrho)
4548  IF ( psnowdz(jst)>=xuepsi ) THEN
4549  zpsnow_old = zpsnow_old + psnowdz(jst)
4550  IF ( abs( zpsnow_new - psnowdzf - zpsnow_old )<xuepsi ) THEN
4551  inlvls_old = jst
4552  ENDIF
4553  ENDIF
4554  ENDDO
4555  IF ( inlvls_old==-1 ) THEN
4556  WRITE(*,*)'pb INLVLS_OLD INLVLS_NEW=',inlvls_new
4557  WRITE(*,*)'pb INLVLS_OLD',psnowdzf
4558  WRITE(*,*)'pb INLVLS_OLD',psnowdzn
4559  WRITE(*,*)'pb INLVLS_OLD',psnowdz
4560  CALL abor1_sfx('SNOWCRO: Error INLVLS_OLD')
4561  ENDIF
4562 ENDIF
4563 !
4564 IF ( gsnowfall ) inlvls_old = inlvls_old + 1
4565 !
4566 zpsnow_old = psnow
4567 zpsnow_new = zpsnow_old
4568 !
4569 ! initialization of variables describing the initial snowpack + new snowfall
4570 !
4571 IF ( gsnowfall ) THEN
4572  DO jst = 2,inlvls_old
4573  zsnowdzo(jst) = psnowdz(jst-1)
4574  zsnowrhoo(jst) = psnowrho(jst-1)
4575  zsnowheato(jst) = psnowheat(jst-1)
4576  zsnowgran1o(jst) = psnowgran1(jst-1)
4577  zsnowgran2o(jst) = psnowgran2(jst-1)
4578  zsnowhisto(jst) = psnowhist(jst-1)
4579  zsnowageo(jst) = psnowage(jst-1)
4580  ENDDO
4581  zsnowdzo(1) = psnowdzf
4582  zsnowrhoo(1) = psnowrhof
4583  zsnowheato(1) = psnowheatf
4584  zsnowgran1o(1) = psnowgran1f
4585  zsnowgran2o(1) = psnowgran2f
4586  zsnowhisto(1) = psnowhistf
4587  zsnowageo(1) = psnowagef
4588 ELSE
4589  DO jst = 1,inlvls_old
4590  zsnowdzo(jst) = psnowdz(jst)
4591  zsnowrhoo(jst) = psnowrho(jst)
4592  zsnowheato(jst) = psnowheat(jst)
4593  zsnowgran1o(jst) = psnowgran1(jst)
4594  zsnowgran2o(jst) = psnowgran2(jst)
4595  zsnowhisto(jst) = psnowhist(jst)
4596  zsnowageo(jst) = psnowage(jst)
4597  ENDDO
4598 ENDIF
4599 !
4600 ! 1. Calculate vertical grid limits (m):
4601 ! --------------------------------------
4602 !
4603 zsnowztop_old(1) = zpsnow_old
4604 zsnowztop_new(1) = zpsnow_new
4605 !
4606 DO jst = 1,inlvls_old
4607  IF ( jst>1 ) zsnowztop_old(jst) = zsnowzbot_old(jst-1)
4608  zsnowzbot_old(jst) = zsnowztop_old(jst) - zsnowdzo(jst)
4609 ENDDO
4610 !
4611 DO jst = 1,inlvls_new
4612  IF ( jst>1 ) zsnowztop_new(jst) = zsnowzbot_new(jst-1)
4613  zsnowzbot_new(jst) = zsnowztop_new(jst) - psnowdzn(jst)
4614 ENDDO
4615 !
4616 ! Check consistency
4617 IF ( abs(zsnowzbot_old(inlvls_old)) > 0.00001 ) WRITE (*,*) 'Error bottom OLD'
4618 !
4619 zsnowzbot_old(inlvls_old) = 0.
4620 !
4621 ! Check consistency
4622 if ( abs(zsnowzbot_new(inlvls_new)) > 0.00001 ) WRITE (*,*) 'Error bottom NEW'
4623 !
4624 zsnowzbot_new(inlvls_new) = 0.
4625 !
4626 ! 3. Calculate mass, heat, charcateristics mixing due to vertical grid resizing:
4627 ! --------------------------------------------------------------------
4628 !
4629 ! loop over the new snow layers
4630 ! Summ or avergage of the constituting quantities of the old snow layers
4631 ! which are totally or partially inserted in the new snow layer
4632  CALL get_mass_heat(kj,inlvls_new,inlvls_old, &
4633  zsnowztop_old,zsnowztop_new,zsnowzbot_old,zsnowzbot_new, &
4634  zsnowrhoo,zsnowdzo,zsnowgran1o,zsnowgran2o,zsnowhisto, &
4635  zsnowageo,zsnowheato, &
4636  zsnowrhon,psnowdzn,zsnowgran1n,zsnowgran2n,zsnowhistn, &
4637  zsnowagen,zsnowheatn,hsnowmetamo )
4638 !
4639 ! check of consistency between new and old snowpacks
4640 zsnowhean = 0.
4641 zmastotn = 0.
4642 zsnowheao = 0.
4643 zmastoto = 0.
4644 zpsnow_new = 0.
4645 zpsnow_old = 0.
4646 !
4647 DO jst = 1,inlvls_new
4648  zsnowhean = zsnowhean + zsnowheatn(jst)
4649  zmastotn = zmastotn + zsnowrhon(jst) * psnowdzn(jst)
4650  zpsnow_new = zpsnow_new + psnowdzn(jst)
4651 ENDDO
4652 !
4653 DO jst = 1,inlvls_old
4654  zsnowheao = zsnowheao + zsnowheato(jst)
4655  zmastoto = zmastoto + zsnowrhoo(jst) * zsnowdzo(jst)
4656  zpsnow_old = zpsnow_old + zsnowdzo(jst)
4657 ENDDO
4658 !
4659 IF ( abs( zsnowhean-zsnowheao )>0.0001 .OR. abs( zmastotn-zmastoto )>0.0001 .OR. &
4660  abs( zpsnow_new-zpsnow_old )> 0.0001 ) THEN
4661  WRITE(*,*) 'Warning diff', zsnowhean-zsnowheao,zmastotn-zmastoto,zpsnow_new-zpsnow_old
4662 ENDIF
4663 !
4664 ! 5. Update mass (density and thickness) and heat:
4665 ! ------------------------------------------------
4666 !
4667 psnowdz(:) = psnowdzn(:)
4668 !
4669 psnowrho(:) = zsnowrhon(:)
4670 psnowheat(:) = zsnowheatn(:)
4671 psnowgran1(:) = zsnowgran1n(:)
4672 psnowgran2(:) = zsnowgran2n(:)
4673 psnowhist(:) = zsnowhistn(:)
4674 !
4675 psnowage(:) = zsnowagen(:)
4676 !
4677 IF (lhook) CALL dr_hook('SNOWNLGRIDFRESH_1D',1,zhook_handle)
4678 !
4679 END SUBROUTINE snownlgridfresh_1d
4680 !####################################################################
4681 !####################################################################
4682 !###################################################################
4683 SUBROUTINE snowdrift(PTSTEP,PVMOD,PSNOWRHO,PSNOWDZ,PSNOW, &
4684  psnowgran1,psnowgran2,psnowhist,knlvls_use, &
4685  pta,pqa,pps,prhoa,pz0eff,puref, &
4686  osnowdrift_sublim,hsnowmetamo,psndrift )
4687 !
4688 !! PURPOSE
4689 !! -------
4690 ! Snow compaction and metamorphism due to drift
4691 ! Mass is unchanged: layer thickness is reduced
4692 ! in proportion to density increases. Method inspired from
4693 ! Brun et al. (1997) and Guyomarch
4694 !
4695 ! - computes a mobility index of each snow layer from its grains, density
4696 ! and history
4697 ! - computes a drift index of each layer from its mobility and wind speed
4698 ! - computes a transport index with an exponential decay taking into
4699 ! account its depth and the mobility of upper layers
4700 ! - increases density and changes grains in case of transport
4701 !
4702 ! HISTORY:
4703 ! Basic parameterization from Crocus/ARPEGE Coupling (1997)
4704 ! Implementation in V5
4705 ! Insertion in V6 of grains type evolution in case of dendritic snow (V.
4706 ! Vionnet)
4707 ! 07/2012 (for V7.3): E. Brun, M. Lafaysse : optional sublimation of drifted snow
4708 ! 2012-09-20 : bug correction : ZFF was not computed if LSNOWDRIFT_SUBLIM=FALSE.
4709 !
4710 ! 2014-02-05 V. Vionnet: systematic use of 5m wind speed to compute drift index
4711 ! 2014-06-03 M. Lafaysse: threshold on PZ0EFF
4712 
4713 USE modd_csts,ONLY : xtt
4714 USE mode_thermos
4715 
4716 USE modd_snow_par, ONLY : xvtime, xvromax, xvromin, xvmob1, &
4717  xvmob2, xvmob3, xvmob4, xvdrift1, xvdrift2, xvdrift3, &
4718  xvsizemin, xcoef_ff, xcoef_effect, xqs_ref
4719 !
4720 IMPLICIT NONE
4721 !
4722 !* 0.1 declarations of arguments
4723 !
4724 REAL, INTENT(IN) :: ptstep
4725 !
4726 REAL, DIMENSION(:), INTENT(IN) :: pta, pqa, pps, prhoa
4727 !
4728 REAL, DIMENSION(:), INTENT(IN) :: pvmod
4729 !
4730 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use
4731 !
4732 REAL, DIMENSION(:),INTENT(IN) :: pz0eff,puref
4733 !
4734 LOGICAL,INTENT(IN) :: osnowdrift_sublim
4735 !
4736  CHARACTER(3), INTENT(IN) :: hsnowmetamo ! metamorphism scheme
4737 !
4738 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowrho, psnowdz,psnowgran1, &
4739  psnowgran2,psnowhist
4740 REAL, DIMENSION(:), INTENT(OUT) :: psnow
4741 REAL, DIMENSION(:), INTENT(OUT) :: psndrift !blowing snow sublimation (kg/m2/s)
4742 !
4743 !* 0.2 declarations of local variables
4744 !
4745 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowrho2
4746 REAL, DIMENSION(SIZE(PSNOWRHO,1) ) :: zsnowdz1
4747 !
4748 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zqsati, zff ! QS wrt ice, gust speed
4749 !
4750 REAL :: zz0eff
4751 !
4752 REAL :: zprofequ, zrmob, zrdrift, zrt, zdro, zdgr1, zdgr2
4753 REAL :: zvt ! 5m wind speed threshold for surface
4754 !transport
4755 REAL :: zqs_effect ! effect of QS on snow
4756 REAL :: zwind_effect ! effect of wind on snow
4757 REAL :: zdrift_effect ! effect of QS and wind on snow
4758 ! transformation
4759 REAL :: zqs !Blowing snow sublimation (kg/m2/s)
4760 REAL :: zrhi, zfact
4761 !
4762 INTEGER :: jj,jst ! looping indexes
4763 !
4764 REAL(KIND=JPRB) :: zhook_handle
4765 !
4766 ! Reference height for wind speed used to dertermine the occurrence of blowing snow
4767 REAL, PARAMETER :: pphref_wind=5.
4768 REAL, PARAMETER :: pphref_min=pphref_wind/2.
4769 !
4770 !-------------------------------------------------------------------------------
4771 IF (lhook) CALL dr_hook('SNOWDRIFT',0,zhook_handle)
4772 !
4773 ! 0. Initialization:
4774 ! ------------------
4775 !
4776 zsnowdz1(:) = psnowdz(:,1)
4777 !
4778 DO jj = 1,SIZE(psnow)
4779  DO jst = 1,knlvls_use(jj)
4780  zsnowrho2(jj,jst) = psnowrho(jj,jst)
4781  ENDDO
4782 ENDDO
4783 !
4784 IF ( osnowdrift_sublim ) THEN
4785  zqsati(:) = qsati( pta(:),pps(:) )
4786 END IF
4787 !
4788 ! 1. Computation of drift and induced settling and metamorphism
4789 ! ------------------
4790 !
4791 DO jj=1, SIZE(psnow)
4792  !
4793  ! gust speed at 5m above the snowpack
4794  ! Computed from PVMOD at PUREF (m) assuming a log profile in the SBL
4795  ! and a roughness length equal to PZ0EFF
4796  zz0eff=min(pz0eff(jj),puref(jj)*0.5,pphref_min)
4797  zff(jj) = xcoef_ff*pvmod(jj)*log(pphref_wind/zz0eff)/log(puref(jj)/zz0eff)
4798  !
4799  ! initialization decay coeff
4800  zprofequ = 0.
4801  !
4802  DO jst = 1,knlvls_use(jj)
4803  !
4804  zfact = 1.25 - 1.25 * ( max( psnowrho(jj,jst), xvromin ) - xvromin )/1000./xvmob1
4805  !
4806  IF ( hsnowmetamo=='B92' ) THEN
4807  !
4808  ! mobility index computation of a layer as a function of its properties
4809  IF( psnowgran1(jj,jst)<0. ) THEN
4810  ! dendritic case
4811  zrmob = 0.34 * ( 0.5 - ( 0.75*psnowgran1(jj,jst) + 0.5*psnowgran2(jj,jst) )/99. ) + &
4812  0.66 * zfact
4813  ELSE
4814  ! non dendritic case
4815  zrmob = 0.34 * ( xvmob2 - xvmob2*psnowgran1(jj,jst)/99. - xvmob3*psnowgran2(jj,jst)*1000. ) + &
4816  0.66 * zfact
4817  ENDIF
4818  !
4819  ELSE
4820  !
4821  IF ( psnowgran1(jj,jst)<xvdiam6*(4.-psnowgran2(jj,jst))-xuepsi ) THEN
4822  ! dendritic case
4823  zrmob = 0.34 * ( 0.5 + 0.75 * &
4824  ( psnowgran1(jj,jst)/xvdiam6-4.+psnowgran2(jj,jst) )/( psnowgran2(jj,jst)-3. ) &
4825  - 0.5 * psnowgran2(jj,jst) ) + &
4826  0.66 * zfact
4827  ELSE
4828  ! non dendritic case
4829  zrmob = 0.34 * ( xvmob2 - xvmob2 * psnowgran2(jj,jst) &
4830  - xvmob3 * (4.-psnowgran2(jj,jst))*xvdiam6*1000. ) + &
4831  0.66 * zfact
4832  ENDIF
4833  !
4834  ENDIF
4835  !
4836  ! correction in case of former wet snow
4837  IF ( psnowhist(jj,jst) >= 2. ) zrmob = min(zrmob, xvmob4)
4838  !
4839  ! computation of drift index supposing no overburden snow
4840  zrdrift = zrmob - ( xvdrift1 * exp( -xvdrift2*zff(jj) ) - 1.)
4841  ! modif_EB exit loop if there is no drift
4842  IF ( zrdrift<=0. ) EXIT
4843  !
4844  ! update the decay coeff by half the current layer
4845  zprofequ = zprofequ + 0.5 * psnowdz(jj,jst) * 0.1 * ( xvdrift3 - zrdrift )
4846  ! computation of the drift index inclunding the decay by overburden snow
4847  zrt = max( 0., zrdrift * exp( -zprofequ*100 ) )
4848  !
4849  IF ( osnowdrift_sublim .AND. jst==1 ) THEN
4850  !Specific case for blowing snow sublimation
4851  ! computation of wind speed threshold QSATI and RH withe respect to ice
4852  zvt = -log( (zrmob+1.)/xvdrift1 ) / xvdrift2
4853  zrhi = pqa(jj) / zqsati(jj)
4854  ! computation of sublimation rate according to Gordon's PhD
4855  zqs = 0.0018 * (xtt/pta(jj))**4 * zvt * prhoa(jj) * zqsati(jj) * &
4856  (1.-zrhi) * (zff(jj)/zvt)**3.6
4857  ! WRITE(*,*) 'surface Vt vent*coef ZRDRIFT ZRMOB :',ZVT,&
4858  ! ZFF(JJ),ZRDRIFT,ZRMOB
4859  ! WRITE(*,*) 'V>Vt ZQS :',ZQS
4860  ! surface depth decrease in case of blowing snow sublimation
4861  ! WRITE(*,*) 'V>Vt DSWE DZ Z:',- MAX(0.,ZQS)*PTSTEP/COEF_FF,
4862  ! - MAX(0.,ZQS)*PTSTEP/COEF_FF/PSNOWRHO(JJ,JST),PSNOWDZ(JJ,JST)
4863  ! 2 lignes ci-dessous a valider pour avoir sublim drift
4864  psnowdz(jj,jst) = max( 0.5*psnowdz(jj,jst), &
4865  psnowdz(jj,jst) - max(0.,zqs) * ptstep/xcoef_ff/psnowrho(jj,jst) )
4866  psndrift(jj) = (zsnowdz1(jj)-psnowdz(jj,jst))*psnowrho(jj,jst)/ptstep
4867  ELSE
4868  zqs = 0.
4869  END IF
4870  !
4871  zqs_effect = min( 3., max( 0.,zqs )/xqs_ref ) * zrt
4872  zwind_effect = xcoef_effect * zrt
4873  zdrift_effect = ( zqs_effect + zwind_effect ) * ptstep / xcoef_ff / xvtime
4874  ! WRITE(*,*) 'ZQS_EFFECT,ZWIND_EFFECT,ZDRIFT_EFFECT:',ZQS_EFFECT,ZWIND_EFFECT,ZDRIFT_EFFECT
4875  !
4876  ! settling by wind transport only in case of not too dense snow
4877  IF( psnowrho(jj,jst) < xvromax ) THEN
4878  zdro = zdrift_effect * ( xvromax - psnowrho(jj,jst) )
4879  psnowrho(jj,jst) = min( xvromax , psnowrho(jj,jst) + zdro )
4880  psnowdz(jj,jst) = psnowdz(jj,jst) * zsnowrho2(jj,jst) / psnowrho(jj,jst)
4881  ENDIF
4882  !
4883  IF ( hsnowmetamo=='B92' ) THEN
4884  !
4885  ! metamorphism induced by snow drift
4886  IF ( psnowgran1(jj,jst)<0. ) THEN
4887  ! dendritic case
4888  zdgr1 = zdrift_effect * ( -psnowgran1(jj,jst) ) * 0.5
4889  psnowgran1(jj,jst) = psnowgran1(jj,jst) + min( zdgr1, -0.99 * psnowgran1(jj,jst) )
4890  ! modif_VV_140910
4891  zdgr2 = zdrift_effect * ( 99. - psnowgran2(jj,jst) )
4892  psnowgran2(jj,jst) = min( 99., psnowgran2(jj,jst) + zdgr2 )
4893  ! fin modif_VV_140910
4894  ELSE
4895  ! non dendritic case
4896  zdgr1 = zdrift_effect * ( 99. - psnowgran1(jj,jst) )
4897  zdgr2 = zdrift_effect * 5. / 10000.
4898  psnowgran1(jj,jst) = min( 99., psnowgran1(jj,jst) + zdgr1 )
4899  psnowgran2(jj,jst) = max( xvsizemin, psnowgran2(jj,jst) - zdgr2 )
4900  ENDIF
4901  !
4902  ELSE
4903  !
4904  ! dendritic case
4905  IF ( psnowgran1(jj,jst)<xvdiam6*(4.-psnowgran2(jj,jst))-xuepsi ) THEN
4906  !
4907  zdgr1 = min( zdrift_effect * ( ( psnowgran1(jj,jst)/xvdiam6-4.+psnowgran2(jj,jst) )/ &
4908  (psnowgran2(jj,jst)-3.) ) * 0.5, &
4909  0.99 * ( ( psnowgran1(jj,jst)/xvdiam6-4.+ psnowgran2(jj,jst))/ &
4910  (psnowgran2(jj,jst)-3.) ) )
4911  zdgr2 = zdrift_effect * ( 1.-psnowgran2(jj,jst) )
4912  !
4913  psnowgran1(jj,jst) = psnowgran1(jj,jst) + xvdiam6 * &
4914  ( zdgr2 * ( (psnowgran1(jj,jst)/xvdiam6-1.)/(psnowgran2(jj,jst)-3.) ) - &
4915  zdgr1 * ( psnowgran2(jj,jst)-3. ) )
4916  psnowgran2(jj,jst) = min(1.,psnowgran2(jj,jst)+zdgr2)
4917  ! non dendritic case
4918  ELSE
4919  !
4920  zdgr1 = zdrift_effect * 5./10000.
4921  zdgr2 = zdrift_effect * (1.-psnowgran2(jj,jst))
4922  !
4923  psnowgran1(jj,jst) = psnowgran1(jj,jst) - 2. * xvdiam6 * psnowgran2(jj,jst) * zdgr2
4924  psnowgran2(jj,jst) = min( 1., psnowgran2(jj,jst)+zdgr2 )
4925  !
4926  ENDIF
4927  !
4928  ENDIF
4929  !
4930  ! update the decay coeff by half the current layer
4931  zprofequ = zprofequ + 0.5 * psnowdz(jj,jst) * 0.1 * ( xvdrift3 - zrdrift )
4932  !
4933  ENDDO ! snow layers loop
4934  !
4935 ENDDO ! grid points loop
4936 !
4937 ! 2. Update total snow depth:
4938 ! -----------------------------------------------
4939 !
4940 ! Compaction of total snowpack depth
4941 !
4942 DO jj = 1,SIZE(psnowdz,1)
4943  psnow(jj) = sum( psnowdz(jj,1:knlvls_use(jj)) )
4944 ENDDO
4945 !
4946 IF (lhook) CALL dr_hook('SNOWDRIFT',1,zhook_handle)
4947 !
4948 END SUBROUTINE snowdrift
4949 !####################################################################
4950 !###################################################################
4951 !####################################################################
4952 !####################################################################
4953 SUBROUTINE snowcrolayer_gone(PTSTEP,PSCAP,PSNOWTEMP,PSNOWDZ, &
4954  psnowrho,psnowliq,psnowgran1,psnowgran2, &
4955  psnowhist,psnowage,ples3l,knlvls_use )
4956 !
4957 !
4958 !! PURPOSE
4959 ! Account for the case when one or several snow layers melt
4960 ! during a time step:
4961 ! in that case, merge these layers with the underlying layer
4962 ! except for the bottom layer which is merged to the abovelying layer
4963 ! energy and mass are conserved
4964 ! a new merged layer keeps the grain, histo and age properties of the
4965 ! non-melted layer
4966 !
4967 USE modd_csts,ONLY : xtt, xlmtt, xrholw, xrholi, xlvtt, xci
4968 !
4969 USE mode_snow3l
4970 !
4971 IMPLICIT NONE
4972 !
4973 !* 0.1 declarations of arguments
4974 !
4975 REAL, INTENT(IN) :: ptstep
4976 !
4977 REAL, DIMENSION(:,:), INTENT(INOUT) :: pscap
4978 !
4979 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowdz, psnowtemp, psnowrho, psnowliq
4980 REAL, DIMENSION(:,:), INTENT(INOUT) :: psnowgran1,psnowgran2,psnowhist,psnowage
4981 !
4982 INTEGER, DIMENSION(:), INTENT(INOUT) :: knlvls_use !
4983 !
4984 REAL, DIMENSION(:), INTENT(IN) :: ples3l
4985 !
4986 !* 0.2 declarations of local variables
4987 !
4988 REAL :: zheat, zmass, zdz, zliq, zsnowlwe
4989 !
4990 INTEGER :: jj,jst,jst_1, jst_2, jst_max, idiff_layer ! loop counter
4991 INTEGER :: id_1, id_2
4992 !
4993 REAL(KIND=JPRB) :: zhook_handle
4994 !-------------------------------------------------------------------------------
4995 !
4996 IF (lhook) CALL dr_hook('SNOWCROLAYER_GONE',0,zhook_handle)
4997 !
4998 DO jj=1,SIZE(psnowrho,1) ! loop on gridpoints
4999  !
5000  jst_max = knlvls_use(jj)
5001  !
5002  idiff_layer = 0 ! used as shift counter of previously melted layers
5003  !
5004  DO jst_1 = jst_max,1-jst_max,-1 ! loop on 2 x layers in case of multi melt
5005  !
5006  jst = jst_1 + idiff_layer
5007  !
5008  ! Merge is possible only in case of 2 active layers or more
5009  IF ( jst>=1 .AND. knlvls_use(jj)>1 ) THEN
5010  !
5011  ! Total Liquid equivalent water content of snow (m):
5012  zsnowlwe = psnowrho(jj,jst) * psnowdz(jj,jst) / xrholw
5013  !
5014  ! Consideration of sublimation if any
5015  IF ( jst==1 ) zsnowlwe = zsnowlwe - max( 0., ples3l(jj)*ptstep/(xlstt*xrholw) )
5016  !
5017  ! Test if avalaible energy exceeds total latent heat
5018  IF ( pscap(jj,jst) * max( 0.0, psnowtemp(jj,jst)-xtt ) * psnowdz(jj,jst) >= &
5019  ( ( zsnowlwe-psnowliq(jj,jst) ) * xlmtt * xrholw ) - xuepsi ) THEN
5020  !
5021  IF ( jst==knlvls_use(jj) ) THEN
5022  id_1 = jst-1
5023  id_2 = jst
5024  ELSE
5025  id_1 = jst
5026  id_2 = jst + 1
5027  ENDIF
5028  !
5029  ! Case of a total melt of the bottom layer: merge with above layer
5030  ! which keeps its grain, histo and age properties
5031  zheat = 0.
5032  zmass = 0.
5033  zdz = 0.
5034  zliq = 0.
5035  DO jst_2 = id_1,id_2
5036  zheat = zheat + &
5037  psnowdz(jj,jst_2) * &
5038  ( pscap(jj,jst_2)*( psnowtemp(jj,jst_2)-xtt ) - xlmtt*psnowrho(jj,jst_2) ) + &
5039  xlmtt * xrholw * psnowliq(jj,jst_2)
5040  zmass = zmass + psnowdz(jj,jst_2) * psnowrho(jj,jst_2)
5041  zdz = zdz + psnowdz(jj,jst_2)
5042  zliq = zliq + psnowliq(jj,jst_2)
5043  ENDDO
5044  !
5045  psnowdz(jj,id_1) = zdz
5046  psnowrho(jj,id_1) = zmass / zdz
5047  psnowliq(jj,id_1) = zliq
5048  !
5049  ! Temperature of the merged layer is deduced from the heat content
5050  pscap(jj,id_1) = ( psnowrho(jj,id_1) - &
5051  psnowliq(jj,id_1) * xrholw / &
5052  max( psnowdz(jj,id_1),xsnowdzmin ) ) * xci
5053  psnowtemp(jj,id_1) = xtt + &
5054  ( ( ( ( zheat - xlmtt*xrholw*psnowliq(jj,id_1) ) / psnowdz(jj,id_1) ) + &
5055  xlmtt*psnowrho(jj,id_1) ) &
5056  / pscap(jj,id_1) )
5057  !
5058  IF( jst/=knlvls_use(jj) ) THEN
5059  !
5060  psnowgran1(jj,jst) = psnowgran1(jj,jst+1)
5061  psnowgran2(jj,jst) = psnowgran2(jj,jst+1)
5062  psnowhist(jj,jst) = psnowhist(jj,jst+1)
5063  psnowage(jj,jst) = psnowage(jj,jst+1)
5064  !
5065  ! Shift the above layers
5066  DO jst_2 = jst+1,knlvls_use(jj)-1
5067  psnowtemp(jj,jst_2) = psnowtemp(jj,jst_2+1)
5068  pscap(jj,jst_2) = pscap(jj,jst_2+1)
5069  psnowdz(jj,jst_2) = psnowdz(jj,jst_2+1)
5070  psnowrho(jj,jst_2) = psnowrho(jj,jst_2+1)
5071  psnowliq(jj,jst_2) = psnowliq(jj,jst_2+1)
5072  psnowgran1(jj,jst_2) = psnowgran1(jj,jst_2+1)
5073  psnowgran2(jj,jst_2) = psnowgran2(jj,jst_2+1)
5074  psnowhist(jj,jst_2) = psnowhist(jj,jst_2+1)
5075  psnowage(jj,jst_2) = psnowage(jj,jst_2+1)
5076  ENDDO ! loop JST_2
5077  !
5078  ! Update the shift counter IDIFF_LAYER
5079  idiff_layer = idiff_layer + 1
5080  !
5081  ENDIF ! end test of bottom layer
5082  !
5083  ! Decrease the number of active snow layers
5084  knlvls_use(jj) = knlvls_use(jj) - 1
5085  !
5086  ENDIF ! end test on availibility of energy
5087  !
5088  ENDIF ! end test on the number of remaining active layers
5089  !
5090  ENDDO ! end loop on the snow layers
5091  !
5092 ENDDO ! end loop gridpoints
5093 !
5094 IF (lhook) CALL dr_hook('SNOWCROLAYER_GONE',1,zhook_handle)
5095 !
5096 END SUBROUTINE snowcrolayer_gone
5097 !####################################################################
5098 !###################################################################
5099 !####################################################################
5100 !###################################################################
5101 SUBROUTINE snowcroprintprofile(HINFO,KLAYERS,OPRINTGRAN,PSNOWDZ,PSNOWRHO, &
5102  psnowtemp,psnowliq,psnowheat,psnowgran1, &
5103  psnowgran2,psnowhist,psnowage,hsnowmetamo )
5104 !
5105 ! Matthieu Lafaysse 08/06/2012
5106 ! This routine prints the snow profile of a given point for debugging
5107 !
5108 !to compute SSA
5109 USE modd_csts, ONLY : xrholi
5110 USE modd_snow_par, ONLY : xd1, xd2, xd3, xx
5111 !
5112 IMPLICIT NONE
5113 !
5114  CHARACTER(*), INTENT(IN) :: hinfo
5115 LOGICAL, INTENT(IN) :: oprintgran
5116 INTEGER, INTENT(IN) :: klayers
5117 REAL, DIMENSION(:), INTENT(IN) :: psnowdz,psnowrho,psnowtemp,psnowliq, &
5118  psnowheat,psnowgran1,psnowgran2, &
5119  psnowhist,psnowage
5120  CHARACTER(3), INTENT(IN) :: hsnowmetamo
5121 !
5122 REAL, DIMENSION(KLAYERS) :: zsnowssa
5123 REAL :: zdiam
5124 !
5125 INTEGER :: jst
5126 !
5127 REAL(KIND=JPRB) :: zhook_handle
5128 !
5129 IF (lhook) CALL dr_hook('SNOWCROPRINTPROFILE',0,zhook_handle)
5130 !
5131 WRITE(*,*)
5132 WRITE(*,*)trim(hinfo)
5133 !
5134 IF (oprintgran) THEN
5135  !
5136  ! Compute SSA from SNOWGRAN1 and SNOWGRAN2
5137  IF ( hsnowmetamo=='B92' ) THEN
5138  !
5139  DO jst = 1,klayers
5140  !
5141  IF ( psnowgran1(jst)<0. ) THEN
5142  zdiam = -psnowgran1(jst)*xd1/xx + (1.+psnowgran1(jst)/xx) * &
5143  ( psnowgran2(jst)*xd2/xx + (1.-psnowgran2(jst)/xx) * xd3 )
5144  zdiam = zdiam/10000.
5145  ELSE
5146  zdiam = psnowgran2(jst)*psnowgran1(jst)/xx + &
5147  max( 0.0004, 0.5*psnowgran2(jst) ) * ( 1.-psnowgran1(jst)/xx )
5148  ENDIF
5149  zsnowssa(jst) = 6. / (xrholi*zdiam)
5150  !
5151  END DO
5152  !
5153  ELSE
5154  !
5155  zsnowssa = 6. / (xrholi*psnowgran1)
5156  !
5157  ENDIF
5158  !
5159  WRITE(*,'(9(A12,"|"))')"-------------","-------------","-------------",&
5160  "-------------","-------------","-------------","-------------",&
5161  "-------------","-------------"
5162  WRITE(*,'(9(A12,"|"))')"PSNOWDZ","PSNOWRHO","PSNOWTEMP","PSNOWLIQ","PSNOWHEAT",&
5163  "PSNOWGRAN1","PSNOWGRAN2","PSNOWHIST","PSNOWAGE"
5164  WRITE(*,'(9(A12,"|"))')"-------------","-------------","-------------",&
5165  "-------------","-------------","-------------","-------------",&
5166  "-------------","-------------"
5167  DO jst = 1,klayers
5168  WRITE(*,'(9(ES12.3,"|")," L",I2.2)') psnowdz(jst),psnowrho(jst),psnowtemp(jst), &
5169  psnowliq(jst),psnowheat(jst),psnowgran1(jst), &
5170  psnowgran2(jst),psnowhist(jst),psnowage(jst),jst
5171  ENDDO
5172  WRITE(*,'(9(A12,"|"))')"-------------","-------------","-------------",&
5173  "-------------","-------------","-------------","-------------",&
5174  "-------------","-------------"
5175  !
5176 ELSE
5177  !
5178  WRITE(*,'(5(A12,"|"))')"------------","------------","------------",&
5179  "------------","------------"
5180  WRITE(*,'(5(A12,"|"))')"PSNOWDZ","PSNOWRHO","PSNOWTEMP","PSNOWLIQ","PSNOWHEAT"
5181  WRITE(*,'(5(A12,"|"))')"------------","------------","------------",&
5182  "------------","------------"
5183  DO jst = 1,klayers
5184  WRITE(*,'(5(ES12.3,"|")," L",I2.2)') psnowdz(jst),psnowrho(jst),psnowtemp(jst),&
5185  psnowliq(jst),psnowheat(jst),jst
5186  ENDDO
5187  WRITE(*,'(5(A12,"|"))')"------------","------------","------------",&
5188  "------------","------------"
5189  !
5190 END IF
5191 !
5192 WRITE(*,*)
5193 !
5194 IF (lhook) CALL dr_hook('SNOWCROPRINTPROFILE',1,zhook_handle)
5195 !
5196 END SUBROUTINE snowcroprintprofile
5197 !####################################################################
5198 !###################################################################
5199 SUBROUTINE snowcroprintatm(CINFO,PTA,PQA,PVMOD,PRR,PSR,PSW_RAD,PLW_RAD, &
5200  ptg, psoilcond,pd_g,ppsn3l )
5201 
5202 ! Matthieu Lafaysse 08/06/2012
5203 ! This routine prints the atmospheric forcing of a given point for debugging
5204 ! and ground data
5205 
5206 IMPLICIT NONE
5207 
5208  CHARACTER(*), INTENT(IN) :: cinfo
5209 REAL, INTENT(IN) :: pta,pqa,pvmod,prr,psr,psw_rad,plw_rad
5210 REAL, INTENT(IN) :: ptg, psoilcond, pd_g, ppsn3l
5211 !
5212 INTEGER :: jst
5213 !
5214 REAL(KIND=JPRB) :: zhook_handle
5215 !
5216 IF (lhook) CALL dr_hook('SNOWCROPRINTATM',0,zhook_handle)
5217 !
5218  CALL snowcroprintdate()
5219 !
5220 WRITE(*,*)
5221 WRITE(*,*)trim(cinfo)
5222 WRITE(*,'(4(A12,"|"))')"------------","------------","------------",&
5223 "------------"
5224 WRITE(*,'(4(A12,"|"))')"PTA","PQA","PRR","PSR"
5225 WRITE(*,'(4(A12,"|"))')"------------","------------","------------",&
5226 "------------"
5227 WRITE(*,'(4(ES12.3,"|")," meteo1")')pta,pqa,prr,psr
5228 WRITE(*,'(4(A12,"|"))')"------------","------------","------------",&
5229 "------------"
5230 WRITE(*,'(3(A12,"|"))')"------------","------------","------------"
5231 WRITE(*,'(3(A12,"|"))')"PSW_RAD","PLW_RAD","PVMOD"
5232 WRITE(*,'(3(A12,"|"))')"------------","------------","------------"
5233 WRITE(*,'(3(ES12.3,"|")," meteo2")')psw_rad,plw_rad,pvmod
5234 WRITE(*,'(3(A12,"|"))')"------------","------------","------------"
5235 WRITE(*,*)
5236 WRITE(*,*)"Ground :"
5237 WRITE(*,'(4(A12,"|"))')"------------","------------","------------",&
5238 "------------"
5239 WRITE(*,'(4(A12,"|"))')"PTG","PSOILCOND","PD_G","PPSN3L"
5240 WRITE(*,'(4(A12,"|"))')"------------","------------","------------",&
5241 "------------"
5242 WRITE(*,'(4(ES12.3,"|")," soil")')ptg,psoilcond,pd_g,ppsn3l
5243 WRITE(*,'(4(A12,"|"))')"------------","------------","------------",&
5244 "------------"
5245 !
5246 IF (lhook) CALL dr_hook('SNOWCROPRINTATM',1,zhook_handle)
5247 !
5248 END SUBROUTINE snowcroprintatm
5249 !
5250 !####################################################################
5251 SUBROUTINE snowcrostopbalance(PMASSBALANCE,PENERGYBALANCE)
5252 !
5253 USE mode_crodebug, ONLY : xwarning_massbalance, xwarning_energybalance
5254 !
5255 USE modi_abor1_sfx
5256 !
5257 ! stop if energy and mass balances are not closed
5258 !
5259 IMPLICIT NONE
5260 !
5261 REAL , DIMENSION(:), INTENT(IN) :: pmassbalance, penergybalance
5262 !
5263 REAL,DIMENSION(SIZE(PSR)) :: zmassbalance,zenergybalance
5264 !
5265 REAL(KIND=JPRB) :: zhook_handle
5266 !
5267 IF (lhook) CALL dr_hook('SNOWCROSTOPBALANCE',0,zhook_handle)
5268 !
5269 IF ( any( pmassbalance > xwarning_massbalance ) ) &
5270  CALL abor1_sfx("SNOWCRO: WARNING MASS BALANCE !")
5271 IF ( any( penergybalance > xwarning_energybalance ) ) &
5272  CALL abor1_sfx("SNOWCRO: WARNING ENERGY BALANCE !")
5273 !
5274 IF (lhook) CALL dr_hook('SNOWCROSTOPBALANCE',1,zhook_handle)
5275 !
5276 END SUBROUTINE snowcrostopbalance
5277 !
5278 !###################################################################
5279 SUBROUTINE snowcroprintbalance(PSUMMASS_INI,PSUMHEAT_INI,PSUMMASS_FIN,PSUMHEAT_FIN, &
5280  psr,prr,pthrufal,pevap,pevapcor,pgrndflux,phsnow, &
5281  prnsnow,plel3l,ples3l,phpsnow,psnowhmass,psnowdz, &
5282  ptstep,pmassbalance,penergybalance,pevapcor2 )
5283 !
5284 ! Matthieu Lafaysse / Eric Brun 03/10/2012
5285 ! Print energy and mass balances.
5286 !
5287 IMPLICIT NONE
5288 !
5289 REAL, INTENT(IN) :: psummass_ini,psumheat_ini,psummass_fin,psumheat_fin
5290 REAL, INTENT(IN) :: psr,prr,pthrufal,pevap,pevapcor
5291 REAL, INTENT(IN) :: pgrndflux,phsnow,prnsnow,plel3l,ples3l,phpsnow,psnowhmass
5292 REAL, INTENT(IN) :: psnowdz !first layer
5293 REAL, INTENT(IN) :: ptstep !time step
5294 REAL, INTENT(IN) :: pmassbalance, penergybalance, pevapcor2
5295 !
5296 REAL(KIND=JPRB) :: zhook_handle
5297 !
5298 IF (lhook) CALL dr_hook('SNOWCROPRINTBALANCE',0,zhook_handle)
5299 !
5300 WRITE(*,*) ' '
5301 WRITE(*,fmt='(A1,67("+"),A1)') "+","+"
5302 !
5303  CALL snowcroprintdate()
5304 !
5305 WRITE(*,*) ' '
5306 !
5307 ! print des residus de bilan et des differents termes pour le point
5308 WRITE (*,fmt="(A25,1x,E17.10)") 'final mass (kg/m2) =' , psummass_fin
5309 WRITE (*,fmt="(A25,1x,E17.10)") 'final energy (J/m2) =', zsumheat_fin
5310 WRITE(*,*) ' '
5311 !
5312 WRITE(*,fmt="(A25,1x,E17.10)") 'mass balance (kg/m2) =', pmassbalance
5313 !
5314 WRITE(*,*) ' '
5315 WRITE(*,fmt="(A35)") 'mass balance contribution (kg/m2) '
5316 WRITE(*,fmt="(A51,1x,E17.10)") 'delta mass:', (psummass_fin-psummass_ini)
5317 WRITE(*,fmt="(A51,1x,E17.10)") 'hoar or condensation (>0 towards snow):', -pevap * ptstep
5318 WRITE(*,fmt="(A51,1x,E17.10)") 'rain:', prr * ptstep
5319 WRITE(*,fmt="(A51,1x,E17.10)") 'snow:', psr * ptstep
5320 WRITE(*,fmt="(A51,1x,E17.10)") 'run-off:', pthrufal * ptstep
5321 WRITE(*,fmt="(A51,1x,E17.10)") 'evapcor:', pevapcor * ptstep
5322 !
5323 WRITE(*,fmt='(A1,55("-"),A1)')"+","+"
5324 WRITE(*,*) ' '
5325 !
5326 WRITE(*,fmt="(A25,4(1x,E17.10))") 'energy balance (W/m2)=',penergybalance
5327 !
5328 WRITE(*,*) ' '
5329 WRITE(*,fmt="(A55)") 'energy balance contribution (W/m2) >0 towards snow :'
5330 WRITE(*,fmt="(A51,1x,E17.10)") 'delta heat:', (zsumheat_fin-zsumheat_ini)/ptstep
5331 WRITE(*,fmt="(A51,1x,E17.10)") 'radiation (LW + SW):', prnsnow
5332 WRITE(*,fmt="(A51,1x,E17.10)") 'sensible flux :', -phsnow
5333 WRITE(*,fmt="(A51,1x,E17.10)") 'ground heat flux :', -pgrndflux
5334 WRITE(*,fmt="(A51,1x,E17.10)") 'liquid latent flux:', -plel3l
5335 WRITE(*,fmt="(A51,1x,E17.10)") 'solid latent flux:', -ples3l
5336 WRITE(*,fmt="(A51,1x,E17.10)") 'rain sensible heat:', phpsnow
5337 WRITE(*,fmt="(A51,1x,E17.10)") 'snowfall/hoar heat (sensible + melt heat):', psnowhmass/ptstep
5338 WRITE(*,fmt="(A51,1x,E17.10)") 'evapcor:', pevapcor2
5339 WRITE(*,fmt='(A1,67("+"),A1)')"+","+"
5340 !
5341 IF (lhook) CALL dr_hook('SNOWCROPRINTBALANCE',1,zhook_handle)
5342 !
5343 END SUBROUTINE snowcroprintbalance
5344 !
5345 !####################################################################
5346 SUBROUTINE get_balance(PSUMMASS_INI,PSUMHEAT_INI,PSUMMASS_FIN,PSUMHEAT_FIN, &
5347  psr,prr,pthrufal,pevap,pevapcor,pgrndflux,phsnow, &
5348  prnsnow,plel3l,ples3l,phpsnow,psnowhmass,psnowdz, &
5349  ptstep,pmassbalance,penergybalance,pevapcor2 )
5350 !
5351 IMPLICIT NONE
5352 !
5353 REAL, INTENT(IN) :: psummass_ini,psumheat_ini,psummass_fin,psumheat_fin
5354 REAL, INTENT(IN) :: psr,prr,pthrufal,pevap,pevapcor
5355 REAL, INTENT(IN) :: pgrndflux,phsnow,prnsnow,plel3l,ples3l,phpsnow,psnowhmass
5356 REAL, INTENT(IN) :: psnowdz !first layer
5357 REAL, INTENT(IN) :: ptstep !time step
5358 !
5359 REAL, INTENT(OUT) :: pmassbalance, penergybalance, pevapcor2
5360 !
5361 REAL(KIND=JPRB) :: zhook_handle
5362 !
5363 IF (lhook) CALL dr_hook('SNOWCRO:GET_BALANCE',0,zhook_handle)
5364 !
5365 pmassbalance = psummass_fin - psummass_ini - &
5366  ( psr + prr - pthrufal - pevap + pevapcor ) * ptstep
5367 !
5368 pevapcor2 = pevapcor * psnowdz / max( xuepsi,psnowdz ) * &
5369  ( abs(plel3l) * xlvtt / max( xuepsi,abs(plel3l) ) + &
5370  abs(ples3l) * xlstt / max( xuepsi,abs(ples3l) ) )
5371 !
5372 penergybalance = ( psumheat_fin-psumheat_ini ) / ptstep - &
5373  ( -pgrndflux - phsnow + prnsnow - plel3l - ples3l + phpsnow ) - &
5374  psnowhmass / ptstep - pevapcor2
5375 !
5376 IF (lhook) CALL dr_hook('SNOWCRO:GET_BALANCE',1,zhook_handle)
5377 !
5378 END SUBROUTINE get_balance
5379 !
5380 !###################################################################
5381 SUBROUTINE snowcroprintdate()
5382 !
5383 IMPLICIT NONE
5384 !
5385 REAL(KIND=JPRB) :: zhook_handle
5386 !
5387 IF (lhook) CALL dr_hook('SNOWCROPRINTDATE',0,zhook_handle)
5388 !
5389 WRITE(*,fmt='(I4.4,2("-",I2.2)," Hour=",F5.2)') &
5390  tptime%TDATE%YEAR, tptime%TDATE%MONTH, tptime%TDATE%DAY, tptime%TIME/3600.
5391 !
5392 IF (lhook) CALL dr_hook('SNOWCROPRINTDATE',1,zhook_handle)
5393 !
5394 END SUBROUTINE snowcroprintdate
5395 !####################################################################
5396 !###################################################################
5397 !
5398 END SUBROUTINE snowcro
subroutine snowcro(HSNOWRES, TPTIME, OGLACIER, HIMPLICIT_WIND, PPEW_A_COEF, PPEW_B_COEF, PPET_A_COEF, PPEQ_A_COEF, PPET_B_COEF, PPEQ_B_COEF, PSNOWSWE, PSNOWRHO, PSNOWHEAT, PSNOWALB, PSNOWGRAN1, PSNOWGRAN2, PSNOWHIST, PSNOWAGE, PTSTEP, PPS, PSR, PRR, PPSN3L, PTA, PTG, PSW_RAD, PQA, PVMOD, PLW_RAD, PRHOA, PUREF, PEXNS, PEXNA, PDIRCOSZW, PZREF, PZ0, PZ0EFF, PZ0H, PALB, PSOILCOND, PD_G, PSNOWLIQ, PSNOWTEMP, PSNOWDZ, PTHRUFAL, PGRNDFLUX, PEVAPCOR, PRNSNOW, PHSNOW, PGFLUXSNOW, PHPSNOW, PLES3L, PLEL3L, PEVAP, PSNDRIFT, PRI, PEMISNOW, PCDSNOW, PUSTAR, PCHSNOW, PSNOWHMASS, PQS, PPERMSNOWFRAC, PZENITH, PXLAT, PXLON, OSNOWDRIFT, OSNOWDRIFT_SUBLIM, OSNOW_ABS_ZENITH, HSNOWMETAMO, HSNOWRAD)
Definition: snowcro.F90:6
subroutine snowcrogone(PTSTEP, PLEL3L, PLES3L, PSNOWRHO, PSNOWHEAT, PRADSINK_2D, PEVAPCOR, PTHRUFAL, PGRNDFLUX, PGFLUXSNOW, PSNOWDZ, PSNOWLIQ, PSNOWTEMP, PRADXS, PRR, KNLVLS_USE)
Definition: snowcro.F90:3328
subroutine snowcroprintatm(CINFO, PTA, PQA, PVMOD, PRR, PSR, PSW_RAD, PLW_RAD, PTG, PSOILCOND, PD_G, PPSN3L)
Definition: snowcro.F90:5199
subroutine snowcroevapn(PLES3L, PTSTEP, PSNOWTEMP, PSNOWRHO, PSNOWDZ, PEVAPCOR, PSNOWHMASS)
Definition: snowcro.F90:3241
subroutine surface_ri(PTG, PQS, PEXNS, PEXNA, PTA, PQA, PZREF, PUREF, PDIRCOSZW, PVMOD, PRI)
Definition: surface_ri.F90:6
subroutine snowcroprintbalance(PSUMMASS_INI, PSUMHEAT_INI, PSUMMASS_FIN, PSUMHEAT_FIN, PSR, PRR, PTHRUFAL, PEVAP, PEVAPCOR, PGRNDFLUX, PHSNOW, PRNSNOW, PLEL3L, PLES3L, PHPSNOW, PSNOWHMASS, PSNOWDZ, PTSTEP, PMASSBALANCE, PENERGYBALANCE, PEVAPCOR2)
Definition: snowcro.F90:5279
subroutine get_alb(KJ, PSNOWRHO_IN, PPS_IN, PVAGE1, PSNOWGRAN1, PSNOWGRAN2, PSNOWAGE, PALB, HSNOWMETAMO)
Definition: snowcro.F90:2018
subroutine snowcroevapgone(PSNOWHEAT, PSNOWDZ, PSNOWRHO, PSNOWTEMP, PSNOWLIQ, PSNOWGRAN1, PSNOWGRAN2, PSNOWHIST, PSNOWAGE, KNLVLS_USE, HSNOWMETAMO)
Definition: snowcro.F90:3442
subroutine snowcrostopbalance(PMASSBALANCE, PENERGYBALANCE)
Definition: snowcro.F90:5251
subroutine snowcrolayer_gone(PTSTEP, PSCAP, PSNOWTEMP, PSNOWDZ, PSNOWRHO, PSNOWLIQ, PSNOWGRAN1, PSNOWGRAN2, PSNOWHIST, PSNOWAGE, PLES3L, KNLVLS_USE)
Definition: snowcro.F90:4953
subroutine snowcroflux(PSNOWTEMP, PSNOWDZ, PEXNS, PEXNA, PUSTAR2_IC, PTSTEP, PALBT, PSW_RAD, PEMIST, PLWUPSNOW, PLW_RAD, PTA, PSFCFRZ, PQA, PHPSNOW, PSNOWTEMPO1, PSNOWFLUX, PCT, PRADSINK, PQSAT, PDQSAT, PRSRA, PRN, PH, PGFLUX, PLES3L, PLEL3L, PEVAP, PUSTAR)
Definition: snowcro.F90:3054
subroutine snowcroprintprofile(HINFO, KLAYERS, OPRINTGRAN, PSNOWDZ, PSNOWRHO, PSNOWTEMP, PSNOWLIQ, PSNOWHEAT, PSNOWGRAN1, PSNOWGRAN2, PSNOWHIST, PSNOWAGE, HSNOWMETAMO)
Definition: snowcro.F90:5101
subroutine get_gran(PTSTEP, PTELM, PGRAN)
Definition: snowcro.F90:1842
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine surface_aero_cond(PRI, PZREF, PUREF, PVMOD, PZ0, PZ0H, PAC, PRA, PCH)
subroutine snowcrorad(TPTIME, OGLACIER, PSW_RAD, PSNOWALB, PSNOWDZ, PSNOWRHO, PALB, PRADSINK, PRADXS, PSNOWGRAN1, PSNOWGRAN2, PSNOWAGE, PPS, PZENITH, PPERMSNOWFRAC, KNLVLS_USE, OSNOW_ABS_ZENITH, HSNOWMETAMO)
Definition: snowcro.F90:2075
subroutine snownlgridfresh_1d(KJ, PSNOW, PSNOWDZ, PSNOWDZN, PSNOWRHO, PSNOWHEAT, PSNOWGRAN1, PSNOWGRAN2, PSNOWHIST, PSNOWAGE, GSNOWFALL, PSNOWRHOF, PSNOWDZF, PSNOWHEATF, PSNOWGRAN1F, PSNOWGRAN2F, PSNOWHISTF, PSNOWAGEF, KNLVLS_USE, HSNOWMETAMO)
Definition: snowcro.F90:4461
subroutine snowcrometamo(PSNOWDZ, PSNOWGRAN1, PSNOWGRAN2, PSNOWHIST, PSNOWTEMP, PSNOWLIQ, PTSTEP, PSNOWSWE, INLVLS_USE, PSNOWAGE, HSNOWMETAMO)
Definition: snowcro.F90:1281
subroutine get_snowdzn_end(KNLVLS, PSNOWDZ, PDZOPT, PSNOWDZN)
Definition: snowcro.F90:4412
subroutine snowcrothrm(PSNOWRHO, PSCOND, PSNOWTEMP, PPS, PSNOWLIQ, OCOND_GRAIN, OCOND_YEN)
Definition: snowcro.F90:2217
subroutine get_rho(PRHO_IN, PDZ, PSNOWLIQ, PFLOWLIQ, PRHO_OUT)
Definition: snowcro.F90:3034
subroutine snowcroebud(HSNOWRES, HIMPLICIT_WIND, PPEW_A_COEF, PPEW_B_COEF, PPET_A_COEF, PPEQ_A_COEF, PPET_B_COEF, PPEQ_B_COEF, PSNOWDZMIN, PZREF, PTS, PSNOWRHO, PSNOWLIQ, PSCAP, PSCOND1, PSCOND2, PUREF, PEXNS, PEXNA, PDIRCOSZW, PVMOD, PLW_RAD, PSW_RAD, PTA, PQA, PPS, PTSTEP, PSNOWDZ1, PSNOWDZ2, PALBT, PZ0, PZ0EFF, PZ0H, PSFCFRZ, PRADSINK, PHPSNOW, PCT, PEMIST, PRHOA, PTSTERM1, PTSTERM2, PRA, PCDSNOW, PCHSNOW, PQSAT, PDQSAT, PRSRA, PUSTAR2_IC, PRI, PPET_A_COEF_T, PPEQ_A_COEF_T, PPET_B_COEF_T, PPEQ_B_COEF_T)
Definition: snowcro.F90:2284
subroutine snowcrocompactn(PTSTEP, PSNOWRHO, PSNOWDZ, PSNOWTEMP, PSNOW, PSNOWGRAN1, PSNOWGRAN2, PSNOWHIST, PSNOWLIQ, INLVLS_USE, PDIRCOSZW, HSNOWMETAMO)
Definition: snowcro.F90:1128
subroutine snowcroalb(TPTIME, OGLACIER, PALBEDOSC, PSPECTRALALBEDO, PSNOWDZ, PSNOWRHO, PPERMSNOWFRAC, PSNOWGRAN1_TOP, PSNOWGRAN2_TOP, PSNOWAGE_TOP, PSNOWGRAN1_BOT, PSNOWGRAN2_BOT, PSNOWAGE_BOT, PPS, PZENITH, KNLVLS_USE, HSNOWMETAMO)
Definition: snowcro.F90:1868
subroutine get_snowdzn_deb(KNLVLS, PSNOWDZ, PDZOPT, PSNOWDZN)
Definition: snowcro.F90:4365
subroutine get_balance(PSUMMASS_INI, PSUMHEAT_INI, PSUMMASS_FIN, PSUMHEAT_FIN, PSR, PRR, PTHRUFAL, PEVAP, PEVAPCOR, PGRNDFLUX, PHSNOW, PRNSNOW, PLEL3L, PLES3L, PHPSNOW, PSNOWHMASS, PSNOWDZ, PTSTEP, PMASSBALANCE, PENERGYBALANCE, PEVAPCOR2)
Definition: snowcro.F90:5346
subroutine getpoint_crodebug(PLAT, PLON, KDEBUG)
subroutine get_flux(PALBT, PEMIST, PSW_RAD, PLW_RAD, PEXNS, PEXNA, PTA, PQA, PRSRA, PQSAT, PDQSAT, PSFCFRZ, PHPSNOW, PSNOWTEMP, PSNOWTEMPO1, PRN, PH, PEVAPC, PLES3L, PLEL3L, PGFLUX)
Definition: snowcro.F90:3193
subroutine surface_cd(PRI, PZREF, PUREF, PZ0EFF, PZ0H, PCD, PCDN)
Definition: surface_cd.F90:6
subroutine snowcroprintdate()
Definition: snowcro.F90:5381
subroutine snowcrorefrz(PTSTEP, PRR, PSNOWRHO, PSNOWTEMP, PSNOWDZ, PSNOWLIQ, PTHRUFAL, PSCAP, PLEL3L, KNLVLS_USE)
Definition: snowcro.F90:2887
subroutine snowcrosolvt(PTSTEP, PSNOWDZMIN, PSNOWDZ, PSCOND, PSCAP, PTG, PSOILCOND, PD_G, PRADSINK, PCT, PTERM1, PTERM2, PPET_A_COEF_T, PPEQ_A_COEF_T, PPET_B_COEF_T, PPEQ_B_COEF_T, PTA_IC, PQA_IC, PGBAS, PSNOWTEMP, PSNOWFLUX, KNLVLS_USE)
Definition: snowcro.F90:2530
subroutine snowcromelt(PSCAP, PSNOWTEMP, PSNOWDZ, PSNOWRHO, PSNOWLIQ, KNLVLS_USE)
Definition: snowcro.F90:2776
subroutine snownlfall_upgrid(TPTIME, OGLACIER, PTSTEP, PSR, PTA, PVMOD, PSNOW, PSNOWRHO, PSNOWDZ, PSNOWHEAT, PSNOWHMASS, PSNOWALB, PPERMSNOWFRAC, PSNOWGRAN1, PSNOWGRAN2, GSNOWFALL, PSNOWDZN, PSNOWRHOF, PSNOWDZF, PSNOWGRAN1F, PSNOWGRAN2F, PSNOWHISTF, PSNOWAGEF, OMODIF_GRID, KNLVLS_USE, OSNOWDRIFT, PZ0EFF, PUREF, HSNOWMETAMO)
Definition: snowcro.F90:3590
subroutine snowcro_tartes(PSNOWGRAN1, PSNOWGRAN2, PSNOWRHO, PSNOWDZ, PSNOWG0, PSNOWY0, PSNOWW0, PSNOWB0, PSNOWIMP_DENSITY, PSNOWIMP_CONTENT, PALB, PSW_RAD, PZENITH, KNLVLS_USE, PSNOWALB, PRADSINK, PRADXS, ODEBUG, HSNOWMETAMO)
subroutine set_thresh(PGRADT, PSNOWLIQ, PSPHE)
Definition: snowcro.F90:1823
subroutine snowdrift(PTSTEP, PVMOD, PSNOWRHO, PSNOWDZ, PSNOW, PSNOWGRAN1, PSNOWGRAN2, PSNOWHIST, KNLVLS_USE, PTA, PQA, PPS, PRHOA, PZ0EFF, PUREF, OSNOWDRIFT_SUBLIM, HSNOWMETAMO, PSNDRIFT)
Definition: snowcro.F90:4683