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 elementxdont(i)it returns inigoest(i) the rank of its value among the distinct values ofxdonttaken in ascending order, so[3,1,3,2,1,5]gives[3,1,3,2,1,4]. Only the firstmin(size(xdont),size(igoest))elements are considered. It is adapted from the ORDERPACK library and it is used byunista.- 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 firstnunielements contain the unique values and the other ones are left unchanged. If the optional argumentmask, of sizesize(xdont), is present it is true for the first occurrence of each value. It relies onuniinv.- 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 inAIN, and returns them in the allocatable arrayAOUT. The input array is overwritten: its firstsize(AOUT)elements contain the unique values and the other ones are left unchanged. If the optional argumentMASKis present it is allocated with sizesize(AIN)and is true for the first occurrence of each value. The function form isuniq. It relies onunista.- 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 argumentMASKis present it is allocated with sizesize(AIN)and is true for the first occurrence of each value. The subroutine form isuniq_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 toNdim. If it is not, the messageroutine error: matname has illegal shapeis printed, only if bothroutineandmatnameare present, and the program stops with the messageassert_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
Ainin place, moving the elementAin(i)to the positionIndex(i), that isAout(Index(i)) = Ain(i). The arrayIndexmust be a permutation of1..size(Ain). Note that this is the inverse of the permutation returned asindxbysort: to apply the latter usea(indx). The function form isreorder.- 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 elementAin(i)moved to the positionIndex(i), that isAout(Index(i)) = Ain(i). The arrayIndexmust be a permutation of1..size(Ain), andAinis unchanged. The subroutine form isreorder_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
ain ascending order, in place, using the insertion method, whose cost scales as \(N^2\), so it is meant for small arrays. The argumentindx_a, of sizesize(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
ain ascending order, in place, using the quicksort algorithm with the median of the first, middle and last elements as pivot. If the optional argumentindxis 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 namessortandsort_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
ain ascending order, in place, using the quicksort algorithm with the median of the first, middle and last elements as pivot. If the optional argumentindxis 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 ofsort_quicksort, also available assort_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
ain ascending order, in place, using the quicksort algorithm, and it is an alias ofsort_quicksort, see there for the description. If the optional argumentindxis 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
ain ascending order, in place, using a somehow slower implementation of the quicksort algorithm that chooses the pivot at random withrandom_number. The argumentindx_a, of sizesize(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 inindx_acan 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]