SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
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 !
66 USE modd_const_tartes, ONLY: npnbands,xpwavelengths,xrefice_r,xrefice_i,xrefimp_i,xp_mudiff
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 !
248 USE modd_const_tartes, ONLY: npnbands,xpwavelengths,xpwavelengths_m,xrefice_r,xrefice_i, &
249  npnbands_ref,xpwavelengths_ref,xprefice_r,xprefice_i, &
250  xrefice_norm,xginf,xconst_c
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()
314 
315 ! Compute refractive index of soot according to wavelengths from Chang (1990)
316 
317 USE modd_const_tartes, ONLY : npnbands,xpwavelengths,xrefimp_i
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)
347 
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 !
388 USE modd_const_tartes, ONLY: npnbands,npnimp,xpwavelengths_m,xrefimp_i
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
444 USE modd_const_tartes, ONLY: npnbands,xginf,xconst_c
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 !
584 USE modd_const_tartes, ONLY: npnbands,xpmax_opticaldepth
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 !
644 USE modd_const_tartes, ONLY : npnbands,xpwavelengths,xptaumax
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)
1015 
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 :: zdexp, zfdu, zfdd, zstar
1033 !
1034 INTEGER::jb,jl,jj !loop counter
1035 !
1036 REAL(KIND=JPRB) :: zhook_handle
1037 !
1038 IF (lhook) CALL dr_hook('ENERGY_PROFILE',0,zhook_handle)
1039 
1040 DO jb = 1,npnbands
1041  !
1042  DO jj =1,SIZE(peprofile,1)
1043  !
1044  zstar = pkestar(jj,1,jb) * pdtaustar(jj,1,jb)
1045  !
1046  !surface layer doc equation 64
1047  peprofile(jj,1,jb) = ( pcoszen(jj) - ( pxc(jj,1,jb)+pxd(jj,1,jb)+pgp(jj,1,jb) ) ) + &
1048  ( pxc(jj,1,jb) * exp(-zstar) + pxd(jj,1,jb) * exp(zstar) + &
1049  pgp(jj,1,jb) * exp( -pdtaustar(jj,1,jb)/pcoszen(jj)) ) - &
1050  ( pxa(jj,1,jb) * exp(-zstar) + pxb(jj,1,jb) * exp(zstar) + &
1051  pgm(jj,1,jb) * exp( -pdtaustar(jj,1,jb)/pcoszen(jj)) + &
1052  pcoszen(jj) * exp( -ptaustar(jj,1,jb)/pcoszen(jj)) )
1053  !
1054  !internal layers
1055  !
1056  DO jl = 2,kmax_eff(jb)
1057  !
1058  zstar = pkestar(jj,jl,jb) * pdtaustar(jj,jl,jb)
1059  !
1060  IF ( jl<=knlvls_eff(jj,jb) ) THEN
1061  !
1062  !last factor in equations 62 and 63
1063  zdexp = exp( -ptaustar(jj,jl ,jb)/pcoszen(jj) ) - exp( -ptaustar(jj,jl-1,jb)/pcoszen(jj) )
1064  !
1065  !doc equation 62
1066  zfdu = pxc(jj,jl,jb) * ( exp(-zstar) -1. ) + &
1067  pxd(jj,jl,jb) * ( exp( zstar) -1. ) + pgp(jj,jl,jb) * zdexp
1068  !
1069  !doc equation 63
1070  zfdd = pxa(jj,jl,jb) * ( exp(-zstar) -1. ) + &
1071  pxb(jj,jl,jb) * ( exp( zstar) -1. ) + ( pgm(jj,jl,jb) + pcoszen(jj) ) * zdexp
1072  !
1073  peprofile(jj,jl,jb) = zfdu - zfdd !doc equation 61
1074  !
1075  ELSE
1076  !
1077  peprofile(jj,jl,jb) = 0.
1078  !
1079  ENDIF
1080  !
1081  ENDDO
1082  !
1083  ENDDO
1084  !
1085 ENDDO
1086 !
1087 IF (lhook) CALL dr_hook('ENERGY_PROFILE',1,zhook_handle)
1088 !
1089 END SUBROUTINE energy_profile
1090 !--------------------------------------------------------------------------------
1091 !--------------------------------------------------------------------------------
1092 SUBROUTINE soil_absorption(PXA,PXB,PKESTAR,PDTAUSTAR,PTAUSTAR,PGM,PCOSZEN,PALB,KNLVLS_EFF,PSOILENERGY)
1093 !compute the energy absorbed by the soil at each wavelength
1094 !
1095 USE modd_const_tartes, ONLY : npnbands
1096 !
1097 IMPLICIT NONE
1098 !
1099 REAL, DIMENSION(:,:,:), INTENT(IN) :: pxa,pxb ! solutions of linear system (npoints,nlayer,nbands)
1100 REAL, DIMENSION(:,:,:), INTENT(IN) :: pkestar !Asymptotic Flux Extinction Coefficent (npoints,nlayer,nbands)
1101 REAL, DIMENSION(:,:,:), INTENT(IN) :: pdtaustar !Optical depth of each layer (npoints,nlayer,nbands)
1102 REAL, DIMENSION(:,:,:), INTENT(IN) :: ptaustar !Cumulated optical depth (npoints,nlayer,nbands)
1103 REAL, DIMENSION(:,:,:), INTENT(IN) :: pgm !GM vector (npoints,nlayer,nbands)
1104 REAL, DIMENSION(:), INTENT(IN) :: pcoszen! cosine of zenithal solar angle (npoints)
1105 REAL, DIMENSION(:,:), INTENT(IN) :: palb! soil albedo (npoints,nbands)
1106 INTEGER, DIMENSION(:,:), INTENT(IN) :: knlvls_eff !number of effective layers (npoints,nbands)
1107 REAL, DIMENSION(:,:), INTENT(OUT) :: psoilenergy
1108 INTEGER :: jb,ji !loop counter
1109 !
1110 REAL(KIND=JPRB) :: zhook_handle
1111 !
1112 IF (lhook) CALL dr_hook('SOIL_ABSORPTION',0,zhook_handle)
1113 !
1114 DO jb=1,npnbands
1115  !
1116  DO ji=1,SIZE(pxa,1)
1117  !
1118  !doc equation 65
1119  psoilenergy(ji,jb) = ( 1.-palb(ji,jb) ) * &
1120  ( pxa(ji,knlvls_eff(ji,jb),jb) * &
1121  exp( -pkestar(ji,knlvls_eff(ji,jb),jb) * pdtaustar(ji,knlvls_eff(ji,jb),jb) ) + &
1122  pxb(ji,knlvls_eff(ji,jb),jb) * &
1123  exp( pkestar(ji,knlvls_eff(ji,jb),jb) * pdtaustar(ji,knlvls_eff(ji,jb),jb) ) + &
1124  ( pgm(ji,knlvls_eff(ji,jb),jb)+pcoszen(ji) ) * &
1125  exp( -ptaustar(ji,knlvls_eff(ji,jb),jb)/pcoszen(ji) ) )
1126  !
1127  END DO
1128  !
1129 END DO
1130 
1131 IF (lhook) CALL dr_hook('SOIL_ABSORPTION',1,zhook_handle)
1132 
1133 END SUBROUTINE soil_absorption
1134 !--------------------------------------------------------------------------------
1135 !--------------------------------------------------------------------------------
1136 SUBROUTINE spectral_repartition(PSW_RAD,PCOSZEN,PSW_RAD_DIF,PSW_RAD_DIR,PNIR_ABS)
1137 
1138 USE modd_const_tartes, ONLY : npnbands,xpratio_dir,xpratio_dif,xpcoefnir_dir,xpcoefnir_dif,xp_mudiff
1139 
1140 IMPLICIT NONE
1141 
1142 REAL, DIMENSION(:), INTENT(IN) :: psw_rad ! broadband global incident light (W/m^2) (npoints)
1143 REAL, DIMENSION(:), INTENT(IN) :: pcoszen ! cosine of zenithal solar angle (npoints)
1144 REAL, DIMENSION(:,:), INTENT(OUT) :: psw_rad_dif ! spectral diffuse incident light (W/m^2) (npoints,nbands)
1145 REAL, DIMENSION(:,:), INTENT(OUT) :: psw_rad_dir ! spectral direct incident light (W/m^2) (npoints,nbands)
1146 REAL, DIMENSION(:), INTENT(OUT) :: pnir_abs ! Near infrared radiation (2500-4000 nm) absorbed by snowpack (W/m^2) (npoints)
1147 !
1148 REAL, DIMENSION(SIZE(PSW_RAD)) :: zsw_rad_broaddir,zsw_rad_broaddif ! direct and diffuse broadband incident light (W/m^2) (npoints)
1149 INTEGER :: jb !Loop counter
1150 !
1151 REAL(KIND=JPRB) :: zhook_handle
1152 !
1153 IF (lhook) CALL dr_hook('SPECTRAL_REPARTITION',0,zhook_handle)
1154 !
1155 ! Separate broadband global radiation in direct and diffuse (parametrization Marie Dumont)
1156 ! NB : thresold 1. to the factor when zenithal angle close to pi/2
1157 zsw_rad_broaddif = min( exp( - 1.54991930344*pcoszen**3 + 3.73535795329*pcoszen**2 &
1158  - 3.52421131883*pcoszen + 0.0299111951172 ), 1. ) * psw_rad
1159 zsw_rad_broaddir = psw_rad - zsw_rad_broaddif
1160 !
1161 ! Spectral decomposition
1162 DO jb = 1,npnbands
1163  psw_rad_dif(:,jb) = xpratio_dif(jb) * zsw_rad_broaddif / xp_mudiff
1164  psw_rad_dir(:,jb) = xpratio_dir(jb) * zsw_rad_broaddir / pcoszen(:)
1165 END DO
1166 
1167 pnir_abs = zsw_rad_broaddif*xpcoefnir_dif + zsw_rad_broaddir*xpcoefnir_dir
1168 
1169 IF (lhook) CALL dr_hook('SPECTRAL_REPARTITION',1,zhook_handle)
1170 
1171 END SUBROUTINE spectral_repartition
1172 !--------------------------------------------------------------------------------
1173 !--------------------------------------------------------------------------------
1174 SUBROUTINE snowcro_tartes(PSNOWGRAN1,PSNOWGRAN2,PSNOWRHO,PSNOWDZ,PSNOWG0,PSNOWY0,PSNOWW0,PSNOWB0, &
1175  psnowimp_density,psnowimp_content,palb,psw_rad,pzenith,knlvls_use, &
1176  psnowalb,pradsink,pradxs,odebug,hsnowmetamo)
1177 !
1178 ! Interface between Tartes and Crocus
1179 ! M. Lafaysse 26/08/2013
1180 !
1181 USE modd_const_tartes, ONLY : npnimp
1182 USE modd_snow_metamo, ONLY : xuepsi
1183 !
1184 IMPLICIT NONE
1185 !
1186 REAL, DIMENSION(:,:), INTENT(IN) :: psnowgran1,psnowgran2 ! (npoints,nlayer)
1187 REAL, DIMENSION(:,:), INTENT(IN) :: psnowrho !snow density (kg/m^3) (npoints,nlayer)
1188 REAL, DIMENSION(:,:), INTENT(IN) :: psnowg0 ! asymmetry parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit) (npoints,nlayer)
1189 REAL, DIMENSION(:,:), INTENT(IN) :: psnowy0 ! Value of y of snow grains at nr=1.3 (no unit
1190 REAL, DIMENSION(:,:), INTENT(IN) :: psnoww0 ! Value of W of snow grains at nr=1.3 (no unit)
1191 REAL, DIMENSION(:,:), INTENT(IN) :: psnowb0 ! absorption enhancement parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit)
1192 REAL, DIMENSION(:,:), INTENT(IN) :: psnowdz !snow layers thickness (m) (npoints,nlayer)
1193 REAL, DIMENSION(:,:,:), INTENT(IN) :: psnowimp_density !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
1194 REAL, DIMENSION(:,:,:), INTENT(IN) :: psnowimp_content !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
1195 !
1196 REAL, DIMENSION(:), INTENT(IN) :: palb ! soil/vegetation albedo (npoints)
1197 !
1198 REAL, DIMENSION(:), INTENT(IN) :: psw_rad ! global broadband incident light (W/m^2) (npoints)
1199 REAL, DIMENSION(:), INTENT(IN) :: pzenith ! zenithal solar angle (npoints)
1200 !
1201 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use ! number of effective snow layers (npoints)
1202 !
1203 !Same outputs as SNOWCRORAD and SNOWCROALB
1204 REAL, DIMENSION(:,:), INTENT(OUT) :: pradsink !(npoints,nlayers)
1205 REAL, DIMENSION(:), INTENT(OUT) :: pradxs !(npoints,nlayers)
1206 REAL, DIMENSION(:), INTENT(OUT) :: psnowalb !(npoints,nlayers)
1207 !
1208 LOGICAL, INTENT(IN) :: odebug ! Print for debugging
1209  CHARACTER(3), INTENT(IN) :: hsnowmetamo ! metamorphism scheme
1210 !
1211 !packed variables
1212 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2),NPNIMP) :: zsnowimp_density_p !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
1213 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2),NPNIMP) :: zsnowimp_content_p !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
1214 !
1215 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowgran1_p,zsnowgran2_p ! (npoints,nlayer)
1216 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowrho_p !snow density (kg/m^3) (npoints,nlayer)
1217 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)
1218 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowy0_p ! Value of y of snow grains at nr=1.3 (no unit
1219 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnoww0_p ! Value of W of snow grains at nr=1.3 (no unit)
1220 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)
1221 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowdz_p !snow layers thickness (m) (npoints,nlayer)
1222 !
1223 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zradsink_p
1224 !
1225 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zalb_p ! soil/vegetation albedo (npoints)
1226 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zsw_rad_p ! global broadband incident light (W/m^2) (npoints)
1227 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zzenith_p ! zenithal solar angle (npoints)
1228 !
1229 !Same outputs as SNOWCRORAD and SNOWCROALB
1230 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zradxs_p
1231 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zsnowalb_p
1232 !
1233 INTEGER, DIMENSION(SIZE(PSNOWRHO,1)) :: inlvls_use_p ! number of effective snow layers (npoints)
1234 !
1235 INTEGER, DIMENSION(SIZE(PSNOWRHO,1)) :: idaymask ! mask for points where it's day
1236 !
1237 INTEGER :: imax_use ! maximum number of layers over the domain
1238 INTEGER :: jl,jimp,jj,jj_p !Loop counter
1239 INTEGER :: ipointday
1240 INTEGER :: inpoints
1241 !
1242 REAL(KIND=JPRB) :: zhook_handle
1243 !
1244 IF (lhook) CALL dr_hook('SNOWCRO_TARTES',0,zhook_handle)
1245 !
1246 !Default values (night)
1247 pradsink = 0.
1248 pradxs = 0.
1249 psnowalb = 1.
1250 !
1251 inpoints = SIZE(psnowrho,1)
1252 !
1253 !Mask
1254 ipointday = 0
1255 DO jj = 1,inpoints
1256  IF ( cos(pzenith(jj))>xuepsi .AND. psw_rad(jj)>xuepsi ) THEN
1257  !mask for day
1258  ipointday = ipointday + 1
1259  idaymask(ipointday) = jj
1260  END IF
1261 END DO
1262 !
1263 IF ( ipointday>=1 ) THEN
1264  !
1265  ! Pack 1D variables
1266  DO jj_p = 1,ipointday
1267  !
1268  jj = idaymask(jj_p)
1269  !
1270  zalb_p(jj_p) = palb(jj)
1271  zsw_rad_p(jj_p) = psw_rad(jj)
1272  zzenith_p(jj_p) = pzenith(jj)
1273  inlvls_use_p(jj_p) = knlvls_use(jj)
1274  !
1275  END DO
1276  !
1277  imax_use = maxval(knlvls_use)
1278  !
1279  ! Pack 2D variables
1280  DO jl = 1,imax_use
1281  !
1282  DO jj_p = 1,ipointday
1283  !
1284  jj = idaymask(jj_p)
1285  !
1286  zsnowgran1_p(jj_p,jl) = psnowgran1(jj,jl)
1287  zsnowgran2_p(jj_p,jl) = psnowgran2(jj,jl)
1288  zsnowrho_p(jj_p,jl) = psnowrho(jj,jl)
1289  zsnowg0_p(jj_p,jl) = psnowg0(jj,jl)
1290  zsnowy0_p(jj_p,jl) = psnowy0(jj,jl)
1291  zsnoww0_p(jj_p,jl) = psnoww0(jj,jl)
1292  zsnowb0_p(jj_p,jl) = psnowb0(jj,jl)
1293  zsnowdz_p(jj_p,jl) = psnowdz(jj,jl)
1294  !
1295  END DO
1296  !
1297  END DO
1298  !
1299  ! Pack 3D variables
1300  DO jimp = 1,npnimp
1301  !
1302  DO jl = 1,imax_use
1303  !
1304  DO jj_p = 1,ipointday
1305  !
1306  jj = idaymask(jj_p)
1307  !
1308  zsnowimp_density_p(jj_p,jl,jimp) = psnowimp_density(jj,jl,jimp)
1309  zsnowimp_content_p(jj_p,jl,jimp) = psnowimp_content(jj,jl,jimp)
1310  !
1311  END DO
1312  !
1313  END DO
1314  !
1315  END DO
1316  !
1317 !RJ: fix fp-invalid(nan) trapping in ISBA_DIF8_SN3L_NIT_SNCRO8_C13_SNOWRAD_TAR, ISBA_DIF8_SN3L_NIT_SNCRO8_C13_SNOWRAD_TA2 tests
1318 #ifdef RJ_OFIX
1319 !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
1320  CALL snowcro_call_tartes(zsnowgran1_p(1:ipointday,1:imax_use),zsnowgran2_p(1:ipointday,1:imax_use), &
1321  zsnowrho_p(1:ipointday,1:imax_use),zsnowdz_p(1:ipointday,1:imax_use), &
1322  zsnowg0_p(1:ipointday,1:imax_use),zsnowy0_p(1:ipointday,1:imax_use), &
1323  zsnoww0_p(1:ipointday,1:imax_use),zsnowb0_p(1:ipointday,1:imax_use), &
1324  zsnowimp_density_p(1:ipointday,1:imax_use,1:npnimp), &
1325  zsnowimp_content_p(1:ipointday,1:imax_use,1:npnimp), &
1326  zalb_p(1:ipointday),zsw_rad_p(1:ipointday), &
1327  zzenith_p(1:ipointday),inlvls_use_p(1:ipointday),zsnowalb_p(1:ipointday), &
1328  zradsink_p(1:ipointday,1:imax_use),zradxs_p(1:ipointday),odebug,hsnowmetamo)
1329 #else
1330  CALL snowcro_call_tartes(zsnowgran1_p(1:ipointday,:),zsnowgran2_p(1:ipointday,:),zsnowrho_p(1:ipointday,:), &
1331  zsnowdz_p(1:ipointday,:),zsnowg0_p(1:ipointday,:),zsnowy0_p(1:ipointday,:), &
1332  zsnoww0_p(1:ipointday,:),zsnowb0_p(1:ipointday,:),zsnowimp_density_p(1:ipointday,:,:), &
1333  zsnowimp_content_p(1:ipointday,:,:),zalb_p(1:ipointday),zsw_rad_p(1:ipointday), &
1334  zzenith_p(1:ipointday),inlvls_use_p(1:ipointday),zsnowalb_p(1:ipointday), &
1335  zradsink_p(1:ipointday,:),zradxs_p(1:ipointday),odebug,hsnowmetamo)
1336 #endif
1337  !
1338  !Unpack 1d output variables
1339  !
1340  DO jj_p = 1,ipointday
1341  !
1342  jj = idaymask(jj_p)
1343  !
1344  pradxs(jj) = zradxs_p(jj_p)
1345  psnowalb(jj) = zsnowalb_p(jj_p)
1346  !
1347  END DO
1348  !
1349  !Unpack 2d output variables
1350  DO jl = 1,imax_use
1351  !
1352  DO jj_p = 1,ipointday
1353  !
1354  jj = idaymask(jj_p)
1355  !
1356  pradsink(jj,jl) = zradsink_p(jj_p,jl)
1357  !
1358  END DO
1359  !
1360  END DO
1361  !
1362 END IF
1363 !
1364 IF (lhook) CALL dr_hook('SNOWCRO_TARTES',1,zhook_handle)
1365 !
1366 END SUBROUTINE snowcro_tartes
1367 
1368 !--------------------------------------------------------------------------------
1369 !--------------------------------------------------------------------------------
1370 
1371 SUBROUTINE snowcro_call_tartes(PSNOWGRAN1,PSNOWGRAN2,PSNOWRHO,PSNOWDZ,PSNOWG0,PSNOWY0,PSNOWW0,PSNOWB0, &
1372  psnowimp_density,psnowimp_content,palb,psw_rad,pzenith,knlvls_use, &
1373  psnowalb,pradsink,pradxs,odebug,hsnowmetamo)
1374 !
1375 ! Interface between Tartes and Crocus
1376 ! M. Lafaysse 26/08/2013
1377 !
1378 USE modd_const_tartes, ONLY : npnbands,xpwavelengths,xp_mudiff
1379 USE modd_csts, ONLY : xrholi,xpi
1380 !
1381 USE mode_snow3l, ONLY : get_diam
1382 !
1383 IMPLICIT NONE
1384 
1385 REAL, DIMENSION(:,:), INTENT(IN) :: psnowgran1,psnowgran2 ! (npoints,nlayer)
1386 REAL, DIMENSION(:,:), INTENT(IN) :: psnowrho !snow density (kg/m^3) (npoints,nlayer)
1387 REAL, DIMENSION(:,:), INTENT(IN) :: psnowg0 ! asymmetry parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit) (npoints,nlayer)
1388 REAL, DIMENSION(:,:), INTENT(IN) :: psnowy0 ! Value of y of snow grains at nr=1.3 (no unit
1389 REAL, DIMENSION(:,:), INTENT(IN) :: psnoww0 ! Value of W of snow grains at nr=1.3 (no unit)
1390 REAL, DIMENSION(:,:), INTENT(IN) :: psnowb0 ! absorption enhancement parameter of snow grains at nr=1.3 and at non absorbing wavelengths (no unit)
1391 REAL, DIMENSION(:,:), INTENT(IN) :: psnowdz !snow layers thickness (m) (npoints,nlayer)
1392 REAL, DIMENSION(:,:,:), INTENT(IN) :: psnowimp_density !impurities density (kg/m^3) (npoints,nlayer,ntypes_impurities)
1393 REAL, DIMENSION(:,:,:), INTENT(IN) :: psnowimp_content !impurities content (g/g) (npoints,nlayer,ntypes_impurities)
1394 !
1395 REAL, DIMENSION(:), INTENT(IN) :: palb ! soil/vegetation albedo (npoints)
1396 !
1397 REAL, DIMENSION(:), INTENT(IN) :: psw_rad ! global broadband incident light (W/m^2) (npoints)
1398 REAL, DIMENSION(:), INTENT(IN) :: pzenith ! zenithal solar angle (npoints)
1399 !
1400 INTEGER, DIMENSION(:), INTENT(IN) :: knlvls_use ! number of effective snow layers (npoints)
1401 !
1402 !Same outputs as SNOWCRORAD and SNOWCROALB
1403 REAL, DIMENSION(:,:), INTENT(OUT) :: pradsink !(npoints,nlayers)
1404 REAL, DIMENSION(:), INTENT(OUT) :: pradxs !(npoints,nlayers)
1405 REAL, DIMENSION(:), INTENT(OUT) :: psnowalb !(npoints,nlayers)
1406 
1407 LOGICAL,INTENT(IN) :: odebug ! Print for debugging
1408  CHARACTER(3), INTENT(IN) :: hsnowmetamo ! metamorphism scheme
1409 
1410 !Local variables
1411 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2),NPNBANDS) :: zsnowenergy !(npoints,nlayer,nbands)
1412 !
1413 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowssa !snow specific surface area (m^2/kg) (npoints,nlayer)
1414 REAL, DIMENSION(SIZE(PSNOWRHO,1),SIZE(PSNOWRHO,2)) :: zsnowenergy_bb ! (W/m^2) (npoints,nlayers)
1415 !
1416 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: zsw_rad_dif ! spectral diffuse incident light (W/m^2) (npoints,nbands)
1417 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: zsw_rad_dir ! spectral direct incident light (W/m^2) (npoints,nbands)
1418 !
1419 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: zsnowalb !(npoints,nbands)
1420 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: zalb ! soil/vegetation albedo (npoints,nbands)
1421 REAL, DIMENSION(SIZE(PSNOWRHO,1),NPNBANDS) :: zsoilenergy !(npoints,nbands)
1422 !
1423 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: znir_abs ! Near infrared radiation (2500-4000 nm) absorbed by snowpack (W/m^2) (npoints)
1424 !
1425 !broad band
1426 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: ztotsnowenergy ! (W/m^2) (npoints)
1427 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zsoilenergy_bb ! (W/m^2) (npoints)
1428 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zreflected_bb ! (W/m^2) (npoints)
1429 !
1430 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zsnowenergy_cum,zsnowenergy_upper ! Cumulated absorbed energy for 1 wavelength W/m^2 (npoints)
1431 REAL, DIMENSION(SIZE(PSNOWRHO,1)) :: zmax ! maximum available energy for 1 wavelength W/m^2 (npoints,nbands)
1432 !
1433 REAL :: zdiam !optical diameter
1434 !
1435 INTEGER :: jb,jl,jj !Loop counter
1436 !
1437 REAL(KIND=JPRB) :: zhook_handle
1438 !
1439 IF (lhook) CALL dr_hook('SNOWCRO_CALL_TARTES',0,zhook_handle)
1440 !
1441 ! Compute SSA from SNOWGRAN1 and SNOWGRAN2
1442 DO jl = 1,SIZE(psnowrho,2)
1443  !
1444  DO jj = 1,SIZE(psnowrho,1)
1445  !
1446  IF ( jl<=knlvls_use(jj) ) THEN
1447  !
1448  CALL get_diam(psnowgran1(jj,jl),psnowgran2(jj,jl),zdiam,hsnowmetamo)
1449  zsnowssa(jj,jl) = 6. / (xrholi*zdiam)
1450  !
1451  ENDIF
1452  !
1453  ENDDO
1454  !
1455 ENDDO
1456 !
1457 DO jb = 1,npnbands
1458  ! Soil-vegetation albedo homogeneous in wavelength
1459  zalb(:,jb) = palb(:)
1460 END DO
1461 !
1462 !Spectral repartition of radiation
1463  CALL spectral_repartition(psw_rad,cos(pzenith),zsw_rad_dif,zsw_rad_dir,znir_abs)
1464 !
1465 IF ( odebug ) THEN
1466  WRITE(*,*) "ZSW_RAD_DIF=",zsw_rad_dif
1467  WRITE(*,*) "ZSW_RAD_DIR=",zsw_rad_dir
1468  WRITE(*,*) "PZENITH=",pzenith
1469 END IF
1470 !
1471 !Call tartes model
1472 ! For test and debugging this routine can be called independently by a python interface
1473 !
1474  CALL tartes(zsnowssa,psnowrho,psnowdz,psnowg0,psnowy0,psnoww0,psnowb0,psnowimp_density,psnowimp_content,zalb,&
1475  zsw_rad_dif,zsw_rad_dir,cos(pzenith),knlvls_use,zsnowalb,zsnowenergy,zsoilenergy)
1476 !
1477  ! Modif ML : in some cases, Tartes is unstable in infra-red wavelengths : control of energy values and apply threshold if necessary
1478  ! --------------------------------------------------------------------------------------------------------------------
1479 
1480 
1481  ! This does not seem to be necessary at CDP when the effective number of layers is properly limited.
1482  ! However, we let the comment code because it might happen again.
1483 
1484 !
1485 ! DO JB=1,NPNBANDS
1486 ! ! maximum available energy at this wavelength
1487 ! ZMAX=ZSW_RAD_DIF(:,JB)*PP_MUDIFF+ZSW_RAD_DIR(:,JB)*COS(PZENITH)
1488 ! ZSNOWENERGY_CUM(:)=0.
1489 ! DO JL=1,SIZE(PSNOWRHO,2)
1490 ! DO JJ=1,SIZE(PSNOWRHO,1)
1491 ! IF (JL<=KNLVLS_USE(JJ)) THEN
1492 ! ZSNOWENERGY_UPPER(JJ)=ZSNOWENERGY_CUM(JJ) !0 for surface layer
1493 ! ! absorbed energy cumulated from the surface
1494 ! ZSNOWENERGY_CUM(JJ)=ZSNOWENERGY_CUM(JJ)+ZSNOWENERGY(JJ,JL,JB)
1495 !
1496 ! ! Case when the energy is negative but close to 0. It can occurs in short wavelengths. Force to 0.
1497 ! IF ((ZSNOWENERGY(JJ,JL,JB)<0).AND. (ZSNOWENERGY(JJ,JL,JB)>-0.1)) THEN
1498 ! ZSNOWENERGY(JJ,JL,JB)=0.
1499 ! END IF
1500 !
1501 ! !if the cumulated absorbed energy excess the available energy or if severe negative energy, numerical problem in Tartes : total absorption
1502 ! IF ((ZSNOWENERGY_CUM(JJ)>ZMAX(JJ)).OR.(ZSNOWENERGY(JJ,JL,JB)<=-0.1)) THEN
1503 ! ! IF (PPWAVELENGTHS(JB)<=1000) THEN
1504 ! IF ((PPWAVELENGTHS(JB)<=1000) .AND.(ABS(ZSNOWENERGY_CUM(JJ)-ZMAX(JJ))>0.01)) THEN
1505 ! ! Tolerance 0.01 W/m2 of excess energy in the visible
1506 ! ! Above, the problem should never happen in visible
1507 !
1508 ! PRINT*,"JB=",JB,"JL=",JL
1509 ! IF (ZSNOWENERGY_CUM(JJ)>ZMAX(JJ)) PRINT*,"excess energy"
1510 ! IF (ZSNOWENERGY(JJ,JL,JB)<0) PRINT*, "negative energy"
1511 !
1512 ! PRINT*,ZSW_RAD_DIF(JJ,JB),ZSW_RAD_DIR(JJ,JB),ZMAX(JJ),ZSNOWENERGY_CUM(JJ)
1513 !
1514 ! PRINT*,"profile :",ZSNOWENERGY(JJ,:,JB)
1515 !
1516 ! STOP "FATAL ERROR TARTES !!"
1517 ! END IF
1518 ! ! The layer absorbes all the remaining energy at this wavelength
1519 ! ZSNOWENERGY(JJ,JL,JB)=ZMAX(JJ)-ZSNOWENERGY_UPPER(JJ)
1520 ! ! update cumulated energy
1521 ! ZSNOWENERGY_CUM(JJ)=ZMAX(JJ)
1522 ! END IF
1523 ! END IF
1524 ! END DO
1525 ! END DO
1526 !
1527 ! ! Threshold on soil absorbed energy
1528 ! DO JJ=1,SIZE(PSNOWRHO,1)
1529 ! ZSNOWENERGY_UPPER(JJ)=ZSNOWENERGY_CUM(JJ)
1530 ! ZSNOWENERGY_CUM(JJ)=ZSNOWENERGY_CUM(JJ)+ZSOILENERGY(JJ,JB)
1531 ! IF (ZSNOWENERGY_CUM(JJ)>ZMAX(JJ)) THEN
1532 ! IF (PPWAVELENGTHS(JB)<=1200) THEN
1533 ! STOP "FATAL ERROR TARTES (soil excess energy in visible)!!"
1534 ! END IF
1535 ! ! The layer absorbes all the remaining energy at this wavelength
1536 ! ZSOILENERGY(JJ,JB)=ZMAX(JJ)-ZSNOWENERGY_UPPER(JJ)
1537 ! END IF
1538 ! END DO
1539 !
1540 ! END DO
1541 
1542  ! End modif ML
1543  ! --------------------------------------------------------------------------------------------------------------------
1544 !
1545 ! Broadband absorbed energy by snowpack and soil
1546 zsnowenergy_bb = 0.
1547 zsoilenergy_bb = 0.
1548 !
1549 DO jb = 1,npnbands
1550  zsnowenergy_bb(:,:) = zsnowenergy_bb(:,:) + zsnowenergy(:,:,jb)
1551  zsoilenergy_bb(:) = zsoilenergy_bb(:) + zsoilenergy(:,jb)
1552 END DO
1553 !
1554 !Add near infra-red wavelengths to first layer
1555 zsnowenergy_bb(:,1) = zsnowenergy_bb(:,1) + znir_abs
1556 !
1557 ! Total energy absorbed by snowpack
1558 ztotsnowenergy(:)=0
1559 DO jl = 1,SIZE(psnowrho,2)
1560  DO jj = 1,SIZE(psnowrho,1)
1561  IF ( jl<=knlvls_use(jj) ) THEN
1562  ztotsnowenergy(jj) = ztotsnowenergy(jj) + zsnowenergy_bb(jj,jl)
1563  END IF
1564  END DO
1565 END DO
1566 !
1567 ! Reflected energy
1568 zreflected_bb = psw_rad - ztotsnowenergy - zsoilenergy_bb
1569 !
1570 ! Broad band Albedo
1571 ! PSW_RAD is never 0 because this routine is not called during the night
1572 psnowalb = zreflected_bb / psw_rad
1573 !
1574 ! Source term
1575 pradsink(:,1) = -psw_rad(:) + zreflected_bb + zsnowenergy_bb(:,1)
1576 !
1577 DO jl = 2,SIZE(psnowrho,2)
1578  pradsink(:,jl) = pradsink(:,jl-1) + zsnowenergy_bb(:,jl)
1579 END DO
1580 !
1581 !Excess energy
1582 pradxs = psw_rad - ztotsnowenergy - zreflected_bb
1583 !
1584 IF (lhook) CALL dr_hook('SNOWCRO_CALL_TARTES',1,zhook_handle)
1585 !
1586 END SUBROUTINE snowcro_call_tartes
1587 
1588 END MODULE mode_tartes
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 taustar_vector(PSNOWSSA, PSNOWRHO, PSNOWDZ, PSNOWSSALB, PSNOWG, PKESTAR, KNLVLS_USE, KMAX_USE, PDTAUSTAR, PTAUSTAR)
subroutine init_tartes()
subroutine shape_parameter_variations(PSNOWG0, PSNOWY0, PSNOWW0, PSNOWB0, PSNOWG00, PSNOWY, PSNOWW, PSNOWB)
subroutine energy_profile(PXA, PXB, PXC, PXD, PKESTAR, PDTAUSTAR, PTAUSTAR, PGM, PGP, PCOSZEN, KNLVLS_EFF, KMAX_EFF, PEPROFILE)
subroutine estimate_effective_layer_number(PKESTAR, PDTAUSTAR, KNLVLS_USE, KMAX_USE, KNLVLS_EFF, KMAX_EFF)
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:62
subroutine refice()
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
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 impurities_co_single_scattering_albedo(PSNOWSSA, PSNOWIMP_DENSITY, PSNOWIMP_CONTENT, KNLVLS_USE, KMAX_USE, PCOSSALB)
subroutine two_stream_vector(PSNOWALBEDO, PSOILALBEDO, PDTAUSTAR, PTAUSTAR, PGM, PGP, PCOSZEN, KNLVLS_EFF, KMAX_EFF, PVECTOR)
subroutine two_stream_matrix(PSNOWALBEDO, PSOILALBEDO, PKESTAR, PDTAUSTAR, KNLVLS_EFF, KMAX_EFF, PDM, PD, PDP)
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 spectral_repartition(PSW_RAD, PCOSZEN, PSW_RAD_DIF, PSW_RAD_DIR, PNIR_ABS)
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)
subroutine soil_absorption(PXA, PXB, PKESTAR, PDTAUSTAR, PTAUSTAR, PGM, PCOSZEN, PALB, KNLVLS_EFF, PSOILENERGY)
subroutine infinite_medium_optical_parameters(PSNOWSSALB, PSNOWG, KNLVLS_USE, KMAX_USE, PSNOWALBEDO, PKESTAR, PG_STAR, PSSALB_STAR, PGAMMA1, PGAMMA2)
subroutine gp_gm_vectors(PSNOWSSALB, PKESTAR, PG_STAR, PSSALB_STAR, PGAMMA1, PGAMMA2, PCOSZEN, PSW_RAD, KNLVLS_EFF, KMAX_EFF, PGP, PGM)
subroutine single_scattering_optical_parameters(PSNOWSSA, PSNOWRHO, PSNOWG0, PSNOWY0, PSNOWW0, PSNOWB0, PSNOWIMP_DENSITY, PSNOWIMP_CONTENT, KNLVLS_USE, KMAX_USE, PSNOWSSALB, PSNOWG)
subroutine refsoot_imag()