SURFEX v8.1
General documentation of Surfex
prep_teb_greenroof_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_teb_greenroof_extern (DTCO, IO, U, GCP, &
7  HPROGRAM,HSURF,HFILE,HFILETYPE,HFILEPGD,HFILEPGDTYPE,KLUOUT,KPATCH,PFIELD)
8 ! #################################################################################
9 !
10 !!**** *PREP_TEB_GREENROOF_EXTERN* - initializes ISBA fields from operational GRIB
11 !!
12 !! PURPOSE
13 !! -------
14 !
15 !!** METHOD
16 !! ------
17 !! Based on "prep_teb_garden_extern"
18 !!
19 !! REFERENCE
20 !! ---------
21 !!
22 !!
23 !! AUTHOR
24 !! ------
25 !! A. Lemonsu & C. de Munck
26 !!
27 !! MODIFICATIONS
28 !! -------------
29 !! Original 07/2011
30 !!------------------------------------------------------------------
31 !
34 USE modd_surf_atm_n, ONLY : surf_atm_t
36 !
37 USE modd_surfex_mpi, ONLY : nrank, npio
38 !
40 !
42 !
43 USE modi_prep_grid_extern
46 USE modi_open_aux_io_surf
47 USE modi_close_aux_io_surf
48 USE modi_read_teb_patch
49 USE modi_town_presence
50 USE modi_make_choice_array
51 !
53 USE modd_prep_teb_greenroof, ONLY : xgrid_soil, xwr_def
54 USE modd_data_cover_par, ONLY : nvegtype
55 USE modd_surf_par, ONLY : xundef
56 !
57 USE yomhook ,ONLY : lhook, dr_hook
58 USE parkind1 ,ONLY : jprb
59 !
60 USE modi_put_on_all_vegtypes
61 !
62 IMPLICIT NONE
63 !
64 !* 0.1 declarations of arguments
65 !
66 !
67 TYPE(data_cover_t), INTENT(INOUT) :: DTCO
68 TYPE(isba_options_t), INTENT(INOUT) :: IO
69 TYPE(surf_atm_t), INTENT(INOUT) :: U
70 TYPE(grid_conf_proj_t),INTENT(INOUT) :: GCP
71 !
72  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! program calling surf. schemes
73  CHARACTER(LEN=7), INTENT(IN) :: HSURF ! type of field
74  CHARACTER(LEN=28), INTENT(IN) :: HFILE ! name of file
75  CHARACTER(LEN=6), INTENT(IN) :: HFILETYPE ! type of input file
76  CHARACTER(LEN=28), INTENT(IN) :: HFILEPGD ! name of file
77  CHARACTER(LEN=6), INTENT(IN) :: HFILEPGDTYPE ! type of input file
78 INTEGER, INTENT(IN) :: KLUOUT ! logical unit of output listing
79 INTEGER, INTENT(IN) :: KPATCH
80 REAL,DIMENSION(:,:,:), POINTER :: PFIELD ! field to interpolate horizontally (on final soil grid)
81 !
82 !* 0.2 declarations of local variables
83 !
84  CHARACTER(LEN=12) :: YRECFM ! Name of the article to be read
85 INTEGER :: IRESP ! reading return code
86 INTEGER :: INI ! total 1D dimension
87 INTEGER :: IPATCH ! number of patch
88 !
89 REAL, DIMENSION(:,:,:), POINTER :: ZFIELD ! field read on initial MNH vertical soil grid, all patches
90 REAL, DIMENSION(:,:), POINTER :: ZFIELD1 ! field read on initial MNH vertical soil grid, one patch
91 REAL, DIMENSION(:,:,:), POINTER :: ZD ! depth of field in the soil
92 REAL, DIMENSION(:,:), POINTER :: ZD1 ! depth of field in the soil, one patch
93 REAL, DIMENSION(:,:), ALLOCATABLE :: ZOUT !
94  CHARACTER(LEN=12) :: YSURF ! type of field
95  CHARACTER(LEN=3) :: YPATCH ! indentificator for TEB patch
96 INTEGER :: JPATCH ! loop counter for patch
97 INTEGER :: ITEB_PATCH ! number of TEB patches in file
98 INTEGER :: IVERSION ! SURFEX version
99 INTEGER :: IBUGFIX ! SURFEX bug version
100 LOGICAL :: GTEB ! flag if TEB fields are present
101 LOGICAL :: GOLD_NAME ! old name flag for temperatures
102 LOGICAL :: GGREENROOF ! T if gardens are present in the file
103 LOGICAL :: GDIM
104 !
105 REAL(KIND=JPRB) :: ZHOOK_HANDLE
106 !
107 !------------------------------------------------------------------------------
108 !
109 !* 1. Preparation of IO for reading in the file
110 ! -----------------------------------------
111 !
112 !* Note that all points are read, even those without physical meaning.
113 ! These points will not be used during the horizontal interpolation step.
114 ! Their value must be defined as XUNDEF.
115 !
116 IF (lhook) CALL dr_hook('PREP_TEB_GREENROOF_EXTERN',0,zhook_handle)
117 !
118  CALL open_aux_io_surf(hfilepgd,hfilepgdtype,'FULL ')
119 !
120 !* reading of version of the file being read
121  CALL read_surf(hfilepgdtype,'VERSION',iversion,iresp)
122  CALL read_surf(hfilepgdtype,'BUG',ibugfix,iresp)
123 gold_name=(iversion<7 .OR. (iversion==7 .AND. ibugfix<3))
124 !
125 !------------------------------------------------------------------------------
126 !
127 !* 2. Reading of grid
128 ! ---------------
129 !
130  CALL prep_grid_extern(gcp,hfilepgdtype,kluout,cingrid_type,cinterp_type,ini)
131 !
132 IF (nrank/=npio) ini = 0
133 !
134 !* reads if TEB fields exist in the input file
135  CALL town_presence(hfilepgdtype,gteb,hdir='-')
136 !
137 IF (gteb) THEN
138  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
139  CALL open_aux_io_surf(hfilepgd,hfilepgdtype,'TOWN ')
140  CALL read_teb_patch(hfilepgd,hfilepgdtype,iversion,ibugfix,iteb_patch,hdir='-')
141  ypatch=' '
142  IF (iteb_patch>1) THEN
143  WRITE(ypatch,fmt='(A,I1,A)') 'T',min(kpatch,iteb_patch),'_'
144  END IF
145 END IF
146 !
147  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
148 !
149 ! A FAIRE : VERIFIER QUE LES MODIFS DES PATCH/GTEB/GGREENROOF SONT CORRECTES
150 !---------------------------------------------------------------------------------------
151 !
152 !* 3. Transformation into physical quantity to be interpolated
153 ! --------------------------------------------------------
154 !
155 SELECT CASE(hsurf)
156 !
157 !* 3. Orography
158 ! ---------
159 !
160  CASE('ZS ')
161  ALLOCATE(pfield(ini,1,1))
162  yrecfm='ZS'
163  CALL open_aux_io_surf(hfilepgd,hfilepgdtype,'TOWN ')
164  CALL read_surf(hfilepgdtype,yrecfm,pfield(:,1,1),iresp,hdir='A')
165  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
166 !
167 !--------------------------------------------------------------------------
168 !
169 !
170 !* 3.1 Profile of temperature, water or ice in the soil
171 !
172  CASE('TG ','WG ','WGI ')
173 !* choice if one reads garden fields (if present) or ISBA fields
174  CALL open_aux_io_surf(hfilepgd,hfilepgdtype,'TOWN ')
175  ggreenroof = .false.
176  IF (gteb) CALL read_surf(hfilepgdtype,'LGREENROOF',ggreenroof,iresp,hdir='-')
177  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
178  IF (ggreenroof) THEN
179  ysurf = 'GR_'//hsurf(1:3)
180  ysurf=ypatch//ysurf
181  ELSE
182  ysurf = hsurf
183  END IF
184  ysurf=adjustl(ysurf)
185 !* reading of the profile and its depth definition
186  CALL read_extern_isba(u, dtco, gcp, io, hfile,hfiletype,hfilepgd,hfilepgdtype,kluout,ini,&
187  hsurf,ysurf,zfield,zd)
188 !
189  IF (nrank==npio) THEN
190 
191  ALLOCATE(zfield1(SIZE(zfield,1),SIZE(zfield,2)))
192  ALLOCATE(zd1(SIZE(zfield,1),SIZE(zfield,2)))
193  ALLOCATE(zout(SIZE(zfield,1),SIZE(xgrid_soil)))
194  ALLOCATE(pfield(SIZE(zfield,1),SIZE(xgrid_soil),SIZE(zfield,3)))
195  DO jpatch=1,SIZE(zfield,3)
196  zfield1(:,:)=zfield(:,:,jpatch)
197  zd1(:,:)=zd(:,:,jpatch)
198  CALL interp_grid_nat(zd1,zfield1,xgrid_soil,zout)
199  pfield(:,:,jpatch)=zout(:,:)
200  END DO
201  DEALLOCATE(zfield)
202  DEALLOCATE(zout)
203  DEALLOCATE(zfield1)
204  DEALLOCATE(zd)
205 
206  ENDIF
207 !
208 !--------------------------------------------------------------------------
209 !
210 !* 3.4 Water content intercepted on leaves, LAI
211 !
212  CASE('WR ')
213  !* choice if one reads garden fields (if present) or ISBA fields
214  CALL open_aux_io_surf(hfilepgd,hfilepgdtype,'TOWN ')
215  ggreenroof = .false.
216  IF (gteb) CALL read_surf(hfilepgdtype,'LGREENROOF',ggreenroof,iresp,hdir='-')
217  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
218  IF (ggreenroof) THEN
219  ipatch = 1
220  yrecfm = 'GR_WR'
221  yrecfm=ypatch//yrecfm
222  CALL open_aux_io_surf(hfile,hfiletype,'TOWN ')
223  ELSE
224  yrecfm = 'PATCH_NUMBER'
225  ipatch = 0
226  CALL open_aux_io_surf(hfilepgd,hfilepgdtype,'NATURE')
227  CALL read_surf(hfilepgdtype,yrecfm,ipatch,iresp,hdir='-')
228  CALL close_aux_io_surf(hfilepgd,hfilepgdtype)
229  CALL open_aux_io_surf(hfile,hfiletype,'NATURE')
230  yrecfm = 'WR'
231  END IF
232 
233  CALL read_surf(hfiletype,'VERSION',iversion,iresp)
234  CALL read_surf(hfiletype,'BUG',ibugfix,iresp)
235  gdim = (iversion>8 .OR. iversion==8 .AND. ibugfix>0)
236  IF (gdim) CALL read_surf(hfiletype,'SPLIT_PATCH',gdim,iresp)
237  yrecfm=adjustl(yrecfm)
238  ALLOCATE(zfield(ini,1,ipatch))
239  IF (ggreenroof) THEN
240  CALL read_surf(hfiletype,yrecfm,zfield(:,1,1),iresp,hdir='E')
241  ELSE
242  CALL make_choice_array(hfiletype, ipatch, gdim, yrecfm, zfield(:,1,:),hdir='E')
243  ENDIF
244  CALL close_aux_io_surf(hfile,hfiletype)
245  IF (ipatch/=1) THEN
246  ALLOCATE(pfield(ini,1,nvegtype))
247  CALL put_on_all_vegtypes(ini,1,ipatch,nvegtype,zfield,pfield)
248  ELSE
249  ALLOCATE(pfield(ini,1,1))
250  pfield(:,:,:) = zfield(:,:,:)
251  ENDIF
252  DEALLOCATE(zfield)
253 !
254  CASE('LAI ')
255  ALLOCATE(pfield(ini,1,1))
256  pfield(:,:,:) = xundef
257 !
258 END SELECT
259 !
260 !
261 !---------------------------------------------------------------------------
262 !
263 !* 6. End of IO
264 ! ---------
265 !
266 IF (lhook) CALL dr_hook('PREP_TEB_GREENROOF_EXTERN',1,zhook_handle)
267 !
268 !---------------------------------------------------------------------------
269 !---------------------------------------------------------------------------
270 END SUBROUTINE prep_teb_greenroof_extern
character(len=10) cingrid_type
Definition: modd_prep.F90:39
subroutine make_choice_array(HPROGRAM, KNPATCH, ODIM, HRECFM, PWORK, HDIR, KPATCH)
character(len=6) cinterp_type
Definition: modd_prep.F90:40
subroutine close_aux_io_surf(HFILE, HFILETYPE)
subroutine town_presence(HFILETYPE, OTEB, HDIR)
subroutine prep_grid_extern(GCP, HFILETYPE, KLUOUT, HGRIDTYPE, HINTER
subroutine put_on_all_vegtypes(KNI, KLAYER, KPATCH, KVEGTYPE, PFIELD_P
real, parameter xundef
integer, parameter jprb
Definition: parkind1.F90:32
subroutine read_extern_isba(U, DTCO, GCP, IO, HFILE, HFILETYPE, HFILEPGD, HFILEPGDTYPE, KLUOUT, KNI, HFIELD, HNAME, PFIELD, PDEPTH, OKEY)
logical lhook
Definition: yomhook.F90:15
subroutine read_teb_patch(HFILEPGD, HFILEPGDTYPE, KVERSION, KBUGFIX,
subroutine prep_teb_greenroof_extern(DTCO, IO, U, GCP, HPROGRAM, HSURF, HFILE, HFILETYPE, HFILEPGD, HFILEPGDTYPE, KLUOUT, KPATCH, PFIELD)
subroutine open_aux_io_surf(HFILE, HFILETYPE, HMASK, HDIR)