SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
pgd_frac.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 pgd_frac (DTCO, UG, U, USS, &
7  hprogram,oecoclimap)
8 ! ##############################################################
9 !
10 !!**** *PGD_FRAC* monitor for averaging and interpolations of cover fractions
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !! METHOD
16 !! ------
17 !!
18 !
19 !! EXTERNAL
20 !! --------
21 !!
22 !! IMPLICIT ARGUMENTS
23 !! ------------------
24 !!
25 !! REFERENCE
26 !! ---------
27 !!
28 !! AUTHOR
29 !! ------
30 !!
31 !! V. Masson Meteo-France
32 !!
33 !! MODIFICATION
34 !! ------------
35 !!
36 !! Original 10/12/97
37 !!
38 !! Modified 08/12/05, P. Le Moigne: user defined fields
39 !! Modified 04/2013 V. Masson : set a cover containing garden for TOWN default
40 !----------------------------------------------------------------------------
41 !
42 !* 0. DECLARATION
43 ! -----------
44 !
45 !
46 !
49 USE modd_surf_atm_n, ONLY : surf_atm_t
51 !
52 USE modd_surf_par, ONLY : xundef
53 USE modd_pgd_grid, ONLY : nl, cgrid
54 USE modd_data_cover_par, ONLY : jpcover
55 !
56 USE modd_pgdwork, ONLY : catype
57 !
58 USE modi_get_luout
59 USE modi_open_namelist
60 USE modi_close_namelist
61 USE modi_pgd_field
62 USE modi_sum_on_all_procs
63 !
64 USE mode_pos_surf
65 !
66 !
67 USE yomhook ,ONLY : lhook, dr_hook
68 USE parkind1 ,ONLY : jprb
69 !
70 USE modi_abor1_sfx
71 !
72 IMPLICIT NONE
73 !
74 !* 0.1 Declaration of arguments
75 ! ------------------------
76 !
77 !
78 TYPE(data_cover_t), INTENT(INOUT) :: dtco
79 TYPE(surf_atm_grid_t), INTENT(INOUT) :: ug
80 TYPE(surf_atm_t), INTENT(INOUT) :: u
81 TYPE(surf_atm_sso_t), INTENT(INOUT) :: uss
82 !
83  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! Type of program
84 LOGICAL, INTENT(OUT) :: oecoclimap ! F if fractions prescribed by user
85 ! ! T if fractions will be computed from ecoclimap
86 !
87 !* 0.2 Declaration of local variables
88 ! ------------------------------
89 !
90 INTEGER :: iluout ! output listing logical unit
91 INTEGER :: ilunam ! namelist file logical unit
92 LOGICAL :: gfound ! true if namelist is found
93 !
94 INTEGER :: jcover ! loop counter on covers
95 !
96 REAL, DIMENSION(NL) :: zsum ! sum of 4 tiles fractions
97 !
98 !* 0.3 Declaration of namelists
99 ! ------------------------
100 !
101 LOGICAL :: lecoclimap ! F if ecoclimap is not used
102 REAL :: xunif_sea ! value of sea fraction
103 REAL :: xunif_water ! value of water fraction
104 REAL :: xunif_nature! value of nature fraction
105 REAL :: xunif_town ! value of town fraction
106 !
107 ! name of files containing data
108 !
109  CHARACTER(LEN=28) :: cfnam_sea ! name of sea file
110  CHARACTER(LEN=28) :: cfnam_water ! name of water file
111  CHARACTER(LEN=28) :: cfnam_nature ! name of nature file
112  CHARACTER(LEN=28) :: cfnam_town ! name of town file
113 !
114 ! type of files containing data
115 !
116  CHARACTER(LEN=6) :: cftyp_sea ! type of sea file
117  CHARACTER(LEN=6) :: cftyp_water ! type of water file
118  CHARACTER(LEN=6) :: cftyp_nature ! type of nature file
119  CHARACTER(LEN=6) :: cftyp_town ! type of town file
120 !
121 INTEGER :: icover ! 0 if cover is not present, >1 if present somewhere
122 ! ! (even on another processor)
123 INTEGER :: icpt
124 !
125 REAL(KIND=JPRB) :: zhook_handle
126 !
127 !
128 namelist/nam_frac/ lecoclimap, &
129  xunif_sea, xunif_water, xunif_nature, xunif_town, &
130  cfnam_sea, cfnam_water, cfnam_nature, cfnam_town, &
131  cftyp_sea, cftyp_water, cftyp_nature, cftyp_town
132 !-------------------------------------------------------------------------------
133 !
134 !* 1. Initializations
135 ! ---------------
136 !
137 IF (lhook) CALL dr_hook('PGD_FRAC',0,zhook_handle)
138 xunif_sea = xundef
139 xunif_water = xundef
140 xunif_nature = xundef
141 xunif_town = xundef
142 lecoclimap = .true.
143  cfnam_sea(:)= ' '
144  cfnam_water(:)= ' '
145  cfnam_nature(:)= ' '
146  cfnam_town(:)= ' '
147  cftyp_sea(:)= ' '
148  cftyp_water(:)= ' '
149  cftyp_nature(:)= ' '
150  cftyp_town(:)= ' '
151 !
152 oecoclimap = .true.
153 !
154 !-------------------------------------------------------------------------------
155 !
156 !* 2. Input file for cover types
157 ! --------------------------
158 !
159  CALL get_luout(hprogram,iluout)
160  CALL open_namelist(hprogram,ilunam)
161 !
162  CALL posnam(ilunam,'NAM_FRAC',gfound,iluout)
163 IF (gfound) READ(unit=ilunam,nml=nam_frac)
164 !
165  CALL close_namelist(hprogram,ilunam)
166 !
167 !-------------------------------------------------------------------------------
168 !
169 IF ((len_trim(cfnam_sea)/=0 .OR. xunif_sea/=xundef) .AND. (len_trim(cfnam_water)/=0 .OR. xunif_water/=xundef) .AND. &
170  (len_trim(cfnam_nature)/=0 .OR. xunif_nature/=xundef) .AND. (len_trim(cfnam_town)/=0 .OR. xunif_town/=xundef)) THEN
171 !
172  ALLOCATE(u%XSEA (nl))
173  ALLOCATE(u%XWATER (nl))
174  ALLOCATE(u%XNATURE(nl))
175  ALLOCATE(u%XTOWN (nl))
176 !
177 !* 3. Uniform fractions are prescribed
178 ! --------------------------------
179 !
180  IF (xunif_sea/=xundef .AND. xunif_water/=xundef .AND. xunif_nature/=xundef .AND. xunif_town/=xundef) THEN
181 !
182 !* 3.1 Verification of the total input cover fractions
183 ! -----------------------------------------------
184 !
185  IF (abs(xunif_sea+xunif_water+xunif_nature+xunif_town-1.)>1.e-6) THEN
186  WRITE(iluout,*) ' '
187  WRITE(iluout,*) '*********************************************************'
188  WRITE(iluout,*) '* Error in fractions preparation *'
189  WRITE(iluout,*) '* The prescribed fractions do not fit *'
190  WRITE(iluout,*) '* The sum of all 4 fractions must be equal to 1 exactly *'
191  WRITE(iluout,*) '*********************************************************'
192  WRITE(iluout,*) ' '
193  CALL abor1_sfx('PGD_FRAC: SUM OF ALL FRACTIONS MUST BE 1.')
194 !
195 !* 3.2 Use of the presribed cover fractions
196 ! ------------------------------------
197 !
198  ELSE
199 !
200  u%XSEA = xunif_sea
201  u%XWATER = xunif_water
202  u%XNATURE = xunif_nature
203  u%XTOWN = xunif_town
204 
205  END IF
206 !
207 !* 3.3 No data
208 ! -------
209 !
210  ELSE
211 
212  catype = 'ARI'
213  IF (xunif_sea==xundef) THEN
214  CALL pgd_field(dtco, ug, u, uss, &
215  hprogram,'XSEA: sea fraction ','ALL', cfnam_sea , &
216  cftyp_sea , xunif_sea , u%XSEA(:) )
217  ELSE
218  u%XSEA(:) = xunif_sea
219  ENDIF
220  IF (xunif_water==xundef) THEN
221  CALL pgd_field(dtco, ug, u, uss, &
222  hprogram,'XWATER: water fraction ','ALL', cfnam_water , &
223  cftyp_water , xunif_water , u%XWATER(:) )
224  ELSE
225  u%XWATER(:) = xunif_water
226  ENDIF
227  IF (xunif_nature==xundef) THEN
228  CALL pgd_field(dtco, ug, u, uss, &
229  hprogram,'XNATURE: nature fraction','ALL', cfnam_nature, &
230  cftyp_nature, xunif_nature, u%XNATURE(:))
231  ELSE
232  u%XNATURE(:) = xunif_nature
233  ENDIF
234  IF (xunif_town==xundef) THEN
235  CALL pgd_field(dtco, ug, u, uss, &
236  hprogram,'XTOWN: town fraction ','ALL', cfnam_town , &
237  cftyp_town , xunif_town , u%XTOWN(:) )
238  ELSE
239  u%XTOWN(:) = xunif_town
240  ENDIF
241  ENDIF
242 
243 ELSE
244 !
245 !* 4. No prescription of fractions
246 ! ----------------------------
247 !
248  IF (lhook) CALL dr_hook('PGD_FRAC',1,zhook_handle)
249  RETURN
250 !
251 ENDIF
252 !-------------------------------------------------------------------------------
253 ! consistency check
254 ! ------------------
255 !
256 zsum(:) = u%XSEA(:) + u%XNATURE(:) + u%XWATER(:) + u%XTOWN(:)
257 
258 u%XSEA(:) = u%XSEA(:) / zsum(:)
259 u%XNATURE(:) = u%XNATURE(:) / zsum(:)
260 u%XWATER(:) = u%XWATER(:) / zsum(:)
261 u%XTOWN(:) = u%XTOWN(:) / zsum(:)
262 !
263 !-------------------------------------------------------------------------------
264 
265 WRITE(iluout,*) ' '
266 !-------------------------------------------------------------------------------
267 !
268 oecoclimap = lecoclimap
269 !
270 !* 5. List of cover present
271 ! ---------------------
272 !
273 IF (.NOT.lecoclimap) THEN
274 
275  ALLOCATE(u%LCOVER(jpcover))
276  u%LCOVER(:) = .false.
277  icover = 0
278  icpt= sum_on_all_procs(hprogram,cgrid,u%XSEA(:)/=0. ,'COV')
279  IF (icpt/=0) THEN
280  u%LCOVER(1) = .true.
281  icover=icover+1
282  ENDIF
283  icpt= sum_on_all_procs(hprogram,cgrid,u%XWATER(:)/=0. ,'COV')
284  IF (icpt/=0) THEN
285  u%LCOVER(2) = .true.
286  icover=icover+1
287  ENDIF
288  icpt= sum_on_all_procs(hprogram,cgrid,u%XNATURE(:)/=0. ,'COV')
289  IF (icpt/=0) THEN
290  u%LCOVER(4) = .true.
291  icover=icover+1
292  ENDIF
293  icpt= sum_on_all_procs(hprogram,cgrid,u%XTOWN(:)/=0. ,'COV')
294  IF (icpt/=0) THEN
295  u%LCOVER(151) = .true.
296  icover=icover+1
297  ENDIF
298 
299  ALLOCATE(u%XCOVER (nl,icover))
300 
301  icpt = 0
302  IF (u%LCOVER(1)) THEN
303  icpt = icpt + 1
304  u%XCOVER(:,icpt) = u%XSEA(:)
305  ENDIF
306  IF (u%LCOVER(2)) THEN
307  icpt = icpt + 1
308  u%XCOVER(:,icpt) = u%XWATER(:)
309  ENDIF
310  IF (u%LCOVER(4)) THEN
311  icpt = icpt + 1
312  u%XCOVER(:,icpt) = u%XNATURE(:)
313  ENDIF
314  IF (u%LCOVER(151)) THEN
315  icpt = icpt + 1
316  u%XCOVER(:,icpt) = u%XTOWN(:)
317  ENDIF
318 
319  ! comment V. Masson: to use this cover type for town by default avoids crashes
320  ! when garden fraction is specified but no garden vegetation parameters.
321  ! In this cas, the properties for garden come from the cover 151
322 !
323 !
324 !-------------------------------------------------------------------------------
325 !
326 !* 6. Land - sea fractions
327 ! --------------------
328 !
329  u%NSIZE_NATURE = count(u%XNATURE(:) > 0.0)
330  u%NSIZE_WATER = count(u%XWATER (:) > 0.0)
331  u%NSIZE_SEA = count(u%XSEA (:) > 0.0)
332  u%NSIZE_TOWN = count(u%XTOWN (:) > 0.0)
333  u%NSIZE_FULL = nl
334 !
335  u%NDIM_NATURE = sum_on_all_procs(hprogram,cgrid,u%XNATURE(:) > 0.0, 'DIM')
336  u%NDIM_WATER = sum_on_all_procs(hprogram,cgrid,u%XWATER (:) > 0.0, 'DIM')
337  u%NDIM_SEA = sum_on_all_procs(hprogram,cgrid,u%XSEA (:) > 0.0, 'DIM')
338  u%NDIM_TOWN = sum_on_all_procs(hprogram,cgrid,u%XTOWN (:) > 0.0, 'DIM')
339 !
340 ENDIF
341 IF (lhook) CALL dr_hook('PGD_FRAC',1,zhook_handle)
342 !-------------------------------------------------------------------------------
343 !
344 END SUBROUTINE pgd_frac
subroutine pgd_field(DTCO, UG, U, USS, HPROGRAM, HFIELD, HAREA, HFILE, HFILETYPE, PUNIF, PFIELD, OPRESENT)
Definition: pgd_field.F90:6
integer function sum_on_all_procs(HPROGRAM, HGRID, OIN, HNAME)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine pgd_frac(DTCO, UG, U, USS, HPROGRAM, OECOCLIMAP)
Definition: pgd_frac.F90:6
subroutine close_namelist(HPROGRAM, KLUNAM)
subroutine posnam(KULNAM, HDNAML, OFOUND, KLUOUT)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine open_namelist(HPROGRAM, KLUNAM, HFILE)