source: branches/ORCHIDEE_2_2/ORCHIDEE/src_sechiba/routing_wrapper.f90 @ 8548

Last change on this file since 8548 was 8548, checked in by josefine.ghattas, 4 weeks ago

Integrated changes from [8536] done by Laurent Fairhead and Amaury Barral, LMD, needed for compiler gfortran.

  • Property svn:keywords set to Date Revision HeadURL
File size: 21.2 KB
Line 
1! ================================================================================================================================
2!  MODULE       : routing_wrapper
3!
4!  CONTACT      : orchidee-help _at_ listes.ipsl.fr
5!
6!  LICENCE      : IPSL (2006)
7!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
8!
9!>\BRIEF          Interfaces to all routing schemes.
10!!
11!!\n DESCRIPTION: This module contains uniformed subroutines called from sechiba. These subroutines make the swich the between
12!!                the different existing routing modules.
13!!               
14!!                Depending on the key world ROUTING_METHOD set in run.def, this module calls one of the
15!!                available routing modules:
16!!                - ROUTING_METOD=standard for the standard routing scheme available in module routing.
17!!                - ROUTING_METHOD=simple for the routing scheme in module routing_simple.
18!!                - ROUTING_METHOD=highres for the high resolution routing scheme in module routing_highres.
19!!
20!! REFERENCE(S) : None
21!!
22!! SVN          :
23!! $HeadURL$
24!! $Date$
25!! $Revision$
26!! \n
27!_ ================================================================================================================================
28
29MODULE routing_wrapper
30
31  USE defprec
32  USE pft_parameters
33  USE grid, not_used => contfrac
34  USE routing
35  USE routing_highres
36  USE routing_simple
37  USE routing_native_mod
38  USE constantes_soil
39
40  IMPLICIT NONE
41
42  CHARACTER(LEN=255), SAVE :: routing_method                      !! 'standard', 'highres' or 'simple': Character string used to switch between routing modules
43  !$OMP THREADPRIVATE(routing_method)
44
45  PUBLIC :: routing_wrapper_xios_initialize, routing_wrapper_initialize, &
46            routing_wrapper_main, routing_wrapper_finalize, routing_wrapper_clear 
47  PRIVATE
48
49CONTAINS
50
51!!  =============================================================================================================================
52!! SUBROUTINE:    routing_wrapper_xios_initialize
53!!
54!>\BRIEF          First initialization phase of the choosen routing module
55!!
56!! DESCRIPTION:   Read ROUTING_METHOD from run.def and call the xios initialization subroutine from corresponding routing module.
57!!                This subroutine is called before the xios context is closed.
58!!                It is called from sechiba_initialize only if 1 is activated.
59!!
60!! RECENT CHANGE(S): None
61!!
62!! REFERENCE(S): None
63!!
64!! FLOWCHART: None
65!! \n
66!_ ==============================================================================================================================
67  SUBROUTINE routing_wrapper_xios_initialize()
68
69    ! Get ROUTING_METHOD from run.def. Note that this is also done in
70    ! routing_wrapper_initialize because current subroutine is not alwyas called.
71    routing_method='standard'
72    CALL getin_p("ROUTING_METHOD",routing_method)
73    IF(routing_method=='standard') THEN
74       CALL routing_xios_initialize
75    ELSEIF(routing_method=='highres') THEN
76       CALL routing_highres_xios_initialize
77    ELSEIF(routing_method=='simple') THEN 
78#ifdef XIOS
79       CALL routing_simple_xios_initialize
80    ELSEIF(routing_method=='native') THEN
81       CALL routing_native_xios_initialize
82#else
83       CALL ipslerr_p(3,'routing_wrapper_xios_inititalize','ROUTING_METHOD simple and native needs XIOS',&
84                        'You must compile XIOS and then ORCHIDEE with cpp key XIOS','')
85#endif
86    ENDIF
87
88  END SUBROUTINE routing_wrapper_xios_initialize
89
90
91
92
93!!  =============================================================================================================================
94!! SUBROUTINE:    routing_wrapper_initialize
95!!
96!>\BRIEF          Initialize the choosen routing module
97!!
98!! DESCRIPTION:   Read ROUTING_METHOD from run.def and call the initialization subroutine from corresponding routing module
99!!
100!! RECENT CHANGE(S): None
101!!
102!! REFERENCE(S): None
103!!
104!! FLOWCHART: None
105!! \n
106!_ ==============================================================================================================================
107  SUBROUTINE routing_wrapper_initialize( &
108       kjit,        nbpt,           index,                 &
109       rest_id,     hist_id,        hist2_id,   lalo,      &
110       neighbours,  resolution,     contfrac,   stempdiag, ftempdiag, &
111       soiltile,    irrig_frac,     veget_max,  irrigated_next, &   
112       returnflow,  reinfiltration, irrigation, riverflow, &
113       coastalflow, flood_frac,     flood_res )
114
115
116    !! 0.1 Input variables
117    INTEGER(i_std), INTENT(in)     :: kjit                 !! Time step number (unitless)
118    INTEGER(i_std), INTENT(in)     :: nbpt                 !! Domain size (unitless)
119    INTEGER(i_std), INTENT(in)     :: index(nbpt)          !! Indices of the points on the map (unitless)
120    INTEGER(i_std),INTENT(in)      :: rest_id              !! Restart file identifier (unitless)
121    INTEGER(i_std),INTENT(in)      :: hist_id              !! Access to history file (unitless)
122    INTEGER(i_std),INTENT(in)      :: hist2_id             !! Access to history file 2 (unitless)
123    REAL(r_std), INTENT(in)        :: lalo(nbpt,2)         !! Vector of latitude and longitudes (beware of the order !)
124
125    INTEGER(i_std), INTENT(in)     :: neighbours(nbpt,8)   !! Vector of neighbours for each grid point
126                                                           !! (1=N, 2=NE, 3=E, 4=SE, 5=S, 6=SW, 7=W, 8=NW) (unitless)
127    REAL(r_std), INTENT(in)        :: resolution(nbpt,2)   !! The size of each grid box in X and Y (m)
128    REAL(r_std), INTENT(in)        :: contfrac(nbpt)       !! Fraction of land in each grid box (unitless;0-1)
129    REAL(r_std), INTENT(in)        :: stempdiag(nbpt,nslm) !! Diagnostic soil temperature profile
130    REAL(r_std), INTENT(in)        :: ftempdiag(nbpt,ngrnd)!! Diagnostic soil temperature profile over full column
131    REAL(r_std), INTENT(in)        :: soiltile(nbpt,nstm)  !! Fraction of each soil tile within vegtot (0-1, unitless)
132    REAL(r_std), INTENT(in)        :: veget_max(nbpt,nvm)  !! Maximal fraction of vegetation (unitless;0-1) !
133    REAL(r_std), INTENT(in)        :: irrigated_next (nbpt)!! Dynamic irrig. area, calculated in slowproc and passed to routing!
134    REAL(r_std), INTENT(in)        :: irrig_frac(nbpt)     !! Irrig. fraction interpolated in routing, and saved to pass to slowproc if irrigated_soiltile = .TRUE.
135
136
137    !! 0.2 Output variables
138    REAL(r_std), INTENT(out)       :: returnflow(nbpt)     !! The water flow from lakes and swamps which returns to the grid box.
139                                                           !! This water will go back into the hydrol or hydrolc module to allow re-evaporation (kg/m^2/dt)
140    REAL(r_std), INTENT(out)       :: reinfiltration(nbpt) !! Water flow from ponds and floodplains which returns to the grid box (kg/m^2/dt)
141    REAL(r_std), INTENT(out)       :: irrigation(nbpt)     !! Irrigation flux. This is the water taken from the reservoirs and beeing put into the upper layers of the soil (kg/m^2/dt)
142    REAL(r_std), INTENT(out)       :: riverflow(nbpt)      !! Outflow of the major rivers. The flux will be located on the continental grid but this should be a coastal point (kg/dt)
143    REAL(r_std), INTENT(out)       :: coastalflow(nbpt)    !! Outflow on coastal points by small basins. This is the water which flows in a disperse way into the ocean (kg/dt)
144    REAL(r_std), INTENT(out)       :: flood_frac(nbpt)     !! Flooded fraction of the grid box (unitless;0-1)
145    REAL(r_std), INTENT(out)       :: flood_res(nbpt)      !! Diagnostic of water amount in the floodplains reservoir (kg)
146
147
148    !_ ================================================================================================================================
149
150    !! 1. Get routing_method from run.def
151    !!    This variable will switch between the existing modules for the routing scheme.
152
153    !Config Key   = ROUTING_METHOD
154    !Config Desc  = Choice of routing module to be used
155    !Config If    = RIVER_ROUTING=T
156    !Config Def   = standard
157    !Config Help  = Possible options are standard and simple
158    !Config Units = character string
159
160    routing_method='standard'
161    CALL getin_p("ROUTING_METHOD",routing_method)
162
163
164    !! 2. Initialize the choosen routing module
165    IF (routing_method == 'standard') THEN
166
167       CALL routing_initialize(  kjit,        nbpt,           index,                 &
168                                 rest_id,     hist_id,        hist2_id,   lalo,      &
169                                 neighbours,  resolution,     contfrac,   stempdiag, &
170                                 returnflow,  reinfiltration, irrigation, riverflow, &
171                                 coastalflow, flood_frac,     flood_res,  soiltile,  &
172                                 irrig_frac,  veget_max,      irrigated_next)
173
174    ELSE IF (routing_method == 'highres') THEN
175
176       CALL routing_highres_initialize(  kjit,        nbpt,           index,                 &
177                                 rest_id,     hist_id,        hist2_id,   lalo,      &
178                                 neighbours,  resolution,     contfrac,   stempdiag, &
179                                 returnflow,  reinfiltration, irrigation, riverflow, &
180                                 coastalflow, flood_frac,     flood_res )
181
182    ELSE IF(routing_method== 'simple') THEN 
183#ifdef XIOS
184       CALL routing_simple_initialize(    kjit,        nbpt,           index,                 &
185                                          rest_id,     hist_id,        hist2_id,   lalo,      &
186                                          neighbours,  resolution,     contfrac,   stempdiag, &
187                                          returnflow,  reinfiltration, irrigation, riverflow, &
188                                          coastalflow, flood_frac,     flood_res )
189#endif
190       riverflow(:) = zero
191       coastalflow(:) = zero
192       returnflow(:) = zero
193       reinfiltration(:) = zero
194       irrigation(:) = zero
195       flood_frac(:) = zero
196       flood_res(:) = zero
197   
198    ELSE IF(routing_method== 'native') THEN
199#ifdef XIOS
200       CALL routing_native_initialize(    kjit,        nbpt,           index,                 &
201                                          rest_id,     hist_id,        hist2_id,   lalo,      &
202                                          neighbours,  resolution,     contfrac,   stempdiag, &
203                                          returnflow,  reinfiltration, irrigation, riverflow, &
204                                          coastalflow, flood_frac,     flood_res , irrigated_next)
205#endif
206       riverflow(:) = zero
207       coastalflow(:) = zero
208       returnflow(:) = zero
209       reinfiltration(:) = zero
210       irrigation(:) = zero
211       flood_frac(:) = zero
212       flood_res(:) = zero
213
214    ELSE
215       ! Bad choice of routing_method. Exit the model now.
216       WRITE(numout,*) 'Following routing method is not implemented, ROUTING_METHOD=',routing_method
217       CALL ipslerr_p(3,'routing_wrapper_inititalize','ROUTING_METHOD can only be standard or simple','Error in run.def','')
218    ENDIF
219
220  END SUBROUTINE routing_wrapper_initialize
221
222
223
224!!  =============================================================================================================================
225!! SUBROUTINE:    routing_wrapper_main
226!!
227!>\BRIEF          Call the main subroutine for the choosen routing module
228!!
229!! DESCRIPTION:   Call the main subroutine for the choosen routing module according to ROUTING_METHOD
230!!
231!! RECENT CHANGE(S): None
232!!
233!! REFERENCE(S): None
234!!
235!! FLOWCHART: None
236!! \n
237!_ ==============================================================================================================================
238  SUBROUTINE routing_wrapper_main(kjit, nbpt, index, &
239       lalo, neighbours, resolution, contfrac, totfrac_nobio, veget_max, floodout, runoff, &
240       drainage, transpot, precip_rain, humrel, k_litt, flood_frac, flood_res, stempdiag, &
241       ftempdiag, reinf_slope, returnflow, reinfiltration, irrigation, riverflow, coastalflow, rest_id, hist_id, hist2_id, &
242       soiltile, root_deficit, irrigated_next, irrig_frac, fraction_aeirrig_sw) 
243
244    IMPLICIT NONE
245
246    !! 0.1 Input variables
247    INTEGER(i_std), INTENT(in)     :: kjit                 !! Time step number (unitless)
248    INTEGER(i_std), INTENT(in)     :: nbpt                 !! Domain size (unitless)
249    INTEGER(i_std),INTENT(in)      :: rest_id              !! Restart file identifier (unitless)
250    INTEGER(i_std),INTENT(in)      :: hist_id              !! Access to history file (unitless)
251    INTEGER(i_std),INTENT(in)      :: hist2_id             !! Access to history file 2 (unitless)
252    INTEGER(i_std), INTENT(in)     :: index(nbpt)          !! Indices of the points on the map (unitless)
253    REAL(r_std), INTENT(in)        :: lalo(nbpt,2)         !! Vector of latitude and longitudes (beware of the order !)
254    INTEGER(i_std), INTENT(in)     :: neighbours(nbpt,NbNeighb)   !! Vector of neighbours for each grid point (1=N, 2=NE, 3=E, 4=SE, 5=S, 6=SW, 7=W, 8=NW) (unitless)
255    REAL(r_std), INTENT(in)        :: resolution(nbpt,2)   !! The size of each grid box in X and Y (m)
256    REAL(r_std), INTENT(in)        :: contfrac(nbpt)       !! Fraction of land in each grid box (unitless;0-1)
257    REAL(r_std), INTENT(in)        :: totfrac_nobio(nbpt)  !! Total fraction of no-vegetation (continental ice, lakes ...) (unitless;0-1)
258    REAL(r_std), INTENT(in)        :: veget_max(nbpt,nvm)  !! Maximal fraction of vegetation (unitless;0-1)
259    REAL(r_std), INTENT(in)        :: floodout(nbpt)       !! Grid-point flow out of floodplains (kg/m^2/dt)
260    REAL(r_std), INTENT(in)        :: runoff(nbpt)         !! Grid-point runoff (kg/m^2/dt)
261    REAL(r_std), INTENT(in)        :: drainage(nbpt)       !! Grid-point drainage (kg/m^2/dt)
262    REAL(r_std), INTENT(in)        :: transpot(nbpt,nvm)   !! Potential transpiration of the vegetation (kg/m^2/dt)
263    REAL(r_std), INTENT(in)        :: precip_rain(nbpt)    !! Rainfall (kg/m^2/dt)
264    REAL(r_std), INTENT(in)        :: k_litt(nbpt)         !! Averaged conductivity for saturated infiltration in the 'litter' layer (kg/m^2/dt)
265    REAL(r_std), INTENT(in)        :: humrel(nbpt,nvm)     !! Soil moisture stress, root extraction potential (unitless)
266    REAL(r_std), INTENT(in)        :: stempdiag(nbpt,nslm) !! Diagnostic soil temperature profile
267    REAL(r_std), INTENT(in)        :: ftempdiag(nbpt,ngrnd)!! Diagnostic soil temperature profile over full column
268    REAL(r_std), INTENT(in)        :: reinf_slope(nbpt)    !! Coefficient which determines the reinfiltration ratio in the grid box due to flat areas (unitless;0-1)
269    REAL(r_std), INTENT(in)        :: root_deficit(nbpt)   !! soil water deficit
270    REAL(r_std), INTENT(in)        :: soiltile(nbpt,nstm)  !! Fraction of each soil tile within vegtot (0-1, unitless)
271    REAL(r_std), INTENT(in)        :: irrig_frac(nbpt)     !! Irrig. fraction interpolated in routing, and saved to pass to slowproc if irrigated_soiltile = .TRUE.
272    REAL(r_std), INTENT(in)        :: irrigated_next (nbpt)!! Dynamic irrig. area, calculated in slowproc and passed to routing
273    REAL(r_std), INTENT(in)        :: fraction_aeirrig_sw(nbpt) !! Fraction of area equipped for irrigation from surface water, of irrig_frac
274
275    !! 0.2 Output variables
276    REAL(r_std), INTENT(out)       :: returnflow(nbpt)     !! The water flow from lakes and swamps which returns to the grid box.
277    !! This water will go back into the hydrol module to allow re-evaporation (kg/m^2/dt)
278    REAL(r_std), INTENT(out)       :: reinfiltration(nbpt) !! Water flow from ponds and floodplains which returns to the grid box (kg/m^2/dt)
279    REAL(r_std), INTENT(out)       :: irrigation(nbpt)     !! Irrigation flux. This is the water taken from the reservoirs and beeing put into the upper layers of the soil (kg/m^2/dt)
280    REAL(r_std), INTENT(out)       :: riverflow(nbpt)      !! Outflow of the major rivers. The flux will be located on the continental grid but this should be a coastal point (kg/dt)
281    REAL(r_std), INTENT(out)       :: coastalflow(nbpt)    !! Outflow on coastal points by small basins. This is the water which flows in a disperse way into the ocean (kg/dt)
282    REAL(r_std), INTENT(out)       :: flood_frac(nbpt)     !! Flooded fraction of the grid box (unitless;0-1)
283    REAL(r_std), INTENT(out)       :: flood_res(nbpt)      !! Diagnostic of water amount in the floodplains reservoir (kg)
284
285    !_ ================================================================================================================================
286
287    !! 1. Call the main subroutine from the routing module corresponding to the choice of ROUTING_METHOD
288
289    IF (routing_method=='standard') THEN
290
291       CALL routing_main (kjit, nbpt, index, &
292            lalo, neighbours, resolution, contfrac, totfrac_nobio, veget_max, floodout, runoff, &
293            drainage, transpot, precip_rain, humrel, k_litt, flood_frac, flood_res, &
294            stempdiag, reinf_slope, returnflow, reinfiltration, irrigation, riverflow, coastalflow, rest_id, hist_id, hist2_id, &
295            soiltile, root_deficit, irrigated_next, irrig_frac, fraction_aeirrig_sw)
296
297    ELSE IF (routing_method=='highres') THEN
298
299       CALL routing_highres_main (kjit, nbpt, index, &
300            lalo, neighbours, resolution, contfrac, totfrac_nobio, veget_max, floodout, runoff, &
301            drainage, transpot, precip_rain, humrel, k_litt, flood_frac, flood_res, &
302            ftempdiag, reinf_slope, returnflow, reinfiltration, irrigation, riverflow, coastalflow, rest_id, hist_id, hist2_id)
303
304    ELSE IF(routing_method=='simple') THEN 
305#ifdef XIOS
306       CALL routing_simple_main (kjit, nbpt, index, &
307            lalo, neighbours, resolution, contfrac, totfrac_nobio, veget_max, floodout, runoff, &
308            drainage, transpot, precip_rain, humrel, k_litt, flood_frac, flood_res, &
309            stempdiag, reinf_slope, returnflow, reinfiltration, irrigation, riverflow, coastalflow, &
310            rest_id, hist_id, hist2_id) 
311#endif
312    ELSE IF(routing_method=='native') THEN
313#ifdef XIOS
314       CALL routing_native_main (kjit, nbpt, index, &
315            lalo, neighbours, resolution, contfrac, totfrac_nobio, veget_max, floodout, runoff, &
316            drainage, transpot, precip_rain, humrel, k_litt, flood_frac, flood_res, &
317            stempdiag, reinf_slope, returnflow, reinfiltration, irrigation, riverflow, coastalflow, &
318            rest_id, hist_id, hist2_id, &
319            soiltile, root_deficit, irrigated_next, irrig_frac, fraction_aeirrig_sw) 
320#endif
321    ENDIF
322
323
324  END SUBROUTINE routing_wrapper_main
325
326
327!!  =============================================================================================================================
328!! SUBROUTINE:    routing_wrapper_finalize
329!!
330!>\BRIEF          Call the finalization subroutine for the choosen routing module
331!!
332!! DESCRIPTION:   Call the subroutine for finalization for the choosen routing module according to ROUTING_METHOD
333!!
334!! RECENT CHANGE(S): None
335!!
336!! REFERENCE(S): None
337!!
338!! FLOWCHART: None
339!! \n
340!_ ==============================================================================================================================
341  SUBROUTINE routing_wrapper_finalize( kjit, nbpt, rest_id, flood_frac, flood_res )
342
343    IMPLICIT NONE
344    !! 0.1 Input variables
345    INTEGER(i_std), INTENT(in)     :: kjit                 !! Time step number (unitless)
346    INTEGER(i_std), INTENT(in)     :: nbpt                 !! Domain size (unitless)
347    INTEGER(i_std),INTENT(in)      :: rest_id              !! Restart file identifier (unitless)
348    REAL(r_std), INTENT(in)        :: flood_frac(nbpt)     !! Flooded fraction of the grid box (unitless;0-1)
349    REAL(r_std), INTENT(in)        :: flood_res(nbpt)      !! Diagnostic of water amount in the floodplains reservoir (kg)
350
351    !_ ================================================================================================================================
352
353    !! 1. Call the finalization subroutine from the routing module corresponding to the choice of ROUTING_METHOD
354
355    IF (routing_method=='standard') THEN
356
357       CALL routing_finalize( kjit, nbpt, rest_id, flood_frac, flood_res )
358
359    ELSE IF (routing_method=='highres') THEN
360
361       CALL routing_highres_finalize( kjit, nbpt, rest_id, flood_frac, flood_res )
362
363    ELSE IF(routing_method=='simple') THEN 
364#ifdef XIOS
365       CALL routing_simple_finalize( kjit, nbpt, rest_id, flood_frac, flood_res )
366#endif
367    ELSE IF(routing_method=='native') THEN
368#ifdef XIOS
369       CALL routing_native_finalize( kjit, nbpt, rest_id, flood_frac, flood_res )
370#endif
371    ENDIF
372
373  END SUBROUTINE routing_wrapper_finalize
374
375
376!!  =============================================================================================================================
377!! SUBROUTINE:    routing_wrapper_clear
378!!
379!>\BRIEF          Call the clear subroutine for the choosen routing module
380!!
381!! DESCRIPTION:   Call the clear subroutine for the choosen routing module according to ROUTING_METHOD
382!!
383!! RECENT CHANGE(S): None
384!!
385!! REFERENCE(S): None
386!!
387!! FLOWCHART: None
388!! \n
389!_ ==============================================================================================================================
390  SUBROUTINE routing_wrapper_clear
391
392    IF (routing_method=='standard') THEN
393
394       CALL routing_clear
395
396    ELSE IF (routing_method=='highres') THEN
397
398       CALL routing_highres_clear
399
400    ELSE IF(routing_method=='simple') THEN 
401#ifdef XIOS
402       CALL routing_simple_clear
403#endif   
404    ELSE IF(routing_method=='native') THEN
405#ifdef XIOS
406       CALL routing_native_clear
407#endif
408    ENDIF
409
410  END SUBROUTINE routing_wrapper_clear
411
412END MODULE routing_wrapper
Note: See TracBrowser for help on using the repository browser.