SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
prep_isba_buffer.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 prep_isba_buffer (IG, U, &
7  hprogram,hsurf,kluout,pfield)
8 ! #################################################################################
9 !
10 !!**** *PREP_ISBA_BUFFER* - initializes ISBA fields from operational BUFFER
11 !!
12 !! PURPOSE
13 !! -------
14 !
15 !!** METHOD
16 !! ------
17 !!
18 !! REFERENCE
19 !! ---------
20 !!
21 !!
22 !! AUTHOR
23 !! ------
24 !! S. Malardel
25 !!
26 !! MODIFICATIONS
27 !! -------------
28 !! Original 03/2005
29 !!------------------------------------------------------------------
30 !
31 
32 !
33 !
34 USE modd_isba_grid_n, ONLY : isba_grid_t
35 USE modd_surf_atm_n, ONLY : surf_atm_t
36 !
38 !
40 !
41 USE modi_prep_buffer_grid
43 !
44 USE modd_prep, ONLY : cinterp_type
45 USE modd_prep_isba, ONLY : xgrid_soil, xwr_def
46 USE modd_surf_par, ONLY : xundef
47 USE modd_grid_buffer, ONLY : nni
48 USE modn_prep_isba, ONLY : lextrap_tg,lextrap_wg,lextrap_wgi
49 #ifdef SFX_ARO
50 USE modi_oi_hor_extrapol_surf
51 #endif
54 USE modi_abor1_sfx
55 !
56 !
57 USE yomhook ,ONLY : lhook, dr_hook
58 USE parkind1 ,ONLY : jprb
59 !
60 IMPLICIT NONE
61 !
62 !* 0.1 declarations of arguments
63 !
64 !
65 TYPE(isba_grid_t), INTENT(INOUT) :: ig
66 TYPE(surf_atm_t), INTENT(INOUT) :: u
67 !
68  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! program calling surf. schemes
69  CHARACTER(LEN=7), INTENT(IN) :: hsurf ! type of field
70 INTEGER, INTENT(IN) :: kluout ! logical unit of output listing
71 REAL,DIMENSION(:,:,:), POINTER :: pfield ! field to interpolate horizontally
72 !
73 !* 0.2 declarations of local variables
74 !
75 TYPE (date_time) :: tztime_buf ! current date and time
76  CHARACTER(LEN=6) :: yinmodel ! model from which buffer originates
77 REAL, DIMENSION(:,:), POINTER :: zfield ! field read
78 REAL, DIMENSION(:), POINTER :: zfield1d ! field read
79 REAL, DIMENSION(:,:), POINTER :: zd ! depth of field in the soil
80 REAL,DIMENSION(:),POINTER :: zlsm
81 REAL,DIMENSION(:),POINTER :: zalt
82 REAL,ALLOCATABLE,DIMENSION(:) :: zfield_ep
83 REAL,ALLOCATABLE,DIMENSION(:) :: zfield_ep_in
84 REAL,ALLOCATABLE,DIMENSION(:) :: zlsm_nature
85 REAL,ALLOCATABLE,DIMENSION(:) :: zalt_nature
86 LOGICAL,ALLOCATABLE,DIMENSION(:) :: ointerp
87 INTEGER :: ilayer,ii
88 REAL(KIND=JPRB) :: zhook_handle
89 !
90 !-------------------------------------------------------------------------------------
91 !
92 !* 1. Reading of grid
93 ! ---------------
94 !
95 IF (lhook) CALL dr_hook('PREP_ISBA_BUFFER',0,zhook_handle)
96  CALL prep_buffer_grid(kluout,yinmodel,tztime_buf)
97 
98 !
99 !* 2. Reading of field
100 ! ----------------
101 !
102 !* 3. Transformation into physical quantity to be interpolated
103 ! --------------------------------------------------------
104 !
105 SELECT CASE(hsurf)
106 !
107 !* 3.1 Profile of temperature in the soil
108 !
109  CASE('TG ')
110  !* reading of the profile and its depth definition
111  SELECT CASE(yinmodel)
112  CASE('ALADIN')
113  CALL read_buffer_tg(kluout,yinmodel,zfield,zd)
114  IF ( lextrap_tg ) THEN
115  IF ( SIZE(u%NR_NATURE) /= u%NSIZE_NATURE ) THEN
116  CALL abor1_sfx('ABORT: PREP_ISBA_BUFFER - DIFFERENT SIZES')
117  ELSE
118  ! Allocate working arrays
119  ALLOCATE(zfield_ep(u%NSIZE_NATURE))
120  ALLOCATE(zfield_ep_in(u%NSIZE_NATURE))
121  ALLOCATE(ointerp(u%NSIZE_NATURE))
122  ALLOCATE(zlsm_nature(u%NSIZE_NATURE))
123  ALLOCATE(zalt_nature(u%NSIZE_NATURE))
124 
125  ! Read LSM and ZS
126  CALL read_buffer_land_mask(kluout,yinmodel,zlsm)
127  CALL read_buffer_zs(kluout,yinmodel,zalt)
128 
129  ! Pack nature points to reduce dimension to nsize_nature
130  CALL pack_same_rank(u%NR_NATURE,zlsm,zlsm_nature)
131  CALL pack_same_rank(u%NR_NATURE,zalt,zalt_nature)
132 
133  ! Do extrapolations in all layers
134  DO ilayer=1,SIZE(zfield,2)
135  WRITE(kluout,*) 'Extrapolating TG from nearest land point in points where LSM < 0.5. LAYER:',ilayer
136 
137  ! Pack nature points to reduce dimension
138  CALL pack_same_rank(u%NR_NATURE,zfield(:,ilayer),zfield_ep(:))
139  ! Set values to be extrapolated
140  ointerp=.false.
141  DO ii=1,u%NSIZE_NATURE
142  IF ( zlsm_nature(ii) < 0.5 ) THEN
143  ointerp(ii) = .true.
144  zfield_ep(ii) = xundef
145  ENDIF
146  ENDDO
147 
148  zfield_ep_in(:) = zfield_ep(:)
149 #ifdef SFX_ARO
150  CALL oi_hor_extrapol_surf(u%NSIZE_NATURE,ig%XLAT,ig%XLON,zfield_ep_in(:), &
151  ig%XLAT,ig%XLON,zfield_ep(:),ointerp,pzs=zalt,ndim2=10)
152 #endif
153 
154  ! Unpack to full rank
155  CALL unpack_same_rank(u%NR_NATURE,zfield_ep(:),zfield(:,ilayer))
156  ENDDO
157  DEALLOCATE(zfield_ep)
158  DEALLOCATE(zfield_ep_in)
159  DEALLOCATE(zlsm_nature)
160  DEALLOCATE(zalt_nature)
161  DEALLOCATE(ointerp)
162  ENDIF
163  ENDIF
164  END SELECT
165 
167 
168  CASE('WG ')
169  !* reading of the profile and its depth definition
170  SELECT CASE(yinmodel)
171  CASE('ARPEGE','ALADIN','MOCAGE')
172  CALL read_buffer_wg(kluout,yinmodel,zfield,zd)
173  IF ( lextrap_wg ) THEN
174  IF ( SIZE(u%NR_NATURE) /= u%NSIZE_NATURE ) THEN
175  CALL abor1_sfx('ABORT: PREP_ISBA_BUFFER - DIFFERENT SIZES')
176  ELSE
177  ! Allocate working arrays
178  ALLOCATE(zfield_ep(u%NSIZE_NATURE))
179  ALLOCATE(zfield_ep_in(u%NSIZE_NATURE))
180  ALLOCATE(ointerp(u%NSIZE_NATURE))
181  ALLOCATE(zlsm_nature(u%NSIZE_NATURE))
182 
183  ! Read LSM
184  CALL read_buffer_land_mask(kluout,yinmodel,zlsm)
185 
186  ! Pack nature points to reduce dimension to nsize_nature
187  CALL pack_same_rank(u%NR_NATURE,zlsm,zlsm_nature)
188 
189  ! Do extrapolations in all layers
190  DO ilayer=1,SIZE(zfield,2)
191  WRITE(kluout,*) 'Extrapolating WG from nearest land point in points where LSM < 0.5. LAYER:',ilayer
192 
193  ! Pack nature points to reduce dimension
194  CALL pack_same_rank(u%NR_NATURE,zfield(:,ilayer),zfield_ep(:))
195  ! Set values to be extrapolated
196  ointerp=.false.
197 
198  DO ii=1,u%NSIZE_NATURE
199  IF ( zlsm_nature(ii) < 0.5 ) THEN
200  ointerp(ii) = .true.
201  zfield_ep(ii) = xundef
202  ENDIF
203  ENDDO
204 
205  zfield_ep_in(:) = zfield_ep
206 #ifdef SFX_ARO
207  CALL oi_hor_extrapol_surf(u%NSIZE_NATURE,ig%XLAT,ig%XLON,zfield_ep_in(:), &
208  ig%XLAT,ig%XLON,zfield_ep(:),ointerp,ndim2=10)
209 #endif
210 
211  ! Unpack to full rank
212  CALL unpack_same_rank(u%NR_NATURE,zfield_ep(:),zfield(:,ilayer))
213  ENDDO
214  DEALLOCATE(zfield_ep)
215  DEALLOCATE(zfield_ep_in)
216  DEALLOCATE(zlsm_nature)
217  DEALLOCATE(ointerp)
218  ENDIF
219  ENDIF
220 
221  END SELECT
223 
224 
225 !* 3.3 Profile of soil ice content
226 
227  CASE('WGI ')
228  !* reading of the profile and its depth definition
229  SELECT CASE(yinmodel)
230  CASE('ALADIN')
231  CALL read_buffer_wgi(kluout,yinmodel,zfield,zd)
232  IF ( lextrap_wgi ) THEN
233 
234  IF ( SIZE(u%NR_NATURE) /= u%NSIZE_NATURE ) THEN
235  CALL abor1_sfx('ABORT: PREP_ISBA_BUFFER - DIFFERENT SIZES')
236  ELSE
237 
238  ! Allocate working arrays
239  ALLOCATE(zfield_ep(u%NSIZE_NATURE))
240  ALLOCATE(zfield_ep_in(u%NSIZE_NATURE))
241  ALLOCATE(ointerp(u%NSIZE_NATURE))
242  ALLOCATE(zlsm_nature(u%NSIZE_NATURE))
243 
244  ! Read LSM
245  CALL read_buffer_land_mask(kluout,yinmodel,zlsm)
246 
247  ! Pack nature points to reduce dimension to nsize_nature
248  CALL pack_same_rank(u%NR_NATURE,zlsm,zlsm_nature)
249 
250  ! Do extrapolations in all layers
251  DO ilayer=1,SIZE(zfield,2)
252  WRITE(kluout,*) 'Extrapolating WGI from nearest land point in points where LSM < 0.5. LAYER:',ilayer
253 
254  ! Pack nature points to reduce dimension
255  CALL pack_same_rank(u%NR_NATURE,zfield(:,ilayer),zfield_ep(:))
256  ! Set values to be extrapolated
257  ointerp=.false.
258  DO ii=1,u%NSIZE_NATURE
259  IF ( zlsm_nature(ii) < 0.5 ) THEN
260  ointerp(ii) = .true.
261  zfield_ep(ii) = xundef
262  ENDIF
263  ENDDO
264 
265  zfield_ep_in(:) = zfield_ep
266 #ifdef SFX_ARO
267  CALL oi_hor_extrapol_surf(u%NSIZE_NATURE,ig%XLAT,ig%XLON,zfield_ep_in(:), &
268  ig%XLAT,ig%XLON,zfield_ep(:),ointerp,ndim2=10)
269 #endif
270 
271  ! Unpack to full rank
272  CALL unpack_same_rank(u%NR_NATURE,zfield_ep(:),zfield(:,ilayer))
273  ENDDO
274  DEALLOCATE(zfield_ep)
275  DEALLOCATE(zfield_ep_in)
276  DEALLOCATE(zlsm_nature)
277  DEALLOCATE(ointerp)
278  ENDIF
279  ENDIF
280 
281  END SELECT
283 !
284 !* 3.4 Water content intercepted on leaves, LAI
285 !
286  CASE('WR ')
287  ALLOCATE(pfield(nni,1,1))
288  pfield(:,:,:) = xwr_def
289 !
290  CASE('LAI ')
291  ALLOCATE(pfield(nni,1,1))
292  pfield(:,:,:) = xundef
293 !
294 !
295 !* 3.5 Other fields
296 !
297  CASE('ZS ')
298  CALL read_buffer_zs(kluout,yinmodel,zfield1d)
299  ALLOCATE(pfield(SIZE(zfield1d,1),1,1))
300  pfield(:,1,1)=zfield1d(:)
301  DEALLOCATE(zfield1d)
302 !
303  CASE('ICE_STO')
304  ALLOCATE(pfield(nni,1,1))
305  pfield(:,:,:) = 0.0
306 !
307  CASE default
308  CALL abor1_sfx('PREP_ISBA_BUFFER: '//trim(hsurf)//" initialization not implemented !")
309 !
310 END SELECT
311 !
312 !* 4. Interpolation method
313 ! --------------------
314 !
315  cinterp_type='BUFFER'
316 !
317 !
318 !-------------------------------------------------------------------------------------
319 !-------------------------------------------------------------------------------------
320 !
321 IF (lhook) CALL dr_hook('PREP_ISBA_BUFFER',1,zhook_handle)
322  CONTAINS
323 !
324 !-------------------------------------------------------------------------------------
325 !-------------------------------------------------------------------------------------
327 !-------------------------------------------------------------------------------------
328 !
329 REAL, DIMENSION(:,:), ALLOCATABLE :: zout ! work array
330 REAL(KIND=JPRB) :: zhook_handle
331 !
332 !-------------------------------------------------------------------------------------
333 !
334  !
335  !* interpolation on fine vertical grid
336  IF (lhook) CALL dr_hook('SOIL_PROFILE_BUFFER',0,zhook_handle)
337  ALLOCATE(zout(SIZE(zfield,1),SIZE(xgrid_soil)))
338  CALL interp_grid_nat(zd,zfield,xgrid_soil,zout)
339  !
340  !* extends definition to all vegtypes.
341  ALLOCATE(pfield(SIZE(zfield,1),SIZE(xgrid_soil),1))
342  pfield(:,:,1)=zout(:,:)
343  !* end
344  DEALLOCATE(zout)
345  DEALLOCATE(zfield)
346  DEALLOCATE(zd)
347 IF (lhook) CALL dr_hook('SOIL_PROFILE_BUFFER',1,zhook_handle)
348 
349 END SUBROUTINE soil_profile_buffer
350 !
351 !-------------------------------------------------------------------------------------
352 END SUBROUTINE prep_isba_buffer
subroutine read_buffer_wgi(KLUOUT, HINMODEL, PFIELD, PD)
subroutine read_buffer_tg(KLUOUT, HINMODEL, PFIELD, PD)
subroutine read_buffer_land_mask(KLUOUT, HINMODEL, PMASK)
subroutine read_buffer_wg(KLUOUT, HINMODEL, PFIELD, PD)
subroutine prep_isba_buffer(IG, U, HPROGRAM, HSURF, KLUOUT, PFIELD)
subroutine prep_buffer_grid(KLUOUT, HINMODEL, TPTIME_BUF)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine oi_hor_extrapol_surf(NDIM, PLAT_IN, PLON_IN, PFIELD_IN, PLAT, PLON, PFIELD, OINTERP, PZS, NDIM2)
subroutine read_buffer_zs(KLUOUT, HINMODEL, PFIELD)
subroutine soil_profile_buffer