SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
prep_isba_extern.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_extern (DTCO, I, U, &
7  hprogram,hsurf,hfile,hfiletype,hfilepgd,hfilepgdtype,kluout,pfield,okey)
8 ! #################################################################################
9 !
10 !!**** *PREP_ISBA_EXTERN* - initializes ISBA fields from operational GRIB
11 !!
12 !! PURPOSE
13 !! -------
14 !
15 !!** METHOD
16 !! ------
17 !!
18 !! REFERENCE
19 !! ---------
20 !!
21 !!
22 !! AUTHOR
23 !! ------
24 !! V. Masson
25 !!
26 !! MODIFICATIONS
27 !! -------------
28 !! Original 01/2004
29 !! B. Decharme 04/2014, external init with FA files
30 !!------------------------------------------------------------------
31 !
32 !
33 !
34 !
35 !
36 !
38 USE modd_isba_n, ONLY : isba_t
39 USE modd_surf_atm_n, ONLY : surf_atm_t
40 !
41 USE modd_prep, ONLY : cingrid_type, cinterp_type
42 USE modd_prep_isba, ONLY : xgrid_soil, xwr_def
43 USE modd_surf_par, ONLY : xundef
44 !
46 !
48 !
49 USE modi_prep_grid_extern
52 USE modi_open_aux_io_surf
53 USE modi_close_aux_io_surf
54 !
55 USE modi_abor1_sfx
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(data_cover_t), INTENT(INOUT) :: dtco
66 TYPE(isba_t), INTENT(INOUT) :: i
67 TYPE(surf_atm_t), INTENT(INOUT) :: u
68 !
69  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! program calling surf. schemes
70  CHARACTER(LEN=7), INTENT(IN) :: hsurf ! type of field
71  CHARACTER(LEN=28), INTENT(IN) :: hfile ! name of file
72  CHARACTER(LEN=6), INTENT(IN) :: hfiletype ! type of input file
73  CHARACTER(LEN=28), INTENT(IN) :: hfilepgd ! name of file
74  CHARACTER(LEN=6), INTENT(IN) :: hfilepgdtype ! type of input file
75 INTEGER, INTENT(IN) :: kluout ! logical unit of output listing
76 REAL,DIMENSION(:,:,:), POINTER :: pfield ! field to interpolate horizontally (on final soil grid)
77 LOGICAL, OPTIONAL, INTENT(INOUT):: okey
78 !
79 !* 0.2 declarations of local variables
80 !
81  CHARACTER(LEN=12) :: yrecfm ! Name of the article to be read
82 INTEGER :: iresp ! reading return code
83 INTEGER :: ini ! total 1D dimension
84 INTEGER :: ipatch ! number of patch
85 LOGICAL :: gglacier
86  CHARACTER(LEN=3) :: yphoto
87 !
88 REAL, DIMENSION(:,:,:), POINTER :: zfield ! field read on initial MNH vertical soil grid, all patches
89 REAL, DIMENSION(:,:), POINTER :: zfield1 ! field read on initial MNH vertical soil grid, one patch
90 REAL, DIMENSION(:,:,:), POINTER :: zd ! layer thicknesses
91 REAL, DIMENSION(:,:), POINTER :: zd1 ! layer thicknesses, one patch
92 REAL, DIMENSION(:,:), ALLOCATABLE :: zout !
93 REAL, DIMENSION(:), ALLOCATABLE :: zmask
94 INTEGER :: jpatch, jl ! loop counter for patch
95 INTEGER :: iversion
96 REAL(KIND=JPRB) :: zhook_handle
97 !
98 !------------------------------------------------------------------------------
99 !
100 !* 1. Preparation of IO for reading in the file
101 ! -----------------------------------------
102 !
103 !* Note that all points are read, even those without physical meaning.
104 ! These points will not be used during the horizontal interpolation step.
105 ! Their value must be defined as XUNDEF.
106 !
107 IF (lhook) CALL dr_hook('PREP_ISBA_EXTERN',0,zhook_handle)
108 !
109 !------------------------------------------------------------------------------
110 !
111 !* 2. Reading of grid
112 ! ---------------
113 !
114  CALL open_aux_io_surf(&
115  hfilepgd,hfilepgdtype,'FULL ')
116 !
117  CALL prep_grid_extern(&
118  hfilepgdtype,kluout,cingrid_type,cinterp_type,ini)
119 !
120 yrecfm='VERSION'
121  CALL read_surf(hfilepgdtype,yrecfm,iversion,iresp)
122 !
123 ALLOCATE(zmask(ini))
124 IF (iversion>=7) THEN
125  yrecfm='FRAC_NATURE'
126  CALL read_surf(hfilepgdtype,yrecfm,zmask,iresp,hdir='A')
127 ELSE
128  zmask(:) = 1.
129 ENDIF
130 !
131 !---------------------------------------------------------------------------------------
132 !
133 !* 3. Transformation into physical quantity to be interpolated
134 ! --------------------------------------------------------
135 !
136 SELECT CASE(hsurf)
137 !
138 !* 3. Orography
139 ! ---------
140 !
141  CASE('ZS ')
142  ALLOCATE(pfield(ini,1,1))
143  pfield(:,:,:) = xundef
144  yrecfm='ZS'
145  CALL read_surf(&
146  hfilepgdtype,yrecfm,pfield(:,1,1),iresp,hdir='A')
147  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
148 !
149 !--------------------------------------------------------------------------
150 !
151 !
152 !* 3.1 Profile of temperature, water or ice in the soil
153 !
154  CASE('TG ','WG ','WGI ')
155  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
156 !* reading of the profile and its depth definition
157  CALL read_extern_isba(u, &
158  dtco, i, &
159  hfile,hfiletype,hfilepgd,hfilepgdtype,&
160  kluout,ini,hsurf,hsurf,zfield,zd,okey)
161 !
162  ALLOCATE(zfield1(SIZE(zfield,1),SIZE(zfield,2)))
163  ALLOCATE(zd1(SIZE(zfield,1),SIZE(zfield,2)))
164  ALLOCATE(zout(SIZE(zfield,1),SIZE(xgrid_soil)))
165  ALLOCATE(pfield(SIZE(zfield,1),SIZE(xgrid_soil),SIZE(zfield,3)))
166  pfield(:,:,:) = xundef
167 !
168  DO jpatch=1,SIZE(zfield,3)
169  zfield1(:,:)=zfield(:,:,jpatch)
170  zd1(:,:)=zd(:,:,jpatch)
171  CALL interp_grid_nat(zd1,zfield1,xgrid_soil,zout)
172  pfield(:,:,jpatch)=zout(:,:)
173  END DO
174  !
175  DO jpatch=1,SIZE(pfield,3)
176  DO jl=1,SIZE(pfield,2)
177  WHERE (zmask(:)==0.) pfield(:,jl,jpatch) = xundef
178  ENDDO
179  ENDDO
180  !
181  DEALLOCATE(zfield)
182  DEALLOCATE(zout)
183  DEALLOCATE(zfield1)
184  DEALLOCATE(zd)
185 !
186 !--------------------------------------------------------------------------
187 !
188 !* 3.4 Water content intercepted on leaves, LAI
189 !
190  CASE('WR ')
191  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
192  !* number of tiles
193  CALL open_aux_io_surf(&
194  hfilepgd,hfilepgdtype,'NATURE')
195  yrecfm='PATCH_NUMBER'
196  CALL read_surf(&
197  hfilepgdtype,yrecfm,ipatch,iresp)
198  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
199  ALLOCATE(pfield(ini,1,ipatch))
200  pfield(:,:,:) = xundef
201  yrecfm = 'WR'
202  CALL open_aux_io_surf(&
203  hfile,hfiletype,'NATURE')
204  CALL read_surf(&
205  hfiletype,yrecfm,pfield(:,1,:),iresp,hdir='A')
206  CALL close_aux_io_surf(hfile,hfiletype)
207  DO jpatch=1,SIZE(pfield,3)
208  WHERE (zmask(:)==0.) pfield(:,1,jpatch) = xundef
209  ENDDO
210 !
211  CASE('LAI ')
212  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
213  !* number of tiles
214  CALL open_aux_io_surf(&
215  hfilepgd,hfilepgdtype,'NATURE')
216  yrecfm='PATCH_NUMBER'
217  CALL read_surf(&
218  hfilepgdtype,yrecfm,ipatch,iresp)
219  yrecfm='PHOTO'
220  CALL read_surf(&
221  hfilepgdtype,yrecfm,yphoto,iresp)
222  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
223  ALLOCATE(pfield(ini,1,ipatch))
224  pfield(:,:,:) = xundef
225  IF (yphoto=='LAI' .OR. yphoto=='LST' .OR. yphoto=='NIT' .OR. yphoto=='NCB') THEN
226  CALL open_aux_io_surf(&
227  hfile,hfiletype,'NATURE')
228  yrecfm = 'LAI'
229  CALL read_surf(&
230  hfiletype,yrecfm,pfield(:,1,:),iresp,hdir='A')
231  CALL close_aux_io_surf(hfile,hfiletype)
232  DO jpatch=1,SIZE(pfield,3)
233  WHERE (zmask(:)==0.) pfield(:,1,jpatch) = xundef
234  ENDDO
235  ENDIF
236 !
237  CASE('ICE_STO')
238  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
239  !* number of tiles
240  CALL open_aux_io_surf(&
241  hfilepgd,hfilepgdtype,'NATURE')
242  yrecfm='PATCH_NUMBER'
243  CALL read_surf(&
244  hfilepgdtype,yrecfm,ipatch,iresp)
245  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
246  CALL open_aux_io_surf(&
247  hfile,hfiletype,'NATURE')
248  yrecfm='GLACIER'
249  CALL read_surf(&
250  hfiletype,yrecfm,gglacier,iresp)
251  ALLOCATE(pfield(ini,1,ipatch))
252  pfield(:,:,:) = 0.0
253  IF(gglacier)THEN
254  yrecfm = 'ICE_STO'
255  CALL read_surf(&
256  hfiletype,yrecfm,pfield(:,1,:),iresp,hdir='A')
257  ENDIF
258  CALL close_aux_io_surf(hfile,hfiletype)
259  DO jpatch=1,SIZE(pfield,3)
260  WHERE (zmask(:)==0.) pfield(:,1,jpatch) = xundef
261  ENDDO
262 !
263  CASE default
264  CALL abor1_sfx('PREP_ISBA_EXTERN: '//trim(hsurf)//" initialization not implemented !")
265 !
266 END SELECT
267 !
268 DEALLOCATE(zmask)
269 !
270 !---------------------------------------------------------------------------
271 !
272 !* 6. End of IO
273 ! ---------
274 !
275 IF (lhook) CALL dr_hook('PREP_ISBA_EXTERN',1,zhook_handle)
276 !
277 !---------------------------------------------------------------------------
278 !---------------------------------------------------------------------------
279 END SUBROUTINE prep_isba_extern
subroutine close_aux_io_surf(HFILE, HFILETYPE)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine open_aux_io_surf(HFILE, HFILETYPE, HMASK)
subroutine read_extern_isba(U, DTCO, I, HFILE, HFILETYPE, HFILEPGD, HFILEPGDTYPE, KLUOUT, KNI, HFIELD, HNAME, PFIELD, PDEPTH, OKEY)
subroutine prep_isba_extern(DTCO, I, U, HPROGRAM, HSURF, HFILE, HFILETYPE, HFILEPGD, HFILEPGDTYPE, KLUOUT, PFIELD, OKEY)
subroutine prep_grid_extern(HFILETYPE, KLUOUT, HGRIDTYPE, HINTERP_TYPE, KNI)