SURFEX v8.1
General documentation of Surfex
trip_oasis_recv.F90
Go to the documentation of this file.
1 !#########
2 SUBROUTINE trip_oasis_recv(TP, TPG, &
3  KLISTING,KLON,KLAT,PTIMEC,PRUNOFF, &
4  PDRAIN,PCALVING,PSRC_FLOOD )
5 !#############################################################################
6 !
7 !!**** *TRIP_OASIS_RECV* - Receive coupling fields
8 !!
9 !! PURPOSE
10 !! -------
11 !!
12 !!** METHOD
13 !! ------
14 !!
15 !! EXTERNAL
16 !! --------
17 !!
18 !!
19 !! IMPLICIT ARGUMENTS
20 !! ------------------
21 !!
22 !! REFERENCE
23 !! ---------
24 !!
25 !!
26 !! AUTHOR
27 !! ------
28 !! B. Decharme *Meteo France*
29 !!
30 !! MODIFICATIONS
31 !! -------------
32 !! Original 10/2013
33 !! B. Decharme 10/2016 bug surface/groundwater coupling
34 !-------------------------------------------------------------------------------
35 !
36 !* 0. DECLARATIONS
37 ! ------------
38 !
39 !
40 USE modd_trip, ONLY : trip_t
41 USE modd_trip_grid, ONLY : trip_grid_t
42 !
44 !
45 USE modd_trip_par, ONLY : xundef
46 !
48 !
49 USE modi_gw_redistrib
50 USE modi_flood_redistrib
51 !
52 USE yomhook ,ONLY : lhook, dr_hook
53 USE parkind1 ,ONLY : jprb
54 !
55 #ifdef CPLOASIS
56 USE mod_oasis
57 #endif
58 !
59 IMPLICIT NONE
60 !
61 !* 0.1 Declarations of arguments
62 ! -------------------------
63 !
64 !
65 TYPE(trip_t), INTENT(INOUT) :: TP
66 TYPE(trip_grid_t), INTENT(INOUT) :: TPG
67 !
68 INTEGER, INTENT(IN) :: KLISTING
69 INTEGER, INTENT(IN) :: KLON
70 INTEGER, INTENT(IN) :: KLAT
71 REAL, INTENT(IN) :: PTIMEC ! Cumulated run time step (s)
72 !
73 REAL, DIMENSION(:,:), INTENT(OUT) :: PRUNOFF ! Surface runoff (kg/s)
74 REAL, DIMENSION(:,:), INTENT(OUT) :: PDRAIN ! Deep drainage (kg/s)
75 REAL, DIMENSION(:,:), INTENT(OUT) :: PCALVING ! Calving flux (kg/s)
76 REAL, DIMENSION(:,:), INTENT(OUT) :: PSRC_FLOOD ! Input P-E-I flood source term (kg/s)
77 !
78 !
79 !* 0.2 Declarations of local variables
80 ! -------------------------------
81 !
82 REAL, DIMENSION(KLON,KLAT) :: ZREAD
83 REAL, DIMENSION(KLON,KLAT) :: ZSRC_FLOOD
84 REAL, DIMENSION(KLON,KLAT) :: ZWORK
85 REAL, DIMENSION(KLON,KLAT) :: ZRESIDU
86 !
87  CHARACTER(LEN=50) :: YCOMMENT
88 INTEGER :: IDATE ! current coupling time step (s)
89 INTEGER :: IERR ! Error info
90 INTEGER :: JVAR
91 !
92 REAL(KIND=JPRB) :: ZHOOK_HANDLE
93 !
94 !-------------------------------------------------------------------------------
95 #ifdef CPLOASIS
96 !-------------------------------------------------------------------------------
97 !
98 IF (lhook) CALL dr_hook('TRIP_OASIS_RECV',0,zhook_handle)
99 !
100 !* 1. Initialize :
101 ! ------------
102 !
103 idate = int(ptimec)
104 !
105 pdrain(:,:) = 0.0
106 prunoff(:,:) = 0.0
107 pcalving(:,:) = 0.0
108 psrc_flood(:,:) = 0.0
109 !
110 !-------------------------------------------------------------------------------
111 !
112 !* 2. Get coupling fields :
113 ! ---------------------
114 !
115 IF(lcpl_land.AND.mod(ptimec,xtstep_cpl_land)==0.0)THEN
116 !
117 ! * Receive surface runoff input fields
118 !
119  zread(:,:) = xundef
120  ycomment='Surface runoff'
121  CALL oasis_get(nrunoff_id,idate,zread(:,:),ierr)
122  CALL check_trip_recv(ierr,ycomment,zread,tpg%GMASK)
123  CALL kgm2s_to_kgs(ierr,zread,prunoff)
124 !
125 ! * Receive drainage/recharge input fields
126 !
127  zread(:,:) = xundef
128  ycomment='Deep drainage'
129  CALL oasis_get(ndrain_id,idate,zread(:,:),ierr)
130  CALL check_trip_recv(ierr,ycomment,zread,tpg%GMASK)
131 !
132  IF(lcpl_gw)THEN
133 ! Redistribute negative recharge flux over groundwater
134 ! and conserve water mass over each bassin
135  zwork(:,:) = xundef
136  CALL gw_redistrib(tp,tpg, &
137  klon,klat,zread,zwork)
138  ELSE
139  zwork(:,:) = zread(:,:)
140  ENDIF
141 !
142  CALL kgm2s_to_kgs(ierr,zwork,pdrain)
143 !
144 ! * Receive calving input fields
145 !
146  IF(lcpl_calving)THEN
147  zread(:,:) = xundef
148  ycomment='calving flux'
149  CALL oasis_get(ncalving_id,idate,zread(:,:),ierr)
150  CALL check_trip_recv(ierr,ycomment,zread,tpg%GMASK)
151  CALL kgm2s_to_kgs(ierr,zread,pcalving)
152  ENDIF
153 !
154 ! * Receive floodplains input fields
155 !
156  IF(lcpl_flood)THEN
157 !
158  zread(:,:) = xundef
159  zsrc_flood(:,:) = xundef
160  zwork(:,:) = xundef
161  zresidu(:,:) = xundef
162 !
163  ycomment='floodplains freshwater flux (P-E-I)'
164  CALL oasis_get(nsrcflood_id,idate,zread(:,:),ierr)
165  CALL check_trip_recv(ierr,ycomment,zread,tpg%GMASK_FLD)
166 !
167 ! Redistribute freshwater flux over flooded grid-cell
168 ! and conserve water mass over each bassin
169  CALL flood_redistrib(tp,tpg, &
170  klon,klat,xtstep_cpl_land, &
171  zread,zsrc_flood,zwork )
172 !
173  CALL kgm2s_to_kgs(ierr,zsrc_flood,psrc_flood)
174  CALL kgm2s_to_kgs(ierr,zwork,zresidu)
175 !
176  WHERE(tpg%GMASK_FLD(:,:))
177  prunoff(:,:)=prunoff(:,:)+zresidu(:,:)
178  ENDWHERE
179 !
180  ENDIF
181 !
182 ENDIF
183 !
184 IF (lhook) CALL dr_hook('TRIP_OASIS_RECV',1,zhook_handle)
185 !
186 !-------------------------------------------------------------------------------
187  CONTAINS
188 !-------------------------------------------------------------------------------
189 !
190 SUBROUTINE check_trip_recv(KERR,HCOMMENT,PFIELD,OMASK)
191 !
192 USE modi_abort_trip
193 !
194 IMPLICIT NONE
195 !
196 INTEGER, INTENT(IN ) :: KERR
197  CHARACTER(LEN=*), INTENT(IN ) :: HCOMMENT
198 REAL, DIMENSION(:,:), INTENT(INOUT) :: PFIELD
199 LOGICAL, DIMENSION(:,:), INTENT(IN ) :: OMASK
200 !
201 REAL(KIND=JPRB) :: ZHOOK_HANDLE
202 !
203 IF (lhook) CALL dr_hook('TRIP_OASIS_RECV:CHECK_TRIP_RECV',0,zhook_handle)
204 !
205 ! Check receiving field
206 !
207 IF (kerr/=oasis_ok.AND.kerr<oasis_recvd) THEN
208  WRITE(klisting,'(A,I4)')'Return code from receiving '//trim(hcomment)//' : ',kerr
209  CALL abort_trip('TRIP_OASIS_RECV: problem receiving '//trim(hcomment))
210 ENDIF
211 !
212 WHERE(.NOT.omask(:,:))
213  pfield(:,:) = 0.0
214 ENDWHERE
215 !
216 IF (lhook) CALL dr_hook('TRIP_OASIS_RECV:CHECK_TRIP_RECV',1,zhook_handle)
217 !
218 END SUBROUTINE check_trip_recv
219 !
220 !-------------------------------------------------------------------------------
221 !
222 SUBROUTINE kgm2s_to_kgs(KERR,PIN,POUT)
223 !
224 IMPLICIT NONE
225 !
226 INTEGER, INTENT(IN ) :: KERR
227 REAL, DIMENSION(:,:), INTENT(IN ) :: PIN
228 REAL, DIMENSION(:,:), INTENT(OUT) :: POUT
229 !
230 REAL(KIND=JPRB) :: ZHOOK_HANDLE
231 !
232 IF (lhook) CALL dr_hook('TRIP_OASIS_RECV:KGM2S_TO_KGS',0,zhook_handle)
233 !
234 ! kg/m2/s -> kg/s
235 !
236 IF(kerr>=oasis_recvd)THEN
237  WHERE(tpg%GMASK(:,:))
238  pout(:,:) = pin(:,:) * tpg%XAREA(:,:)
239  ELSEWHERE
240  pout(:,:) = xundef
241  ENDWHERE
242 ELSE
243  pout(:,:) = 0.0
244 ENDIF
245 !
246 IF (lhook) CALL dr_hook('TRIP_OASIS_RECV:KGM2S_TO_KGS',1,zhook_handle)
247 !
248 END SUBROUTINE kgm2s_to_kgs
249 !
250 !-------------------------------------------------------------------------------
251 #endif
252 !-------------------------------------------------------------------------------
253 !
254 END SUBROUTINE trip_oasis_recv
static const char * trim(const char *name, int *n)
Definition: drhook.c:2383
subroutine gw_redistrib(TP, TPG, KLON, KLAT, PREAD, PFOUT)
Definition: gw_redistrib.F90:4
subroutine check_trip_recv(KERR, HCOMMENT, PFIELD, OMASK)
integer, parameter jprb
Definition: parkind1.F90:32
subroutine flood_redistrib(TP, TPG,
logical lhook
Definition: yomhook.F90:15
subroutine abort_trip(YTEXT)
Definition: abort_trip.F90:3
subroutine kgm2s_to_kgs(KERR, PIN, POUT)
subroutine trip_oasis_recv(TP, TPG, KLISTING, KLON, KLAT, PTIMEC, PRUNOFF, PDRAIN, PCALVING, PSRC_FLOOD)
real, save xundef