SURFEX v8.1
General documentation of Surfex
gw_redistrib.F90
Go to the documentation of this file.
1 ! #########
2  SUBROUTINE gw_redistrib (TP, TPG, &
3  KLON,KLAT,PREAD,PFOUT)
4 ! #####################################################################
5 !
6 !!**** *GW_REDISTRIB*
7 !!
8 !! PURPOSE
9 !! -------
10 !
11 !
12 !!** METHOD
13 !! ------
14 !
15 ! Direct calculation
16 !
17 !! EXTERNAL
18 !! --------
19 !
20 ! None
21 !!
22 !! IMPLICIT ARGUMENTS
23 !! ------------------
24 !!
25 !!
26 !! REFERENCE
27 !! ---------
28 !!
29 !! AUTHOR
30 !! ------
31 !! B. Decharme
32 !!
33 !! MODIFICATIONS
34 !! -------------
35 !! Original 01/10/16
36 !-------------------------------------------------------------------------------
37 !
38 !* 0. DECLARATIONS
39 ! ------------
40 !
41 USE modd_trip, ONLY : trip_t
42 USE modd_trip_grid, ONLY : trip_grid_t
43 !
45 !
46 USE modd_trip_par, ONLY : xundef
47 !
48 USE modi_abort_trip
49 !
50 USE yomhook ,ONLY : lhook, dr_hook
51 USE parkind1 ,ONLY : jprb
52 !
53 IMPLICIT NONE
54 !
55 !* 0.1 declarations of arguments
56 !
57 !
58 TYPE(trip_t), INTENT(INOUT) :: TP
59 TYPE(trip_grid_t), INTENT(INOUT) :: TPG
60 !
61 INTEGER, INTENT(IN) :: KLON
62 INTEGER, INTENT(IN) :: KLAT
63 !
64 REAL, DIMENSION(:,:), INTENT(IN ) :: PREAD ![kg/m2/s]
65 REAL, DIMENSION(:,:), INTENT(OUT) :: PFOUT ![kg/m2/s]
66 !
67 !
68 !* 0.2 declarations of local variables
69 !
70 !
71 REAL, DIMENSION(1000) :: ZBAS_FNEG
72 REAL, DIMENSION(1000) :: ZBAS_AREA
73 !
74 LOGICAL, DIMENSION(KLON,KLAT) :: GMASK_NOGW
75 !
76 REAL, DIMENSION(KLON,KLAT) :: ZFNEG
77 REAL, DIMENSION(KLON,KLAT) :: ZRATIO
78 !
79 INTEGER, DIMENSION(KLON,KLAT) :: INUM_AQUI
80 !
81 REAL :: ZFLUXE_IN
82 REAL :: ZFLUXE_OUT
83 REAL :: ZAREA_TOT, ZTOT_STO
84 REAL :: ZBILAN
85 !
86 INTEGER :: JBAS, JLON, JLAT
87 !
88 REAL(KIND=JPRB) :: ZHOOK_HANDLE
89 !
90 !-------------------------------------------------------------------------------
91 !
92 IF (lhook) CALL dr_hook('GW_REDISTRIB',0,zhook_handle)
93 !
94 !-------------------------------------------------------------------------------
95 ! * Init none groundwater mask
96 !-------------------------------------------------------------------------------
97 !
98 WHERE(tpg%GMASK(:,:).AND.(.NOT.tpg%GMASK_GW(:,:)))
99  gmask_nogw(:,:)=.true.
100 ELSEWHERE
101  gmask_nogw(:,:)=.false.
102 ENDWHERE
103 !
104 !-------------------------------------------------------------------------------
105 ! * Init flux fileds
106 !-------------------------------------------------------------------------------
107 !
108 zbilan = 0.0
109 zfneg(:,:) = 0.0
110 pfout(:,:) = pread(:,:)
111 !
112 DO jlat=1,klat
113  DO jlon=1,klon
114  IF(gmask_nogw(jlon,jlat).AND.pread(jlon,jlat)<0.0)THEN
115  pfout(jlon,jlat) = 0.0
116  zfneg(jlon,jlat) = pread(jlon,jlat)
117  zbilan = zbilan + pread(jlon,jlat)
118  ENDIF
119  ENDDO
120 ENDDO
121 !
122 IF(zbilan==0.0)THEN
123 ! If no negative fluxes over none groundwater mask, return
124  IF (lhook) CALL dr_hook('GW_REDISTRIB',1,zhook_handle)
125  RETURN
126 ENDIF
127 !
128 !-------------------------------------------------------------------------------
129 ! * Redistribute negative field over aquifer basins
130 !-------------------------------------------------------------------------------
131 !
132 WHERE(tpg%GMASK(:,:))
133  inum_aqui(:,:)=int(tp%XNEAR_AQUI(:,:))
134 ELSEWHERE
135  inum_aqui(:,:)=0
136 ENDWHERE
137 !
138 zbas_fneg(:) = 0.0
139 zbas_area(:) = 0.0
140 !
141 DO jlat=1,klat
142  DO jlon=1,klon
143  jbas=inum_aqui(jlon,jlat)
144  IF(tpg%GMASK_GW(jlon,jlat))THEN
145  zbas_area(jbas)=zbas_area(jbas)+tpg%XAREA(jlon,jlat)
146  ENDIF
147  IF(gmask_nogw(jlon,jlat))THEN
148  zbas_fneg(jbas)=zbas_fneg(jbas)+tpg%XAREA(jlon,jlat)*zfneg(jlon,jlat) ! kg/s
149  ENDIF
150  ENDDO
151 ENDDO
152 !
153 DO jlat=1,klat
154  DO jlon=1,klon
155  jbas = inum_aqui(jlon,jlat)
156  IF(tpg%GMASK_GW(jlon,jlat))THEN
157  pfout(jlon,jlat) = pfout(jlon,jlat) + zbas_fneg(jbas)/zbas_area(jbas) ! kg/m2/s
158  ENDIF
159  ENDDO
160 ENDDO
161 !
162 !
163 !-------------------------------------------------------------------------------
164 ! * Comput cumulated Fluxes (kg/s) and flooded areas (-)
165 !-------------------------------------------------------------------------------
166 !
167 zfluxe_in = 0.0
168 zfluxe_out = 0.0
169 zarea_tot = 0.0
170 !
171 DO jlat=1,klat
172  DO jlon=1,klon
173  IF(tpg%GMASK(jlon,jlat))THEN
174  zarea_tot = zarea_tot + tpg%XAREA(jlon,jlat)
175  zfluxe_in = zfluxe_in + tpg%XAREA(jlon,jlat) * pread(jlon,jlat)
176  zfluxe_out = zfluxe_out + tpg%XAREA(jlon,jlat) * pfout(jlon,jlat)
177  ENDIF
178  ENDDO
179 ENDDO
180 !
181 zbilan=(zfluxe_in-zfluxe_out)/zarea_tot
182 !
183 IF(abs(zbilan)>1.e-12)THEN
184  WRITE(nlisting,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
185  WRITE(nlisting,*)'Redistribution of negative recharge sources has a problem'
186  WRITE(nlisting,*)'BILAN = ', zbilan, zfluxe_in/zarea_tot, zfluxe_out/zarea_tot
187  WRITE(nlisting,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
188  CALL abort_trip('GW_REDISTRIB: Redistribution of negative recharge sources has a problem')
189 ENDIF
190 !
191 !-------------------------------------------------------------------------------
192 !
193 IF (lhook) CALL dr_hook('GW_REDISTRIB',1,zhook_handle)
194 !
195 !-------------------------------------------------------------------------------
196 !
197 END SUBROUTINE gw_redistrib
subroutine gw_redistrib(TP, TPG, KLON, KLAT, PREAD, PFOUT)
Definition: gw_redistrib.F90:4
integer, parameter jprb
Definition: parkind1.F90:32
logical lhook
Definition: yomhook.F90:15
subroutine abort_trip(YTEXT)
Definition: abort_trip.F90:3
real, save xundef