0d7a18619a28ce8f0e37a8a04ac08fab28ef0fb1
[MNH-git_open_source-lfs.git] / src / SURFEX / alloc_diag_surf_atmn.F90
1 !SURFEX_LIC Copyright 1994-2014 Meteo-France 
2 !SURFEX_LIC This is part of the SURFEX software governed by the CeCILL-C  licence
3 !SURFEX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SURFEX_LIC for details. version 1.
5 !     #############################################################
6       SUBROUTINE ALLOC_DIAG_SURF_ATM_n(HPROGRAM,KSW)
7 !     #############################################################
8 !
9 !!    AUTHOR
10 !!    ------
11 !!      V. Masson   *Meteo France*      
12 !!
13 !!    MODIFICATIONS
14 !!    -------------
15 !!      Original    01/2004
16 !!      Modified    01/2006 : sea flux parameterization.
17 !!                  08/2009 : TIME_BUDGETC for all Tile
18 !       B. decharme 09/2012 : XQS_TILE not initialize
19 !-------------------------------------------------------------------------------
20 !
21 !*       0.    DECLARATIONS
22 !              ------------
23 !
24 USE MODD_SURF_ATM_n,     ONLY : NSIZE_FULL, TTIME
25 USE MODD_DATA_COVER_PAR, ONLY : NTILESFC
26 USE MODD_SURF_PAR,       ONLY : XUNDEF
27 USE MODD_DIAG_SURF_ATM_n,ONLY : XRN_TILE, XH_TILE, XLE_TILE, XGFLUX_TILE,         &
28                                 XLEI_TILE, XRI_TILE, XCD_TILE, XCH_TILE, XCE_TILE,&
29                                 XT2M_TILE, XTS_TILE, XQ2M_TILE, XHU2M_TILE,       &
30                                 XZON10M_TILE, XMER10M_TILE, XQS_TILE,             &
31                                 XZ0_TILE, XZ0H_TILE, XT2M_MIN_TILE, XT2M_MAX_TILE,&
32                                 XSWD_TILE, XSWU_TILE, XSWBD_TILE, XSWBU_TILE,     &
33                                 XLWD_TILE,XLWU_TILE, XFMU_TILE, XFMV_TILE,        &
34                                 XAVG_RN, XAVG_H, XAVG_LE, XAVG_LEI,XAVG_GFLUX,    &
35                                 XAVG_LEIC, XAVG_RI, XAVG_CD, XAVG_CH, XAVG_CE,    &
36                                 XAVG_T2M, XAVG_TS, XAVG_Q2M, XAVG_HU2M,           &
37                                 XAVG_ZON10M, XAVG_MER10M, XAVG_SFCO2,             &
38                                 XAVG_T2M_MIN_ZS,XAVG_Q2M_MIN_ZS,XAVG_HU2M_MIN_ZS, &
39                                 XPS,XRHOA, XDIAG_TRAD, XDIAG_EMIS, XAVG_QS,       &
40                                 XAVG_Z0, XAVG_Z0H, XDIAG_UREF, XDIAG_ZREF,        &
41                                 XAVG_SWD, XAVG_SWU, XAVG_LWD, XAVG_LWU,           &
42                                 XAVG_SWBD, XAVG_SWBU, XAVG_FMU, XAVG_FMV,         &
43                                 XSSO_FMU, XSSO_FMV,                               &
44                                 TIME_BUDGETC, LSURF_BUDGETC, LRESET_BUDGETC,      &
45                                 LREAD_BUDGETC, XAVG_RNC, XAVG_HC, XAVG_LEC,       &
46                                 XAVG_GFLUXC, XAVG_SWDC, XAVG_SWUC, XAVG_LWDC,     &
47                                 XAVG_LWUC, XAVG_FMUC, XAVG_FMVC, XRNC_TILE,       &
48                                 XHC_TILE, XLEC_TILE, XGFLUXC_TILE, XSWDC_TILE,    &
49                                 XSWUC_TILE, XLWDC_TILE, XLWUC_TILE, XFMUC_TILE,   &
50                                 XFMVC_TILE, XAVG_T2M_MIN, XAVG_T2M_MAX,           &
51                                 XLEIC_TILE, XHU2M_MIN_TILE, XAVG_HU2M_MIN,        &
52                                 XHU2M_MAX_TILE, XAVG_HU2M_MAX, XWIND10M_TILE,     &
53                                 XAVG_WIND10M, XWIND10M_MAX_TILE, XAVG_WIND10M_MAX
54
55 !
56 USE MODI_READ_SURF
57 !
58 USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
59 USE PARKIND1  ,ONLY : JPRB
60 !
61 IMPLICIT NONE
62 !
63 !*       0.1   Declarations of arguments
64 !              -------------------------
65  CHARACTER(LEN=6),        INTENT(IN) :: HPROGRAM  ! program calling surf. schemes
66 INTEGER,                 INTENT(IN) :: KSW       ! number of short-wave spectral bands
67 !
68 !*       0.2   Declarations of local variables
69 !              -------------------------------
70 !
71 INTEGER           :: IRESP          ! IRESP  : return-code if a problem appears
72  CHARACTER(LEN=12) :: YREC           ! Name of the article to be read
73 REAL(KIND=JPRB) :: ZHOOK_HANDLE
74 !
75 !-------------------------------------------------------------------------------
76 !
77 !
78 ! Initialization: Outputs to atmosphere over each tile:
79 !
80 IF (LHOOK) CALL DR_HOOK('ALLOC_DIAG_SURF_ATM_N',0,ZHOOK_HANDLE)
81 ALLOCATE(XRI_TILE     (NSIZE_FULL,NTILESFC))
82 ALLOCATE(XCD_TILE     (NSIZE_FULL,NTILESFC))
83 ALLOCATE(XCH_TILE     (NSIZE_FULL,NTILESFC))
84 ALLOCATE(XCE_TILE     (NSIZE_FULL,NTILESFC))
85 ALLOCATE(XRN_TILE     (NSIZE_FULL,NTILESFC))
86 ALLOCATE(XH_TILE      (NSIZE_FULL,NTILESFC))
87 ALLOCATE(XLE_TILE     (NSIZE_FULL,NTILESFC))
88 ALLOCATE(XLEI_TILE    (NSIZE_FULL,NTILESFC))
89 ALLOCATE(XGFLUX_TILE  (NSIZE_FULL,NTILESFC))
90 ALLOCATE(XT2M_TILE    (NSIZE_FULL,NTILESFC))
91 ALLOCATE(XTS_TILE     (NSIZE_FULL,NTILESFC))
92 ALLOCATE(XT2M_MIN_TILE(NSIZE_FULL,NTILESFC))
93 ALLOCATE(XT2M_MAX_TILE(NSIZE_FULL,NTILESFC))
94 ALLOCATE(XQ2M_TILE    (NSIZE_FULL,NTILESFC))
95 ALLOCATE(XHU2M_TILE   (NSIZE_FULL,NTILESFC))
96 ALLOCATE(XHU2M_MIN_TILE(NSIZE_FULL,NTILESFC))
97 ALLOCATE(XHU2M_MAX_TILE(NSIZE_FULL,NTILESFC))
98 ALLOCATE(XZON10M_TILE (NSIZE_FULL,NTILESFC))
99 ALLOCATE(XMER10M_TILE (NSIZE_FULL,NTILESFC))
100 ALLOCATE(XQS_TILE     (NSIZE_FULL,NTILESFC))
101 ALLOCATE(XZ0_TILE     (NSIZE_FULL,NTILESFC))
102 ALLOCATE(XZ0H_TILE    (NSIZE_FULL,NTILESFC))
103 ALLOCATE(XSWD_TILE    (NSIZE_FULL,NTILESFC))
104 ALLOCATE(XSWU_TILE    (NSIZE_FULL,NTILESFC))
105 ALLOCATE(XLWD_TILE    (NSIZE_FULL,NTILESFC))
106 ALLOCATE(XLWU_TILE    (NSIZE_FULL,NTILESFC))
107 ALLOCATE(XSWBD_TILE   (NSIZE_FULL,NTILESFC,KSW))
108 ALLOCATE(XSWBU_TILE   (NSIZE_FULL,NTILESFC,KSW))
109 ALLOCATE(XFMU_TILE    (NSIZE_FULL,NTILESFC))
110 ALLOCATE(XFMV_TILE    (NSIZE_FULL,NTILESFC))
111 ALLOCATE(XWIND10M_TILE(NSIZE_FULL,NTILESFC))
112 ALLOCATE(XWIND10M_MAX_TILE(NSIZE_FULL,NTILESFC))
113 !
114 XRI_TILE      = XUNDEF
115 XCD_TILE      = XUNDEF
116 XCH_TILE      = XUNDEF
117 XCE_TILE      = XUNDEF
118 XRN_TILE      = XUNDEF
119 XH_TILE       = XUNDEF
120 XLE_TILE      = XUNDEF
121 XLEI_TILE     = XUNDEF
122 XGFLUX_TILE   = XUNDEF
123 XT2M_TILE     = XUNDEF
124 XTS_TILE      = XUNDEF
125 XT2M_MIN_TILE = XUNDEF
126 XT2M_MAX_TILE = XUNDEF
127 XQ2M_TILE     = XUNDEF
128 XHU2M_TILE    = XUNDEF
129 XHU2M_MIN_TILE= XUNDEF
130 XHU2M_MAX_TILE= XUNDEF
131 XZON10M_TILE  = XUNDEF
132 XMER10M_TILE  = XUNDEF
133 XQS_TILE      = XUNDEF
134 XZ0_TILE      = XUNDEF
135 XZ0H_TILE     = XUNDEF
136 XSWD_TILE     = XUNDEF
137 XSWU_TILE     = XUNDEF
138 XLWD_TILE     = XUNDEF
139 XLWU_TILE     = XUNDEF
140 XSWBD_TILE    = XUNDEF
141 XSWBU_TILE    = XUNDEF
142 XFMU_TILE     = XUNDEF
143 XFMV_TILE     = XUNDEF
144 XWIND10M_TILE = XUNDEF
145 XWIND10M_MAX_TILE = XUNDEF
146 !
147 ! Initialization: aggregated fields
148 !
149 ALLOCATE(XAVG_RI     (NSIZE_FULL))
150 ALLOCATE(XAVG_CD     (NSIZE_FULL))
151 ALLOCATE(XAVG_CH     (NSIZE_FULL))
152 ALLOCATE(XAVG_CE     (NSIZE_FULL))
153 ALLOCATE(XAVG_RN     (NSIZE_FULL))
154 ALLOCATE(XAVG_H      (NSIZE_FULL))
155 ALLOCATE(XAVG_LE     (NSIZE_FULL))
156 ALLOCATE(XAVG_LEI    (NSIZE_FULL))
157 ALLOCATE(XAVG_GFLUX  (NSIZE_FULL))
158 ALLOCATE(XAVG_T2M    (NSIZE_FULL))
159 ALLOCATE(XAVG_TS     (NSIZE_FULL))
160 ALLOCATE(XAVG_T2M_MIN(NSIZE_FULL))
161 ALLOCATE(XAVG_T2M_MAX(NSIZE_FULL))
162 ALLOCATE(XAVG_Q2M    (NSIZE_FULL))
163 ALLOCATE(XAVG_HU2M   (NSIZE_FULL))
164 ALLOCATE(XAVG_HU2M_MIN(NSIZE_FULL))
165 ALLOCATE(XAVG_HU2M_MAX(NSIZE_FULL))
166 ALLOCATE(XAVG_ZON10M (NSIZE_FULL))
167 ALLOCATE(XAVG_MER10M (NSIZE_FULL))
168 ALLOCATE(XAVG_SFCO2  (NSIZE_FULL))
169 ALLOCATE(XAVG_T2M_MIN_ZS    (NSIZE_FULL))
170 ALLOCATE(XAVG_Q2M_MIN_ZS    (NSIZE_FULL))
171 ALLOCATE(XAVG_HU2M_MIN_ZS   (NSIZE_FULL))
172 ALLOCATE(XPS                (NSIZE_FULL))
173 ALLOCATE(XRHOA              (NSIZE_FULL))
174 ALLOCATE(XAVG_QS     (NSIZE_FULL))
175 ALLOCATE(XAVG_Z0     (NSIZE_FULL))
176 ALLOCATE(XAVG_Z0H    (NSIZE_FULL))
177 ALLOCATE(XAVG_SWD    (NSIZE_FULL))
178 ALLOCATE(XAVG_SWU    (NSIZE_FULL))
179 ALLOCATE(XAVG_LWD    (NSIZE_FULL))
180 ALLOCATE(XAVG_LWU    (NSIZE_FULL))
181 ALLOCATE(XAVG_SWBD   (NSIZE_FULL,KSW))
182 ALLOCATE(XAVG_SWBU   (NSIZE_FULL,KSW))
183 ALLOCATE(XAVG_FMU    (NSIZE_FULL))
184 ALLOCATE(XAVG_FMV    (NSIZE_FULL))
185 ALLOCATE(XSSO_FMU    (NSIZE_FULL))
186 ALLOCATE(XSSO_FMV    (NSIZE_FULL))
187 ALLOCATE(XAVG_WIND10M(NSIZE_FULL))
188 ALLOCATE(XAVG_WIND10M_MAX(NSIZE_FULL))
189 !
190 ALLOCATE(XDIAG_UREF  (NSIZE_FULL))
191 ALLOCATE(XDIAG_ZREF  (NSIZE_FULL))
192 ALLOCATE(XDIAG_TRAD  (NSIZE_FULL))
193 ALLOCATE(XDIAG_EMIS  (NSIZE_FULL))
194 !
195 XAVG_RI      = XUNDEF
196 XAVG_CD      = XUNDEF
197 XAVG_CH      = XUNDEF
198 XAVG_CE      = XUNDEF
199 XAVG_RN      = XUNDEF
200 XAVG_H       = XUNDEF
201 XAVG_LE      = XUNDEF
202 XAVG_LEI     = XUNDEF
203 XAVG_GFLUX   = XUNDEF
204 XAVG_T2M     = XUNDEF
205 XAVG_TS      = XUNDEF
206 XAVG_T2M_MIN = XUNDEF
207 XAVG_T2M_MAX = XUNDEF
208 XAVG_Q2M     = XUNDEF
209 XAVG_HU2M    = XUNDEF
210 XAVG_HU2M_MIN= XUNDEF
211 XAVG_HU2M_MAX= XUNDEF
212 XAVG_ZON10M  = XUNDEF
213 XAVG_MER10M  = XUNDEF
214 XAVG_SFCO2   = XUNDEF
215 XAVG_T2M_MIN_ZS     = XUNDEF
216 XAVG_Q2M_MIN_ZS     = XUNDEF
217 XAVG_HU2M_MIN_ZS    = XUNDEF
218 XPS                 = XUNDEF
219 XRHOA               = XUNDEF
220 XAVG_QS      = XUNDEF
221 XAVG_Z0      = XUNDEF
222 XAVG_Z0H     = XUNDEF
223 XAVG_SWD     = XUNDEF
224 XAVG_SWU     = XUNDEF
225 XAVG_LWD     = XUNDEF
226 XAVG_LWU     = XUNDEF
227 XAVG_SWBD    = XUNDEF
228 XAVG_SWBU    = XUNDEF
229 XAVG_FMU     = XUNDEF
230 XAVG_FMV     = XUNDEF
231 XSSO_FMU     = XUNDEF
232 XSSO_FMV     = XUNDEF
233 XAVG_WIND10M = XUNDEF
234 XAVG_WIND10M_MAX = XUNDEF
235 !
236 XDIAG_UREF   = XUNDEF
237 XDIAG_ZREF   = XUNDEF
238 XDIAG_TRAD   = XUNDEF
239 XDIAG_EMIS   = XUNDEF
240 !
241 IF (LSURF_BUDGETC) THEN
242 !
243   ALLOCATE(XRNC_TILE     (NSIZE_FULL,NTILESFC))
244   ALLOCATE(XHC_TILE      (NSIZE_FULL,NTILESFC))
245   ALLOCATE(XLEC_TILE     (NSIZE_FULL,NTILESFC))
246   ALLOCATE(XLEIC_TILE    (NSIZE_FULL,NTILESFC))
247   ALLOCATE(XGFLUXC_TILE  (NSIZE_FULL,NTILESFC))
248   ALLOCATE(XSWDC_TILE    (NSIZE_FULL,NTILESFC))
249   ALLOCATE(XSWUC_TILE    (NSIZE_FULL,NTILESFC))
250   ALLOCATE(XLWDC_TILE    (NSIZE_FULL,NTILESFC))
251   ALLOCATE(XLWUC_TILE    (NSIZE_FULL,NTILESFC))
252   ALLOCATE(XFMUC_TILE    (NSIZE_FULL,NTILESFC))
253   ALLOCATE(XFMVC_TILE    (NSIZE_FULL,NTILESFC))
254 !
255   XRNC_TILE      = XUNDEF
256   XHC_TILE       = XUNDEF
257   XLEC_TILE      = XUNDEF
258   XLEIC_TILE     = XUNDEF
259   XGFLUXC_TILE   = XUNDEF
260   XSWDC_TILE     = XUNDEF
261   XSWUC_TILE     = XUNDEF
262   XLWDC_TILE     = XUNDEF
263   XLWUC_TILE     = XUNDEF
264   XFMUC_TILE     = XUNDEF
265   XFMVC_TILE     = XUNDEF
266 !
267   ALLOCATE(XAVG_RNC     (NSIZE_FULL))
268   ALLOCATE(XAVG_HC      (NSIZE_FULL))
269   ALLOCATE(XAVG_LEC     (NSIZE_FULL))
270   ALLOCATE(XAVG_LEIC    (NSIZE_FULL))
271   ALLOCATE(XAVG_GFLUXC  (NSIZE_FULL))
272   ALLOCATE(XAVG_SWDC    (NSIZE_FULL))
273   ALLOCATE(XAVG_SWUC    (NSIZE_FULL))
274   ALLOCATE(XAVG_LWDC    (NSIZE_FULL))
275   ALLOCATE(XAVG_LWUC    (NSIZE_FULL))
276   ALLOCATE(XAVG_FMUC    (NSIZE_FULL))
277   ALLOCATE(XAVG_FMVC    (NSIZE_FULL))
278 !
279   YREC='BUDC'
280   CALL READ_SURF(HPROGRAM,YREC,LREAD_BUDGETC,IRESP)
281 !
282   IF (.NOT. LREAD_BUDGETC) THEN
283       TIME_BUDGETC = TTIME
284       XAVG_RNC    = 0.0
285       XAVG_HC     = 0.0
286       XAVG_LEC    = 0.0
287       XAVG_LEIC   = 0.0
288       XAVG_GFLUXC = 0.0
289       XAVG_SWDC   = 0.0
290       XAVG_SWUC   = 0.0
291       XAVG_LWDC   = 0.0
292       XAVG_LWUC   = 0.0
293       XAVG_FMUC   = 0.0
294       XAVG_FMVC   = 0.0      
295   ELSEIF (LREAD_BUDGETC.AND.LRESET_BUDGETC) THEN
296       TIME_BUDGETC = TTIME
297       XAVG_RNC    = 0.0
298       XAVG_HC     = 0.0
299       XAVG_LEC    = 0.0
300       XAVG_LEIC   = 0.0
301       XAVG_GFLUXC = 0.0
302       XAVG_SWDC   = 0.0
303       XAVG_SWUC   = 0.0
304       XAVG_LWDC   = 0.0
305       XAVG_LWUC   = 0.0
306       XAVG_FMUC   = 0.0
307       XAVG_FMVC   = 0.0       
308   ELSE
309       YREC='TBUDC'
310       CALL READ_SURF(HPROGRAM,YREC,TIME_BUDGETC,IRESP)
311      YREC='RNC'
312      CALL READ_SURF(HPROGRAM,YREC,XAVG_RNC,IRESP)
313      YREC='HC'
314      CALL READ_SURF(HPROGRAM,YREC,XAVG_HC ,IRESP)
315      YREC='LEC'
316      CALL READ_SURF(HPROGRAM,YREC,XAVG_LEC,IRESP)
317      YREC='LEIC'
318      CALL READ_SURF(HPROGRAM,YREC,XAVG_LEIC,IRESP)     
319      YREC='GFLUXC'
320      CALL READ_SURF(HPROGRAM,YREC,XAVG_GFLUXC ,IRESP)
321      YREC='SWDC'
322      CALL READ_SURF(HPROGRAM,YREC,XAVG_SWDC,IRESP)
323      YREC='SWUC'
324      CALL READ_SURF(HPROGRAM,YREC,XAVG_SWUC,IRESP)
325      YREC='LWDC'
326      CALL READ_SURF(HPROGRAM,YREC,XAVG_LWDC,IRESP)
327      YREC='LWUC'
328      CALL READ_SURF(HPROGRAM,YREC,XAVG_LWUC,IRESP)
329      YREC='FMUC'
330      CALL READ_SURF(HPROGRAM,YREC,XAVG_FMUC,IRESP)
331      YREC='FMVC'
332      CALL READ_SURF(HPROGRAM,YREC,XAVG_FMVC,IRESP)      
333   ENDIF
334 !
335 ELSE
336 !
337   ALLOCATE(XRNC_TILE     (0,0))
338   ALLOCATE(XHC_TILE      (0,0))
339   ALLOCATE(XLEC_TILE     (0,0))
340   ALLOCATE(XLEIC_TILE    (0,0))
341   ALLOCATE(XGFLUXC_TILE  (0,0))
342   ALLOCATE(XSWDC_TILE    (0,0))
343   ALLOCATE(XSWUC_TILE    (0,0))
344   ALLOCATE(XLWDC_TILE    (0,0))
345   ALLOCATE(XLWUC_TILE    (0,0))
346   ALLOCATE(XFMUC_TILE    (0,0))
347   ALLOCATE(XFMVC_TILE    (0,0))
348 !
349   ALLOCATE(XAVG_RNC     (0))
350   ALLOCATE(XAVG_HC      (0))
351   ALLOCATE(XAVG_LEC     (0))
352   ALLOCATE(XAVG_LEIC    (0))
353   ALLOCATE(XAVG_GFLUXC  (0))
354   ALLOCATE(XAVG_SWDC    (0))
355   ALLOCATE(XAVG_SWUC    (0))
356   ALLOCATE(XAVG_LWDC    (0))
357   ALLOCATE(XAVG_LWUC    (0))
358   ALLOCATE(XAVG_FMUC    (0))
359   ALLOCATE(XAVG_FMVC    (0))
360 !
361 ENDIF
362 IF (LHOOK) CALL DR_HOOK('ALLOC_DIAG_SURF_ATM_N',1,ZHOOK_HANDLE)
363 !
364 !-------------------------------------------------------------------------------
365 !
366 END SUBROUTINE ALLOC_DIAG_SURF_ATM_n