SURFEX v8.1
General documentation of Surfex
init_budget_coupl_rout.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 init_budget_coupl_rout (DEC, DC, DMI, PMESH_SIZE, IO, NP, NPE, U, KNI)
7 ! ##########################
8 !
9 !!
10 !! PURPOSE
11 !! -------
12 ! Initialise varriables usefull for budget computation
13 !
14 !!** METHOD
15 !! ------
16 !! Terms of the budget on all the domain
17 !! XB_VAR_TOT(forcing time step,variable)
18 !! Water going in the system
19 !! variable =1 : Rain
20 !! variable =2 : Snow
21 !! Water going out of the system
22 !! variable =3 : Incerception
23 !! variable =4 : Evaporation
24 !! variable =5 : Runoff
25 !! variable =6 : Drainage
26 !! variable =7 : Variation of liquid water stocked in the ground
27 !! variable =8 : Variation of solid water stocked in the ground
28 !! variable =9 : Variation of melting snow
29 !! Budget
30 !! variable =10: Water going in the system- Water going out of the system
31 !!
32 !! Terms of the budget on a given catchment
33 !! XB_VAR_BV(forcing time step,catchment,variable)
34 !! XB_VAR_NOBV(forcing time step,catchment,variable)
35 !!
36 !! EXTERNAL
37 !! --------
38 !!
39 !! none
40 !!
41 !! IMPLICIT ARGUMENTS
42 !! ------------------
43 !!
44 !! REFERENCE
45 !! ---------
46 !!
47 !! AUTHOR
48 !! ------
49 !!
50 !! L. Bouilloud & B. Vincendon * Meteo-France *
51 
52 !!
53 !! MODIFICATIONS
54 !! -------------
55 !!
56 !! Original 03/2008
57 !! 03/2014: Modif BV : add more variables
58 !-------------------------------------------------------------------------------
59 !
60 !* 0. DECLARATIONS
61 ! ------------
62 !
63 ! declarative modules
64 !
65 USE modd_diag_n, ONLY : diag_t
69 USE modd_isba_n, ONLY : isba_np_t, isba_npe_t
70 USE modd_surf_atm_n, ONLY : surf_atm_t
71 !
72 USE modd_budget_coupl_rout ! contains all useful variables XB_*
73 !
74 USE modd_topodyn, ONLY : nncat, nnmc, xqtot,&
78 !
79 USE modd_surf_par, ONLY:xundef
80 !
82 USE modi_avg_patch_wg
83 USE modi_dg_dfto3l
84 !
85 USE yomhook ,ONLY : lhook, dr_hook
86 USE parkind1 ,ONLY : jprb
87 !
88 IMPLICIT NONE
89 !
90 !* 0.1 declarations of arguments
91 !
92 !
93 TYPE(diag_evap_isba_t), INTENT(INOUT) :: DEC
94 TYPE(diag_t), INTENT(INOUT) :: DC
95 TYPE(diag_misc_isba_t), INTENT(INOUT) :: DMI
96 REAL, DIMENSION(:), INTENT(IN) :: PMESH_SIZE
97 TYPE(isba_options_t), INTENT(INOUT) :: IO
98 TYPE(isba_np_t), INTENT(INOUT) :: NP
99 TYPE(isba_npe_t), INTENT(INOUT) :: NPE
100 TYPE(surf_atm_t), INTENT(INOUT) :: U
101 !
102 INTEGER, INTENT(IN) :: KNI ! expected physical size of full surface array
103 !
104 !* 0.2 declarations of local variables
105 !
106 INTEGER :: JJ,JWRK2
107 INTEGER :: INB_VAR ! number of variable to write
108 REAL, DIMENSION(U%NSIZE_NATURE,3) :: ZWG_3L,ZWGI_3L,ZDG_3L
109 REAL, DIMENSION(U%NSIZE_NATURE) :: ZINTER
110 !
111 REAL(KIND=JPRB) :: ZHOOK_HANDLE
112 !-------------------------------------------------------------------------------
113 IF (lhook) CALL dr_hook('INIT_BUDGET_COUPL_ROUT',0,zhook_handle)
114 !
115 !* 0. Initialization:
116 ! ---------------
117 inb_var=12
118 
119 IF (io%CISBA=='DIF') THEN
120  CALL dg_dfto3l(io, np, zdg_3l)
121  zwg_3l(:,2)=dmi%XFRD2_TWG(:)
122  zwg_3l(:,3)=dmi%XFRD3_TWG(:)
123  zwgi_3l(:,2)=dmi%XFRD2_TWGI(:)
124  zwgi_3l(:,3)=dmi%XFRD3_TWGI(:)
125 ELSEIF (io%CISBA=='3-L') THEN
126  CALL avg_patch_wg(io, np, npe, zwg_3l,zwgi_3l,zdg_3l)
127 ENDIF
128 !
129 ALLOCATE(yb_var(inb_var))
130 yb_var(1)='RAIN '
131 yb_var(2)='SNOW '
132 yb_var(3)='INTERC'
133 yb_var(4)='EVATRA'
134 yb_var(5)='RUNOFF'
135 yb_var(6)='DRAINA'
136 yb_var(7)='DSTOWG'
137 yb_var(8)='DSTOWI'
138 yb_var(9)='DSTOSW'
139 yb_var(10)='BUDGET'
140 yb_var(11)='HORTON'
141 yb_var(12)='WATBUD'
142 !
143 !
144 ALLOCATE(xb_rain(kni))
145 ALLOCATE(xb_snow(kni))
146 !
147 ALLOCATE(xb_wr(kni))
148 ALLOCATE(xb_evap(kni))
149 ALLOCATE(xb_runoff_isba(kni))
150 ALLOCATE(xb_horton(kni))
151 ALLOCATE(xb_drain(kni))
152 ALLOCATE(xb_wg2(kni))
153 ALLOCATE(xb_wg3(kni))
154 ALLOCATE(xb_wgtot(kni))
155 ALLOCATE(xb_wgi2(kni))
156 ALLOCATE(xb_wgi3(kni))
157 ALLOCATE(xb_wgitot(kni))
158 ALLOCATE(xb_swe1(kni))
159 ALLOCATE(xb_swe2(kni))
160 ALLOCATE(xb_swe3(kni))
161 ALLOCATE(xb_swetot(kni))
162 !
163 ALLOCATE(xb_wrm(kni))
164 ALLOCATE(xb_evapm(kni))
165 ALLOCATE(xb_drainm(kni))
166 ALLOCATE(xb_runoff_isbam(kni))
167 ALLOCATE(xb_hortonm(kni))
168 ALLOCATE(xb_wg2m(kni))
169 ALLOCATE(xb_wg3m(kni))
170 ALLOCATE(xb_wgtotm(kni))
171 ALLOCATE(xb_wgi2m(kni))
172 ALLOCATE(xb_wgi3m(kni))
173 ALLOCATE(xb_wgitotm(kni))
174 ALLOCATE(xb_swe1m(kni))
175 ALLOCATE(xb_swe2m(kni))
176 ALLOCATE(xb_swe3m(kni))
177 ALLOCATE(xb_swetotm(kni))
178 !
179 ALLOCATE(xb_mesh_size(kni))
180 ALLOCATE(xb_dg2(kni))
181 ALLOCATE(xb_dg3(kni))
182 !
183 !init var tot
184 CALL UNPACK_SAME_RANK(NP%AL(1)%NR_P,NPE%AL(1)%XWR(:),ZINTER(:))
185 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZINTER,XB_WRM)
186 !
187 CALL UNPACK_SAME_RANK(U%NR_NATURE,DC%XEVAP,XB_EVAPM)
188 CALL UNPACK_SAME_RANK(U%NR_NATURE,DEC%XRUNOFF,XB_RUNOFF_ISBAM)
189 CALL UNPACK_SAME_RANK(U%NR_NATURE,DEC%XHORT,XB_HORTONM)
190 CALL UNPACK_SAME_RANK(U%NR_NATURE,DEC%XDRAIN,XB_DRAINM)
191 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZWG_3L(:,2),XB_WG2M)
192 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZWG_3L(:,3),XB_WG3M)
193 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZDG_3L(:,2),XB_DG2)
194 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZDG_3L(:,3),XB_DG3)
195 !
196 WHERE ( xb_wg2m/=xundef .AND. xb_dg2/=xundef .AND. xb_wg3m/=xundef .AND. xb_dg3/=xundef )
197  xb_wgtotm(:) = xb_wg2m(:)*xb_dg2(:) + xb_wg3m(:)*(xb_dg3(:)-xb_dg2(:)) !m3/m2
198 ELSEWHERE
199  xb_wgtotm(:) = xundef
200 ENDWHERE
201 !
202 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZWGI_3L(:,2),XB_WGI2M)
203 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZWGI_3L(:,3),XB_WGI3M)
204 WHERE ((xb_wgi2m/=xundef).AND.(xb_dg2/=xundef).AND.(xb_wgi3m/=xundef).AND.(xb_dg3/=xundef))
205  xb_wgitotm(:) = xb_wgi2m(:)*xb_dg2(:) + xb_wgi3m(:)*(xb_dg3(:)-xb_dg2(:)) !m3/m2
206 ELSEWHERE
207  xb_wgitotm(:) = xundef
208 ENDWHERE
209 !
210 CALL UNPACK_SAME_RANK(NP%AL(1)%NR_P,NPE%AL(1)%TSNOW%WSNOW(:,1),ZINTER)
211 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZINTER,XB_SWE1M)
212 !
213 CALL UNPACK_SAME_RANK(NP%AL(1)%NR_P,NPE%AL(1)%TSNOW%WSNOW(:,2),ZINTER)
214 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZINTER,XB_SWE2M)
215 !
216 CALL UNPACK_SAME_RANK(NP%AL(1)%NR_P,NPE%AL(1)%TSNOW%WSNOW(:,3),ZINTER)
217 CALL UNPACK_SAME_RANK(U%NR_NATURE,ZINTER,XB_SWE3M)
218 !
219 xb_swetotm(:) = xb_swe1m(:)+xb_swe2m(:)+xb_swe3m(:)
220 !
221 CALL UNPACK_SAME_RANK(U%NR_NATURE,PMESH_SIZE,XB_MESH_SIZE)
222 !
223 ALLOCATE(xb_abv_bymesh(kni,nncat))
224 DO jj=1,kni
225  xb_abv_bymesh(jj,:) = xbv_in_mesh(jj,:)/xb_mesh_size(jj) !*NNMC(:)*XDXT(:)**2 !
226  xb_abv_bymesh(jj,:) = min(1.,xb_abv_bymesh(jj,:))
227 ENDDO
228 !
229 ALLOCATE(xb_var_bv(nnb_topd_step,nncat,inb_var))
230 xb_var_bv(:,:,:) = 0.
231 ALLOCATE(xb_var_nobv(nnb_topd_step,nncat,inb_var))
232 xb_var_nobv(:,:,:) = 0.
233 !
234 ALLOCATE(xb_var_tot(nnb_topd_step,inb_var))
235 xb_var_tot(:,:) = 0.
236 !
237 ALLOCATE(xb_runoff_topd(kni))
238 ALLOCATE(xb_runoff_topdm(kni))
239 ALLOCATE(xb_atop_bymesh(kni))
240 !
241 CALL UNPACK_SAME_RANK(U%NR_NATURE,XATOP,XB_ATOP_BYMESH)
243 !
244 ALLOCATE(yb_varq(5))
245 yb_varq(1)='Q_TOT '
246 yb_varq(2)='Q_RUN '
247 yb_varq(3)='Q_DR '
248 yb_varq(4)='ST_RUN'
249 yb_varq(5)='ST_DR '
250 !
251 !
252 ALLOCATE(xb_qtot(nncat))
253 ALLOCATE(xb_qdr(nncat))
254 ALLOCATE(xb_qrun(nncat))
255 ALLOCATE(xb_var_q(nnb_topd_step,nncat,5))
256 !
257 ALLOCATE(xb_qtotm(nncat))
258 ALLOCATE(xb_qdrm(nncat))
259 ALLOCATE(xb_qrunm(nncat))
260 !
261 !init var bilan q
262 xb_qtot(:) = 0.
263 xb_qdr(:) = 0.
264 xb_qrun(:) = 0.
265 !
266 xb_var_q(:,:,:)=0
267 !
268 DO jj=1,nncat
269  xb_qtotm(jj) = sum(xqtot(jj,:))
270  xb_qrunm(jj) = sum(xqb_run(jj,:))
271  xb_qdrm(jj) = sum(xqb_dr(jj,:))
272 ENDDO
273 !
274 IF (lhook) CALL dr_hook('INIT_BUDGET_COUPL_ROUT',1,zhook_handle)
275 !
276 END SUBROUTINE init_budget_coupl_rout
real, dimension(:), allocatable xb_dg2
real, dimension(:), allocatable xb_wg2
real, dimension(:,:), allocatable xb_var_tot
real, dimension(:,:), allocatable xbv_in_mesh
real, dimension(:), allocatable xb_runoff_topd
real, dimension(:), allocatable xb_qtotm
real, dimension(:), allocatable xb_qdrm
real, dimension(:), allocatable xb_wg3m
real, dimension(:), allocatable xb_evapm
real, dimension(:), allocatable xb_mesh_size
real, dimension(:), allocatable xb_snow
real, dimension(:,:), allocatable xqb_dr
real, dimension(:,:), allocatable xqb_run
real, dimension(:), allocatable xb_wrm
real, dimension(:,:,:), allocatable xb_var_nobv
integer nnb_topd_step
real, dimension(:), allocatable xb_evap
real, dimension(:), allocatable xb_runoff_topdm
real, dimension(:), allocatable xb_swe3m
real, dimension(:), allocatable xb_swe2m
real, parameter xundef
real, dimension(:,:), allocatable xb_abv_bymesh
real, dimension(:), allocatable xb_swe1m
subroutine init_budget_coupl_rout(DEC, DC, DMI, PMESH_SIZE, IO, N
real, dimension(:,:,:), allocatable xb_var_bv
real, dimension(:), allocatable xb_drainm
integer, parameter jprb
Definition: parkind1.F90:32
real, dimension(:), allocatable xb_wgtot
subroutine dg_dfto3l(IO, NP, PDG)
Definition: dg_dfto3l.F90:8
real, dimension(:), allocatable xdxt
real, dimension(:), allocatable xas_nature
real, dimension(:), allocatable xb_swe1
real, dimension(:,:,:), allocatable xb_var_q
real, dimension(:), allocatable xb_wgi3
real, dimension(:), allocatable xb_wgi3m
real, dimension(:), allocatable xb_runoff_isba
real, dimension(:), allocatable xb_wgitot
intent(out) overrides sub arrays one Sort by the least significant key first sum(iindex(1:n))
real, dimension(:), allocatable xb_swe3
real, dimension(:), allocatable xb_qrun
logical lhook
Definition: yomhook.F90:15
real, dimension(:), allocatable xb_wg3
real, dimension(:), allocatable xb_dg3
real, dimension(:), allocatable xb_qrunm
real, dimension(:), allocatable xb_rain
real, dimension(:), allocatable xb_qdr
real, dimension(:), allocatable xb_wg2m
real, dimension(:), allocatable xb_drain
real, dimension(:), allocatable xb_swetot
real, dimension(:), allocatable xb_wgitotm
real, dimension(:), allocatable xb_wr
real, dimension(:), allocatable xatop
real, dimension(:), allocatable xb_wgtotm
real, dimension(:), allocatable xb_atop_bymesh
real, dimension(:), allocatable xb_hortonm
real, dimension(:), allocatable xb_qtot
real, dimension(:), allocatable xb_wgi2
real, dimension(:), allocatable xb_wgi2m
subroutine avg_patch_wg(IO, NP, NPE, PWG, PWGI, PDG)
Definition: avg_patch_wg.F90:8
real, dimension(:), allocatable xb_swe2
real, dimension(:), allocatable xb_runoff_isbam
integer, dimension(:), allocatable nnmc
real, dimension(:), allocatable xb_horton
real, dimension(:,:), allocatable xqtot