MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
gridsorting Module Reference

Functions/Subroutines

subroutine, public quicksortgrid (array, arraySize, idxToGlobal)
 

Function/Subroutine Documentation

◆ quicksortgrid()

subroutine, public gridsorting::quicksortgrid ( integer, dimension(:), intent(inout)  array,
integer, intent(in)  arraySize,
type(globalcelltype), dimension(:), pointer  idxToGlobal 
)

Definition at line 14 of file GridSorting.f90.

15  integer, intent(inout), dimension(:) :: array
16  integer, intent(in) :: arraySize
17  type(GlobalCellType), dimension(:), pointer :: idxToGlobal
18  ! local
19  integer :: QSORT_THRESHOLD = 8
20  include "qsort_inline.inc"
21 
22  contains
23  subroutine init()
24  end subroutine init
25 
26  ! Compare two grid cells, this doesn't work as
27  ! smooth for staggered discretizations though...
28  function lessthan(n, m) result(isLess)
29  integer(I4B), intent(in) :: n
30  integer(I4B), intent(in) :: m
31  logical(LGP) :: isLess
32  ! local
33  type(GlobalCellType), pointer :: gcn, gcm
34  real(DP) :: xn, yn, zn, xm, ym, zm
35  real(DP), dimension(:), pointer, contiguous :: dis_top_n, dis_bot_n, &
36  dis_top_m, dis_bot_m
37  real(DP), dimension(:), pointer, contiguous :: dis_xc_n, dis_yc_n, &
38  dis_xc_m, dis_yc_m
39  real(DP) :: xorigin_n, yorigin_n, angrot_n, &
40  xorigin_m, yorigin_m, angrot_m
41 
42  ! get coordinates
43  gcn => idxtoglobal(array(n))
44  gcm => idxtoglobal(array(m))
45 
46  ! get model data
47  ! for n:
48  dis_top_n => gcn%v_model%dis_top%get_array()
49  dis_bot_n => gcn%v_model%dis_bot%get_array()
50  dis_xc_n => gcn%v_model%dis_xc%get_array()
51  dis_yc_n => gcn%v_model%dis_yc%get_array()
52  xorigin_n = gcn%v_model%dis_xorigin%get()
53  yorigin_n = gcn%v_model%dis_yorigin%get()
54  angrot_n = gcn%v_model%dis_angrot%get()
55  ! for m:
56  dis_top_m => gcm%v_model%dis_top%get_array()
57  dis_bot_m => gcm%v_model%dis_bot%get_array()
58  dis_xc_m => gcm%v_model%dis_xc%get_array()
59  dis_yc_m => gcm%v_model%dis_yc%get_array()
60  xorigin_m = gcm%v_model%dis_xorigin%get()
61  yorigin_m = gcm%v_model%dis_yorigin%get()
62  angrot_m = gcm%v_model%dis_angrot%get()
63 
64  ! convert coordinates
65  call dis_transform_xy(dis_xc_n(gcn%index), dis_yc_n(gcn%index), &
66  xorigin_n, yorigin_n, angrot_n, &
67  xn, yn)
68  zn = dhalf * (dis_top_n(gcn%index) + &
69  dis_bot_n(gcn%index))
70 
71  call dis_transform_xy(dis_xc_m(gcm%index), dis_yc_m(gcm%index), &
72  xorigin_m, yorigin_m, angrot_m, &
73  xm, ym)
74  zm = dhalf * (dis_top_m(gcm%index) + &
75  dis_bot_m(gcm%index))
76 
77  ! compare
78  if (.not. is_close(zn, zm, 10 * epsilon(zn))) then
79  isless = zn > zm
80  else if (.not. is_close(yn, ym, 10 * epsilon(yn))) then
81  isless = yn > ym
82  else if (.not. is_close(xn, xm, 10 * epsilon(xn))) then
83  isless = xn < xm
84  else
85  isless = .false.
86  end if
87 
88  end function lessthan
89 
90  ! swap indices
91  subroutine swap(a, b)
92  integer, intent(in) :: a, b
93  integer :: hold
94 
95  hold = array(a)
96  array(a) = array(b)
97  array(b) = hold
98 
99  end subroutine swap
100 
101  ! circular shift-right by one
102  subroutine rshift(left, right)
103  integer, intent(in) :: left, right
104  integer :: hold
105 
106  hold = array(right)
107  array(left + 1:right) = array(left:right - 1)
108  array(left) = hold
109 
110  end subroutine rshift
subroutine swap(a, b)
Definition: GridSorting.f90:92
logical(lgp) function lessthan(n, m)
Definition: GridSorting.f90:29
subroutine rshift(left, right)
subroutine init()
Definition: GridSorting.f90:24
Here is the caller graph for this function: