mergesort_module Module Reference

Module mergesort_module for merging arrays of rates. More...

Functions/Subroutines

subroutine, public mergesort_init ()
 Initialize the mergesort module and open files for debugging. More...
 
subroutine, public nurate_ms (x, xs, y, ys, r)
 Merges two tables of neutrino rates (of type global_class::nurate_type). More...
 
subroutine, public rrate_ms (x, xs, y, ys, r, ptz, rate_out)
 Merges two tables of rates (of type global_class::reactionrate_type). More...
 
subroutine, public rrate_qs_replace (x, xs, y, ys, r, out_array, ptz)
 Wrapper around the quicksort subroutine. More...
 
recursive subroutine, private qsort (A, nA)
 Modified quicksort algorithm. More...
 
subroutine, public mergesort_finalize ()
 Close files and finalize this module. More...
 
subroutine, public rrate_sort (num, rate_array)
 Sorts chapter one of the rate array. More...
 
subroutine, public bubblesort (mode, length, arr1, arr2)
 Bubblesort of array. More...
 
recursive subroutine, public quicksort (mode, length, arr1, arr2, is_recursion)
 Quicksort of array. More...
 
subroutine, public reorder (arr1, arr2, length)
 Takes an array and an array with indices to reorder the first array. More...
 
subroutine, public reorder_int (arr1, arr2, length)
 Takes an array and an array with indices to reorder the first array. More...
 

Variables

integer, private debug_tabl
 File ID for debugging tabulated rate class. More...
 

Detailed Description

Module mergesort_module for merging arrays of rates.

A mergesort is a recursive algorithm to sort arrays. It works as illustrated in these two figures (Source: en.wikipedia)

Illustration of a mergesort
Illustration of a mergesort

Function/Subroutine Documentation

◆ bubblesort()

subroutine, public mergesort_module::bubblesort ( integer, intent(in)  mode,
integer, intent(in)  length,
real(r_kind), dimension(:), intent(inout)  arr1,
integer, dimension(:), intent(out), optional  arr2 
)

Bubblesort of array.

This subroutine performs a bubblesort of an array. See the following illustration (from wikipedia):

Illustration of a bubblesort

The subroutine is able to run in 2 modes,

  • mode 0 : Ascending order
  • mode 1 : Descending order

Furthermore, a second array can be given which will return the indices of the changes within the first array.

See also
reorder, tw_rate_module::readweak_logft
Author
M. Reichert
Parameters
[in,out]arr1Array to get sorted
[out]arr2Indices of the sort
[in]lengthLength of the arrays
[in]mode0 descending; 1 ascending

Definition at line 723 of file mergesort_module.f90.

Here is the call graph for this function:

◆ mergesort_finalize()

subroutine, public mergesort_module::mergesort_finalize

Close files and finalize this module.

This subroutine closes the debug file "debug_tabln.dat"

Author
: Moritz Reichert

Edited:

  • 07.06.17

Definition at line 636 of file mergesort_module.f90.

Here is the call graph for this function:

◆ mergesort_init()

subroutine, public mergesort_module::mergesort_init

Initialize the mergesort module and open files for debugging.

The file debug_tabln.dat is created in case of verbose_level>2.

Author
Moritz Reichert

Edited:

  • 06.06.17

Definition at line 47 of file mergesort_module.f90.

Here is the call graph for this function:

◆ nurate_ms()

subroutine, public mergesort_module::nurate_ms ( type(nurate_type), dimension(xs), intent(in)  x,
integer, intent(in)  xs,
type(nurate_type), dimension(ys), intent(in)  y,
integer, intent(in)  ys,
integer, intent(in)  r 
)

Merges two tables of neutrino rates (of type global_class::nurate_type).

Parameter r is a flag with the following meaning:

Explanation of the flag "r"
r mode Behavior
1 Values of y replace corresponding values of x
2 Values of x replace corresponding values of y
other Both values are stored one after the other\
Remarks
At the moment, this function is only called with \( r=0 \) i.e., case "other".
See also
rrate_ms, network_init_module::network_init

Edited:

  • 11.01.14
Parameters
[in]xsLength of x
[in]ysLength of y
[in]xthe first nurates table
[in]ythe second nurates table
[in]rflag

Definition at line 87 of file mergesort_module.f90.

Here is the call graph for this function:

◆ qsort()

recursive subroutine, private mergesort_module::qsort ( type (reactionrate_type), dimension(na), intent(inout)  A,
integer, intent(in)  nA 
)
private

Modified quicksort algorithm.

A quicksort is a recursive sorting algorithm. An illustration of it is shown in the following (Source en.wikipedia):

Illustration of the quicksort

In this gif, the red indicated number is the so called pivot-element.

See also
Rosettacode, rateSortKey, rrate_qs_replace

Edited:

  • 15.04.15
  • 25.4.19, M.R.
Parameters
[in,out]aReaction rate array
[in]naLength of the investigated reaction rate array. The recursion anchor of the routine is given for nA \(\le =1 \).

Definition at line 555 of file mergesort_module.f90.

Here is the call graph for this function:

◆ quicksort()

recursive subroutine, public mergesort_module::quicksort ( integer, intent(in)  mode,
integer, intent(in)  length,
real(r_kind), dimension(:), intent(inout)  arr1,
integer, dimension(:), intent(out), optional  arr2,
logical, intent(in), optional  is_recursion 
)

Quicksort of array.

This subroutine performs a quicksort of an array. A quicksort is a recursive sorting algorithm. An illustration of it is shown in the following (Source en.wikipedia):

Illustration of the quicksort

In this gif, the red indicated number is the so called pivot-element. In contrast to QSort, this subroutine is able to sort an array that is not a derived type and comes in form of an array of doubles. The subroutine is able to run in 2 modes,

  • mode 0 : Ascending order
  • mode 1 : Descending order

Furthermore, a second array can be given which will return the indices of the changes within the first array.

See also
Rosettacode,
reorder
Author
M. Reichert
Date
08.05.24
Parameters
[in,out]arr1Array to get sorted
[out]arr2Indices of the sort
[in]lengthLength of the arrays
[in]mode0 descending; 1 ascending
[in]is_recursionFlag to indicate if the subroutine is called recursively

Definition at line 809 of file mergesort_module.f90.

Here is the call graph for this function:

◆ reorder()

subroutine, public mergesort_module::reorder ( real(r_kind), dimension(:), intent(inout)  arr1,
integer, dimension(:), intent(in)  arr2,
integer, intent(in)  length 
)

Takes an array and an array with indices to reorder the first array.

See also
bubblesort, tw_rate_module::readweak_logft
Author
M. Reichert
Parameters
[in,out]arr1Array to reorder
[in]arr2Array containing the indices
[in]lengthLength of the arrays

Definition at line 900 of file mergesort_module.f90.

Here is the call graph for this function:

◆ reorder_int()

subroutine, public mergesort_module::reorder_int ( integer, dimension(:), intent(inout)  arr1,
integer, dimension(:), intent(in)  arr2,
integer, intent(in)  length 
)

Takes an array and an array with indices to reorder the first array.

Same as reorder, but for integer arrays.

See also
bubblesort, tw_rate_module::readweak_logft
Author
M. Reichert
Parameters
[in,out]arr1Array to reorder
[in]arr2Array containing the indices
[in]lengthLength of the arrays

Definition at line 931 of file mergesort_module.f90.

Here is the call graph for this function:

◆ rrate_ms()

subroutine, public mergesort_module::rrate_ms ( type(reactionrate_type), dimension(xs), intent(in)  x,
integer, intent(in)  xs,
type(reactionrate_type), dimension(ys), intent(in)  y,
integer, intent(in)  ys,
integer, intent(in)  r,
integer, intent(out)  ptz,
type(reactionrate_type), dimension(:), intent(out), optional, allocatable  rate_out 
)

Merges two tables of rates (of type global_class::reactionrate_type).

Parameter r is a flag with the following meaning:

Evolution mode switches
r mode Behavior
1 Values of y replace corresponding values of x
2 Values of x replace corresponding values of y
other Both values are stored one after the other\

In case of theoretical weak rates that get merged, this function counts the amount of rates that get replaced.

Remarks
The function is used to merge the rate array with theoretical weak rates (with r=1) and neutrino rates (r=0).
See also
nurate_ms, network_init_module::network_init

Edited:

  • 17.02.14
  • 27.01.21, MR - introduced "rate_out" instead of writing directly to rrate
  • 04.08.22, MR - removed hardcoded " ffn" flag and replaced it with "rrs_twr"
Parameters
[in]xsLength of x
[in]ysLength of y
[in]xthe first nurates table
[in]ythe second nurates table
[in]rflag
[out]ptzlength of new (merged) array
[out]rate_outreturns the merged
[out]rate_outreactions in this array, if present

Definition at line 226 of file mergesort_module.f90.

Here is the call graph for this function:

◆ rrate_qs_replace()

subroutine, public mergesort_module::rrate_qs_replace ( type(reactionrate_type), dimension(xs), intent(in)  x,
integer, intent(in)  xs,
type(reactionrate_type), dimension(ys), intent(in)  y,
integer, intent(in)  ys,
integer, intent(in)  r,
type(reactionrate_type), dimension(:), intent(out), allocatable  out_array,
integer, intent(out)  ptz 
)

Wrapper around the quicksort subroutine.

This subroutine is able to replace rates that appear with multiple entries in the REACLIB (e.g., because it has a resonance) with a tabulated rate. In debug mode, the file debug_tabln.dat is written to debug this subroutine.

See also
qsort
Author
D. Martin

Edited:

  • 15.04.15
  • 07.06.17
  • 04.08.22, MR: removed hardcoded "tabl" flag and replaced it with "rrs_tabl"
  • 05.08.22, MR: fixed bug and gave a new array as output (out_array)
Parameters
[in]ysreplacement rule, lenghts of arrays
[in]xarray 1 (rrate)
[in]yarray 2 (tabl)
[out]out_arraynew merged array

Definition at line 424 of file mergesort_module.f90.

Here is the call graph for this function:

◆ rrate_sort()

subroutine, public mergesort_module::rrate_sort ( integer, intent(in)  num,
type(reactionrate_type), dimension(num), intent(inout)  rate_array 
)

Sorts chapter one of the rate array.

The sorting is based on the second nucleus in the rate array.

Example

 Rate 1: cl34 (Z=17) ->  s34 (Z=16)
 Rate 2: cl36 (Z=17) -> ar36 (Z=18)
 Rate 3: cl36 (Z=17) ->  s36 (Z=16)
 Rate 4: cl38 (Z=17) -> ar38 (Z=18)
 

will switch the order of the rates to:

 Rate 1: cl34 (Z=17) ->  s34 (Z=16)
 Rate 3: cl36 (Z=17) ->  s36 (Z=16)
 Rate 2: cl36 (Z=17) -> ar36 (Z=18)
 Rate 4: cl38 (Z=17) -> ar38 (Z=18)
 

In case the sunet is ordered by proton number.

Warning
This subroutine assumes a certain ordering of the sunet!
Parameters
[in]numNumber of rates in chapter 1
[in,out]rate_arrayRate array that will get sorted

Definition at line 675 of file mergesort_module.f90.

Variable Documentation

◆ debug_tabl

integer, private mergesort_module::debug_tabl
private

File ID for debugging tabulated rate class.

Definition at line 20 of file mergesort_module.f90.