SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
av_pgd_param.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! ################################################################
6  SUBROUTINE av_pgd_param (DTI, &
7  pfield,pvegtype,pdata,hsftype,hatype,pdz,kdecade)
8 ! ################################################################
9 !
10 !!**** *AV_PATCH_PGD* average for each surface patch a secondary physiographic
11 !! variable from the
12 !! fractions of coverage class.
13 !!
14 !! PURPOSE
15 !! -------
16 !!
17 !! METHOD
18 !! ------
19 !!
20 !! The averaging is performed with one way into three:
21 !!
22 !! - arithmetic averaging (HATYPE='ARI')
23 !!
24 !! - inverse averaging (HATYPE='INV')
25 !!
26 !! - inverse of square logarithm averaging (HATYPE='CDN') :
27 !!
28 !! 1 / ( ln (dz/data) )**2
29 !!
30 !! This latest uses (if available) the height of the first model mass
31 !! level. In the other case, 20m is chosen. It works for roughness lengths.
32 !!
33 !! EXTERNAL
34 !! --------
35 !!
36 !! IMPLICIT ARGUMENTS
37 !! ------------------
38 !!
39 !! REFERENCE
40 !! ---------
41 !!
42 !! AUTHOR
43 !! ------
44 !!
45 !! F.Solmon /V. Masson
46 !!
47 !! MODIFICATION
48 !! ------------
49 !!
50 !! Original 15/12/97
51 !! V. Masson 01/2004 Externalization
52 !! R. Alkama 04/2012 add 6 new tree vegtype (9 instead 3)
53 !
54 !----------------------------------------------------------------------------
55 !
56 !* 0. DECLARATION
57 ! -----------
58 !
59 !
60 USE modd_data_isba_n, ONLY : data_isba_t
61 !
62 USE modd_surf_par, ONLY : xundef
63 USE modd_data_cover_par, ONLY : nvt_tebd, nvt_bone, nvt_trbe, nvt_trbd, nvt_tebe, &
64  nvt_tene, nvt_bobd, nvt_bond, nvt_shrb, nvegtype, &
65  xcdref
66 
67 !
68 USE modi_vegtype_to_patch
69 !
70 !
71 !
72 USE yomhook ,ONLY : lhook, dr_hook
73 USE parkind1 ,ONLY : jprb
74 !
75 USE modi_abor1_sfx
76 !
77 IMPLICIT NONE
78 !
79 !* 0.1 Declaration of arguments
80 ! ------------------------
81 !
82 !
83 TYPE(data_isba_t), INTENT(INOUT) :: dti
84 !
85 REAL, DIMENSION(:,:), INTENT(OUT) :: pfield ! secondary field to construct
86 REAL, DIMENSION(:,:), INTENT(IN) :: pvegtype ! fraction of each cover class
87 REAL, DIMENSION(:,:), INTENT(IN) :: pdata ! secondary field value for each class
88  CHARACTER(LEN=3), INTENT(IN) :: hsftype ! Type of surface where the field
89  ! is defined
90  CHARACTER(LEN=3), INTENT(IN) :: hatype ! Type of averaging
91 REAL, DIMENSION(:), INTENT(IN), OPTIONAL :: pdz ! first model half level
92 INTEGER, INTENT(IN), OPTIONAL :: kdecade ! current month
93 !
94 !* 0.2 Declaration of local variables
95 ! ------------------------------
96 !
97 !
98 INTEGER :: icover ! number of cover classes
99 INTEGER :: jcover ! loop on cover classes
100 !
101 ! nbe of vegtype
102 ! nbre of patches
103 INTEGER :: jvegtype! loop on vegtype
104 INTEGER :: ipatch ! number of patches
105 INTEGER :: jpatch ! PATCH index
106 INTEGER :: jj, ji
107 !
108 REAL, DIMENSION(SIZE(PFIELD,1),NVEGTYPE) :: zweight
109 !
110 REAL, DIMENSION(SIZE(PFIELD,1),SIZE(PFIELD,2)) :: zsum_weight_patch
111 !
112 REAL, DIMENSION(SIZE(PFIELD,1),SIZE(PFIELD,2)) :: zwork
113 REAL, DIMENSION(SIZE(PFIELD,1),SIZE(PFIELD,2)) :: zdz
114 !
115 INTEGER, DIMENSION(SIZE(PFIELD,1),SIZE(PFIELD,2)) :: nmask
116 INTEGER, DIMENSION(SIZE(PFIELD,2)) :: jcount
117 INTEGER :: patch_list(nvegtype)
118 REAL(KIND=JPRB) :: zhook_handle
119 
120 !-------------------------------------------------------------------------------
121 !
122 !* 1.1 field does not exist
123 ! --------------------
124 !
125 IF (lhook) CALL dr_hook('AV_PGD_PARAM',0,zhook_handle)
126 IF (SIZE(pfield)==0 .AND. lhook) CALL dr_hook('AV_PGD_PARAM',1,zhook_handle)
127 IF (SIZE(pfield)==0) RETURN
128 !
129 !-------------------------------------------------------------------------------
130 !
131 !* 1.2 Initializations
132 ! ---------------
133 !
134 ipatch=SIZE(pfield,2)
135 !
136 !
137 IF (present(pdz)) THEN
138  DO jpatch=1,ipatch
139  zdz(:,jpatch)=pdz(:)
140  END DO
141 ELSE
142  zdz(:,:)=xcdref
143 END IF
144 !
145 pfield(:,:)=xundef
146 !
147 zwork(:,:)=0.
148 zweight(:,:)=0.
149 zsum_weight_patch(:,:)=0.
150 !
151 DO jvegtype=1,nvegtype
152  patch_list(jvegtype) = vegtype_to_patch(jvegtype, ipatch)
153 ENDDO
154 
155 !-------------------------------------------------------------------------------
156 !-------------------------------------------------------------------------------
157 !
158 !* 2. Selection of the weighting function for vegtype
159 ! -----------------------------------
160 !
161 SELECT CASE (hsftype)
162 
163  CASE('NAT','GRD')
164  DO jvegtype=1,nvegtype
165  zweight(:,jvegtype)=pvegtype(:,jvegtype)
166  END DO
167 
168  CASE('VEG','GRV')
169  DO jvegtype=1,nvegtype
170  zweight(:,jvegtype)=pvegtype(:,jvegtype)*dti%XPAR_VEG(:,kdecade,jvegtype)
171  END DO
172 
173  CASE('BAR','GRB')
174  DO jvegtype=1,nvegtype
175  zweight(:,jvegtype)=pvegtype(:,jvegtype)*(1.-dti%XPAR_VEG(:,kdecade,jvegtype))
176  END DO
177 
178  CASE('DVG','GDV') ! for diffusion scheme only, average only on vegetated area
179  DO jvegtype=1,nvegtype
180  WHERE ( sum(dti%XPAR_LAI(:,:,jvegtype),2) .GT. 0.0) &
181  zweight(:,jvegtype)=pvegtype(:,jvegtype)
182  END DO
183 
184  CASE('LAI','GRL')
185  DO jvegtype=4,nvegtype
186  zweight(:,jvegtype)=pvegtype(:,jvegtype)*dti%XPAR_LAI(:,kdecade,jvegtype)
187  END DO
188 
189  CASE('TRE','GRT')
190  zweight(:,:)=0.
191  WHERE (pvegtype(:,nvt_tebd)>0.)
192  zweight(:,nvt_tebd)=pvegtype(:,nvt_tebd)
193  ENDWHERE
194  WHERE (pvegtype(:,nvt_bone)>0.)
195  zweight(:,nvt_bone)=pvegtype(:,nvt_bone)
196  ENDWHERE
197  WHERE (pvegtype(:,nvt_trbe)>0.)
198  zweight(:,nvt_trbe)=pvegtype(:,nvt_trbe)
199  ENDWHERE
200 
201  WHERE (pvegtype(:,nvt_trbd)>0.)
202  zweight(:,nvt_trbd)=pvegtype(:,nvt_trbd)
203  ENDWHERE
204  WHERE (pvegtype(:,nvt_tebe)>0.)
205  zweight(:,nvt_tebe)=pvegtype(:,nvt_tebe)
206  ENDWHERE
207  WHERE (pvegtype(:,nvt_tene)>0.)
208  zweight(:,nvt_tene)=pvegtype(:,nvt_tene)
209  ENDWHERE
210  WHERE (pvegtype(:,nvt_bobd)>0.)
211  zweight(:,nvt_bobd)=pvegtype(:,nvt_bobd)
212  ENDWHERE
213  WHERE (pvegtype(:,nvt_bond)>0.)
214  zweight(:,nvt_bond)=pvegtype(:,nvt_bond)
215  ENDWHERE
216  WHERE (pvegtype(:,nvt_shrb)>0.)
217  zweight(:,nvt_shrb)=pvegtype(:,nvt_shrb)
218  ENDWHERE
219 
220  CASE default
221  CALL abor1_sfx('AV_PGD_PARAM: WEIGHTING FUNCTION FOR VEGTYPE NOT ALLOWED')
222 END SELECT
223 !
224 !-------------------------------------------------------------------------------
225 !
226 !* 3. Averaging
227 ! ---------
228 !
229 !* 3.1 Work arrays given for each patch
230 ! -----------
231 !
232 !* 3.2 Selection of averaging type
233 ! ---------------------------
234 !
235 SELECT CASE (hatype)
236 !
237 !-------------------------------------------------------------------------------
238 !
239 !* 3.3 Arithmetic averaging
240 ! --------------------
241 !
242  CASE ('ARI')
243 !
244  DO jvegtype=1,nvegtype
245  jpatch= patch_list(jvegtype)
246  DO jj=1,SIZE(pdata,1)
247  zsum_weight_patch(jj,jpatch) = zsum_weight_patch(jj,jpatch) + zweight(jj,jvegtype)
248  zwork(jj,jpatch) = zwork(jj,jpatch) + pdata(jj,jvegtype) * zweight(jj,jvegtype)
249  ENDDO
250  END DO
251 !
252 !-------------------------------------------------------------------------------
253 !
254 !* 3.4 Inverse averaging
255 ! -----------------
256 !
257  CASE('INV' )
258 !
259  DO jvegtype=1,nvegtype
260  jpatch=patch_list(jvegtype)
261  DO jj=1,SIZE(pdata,1)
262  zsum_weight_patch(jj,jpatch) = zsum_weight_patch(jj,jpatch)+zweight(jj,jvegtype)
263  IF (pdata(jj,jvegtype).NE.0.) THEN
264  zwork(jj,jpatch)= zwork(jj,jpatch) + 1./ pdata(jj,jvegtype) * zweight(jj,jvegtype)
265  ENDIF
266  ENDDO
267  END DO
268 !
269 !-------------------------------------------------------------------------------!
270 !
271 !* 3.5 Roughness length averaging
272 ! --------------------------
273 
274 !
275  CASE('CDN')
276 !
277  DO jvegtype=1,nvegtype
278  jpatch=patch_list(jvegtype)
279  DO jj=1,SIZE(pdata,1)
280  zsum_weight_patch(jj,jpatch) = zsum_weight_patch(jj,jpatch)+ zweight(jj,jvegtype)
281  IF (pdata(jj,jvegtype).NE.0.) THEN
282  zwork(jj,jpatch)= zwork(jj,jpatch) + 1./(log(zdz(jj,jpatch)/ pdata(jj,jvegtype)))**2 &
283  * zweight(jj,jvegtype)
284  ENDIF
285  ENDDO
286  END DO
287 !
288 !-------------------------------------------------------------------------------
289 !
290  CASE default
291  CALL abor1_sfx('AV_PGD_PARAM: (1) AVERAGING TYPE NOT ALLOWED')
292 !
293 END SELECT
294 !
295 !-------------------------------------------------------------------------------
296 !
297 !* 4. End of Averaging
298 ! ----------------
299 !
300 nmask(:,:)=0
301 jcount(:)=0
302 DO jpatch=1,ipatch
303  DO jj=1,SIZE(zwork,1)
304  IF ( zsum_weight_patch(jj,jpatch) >0.) THEN
305  jcount(jpatch)=jcount(jpatch)+1
306  nmask(jcount(jpatch),jpatch)=jj
307  ENDIF
308  ENDDO
309 ENDDO
310 
311 !* 4.1 Selection of averaging type
312 ! ---------------------------
313 !
314 SELECT CASE (hatype)
315 !
316 !-------------------------------------------------------------------------------
317 !
318 !* 4.2 Arithmetic averaging
319 ! --------------------
320 !
321  CASE ('ARI')
322 !
323  DO jpatch=1,ipatch
324 !cdir nodep
325  DO jj=1,jcount(jpatch)
326  ji = nmask(jj,jpatch)
327  pfield(ji,jpatch) = zwork(ji,jpatch) / zsum_weight_patch(ji,jpatch)
328  ENDDO
329  ENDDO
330 !
331 !-------------------------------------------------------------------------------
332 !
333 !* 4.3 Inverse averaging
334 ! -----------------
335 !
336  CASE('INV' )
337 !
338  DO jpatch=1,ipatch
339 !cdir nodep
340  DO jj=1,jcount(jpatch)
341  ji = nmask(jj,jpatch)
342  pfield(ji,jpatch) = zsum_weight_patch(ji,jpatch) / zwork(ji,jpatch)
343  ENDDO
344  ENDDO
345 !-------------------------------------------------------------------------------!
346 !
347 !* 4.4 Roughness length averaging
348 ! --------------------------
349 
350 !
351  CASE('CDN')
352 !
353  DO jpatch=1,ipatch
354 !cdir nodep
355  DO jj=1,jcount(jpatch)
356  ji=nmask(jj,jpatch)
357  pfield(ji,jpatch) = zdz(ji,jpatch) * exp( - sqrt(zsum_weight_patch(ji,jpatch)/zwork(ji,jpatch)) )
358  ENDDO
359  ENDDO
360 !
361 !-------------------------------------------------------------------------------
362 !
363  CASE default
364  CALL abor1_sfx('AV_PGD_PARAM: (2) AVERAGING TYPE NOT ALLOWED')
365 !
366 END SELECT
367 IF (lhook) CALL dr_hook('AV_PGD_PARAM',1,zhook_handle)
368 !-------------------------------------------------------------------------------
369 !
370 END SUBROUTINE av_pgd_param
subroutine av_pgd_param(DTI, PFIELD, PVEGTYPE, PDATA, HSFTYPE, HATYPE, PDZ, KDECADE)
Definition: av_pgd_param.F90:6
integer function vegtype_to_patch(IVEGTYPE, INPATCH)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6