Portability Subroutine: Performs a quick sort on an array of rank one.
Module: USE IFPORT
Syntax
CALL QSORT (array, len, isize, compar)
array
(Input) Any type. One-dimensional array to be sorted.
If the data type does not conform to one of the predefined interfaces for QSORT, you may have to create a new interface (see below).
len
(Input) INTEGER(4) on IA-32 architecture; INTEGER(8) on Intel® 64 and IA-64 architectures. Number of elements in array.
isize
(Input) INTEGER(4) on IA-32 architecture; INTEGER(8) on Intel® 64 and IA-64 architectures. Size, in bytes, of a single element of array:
compar
(Input) INTEGER(2). Name of a user-defined ordering function that determines sort order. The type declaration of compar takes the form:
INTEGER(2) FUNCTION compar(arg1, arg2)
In place of an INTEGER kind, you can specify the constant SIZEOF_SIZE_T, defined in IFPORT.F90
, for argument len or isize. Use of this constant ensures correct compilation.
If you use QSORT with different data types, your program must have a USE IFPORT statement so that all the calls work correctly. In addition, if you wish to use QSORT with a derived type or a type that is not in the predefined interfaces, you must include an overload for the generic subroutine QSORT. Examples of how to do this are in the portability module's source file, IFPORT.F90
.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
Example
PROGRAM SORTQ
USE IFPORT
integer(2), external :: cmp_function
integer(2) insort(26), i
integer (SIZEOF_SIZE_T) array_len, array_size
array_len = 26
array_size = 2
do i=90,65,-1
insort(i-64)=91 - i
end do
print *, "Before: "
print *,insort
CALL qsort(insort,array_len,array_size,cmp_function)
print *, 'After: '
print *, insort
END
!
integer(2) function cmp_function(a1, a2)
integer(2) a1, a2
cmp_function=a1-a2
end function