SF_MISC

Description

SciFortran module for sundry functions

Quick access

Routines:

assert_shape(), reorder(), reorder_array(), sort(), sort_array(), sort_insertion(), sort_qsort(), sort_quicksort(), uniinv(), uniq(), uniq_array(), unista()

Subroutines and functions

interface  sf_misc/uniinv(xdont, igoest)

This subroutine evaluates the merge-sort inverse ranking of a real(8), real(4) or integer array xdont, with removal of the duplicate entries: for each element xdont(i) it returns in igoest ( i ) the rank of its value among the distinct values of xdont taken in ascending order, so [3,1,3,2,1,5] gives [3,1,3,2,1,4]. Only the first min(size(xdont),size(igoest)) elements are considered. It is adapted from the ORDERPACK library and it is used by unista.

Parameters:
  • xdont (•) [real/integer, in] – array to rank

  • igoest (•) [integer, out]

interface  sf_misc/unista(xdont, nuni[, mask])

This subroutine is a stable unique: it removes the duplicates from a real(8), real(4) or integer array xdont, leaving the unique entries in the order of their first appearance. The input array is overwritten: its first nuni elements contain the unique values and the other ones are left unchanged. If the optional argument mask, of size size(xdont), is present it is true for the first occurrence of each value. It relies on uniinv.

Parameters:
  • xdont (•) [real/integer, inout/in,required] – array to reduce; first nuni elements become the unique values

  • nuni [integer, out]

Options:

mask (size(xdont)) [logical]

interface  sf_misc/uniq_array(ain, aout[, mask])

This subroutine removes the duplicates from an integer or real(8) array AIN, leaving the unique entries in the order of their first appearance in AIN, and returns them in the allocatable array AOUT. The input array is overwritten: its first size(AOUT) elements contain the unique values and the other ones are left unchanged. If the optional argument MASK is present it is allocated with size size(AIN) and is true for the first occurrence of each value. The function form is uniq. It relies on unista.

Parameters:
  • ain (•) [integer/real, inout] – array to reduce; first elements become the unique values

  • aout (•) [integer/real, out,allocatable]

Options:

mask (•) [logical, out,allocatable]

interface  sf_misc/uniq(ain[, mask])

This function returns the unique entries of an integer or real(8) array AIN, in the order of their first appearance, as an allocatable array. The input array is overwritten: its first elements contain the unique values and the other ones are left unchanged. If the optional argument MASK is present it is allocated with size size(AIN) and is true for the first occurrence of each value. The subroutine form is uniq_array.

Parameters:

ain (•) [integer/real, inout] – array to reduce; first elements become the unique values

Options:

mask (•) [logical, out,allocatable]

Result:

aout (•) [integer/real, allocatable]

interface  sf_misc/assert_shape(a, ndim[, routine, matname])

This subroutine checks that the shape of the integer, real(8) or complex(8) array A, of rank 1 to 7 (8 with gfortran newer than 8), is equal to Ndim. If it is not, the message routine error: matname has illegal shape is printed, only if both routine and matname are present, and the program stops with the message assert_shape error: wrong matrix shape. The source has to be preprocessed.

Parameters:
  • a (various shapes) [integer/real/complex, in] – array whose shape is checked: integer, real(8) or complex(8)

  • ndim (•) [integer, in] – expected shape, one element for each dimension of A

Options:
  • routine [character(len=*)]

  • matname [character(len=*)] – calling routine and array names, for the error message

interface  sf_misc/reorder_array(ain, index)

This subroutine reorders a one-dimensional integer, real(8), complex(8) or logical array Ain in place, moving the element Ain(i) to the position Index(i), that is Aout(Index(i)) = Ain(i). The array Index must be a permutation of 1..size(Ain). Note that this is the inverse of the permutation returned as indx by sort: to apply the latter use a(indx). The function form is reorder.

Parameters:
  • ain (•) [integer/real/complex/logical, in,required] – array to reorder

  • index (size(ain)) [integer] – permutation: Ain(i) is moved to position Index(i)

interface  sf_misc/reorder(ain, index)

This function returns a reordered copy of a one-dimensional integer, real(8), complex(8) or logical array Ain, with the element Ain(i) moved to the position Index(i), that is Aout(Index(i)) = Ain(i). The array Index must be a permutation of 1..size(Ain), and Ain is unchanged. The subroutine form is reorder_array.

Parameters:
  • ain (•) [integer/real/complex/logical, in,required] – array to reorder

  • index (size(ain)) [integer] – permutation: Ain(i) is moved to position Index(i)

Result:

aout (size(ain)) [integer/real/complex/logical]

interface  sf_misc/sort_insertion(a, indx_a)

This subroutine sorts an integer or real(8) array a in ascending order, in place, using the insertion method, whose cost scales as \(N^2\), so it is meant for small arrays. The argument indx_a, of size size(a), is required and returns the permutation that sorts the input array, a_sorted(i) = a_in(indx_a(i)). The sort is stable.

Parameters:
  • a (•) [integer/real, inout/in,required] – array to sort, overwritten with the values in ascending order

  • indx_a (size(a)) [integer, inout]

interface  sf_misc/sort_quicksort(a[, indx])

This subroutine sorts an integer or real(8) array a in ascending order, in place, using the quicksort algorithm with the median of the first, middle and last elements as pivot. If the optional argument indx is present it returns the permutation that sorts the input array, a_sorted(i) = a_in(indx(i)). The sort is not stable. It is also available under the names sort and sort_array.

Parameters:

a (•) [integer/real, inout/in,required] – array to sort, overwritten with the values in ascending order

Options:

indx (size(a)) [integer, inout]

interface  sf_misc/sort(a[, indx])

This subroutine sorts an integer or real(8) array a in ascending order, in place, using the quicksort algorithm with the median of the first, middle and last elements as pivot. If the optional argument indx is present it returns the permutation that sorts the input array, a_sorted(i) = a_in(indx(i)). The sort is not stable. It is the generic name of sort_quicksort, also available as sort_array.

Parameters:

a (•) [integer/real, inout/in,required] – array to sort, overwritten with the values in ascending order

Options:

indx (size(a)) [integer, inout]

interface  sf_misc/sort_array(a[, indx])

This subroutine sorts an integer or real(8) array a in ascending order, in place, using the quicksort algorithm, and it is an alias of sort_quicksort, see there for the description. If the optional argument indx is present it returns the permutation that sorts the input array, a_sorted(i) = a_in(indx(i)).

Parameters:

a (•) [integer/real, inout/in,required] – array to sort, overwritten with the values in ascending order

Options:

indx (size(a)) [integer, inout]

interface  sf_misc/sort_qsort(a, indx_a)

This subroutine sorts an integer or real(8) array a in ascending order, in place, using a somehow slower implementation of the quicksort algorithm that chooses the pivot at random with random_number. The argument indx_a, of size size(a), is required and returns the permutation that sorts the input array, a_sorted(i) = a_in(indx_a(i)). The sort is not stable, and the order of equal elements in indx_a can change between runs.

Parameters:
  • a (•) [integer/real, inout/in,required] – array to sort, overwritten with the values in ascending order

  • indx_a (size(a)) [integer, inout]