53 if (verbose_level .gt. 2)
then
58 write(
debug_tabl,
'(A)')
'# This file contains data to debug the subroutine rrate_qs_replace, contained in mergesort_module.f90'
92 integer,
intent(in) :: xs
93 integer,
intent(in) :: ys
96 integer,
intent(in) :: r
99 integer :: x1,x2,y1,y2,n
100 integer :: ptx, pty, ptz
112 allocate(tmp(n),stat=istat)
164 if (ptx.gt.xs) fin = fin+1
165 if (pty.gt.ys) fin = fin+2
171 else if (fin.eq.2)
then
184 if (fin.eq.1) tmp(ptz) = y(i)
185 if (fin.eq.2) tmp(ptz) = x(i)
233 integer,
intent(in) :: xs
234 integer,
intent(in) :: ys
237 integer,
intent(in) :: r
238 integer,
intent(out) :: ptz
240 allocatable,
optional,
intent(out) :: rate_out
245 integer :: x1,x2,y1,y2,n
249 integer :: alloc_stat
264 if (y(pty)%reac_src .eq.
rrs_twr)
then
265 if (.not.
allocated(tmp2))
allocate(tmp2(ys))
279 if((x1.eq.tmp(ptz-1)%parts(1)).and.(x2.eq.tmp(ptz-1)%parts(2)))
then
288 if((y1.eq.tmp(ptz-1)%parts(1)).and.(y2.eq.tmp(ptz-1)%parts(2)))
then
303 if (y(pty)%reac_src .eq.
rrs_twr)
then
304 only_theo_weak_rates = only_theo_weak_rates + 1
316 if (y(pty)%reac_src .eq.
rrs_twr)
then
317 only_theo_weak_rates = only_theo_weak_rates + 1
343 if (y(pty-1)%reac_src .eq.
rrs_twr)
then
344 common_weak_rates = common_weak_rates + 1
345 tmp2(common_weak_rates) = x(ptx-1)
349 if (ptx.gt.xs) fin = fin+1
350 if (pty.gt.ys) fin = fin+2
356 else if (fin.eq.2)
then
361 if (
present(rate_out))
then
362 if (
allocated(rate_out))
deallocate(rate_out)
363 allocate(rate_out(ptz),stat=alloc_stat)
364 rate_out(1:ptz) = tmp(1:ptz)
366 rrate(1:ptz) = tmp(1:ptz)
375 if (y(i)%reac_src .eq.
rrs_twr)
then
376 only_theo_weak_rates = only_theo_weak_rates + 1
379 if (fin.eq.2) tmp(ptz) = x(i)
384 if (
present(rate_out))
then
385 if (
allocated(rate_out))
deallocate(rate_out)
386 allocate(rate_out(ptz),stat=alloc_stat)
387 if ( alloc_stat /= 0)
call raise_exception(
'Allocation of "rrate_array" failed.',&
388 "merge_neutrino_rates",290001)
389 rate_out(1:ptz) = tmp(1:ptz)
391 rrate(1:ptz) = tmp(1:ptz)
396 if (y(1)%reac_src .eq.
rrs_twr)
then
429 integer,
intent(in) :: r,xs,ys
433 integer,
intent(out) :: ptz
436 integer :: n, i, j, k
437 integer :: nrduplicates
440 integer :: count_duplicates
441 integer :: tabl_position
442 integer :: new_rate_length
443 character(5),
dimension(6) :: part_names
465 tmp_find_duplicates = tmp(i)
467 if (tmp_find_duplicates%reac_src .eq.
rrs_tabl)
then
473 do k =i, new_rate_length-1
474 if (all(tmp_find_duplicates%parts .eq. tmp(k+1)%parts) .and. &
475 (tmp_find_duplicates%group .eq. tmp(k+1)%group))
then
477 count_duplicates= count_duplicates + 1
479 if (tmp(k+1)%reac_src .eq.
rrs_tabl)
then
489 if (tabl_position .ne. 0)
then
491 if (verbose_level .gt. 2)
then
494 if (tmp_find_duplicates%parts(k) .ne. 0)
then
495 part_names(k) =
net_names(tmp_find_duplicates%parts(k))
501 write(
debug_tabl,
"('Replacing rate ',6a,' found ',i10,' reactions in Reaclib')") part_names(:),count_duplicates-1
505 tmp(i) = tmp(tabl_position)
506 do k=i,new_rate_length - count_duplicates
507 tmp(k+1)=tmp(k+count_duplicates)
509 new_rate_length = (new_rate_length - count_duplicates) + 1
513 if (i .ge. new_rate_length)
then
519 if (verbose_level .gt. 2)
then
522 write(
debug_tabl,
'(A,i10,A)')
'Merged in ', n-xs,
' rates.'
526 if (verbose_level .gt. 2) print *,
"duplicates: ", new_rate_length
528 ptz = new_rate_length
530 allocate(out_array(new_rate_length))
533 out_array(1:new_rate_length) = tmp(1:new_rate_length)
562 integer,
intent(in) :: na
568 integer :: left, right
570 character(31) :: pivot
572 integer :: marker, randi, clock
574 integer,
dimension(:) ,
allocatable :: variable_put
580 call system_clock(count=clock)
583 call random_seed(size=n)
584 allocate(variable_put(n),stat=istat)
585 if (istat /= 0)
call raise_exception(
'Allocation failed.',
"QSort",290001)
586 variable_put(:) = clock
588 call random_seed(put = variable_put)
589 call random_number(random)
590 randi = int(random*real(na-1))+1
591 pivot =
ratesortkey(a(randi)%group, a(randi)%parts)
595 do while (left < right)
597 do while (lgt(
ratesortkey(a(right)%group, a(right)%parts), pivot))
601 do while (llt(
ratesortkey(a(left)%group, a(left)%parts), pivot))
604 if (left < right)
then
611 if (left == right)
then
617 call qsort(a(:marker-1),marker-1)
618 call qsort(a(marker:),na-marker+1)
642 if (verbose_level .gt. 2)
then
680 integer,
intent(in) :: num
685 info_entry(
"rrate_sort")
689 if (rate_array(i+1)%group.ne.1)
exit
690 if ((rate_array(i)%parts(1).eq.rate_array(i+1)%parts(1)) .and. &
691 (rate_array(i)%parts(2).gt.rate_array(i+1)%parts(2)))
then
692 if (verbose_level .ge. 2)
then
693 print
'(a10,4i6)',
'switch ' ,rate_array(i)%parts(1:2), rate_array(i+1)%parts(1:2)
695 temp(1) = rate_array(i+1)
696 rate_array(i+1) = rate_array(i)
697 rate_array(i) = temp(1)
701 info_exit(
"rrate_sort")
726 real(
r_kind),
dimension(:),
intent(inout) :: arr1
727 integer,
dimension(:),
intent(out),
optional :: arr2
728 integer,
intent(in) :: length
729 integer,
intent(in) :: mode
736 if (
present(arr2))
then
748 if (mode .eq. 1)
then
750 if (arr1(i)>arr1(i+1))
then
755 if (
present(arr2))
then
762 elseif (mode .eq. 0)
then
764 if (arr1(i)<arr1(i+1))
then
769 if (
present(arr2))
then
809 recursive subroutine quicksort(mode, length, arr1, arr2, is_recursion)
812 real(
r_kind),
dimension(:),
intent(inout) :: arr1
813 integer,
dimension(:),
intent(out),
optional :: arr2
814 integer,
intent(in) :: length
815 integer,
intent(in) :: mode
816 logical,
intent(in),
optional :: is_recursion
818 real(
r_kind) :: pivot_value
819 integer :: pivot_index, i, j
820 logical :: recursive_call
824 if (
present(is_recursion))
then
825 recursive_call = is_recursion
827 recursive_call = .false.
830 if (.not. recursive_call)
then
831 if (
present(arr2))
then
832 arr2 = [(i, i=1,length)]
837 if (length <= 1)
return
840 pivot_index = length / 2
841 pivot_value = arr1(pivot_index)
849 do while (arr1(i) < pivot_value)
852 do while (arr1(j) > pivot_value)
856 do while (arr1(i) > pivot_value)
859 do while (arr1(j) < pivot_value)
870 if (
present(arr2))
then
882 if (
present(arr2))
then
883 call quicksort(mode, j, arr1, arr2, .true.)
884 call quicksort(mode, length - i + 1, arr1(i:), arr2(i:),.true.)
886 call quicksort(mode, j, arr1, is_recursion=.true.)
887 call quicksort(mode, length - i + 1, arr1(i:), is_recursion=.true.)
903 real(
r_kind),
dimension(:),
intent(inout) :: arr1
904 integer,
dimension(:),
intent(in) :: arr2
905 integer,
intent(in) :: length
907 real(
r_kind),
dimension(length) :: helper
912 if ((arr2(i) .lt. 1) .or. (arr2(i) .gt. length))
then
917 helper(i) = arr1(arr2(i))
934 integer,
dimension(:),
intent(inout) :: arr1
935 integer,
dimension(:),
intent(in) :: arr2
936 integer,
intent(in) :: length
938 integer,
dimension(length) :: helper
943 if ((arr2(i) .lt. 1) .or. (arr2(i) .gt. length))
then
948 helper(i) = arr1(arr2(i))
980 integer,
dimension(6) :: parts
986 write (
ratesortkey,
"(I1,6I5)") group, parts(2), parts(1), parts(3:)
988 write (
ratesortkey,
"(I1,6I5)") group, parts(3), parts(2), parts(1), parts(4:)
990 write (
ratesortkey,
"(I1,6I5)") group, parts(4), parts(3), parts(2), parts(1), parts(5:)