@@ -15,6 +15,7 @@ module GEOS_LdasGridCompMod
1515 use GEOS_EnsGridCompMod, only: EnsSetServices = > SetServices
1616 use GEOS_LandAssimGridCompMod, only: LandAssimSetServices = > SetServices
1717 use GEOS_LandiceGridCompMod, only: LandiceSetServices = > SetServices
18+ use GEOS_RouteGridCompMod, only: RouteSetServices = > SetServices
1819
1920 use LDAS_TileCoordType, only: tile_coord_type , T_TILECOORD_STATE, TILECOORD_WRAP
2021 use LDAS_TileCoordType, only: grid_def_type, io_grid_def_type, operator (==)
@@ -51,6 +52,7 @@ module GEOS_LdasGridCompMod
5152 ! All children
5253 integer ,allocatable :: LAND(:)
5354 integer ,allocatable :: LANDICE(:)
55+ integer ,allocatable :: ROUTE(:)
5456 integer ,allocatable :: LANDPERT(:)
5557 integer ,allocatable :: METFORCE(:)
5658 integer :: ENSAVG, LANDASSIM
@@ -62,6 +64,7 @@ module GEOS_LdasGridCompMod
6264 logical :: ensemble_forcing ! switch between deterministic and ensemble forcing
6365 logical :: with_landice ! true if landice tiles requested by config
6466 logical :: with_land ! true if land tiles requested by config
67+ integer :: RUN_ROUTE ! 0:, no river routing, 1: routing w/o reservoirs, 2: routing w/ reservoirs
6568
6669contains
6770
@@ -143,13 +146,15 @@ subroutine SetServices(gc, rc)
143146 ! create ensemble children
144147 call MAPL_GetObjectFromGC(gc, MAPL, rc= status)
145148 VERIFY_(status)
146- call MAPL_GetResource ( MAPL, NUM_ENSEMBLE, Label= " NUM_LDAS_ENSEMBLE:" , DEFAULT= 1 , RC= STATUS)
149+ call MAPL_GetResource ( MAPL, NUM_ENSEMBLE, Label= " NUM_LDAS_ENSEMBLE:" , DEFAULT= 1 , RC= STATUS)
147150 VERIFY_(STATUS)
148- call MAPL_GetResource ( MAPL, ens_id_width, Label= " ENS_ID_WIDTH:" , DEFAULT= 0 , RC= STATUS)
151+ call MAPL_GetResource ( MAPL, ens_id_width, Label= " ENS_ID_WIDTH:" , DEFAULT= 0 , RC= STATUS)
149152 VERIFY_(STATUS)
150- call MAPL_GetResource ( MAPL, FIRST_ENS_ID, Label= " FIRST_ENS_ID:" , DEFAULT= 0 , RC= STATUS)
153+ call MAPL_GetResource ( MAPL, RUN_ROUTE, Label= " RUN_ROUTE:" , DEFAULT= 0 , RC= STATUS)
154+ VERIFY_(STATUS)
155+ call MAPL_GetResource ( MAPL, FIRST_ENS_ID, Label= " FIRST_ENS_ID:" , DEFAULT= 0 , RC= STATUS)
151156 VERIFY_(STATUS)
152- call MAPL_GetResource ( MAPL, ENS_FORCING_STR, Label= " ENSEMBLE_FORCING:" , DEFAULT= " NO" , RC= STATUS)
157+ call MAPL_GetResource ( MAPL, ENS_FORCING_STR, Label= " ENSEMBLE_FORCING:" , DEFAULT= " NO" , RC= STATUS)
153158 VERIFY_(STATUS)
154159 ENS_FORCING_STR = ESMF_UtilStringUpperCase(ENS_FORCING_STR, rc= STATUS)
155160 VERIFY_(STATUS)
@@ -174,6 +179,10 @@ subroutine SetServices(gc, rc)
174179 if (any (tile_types == MAPL_LAND )) with_land = .true.
175180! if (any(tile_types == MAPL_LAKE )) with_lake = .true.
176181
182+ if (NUM_ENSEMBLE> 1 ) then
183+ _ASSERT( .not. (with_landice .or. RUN_ROUTE> 0 ), " Landice and route not supported in ensemble mode." )
184+ endif
185+
177186 call MAPL_GetResource ( MAPL, LAND_ASSIM_STR, Label= " LAND_ASSIM:" , DEFAULT= " NO" , RC= STATUS)
178187 VERIFY_(STATUS)
179188 LAND_ASSIM_STR = ESMF_UtilStringUpperCase(LAND_ASSIM_STR, rc= STATUS)
@@ -205,7 +214,10 @@ subroutine SetServices(gc, rc)
205214
206215 if (with_land) allocate (LAND( NUM_ENSEMBLE),LANDPERT(NUM_ENSEMBLE))
207216 if (with_landice) allocate (LANDICE(NUM_ENSEMBLE))
208-
217+ if (RUN_ROUTE >= 1 ) then
218+ _ASSERT( with_land, " RUNOFF must be from the export of land_gridcomp for now." )
219+ allocate (ROUTE(NUM_ENSEMBLE))
220+ endif
209221 ! ens_id_with = 2 + number of digits = total number of chars in ensid_string ("_eXXXX")
210222 !
211223 ! Assert ens_id_width<=2+9 so number of digits remains single-digit and "I1" can be
@@ -253,6 +265,12 @@ subroutine SetServices(gc, rc)
253265 LANDICE(i) = MAPL_AddChild(gc, name= childname, ss= LandiceSetServices, rc= status)
254266 VERIFY_(status)
255267 endif
268+
269+ if (RUN_ROUTE >= 1 ) then
270+ childname= ' ROUTE' // trim (ensid_string)
271+ ROUTE(i) = MAPL_AddChild(gc, name= childname, ss= RouteSetServices, rc= status)
272+ VERIFY_(status)
273+ endif
256274 enddo
257275
258276 if (with_land) then
@@ -302,6 +320,17 @@ subroutine SetServices(gc, rc)
302320 rc = status &
303321 )
304322 VERIFY_(status)
323+
324+ IF (RUN_ROUTE >= 1 ) THEN
325+ call MAPL_AddConnectivity ( &
326+ GC ,&
327+ SHORT_NAME = (/ ' RUNOFF ' / ) ,& ! RUNOFF = total runoff = surface runoff + baseflow
328+ SRC_ID = LAND(I) ,&
329+ DST_ID = ROUTE(I) ,&
330+ RC= STATUS )
331+ VERIFY_(STATUS)
332+ ENDIF
333+
305334 enddo
306335
307336 if (land_assim .or. mwRTM) then
@@ -788,6 +817,13 @@ subroutine Initialize(gc, import, export, clock, rc)
788817 call MAPL_Set(CHILD_MAPL, LocStream= landice_locstream, rc= status)
789818 VERIFY_(status)
790819 endif
820+
821+ if (RUN_ROUTE >= 1 ) then
822+ call MAPL_GetObjectFromGC(gcs(ROUTE(i)), CHILD_MAPL, rc= status)
823+ VERIFY_(status) ! CHILD = ens_avg
824+ call MAPL_Set(CHILD_MAPL, LocStream= land_locstream, rc= status)
825+ VERIFY_(status)
826+ endif
791827
792828 enddo
793829
@@ -1016,6 +1052,16 @@ subroutine Run(gc, import, export, clock, rc)
10161052 call MAPL_TimerOff(MAPL, gcnames(igc))
10171053 endif ! with_land_ice
10181054
1055+ if ( RUN_ROUTE >= 1 ) then
1056+ igc = ROUTE(i)
1057+ call MAPL_TimerOn(MAPL, gcnames(igc))
1058+ call ESMF_GridCompRun(gcs(igc), importState= gim(igc), exportState= gex(igc), clock= clock, phase= 1 , userRC= status)
1059+ VERIFY_(status)
1060+ call ESMF_GridCompRun(gcs(ENSAVG), importState= gex(igc), exportState= gex(ENSAVG), clock= clock,phase= 4 , userRC= status)
1061+ VERIFY_(status)
1062+ call MAPL_TimerOff(MAPL, gcnames(igc))
1063+ endif ! river-routine
1064+
10191065 if (with_land) then
10201066 ! ApplyPrognPert - moved: now before calculating ensemble average that is picked up by land analysis and HISTORY; reichle 28 May 2020
10211067 igc = LANDPERT(i)
0 commit comments