25 use mo_kind,
only : i4, dp
26 use mo_message,
only : message, error_message
63 use mo_append,
only : append
71 integer(i4),
intent(in) :: idomain
73 integer(i4) :: nrows1, ncols1
75 integer(i4) :: nrows11, ncols11
79 integer(i4) :: icc, jcc
81 integer(i4) :: iu, id, jl, jr
84 integer(i4),
dimension(:, :),
allocatable :: l11id_on_l1
87 integer(i4),
dimension(:, :),
allocatable :: l1id_on_l11
90 integer(i4),
dimension(:, :),
allocatable :: dummy_2d_id
92 real(dp) :: cellfactorrbyh
94 integer(i4) :: cellfactorrbyh_inv
97 nrows1 =
level1(idomain)%nrows
98 nrows11 =
level11(idomain)%nrows
99 ncols1 =
level1(idomain)%ncols
100 ncols11 =
level11(idomain)%ncols
103 allocate (l11id_on_l1(nrows1, ncols1))
104 allocate (l1id_on_l11(nrows11, ncols11))
109 cellfactorrbyh =
level11(idomain)%cellsize /
level1(idomain)%cellsize
113 if (cellfactorrbyh .lt. 1._dp)
then
114 allocate (dummy_2d_id(nrows1, ncols1))
116 cellfactorrbyh_inv = int(1. / cellfactorrbyh, i4)
120 if(.not.
level1(idomain)%mask(icc, jcc)) cycle
123 iu = (icc - 1) * cellfactorrbyh_inv + 1
124 id = min(icc * cellfactorrbyh_inv, nrows11)
125 jl = (jcc - 1) * cellfactorrbyh_inv + 1
126 jr = min(jcc * cellfactorrbyh_inv, ncols11)
128 l1id_on_l11(iu : id, jl : jr) = merge(dummy_2d_id(icc, jcc),
nodata_i4,
level11(idomain)%mask(iu : id, jl : jr))
132 allocate (dummy_2d_id(nrows11, ncols11))
138 if(.not.
level11(idomain)%mask(icc, jcc)) cycle
142 iu = (icc - 1) * nint(cellfactorrbyh, i4) + 1
143 id = icc * nint(cellfactorrbyh, i4)
144 jl = (jcc - 1) * nint(cellfactorrbyh, i4) + 1
145 jr = jcc * nint(cellfactorrbyh, i4)
149 if(id > nrows1) id = nrows1
151 if(jr > ncols1) jr = ncols1
154 l11id_on_l1(iu : id, jl : jr) = merge(dummy_2d_id(icc, jcc),
nodata_i4,
level1(idomain)%mask(iu : id, jl : jr))
164 deallocate(l11id_on_l1, l1id_on_l11, dummy_2d_id)
229 use mo_append,
only : append
235 use mo_string_utils,
only : num2str
240 integer(i4),
intent(in) :: idomain
242 integer(i4) :: ncells0
244 integer(i4) :: nrows0, ncols0
246 integer(i4) :: s0, e0
248 integer(i4) :: nrows11, ncols11
251 integer(i4) :: nnodes
253 integer(i4) :: ii, jj, kk, ic, jc
255 integer(i4) :: iu, id
257 integer(i4) :: jl, jr
259 integer(i4) :: irow, jcol
261 integer(i4),
dimension(:, :),
allocatable :: id0
263 integer(i4),
dimension(:, :),
allocatable :: fdir0
265 integer(i4),
dimension(:, :),
allocatable :: facc0
267 integer(i4),
dimension(:, :),
allocatable :: fdir11
270 integer(i4),
dimension(:),
allocatable :: rowout
273 integer(i4),
dimension(:),
allocatable :: colout
275 integer(i4),
dimension(:, :),
allocatable :: drasc0
278 integer(i4),
dimension(:, :),
allocatable :: oloc
282 integer(i4) :: faccmax, idmax
285 integer(i4) :: noutlet
288 integer(i4) :: old_noutlet
293 type(
grid),
pointer :: level0_idomain => null()
316 nrows0 = level0_idomain%nrows
317 ncols0 = level0_idomain%ncols
318 ncells0 = level0_idomain%ncells
319 nrows11 =
level11(idomain)%nrows
320 ncols11 =
level11(idomain)%ncols
321 nnodes =
level11(idomain)%ncells
322 s0 = level0_idomain%iStart
323 e0 = level0_idomain%iEnd
325 allocate (id0(nrows0, ncols0))
326 allocate (facc0(nrows0, ncols0))
327 allocate (fdir0(nrows0, ncols0))
328 allocate (drasc0(nrows0, ncols0))
329 allocate (fdir11(nrows11, ncols11))
330 allocate (rowout(nnodes))
331 allocate (colout(nnodes))
332 allocate (oloc(1, 2))
346 id0(:, :) = unpack(level0_idomain%Id, level0_idomain%mask,
nodata_i4)
351 IF(ncells0 .EQ. nnodes)
THEN
352 oloc(1, :) = maxloc(facc0, level0_idomain%mask)
353 kk =
l0_l11_remap(idomain)%lowres_id_on_highres(oloc(1, 1), oloc(1, 2))
355 if(ncells0 .EQ. 1)
then
356 fdir11(1, 1) = fdir0(oloc(1, 1), oloc(1, 2))
358 fdir11(:, :) = fdir0(:, :)
360 fdir11(
level11(idomain)%CellCoor(kk, 1),
level11(idomain)%CellCoor(kk, 2)) = 0
363 ii =
level11(idomain)%CellCoor(kk, 1)
364 jj =
level11(idomain)%CellCoor(kk, 2)
369 ii = level0_idomain%CellCoor(kk, 1)
370 jj = level0_idomain%CellCoor(kk, 2)
380 irow = level0_idomain%CellCoor(ii, 1)
381 jcol = level0_idomain%CellCoor(ii, 2)
385 if ((irow .le. 0_i4) .or. (irow .gt. nrows0) .or. &
386 (jcol .le. 0_i4) .or. (jcol .gt. ncols0))
then
389 if (fdir0(irow, jcol) .le. 0) is_outlet = .true.
393 noutlet = noutlet + 1_i4
395 if (noutlet .eq. 1)
then
396 oloc(1, :) = level0_idomain%CellCoor(ii, :)
398 call append(oloc, level0_idomain%CellCoor(ii : ii, :))
401 kk =
l0_l11_remap(idomain)%lowres_id_on_highres(oloc(noutlet, 1), oloc(noutlet, 2))
402 drasc0(oloc(noutlet, 1), oloc(noutlet, 2)) = kk
409 if (maxval(facc0(iu : id, jl : jr)) .eq. facc0(oloc(noutlet, 1), oloc(noutlet, 2)))
then
411 rowout(kk) = oloc(noutlet, 1)
412 colout(kk) = oloc(noutlet, 2)
413 fdir11(
level11(idomain)%CellCoor(kk, 1),
level11(idomain)%CellCoor(kk, 2)) = 0
423 if (rowout(kk) > 0) cycle
425 ic =
level11(idomain)%CellCoor(kk, 1)
426 jc =
level11(idomain)%CellCoor(kk, 2)
439 if ((facc0(iu, jj) > faccmax) .and. &
440 (fdir0(iu, jj) == 32 .or. &
441 fdir0(iu, jj) == 64 .or. &
442 fdir0(iu, jj) == 128))
then
443 faccmax = facc0(iu, jj)
451 if ((facc0(ii, jr) > faccmax) .and. &
452 (fdir0(ii, jr) == 1 .or. &
453 fdir0(ii, jr) == 2 .or. &
454 fdir0(ii, jr) == 128))
then
455 faccmax = facc0(ii, jr)
463 if ((facc0(id, jj) > faccmax) .and. &
464 (fdir0(id, jj) == 2 .or. &
465 fdir0(id, jj) == 4 .or. &
466 fdir0(id, jj) == 8))
then
467 faccmax = facc0(id, jj)
475 if ((facc0(ii, jl) > faccmax) .and. &
476 (fdir0(ii, jl) == 8 .or. &
477 fdir0(ii, jl) == 16 .or. &
478 fdir0(ii, jl) == 32))
then
479 faccmax = facc0(ii, jl)
486 ii = level0_idomain%CellCoor(idmax, 1)
487 jj = level0_idomain%CellCoor(idmax, 2)
493 if (ii == iu .and. jj == jl)
then
494 select case (fdir0(ii, jj))
502 elseif (ii == iu .and. jj == jr)
then
503 select case (fdir0(ii, jj))
511 elseif (ii == id .and. jj == jl)
then
512 select case (fdir0(ii, jj))
520 elseif (ii == id .and. jj == jr)
then
521 select case (fdir0(ii, jj))
541 call error_message(
'Error L11_flow_direction: side = -1')
562 if (idomain .eq. 1)
then
563 call append(
l0_drasc, pack(drasc0(:, :), level0_idomain%mask))
564 else if (
domainmeta%L0DataFrom(idomain) == idomain)
then
565 call append(
l0_drasc, pack(drasc0(:, :), level0_idomain%mask))
570 old_noutlet =
size(
domain_mrm(idomain)%L0_rowOutlet, dim = 1)
571 if (noutlet .le. old_noutlet)
then
572 domain_mrm(idomain)%L0_rowOutlet(: noutlet) = oloc(:, 1)
573 domain_mrm(idomain)%L0_colOutlet(: noutlet) = oloc(:, 2)
576 domain_mrm(idomain)%L0_rowOutlet(: old_noutlet) = oloc(: old_noutlet, 1)
577 domain_mrm(idomain)%L0_colOutlet(: old_noutlet) = oloc(: old_noutlet, 2)
580 call append(
domain_mrm(idomain)%L0_rowOutlet, oloc(old_noutlet + 1 :, 1))
581 call append(
domain_mrm(idomain)%L0_colOutlet, oloc(old_noutlet + 1 :, 2))
592 call message(
' Domain: ' // num2str(idomain,
'(i3)'))
593 call message(
' Number of outlets found at Level 0:.. ' // num2str(noutlet,
'(i7)'))
594 call message(
' Number of outlets found at Level 11:. ' // num2str(count(fdir11 .eq. 0_i4),
'(i7)'))
597 deallocate(fdir0, facc0, fdir11, rowout, colout, drasc0)
632 use mo_append,
only : append
639 integer(i4),
intent(in) :: idomain
641 integer(i4),
dimension(:, :),
allocatable :: fdir11
643 integer(i4),
dimension(:, :),
allocatable :: dummy_2d_id
645 integer(i4) :: jj, kk, ic, jc
647 integer(i4) :: fn, tn
649 integer(i4),
dimension(:),
allocatable :: nlinkfromn, nlinkton
655 allocate (nlinkfromn(
level11(idomain)%nCells))
656 allocate (nlinkton(
level11(idomain)%nCells))
658 allocate (dummy_2d_id(
level11(idomain)%nrows,
level11(idomain)%ncols))
675 do kk = 1,
level11(idomain)%nCells
676 ic =
level11(idomain)%CellCoor(kk, 1)
677 jc =
level11(idomain)%CellCoor(kk, 2)
680 tn = dummy_2d_id(ic, jc)
693 call append(
l11_ton, nlinkton(:))
696 deallocate (fdir11, nlinkfromn, nlinkton)
730 use mo_append,
only : append
738 integer(i4),
intent(in) :: idomain
740 integer(i4) :: nlinks
743 integer(i4),
dimension(:),
allocatable :: nlinkfromn
746 integer(i4),
dimension(:),
allocatable :: nlinkton
749 integer(i4),
dimension(:),
allocatable :: nlinkrorder
752 integer(i4),
dimension(:),
allocatable :: nlinklabel
755 logical,
dimension(:),
allocatable :: nlinksink
758 integer(i4),
dimension(:),
allocatable :: netperm
760 integer(i4) :: ii, jj, kk
770 allocate (nlinkfromn(
level11(idomain)%nCells))
771 allocate (nlinkton(
level11(idomain)%nCells))
772 allocate (nlinkrorder(
level11(idomain)%nCells))
773 allocate (nlinklabel(
level11(idomain)%nCells))
774 allocate (nlinksink(
level11(idomain)%nCells))
775 allocate (netperm(
level11(idomain)%nCells))
779 nlinkrorder(1 : nlinks) = 1
781 nlinklabel(1 : nlinks) = 0
783 nlinksink(:) = .false.
787 if(
level11(idomain)%nCells .GT. 1)
then
792 loop1 :
do ii = 1, nlinks
793 loop2 :
do jj = 1, nlinks
794 if (jj == ii) cycle loop2
795 if (nlinkfromn(ii) == nlinkton(jj))
then
798 if (nlinkrorder(ii) == -9) cycle loop1
804 if (nlinkrorder(ii) == 1)
then
811 do while (minval(nlinkrorder(1 : nlinks)) < 0)
813 loop3 :
do ii = 1, nlinks
814 if (.NOT. nlinkrorder(ii) == -9) cycle loop3
816 loop4 :
do jj = 1, nlinks
817 if (jj == ii .OR. nlinkfromn(ii) /= nlinkton(jj))
then
819 else if (.NOT. (nlinkfromn(ii) == nlinkton(jj) .AND. nlinkrorder(jj) > 0))
then
835 if (
l11_fdir(
level11(idomain)%iStart + nlinkton(ii) - 1_i4) .eq. 0_i4) nlinksink(ii) = .true.
837 where(nlinksink) nlinklabel = 2
841 netperm(nlinkrorder(ii)) = ii
857 deallocate (nlinkfromn, nlinkton, nlinkrorder, nlinklabel, nlinksink, netperm)
889 use mo_append,
only : append
895 use mo_string_utils,
only : num2str
900 integer(i4),
intent(in) :: idomain
902 integer(i4) :: nlinks
905 integer(i4),
dimension(:),
allocatable :: rowout
908 integer(i4),
dimension(:),
allocatable :: colout
910 integer(i4),
dimension(:),
allocatable :: nlinkfromn
912 integer(i4),
dimension(:),
allocatable :: netperm
914 integer(i4),
dimension(:),
allocatable :: nlinkfromrow
916 integer(i4),
dimension(:),
allocatable :: nlinkfromcol
918 integer(i4),
dimension(:),
allocatable :: nlinktorow
920 integer(i4),
dimension(:),
allocatable :: nlinktocol
922 integer(i4),
dimension(:, :),
allocatable :: fdir0
924 integer(i4),
dimension(:, :),
allocatable :: drasc0
926 integer(i4) :: ii, rr, kk, s0, e0
928 integer(i4) :: inode, irow, jcol, prevrow, prevcol
931 integer(i4),
dimension(:, :),
allocatable :: oloc
934 integer(i4) :: noutlets
939 type(
grid),
pointer :: level0_idomain => null()
943 s0 = level0_idomain%iStart
944 e0 = level0_idomain%iEnd
948 nlinks =
level11(idomain)%nCells - noutlets
953 allocate (rowout(
level11(idomain)%nCells))
954 allocate (colout(
level11(idomain)%nCells))
955 allocate (nlinkfromn(
level11(idomain)%nCells))
956 allocate (netperm(
level11(idomain)%nCells))
957 allocate (nlinkfromrow(
level11(idomain)%nCells))
958 allocate (nlinkfromcol(
level11(idomain)%nCells))
959 allocate (nlinktorow(
level11(idomain)%nCells))
960 allocate (nlinktocol(
level11(idomain)%nCells))
961 allocate (fdir0(level0_idomain%nrows, level0_idomain%ncols))
962 allocate (drasc0(level0_idomain%nrows, level0_idomain%ncols))
977 if(
level11(idomain)%nCells .GT. 1)
then
989 allocate(oloc(noutlets, 2))
990 oloc(:, 1) =
domain_mrm(idomain)%L0_rowOutlet(: noutlets)
991 oloc(:, 2) =
domain_mrm(idomain)%L0_colOutlet(: noutlets)
997 inode = nlinkfromn(ii)
1002 nlinkfromrow(ii) = irow
1003 nlinkfromcol(ii) = jcol
1008 if (irow .eq. oloc(kk, 1) .and. jcol .eq. oloc(kk, 2)) is_outlet = .true.
1013 nlinktorow(ii) = irow
1014 nlinktocol(ii) = jcol
1018 do while (.not. (drasc0(irow, jcol) > 0))
1024 if (irow .eq. oloc(kk, 1) .and. jcol .eq. oloc(kk, 2))
exit
1026 if (prevrow .eq. irow .and. prevcol .eq. jcol)
then
1027 call error_message(
'Something went wrong during L11_link_location, ', &
1028 'movedownonecell got stuck in infinite loop at cell (', num2str(irow),
' ', &
1033 nlinktorow(ii) = irow
1034 nlinktocol(ii) = jcol
1046 call append(
l11_frow, nlinkfromrow(:))
1047 call append(
l11_fcol, nlinkfromcol(:))
1048 call append(
l11_trow, nlinktorow(:))
1049 call append(
l11_tcol, nlinktocol(:))
1052 deallocate (rowout, colout, nlinkfromn, netperm, nlinkfromrow, &
1053 nlinkfromcol, nlinktorow, nlinktocol, fdir0, drasc0)
1090 use mo_append,
only : append
1100 integer(i4),
intent(in) :: idomain
1102 integer(i4),
dimension(:, :),
allocatable :: drasc0
1104 integer(i4),
dimension(:, :),
allocatable :: fdir0
1106 integer(i4),
dimension(:, :),
allocatable :: gaugeloc0
1108 integer(i4),
dimension(:, :),
allocatable :: inflowgaugeloc0
1110 integer(i4),
dimension(:, :),
allocatable :: dracell0
1112 integer(i4) :: ii, jj, kk, ll, s0, e0
1116 integer(i4) :: irow, jcol
1118 type(
grid),
pointer :: level0_idomain => null()
1122 s0 = level0_idomain%iStart
1123 e0 = level0_idomain%iEnd
1127 allocate (drasc0(level0_idomain%nrows, level0_idomain%ncols))
1128 allocate (fdir0(level0_idomain%nrows, level0_idomain%ncols))
1129 allocate (gaugeloc0(level0_idomain%nrows, level0_idomain%ncols))
1130 allocate (inflowgaugeloc0(level0_idomain%nrows, level0_idomain%ncols))
1131 allocate (dracell0(level0_idomain%nrows, level0_idomain%ncols))
1140 drasc0(:, :) = unpack(
l0_drasc(s0 : e0), &
1142 fdir0(:, :) = unpack(
l0_fdir(s0 : e0), &
1149 do kk = 1, level0_idomain%nCells
1150 ii = level0_idomain%CellCoor(kk, 1)
1151 jj = level0_idomain%CellCoor(kk, 2)
1152 isc = drasc0(ii, jj)
1156 do while (.NOT. isc > 0)
1159 isc = drasc0(irow, jcol)
1161 dracell0(ii, jj) = isc
1165 if (gaugeloc0(ii, jj) .NE.
nodata_i4)
then
1169 if (
domain_mrm(idomain)%gaugeIdList(ll) .EQ. gaugeloc0(ii, jj))
then
1175 if (inflowgaugeloc0(ii, jj) .NE.
nodata_i4)
then
1179 if (
domain_mrm(idomain)%InflowGaugeIdList(ll) .EQ. inflowgaugeloc0(ii, jj)) &
1191 if (idomain .eq. 1)
then
1192 call append(
l0_dracell, pack(dracell0(:, :), level0_idomain%mask))
1193 else if (
domainmeta%L0DataFrom(idomain) == idomain)
then
1194 call append(
l0_dracell, pack(dracell0(:, :), level0_idomain%mask))
1198 deallocate (drasc0, fdir0, gaugeloc0, dracell0)
1235 use mo_append,
only : append
1242 use mo_percentile,
only: percentile
1247 integer(i4),
intent(in) :: idomain
1249 integer(i4) :: nlinks
1251 integer(i4),
dimension(:, :),
allocatable :: id0
1253 integer(i4),
dimension(:, :),
allocatable :: fdir0
1255 real(dp),
dimension(:, :),
allocatable :: elev0
1257 real(dp),
dimension(:, :),
allocatable :: cellarea0
1259 integer(i4),
dimension(:, :),
allocatable :: streamnet0
1261 integer(i4),
dimension(:, :),
allocatable :: floodplain0
1264 integer(i4),
dimension(:),
allocatable :: netperm
1266 integer(i4),
dimension(:),
allocatable :: nlinkfromrow
1268 integer(i4),
dimension(:),
allocatable :: nlinkfromcol
1270 integer(i4),
dimension(:),
allocatable :: nlinktorow
1272 integer(i4),
dimension(:),
allocatable :: nlinktocol
1274 real(dp),
dimension(:),
allocatable :: nlinklength
1276 real(dp),
dimension(:),
allocatable :: nlinkafloodplain
1278 real(dp),
dimension(:),
allocatable :: nlinkslope
1280 integer(i4) :: ii, rr, ns, s0, e0
1282 integer(i4) :: frow, fcol
1284 integer(i4) :: fid, tid
1286 integer(i4),
dimension(:, :),
allocatable :: stack, append_chunk
1288 integer(i4),
dimension(:),
allocatable :: dummy_1d
1292 integer(i4),
dimension(:, :),
allocatable :: nodata_i4_tmp
1294 real(dp),
dimension(:, :),
allocatable :: nodata_dp_tmp
1296 type(
grid),
pointer :: level0_idomain => null()
1300 s0 = level0_idomain%iStart
1301 e0 = level0_idomain%iEnd
1306 allocate (id0(level0_idomain%nrows, level0_idomain%ncols))
1307 allocate (elev0(level0_idomain%nrows, level0_idomain%ncols))
1308 allocate (fdir0(level0_idomain%nrows, level0_idomain%ncols))
1309 allocate (cellarea0(level0_idomain%nrows, level0_idomain%ncols))
1310 allocate (streamnet0(level0_idomain%nrows, level0_idomain%ncols))
1311 allocate (floodplain0(level0_idomain%nrows, level0_idomain%ncols))
1315 allocate (stack(
level11(idomain)%nCells, 2))
1316 allocate (dummy_1d(2))
1317 allocate (append_chunk(8, 2))
1318 allocate (netperm(
level11(idomain)%nCells))
1319 allocate (nlinkfromrow(
level11(idomain)%nCells))
1320 allocate (nlinkfromcol(
level11(idomain)%nCells))
1321 allocate (nlinktorow(
level11(idomain)%nCells))
1322 allocate (nlinktocol(
level11(idomain)%nCells))
1323 allocate (nlinklength(
level11(idomain)%nCells))
1324 allocate (nlinkafloodplain(
level11(idomain)%nCells))
1325 allocate (nlinkslope(
level11(idomain)%nCells))
1327 allocate (nodata_i4_tmp(level0_idomain%nrows, level0_idomain%ncols))
1328 allocate (nodata_dp_tmp(level0_idomain%nrows, level0_idomain%ncols))
1353 if(
level11(idomain)%nCells .GT. 1)
then
1355 id0(:, :) = unpack(level0_idomain%Id, level0_idomain%mask, nodata_i4_tmp)
1356 elev0(:, :) = unpack(
l0_elev(s0 : e0), &
1357 level0_idomain%mask, nodata_dp_tmp)
1358 fdir0(:, :) = unpack(
l0_fdir(s0 : e0), &
1359 level0_idomain%mask, nodata_i4_tmp)
1360 cellarea0(:, :) = unpack(level0_idomain%CellArea, level0_idomain%mask, nodata_dp_tmp)
1376 frow = nlinkfromrow(ii)
1377 fcol = nlinkfromcol(ii)
1380 streamnet0(frow, fcol) = ii
1381 floodplain0(frow, fcol) = ii
1389 nlinkslope(ii) = elev0(frow, fcol)
1391 fid = id0(frow, fcol)
1392 tid = id0(nlinktorow(ii), nlinktocol(ii))
1394 do while (.NOT. (fid == tid))
1397 if (ns + 8 .gt.
size(stack, 1))
then
1398 call append(stack, append_chunk)
1400 call moveup(elev0, fdir0, frow, fcol, stack, ns)
1405 dummy_1d = stack(1, :)
1406 stack(:
size(stack, dim = 1) - 1, :) = stack(2 :, :)
1407 stack(
size(stack, dim = 1), :) = dummy_1d
1409 if (stack(1, 1) > 0 .and. stack(1, 2) > 0) floodplain0(stack(1, 1), stack(1, 2)) = ii
1410 ns = count(stack > 0) / 2
1415 streamnet0(frow, fcol) = ii
1416 floodplain0(frow, fcol) = ii
1417 fid = id0(frow, fcol)
1423 nlinklength(ii) = nlinklength(ii) + length
1428 nlinkslope(ii) = (nlinkslope(ii) - elev0(frow, fcol)) / nlinklength(ii)
1430 if (nlinkslope(ii) < 0.0001_dp) nlinkslope(ii) = 0.0001_dp
1433 nlinkafloodplain(ii) = sum(cellarea0(:, :), mask = (floodplain0(:, :) == ii))
1443 if (count(nlinklength(:) .ge. 0._dp) .gt. 2)
then
1444 length = percentile(pack(nlinklength(:), nlinklength(:) .ge. 0._dp), 40._dp)
1445 nlinklength(:) = merge(nlinklength(:), length, (nlinklength(:) .gt. length))
1456 if (idomain .eq. 1)
then
1457 call append(
l0_streamnet, pack(streamnet0(:, :), level0_idomain%mask))
1458 call append(
l0_floodplain, pack(floodplain0(:, :), level0_idomain%mask))
1459 else if (
domainmeta%L0DataFrom(idomain) == idomain)
then
1460 call append(
l0_streamnet, pack(streamnet0(:, :), level0_idomain%mask))
1461 call append(
l0_floodplain, pack(floodplain0(:, :), level0_idomain%mask))
1472 id0, elev0, fdir0, streamnet0, floodplain0, &
1473 cellarea0, stack, netperm, nlinkfromrow, nlinkfromcol, nlinktorow, nlinktocol, &
1474 nlinklength, nlinkafloodplain, nlinkslope, dummy_1d)
1475 deallocate(nodata_i4_tmp, nodata_dp_tmp)
1512 use mo_append,
only : append
1522 integer(i4),
intent(in) :: lcclassimp
1524 logical,
intent(in) :: do_init
1526 integer(i4) :: nlinks
1528 real(dp),
dimension(:),
pointer :: nlinkafloodplain => null()
1530 real(dp),
dimension(:,:),
allocatable :: temp_array
1532 integer(i4) :: ii, idomain, iilc, s0, e0
1534 type(
grid),
pointer :: level0_idomain => null()
1544 s0 = level0_idomain%iStart
1545 e0 = level0_idomain%iEnd
1551 if(nlinks .GT. 0)
then
1553 temp_array(ii, iilc) = sum(level0_idomain%CellArea(:), &
1555 / nlinkafloodplain(ii)
1561 deallocate(temp_array)
1595 subroutine moveup(elev0, fDir0, fi, fj, ss, nn)
1598 use mo_utils,
only : ge, le
1602 real(dp),
dimension(:, :),
allocatable,
intent(IN) :: elev0
1604 integer(i4),
dimension(:, :),
allocatable,
intent(IN) :: fDir0
1607 integer(i4),
intent(IN) :: fi, fj
1609 integer(i4),
dimension(:, :),
intent(INOUT) :: ss
1611 integer(i4),
intent(INOUT) :: nn
1613 integer(i4) :: ii, jj, ip, im, jp, jm
1615 integer(i4) :: nrows, ncols
1625 nrows =
size(fdir0, 1)
1626 ncols =
size(fdir0, 2)
1629 if (jp <= ncols)
then
1630 if ((fdir0(ii, jp) == 16) .and. &
1631 (le((elev0(ii, jp) - elev0(fi, fj)),
deltah)) .and. &
1632 (ge((elev0(ii, jp) - elev0(fi, fj)), 0.0_dp)) &
1642 if ((ip <= nrows) .and. &
1644 if ((fdir0(ip, jp) == 32) .and. &
1645 (le((elev0(ip, jp) - elev0(fi, fj)),
deltah)) .and. &
1646 (ge((elev0(ii, jp) - elev0(fi, fj)), 0.0_dp)) &
1656 if ((ip <= nrows) .and. &
1658 if ((fdir0(ip, jj) == 64) .and. &
1659 (le((elev0(ip, jj) - elev0(fi, fj)),
deltah)) .and. &
1660 (ge((elev0(ii, jp) - elev0(fi, fj)), 0.0_dp)) &
1670 if ((ip <= nrows) .and. &
1671 (jp <= ncols) .and. &
1673 if ((fdir0(ip, jm) == 128) .and. &
1674 (le((elev0(ip, jm) - elev0(fi, fj)),
deltah)) .and. &
1675 (ge((elev0(ii, jp) - elev0(fi, fj)), 0.0_dp)) &
1685 if ((jm >= 1) .and. &
1687 if ((fdir0(ii, jm) == 1) .and. &
1688 (le((elev0(ii, jm) - elev0(fi, fj)),
deltah)) .and. &
1689 (ge((elev0(ii, jp) - elev0(fi, fj)), 0.0_dp)) &
1699 if ((im >= 1) .and. &
1700 (jp <= ncols) .and. &
1702 if ((fdir0(im, jm) == 2) .and. &
1703 (le((elev0(im, jm) - elev0(fi, fj)),
deltah)) .and. &
1704 (ge((elev0(ii, jp) - elev0(fi, fj)), 0.0_dp)) &
1714 if ((im >= 1) .and. &
1716 if ((fdir0(im, jj) == 4) .and. &
1717 (le((elev0(im, jj) - elev0(fi, fj)),
deltah)) .and. &
1718 (ge((elev0(ii, jp) - elev0(fi, fj)), 0.0_dp)) &
1728 if ((im >= 1) .and. &
1730 if ((fdir0(im, jp) == 8) .and. &
1731 (le((elev0(im, jp) - elev0(fi, fj)),
deltah)) .and. &
1732 (ge((elev0(ii, jp) - elev0(fi, fj)), 0.0_dp)) &
1771 integer(i4),
intent(IN) :: fDir
1773 integer(i4),
intent(INOUT) :: iRow, jCol
1831 subroutine celllength(iDomain, fDir, iRow, jCol, iCoorSystem, length)
1835 use mo_constants,
only : sqrt2_dp
1839 integer(i4),
intent(IN) :: iDomain
1841 integer(i4),
intent(IN) :: fDir
1843 integer(i4),
intent(IN) :: iRow
1845 integer(i4),
intent(IN) :: jCol
1847 integer(i4),
intent(IN) :: iCoorSystem
1849 real(dp),
intent(OUT) :: length
1851 integer(i4) :: iRow_to, jCol_to
1853 real(dp) :: lat_1, long_1, lat_2, long_2
1855 type(
grid),
pointer :: level0_iDomain => null()
1861 IF(icoorsystem .EQ. 0)
THEN
1869 length = length * level0_idomain%cellsize
1872 ELSE IF(icoorsystem .EQ. 1)
THEN
1880 lat_1 = level0_idomain%yllcorner + real((level0_idomain%ncols - jcol), dp) * level0_idomain%cellsize + &
1881 0.5_dp * level0_idomain%cellsize
1882 long_1 = level0_idomain%xllcorner + real((irow - 1), dp) * level0_idomain%cellsize + &
1883 0.5_dp * level0_idomain%cellsize
1885 lat_2 = level0_idomain%yllcorner + real((level0_idomain%ncols - jcol_to), dp) * level0_idomain%cellsize + &
1886 0.5_dp * level0_idomain%cellsize
1887 long_2 = level0_idomain%xllcorner + real((irow_to - 1), dp) * level0_idomain%cellsize + &
1888 0.5_dp * level0_idomain%cellsize
1928 use mo_constants,
only : radiusearth_dp, twopi_dp
1933 real(dp),
intent(in) :: lat1, long1, lat2, long2
1936 real(dp),
intent(out) :: distance_out
1957 dtor = twopi_dp / 360.0_dp
1958 theta1 = dtor * long1
1960 theta2 = dtor * long2
1963 term1 = cos(phi1) * cos(theta1) * cos(phi2) * cos(theta2)
1964 term2 = cos(phi1) * sin(theta1) * cos(phi2) * sin(theta2)
1965 term3 = sin(phi1) * sin(phi2)
1966 temp = term1 + term2 + term3
1967 if(temp .GT. 1.0_dp) temp = 1.0_dp
1969 distance_out = radiusearth_dp * acos(temp);
2029 use mo_append,
only : append
2034 integer(i4),
intent(in) :: idomain
2035 real(dp),
dimension(:,:),
allocatable :: facc11
2036 integer(i4) :: ii, jj
2037 integer(i4) :: s11, e11
2038 integer(i4) :: nrows11, ncols11
2039 integer(i4),
dimension(:,:),
allocatable :: fdir11
2040 logical,
dimension(:,:),
allocatable :: mask11
2043 nrows11 =
level11(idomain)%nrows
2044 ncols11 =
level11(idomain)%ncols
2047 mask11 =
level11(idomain)%mask
2050 allocate(fdir11(nrows11, ncols11))
2051 allocate(facc11(nrows11, ncols11))
2065 if (fdir11(ii,jj) .eq. 0)
then
2077 call append(
l11_facc, pack(facc11(:,:),mask11))
2080 deallocate(fdir11, facc11, mask11)
2088 integer(i4),
intent(in) :: fdir(:,:)
2089 real(dp),
intent (inout) :: facc(:,:)
2090 integer(i4),
intent(in) :: ii, jj
2091 integer(i4),
intent(in) :: nrow, ncol
2103 if (jj+1 .le. ncol)
then
2104 if (fdir(ii,jj+1) .eq. 16_i4)
then
2106 facc(ii,jj) = facc(ii,jj) + facc(ii,jj+1)
2110 if ((ii+1 .le. nrow) .and. (jj+1 .le. ncol))
then
2111 if (fdir(ii+1,jj+1) .eq. 32_i4)
then
2113 facc(ii,jj) = facc(ii,jj) + facc(ii+1,jj+1)
2117 if (ii+1 .le. nrow)
then
2118 if (fdir(ii+1,jj) .eq. 64_i4)
then
2120 facc(ii,jj) = facc(ii,jj) + facc(ii+1,jj)
2124 if ((ii+1 .le. nrow) .and. (jj-1 .ge. 1))
then
2125 if (fdir(ii+1,jj-1) .eq. 128_i4)
then
2127 facc(ii,jj) = facc(ii,jj) + facc(ii+1,jj-1)
2131 if (jj-1 .ge. 1)
then
2132 if (fdir(ii,jj-1) .eq. 1_i4)
then
2134 facc(ii,jj) = facc(ii,jj) + facc(ii,jj-1)
2138 if ((ii-1 .ge. 1) .and. (jj-1 .ge. 1))
then
2139 if (fdir(ii-1,jj-1) .eq. 2_i4)
then
2141 facc(ii,jj) = facc(ii,jj) + facc(ii-1,jj-1)
2145 if (ii-1 .ge. 1)
then
2146 if (fdir(ii-1,jj) .eq. 4_i4)
then
2148 facc(ii,jj) = facc(ii,jj) + facc(ii-1,jj)
2152 if ((ii-1 .ge. 1) .and. (jj+1 .le. ncol))
then
2153 if (fdir11(ii-1,jj+1) .eq. 8_i4)
then
2155 facc(ii,jj) = facc(ii,jj) + facc(ii-1,jj+1)
2214 use mo_mad,
only: mad
2215 use mo_append,
only: append
2238 integer(i4),
intent(in) :: idomain
2239 real(dp),
dimension(:),
intent(in) :: param
2242 integer(i4) :: ncells0
2243 integer(i4) :: nnodes
2244 integer(i4) :: nlinks
2245 integer(i4) :: nrows0, ncols0
2246 integer(i4) :: istart0, iend0
2247 integer(i4) :: nrows11, ncols11
2248 integer(i4) :: istart11, iend11
2249 logical,
dimension(:,:),
allocatable :: mask0
2250 integer(i4),
dimension(:,:),
allocatable :: id0
2251 integer(i4),
dimension(:,:),
allocatable :: fdir0
2252 integer(i4),
dimension(:,:),
allocatable :: facc0
2253 real(dp),
dimension(:,:),
allocatable :: slope0
2254 real(dp),
dimension(:),
allocatable :: slope_tmp
2255 real(dp),
dimension(:,:),
allocatable :: cellarea0
2256 integer(i4),
dimension(:),
allocatable :: netperm
2257 integer(i4),
dimension(:),
allocatable :: nlinkfromrow
2258 integer(i4),
dimension(:),
allocatable :: nlinkfromcol
2259 integer(i4),
dimension(:),
allocatable :: nlinktorow
2260 integer(i4),
dimension(:),
allocatable :: nlinktocol
2261 integer(i4) :: ii, rr, ns
2262 integer(i4) :: frow, fcol
2263 integer(i4) :: fid, tid
2264 real(dp),
dimension(:),
allocatable :: stack, append_chunk
2265 integer(i4),
dimension(:),
allocatable :: dummy_1d
2267 real(dp) :: l0_link_slope
2268 real(dp),
dimension(:),
allocatable :: celerity11
2269 real(dp),
dimension(:,:),
allocatable :: celerity0
2271 integer(i4),
dimension(:,:),
allocatable :: nodata_i4_tmp
2272 real(dp),
dimension(:,:),
allocatable :: nodata_dp_tmp
2273 logical,
dimension(:),
allocatable :: slopemask0
2275 type(
grid),
pointer :: level0_idomain
2279 nrows0 = level0_idomain%nrows
2280 ncols0 = level0_idomain%ncols
2281 ncells0 = level0_idomain%ncells
2282 istart0 = level0_idomain%iStart
2283 iend0 = level0_idomain%iEnd
2284 mask0 = level0_idomain%mask
2287 istart11 =
level11(idomain)%iStart
2288 iend11 =
level11(idomain)%iEnd
2289 nrows11 =
level11(idomain)%nrows
2290 ncols11 =
level11(idomain)%ncols
2291 nnodes =
level11(idomain)%ncells
2296 allocate ( id0( nrows0, ncols0 ) )
2297 allocate ( slope0( nrows0, ncols0 ) )
2298 allocate ( fdir0( nrows0, ncols0 ) )
2299 allocate ( facc0( nrows0, ncols0 ) )
2300 allocate ( cellarea0( nrows0, ncols0 ) )
2301 allocate ( celerity0( nrows0, ncols0 ) )
2302 allocate ( slopemask0( ncells0 ) )
2306 allocate ( stack( 1 ) )
2307 allocate ( append_chunk( 1 ) )
2308 allocate ( dummy_1d( 2 ))
2309 allocate ( netperm( nnodes ) )
2310 allocate ( nlinkfromrow( nnodes ) )
2311 allocate ( nlinkfromcol( nnodes ) )
2312 allocate ( nlinktorow( nnodes ) )
2313 allocate ( nlinktocol( nnodes ) )
2314 allocate ( celerity11( nnodes ) )
2315 allocate ( slope_tmp( nnodes ) )
2317 allocate (nodata_i4_tmp( nrows0, ncols0 ) )
2318 allocate (nodata_dp_tmp( nrows0, ncols0 ) )
2336 slopemask0(:) = .false.
2343 if(nnodes .GT. 1)
then
2345 id0(:,:) = unpack(level0_idomain%Id(1:ncells0), mask0, nodata_i4_tmp)
2346 fdir0(:,:) = unpack(
l0_fdir(istart0:iend0), mask0, nodata_i4_tmp)
2347 facc0(:,:) = unpack(
l0_facc(istart0:iend0), mask0, nodata_i4_tmp)
2348 cellarea0(:,:) = unpack(level0_idomain%cellarea(1:ncells0), mask0, nodata_dp_tmp)
2351 slope_tmp =
l0_slope(istart0:iend0)
2352 where ( slope_tmp .lt. 0.1_dp ) slope_tmp = 0.1_dp
2357 if( count(slopemask0) .GT. 1)
then
2358 slope_tmp = mad(arr = slope_tmp, z = 2.25_dp, mask = slopemask0, tout=
'u', mval=0.1_dp)
2360 slope0(:,:) = unpack(slope_tmp, mask0, nodata_dp_tmp )
2364 nlinkfromrow(:) =
l11_frow( istart11 : iend11 )
2365 nlinkfromcol(:) =
l11_fcol( istart11 : iend11 )
2366 nlinktorow(:) =
l11_trow( istart11 : iend11 )
2367 nlinktocol(:) =
l11_tcol( istart11 : iend11 )
2372 frow = nlinkfromrow(ii)
2373 fcol = nlinkfromcol(ii)
2379 fid = id0( frow, fcol )
2380 tid = id0( nlinktorow(ii) , nlinktocol(ii) )
2382 l0_link_slope = slope0(frow, fcol) / 100._dp
2385 stack(ns) = param(1) * sqrt(l0_link_slope)
2387 celerity0(frow, fcol) = stack(ns)
2389 fid = id0(frow, fcol)
2390 if( .NOT. (fid == tid))
then
2391 call append(stack, append_chunk)
2399 celerity11(ii) =
size(stack) / sum(1/stack(:))
2409 celerity11(:) = 1._dp
2415 l0_celerity(istart0:iend0) = pack(celerity0(:,:), mask0)
2419 mask0, id0, slope_tmp, slopemask0, &
2420 slope0, fdir0, cellarea0, &
2421 stack, netperm, nlinkfromrow, nlinkfromcol, nlinktorow, nlinktocol)
recursive subroutine calculate_l11_flow_accumulation(fdir, facc, ii, jj, nrow, ncol)
Provides constants commonly used by mHM, mRM and MPR.
real(dp), parameter, public nodata_dp
integer(i4), parameter, public nodata_i4
Provides common types needed by mHM, mRM and/or mpr.
Provides structures needed by mHM, mRM and/or mpr.
type(domain_meta), public domainmeta
integer(i4), public nlcoverscene
real(dp), dimension(:), allocatable, public l0_elev
integer(i4), public iflag_cordinate_sys
integer(i4), dimension(:, :), allocatable, public l0_lcover
integer(i4), dimension(nprocesses, 3), public processmatrix
type(grid), dimension(:), allocatable, target, public level1
type(grid), dimension(:), allocatable, target, public level0
Global variables for mpr only.
real(dp), dimension(:), allocatable, public l0_slope
Provides mRM specific constants.
real(dp), parameter, public deltah
Global variables for mRM only.
type(gridremapper), dimension(:), allocatable, public l0_l11_remap
integer(i4), dimension(:), allocatable, public l0_floodplain
real(dp), dimension(:), allocatable, public l11_facc
integer(i4), dimension(:), allocatable, public l11_netperm
real(dp), dimension(:, :), allocatable, public l11_nlinkfracfpimp
integer(i4), dimension(:), allocatable, public l11_l1_id
integer(i4), dimension(:), allocatable, public l1_l11_id
real(dp), dimension(:), allocatable, public l0_celerity
real(dp), dimension(:), allocatable, target, public l11_afloodplain
integer(i4), dimension(:), allocatable, public l0_fdir
integer(i4), dimension(:), allocatable, public l11_fcol
integer(i4), dimension(:), allocatable, public l0_dracell
integer(i4), dimension(:), allocatable, public l11_label
integer(i4), dimension(:), allocatable, public l0_streamnet
integer(i4), dimension(:), allocatable, public l11_fromn
real(dp), dimension(:), allocatable, public l11_length
integer(i4), dimension(:), allocatable, public l11_rowout
integer(i4), dimension(:), allocatable, public l11_ton
type(domaininfo_mrm), dimension(:), allocatable, target, public domain_mrm
integer(i4), dimension(:), allocatable, public l11_trow
type(grid), dimension(:), allocatable, target, public level11
integer(i4), dimension(:), allocatable, public l11_fdir
integer(i4), dimension(:), allocatable, public l0_facc
integer(i4), dimension(:), allocatable, public l11_tcol
integer(i4), dimension(:), allocatable, public l11_frow
real(dp), dimension(:), allocatable, public l11_slope
logical, dimension(:), allocatable, public l11_sink
integer(i4), dimension(:), allocatable, public l0_inflowgaugeloc
real(dp), dimension(:), allocatable, public l11_celerity
integer(i4), dimension(:), allocatable, public l11_noutlets
integer(i4), dimension(:), allocatable, public l0_drasc
integer(i4), dimension(:), allocatable, public l11_rorder
integer(i4), dimension(:), allocatable, public l0_gaugeloc
integer(i4), dimension(:), allocatable, public l11_colout
Startup drainage network for mHM.
subroutine, public l11_stream_features(idomain)
Stream features (stream network and floodplain)
subroutine, public l11_flow_direction(idomain)
Determine the flow direction of the upscaled river network at level L11.
subroutine celllength(idomain, fdir, irow, jcol, icoorsystem, length)
TODO: add description.
subroutine moveup(elev0, fdir0, fi, fj, ss, nn)
TODO: add description.
subroutine, public get_distance_two_lat_lon_points(lat1, long1, lat2, long2, distance_out)
estimate distance in [m] between two points in a lat-lon
subroutine, public l11_fraction_sealed_floodplain(lcclassimp, do_init)
Fraction of the flood plain with impervious cover.
subroutine, public l11_set_drain_outlet_gauges(idomain)
Draining cell identification and Set gauging node.
subroutine, public l11_set_network_topology(idomain)
Set network topology.
subroutine, public l11_routing_order(idomain)
Find routing order, headwater cells and sink.
subroutine movedownonecell(fdir, irow, jcol)
TODO: add description.
subroutine, public l11_link_location(idomain)
Estimate the LO (row,col) location for each routing link at level L11.
subroutine, public l11_calc_celerity(idomain, param)
L11 celerity based on L0 elevation and L0 fAcc.
subroutine, public l11_l1_mapping(idomain)
TODO: add description.
subroutine, public l11_flow_accumulation(idomain)
Calculates L11 flow accumulation per grid cell.