Beginning of open source history
[MNH-git_open_source-lfs.git] / src / SURFEX / init_tebn.F90
1 !     #############################################################
2       SUBROUTINE INIT_TEB_n     (HPROGRAM,HINIT,                            &
3                                  KI,KSV,KSW,                                &
4                                  HSV,PCO2,PRHOA,                            &
5                                  PZENITH,PAZIM,PSW_BANDS,PDIR_ALB,PSCA_ALB, &
6                                  PEMIS,PTSRAD,                              &
7                                  KYEAR, KMONTH,KDAY, PTIME,                 &
8                                  HATMFILE,HATMFILETYPE,                     &
9                                  HTEST                                      )  
10 !     #############################################################
11 !
12 !!****  *INIT_TEB_n* - routine to initialize TEB
13 !!
14 !!    PURPOSE
15 !!    -------
16 !!
17 !!**  METHOD
18 !!    ------
19 !!
20 !!    EXTERNAL
21 !!    --------
22 !!
23 !!
24 !!    IMPLICIT ARGUMENTS
25 !!    ------------------
26 !!
27 !!    REFERENCE
28 !!    ---------
29 !!
30 !!
31 !!    AUTHOR
32 !!    ------
33 !!      V. Masson   *Meteo France*      
34 !!
35 !!    MODIFICATIONS
36 !!    -------------
37 !!      Original    01/2003
38 !!      G. Pigeon   09/2012: add ROUGH_WALL/ROUGH_ROOF/CH_BEM for conv. coef.
39 !-------------------------------------------------------------------------------
40 !
41 !*       0.    DECLARATIONS
42 !              ------------
43 !
44 USE MODD_IO_SURF_ASC,ONLY: CMASK
45 USE MODD_SNOW_PAR, ONLY : XEMISSN
46 !
47 USE MODD_READ_NAMELIST, ONLY : LNAM_READ
48
49 USE MODD_TEB_n,           ONLY: LGARDEN, LGREENROOF,                                     &
50                                 XTSTEP, XOUT_TSTEP, TTIME, XCOVER,                       &
51                                 XH_TRAFFIC, XLE_TRAFFIC, XH_INDUSTRY, XLE_INDUSTRY,      &
52                                 XZ0_TOWN, XBLD, XGARDEN, XROAD_DIR, XGREENROOF,          &
53                                 XROAD, XBLD_HEIGHT, XWALL_O_HOR, XCAN_HW_RATIO,          &
54                                 XROAD_O_GRND, XGARDEN_O_GRND, XWALL_O_GRND, XWALL_O_BLD, &
55                                 XALB_ROOF, XEMIS_ROOF, XHC_ROOF,XTC_ROOF, XD_ROOF,       &
56                                 XALB_ROAD, XEMIS_ROAD, XHC_ROAD,XTC_ROAD, XD_ROAD,       &
57                                 XALB_WALL, XEMIS_WALL, XHC_WALL,XTC_WALL, XD_WALL,       &
58                                 XSVF_ROAD, XSVF_GARDEN, XSVF_WALL,                       &
59                                 TSNOW_ROOF, TSNOW_ROAD,                                  &
60                                 NROOF_LAYER, NROAD_LAYER, NWALL_LAYER,                   &
61                                 XT_ROOF, XT_ROAD, XT_WALL_A, XT_WALL_B, CZ0H,            &
62                                 CROAD_DIR, CWALL_OPT,                                    &
63                                 XT_CANYON, XQ_CANYON,                                    &
64                                 XAC_ROOF, XAC_ROAD, XAC_WALL, XAC_TOP,                   &
65                                 XAC_ROOF_WAT, XAC_ROAD_WAT,                              &
66                                 XQSAT_ROOF, XQSAT_ROAD, XDELT_ROOF, XDELT_ROAD,          &
67                                 NTEB_PATCH, XTEB_PATCH, CBEM, CCH_BEM,                   &
68                                 XROUGH_ROOF, XROUGH_WALL
69
70 USE MODD_BEM_n,           ONLY: NFLOOR_LAYER, XHC_FLOOR, XTC_FLOOR, XD_FLOOR,            &
71                                 XTCOOL_TARGET, XTHEAT_TARGET, XF_WASTE_CAN, XEFF_HEAT,   &
72                                 XQIN, XQIN_FRAD, XSHGC, XSHGC_SH, XU_WIN, XGR,           &
73                                 XFLOOR_HEIGHT, XINF, XQIN_FLAT, XHR_TARGET, XV_VENT,     &
74                                 XCAP_SYS_HEAT, XAUX_MAX, XCAP_SYS_RAT, XT_ADP,           &
75                                 XM_SYS_RAT, XCOP_RAT, XT_SIZE_MAX, XT_SIZE_MIN,          &
76                                 CCOOL_COIL, CHEAT_COIL, XF_WATER_COND, LSHAD_DAY,        &
77                                 LNATVENT_NIGHT, LSHADE, XSHADE, CNATVENT, XNATVENT,      &
78                                 LAUTOSIZE, XT_WIN1, XALB_WIN, XABS_WIN, XUGG_WIN,        &
79                                 XN_FLOOR, XGLAZ_O_BLD, XMASS_O_BLD, XFLOOR_HW_RATIO,     &
80                                 XF_FLOOR_MASS, XF_FLOOR_WALL, XF_FLOOR_WIN,              &
81                                 XF_FLOOR_ROOF, XF_WALL_FLOOR, XF_WALL_MASS,              &
82                                 XF_WALL_WIN, XF_WIN_FLOOR, XF_WIN_MASS, XF_WIN_WALL,     &
83                                 XF_MASS_FLOOR, XF_MASS_WALL, XF_MASS_WIN, XTRAN_WIN
84
85 USE MODD_TEB_VEG_n,       ONLY: CC1DRY, CSOILFRZ, CDIFSFCOND, CSNOWRES,                  &
86                                 CCPSURF, XCGMAX, CKSAT, CTOPREG,                         &
87                                 CRAIN, CHORT,                                            &
88                                 LCANOPY_DRAG, LVEGUPD
89
90 USE MODD_CH_TEB_n,        ONLY: XDEP, CCH_DRY_DEP, CSV, CCH_NAMES,                       &
91                                 NBEQ, NSV_CHSBEG, NSV_CHSEND,                            &
92                                 NAEREQ, NSV_AERBEG, NSV_AEREND, CAER_NAMES,              &
93                                 NSV_DSTBEG, NSV_DSTEND, NDSTEQ, CDSTNAMES,               &
94                                 NSV_SLTBEG, NSV_SLTEND, NSLTEQ, CSLTNAMES  
95
96
97 USE MODD_CHS_AEROSOL,     ONLY: LVARSIGI, LVARSIGJ
98 USE MODD_DST_SURF,        ONLY: LVARSIG_DST, NDSTMDE, NDST_MDEBEG, LRGFIX_DST 
99 USE MODD_SLT_SURF,        ONLY: LVARSIG_SLT, NSLTMDE, NSLT_MDEBEG, LRGFIX_SLT
100 USE MODD_DIAG_TEB_n,      ONLY: N2M, LSURF_BUDGET, LRAD_BUDGET, XDIAG_TSTEP,             &
101                                   LPGD, LPGD_FIX, L2M_MIN_ZS, LCOEF, LSURF_VARS  
102 USE MODD_DIAG_MISC_TEB_n, ONLY: LSURF_MISC_BUDGET,                                       &
103                                   LSURF_DIAG_ALBEDO, LSURF_EVAP_BUDGET  
104 USE MODD_DIAG_UTCI_TEB_n, ONLY: LUTCI
105 USE MODD_SURF_PAR,        ONLY: XUNDEF, NUNDEF
106 !
107 USE MODD_TEB_GARDEN_n,    ONLY : XLAI_GARDEN => XLAI
108 USE MODD_TEB_GREENROOF_n, ONLY : XLAI_GREENROOF => XLAI, NLAYER_GR
109 !
110 USE MODI_INIT_IO_SURF_n
111 USE MODI_DEFAULT_CH_DEP
112 USE MODI_DEFAULT_TEB
113 USE MODI_DEFAULT_DIAG_TEB
114 USE MODI_READ_DEFAULT_TEB_n
115 USE MODI_READ_TEB_CONF_n
116 USE MODI_PREP_CTRL_TEB
117 USE MODI_READ_TEB_n
118 USE MODI_READ_PGD_TEB_n
119 USE MODI_CONVERT_TEB
120 USE MODI_CONVERT_PATCH_TEB
121 USE MODI_INIT_SNOW_LW
122 USE MODI_AVERAGED_TSRAD_TEB
123 USE MODI_AVERAGED_ALBEDO_TEB
124 USE MODI_DIAG_TEB_INIT_n
125 USE MODI_DIAG_MISC_TEB_INIT_n
126 USE MODI_END_IO_SURF_n
127 USE MODI_GET_LUOUT
128 USE MODI_READ_SURF
129 USE MODI_READ_PREP_TEB_SNOW
130 USE MODI_READ_TEB_DATE
131 USE MODI_READ_NAM_PREP_TEB_n
132 USE MODI_INIT_CHEMICAL_n
133 USE MODI_GARDEN_PROPERTIES
134 USE MODI_HVAC_AUTOSIZE
135 USE MODI_GOTO_TEB
136 !
137 USE MODI_INIT_TEB_GARDEN_n
138 USE MODI_INIT_TEB_GARDEN_PGD_n
139 USE MODI_INIT_TEB_VEG_OPTIONS_n
140 USE MODI_TEB_MORPHO
141 USE MODI_INIT_BEM_n
142 USE MODI_INIT_TEB_GREENROOF_n
143 USE MODI_INIT_TEB_GREENROOF_PGD_n
144 USE MODI_GREENROOF_PROPERTIES
145 !
146 USE MODI_READ_COVER_GARDEN
147 USE MODI_WRITE_COVER_TEX_TEB
148 USE MODI_ABOR1_SFX
149 USE MODI_READ_TEB_CANOPY_n
150 USE MODI_SET_SURFEX_FILEIN
151 !
152 USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
153 USE PARKIND1  ,ONLY : JPRB
154 !
155 IMPLICIT NONE
156 !
157 !*       0.1   Declarations of arguments
158 !              -------------------------
159 !
160  CHARACTER(LEN=6),                   INTENT(IN)  :: HPROGRAM    ! program calling surf. schemes
161  CHARACTER(LEN=3),                   INTENT(IN)  :: HINIT       ! choice of fields to initialize
162 INTEGER,                            INTENT(IN)  :: KI          ! number of points
163 INTEGER,                            INTENT(IN)  :: KSV         ! number of scalars
164 INTEGER,                            INTENT(IN)  :: KSW         ! number of short-wave spectral bands
165  CHARACTER(LEN=6), DIMENSION(KSV),   INTENT(IN)  :: HSV         ! name of all scalar variables
166 REAL,             DIMENSION(KI),    INTENT(IN)  :: PCO2        ! CO2 concentration (kg/m3)
167 REAL,             DIMENSION(KI),    INTENT(IN)  :: PRHOA       ! air density
168 REAL,             DIMENSION(KI),    INTENT(IN)  :: PZENITH     ! solar zenithal angle
169 REAL,             DIMENSION(KI),    INTENT(IN)  :: PAZIM       ! solar azimuthal angle (rad from N, clock)
170 REAL,             DIMENSION(KSW),   INTENT(IN)  :: PSW_BANDS   ! middle wavelength of each band
171 REAL,             DIMENSION(KI,KSW),INTENT(OUT) :: PDIR_ALB    ! direct albedo for each band
172 REAL,             DIMENSION(KI,KSW),INTENT(OUT) :: PSCA_ALB    ! diffuse albedo for each band
173 REAL,             DIMENSION(KI),    INTENT(OUT) :: PEMIS       ! emissivity
174 REAL,             DIMENSION(KI),    INTENT(OUT) :: PTSRAD      ! radiative temperature
175 INTEGER,                            INTENT(IN)  :: KYEAR       ! current year (UTC)
176 INTEGER,                            INTENT(IN)  :: KMONTH      ! current month (UTC)
177 INTEGER,                            INTENT(IN)  :: KDAY        ! current day (UTC)
178 REAL,                               INTENT(IN)  :: PTIME       ! current time since
179                                                                !  midnight (UTC, s)
180 !
181  CHARACTER(LEN=28),                  INTENT(IN)  :: HATMFILE    ! atmospheric file name
182  CHARACTER(LEN=6),                   INTENT(IN)  :: HATMFILETYPE! atmospheric file type
183  CHARACTER(LEN=2),                   INTENT(IN)  :: HTEST       ! must be equal to 'OK'
184 !
185 !*       0.2   Declarations of local variables
186 !              -------------------------------
187 !
188 INTEGER                         :: ILU              ! sizes of TEB arrays
189 INTEGER                         :: ILUOUT           ! unit of output listing file
190 INTEGER                         :: IRESP            ! return code
191 !
192 INTEGER                         :: ISWB             ! number of shortwave spectral bands
193 INTEGER                         :: JSWB             ! loop on shortwave spectral bands
194 !
195 REAL                            :: ZDEF_ROAD_DIR    ! default raod direction
196 REAL, DIMENSION(:), ALLOCATABLE :: ZDIR_ALB         ! direct town albedo
197 REAL, DIMENSION(:), ALLOCATABLE :: ZSCA_ALB         ! diffuse town albedo
198 !
199 !              local variables for urban green areas
200 REAL, DIMENSION(KI,KSW)         :: ZDIR_SW          ! direct  SW for each band
201 REAL, DIMENSION(KI,KSW)         :: ZSCA_SW          ! diffuse SW for each band
202 REAL, DIMENSION(KI)             :: ZEMIS_GARDEN     ! emissivity
203 REAL, DIMENSION(KI)             :: ZALB_GARDEN      ! albedo
204 REAL, DIMENSION(KI)             :: ZTS_GARDEN       ! radiative temperature
205 !
206 !              local variables for urban greenroofs
207 REAL, DIMENSION(KI)             :: ZEMIS_GREENROOF     ! emissivity
208 REAL, DIMENSION(KI)             :: ZALB_GREENROOF      ! albedo
209 REAL, DIMENSION(KI)             :: ZTS_GREENROOF       ! radiative temperature
210 !
211 INTEGER                         :: JPATCH
212 INTEGER                         :: IVERSION, IBUGFIX
213
214 REAL(KIND=JPRB) :: ZHOOK_HANDLE
215 !-------------------------------------------------------------------------------
216 !
217 !         Initialisation for IO
218 !
219 IF (LHOOK) CALL DR_HOOK('INIT_TEB_N',0,ZHOOK_HANDLE)
220  CALL GET_LUOUT(HPROGRAM,ILUOUT)
221 !
222 IF (HTEST/='OK') THEN
223   CALL ABOR1_SFX('INIT_TEBN: FATAL ERROR DURING ARGUMENT TRANSFER')
224 END IF
225 !
226 !         Other little things
227 !
228 PDIR_ALB = XUNDEF
229 PSCA_ALB = XUNDEF
230 PEMIS    = XUNDEF
231 PTSRAD   = XUNDEF
232 !
233 LSURF_DIAG_ALBEDO = .FALSE.
234 LSURF_EVAP_BUDGET = .FALSE.
235 !
236 IF (LNAM_READ) THEN
237  !
238  !*       0.     Defaults
239  !               --------
240  !
241  !        0.1. Hard defaults
242  !      
243  CALL DEFAULT_TEB(CZ0H,XTSTEP,XOUT_TSTEP, CCH_BEM)
244  CALL DEFAULT_CH_DEP(CCH_DRY_DEP)
245  CALL DEFAULT_DIAG_TEB(N2M,LSURF_BUDGET,L2M_MIN_ZS,LRAD_BUDGET,LCOEF,LSURF_VARS, &
246                        LSURF_MISC_BUDGET,LUTCI,LPGD,LPGD_FIX,XDIAG_TSTEP)  
247 !
248 ENDIF
249 !
250 !        0.2. Defaults from file header
251 !    
252  CALL READ_DEFAULT_TEB_n(HPROGRAM)
253 !
254 !*       1.     Reading of configuration:
255 !               -------------------------
256 !
257  CALL READ_TEB_CONF_n(HPROGRAM)
258 !
259 !* initialization of snow scheme
260 !
261 IF (HINIT=='PRE') THEN
262   DO JPATCH=1,NTEB_PATCH
263     CALL GOTO_TEB(JPATCH)
264     CALL READ_PREP_TEB_SNOW(HPROGRAM,TSNOW_ROOF%SCHEME,TSNOW_ROOF%NLAYER, &
265                                      TSNOW_ROAD%SCHEME,TSNOW_ROAD%NLAYER)
266   END DO
267 ENDIF
268 !
269 !*       2.     Cover fields and grid:
270 !               ---------------------
271 !* date
272 !
273 SELECT CASE (HINIT)
274   CASE ('PGD')
275     TTIME%TDATE%YEAR = NUNDEF
276     TTIME%TDATE%MONTH= NUNDEF
277     TTIME%TDATE%DAY  = NUNDEF
278     TTIME%TIME       = XUNDEF
279
280   CASE ('PRE')
281     CALL PREP_CTRL_TEB(N2M,LSURF_BUDGET,L2M_MIN_ZS,LRAD_BUDGET,LCOEF,LSURF_VARS,&
282                          LSURF_EVAP_BUDGET,LSURF_MISC_BUDGET,LUTCI,ILUOUT )           
283     IF (LNAM_READ) CALL READ_NAM_PREP_TEB_n(HPROGRAM)   
284     CALL READ_TEB_DATE(HPROGRAM,HINIT,ILUOUT,HATMFILE,HATMFILETYPE,KYEAR,KMONTH,KDAY,PTIME,TTIME)
285
286   CASE DEFAULT
287     CALL INIT_IO_SURF_n(HPROGRAM,'TOWN  ','TEB   ','READ ')
288     CALL READ_SURF(HPROGRAM,'DTCUR',TTIME,IRESP)
289     CALL END_IO_SURF_n(HPROGRAM)
290 END SELECT
291 !
292 !-----------------------------------------------------------------------------------------------------
293 ! READ PGD FILE
294 !-----------------------------------------------------------------------------------------------------
295 !
296 !         Initialisation for IO
297 !
298  CALL SET_SURFEX_FILEIN(HPROGRAM,'PGD ') ! change input file name to pgd name
299  CALL INIT_IO_SURF_n(HPROGRAM,'TOWN  ','TEB   ','READ ')
300 !
301  CALL READ_SURF(HPROGRAM,'VERSION',IVERSION,IRESP)
302  CALL READ_SURF(HPROGRAM,'BUG',IBUGFIX,IRESP)
303 !
304 !         Reading of the fields
305 !
306  CALL READ_COVER_GARDEN(HPROGRAM,LGARDEN)
307 !
308  CALL READ_PGD_TEB_n(HPROGRAM)
309 !
310  CALL END_IO_SURF_n(HPROGRAM)
311
312 !*        Fraction of each patch in the grid mesh
313 !
314 ILU = SIZE(XCOVER,1)
315 !
316 ALLOCATE(XTEB_PATCH(ILU,NTEB_PATCH))
317  CALL CONVERT_TEB(XCOVER,XTEB_PATCH)
318 !
319  CALL SET_SURFEX_FILEIN(HPROGRAM,'PREP') ! restore input file name
320  CALL INIT_IO_SURF_n(HPROGRAM,'TOWN  ','TEB   ','READ ')
321 !
322  CALL READ_SURF(HPROGRAM,'VERSION',IVERSION,IRESP)
323  CALL READ_SURF(HPROGRAM,'BUG',IBUGFIX,IRESP)
324 !
325 !* reads what is the option defined for road orientations & walls
326 !
327 IF (HINIT=='ALL') THEN
328   CROAD_DIR='UNIF'
329   CWALL_OPT='UNIF'
330   IF (IVERSION>7 .OR. (IVERSION==7 .AND. IBUGFIX>=3)) THEN
331     CALL READ_SURF(HPROGRAM,'ROAD_DIR',CROAD_DIR,IRESP)
332     CALL READ_SURF(HPROGRAM,'WALL_OPT',CWALL_OPT,IRESP)
333   END IF
334 END IF
335  CALL END_IO_SURF_n(HPROGRAM)
336 !-----------------------------------------------------------------------------------
337 !
338 !*              LOOP ON TEB PATCHES
339 !               -------------------
340 !
341 DO JPATCH=1,NTEB_PATCH
342
343   CALL GOTO_TEB(JPATCH)
344   !-----------------------------------------------------------------------------------
345   !
346   !*       3.     Physiographic data fields from land cover:
347   !               -----------------------------------------
348   !
349   ALLOCATE(XZ0_TOWN     (ILU))
350   ALLOCATE(XALB_ROOF    (ILU))
351   ALLOCATE(XEMIS_ROOF   (ILU))
352   ALLOCATE(XALB_ROAD    (ILU))
353   ALLOCATE(XEMIS_ROAD   (ILU))
354   ALLOCATE(XALB_WALL    (ILU))
355   ALLOCATE(XEMIS_WALL   (ILU))
356   ALLOCATE(XBLD         (ILU))
357   ALLOCATE(XROAD_DIR    (ILU))
358   ALLOCATE(XROAD        (ILU))
359   ALLOCATE(XBLD_HEIGHT  (ILU))
360   ALLOCATE(XWALL_O_HOR  (ILU))
361   ALLOCATE(XCAN_HW_RATIO(ILU))
362   ALLOCATE(XROAD_O_GRND(ILU))
363   ALLOCATE(XGARDEN_O_GRND(ILU))
364   ALLOCATE(XWALL_O_GRND(ILU))
365   ALLOCATE(XWALL_O_BLD(ILU))
366   ALLOCATE(XH_TRAFFIC   (ILU))
367   ALLOCATE(XLE_TRAFFIC  (ILU))
368   ALLOCATE(XH_INDUSTRY  (ILU))
369   ALLOCATE(XLE_INDUSTRY (ILU))
370   ALLOCATE(XHC_ROOF     (ILU,NROOF_LAYER))
371   ALLOCATE(XTC_ROOF     (ILU,NROOF_LAYER))
372   ALLOCATE(XD_ROOF      (ILU,NROOF_LAYER))
373   ALLOCATE(XHC_ROAD     (ILU,NROAD_LAYER))
374   ALLOCATE(XTC_ROAD     (ILU,NROAD_LAYER))
375   ALLOCATE(XD_ROAD      (ILU,NROAD_LAYER))
376   ALLOCATE(XHC_WALL     (ILU,NWALL_LAYER))
377   ALLOCATE(XTC_WALL     (ILU,NWALL_LAYER))
378   ALLOCATE(XD_WALL      (ILU,NWALL_LAYER))
379   ALLOCATE(XROUGH_ROOF      (ILU))
380   ALLOCATE(XROUGH_WALL      (ILU))
381   ALLOCATE(XGREENROOF       (ILU))
382   ALLOCATE(XGARDEN          (ILU))
383   !
384   XROAD_DIR(:) = 0.
385   XROAD    (:) = 0.
386   !
387   ZDEF_ROAD_DIR = 0.
388   IF (CROAD_DIR/='UNIF') THEN
389     !* road direction if not specified by the user depends on patch number
390     !  First patch has a Notrh-South road. Other patches have roads spaced by
391     !  regular angles
392     ZDEF_ROAD_DIR = 180. * FLOAT(JPATCH-1) / FLOAT(NTEB_PATCH)
393   END IF
394   !
395   CALL CONVERT_PATCH_TEB(XCOVER, ZDEF_ROAD_DIR,                                  &
396                       PZ0_TOWN=XZ0_TOWN,                                         &
397                       PALB_ROOF=XALB_ROOF,                                       &
398                       PEMIS_ROOF=XEMIS_ROOF,PHC_ROOF=XHC_ROOF,PTC_ROOF=XTC_ROOF, &
399                       PD_ROOF=XD_ROOF,                                           &
400                       PALB_ROAD=XALB_ROAD,                                       &
401                       PEMIS_ROAD=XEMIS_ROAD,PHC_ROAD=XHC_ROAD,PTC_ROAD=XTC_ROAD, &
402                       PD_ROAD=XD_ROAD,                                           &
403                       PALB_WALL=XALB_WALL,                                       &
404                       PEMIS_WALL=XEMIS_WALL,PHC_WALL=XHC_WALL,PTC_WALL=XTC_WALL, &
405                       PD_WALL=XD_WALL,                                           &
406                       PBLD_HEIGHT=XBLD_HEIGHT,                                   &
407                       PWALL_O_HOR=XWALL_O_HOR,PBLD=XBLD, PROAD_DIR=XROAD_DIR,    &
408                       PGARDEN=XGARDEN,                                           &
409                       PH_TRAFFIC=XH_TRAFFIC, PLE_TRAFFIC=XLE_TRAFFIC,            &
410                       PH_INDUSTRY=XH_INDUSTRY, PLE_INDUSTRY=XLE_INDUSTRY,        &
411                       PROUGH_ROOF = XROUGH_ROOF, PROUGH_WALL = XROUGH_WALL,      &
412                       PGREENROOF = XGREENROOF                                    )
413   !
414   IF (.NOT. LGREENROOF .AND. MAXVAL(XGREENROOF)>0. ) THEN !<== A paralleliser pour un stop propre
415     WRITE(ILUOUT,*) 'You choose NOT to have greenroofs, BUT your greenroof fraction is not zero'
416     WRITE(ILUOUT,*) 'Please activate the greenroof option (and rerun the SURFEX suite from the PGD step)'
417     WRITE(ILUOUT,*) 'Or be sure NOT to have any greenroofs in your area'
418     CALL ABOR1_SFX('INIT_TEBN: GREENROOF OPTION NOT ACTIVATED WHILE GREENROOFS ARE PRESENT')
419   ENDIF
420   !-------------------------------------------------------------------------------
421   !
422   !*       5.     Sky-view-factors:
423   !               ----------------
424   !
425   ALLOCATE(XSVF_ROAD  (ILU))
426   ALLOCATE(XSVF_GARDEN(ILU))
427   ALLOCATE(XSVF_WALL  (ILU))
428   !
429   ALLOCATE(XGR          (ILU))
430   ALLOCATE(XALB_WIN     (ILU))
431   ALLOCATE(XF_WASTE_CAN (ILU))
432   !
433   !
434   CALL TEB_MORPHO(HPROGRAM, XBLD, XWALL_O_HOR, XGARDEN, XBLD_HEIGHT, XROAD, XROAD_O_GRND, &
435                 XGARDEN_O_GRND, XWALL_O_GRND, XCAN_HW_RATIO, XSVF_ROAD, XSVF_GARDEN,    &
436                 XSVF_WALL, XZ0_TOWN, XWALL_O_BLD, XH_TRAFFIC, XLE_TRAFFIC               )
437                 !
438   !-------------------------------------------------------------------------------
439   !
440   !*       6.     Building Energy Model
441   !               ---------------------
442   !
443   CALL INIT_BEM_n(ILUOUT)
444   !
445   !-------------------------------------------------------------------------------
446   !
447   !*      7.      Case of urban green areas
448   !               -------------------------
449   !
450   IF (LGARDEN) THEN
451   !
452     CALL SET_SURFEX_FILEIN(HPROGRAM,'PGD ') ! change input file name to pgd name
453     CALL INIT_IO_SURF_n(HPROGRAM,'TOWN  ','TEB   ','READ ')     
454     IF (JPATCH==1) CALL INIT_TEB_VEG_OPTIONS_n(HPROGRAM)
455     CALL INIT_TEB_GARDEN_PGD_n(HPROGRAM,HINIT,(JPATCH==1),KI,KSV,HSV,IVERSION,IBUGFIX,PCO2,PRHOA)
456     ! Case of urban green roofs
457     IF (LGREENROOF) CALL INIT_TEB_GREENROOF_PGD_n(HPROGRAM,HINIT,(JPATCH==1), &
458                                                   KI,KSV,HSV,IVERSION,PCO2,PRHOA)
459     CALL END_IO_SURF_n(HPROGRAM)
460     !
461   ENDIF
462 !-------------------------------------------------------------------------------
463 END DO ! end of loop on TEB patches
464 !-------------------------------------------------------------------------------
465 !
466 !* if only physiographic fields are to be initialized, stop here.
467 !
468  CALL WRITE_COVER_TEX_TEB
469 !
470 IF (HINIT/='ALL') THEN
471   IF (LHOOK) CALL DR_HOOK('INIT_TEB_N',1,ZHOOK_HANDLE)
472   RETURN
473 END IF
474 !
475 !-------------------------------------------------------------------------------
476 !
477 !         Initialisation for IO
478 !
479  CALL SET_SURFEX_FILEIN(HPROGRAM,'PREP') ! restore input file name
480  CALL INIT_IO_SURF_n(HPROGRAM,'TOWN  ','TEB   ','READ ')
481 !
482 !*       9.     Prognostic fields:
483 !               -----------------
484 !
485 !               -------------------------
486 !
487
488 !
489 !*              LOOP ON TEB PATCHES
490 !               -------------------
491 !
492 DO JPATCH=1,NTEB_PATCH
493   CALL GOTO_TEB(JPATCH)
494 !
495 !* TEB fields
496   CALL READ_TEB_n(HPROGRAM,JPATCH)
497 !
498   ALLOCATE(XAC_ROOF    (ILU))
499   ALLOCATE(XAC_ROAD    (ILU))
500   ALLOCATE(XAC_WALL    (ILU))
501   ALLOCATE(XAC_TOP     (ILU))
502   ALLOCATE(XAC_ROOF_WAT(ILU))
503   ALLOCATE(XAC_ROAD_WAT(ILU))
504   ALLOCATE(XQSAT_ROOF  (ILU))
505   ALLOCATE(XQSAT_ROAD  (ILU))
506   ALLOCATE(XDELT_ROOF  (ILU))
507   ALLOCATE(XDELT_ROAD  (ILU))
508 !
509 !* Case of urban green areas
510   IF (LGARDEN) THEN
511 !    CALL SET_SURFEX_FILEIN(HPROGRAM,'PREP') ! change input file name to pgd name
512 !    CALL INIT_IO_SURF_n(HPROGRAM,'TOWN  ','TEB   ','READ ')       
513     CALL INIT_TEB_GARDEN_n(HPROGRAM,HINIT,KI,KSW,PSW_BANDS)
514   ! Case of urban green roofs
515     IF (LGREENROOF) CALL INIT_TEB_GREENROOF_n(HPROGRAM,HINIT,KI,KSV,PSW_BANDS)
516 !    CALL END_IO_SURF_n(HPROGRAM)
517   ENDIF
518 !-------------------------------------------------------------------------------
519 !
520 !*      10.     Infra-red Radiative fields:
521 !               --------------------------
522 !
523 !* snow long-wave properties (not initialized in read_gr_snow)
524 !
525   CALL INIT_SNOW_LW(XEMISSN,TSNOW_ROOF)
526   CALL INIT_SNOW_LW(XEMISSN,TSNOW_ROAD)
527 !
528   IF (LGARDEN) THEN
529     ZDIR_SW=0. ! night as first guess for albedo computation
530     ZSCA_SW=0. !
531     CALL GARDEN_PROPERTIES(ZDIR_SW, ZSCA_SW, PSW_BANDS, KSW,     &
532                            ZTS_GARDEN, ZEMIS_GARDEN, ZALB_GARDEN )      
533   ELSE
534     ZALB_GARDEN = XUNDEF
535     ZEMIS_GARDEN= XUNDEF
536     ZTS_GARDEN  = XUNDEF
537   END IF
538   !
539   IF (LGREENROOF) THEN
540     ZDIR_SW=0. ! night as first guess for albedo computation
541     ZSCA_SW=0. !
542     CALL GREENROOF_PROPERTIES(ZDIR_SW, ZSCA_SW, PSW_BANDS, KSW,              &
543                               ZTS_GREENROOF, ZEMIS_GREENROOF, ZALB_GREENROOF )  
544   ELSE
545     ZALB_GREENROOF  = XUNDEF
546     ZEMIS_GREENROOF = XUNDEF
547     ZTS_GREENROOF   = XUNDEF
548   END IF
549 !
550 !* averaged albedo, emissivity and radiative temperature
551 !
552   CALL AVERAGED_TSRAD_TEB(XEMIS_ROOF,XT_ROOF(:,1),       &
553                         XEMIS_ROAD,XT_ROAD(:,1),       &
554                         XEMIS_WALL,                    &
555                         XT_WALL_A(:,1),                &
556                         XT_WALL_B(:,1),                &
557                         ZEMIS_GARDEN, ZTS_GARDEN,      &
558                         ZEMIS_GREENROOF, ZTS_GREENROOF,&
559                         TSNOW_ROOF,TSNOW_ROAD,         &
560                         XROAD, XGREENROOF, XGARDEN,    &
561                         XBLD,XWALL_O_HOR,              &
562                         XSVF_ROAD,XSVF_WALL,           &
563                         XSVF_GARDEN,                   &
564                         PEMIS,PTSRAD, XT_WIN1,         &
565                         XGR                            )
566 !
567 !
568 !*       9.     Visible and near-infra-red Radiative fields:
569 !               -------------------------------------------
570 !
571   ALLOCATE(ZDIR_ALB(ILU))
572   ALLOCATE(ZSCA_ALB(ILU))
573 !
574   CALL AVERAGED_ALBEDO_TEB(CBEM,CROAD_DIR,CWALL_OPT,PZENITH,PAZIM, &
575                        XBLD, XGARDEN, XROAD_DIR, XROAD, XGREENROOF,&
576                        XWALL_O_HOR, XCAN_HW_RATIO,                 &
577                        XALB_ROOF,                                  &
578                        XALB_ROAD, XSVF_ROAD,                       &
579                        XALB_WALL, XSVF_WALL,                       &
580                        ZALB_GARDEN, XSVF_GARDEN,                   &
581                        ZALB_GREENROOF,                             &
582                        TSNOW_ROOF, TSNOW_ROAD,                     &
583                        XGR, XSHGC, XSHGC_SH, XABS_WIN, XALB_WIN,   &
584                        LSHAD_DAY,                                  &
585                        ZDIR_ALB, ZSCA_ALB, XTRAN_WIN               )  
586
587   ISWB=SIZE(PSW_BANDS)
588   DO JSWB=1,ISWB
589     PDIR_ALB(:,JSWB) = ZDIR_ALB(:)
590     PSCA_ALB(:,JSWB) = ZSCA_ALB(:)
591   END DO
592   !
593   DEALLOCATE(ZDIR_ALB)
594   DEALLOCATE(ZSCA_ALB)
595 !-------------------------------------------------------------------------------
596 !
597 !*      10.     Chemistry /dust
598 !               ---------------
599 !
600   CALL INIT_CHEMICAL_n(ILUOUT, KSV, HSV, NBEQ, CSV, NAEREQ,            &
601                      NSV_CHSBEG, NSV_CHSEND, NSV_AERBEG, NSV_AEREND, &
602                      CCH_NAMES, CAER_NAMES, NDSTEQ, NSV_DSTBEG,      &
603                      NSV_DSTEND, NSLTEQ, NSV_SLTBEG, NSV_SLTEND,     &
604                      HDSTNAMES=CDSTNAMES, HSLTNAMES=CSLTNAMES        )
605 !
606 !* Initialization of dry deposition scheme (chemistry)
607 !
608   IF (NBEQ>0 .AND. CCH_DRY_DEP=='WES89') THEN
609     ALLOCATE(XDEP(ILU,NBEQ))
610   ELSE
611     ALLOCATE(XDEP(0,0))
612   END IF
613 !
614 !-------------------------------------------------------------------------------
615 END DO ! end of loop on patches
616 !-------------------------------------------------------------------------------
617 !
618 !*       7.     Canopy air fields:
619 !               ------------------
620 !
621  CALL READ_TEB_CANOPY_n(HPROGRAM)
622 !
623 !-------------------------------------------------------------------------------
624 !
625 !*      11.     Diagnostics:
626 !               -----------
627 !
628  CALL DIAG_TEB_INIT_n(HPROGRAM,ILU,ISWB)
629 DO JPATCH=1,NTEB_PATCH
630   CALL GOTO_TEB(JPATCH)
631   CALL DIAG_MISC_TEB_INIT_n(HPROGRAM,ILU,ISWB)
632 END DO ! end of loop on patches
633 !
634 !-------------------------------------------------------------------------------
635 !
636 !         End of IO
637 !
638  CALL END_IO_SURF_n(HPROGRAM)
639 IF (LHOOK) CALL DR_HOOK('INIT_TEB_N',1,ZHOOK_HANDLE)
640 !
641 !
642 END SUBROUTINE INIT_TEB_n