49    real(double), 
intent(in) :: array(:)
 
   50    integer, 
intent(out) :: index_list(:)
 
   51    logical, 
intent(in), 
optional :: mask(:)
 
   52    integer, 
intent(out),
optional :: index_n
 
   54    integer, 
parameter :: mm=7, nstack=50
 
   55    integer :: ii,index_i,ir,itemp,istack(nstack), jj,jstack, kk,ll, loc_list(size(index_list)), loc_index_n
 
   57    logical :: loc_mask(size(array))
 
   60    if(
size(array).ne.
size(index_list)) &
 
   61         call quit_program_error(
'libSUFR sorted_index_list():  array and index_list must have the same size',0)
 
   64    if(
present(mask)) loc_mask = mask
 
   82             index_i = loc_list(jj)
 
   83             arr_i = array(index_i)
 
   84             subloop1: 
do ii=jj-1,ll,-1
 
   85                if(array(loc_list(ii)).le.arr_i) 
exit subloop1
 
   86                loc_list(ii+1) = loc_list(ii)
 
   90             loc_list(ii+1) = index_i
 
  100                if(loc_mask(loc_list(ii))) 
then 
  101                   loc_index_n = loc_index_n + 1
 
  102                   index_list(loc_index_n) = loc_list(ii)
 
  103                   if(
present(index_n)) index_n = loc_index_n
 
  114          ll = istack(jstack-1)
 
  121          loc_list(kk) = loc_list(ll+1)
 
  122          loc_list(ll+1) = itemp
 
  124          if(array(loc_list(ll)).gt.array(loc_list(ir))) 
then 
  126             loc_list(ll) = loc_list(ir)
 
  130          if(array(loc_list(ll+1)).gt.array(loc_list(ir))) 
then 
  131             itemp = loc_list(ll+1)
 
  132             loc_list(ll+1) = loc_list(ir)
 
  136          if(array(loc_list(ll)).gt.array(loc_list(ll+1))) 
then 
  138             loc_list(ll) = loc_list(ll+1)
 
  139             loc_list(ll+1) = itemp
 
  144          index_i = loc_list(ll+1)
 
  145          arr_i = array(index_i)
 
  150             if(array(loc_list(ii)).lt.arr_i) cycle subloop2
 
  155                if(array(loc_list(jj)).le.arr_i) 
exit 
  161                loc_list(ii) = loc_list(jj)
 
  171          loc_list(ll+1) = loc_list(jj)
 
  172          loc_list(jj) = index_i
 
  175          if(jstack.gt.nstack) 
write(0,
'(A)')
' sorted_index_list():  nstack is too small' 
  177          if(ir-ii+1.ge.jj-ll) 
then 
  179             istack(jstack-1) = ii
 
  182             istack(jstack) = jj-1
 
  183             istack(jstack-1) = ll
 
 
  254    integer, 
intent(in) :: narr, strlen
 
  255    character, 
intent(in) :: strarr(narr)*(strlen)
 
  256    integer, 
intent(out) :: index_list(narr)
 
  264          ic = ichar(strarr(i)(l:l))
 
  265          if(ic.ge.97.and.ic.le.122) ic = ic-32
 
  267          score(i) = score(i) + real(ic) * 64.**(strlen-l)
 
 
subroutine sorted_index_list(array, index_list, mask, index_n)
Return a list of indices index_list that sorts the members of array to ascending value,...