SURFEX v8.1
General documentation of Surfex
mode_tartes.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 MODULE mode_tartes
6 
7 !##########################
8 !
9 !! *MODE_TARTES*
10 !!
11 !! Radiative transfer in snowpack
12 
13 !!
14 !!** IMPLICIT ARGUMENTS
15 !! ------------------
16 !! NONE
17 !!
18 !! REFERENCE
19 !! ---------
20 !!
21 !! AUTHOR
22 !! ------
23 !! M. Lafaysse * Meteo France *
24 !! translated from python codes of G. Picard, Q. Libois, LGGE.
25 !!
26 !! Main differences relatively to the python code :
27 !! ------------------------------------------------
28 !!
29 !! For optimization on large domains :
30 !! * Loops are inside the subroutines
31 !! * All variables are multi-points (first dimension)
32 !! * Loop on points is the last loop
33 !! * Number of active or effective layers : argument of subroutines
34 !!
35 !! New routine to interpolate ice refractive index on the given wavelengths
36 !!
37 !! Wavelengths are assumed to be a parameter of the model and not an argument (if necessary, it will be in surfex namelists)
38 !!
39 !! Impurities : the python object is replaced by two variables (density and content). Last dimension represents impurity type.
40 !! For now : it is just implemented for soot (indice 1).
41 !!
42 !! To solve the linear system MX=Y :
43 !! * Indices of upper diagonal (PDP) shifted one step right
44 !! * Indices of lower diagonal (PDM) shifted one step left
45 !!
46 !! In routine INFINITE_MEDIUM_OPTICAL_PARAMETERS add a control IF ABS(PSNOWALB)<UEPSI
47 !!
48 !! Add a control of absorbed energy output to avoid occasional numerical problem in infra-red (not used)
49 !!
50 !! MODIFICATIONS
51 !! -------------
52 !! Original 24/07/2013
53 !! Matthieu Lafaysse interface with SURFEX 23/08/2013
54 !--------------------------------------------------------------------------------
55 
56 USE yomhook ,ONLY : lhook, dr_hook
57 USE parkind1 ,ONLY : jprb
58 
59 
60  CONTAINS
61 
62 SUBROUTINE tartes(PSNOWSSA,PSNOWRHO,PSNOWDZ,PSNOWG0,PSNOWY0,PSNOWW0,PSNOWB0,PSNOWIMP_DENSITY,&
63  PSNOWIMP_CONTENT,PALB,PSW_RAD_DIF,PSW_RAD_DIR,PCOSZEN,KNLVLS_USE,PSNOWALB, &
64  PSNOWENERGY,PSOILENERGY)
65 !
67 !
68 IMPLICIT NONE
69 !
70 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWSSA !snow specific surface area (m^2/kg) (npoints,nlayer)
71 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWRHO !snow density (kg/m^3) (npoints,nlayer)
72 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWG0 ! asymmetry parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit) (npoints,nlayer)
73 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWY0 ! Value of y of snow grains at nr=1.3 (no unit
74 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWW0 ! Value of W of snow grains at nr=1.3 (no unit)
75 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWB0 ! absorption enhancement parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit)
76 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWDZ !snow layers thickness (m) (npoints,nlayer)
77 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_DENSITY !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
78 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_CONTENT !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
79 !
80 REAL, DIMENSION(:,:), INTENT(IN) :: PALB ! soil/vegetation albedo (npoints,nbands)
81 !
82 REAL, DIMENSION(:,:), INTENT(IN) :: PSW_RAD_DIF ! spectral diffuse incident light (W/m^2) (npoints,nbands)
83 REAL, DIMENSION(:,:), INTENT(IN) :: PSW_RAD_DIR ! spectral direct incident light (W/m^2) (npoints,nbands)
84 REAL, DIMENSION(:), INTENT(IN) :: PCOSZEN ! cosine of zenithal solar angle (npoints)
85 !
86 INTEGER, DIMENSION(:), INTENT(IN) :: KNLVLS_USE ! number of effective snow layers (npoints)
87 !
88 REAL, DIMENSION(:,:), INTENT(OUT) :: PSNOWALB !(npoints,nbands)
89 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSNOWENERGY !(npoints,nlayer,nbands)
90 REAL, DIMENSION(:,:), INTENT(OUT) :: PSOILENERGY !(npoints,nbands)
91 !
92 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2)*2,NPNBANDS) :: ZDM,ZD,ZDP !3 diagonals of the matrix
93 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2)*2,NPNBANDS) :: ZVECTOR_DIR,ZVECTOR_DIF
94 !
95 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZSNOWSSALB !total single scattering albedo (npoints,nlayer,nbands)
96 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZSNOWG !asymmetry factor (npoints,nlayer,nbands)
97 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZSNOWALBEDO! Albedo (npoints,nlayer,nbands)
98 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZKESTAR !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
99 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZG_STAR,ZSSALB_STAR,ZGAMMA1,ZGAMMA2
100 !
101 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZDTAUSTAR !Optical depth of each layer
102 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZTAUSTAR !Cumulated optical depth
103 !
104 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZGP_DIR,ZGM_DIR ! Gp Gm vectors for direct radiation
105 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZGP_DIF,ZGM_DIF ! Gp Gm vectors for diffuse radiation
106 !
107 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZXA_DIR,ZXA_DIF,ZXB_DIR,ZXB_DIF,ZXC_DIR,ZXC_DIF,ZXD_DIR,ZXD_DIF
108 !
109 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZEPROFILE_DIR,ZEPROFILE_DIF
110 !
111 REAL, DIMENSION(SIZE(PSNOWSSA,1),NPNBANDS) :: ZSOILABS_DIR,ZSOILABS_DIF
112 !
113 REAL, DIMENSION(SIZE(PSNOWSSA,1),NPNBANDS) :: ZALB ! same as PALB but possibly modified if snowpack is truncated
114 !
115 REAL, DIMENSION(SIZE(PSNOWSSA,1))::ZMUDIFF
116 !
117 INTEGER, DIMENSION(SIZE(PSNOWSSA,1),NPNBANDS) :: INLVLS_EFF ! number of effective snow layers
118 !
119 INTEGER, DIMENSION(NPNBANDS) :: IMAX_EFF ! maximum number of effective layers over each band
120 !
121 INTEGER :: JB,JI,JL !loop counters
122 INTEGER :: IMAX_USE ! maximum number of layers over the domain
123 !
124 REAL(KIND=JPRB) :: ZHOOK_HANDLE
125 !
126 IF (lhook) CALL dr_hook('TARTES',0,zhook_handle)
127 !
128 ! Initialization
129 psnowalb = 0.
130 psnowenergy = 0.
131 psoilenergy = 0.
132 zalb = palb
133 !
134 zmudiff = xp_mudiff !the diffuse incident flux is treated as direct flux at zenithal angle 53deg
135 !
136 imax_use = maxval(knlvls_use)
137 !
138 !1 compute optical properties for each wavelength
139  CALL single_scattering_optical_parameters(psnowssa,psnowrho,psnowg0,psnowy0,psnoww0,psnowb0, &
140  psnowimp_density,psnowimp_content,knlvls_use,imax_use, &
141  zsnowssalb,zsnowg)
142 
143  CALL infinite_medium_optical_parameters(zsnowssalb,zsnowg,knlvls_use,imax_use,zsnowalbedo,zkestar, &
144  zg_star,zssalb_star,zgamma1,zgamma2)
145 
146 ! 2 computation on every wavelength and layer of the optical depth
147  CALL taustar_vector(psnowssa,psnowrho,psnowdz,zsnowssalb,zsnowg,zkestar,knlvls_use,imax_use, &
148  zdtaustar,ztaustar)
149 
150 ! estimate the effective layers for absorption
151  CALL estimate_effective_layer_number(zkestar,zdtaustar,knlvls_use,imax_use,inlvls_eff,imax_eff)
152 
153 !3 solve the radiative transfer for each wavelength
154 !3.1 Compte G+ and G- vectors for direct and diffuse radiations
155  CALL gp_gm_vectors(zsnowssalb,zkestar,zg_star,zssalb_star,zgamma1,zgamma2,pcoszen,psw_rad_dir, &
156  inlvls_eff,imax_eff,zgp_dir,zgm_dir)
157  CALL gp_gm_vectors(zsnowssalb,zkestar,zg_star,zssalb_star,zgamma1,zgamma2,zmudiff,psw_rad_dif, &
158  inlvls_eff,imax_eff,zgp_dif,zgm_dif)
159 !
160 !3.2 If the snowpack has been truncated, add a thick layer (optical) and force soil albedo to 1
161 DO jb = 1,npnbands
162  DO ji = 1,SIZE(knlvls_use)
163  IF ( inlvls_eff(ji,jb)<knlvls_use(ji) ) THEN
164  zdtaustar(ji,inlvls_eff(ji,jb)+1,jb) = 30. / zkestar(ji,inlvls_eff(ji,jb)+1,jb)
165  zalb(ji,jb) = 1.
166  END IF
167  END DO
168 END DO
169 !
170 !3.3 Compute the matrix and vectors
171  CALL two_stream_matrix(zsnowalbedo,zalb,zkestar,zdtaustar,inlvls_eff,imax_eff,zdm,zd,zdp)
172  CALL two_stream_vector(zsnowalbedo,zalb,zdtaustar,ztaustar,zgm_dir,zgp_dir,pcoszen,inlvls_eff,imax_eff,zvector_dir)
173  CALL two_stream_vector(zsnowalbedo,zalb,zdtaustar,ztaustar,zgm_dif,zgp_dif,zmudiff,inlvls_eff,imax_eff,zvector_dif)
174 !
175 ! DO JB=1,NPNBANDS,30
176 ! PRINT*,"band ",JB
177 ! PRINT*,ZDM(:,:,JB)
178 ! PRINT*,ZD(:,:,JB)
179 ! PRINT*,ZDP(:,:,JB)
180 ! PRINT*,ZVECTOR_DIR(:,:,JB)
181 ! PRINT*,ZVECTOR_DIF(:,:,JB)
182 ! END DO
183 !
184 !3.4 solve the system
185  CALL solves_two_stream2(zdm,zd,zdp,zvector_dir,zvector_dif,zsnowalbedo,psw_rad_dir,psw_rad_dif,inlvls_eff, &
186  imax_eff,zxa_dir,zxa_dif,zxb_dir,zxb_dif,zxc_dir,zxc_dif,zxd_dir,zxd_dif)
187 !
188 ! DO JB=1,NPNBANDS,30
189 ! PRINT*,"solution band ",JB
190 ! PRINT*,ZXA_DIR(:,:,JB)
191 ! PRINT*,ZXA_DIF(:,:,JB)
192 ! END DO
193 !
194 !4 Diagnostics
195 !4.1 Albedo
196  CALL snowpack_albedo(zxc_dir(:,1,:),zxc_dif(:,1,:),zxd_dir(:,1,:),zxd_dif(:,1,:), &
197  zgp_dir(:,1,:),zgp_dif(:,1,:),pcoszen,zmudiff,psw_rad_dir, &
198  psw_rad_dif,psnowalb)
199 !
200 !4.2 Energy profile
201  CALL energy_profile(zxa_dir,zxb_dir,zxc_dir,zxd_dir,zkestar,zdtaustar,ztaustar,zgm_dir,zgp_dir,pcoszen, &
202  inlvls_eff,imax_eff,zeprofile_dir)
203  CALL energy_profile(zxa_dif,zxb_dif,zxc_dif,zxd_dif,zkestar,zdtaustar,ztaustar,zgm_dif,zgp_dif,zmudiff, &
204  inlvls_eff,imax_eff,zeprofile_dif)
205 !
206 DO jb = 1,npnbands
207  DO jl = 1,SIZE(psnowssa,2)
208  WHERE ( jl<=inlvls_eff(:,jb) )
209  psnowenergy(:,jl,jb) = psw_rad_dir(:,jb) * zeprofile_dir(:,jl,jb) + &
210  psw_rad_dif(:,jb) * zeprofile_dif(:,jl,jb)
211  ENDWHERE
212  END DO
213 END DO
214 !
215 !4.3 Soil absorption
216  CALL soil_absorption(zxa_dir,zxb_dir,zkestar,zdtaustar,ztaustar,zgm_dir,pcoszen,palb,inlvls_eff,zsoilabs_dir)
217  CALL soil_absorption(zxa_dif,zxb_dif,zkestar,zdtaustar,ztaustar,zgm_dif,zmudiff,palb,inlvls_eff,zsoilabs_dif)
218 !
219 psoilenergy = psw_rad_dir * zsoilabs_dir + psw_rad_dif * zsoilabs_dif
220 !
221 IF (lhook) CALL dr_hook('TARTES',1,zhook_handle)
222 !
223 END SUBROUTINE tartes
224 !--------------------------------------------------------------------------------
225 !--------------------------------------------------------------------------------
226 SUBROUTINE init_tartes()
227 !
228 !In surfex this routine has to been called only once (Crocus init).
229 !
230 IMPLICIT NONE
231 !
232 REAL(KIND=JPRB) :: ZHOOK_HANDLE
233 !
234 IF (lhook) CALL dr_hook('INIT_TARTES',0,zhook_handle)
235 !
236  CALL refice() ! Interpolate refractive index for pure ice on the prescribed wavelengths
237  CALL refsoot_imag() ! Compute refractive index of soot according to wavelengths from Chang (1990)
238 !
239 IF (lhook) CALL dr_hook('INIT_TARTES',1,zhook_handle)
240 !
241 END SUBROUTINE init_tartes
242 !--------------------------------------------------------------------------------
243 !--------------------------------------------------------------------------------
244 SUBROUTINE refice()
245 !
246 ! Interpolate refractive index for pure ice on the prescribed wavelengths
247 !
251 USE modd_csts, ONLY: xpi, xrholi
252 !
253 USE modi_abor1_sfx
254 !
255 IMPLICIT NONE
256 !
257 ! Log of PPWAVELENGTHS PPWAVELENGTHS_REF PPREFICE_I for interpolation
258 REAL, DIMENSION(NPNBANDS) :: ZLOG_WL
259 REAL, DIMENSION(NPNBANDS_REF) :: ZLOG_WL_REF
260 REAL, DIMENSION(NPNBANDS_REF) :: ZLOG_REFICE_I
261 !
262 INTEGER :: JB,JBREF !loop counters (wl band)
263 !
264 LOGICAL :: GINF !logical for interpolation
265 !
266 REAL(KIND=JPRB) :: ZHOOK_HANDLE
267 !
268 IF (lhook) CALL dr_hook('REFICE',0,zhook_handle)
269 !
270 zlog_wl = log(xpwavelengths)
271 zlog_wl_ref = log(xpwavelengths_ref)
272 zlog_refice_i = log(xprefice_i)
273 
274 ! Interpolate retractive index
275 DO jb = 1,npnbands
276  !
277  ginf = .true.
278  !
279  DO jbref = 1,npnbands_ref
280  !
281  IF ( xpwavelengths_ref(jbref)>xpwavelengths(jb) ) THEN
282  !
283  IF ( jbref<2 ) CALL abor1_sfx("FATAL ERROR INIT_TARTES (interpolation of refractive indexs)")
284  !
285  ginf = .false.
286  !
287  xrefice_r(jb) = ( (xpwavelengths(jb) - xpwavelengths_ref(jbref-1)) * xprefice_r(jbref) + &
288  (xpwavelengths_ref(jbref) - xpwavelengths(jb) ) * xprefice_r(jbref-1) ) / &
289  ( xpwavelengths_ref(jbref) - xpwavelengths_ref(jbref-1) )
290  xrefice_i(jb) = exp( ( (zlog_wl(jb) - zlog_wl_ref(jbref-1)) * zlog_refice_i(jbref) + &
291  (zlog_wl_ref(jbref) - zlog_wl(jb) ) * zlog_refice_i(jbref-1) ) / &
292  ( zlog_wl_ref(jbref) - zlog_wl_ref(jbref-1) ) )
293  !
294  xrefice_norm(jb) = xrefice_r(jb) - 1.3 !factor in eq 72-73-74
295  xginf(jb) = 0.9751 - 0.105 * xrefice_norm(jb) !doc equation 72
296  xconst_c(jb) = 24. * xpi * xrefice_i(jb) / ( xrholi * xpwavelengths_m(jb) ) !constant c*SSA in equation 71
297  !
298  EXIT
299  !
300  END IF
301  !
302  END DO
303  !
304  IF ( ginf ) CALL abor1_sfx("FATAL ERROR INIT_TARTES (interpolation of refractive indexs)")
305  !
306 END DO
307 !
308 IF (lhook) CALL dr_hook('REFICE',1,zhook_handle)
309 !
310 END SUBROUTINE refice
311 !--------------------------------------------------------------------------------
312 !--------------------------------------------------------------------------------
313 SUBROUTINE refsoot_imag()
315 ! Compute refractive index of soot according to wavelengths from Chang (1990)
316 
318 !
319 !PPWAVELENGTHS nanometers
320 !
321 IMPLICIT NONE
322 !
323 REAL, DIMENSION (NPNBANDS) :: ZWL_UM ! Wavelengths in micrometers (Chang, 1990 formulas)
324 REAL, DIMENSION (NPNBANDS) :: ZINDEX_SOOT_REAL,ZINDEX_SOOT_IMAG ! real and imaginary components of refractive index
325  COMPLEX, DIMENSION(NPNBANDS) :: ZINDEX_SOOT !complex refractive index
326 !
327 REAL(KIND=JPRB) :: ZHOOK_HANDLE
328 !
329 IF (lhook) CALL dr_hook('REFSOOT_IMAG',0,zhook_handle)
330 !
331 zwl_um = xpwavelengths / 1000.
332 !
333 zindex_soot_real = 1.811 + 0.1263*log(zwl_um) + 0.027 *log(zwl_um)**2 + 0.0417*log(zwl_um)**3
334 zindex_soot_imag = 0.5821 + 0.1213*log(zwl_um) + 0.2309*log(zwl_um)**2 - 0.01 *log(zwl_um)**3
335 !
336 zindex_soot = zindex_soot_real - cmplx(0,1) * zindex_soot_imag
337 !
338 ! absorption cross section of small particles (Bohren and Huffman, 1983)
339 xrefimp_i(:,1) = aimag( (zindex_soot**2-1.) / (zindex_soot**2 + 2.) )
340 !
341 IF (lhook) CALL dr_hook('REFSOOT_IMAG',1,zhook_handle)
342 !
343 END SUBROUTINE refsoot_imag
344 !--------------------------------------------------------------------------------
345 !--------------------------------------------------------------------------------
346 SUBROUTINE shape_parameter_variations(PSNOWG0,PSNOWY0,PSNOWW0,PSNOWB0,PSNOWG00,PSNOWY,PSNOWW,PSNOWB)
348 !compute shape parameter variations as a function of the the refraction index with respect to the value in the visible range.
349 !These variation equations were obtained for sphere (Light Scattering Media Optics, Kokhanovsky, A., p.61) but should also apply to other shapes in a first approximation.
350 !see doc Section 2
351 !
352 USE modd_const_tartes, ONLY: npnbands,xrefice_norm !number of spectral bands
353 !
354 IMPLICIT NONE
355 !
356 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWG0 !asymmetry parameter of snow grains at refractive index=1.3 and at non absorbing wavelengths (no unit) (npoints*nlayers)
357 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWY0 !Value of y of snow grains at refractive index=1.3 (no unit) (npoints*nlayers)
358 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWW0 !Value of W of snow grains at refractive index=1.3 (no unit) (npoints*nlayers)
359 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWB0 !absorption enhancement parameter of snow grains at refractive index=1.3 and at non absorbing wavelengths (no unit) (npoints*nlayers)
360 !
361 ! Spectral parameters necessary to compute the asymmetry parameter and single scattering albedo of snow. For now, those parameters do not evolve with time. They depend on shape only
362 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSNOWG00 !(npoints*nlayers*nbands)
363 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSNOWY !(npoints*nlayers*nbands)
364 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSNOWW !(npoints*nlayers*nbands)
365 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSNOWB !(npoints*nlayers*nbands)
366 !
367 INTEGER :: JB !loop counter
368 !
369 REAL(KIND=JPRB) :: ZHOOK_HANDLE
370 !
371 IF (lhook) CALL dr_hook('SHAPE_PARAMETER_VARIATIONS',0,zhook_handle)
372 !
373 DO jb = 1,npnbands
374  psnowg00(:,:,jb) = psnowg0(:,:) - 0.38 * xrefice_norm(jb) !doc equation 73
375  psnowb(:,:,jb) = psnowb0(:,:) + 0.4 * xrefice_norm(jb) !doc equation 77
376  psnoww(:,:,jb) = psnoww0(:,:) + 0.17 * xrefice_norm(jb)
377  psnowy(:,:,jb) = psnowy0(:,:) + 0.752 * xrefice_norm(jb) !doc equation 74
378 END DO
379 !
380 IF (lhook) CALL dr_hook('SHAPE_PARAMETER_VARIATIONS',1,zhook_handle)
381 !
382 END SUBROUTINE shape_parameter_variations
383 !--------------------------------------------------------------------------------
384 !--------------------------------------------------------------------------------
385 SUBROUTINE impurities_co_single_scattering_albedo(PSNOWSSA,PSNOWIMP_DENSITY,PSNOWIMP_CONTENT, &
386  KNLVLS_USE,KMAX_USE,PCOSSALB)
387 !
389 USE modd_csts, ONLY: xpi
390 !
391 IMPLICIT NONE
392 !
393 !return the spectral absorption of snow due to the impurities
394 !see doc Section 2.6
395 !
396 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWSSA !snow specific surface area (m^2/kg) (npoints,nlayer)
397 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_DENSITY !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
398 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_CONTENT !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
399 INTEGER, DIMENSION(:), INTENT(IN) :: KNLVLS_USE !number of active layers
400 INTEGER, INTENT(IN) :: KMAX_USE !maximum number of active layers over the domain
401 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PCOSSALB !co single scattering albedo of impurities
402 !
403 REAL,DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2)) :: ZABS_IMP
404 !
405 INTEGER :: JIMP !loop counter
406 INTEGER :: JB, JL,JJ !loop counter
407 !
408 REAL(KIND=JPRB) :: ZHOOK_HANDLE
409 !
410 IF (lhook) CALL dr_hook('IMPURITIES_CO_SINGLE_SCATTERING_ALBEDO',0,zhook_handle)
411 !
412 pcossalb = 0.
413 !
414 DO jb = 1,npnbands
415  DO jimp = 1,npnimp
416  DO jl = 1,kmax_use
417  DO jj = 1,SIZE(knlvls_use)
418  !
419  IF ( knlvls_use(jj)>=jl ) THEN
420  !
421  zabs_imp(jj,jl) = -xrefimp_i(jb,jimp)
422  pcossalb(jj,jl,jb) = pcossalb(jj,jl,jb) + &
423  12. * xpi / ( xpwavelengths_m(jb)*psnowssa(jj,jl) ) * &
424  psnowimp_content(jj,jl,jimp) / psnowimp_density(jj,jl,jimp) * &
425  zabs_imp(jj,jl) !doc equation 79
426  !
427  ENDIF
428  !
429  ENDDO
430  ENDDO
431  ENDDO
432 ENDDO
433 !
434 IF (lhook) CALL dr_hook('IMPURITIES_CO_SINGLE_SCATTERING_ALBEDO',1,zhook_handle)
435 !
437 !--------------------------------------------------------------------------------
438 !--------------------------------------------------------------------------------
439 SUBROUTINE single_scattering_optical_parameters(PSNOWSSA,PSNOWRHO,PSNOWG0,PSNOWY0,PSNOWW0,PSNOWB0, &
440  PSNOWIMP_DENSITY,PSNOWIMP_CONTENT,KNLVLS_USE,KMAX_USE, &
441  PSNOWSSALB,PSNOWG)
442 !
443 !see doc Section 2.3, 2.5, 2.6
445 !
446 IMPLICIT NONE
447 !
448 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWSSA !snow specific surface area (m^2/kg) (npoints,nlayer)
449 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWRHO !snow density (kg/m^3) (npoints,nlayer)
450 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWG0 ! asymmetry parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit) (npoints,nlayer)
451 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWY0 ! Value of y of snow grains at nr=1.3 (no unit
452 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWW0 ! Value of W of snow grains at nr=1.3 (no unit)
453 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWB0 ! absorption enhancement parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit)
454 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_DENSITY !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
455 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_CONTENT !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
456 INTEGER, DIMENSION(:), INTENT(IN) :: KNLVLS_USE !number of active layers
457 INTEGER, INTENT(IN) :: KMAX_USE !maximum number of active layers over the domain
458 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSNOWSSALB !total single scattering albedo (npoints,nlayer,nbands)
459 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSNOWG !asymmetry factor (npoints,nlayer,nbands)
460 !
461 !Local variables
462 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZSNOWG00,ZSNOWY,ZSNOWW,ZSNOWB
463 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZSNOWCOSSALB ! co- single scattering albedo of pure snow
464 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2),NPNBANDS) :: ZIMPCOSSALB ! co- single scattering albedo of impurities
465 !
466 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2)) :: ZC,ZPHI
467 !
468 INTEGER :: JB,JL,JJ !loop counter
469 !
470 REAL(KIND=JPRB) :: ZHOOK_HANDLE
471 !
472 IF (lhook) CALL dr_hook('SINGLE_SCATTERING_OPTICAL_PARAMETERS',0,zhook_handle)
473 !
474  CALL shape_parameter_variations(psnowg0,psnowy0,psnoww0,psnowb0,zsnowg00,zsnowy,zsnoww,zsnowb)
475 !
476 DO jl = 1,kmax_use
477  !
478  DO jj =1,SIZE(psnowssa,1)
479  !
480  IF ( knlvls_use(jj)>=jl ) THEN
481  !
482  DO jb = 1,npnbands
483  !
484  ! calculation of the spectral asymmetry parameter of snow
485  zc(jj,jl) = xconst_c(jb) / psnowssa(jj,jl)
486  !
487  psnowg(jj,jl,jb) = xginf(jb) - ( xginf(jb)-zsnowg00(jj,jl,jb) ) * exp( -zsnowy(jj,jl,jb)*zc(jj,jl) )
488  !
489  ! co- single scattering albedo of pure snow
490  zphi(jj,jl) = 2./3. * zsnowb(jj,jl,jb) / ( 1.-zsnoww(jj,jl,jb) )
491  zsnowcossalb(jj,jl,jb) = 0.5 * ( 1.-zsnoww(jj,jl,jb) ) * ( 1.-exp( -zphi(jj,jl)*zc(jj,jl) ) ) !doc equation 76
492  !
493  ENDDO
494  !
495  ENDIF
496  !
497  ENDDO
498  !
499 ENDDO
500 !
501 !adding co- single scattering albedo for impureties
502  CALL impurities_co_single_scattering_albedo(psnowssa,psnowimp_density,psnowimp_content,&
503  knlvls_use,kmax_use,zimpcossalb)
504 !
505 zsnowcossalb = zsnowcossalb + zimpcossalb
506 !
507 !total single scattering albedo
508 psnowssalb = 1.-zsnowcossalb
509 !
510 IF (lhook) CALL dr_hook('SINGLE_SCATTERING_OPTICAL_PARAMETERS',1,zhook_handle)
511 !
513 !--------------------------------------------------------------------------------
514 !--------------------------------------------------------------------------------
515 SUBROUTINE infinite_medium_optical_parameters(PSNOWSSALB,PSNOWG,KNLVLS_USE,KMAX_USE,PSNOWALBEDO,PKESTAR,&
516  PG_STAR,PSSALB_STAR,PGAMMA1,PGAMMA2)
517 !return albedo and kestar using Delta-Eddington Approximation (The Delta-Eddington Approximation of Radiative Flux Transfer, Jospeh et al (1976)).
518 ! Fluxes in the snowpack depend on these 2 quantities
519 ! see doc section 1.4
520 !
521 USE modd_const_tartes, ONLY: npnbands
522 USE modd_snow_metamo, ONLY: xuepsi
523 !
524 IMPLICIT NONE
525 !
526 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWSSALB !total single scattering albedo (npoints,nlayer,nbands)
527 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWG !asymmetry factor (npoints,nlayer,nbands)
528 INTEGER, DIMENSION(:), INTENT(IN) :: KNLVLS_USE !number of active layers
529 INTEGER, INTENT(IN) :: KMAX_USE !maximum number of active layers over the domain
530 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PSNOWALBEDO ! Albedo (npoints,nlayer,nbands)
531 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PKESTAR !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
532 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PG_STAR,PSSALB_STAR,PGAMMA1,PGAMMA2 !(npoints,nlayer,nbands)
533 !
534 INTEGER :: JB,JL,JJ !loop counter
535 !
536 REAL(KIND=JPRB) :: ZHOOK_HANDLE
537 !
538 IF (lhook) CALL dr_hook('INFINITE_MEDIUM_OPTICAL_PARAMETERS',0,zhook_handle)
539 !
540 DO jb = 1,npnbands
541  !
542  DO jl = 1,kmax_use
543  !
544  DO jj =1,SIZE(psnowg,1)
545  !
546  IF ( knlvls_use(jj)>=jl ) THEN
547  !
548  pg_star(jj,jl,jb) = psnowg(jj,jl,jb) / ( 1. + psnowg(jj,jl,jb) ) !doc equation 12
549  pssalb_star(jj,jl,jb) = psnowssalb(jj,jl,jb) * ( 1. - psnowg(jj,jl,jb)**2 ) / &
550  ( 1. - psnowg(jj,jl,jb)**2 * psnowssalb(jj,jl,jb) ) !doc equation 16
551  !
552  ! Jimenez-Aquino, J. and Varela, J. R., (2005)
553  pgamma1(jj,jl,jb) = 0.25 * ( 7. - pssalb_star(jj,jl,jb)*(4.+3.*pg_star(jj,jl,jb)) ) !doc equation 38
554  pgamma2(jj,jl,jb) = -0.25 * ( 1. - pssalb_star(jj,jl,jb)*(4.-3.*pg_star(jj,jl,jb)) ) !doc equation 39
555  !
556  pkestar(jj,jl,jb) = sqrt( pgamma1(jj,jl,jb)**2 - pgamma2(jj,jl,jb)**2 ) !doc equation 42
557  psnowalbedo(jj,jl,jb) = ( pgamma1(jj,jl,jb)-pkestar(jj,jl,jb) ) / pgamma2(jj,jl,jb) !doc equation 43
558  !
559  ! Modif M Lafaysse to avoid division by 0
560  !NB JJ note that this variable can be negative in infra-red wavelengths (it represents the albedo only in smallest wavelengths
561  IF ( abs(psnowalbedo(jj,jl,jb))<xuepsi ) THEN
562  psnowalbedo(jj,jl,jb) = sign( xuepsi, psnowalbedo(jj,jl,jb) )
563  ENDIF
564  !
565  ENDIF
566  !
567  ENDDO
568  !
569  ENDDO
570  !
571 ENDDO
572 !
573 IF (lhook) CALL dr_hook('INFINITE_MEDIUM_OPTICAL_PARAMETERS',1,zhook_handle)
574 !
576 !--------------------------------------------------------------------------------
577 !--------------------------------------------------------------------------------
578 !
579 SUBROUTINE taustar_vector(PSNOWSSA,PSNOWRHO,PSNOWDZ,PSNOWSSALB,PSNOWG,PKESTAR,KNLVLS_USE,KMAX_USE,&
580  PDTAUSTAR,PTAUSTAR)
581 !compute the taustar and dtaustar of the snowpack, the optical depth of each layer and cumulated optical depth
582 !see doc Section 1.2, 1.8, 2.4
583 !
585 !
586 IMPLICIT NONE
587 !
588 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWSSA !snow specific surface area (m^2/kg) (npoints,nlayer)
589 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWRHO !snow density (kg/m^3) (npoints,nlayer)
590 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWDZ !snow depth (m) (npoints,nlayer)
591 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWSSALB !total single scattering albedo (npoints,nlayer,nbands)
592 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWG ! asymmetry factor (npoints,nlayer,nbands)
593 REAL, DIMENSION(:,:,:), INTENT(IN) :: PKESTAR !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
594 INTEGER, DIMENSION(:), INTENT(IN) :: KNLVLS_USE !number of active layers
595 INTEGER, INTENT(IN) :: KMAX_USE !maximum number of active layers over the domain
596 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PDTAUSTAR !Optical depth of each layer
597 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PTAUSTAR !Cumulated optical depth
598 !
599 REAL, DIMENSION(SIZE(PSNOWSSA,1),SIZE(PSNOWSSA,2)) :: ZSIGEXT ! Extinction coefficient (npoints,nlayer)
600 !
601 INTEGER :: JB,JL !loop counters
602 !
603 REAL(KIND=JPRB) :: ZHOOK_HANDLE
604 !
605 IF (lhook) CALL dr_hook('TAUSTAR_VECTOR',0,zhook_handle)
606 !
607 !Compute extinction coefficient
608 zsigext = psnowrho*psnowssa/2. !doc equation 75
609 !
610 DO jb=1,npnbands
611  !
612  DO jl = 1,kmax_use
613  !
614  WHERE ( knlvls_use>=jl )
615  !Optical depth of each layer with delta-eddington variable change, doc equation 15
616  ! + optical depth threshold (doc section 1.8)
617  pdtaustar(:,jl,jb) = min( zsigext(:,jl) * psnowdz(:,jl) * ( 1.- psnowssalb(:,jl,jb)*psnowg(:,jl,jb)**2 ), &
618  xpmax_opticaldepth / pkestar(:,jl,jb) )
619  ENDWHERE
620  !
621  END DO
622  !
623  !Cumulated optical depth
624  !First layer
625  ptaustar(:,1,jb) = pdtaustar(:,1,jb)
626  !Other layers
627  DO jl = 2,kmax_use
628  WHERE ( knlvls_use>=jl )
629  ptaustar(:,jl,jb) = ptaustar(:,jl-1,jb) + pdtaustar(:,jl,jb)
630  ENDWHERE
631  END DO
632  !
633 END DO
634 
635 IF (lhook) CALL dr_hook('TAUSTAR_VECTOR',1,zhook_handle)
636 
637 END SUBROUTINE taustar_vector
638 !--------------------------------------------------------------------------------
639 !--------------------------------------------------------------------------------
640 SUBROUTINE estimate_effective_layer_number(PKESTAR,PDTAUSTAR,KNLVLS_USE,KMAX_USE,KNLVLS_EFF,KMAX_EFF)
641 ! estimate the number of layers to take into account at each wavelength
642 !doc section 1.8
643 !
645 !
646 IMPLICIT NONE
647 !
648 REAL, DIMENSION(:,:,:), INTENT(IN) :: PKESTAR !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
649 REAL, DIMENSION(:,:,:), INTENT(IN) :: PDTAUSTAR !Optical depth of each layer
650 INTEGER, DIMENSION(:), INTENT(IN) :: KNLVLS_USE !number of active layers
651 INTEGER, INTENT(IN) :: KMAX_USE !maximum number of active layers over the domain
652 INTEGER, DIMENSION(:,:), INTENT(OUT) :: KNLVLS_EFF !number of effective layers (npoints,nbands)
653 INTEGER, DIMENSION(:), INTENT(OUT) :: KMAX_EFF !maximum number of effective layers over the domain (nbands)
654 !
655 REAL, DIMENSION(SIZE(PKESTAR,1),SIZE(PKESTAR,2),NPNBANDS) :: ZTAU
656 LOGICAL, DIMENSION(SIZE(PKESTAR,1)) :: GEFF
657 INTEGER :: JB,JL !loop counter
658 !
659 REAL(KIND=JPRB) :: ZHOOK_HANDLE
660 !
661 IF (lhook) CALL dr_hook('ESTIMATE_EFFECTIVE_LAYER_NUMBER',0,zhook_handle)
662 !
663 DO jb = 1,npnbands
664  !
665  knlvls_eff(:,jb) = knlvls_use
666  ztau(:,1,jb) = pkestar(:,1,jb) * pdtaustar(:,1,jb)
667  geff = .true.
668  !
669  DO jl = 2,kmax_use
670  !
671  WHERE ( (knlvls_use>=jl) .AND. geff )
672  ztau(:,jl,jb) = ztau(:,jl-1,jb) + pkestar(:,jl,jb) * pdtaustar(:,jl,jb)
673  ELSEWHERE
674  ztau(:,jl,jb) = 0.
675  ENDWHERE
676  WHERE ( ztau(:,jl,jb)>xptaumax )
677  knlvls_eff(:,jb) = max(1,jl-1)
678  geff = .false.
679  ENDWHERE
680  !
681  END DO
682  !
683  kmax_eff(jb) = maxval(knlvls_eff(:,jb))
684  !
685 END DO
686 
687 IF (lhook) CALL dr_hook('ESTIMATE_EFFECTIVE_LAYER_NUMBER',1,zhook_handle)
688 
689 END SUBROUTINE estimate_effective_layer_number
690 !--------------------------------------------------------------------------------
691 !--------------------------------------------------------------------------------
692 !
693 SUBROUTINE gp_gm_vectors(PSNOWSSALB,PKESTAR,PG_STAR,PSSALB_STAR,PGAMMA1,PGAMMA2,PCOSZEN,PSW_RAD,KNLVLS_EFF,KMAX_EFF,PGP,PGM)
694 !
695 !return GP and GM vectors of equations 40/41 and 46/47
696 ! (equations for the downward and upward fluxes in the snowpack for the 2 stream approximation)
697 !
698 USE modd_const_tartes, ONLY : npnbands
699 !
700 IMPLICIT NONE
701 !
702 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWSSALB !total single scattering albedo (npoints,nlayer,nbands)
703 REAL, DIMENSION(:,:,:), INTENT(IN) :: PKESTAR !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
704 REAL, DIMENSION(:,:,:), INTENT(IN) :: PG_STAR ! asymmetry factor * (npoints,nlayer,nbands)
705 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSSALB_STAR
706 REAL, DIMENSION(:,:,:), INTENT(IN) :: PGAMMA1,PGAMMA2
707 REAL, DIMENSION(:,:), INTENT(IN) :: PSW_RAD ! incident radiation (direct or diffuse) (npoints,nbands)
708 REAL, DIMENSION(:), INTENT(IN) :: PCOSZEN ! cosine of zenithal solar angle (npoints)
709 INTEGER, DIMENSION(:,:), INTENT(IN) :: KNLVLS_EFF !number of effective layers (npoints,nbands)
710 INTEGER, DIMENSION(:), INTENT(IN) :: KMAX_EFF !maximum number of effective layers over the domain (nbands)
711 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PGP !GP vector (npoints,nlayer,nbands)
712 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PGM !GM vector (npoints,nlayer,nbands)
713 !
714 REAL :: ZGAMMA3,ZGAMMA4,ZG ! intermediate terms
715 !
716 INTEGER :: JB,JL,JJ !loop counter
717 !
718 REAL(KIND=JPRB) :: ZHOOK_HANDLE
719 !
720 IF (lhook) CALL dr_hook('GP_GM_VECTORS',0,zhook_handle)
721 !
722 !Init
723 pgp = 0.
724 pgm = 0.
725 !
726 DO jb = 1,npnbands
727  !
728  DO jl = 1,kmax_eff(jb)
729  !
730  DO jj =1,SIZE(psw_rad,1)
731  !
732  IF ( psw_rad(jj,jb)>0. .AND. knlvls_eff(jj,jb)>=jl ) THEN
733  !
734  zgamma3 = 0.25 * ( 2. - 3.*pg_star(jj,jl,jb)*pcoszen(jj) ) !doc equation 28
735  zgamma4 = 0.25 * ( 2. + 3.*pg_star(jj,jl,jb)*pcoszen(jj) ) !doc equation 27
736  zg = pcoszen(jj)**2 * pssalb_star(jj,jl,jb) / ( (pkestar(jj,jl,jb)*pcoszen(jj))**2 - 1. ) !factor eq 44-45
737  pgp(jj,jl,jb) = zg * ( (pgamma1(jj,jl,jb)-1./pcoszen(jj))*zgamma3 + pgamma2(jj,jl,jb)*zgamma4 ) !doc equation 45
738  pgm(jj,jl,jb) = zg * ( (pgamma1(jj,jl,jb)+1./pcoszen(jj))*zgamma4 + pgamma2(jj,jl,jb)*zgamma3 ) !doc equation 44
739  !
740  ENDIF
741  !
742  ENDDO
743  !
744  END DO
745  !
746 END DO
747 !
748 IF (lhook) CALL dr_hook('GP_GM_VECTORS',1,zhook_handle)
749 !
750 END SUBROUTINE gp_gm_vectors
751 !--------------------------------------------------------------------------------
752 !--------------------------------------------------------------------------------
753 SUBROUTINE two_stream_matrix(PSNOWALBEDO,PSOILALBEDO,PKESTAR,PDTAUSTAR,KNLVLS_EFF,KMAX_EFF,PDM,PD,PDP)
754 !compute the matrix in the system describing the continuity and boundary conditions at one point and one wavelength.
755 ! see doc section 1.5
756 !
757 USE modd_const_tartes, ONLY : npnbands
758 !
759 IMPLICIT NONE
760 !
761 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWALBEDO ! snow albedo (npoints,nlayer,nbands)
762 REAL, DIMENSION(:,:), INTENT(IN) :: PSOILALBEDO ! soil albedo (npoints,nbands)
763 REAL, DIMENSION(:,:,:), INTENT(IN) :: PKESTAR !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
764 REAL, DIMENSION(:,:,:), INTENT(IN) :: PDTAUSTAR !Optical depth of each layer
765 INTEGER, DIMENSION(:,:), INTENT(IN) :: KNLVLS_EFF !number of effective layers (npoints,nbands)
766 INTEGER, DIMENSION(:), INTENT(IN) :: KMAX_EFF !maximum number of effective layers over the domain (nbands)
767 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PDM,PD,PDP ! three diagnonals of the matrix
768 !
769 REAL, DIMENSION(SIZE(PSNOWALBEDO,1)) :: ZFDIAG
770 !
771 REAL :: ZFDIAG2
772 !
773 INTEGER :: JB,JL,JI !loop counter
774 !
775 REAL(KIND=JPRB) :: ZHOOK_HANDLE
776 !
777 IF (lhook) CALL dr_hook('TWO_STREAM_MATRIX',0,zhook_handle)
778 !
779 !Initialization
780 pdm = 0.
781 pd = 0.
782 pdp = 0.
783 !
784 DO jb = 1,npnbands
785  !
786  DO jl = 1,kmax_eff(jb)-1
787  !
788 ! IF(PSNOWALBEDO(1,JL,JB)<0.000001) THEN
789 ! PRINT*,"WARNING PSNOWALBEDO LAYER ",JL," BAND ",JB," : ",PSNOWALBEDO(1,JL,JB)
790 ! END IF
791 
792 
793 ! IF (EXP(-PKESTAR(1,JL,JB)*PDTAUSTAR(1,JL,JB))<0.000001) THEN
794 ! PRINT*,"WARNING ZFDIAG ",JL," BAND ",JB," : ",EXP(-PKESTAR(1,JL,JB)*PDTAUSTAR(1,JL,JB))
795 ! END IF
796 !
797  DO ji =1,SIZE(knlvls_eff,1)
798  !
799  IF ( jl<=knlvls_eff(ji,jb)-1 ) THEN
800  !
801  !See matrix documentation page 8 and formal expressions page 9
802  zfdiag(ji) = exp( -pkestar(ji,jl,jb)*pdtaustar(ji,jl,jb) )
803  !
804  !Décalage d'un indice vers la droite par rapport au code python
805  pdm(ji,jl*2,jb) = ( 1. - psnowalbedo(ji,jl,jb)*psnowalbedo(ji,jl+1,jb) ) * zfdiag(ji)
806  pdm(ji,jl*2+1,jb) = ( 1./psnowalbedo(ji,jl,jb) - psnowalbedo(ji,jl,jb) ) * 1./zfdiag(ji)
807  !
808  pd(ji,jl*2,jb) = ( 1. - psnowalbedo(ji,jl+1,jb)/psnowalbedo(ji,jl,jb) ) * 1./zfdiag(ji)
809  pd(ji,jl*2+1,jb) = psnowalbedo(ji,jl,jb) - psnowalbedo(ji,jl+1,jb)
810  !
811  !Décalage d'un indice vers la gauche par rapport au code python
812  pdp(ji,jl*2,jb) = psnowalbedo(ji,jl+1,jb) * psnowalbedo(ji,jl+1,jb) - 1.
813  pdp(ji,jl*2+1,jb) = psnowalbedo(ji,jl,jb) - 1./psnowalbedo(ji,jl+1,jb)
814  !
815  ENDIF
816  !
817  ENDDO
818  !
819  ENDDO
820  !
821  pdp(:,1,jb) = 1. !Décalage d'un indice vers la gauche par rapport au code python
822  pd(:,1,jb) = 1.
823  !
824  DO ji=1,SIZE(psnowalbedo,1)
825  !
826  zfdiag2 = exp( -pkestar(ji,knlvls_eff(ji,jb),jb) * pdtaustar(ji,knlvls_eff(ji,jb),jb) )
827  !
828  !Décalage d'un indice vers la droite par rapport au code python
829  pdm(ji,2*knlvls_eff(ji,jb),jb) = zfdiag2 * &
830  ( psnowalbedo(ji,knlvls_eff(ji,jb),jb) - psoilalbedo(ji,jb) )
831  !
832  pd(ji,2*knlvls_eff(ji,jb),jb) = 1./zfdiag2 * &
833  ( 1./psnowalbedo(ji,knlvls_eff(ji,jb),jb) - psoilalbedo(ji,jb) )
834  END DO
835  !
836 END DO
837 !
838 IF (lhook) CALL dr_hook('TWO_STREAM_MATRIX',1,zhook_handle)
839 !
840 END SUBROUTINE two_stream_matrix
841 !--------------------------------------------------------------------------------
842 !--------------------------------------------------------------------------------
843 SUBROUTINE two_stream_vector(PSNOWALBEDO,PSOILALBEDO,PDTAUSTAR,PTAUSTAR,PGM,PGP,PCOSZEN,KNLVLS_EFF,KMAX_EFF,PVECTOR)
844 !compute the V vector in the system describing the continuity and boundary conditions at one point and one wavelength.
845 ! see doc section 1.5
846 !
847 USE modd_const_tartes, ONLY : npnbands
848 !
849 IMPLICIT NONE
850 !
851 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWALBEDO ! snow albedo (npoints,nlayer,nbands)
852 REAL, DIMENSION(:,:), INTENT(IN) :: PSOILALBEDO ! soil albedo (npoints,nbands)
853 REAL, DIMENSION(:,:,:), INTENT(IN) :: PDTAUSTAR !Optical depth of each layer
854 REAL, DIMENSION(:,:,:), INTENT(IN) :: PTAUSTAR !Cumulated optical depth
855 REAL, DIMENSION(:,:,:), INTENT(IN) :: PGP !GP vector (npoints,nlayer,nbands)
856 REAL, DIMENSION(:,:,:), INTENT(IN) :: PGM !GM vector (npoints,nlayer,nbands)
857 REAL, DIMENSION(:), INTENT(IN) :: PCOSZEN ! cosine of zenithal solar angle (npoints)
858 INTEGER, DIMENSION(:,:), INTENT(IN) :: KNLVLS_EFF !number of effective layers (npoints,nbands)
859 INTEGER, DIMENSION(:), INTENT(IN) :: KMAX_EFF !maximum number of effective layers over the domain (nbands)
860 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PVECTOR !output vector V
861 !
862 REAL :: ZDGP,ZDGM,ZEXP
863 !
864 INTEGER :: JB,JL,JI !loop counter
865 !
866 REAL(KIND=JPRB) :: ZHOOK_HANDLE
867 !
868 IF (lhook) CALL dr_hook('TWO_STREAM_VECTOR',0,zhook_handle)
869 !
870 pvector(:,1,:) = -pgm(:,1,:)
871 !
872 DO jb = 1,npnbands
873  !
874  DO ji = 1,SIZE(psnowalbedo,1)
875  !
876  DO jl = 1,kmax_eff(jb)
877  !
878  IF ( jl<=knlvls_eff(ji,jb)-1 ) THEN
879  !
880  zdgp = pgp(ji,jl+1,jb) - pgp(ji,jl,jb) !doc equation 58
881  zdgm = pgm(ji,jl+1,jb) - pgm(ji,jl,jb) !doc equation 58
882  !
883  zexp = exp( -ptaustar(ji,jl,jb)/pcoszen(ji) )
884  !see expression doc page 9
885  pvector(ji,2*jl,jb) = ( zdgm - psnowalbedo(ji,jl+1,jb) * zdgp ) * zexp
886  pvector(ji,2*jl+1,jb) = ( zdgp - psnowalbedo(ji,jl,jb) * zdgm ) * zexp
887  !
888  END IF
889  !
890  END DO
891  !
892  pvector(ji,2*knlvls_eff(ji,jb),jb) = ( psoilalbedo(ji,jb) * &
893  ( pgm(ji,knlvls_eff(ji,jb),jb) + pcoszen(ji) ) - &
894  pgp(ji,knlvls_eff(ji,jb),jb) ) * &
895  exp( -ptaustar(ji,knlvls_eff(ji,jb),jb) / pcoszen(ji) )
896  !
897  END DO
898  !
899 END DO
900 !
901 IF (lhook) CALL dr_hook('TWO_STREAM_VECTOR',1,zhook_handle)
902 !
903 END SUBROUTINE two_stream_vector
904 !--------------------------------------------------------------------------------
905 !--------------------------------------------------------------------------------
906 SUBROUTINE solves_two_stream2(PDM,PD,PDP,PVECT_DIR,PVECT_DIF,PSNOWALBEDO,PSW_RAD_DIR,PSW_RAD_DIF,KNLVLS_EFF, &
907  KMAX_EFF,PXA_DIR,PXA_DIF,PXB_DIR,PXB_DIF,PXC_DIR,PXC_DIF,PXD_DIR,PXD_DIF)
908 !solve the two stream linear system for both direct and diffuse radiation
909 !
910 USE modd_const_tartes, ONLY : npnbands
911 !
913 !
914 IMPLICIT NONE
915 !
916 REAL, DIMENSION(:,:,:), INTENT(IN) :: PDM,PD,PDP ! three diagnonals of the matrix
917 REAL, DIMENSION(:,:,:), INTENT(IN) :: PVECT_DIR,PVECT_DIF !two-stream vector V (2 vectors are used when ther is diffuse AND direct incident light)
918 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWALBEDO! snow albedo (npoints,nlayer,nbands)
919 REAL, DIMENSION(:,:), INTENT(IN) :: PSW_RAD_DIR,PSW_RAD_DIF !not used for now : useful if we want to pack the points excluding zero radiations
920 INTEGER, DIMENSION(:,:), INTENT(IN) :: KNLVLS_EFF !number of effective layers (npoints,nbands)
921 INTEGER, DIMENSION(:), INTENT(IN) :: KMAX_EFF !maximum number of effective layers over the domain (nbands)
922 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PXA_DIR,PXA_DIF,PXB_DIR,PXB_DIF,PXC_DIR,PXC_DIF,PXD_DIR,PXD_DIF ! solutions (coeffs A and B in eq 46-47 or 48-49)
923 !
924 REAL, DIMENSION(SIZE(PDM,1),2*SIZE(PSNOWALBEDO,2),NPNBANDS) :: ZX0_DIR,ZX0_DIF
925 INTEGER :: JB,JI,JL !loop counters
926 !
927 REAL(KIND=JPRB) :: ZHOOK_HANDLE
928 !
929 IF (lhook) CALL dr_hook('SOLVES_TWO_STREAM2',0,zhook_handle)
930 !
931 ! for now we inverse the matrix twice :
932 ! to be improved by adding a dimension in tridiag_ground_snowcro
933  CALL tridiag_ground_snowcro(pdm(:,:,:),pd(:,:,:),pdp(:,:,:), &
934  pvect_dir(:,:,:),zx0_dir(:,:,:), &
935  2*knlvls_eff(:,:),0)
936 !
937  CALL tridiag_ground_snowcro(pdm(:,:,:),pd(:,:,:),pdp(:,:,:), &
938  pvect_dif(:,:,:),zx0_dif(:,:,:), &
939  2*knlvls_eff(:,:),0)
940 !
941 !for now we always compute everything
942 DO jb = 1,npnbands
943  !
944  DO jl=1,kmax_eff(jb)
945  !
946  DO ji=1,SIZE(pdm,1)
947  !
948  IF ( jl<=knlvls_eff(ji,jb) ) THEN
949  pxa_dir(ji,jl,jb) = zx0_dir(ji,jl*2-1,jb)
950  pxa_dif(ji,jl,jb) = zx0_dif(ji,jl*2-1,jb)
951  pxb_dir(ji,jl,jb) = zx0_dir(ji,jl*2,jb)
952  pxb_dif(ji,jl,jb) = zx0_dif(ji,jl*2,jb)
953  !
954  pxc_dir(ji,jl,jb) = pxa_dir(ji,jl,jb) * psnowalbedo(ji,jl,jb)
955  pxc_dif(ji,jl,jb) = pxa_dif(ji,jl,jb) * psnowalbedo(ji,jl,jb)
956  pxd_dir(ji,jl,jb) = pxb_dir(ji,jl,jb) / psnowalbedo(ji,jl,jb)
957  pxd_dif(ji,jl,jb) = pxb_dif(ji,jl,jb) / psnowalbedo(ji,jl,jb)
958  END IF
959  !
960  END DO
961  !
962  END DO
963  !
964 END DO
965 !
966 IF (lhook) CALL dr_hook('SOLVES_TWO_STREAM2',1,zhook_handle)
967 !
968 END SUBROUTINE solves_two_stream2
969 !--------------------------------------------------------------------------------
970 !--------------------------------------------------------------------------------
971 SUBROUTINE snowpack_albedo(PXC_DIR,PXC_DIF,PXD_DIR,PXD_DIF,PGP_DIR,PGP_DIF,&
972  PCOSZEN_DIR,PCOSZEN_DIF,PSW_RAD_DIR,PSW_RAD_DIF,PSNOWALB)
973 ! compute the albedo of the snowpack at one wavelength
974 !
975 USE modd_const_tartes, ONLY : npnbands
976 !
977 IMPLICIT NONE
978 !
979 REAL, DIMENSION(:,:), INTENT(IN) :: PXC_DIR,PXC_DIF,PXD_DIR,PXD_DIF ! for first level (npoints*nbands)
980 REAL, DIMENSION(:,:), INTENT(IN) :: PGP_DIR,PGP_DIF ! for first level (npoints*nbands)
981 REAL, DIMENSION(:), INTENT(IN) :: PCOSZEN_DIR,PCOSZEN_DIF ! cosine of zenithal solar angle (npoints)
982 REAL, DIMENSION(:,:), INTENT(IN) :: PSW_RAD_DIR,PSW_RAD_DIF ! incident radiation W/m^2 (npoints*nbands)
983 REAL, DIMENSION(:,:), INTENT(OUT) :: PSNOWALB ! albedo at one wavelength
984 !
985 REAL,DIMENSION(SIZE(PSW_RAD_DIR,1)) :: ZREF_DIR,ZREF_DIF ! reflected direct and diffuse radiations W/m^2
986  ! for one band
987 REAL,DIMENSION(SIZE(PSW_RAD_DIR,1)) :: ZINC ! incident radiation
988 !
989 INTEGER :: JB !loop counter
990 !
991 REAL(KIND=JPRB) :: ZHOOK_HANDLE
992 !
993 IF (lhook) CALL dr_hook('SNOWPACK_ALBEDO',0,zhook_handle)
994 !
995 DO jb = 1,npnbands
996  !
997  ! Doc equation 66 (separated in direct and diffuse components)
998  zref_dir = ( pxc_dir(:,jb)+pxd_dir(:,jb)+pgp_dir(:,jb) ) * psw_rad_dir(:,jb)
999  zref_dif = ( pxc_dif(:,jb)+pxd_dif(:,jb)+pgp_dif(:,jb) ) * psw_rad_dif(:,jb)
1000  zinc = psw_rad_dir(:,jb)*pcoszen_dir + psw_rad_dif(:,jb)*pcoszen_dif
1001  WHERE ( zinc>0. )
1002  psnowalb(:,jb) = (zref_dir+zref_dif) / zinc
1003  ELSEWHERE
1004  psnowalb(:,jb) = 0.
1005  ENDWHERE
1006  !
1007 END DO
1008 
1009 IF (lhook) CALL dr_hook('SNOWPACK_ALBEDO',1,zhook_handle)
1010 
1011 END SUBROUTINE snowpack_albedo
1012 !--------------------------------------------------------------------------------
1013 !--------------------------------------------------------------------------------
1014 SUBROUTINE energy_profile(PXA,PXB,PXC,PXD,PKESTAR,PDTAUSTAR,PTAUSTAR,PGM,PGP,PCOSZEN,KNLVLS_EFF,KMAX_EFF,PEPROFILE)
1016  !compute energy absorption for each layer and wavelength
1017 USE modd_const_tartes, ONLY : npnbands
1018 !
1019 IMPLICIT NONE
1020 !
1021 REAL, DIMENSION(:,:,:), INTENT(IN) :: PXA,PXB,PXC,PXD ! solutions of linear system (npoints,nlayer,nbands)
1022 REAL, DIMENSION(:,:,:), INTENT(IN) :: PKESTAR !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
1023 REAL, DIMENSION(:,:,:), INTENT(IN) :: PDTAUSTAR !Optical depth of each layer (npoints,nlayer,nbands)
1024 REAL, DIMENSION(:,:,:), INTENT(IN) :: PTAUSTAR !Cumulated optical depth (npoints,nlayer,nbands)
1025 REAL, DIMENSION(:,:,:), INTENT(IN) :: PGP !GP vector (npoints,nlayer,nbands)
1026 REAL, DIMENSION(:,:,:), INTENT(IN) :: PGM !GM vector (npoints,nlayer,nbands)
1027 REAL, DIMENSION(:), INTENT(IN) :: PCOSZEN! cosine of zenithal solar angle (npoints)
1028 INTEGER, DIMENSION(:,:), INTENT(IN) :: KNLVLS_EFF !number of effective layers (npoints,nbands)
1029 INTEGER, DIMENSION(:), INTENT(IN) :: KMAX_EFF !maximum number of effective layers over the domain (nbands)
1030 REAL, DIMENSION(:,:,:), INTENT(OUT) :: PEPROFILE ! energy absorbed by each layer (W/m^2) npoints,nlayer,nbands)
1031 !
1032 REAL :: ZINT1, ZINT2, ZINT3, ZINT4, ZINT5
1033 REAL :: ZDEXP, ZFDU, ZFDD, ZSTAR
1034 !
1035 INTEGER::JB,JL,JJ !loop counter
1036 !
1037 REAL(KIND=JPRB) :: ZHOOK_HANDLE
1038 !
1039 IF (lhook) CALL dr_hook('ENERGY_PROFILE',0,zhook_handle)
1040 
1041 DO jb = 1,npnbands
1042  !
1043  DO jj =1,SIZE(peprofile,1)
1044  !
1045  DO jl = 1,kmax_eff(jb)
1046  !
1047  IF (jl==1.OR.jl<=knlvls_eff(jj,jb)) THEN
1048  !
1049  zstar = pkestar(jj,jl,jb) * pdtaustar(jj,jl,jb)
1050  zint1 = exp(-zstar)
1051  zint2 = exp( zstar)
1052  !
1053  IF (jl==1) THEN
1054  !
1055  zint3 = exp( -pdtaustar(jj,jl,jb)/pcoszen(jj))
1056  zint4 = exp( -ptaustar(jj,jl,jb)/pcoszen(jj))
1057  !
1058  !surface layer doc equation 64
1059  peprofile(jj,1,jb) = ( pcoszen(jj) - ( pxc(jj,1,jb)+pxd(jj,1,jb)+pgp(jj,1,jb) ) ) + &
1060  ( pxc(jj,1,jb) * zint1 + pxd(jj,1,jb) * zint2 + &
1061  pgp(jj,1,jb) * zint3 ) - &
1062  ( pxa(jj,1,jb) * zint1 + pxb(jj,1,jb) * zint2 + &
1063  pgm(jj,1,jb) * zint3 + &
1064  pcoszen(jj) * zint4 )
1065  !
1066  ELSE
1067  !
1068  zint5 = exp( -ptaustar(jj,jl ,jb)/pcoszen(jj) )
1069  !last factor in equations 62 and 63
1070  zdexp = zint5 - zint4
1071  zint4 = zint5
1072  !
1073  !doc equation 62
1074  zfdu = pxc(jj,jl,jb) * ( zint1 -1. ) + &
1075  pxd(jj,jl,jb) * ( zint2 -1. ) + pgp(jj,jl,jb) * zdexp
1076  !
1077  !doc equation 63
1078  zfdd = pxa(jj,jl,jb) * ( zint1 -1. ) + &
1079  pxb(jj,jl,jb) * ( zint2 -1. ) + ( pgm(jj,jl,jb) + pcoszen(jj) ) * zdexp
1080  !
1081  peprofile(jj,jl,jb) = zfdu - zfdd !doc equation 61
1082  !
1083  ENDIF
1084  !
1085  ELSE
1086  !
1087  peprofile(jj,jl,jb) = 0.
1088  !
1089  ENDIF
1090  !
1091  ENDDO
1092  !
1093  ENDDO
1094  !
1095 ENDDO
1096 !
1097 IF (lhook) CALL dr_hook('ENERGY_PROFILE',1,zhook_handle)
1098 !
1099 END SUBROUTINE energy_profile
1100 !--------------------------------------------------------------------------------
1101 !--------------------------------------------------------------------------------
1102 SUBROUTINE soil_absorption(PXA,PXB,PKESTAR,PDTAUSTAR,PTAUSTAR,PGM,PCOSZEN,PALB,KNLVLS_EFF,PSOILENERGY)
1103 !compute the energy absorbed by the soil at each wavelength
1104 !
1105 USE modd_const_tartes, ONLY : npnbands
1106 !
1107 IMPLICIT NONE
1108 !
1109 REAL, DIMENSION(:,:,:), INTENT(IN) :: PXA,PXB ! solutions of linear system (npoints,nlayer,nbands)
1110 REAL, DIMENSION(:,:,:), INTENT(IN) :: PKESTAR !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
1111 REAL, DIMENSION(:,:,:), INTENT(IN) :: PDTAUSTAR !Optical depth of each layer (npoints,nlayer,nbands)
1112 REAL, DIMENSION(:,:,:), INTENT(IN) :: PTAUSTAR !Cumulated optical depth (npoints,nlayer,nbands)
1113 REAL, DIMENSION(:,:,:), INTENT(IN) :: PGM !GM vector (npoints,nlayer,nbands)
1114 REAL, DIMENSION(:), INTENT(IN) :: PCOSZEN! cosine of zenithal solar angle (npoints)
1115 REAL, DIMENSION(:,:), INTENT(IN) :: PALB! soil albedo (npoints,nbands)
1116 INTEGER, DIMENSION(:,:), INTENT(IN) :: KNLVLS_EFF !number of effective layers (npoints,nbands)
1117 REAL, DIMENSION(:,:), INTENT(OUT) :: PSOILENERGY
1118 INTEGER :: JB,JI !loop counter
1119 !
1120 REAL(KIND=JPRB) :: ZHOOK_HANDLE
1121 !
1122 IF (lhook) CALL dr_hook('SOIL_ABSORPTION',0,zhook_handle)
1123 !
1124 DO jb=1,npnbands
1125  !
1126  DO ji=1,SIZE(pxa,1)
1127  !
1128  !doc equation 65
1129  psoilenergy(ji,jb) = ( 1.-palb(ji,jb) ) * &
1130  ( pxa(ji,knlvls_eff(ji,jb),jb) * &
1131  exp( -pkestar(ji,knlvls_eff(ji,jb),jb) * pdtaustar(ji,knlvls_eff(ji,jb),jb) ) + &
1132  pxb(ji,knlvls_eff(ji,jb),jb) * &
1133  exp( pkestar(ji,knlvls_eff(ji,jb),jb) * pdtaustar(ji,knlvls_eff(ji,jb),jb) ) + &
1134  ( pgm(ji,knlvls_eff(ji,jb),jb)+pcoszen(ji) ) * &
1135  exp( -ptaustar(ji,knlvls_eff(ji,jb),jb)/pcoszen(ji) ) )
1136  !
1137  END DO
1138  !
1139 END DO
1140 
1141 IF (lhook) CALL dr_hook('SOIL_ABSORPTION',1,zhook_handle)
1142 
1143 END SUBROUTINE soil_absorption
1144 !--------------------------------------------------------------------------------
1145 !--------------------------------------------------------------------------------
1146 SUBROUTINE spectral_repartition(PSW_RAD,PCOSZEN,PSW_RAD_DIF,PSW_RAD_DIR,PNIR_ABS)
1149 
1150 IMPLICIT NONE
1151 
1152 REAL, DIMENSION(:), INTENT(IN) :: PSW_RAD ! broadband global incident light (W/m^2) (npoints)
1153 REAL, DIMENSION(:), INTENT(IN) :: PCOSZEN ! cosine of zenithal solar angle (npoints)
1154 REAL, DIMENSION(:,:), INTENT(OUT) :: PSW_RAD_DIF ! spectral diffuse incident light (W/m^2) (npoints,nbands)
1155 REAL, DIMENSION(:,:), INTENT(OUT) :: PSW_RAD_DIR ! spectral direct incident light (W/m^2) (npoints,nbands)
1156 REAL, DIMENSION(:), INTENT(OUT) :: PNIR_ABS ! Near infrared radiation (2500-4000 nm) absorbed by snowpack (W/m^2) (npoints)
1157 !
1158 REAL, DIMENSION(SIZE(PSW_RAD)) :: ZSW_RAD_BROADDIR,ZSW_RAD_BROADDIF ! direct and diffuse broadband incident light (W/m^2) (npoints)
1159 INTEGER :: JB !Loop counter
1160 !
1161 REAL(KIND=JPRB) :: ZHOOK_HANDLE
1162 !
1163 IF (lhook) CALL dr_hook('SPECTRAL_REPARTITION',0,zhook_handle)
1164 !
1165 ! Separate broadband global radiation in direct and diffuse (parametrization Marie Dumont)
1166 ! NB : thresold 1. to the factor when zenithal angle close to pi/2
1167 zsw_rad_broaddif = min( exp( - 1.54991930344*pcoszen**3 + 3.73535795329*pcoszen**2 &
1168  - 3.52421131883*pcoszen + 0.0299111951172 ), 1. ) * psw_rad
1169 zsw_rad_broaddir = psw_rad - zsw_rad_broaddif
1170 !
1171 ! Spectral decomposition
1172 DO jb = 1,npnbands
1173  psw_rad_dif(:,jb) = xpratio_dif(jb) * zsw_rad_broaddif / xp_mudiff
1174  psw_rad_dir(:,jb) = xpratio_dir(jb) * zsw_rad_broaddir / pcoszen(:)
1175 END DO
1176 
1177 pnir_abs = zsw_rad_broaddif*xpcoefnir_dif + zsw_rad_broaddir*xpcoefnir_dir
1178 
1179 IF (lhook) CALL dr_hook('SPECTRAL_REPARTITION',1,zhook_handle)
1180 
1181 END SUBROUTINE spectral_repartition
1182 !--------------------------------------------------------------------------------
1183 !--------------------------------------------------------------------------------
1184 SUBROUTINE snowcro_tartes(PSNOWGRAN1,PSNOWGRAN2,PSNOWRHO,PSNOWDZ,PSNOWG0,PSNOWY0,PSNOWW0,PSNOWB0, &
1185  PSNOWIMP_DENSITY,PSNOWIMP_CONTENT,PALB,PSW_RAD,PZENITH,KNLVLS_USE, &
1186  PSNOWALB,PRADSINK,PRADXS,ODEBUG,HSNOWMETAMO)
1188 ! Interface between Tartes and Crocus
1189 ! M. Lafaysse 26/08/2013
1190 !
1191 USE modd_const_tartes, ONLY : npnimp
1192 USE modd_snow_metamo, ONLY : xuepsi
1193 !
1194 IMPLICIT NONE
1195 !
1196 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWGRAN1,PSNOWGRAN2 ! (npoints,nlayer)
1197 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWRHO !snow density (kg/m^3) (npoints,nlayer)
1198 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWG0 ! asymmetry parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit) (npoints,nlayer)
1199 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWY0 ! Value of y of snow grains at nr=1.3 (no unit
1200 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWW0 ! Value of W of snow grains at nr=1.3 (no unit)
1201 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWB0 ! absorption enhancement parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit)
1202 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWDZ !snow layers thickness (m) (npoints,nlayer)
1203 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_DENSITY !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
1204 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_CONTENT !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
1205 !
1206 REAL, DIMENSION(:), INTENT(IN) :: PALB ! soil/vegetation albedo (npoints)
1207 !
1208 REAL, DIMENSION(:), INTENT(IN) :: PSW_RAD ! global broadband incident light (W/m^2) (npoints)
1209 REAL, DIMENSION(:), INTENT(IN) :: PZENITH ! zenithal solar angle (npoints)
1210 !
1211 INTEGER, DIMENSION(:), INTENT(IN) :: KNLVLS_USE ! number of effective snow layers (npoints)
1212 !
1213 !Same outputs as SNOWCRORAD and SNOWCROALB
1214 REAL, DIMENSION(:,:), INTENT(OUT) :: PRADSINK !(npoints,nlayers)
1215 REAL, DIMENSION(:), INTENT(OUT) :: PRADXS !(npoints,nlayers)
1216 REAL, DIMENSION(:), INTENT(OUT) :: PSNOWALB !(npoints,nlayers)
1217 !
1218 LOGICAL, INTENT(IN) :: ODEBUG ! Print for debugging
1219  CHARACTER(3), INTENT(IN) :: HSNOWMETAMO ! metamorphism scheme
1220 !
1221 !packed variables
1222 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2),NPNIMP) :: ZSNOWIMP_DENSITY_P !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
1223 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2),NPNIMP) :: ZSNOWIMP_CONTENT_P !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
1224 !
1225 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWGRAN1_P,ZSNOWGRAN2_P ! (npoints,nlayer)
1226 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWRHO_P !snow density (kg/m^3) (npoints,nlayer)
1227 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWG0_P ! asymmetry parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit) (npoints,nlayer)
1228 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWY0_P ! Value of y of snow grains at nr=1.3 (no unit
1229 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWW0_P ! Value of W of snow grains at nr=1.3 (no unit)
1230 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWB0_P ! absorption enhancement parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit)
1231 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWDZ_P !snow layers thickness (m) (npoints,nlayer)
1232 !
1233 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZRADSINK_P
1234 !
1235 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZALB_P ! soil/vegetation albedo (npoints)
1236 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZSW_RAD_P ! global broadband incident light (W/m^2) (npoints)
1237 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZZENITH_P ! zenithal solar angle (npoints)
1238 !
1239 !Same outputs as SNOWCRORAD and SNOWCROALB
1240 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZRADXS_P
1241 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZSNOWALB_P
1242 !
1243 INTEGER, DIMENSION(SIZE(PSNOWRHO,1)) :: INLVLS_USE_P ! number of effective snow layers (npoints)
1244 !
1245 INTEGER, DIMENSION(SIZE(PSNOWRHO,1)) :: IDAYMASK ! mask for points where it's day
1246 !
1247 INTEGER :: IMAX_USE ! maximum number of layers over the domain
1248 INTEGER :: JL,JIMP,JJ,JJ_P !Loop counter
1249 INTEGER :: IPOINTDAY
1250 INTEGER :: INPOINTS
1251 !
1252 REAL(KIND=JPRB) :: ZHOOK_HANDLE
1253 !
1254 IF (lhook) CALL dr_hook('SNOWCRO_TARTES',0,zhook_handle)
1255 !
1256 !Default values (night)
1257 pradsink = 0.
1258 pradxs = 0.
1259 psnowalb = 1.
1260 !
1261 inpoints = SIZE(psnowrho,1)
1262 !
1263 !Mask
1264 ipointday = 0
1265 DO jj = 1,inpoints
1266  IF ( cos(pzenith(jj))>xuepsi .AND. psw_rad(jj)>xuepsi ) THEN
1267  !mask for day
1268  ipointday = ipointday + 1
1269  idaymask(ipointday) = jj
1270  END IF
1271 END DO
1272 !
1273 IF ( ipointday>=1 ) THEN
1274  !
1275  ! Pack 1D variables
1276  DO jj_p = 1,ipointday
1277  !
1278  jj = idaymask(jj_p)
1279  !
1280  zalb_p(jj_p) = palb(jj)
1281  zsw_rad_p(jj_p) = psw_rad(jj)
1282  zzenith_p(jj_p) = pzenith(jj)
1283  inlvls_use_p(jj_p) = knlvls_use(jj)
1284  !
1285  END DO
1286  !
1287  imax_use = maxval(knlvls_use)
1288  !
1289  ! Pack 2D variables
1290  DO jl = 1,imax_use
1291  !
1292  DO jj_p = 1,ipointday
1293  !
1294  jj = idaymask(jj_p)
1295  !
1296  zsnowgran1_p(jj_p,jl) = psnowgran1(jj,jl)
1297  zsnowgran2_p(jj_p,jl) = psnowgran2(jj,jl)
1298  zsnowrho_p(jj_p,jl) = psnowrho(jj,jl)
1299  zsnowg0_p(jj_p,jl) = psnowg0(jj,jl)
1300  zsnowy0_p(jj_p,jl) = psnowy0(jj,jl)
1301  zsnoww0_p(jj_p,jl) = psnoww0(jj,jl)
1302  zsnowb0_p(jj_p,jl) = psnowb0(jj,jl)
1303  zsnowdz_p(jj_p,jl) = psnowdz(jj,jl)
1304  !
1305  END DO
1306  !
1307  END DO
1308  !
1309  ! Pack 3D variables
1310  DO jimp = 1,npnimp
1311  !
1312  DO jl = 1,imax_use
1313  !
1314  DO jj_p = 1,ipointday
1315  !
1316  jj = idaymask(jj_p)
1317  !
1318  zsnowimp_density_p(jj_p,jl,jimp) = psnowimp_density(jj,jl,jimp)
1319  zsnowimp_content_p(jj_p,jl,jimp) = psnowimp_content(jj,jl,jimp)
1320  !
1321  END DO
1322  !
1323  END DO
1324  !
1325  END DO
1326  !
1327 !RJ: fix fp-invalid(nan) trapping in ISBA_DIF8_SN3L_NIT_SNCRO8_C13_SNOWRAD_TAR, ISBA_DIF8_SN3L_NIT_SNCRO8_C13_SNOWRAD_TA2 tests
1328 #ifdef RJ_OFIX
1329 !RJ: temp fix to avoid accessing uninited values (NANS) in mode_tartes.F90 by explicit inited shape, no inpact for results, problem in array padding
1330  CALL snowcro_call_tartes(zsnowgran1_p(1:ipointday,1:imax_use),zsnowgran2_p(1:ipointday,1:imax_use), &
1331  zsnowrho_p(1:ipointday,1:imax_use),zsnowdz_p(1:ipointday,1:imax_use), &
1332  zsnowg0_p(1:ipointday,1:imax_use),zsnowy0_p(1:ipointday,1:imax_use), &
1333  zsnoww0_p(1:ipointday,1:imax_use),zsnowb0_p(1:ipointday,1:imax_use), &
1334  zsnowimp_density_p(1:ipointday,1:imax_use,1:npnimp), &
1335  zsnowimp_content_p(1:ipointday,1:imax_use,1:npnimp), &
1336  zalb_p(1:ipointday),zsw_rad_p(1:ipointday), &
1337  zzenith_p(1:ipointday),inlvls_use_p(1:ipointday),zsnowalb_p(1:ipointday), &
1338  zradsink_p(1:ipointday,1:imax_use),zradxs_p(1:ipointday),odebug,hsnowmetamo)
1339 #else
1340  CALL snowcro_call_tartes(zsnowgran1_p(1:ipointday,:),zsnowgran2_p(1:ipointday,:),zsnowrho_p(1:ipointday,:), &
1341  zsnowdz_p(1:ipointday,:),zsnowg0_p(1:ipointday,:),zsnowy0_p(1:ipointday,:), &
1342  zsnoww0_p(1:ipointday,:),zsnowb0_p(1:ipointday,:),zsnowimp_density_p(1:ipointday,:,:), &
1343  zsnowimp_content_p(1:ipointday,:,:),zalb_p(1:ipointday),zsw_rad_p(1:ipointday), &
1344  zzenith_p(1:ipointday),inlvls_use_p(1:ipointday),zsnowalb_p(1:ipointday), &
1345  zradsink_p(1:ipointday,:),zradxs_p(1:ipointday),odebug,hsnowmetamo)
1346 #endif
1347  !
1348  !Unpack 1d output variables
1349  !
1350  DO jj_p = 1,ipointday
1351  !
1352  jj = idaymask(jj_p)
1353  !
1354  pradxs(jj) = zradxs_p(jj_p)
1355  psnowalb(jj) = zsnowalb_p(jj_p)
1356  !
1357  END DO
1358  !
1359  !Unpack 2d output variables
1360  DO jl = 1,imax_use
1361  !
1362  DO jj_p = 1,ipointday
1363  !
1364  jj = idaymask(jj_p)
1365  !
1366  pradsink(jj,jl) = zradsink_p(jj_p,jl)
1367  !
1368  END DO
1369  !
1370  END DO
1371  !
1372 END IF
1373 !
1374 IF (lhook) CALL dr_hook('SNOWCRO_TARTES',1,zhook_handle)
1375 !
1376 END SUBROUTINE snowcro_tartes
1377 
1378 !--------------------------------------------------------------------------------
1379 !--------------------------------------------------------------------------------
1380 
1381 SUBROUTINE snowcro_call_tartes(PSNOWGRAN1,PSNOWGRAN2,PSNOWRHO,PSNOWDZ,PSNOWG0,PSNOWY0,PSNOWW0,PSNOWB0, &
1382  PSNOWIMP_DENSITY,PSNOWIMP_CONTENT,PALB,PSW_RAD,PZENITH,KNLVLS_USE, &
1383  PSNOWALB,PRADSINK,PRADXS,ODEBUG,HSNOWMETAMO)
1385 ! Interface between Tartes and Crocus
1386 ! M. Lafaysse 26/08/2013
1387 !
1389 USE modd_csts, ONLY : xrholi,xpi
1390 !
1391 USE mode_snow3l, ONLY : get_diam
1392 !
1393 IMPLICIT NONE
1394 
1395 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWGRAN1,PSNOWGRAN2 ! (npoints,nlayer)
1396 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWRHO !snow density (kg/m^3) (npoints,nlayer)
1397 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWG0 ! asymmetry parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit) (npoints,nlayer)
1398 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWY0 ! Value of y of snow grains at nr=1.3 (no unit
1399 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWW0 ! Value of W of snow grains at nr=1.3 (no unit)
1400 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWB0 ! absorption enhancement parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit)
1401 REAL, DIMENSION(:,:), INTENT(IN) :: PSNOWDZ !snow layers thickness (m) (npoints,nlayer)
1402 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_DENSITY !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
1403 REAL, DIMENSION(:,:,:), INTENT(IN) :: PSNOWIMP_CONTENT !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
1404 !
1405 REAL, DIMENSION(:), INTENT(IN) :: PALB ! soil/vegetation albedo (npoints)
1406 !
1407 REAL, DIMENSION(:), INTENT(IN) :: PSW_RAD ! global broadband incident light (W/m^2) (npoints)
1408 REAL, DIMENSION(:), INTENT(IN) :: PZENITH ! zenithal solar angle (npoints)
1409 !
1410 INTEGER, DIMENSION(:), INTENT(IN) :: KNLVLS_USE ! number of effective snow layers (npoints)
1411 !
1412 !Same outputs as SNOWCRORAD and SNOWCROALB
1413 REAL, DIMENSION(:,:), INTENT(OUT) :: PRADSINK !(npoints,nlayers)
1414 REAL, DIMENSION(:), INTENT(OUT) :: PRADXS !(npoints,nlayers)
1415 REAL, DIMENSION(:), INTENT(OUT) :: PSNOWALB !(npoints,nlayers)
1416 
1417 LOGICAL,INTENT(IN) :: ODEBUG ! Print for debugging
1418  CHARACTER(3), INTENT(IN) :: HSNOWMETAMO ! metamorphism scheme
1419 
1420 !Local variables
1421 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2),NPNBANDS) :: ZSNOWENERGY !(npoints,nlayer,nbands)
1422 !
1423 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWSSA !snow specific surface area (m^2/kg) (npoints,nlayer)
1424 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: ZSNOWENERGY_BB ! (W/m^2) (npoints,nlayers)
1425 !
1426 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: ZSW_RAD_DIF ! spectral diffuse incident light (W/m^2) (npoints,nbands)
1427 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: ZSW_RAD_DIR ! spectral direct incident light (W/m^2) (npoints,nbands)
1428 !
1429 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: ZSNOWALB !(npoints,nbands)
1430 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: ZALB ! soil/vegetation albedo (npoints,nbands)
1431 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: ZSOILENERGY !(npoints,nbands)
1432 !
1433 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZNIR_ABS ! Near infrared radiation (2500-4000 nm) absorbed by snowpack (W/m^2) (npoints)
1434 !
1435 !broad band
1436 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZTOTSNOWENERGY ! (W/m^2) (npoints)
1437 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZSOILENERGY_BB ! (W/m^2) (npoints)
1438 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZREFLECTED_BB ! (W/m^2) (npoints)
1439 !
1440 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZSNOWENERGY_CUM,ZSNOWENERGY_UPPER ! Cumulated absorbed energy for 1 wavelength W/m^2 (npoints)
1441 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ZMAX ! maximum available energy for 1 wavelength W/m^2 (npoints,nbands)
1442 !
1443 REAL :: ZDIAM !optical diameter
1444 !
1445 INTEGER :: JB,JL,JJ !Loop counter
1446 !
1447 REAL(KIND=JPRB) :: ZHOOK_HANDLE
1448 !
1449 IF (lhook) CALL dr_hook('SNOWCRO_CALL_TARTES',0,zhook_handle)
1450 !
1451 ! Compute SSA from SNOWGRAN1 and SNOWGRAN2
1452 DO jl = 1,SIZE(psnowrho,2)
1453  !
1454  DO jj = 1,SIZE(psnowrho,1)
1455  !
1456  IF ( jl<=knlvls_use(jj) ) THEN
1457  !
1458  CALL get_diam(psnowgran1(jj,jl),psnowgran2(jj,jl),zdiam,hsnowmetamo)
1459  zsnowssa(jj,jl) = 6. / (xrholi*zdiam)
1460  !
1461  ENDIF
1462  !
1463  ENDDO
1464  !
1465 ENDDO
1466 !
1467 DO jb = 1,npnbands
1468  ! Soil-vegetation albedo homogeneous in wavelength
1469  zalb(:,jb) = palb(:)
1470 END DO
1471 !
1472 !Spectral repartition of radiation
1473  CALL spectral_repartition(psw_rad,cos(pzenith),zsw_rad_dif,zsw_rad_dir,znir_abs)
1474 !
1475 IF ( odebug ) THEN
1476  WRITE(*,*) "ZSW_RAD_DIF=",zsw_rad_dif
1477  WRITE(*,*) "ZSW_RAD_DIR=",zsw_rad_dir
1478  WRITE(*,*) "PZENITH=",pzenith
1479 END IF
1480 !
1481 !Call tartes model
1482 ! For test and debugging this routine can be called independently by a python interface
1483 !
1484  CALL tartes(zsnowssa,psnowrho,psnowdz,psnowg0,psnowy0,psnoww0,psnowb0,psnowimp_density,psnowimp_content,zalb,&
1485  zsw_rad_dif,zsw_rad_dir,cos(pzenith),knlvls_use,zsnowalb,zsnowenergy,zsoilenergy)
1486 !
1487  ! Modif ML : in some cases, Tartes is unstable in infra-red wavelengths : control of energy values and apply threshold if necessary
1488  ! --------------------------------------------------------------------------------------------------------------------
1489 
1490 
1491  ! This does not seem to be necessary at CDP when the effective number of layers is properly limited.
1492  ! However, we let the comment code because it might happen again.
1493 
1494 !
1495 ! DO JB=1,NPNBANDS
1496 ! ! maximum available energy at this wavelength
1497 ! ZMAX=ZSW_RAD_DIF(:,JB)*PP_MUDIFF+ZSW_RAD_DIR(:,JB)*COS(PZENITH)
1498 ! ZSNOWENERGY_CUM(:)=0.
1499 ! DO JL=1,SIZE(PSNOWRHO,2)
1500 ! DO JJ=1,SIZE(PSNOWRHO,1)
1501 ! IF (JL<=KNLVLS_USE(JJ)) THEN
1502 ! ZSNOWENERGY_UPPER(JJ)=ZSNOWENERGY_CUM(JJ) !0 for surface layer
1503 ! ! absorbed energy cumulated from the surface
1504 ! ZSNOWENERGY_CUM(JJ)=ZSNOWENERGY_CUM(JJ)+ZSNOWENERGY(JJ,JL,JB)
1505 !
1506 ! ! Case when the energy is negative but close to 0. It can occurs in short wavelengths. Force to 0.
1507 ! IF ((ZSNOWENERGY(JJ,JL,JB)<0).AND. (ZSNOWENERGY(JJ,JL,JB)>-0.1)) THEN
1508 ! ZSNOWENERGY(JJ,JL,JB)=0.
1509 ! END IF
1510 !
1511 ! !if the cumulated absorbed energy excess the available energy or if severe negative energy, numerical problem in Tartes : total absorption
1512 ! IF ((ZSNOWENERGY_CUM(JJ)>ZMAX(JJ)).OR.(ZSNOWENERGY(JJ,JL,JB)<=-0.1)) THEN
1513 ! ! IF (PPWAVELENGTHS(JB)<=1000) THEN
1514 ! IF ((PPWAVELENGTHS(JB)<=1000) .AND.(ABS(ZSNOWENERGY_CUM(JJ)-ZMAX(JJ))>0.01)) THEN
1515 ! ! Tolerance 0.01 W/m2 of excess energy in the visible
1516 ! ! Above, the problem should never happen in visible
1517 !
1518 ! PRINT*,"JB=",JB,"JL=",JL
1519 ! IF (ZSNOWENERGY_CUM(JJ)>ZMAX(JJ)) PRINT*,"excess energy"
1520 ! IF (ZSNOWENERGY(JJ,JL,JB)<0) PRINT*, "negative energy"
1521 !
1522 ! PRINT*,ZSW_RAD_DIF(JJ,JB),ZSW_RAD_DIR(JJ,JB),ZMAX(JJ),ZSNOWENERGY_CUM(JJ)
1523 !
1524 ! PRINT*,"profile :",ZSNOWENERGY(JJ,:,JB)
1525 !
1526 ! STOP "FATAL ERROR TARTES !!"
1527 ! END IF
1528 ! ! The layer absorbes all the remaining energy at this wavelength
1529 ! ZSNOWENERGY(JJ,JL,JB)=ZMAX(JJ)-ZSNOWENERGY_UPPER(JJ)
1530 ! ! update cumulated energy
1531 ! ZSNOWENERGY_CUM(JJ)=ZMAX(JJ)
1532 ! END IF
1533 ! END IF
1534 ! END DO
1535 ! END DO
1536 !
1537 ! ! Threshold on soil absorbed energy
1538 ! DO JJ=1,SIZE(PSNOWRHO,1)
1539 ! ZSNOWENERGY_UPPER(JJ)=ZSNOWENERGY_CUM(JJ)
1540 ! ZSNOWENERGY_CUM(JJ)=ZSNOWENERGY_CUM(JJ)+ZSOILENERGY(JJ,JB)
1541 ! IF (ZSNOWENERGY_CUM(JJ)>ZMAX(JJ)) THEN
1542 ! IF (PPWAVELENGTHS(JB)<=1200) THEN
1543 ! STOP "FATAL ERROR TARTES (soil excess energy in visible)!!"
1544 ! END IF
1545 ! ! The layer absorbes all the remaining energy at this wavelength
1546 ! ZSOILENERGY(JJ,JB)=ZMAX(JJ)-ZSNOWENERGY_UPPER(JJ)
1547 ! END IF
1548 ! END DO
1549 !
1550 ! END DO
1551 
1552  ! End modif ML
1553  ! --------------------------------------------------------------------------------------------------------------------
1554 !
1555 ! Broadband absorbed energy by snowpack and soil
1556 zsnowenergy_bb = 0.
1557 zsoilenergy_bb = 0.
1558 !
1559 DO jb = 1,npnbands
1560  zsnowenergy_bb(:,:) = zsnowenergy_bb(:,:) + zsnowenergy(:,:,jb)
1561  zsoilenergy_bb(:) = zsoilenergy_bb(:) + zsoilenergy(:,jb)
1562 END DO
1563 !
1564 !Add near infra-red wavelengths to first layer
1565 zsnowenergy_bb(:,1) = zsnowenergy_bb(:,1) + znir_abs
1566 !
1567 ! Total energy absorbed by snowpack
1568 ztotsnowenergy(:)=0
1569 DO jl = 1,SIZE(psnowrho,2)
1570  DO jj = 1,SIZE(psnowrho,1)
1571  IF ( jl<=knlvls_use(jj) ) THEN
1572  ztotsnowenergy(jj) = ztotsnowenergy(jj) + zsnowenergy_bb(jj,jl)
1573  END IF
1574  END DO
1575 END DO
1576 !
1577 ! Reflected energy
1578 zreflected_bb = psw_rad - ztotsnowenergy - zsoilenergy_bb
1579 !
1580 ! Broad band Albedo
1581 ! PSW_RAD is never 0 because this routine is not called during the night
1582 psnowalb = zreflected_bb / psw_rad
1583 !
1584 ! Source term
1585 pradsink(:,1) = -psw_rad(:) + zreflected_bb + zsnowenergy_bb(:,1)
1586 !
1587 DO jl = 2,SIZE(psnowrho,2)
1588  pradsink(:,jl) = pradsink(:,jl-1) + zsnowenergy_bb(:,jl)
1589 END DO
1590 !
1591 !Excess energy
1592 pradxs = psw_rad - ztotsnowenergy - zreflected_bb
1593 !
1594 IF (lhook) CALL dr_hook('SNOWCRO_CALL_TARTES',1,zhook_handle)
1595 !
1596 END SUBROUTINE snowcro_call_tartes
1597 
1598 END MODULE mode_tartes
real, dimension(npnbands) xrefice_r
real, dimension(npnbands) xconst_c
real, parameter xp_mudiff
real, dimension(npnbands_ref), parameter xpwavelengths_ref
real, parameter xuepsi
subroutine single_scattering_optical_parameters(PSNOWSSA, PSNOWRHO, PSNOWG0, PSNOWY0, PSNOWW0, PSNOWB0, PSNOWIMP_DENSITY, PSNOWIMP_CONTENT, KNLVLS_USE, KMAX_USE, PSNOWSSALB, PSNOWG)
subroutine spectral_repartition(PSW_RAD, PCOSZEN, PSW_RAD_DIF, PSW_RAD_DIR, PNIR_ABS)
subroutine two_stream_vector(PSNOWALBEDO, PSOILALBEDO, PDTAUSTAR, PTAUSTAR, PGM, PGP, PCOSZEN, KNLVLS_EFF, KMAX_EFF, PVECTOR)
subroutine gp_gm_vectors(PSNOWSSALB, PKESTAR, PG_STAR, PSSALB_STAR, PGAMMA1, PGAMMA2, PCOSZEN, PSW_RAD, KNLVLS_EFF, KMAX_EFF, PGP, PGM)
real, dimension(npnbands) xginf
real, dimension(npnbands) xrefice_norm
subroutine two_stream_matrix(PSNOWALBEDO, PSOILALBEDO, PKESTAR, PDTAUSTAR, KNLVLS_EFF, KMAX_EFF, PDM, PD, PDP)
subroutine snowpack_albedo(PXC_DIR, PXC_DIF, PXD_DIR, PXD_DIF, PGP_DIR, PGP_DIF, PCOSZEN_DIR, PCOSZEN_DIF, PSW_RAD_DIR, PSW_RAD_DIF, PSNOWALB)
real, parameter xpcoefnir_dif
real, save xpi
Definition: modd_csts.F90:43
subroutine refsoot_imag()
real, dimension(npnbands_ref), save xprefice_r
integer, parameter npnbands
subroutine solves_two_stream2(PDM, PD, PDP, PVECT_DIR, PVECT_DIF, PSNOWALBEDO, PSW_RAD_DIR, PSW_RAD_DIF, KNLVLS_EFF, KMAX_EFF, PXA_DIR, PXA_DIF, PXB_DIR, PXB_DIF, PXC_DIR, PXC_DIF, PXD_DIR, PXD_DIF)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
subroutine shape_parameter_variations(PSNOWG0, PSNOWY0, PSNOWW0, PSNOWB0, PSNOWG00, PSNOWY, PSNOWW, PSNOWB)
integer, dimension(nvegtype_old), parameter npnimp
subroutine impurities_co_single_scattering_albedo(PSNOWSSA, PSNOWIMP_DENSITY, PSNOWIMP_CONTENT, KNLVLS_USE, KMAX_USE, PCOSSALB)
real, dimension(npnbands) xrefice_i
real, dimension(npnbands), parameter xpwavelengths_m
real, dimension(npnbands), parameter xpratio_dir
subroutine energy_profile(PXA, PXB, PXC, PXD, PKESTAR, PDTAUSTAR, PTAUSTAR, PGM, PGP, PCOSZEN, KNLVLS_EFF, KMAX_EFF, PEPROFILE)
real, dimension(npnbands, npnimp) xrefimp_i
integer, parameter jprb
Definition: parkind1.F90:32
real, dimension(npnbands), parameter xpwavelengths
subroutine snowcro_call_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 infinite_medium_optical_parameters(PSNOWSSALB, PSNOWG, KNLVLS_USE, KMAX_USE, PSNOWALBEDO, PKESTAR, PG_STAR, PSSALB_STAR, PGAMMA1, PGAMMA2)
real, parameter xpcoefnir_dir
subroutine tartes(PSNOWSSA, PSNOWRHO, PSNOWDZ, PSNOWG0, PSNOWY0, PSNOWW0, PSNOWB0, PSNOWIMP_DENSITY, PSNOWIMP_CONTENT, PALB, PSW_RAD_DIF, PSW_RAD_DIR, PCOSZEN, KNLVLS_USE, PSNOWALB, PSNOWENERGY, PSOILENERGY)
Definition: mode_tartes.F90:65
subroutine init_tartes()
logical lhook
Definition: yomhook.F90:15
real, save xrholi
Definition: modd_csts.F90:81
integer, parameter npnbands_ref
subroutine soil_absorption(PXA, PXB, PKESTAR, PDTAUSTAR, PTAUSTAR, PGM, PCOSZEN, PALB, KNLVLS_EFF, PSOILENERGY)
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 refice()
real, parameter xpmax_opticaldepth
subroutine taustar_vector(PSNOWSSA, PSNOWRHO, PSNOWDZ, PSNOWSSALB, PSNOWG, PKESTAR, KNLVLS_USE, KMAX_USE, PDTAUSTAR, PTAUSTAR)
real, dimension(npnbands_ref), save xprefice_i
real, parameter xptaumax
subroutine estimate_effective_layer_number(PKESTAR, PDTAUSTAR, KNLVLS_USE, KMAX_USE, KNLVLS_EFF, KMAX_EFF)
real, dimension(npnbands), parameter xpratio_dif