sort(3f) - [M_datapac:SORT] sort a vector of sample observations, also return the positions in the original vector
Synopsis
Description
Options
Input
Output
Examples
Author
Maintainer
References
License
SUBROUTINE SORT(X,N,Y)
real,intent(in) :: x(:) integer,intent(in) :: n real,intent(out) :: y(:)
This subroutine sorts (in ascending order) the N elements of the REAL vector X using the binary sort algorithm and puts the resulting N sorted values into the REAL vector Y.
X The REAL vector of observations to be sorted. The input vector X remains unaltered. N The integer number of observations in the vector X.
Y The REAL vector into which the sorted data values from X will be placed in ascending order.
Sample program:
program demo_sort use M_datapac, only : sort implicit none integer,parameter :: isz=20 real :: aa(isz) real :: bb(isz) integer :: i write(*,*)initializing array with ,isz, random numbers call random_seed() CALL RANDOM_NUMBER(aa) aa=aa*450000.0 bb=real([(i,i=1,isz)])Results:call sort(aa,isz,bb) ! sort data
write(*,*)checking if real values are sorted(3f) do i=1,isz-1 if(bb(i).gt.bb(i+1))then write(*,*)Error in sorting reals small to large ,i,bb(i),bb(i+1) endif enddo write(*,(2(g0,1x)))ORIGINAL,SORTED,(aa(i),bb(i),i=1,isz)
end program demo_sort
The original DATAPAC library was written by James Filliben of the Statistical Engineering Division, National Institute of Standards and Technology.
John Urban, 2022.05.31
1. CACM MARCH 1969, page 186 (BINARY SORT ALGORITHM BY RICHARD C. SINGLETON). 2. CACM JANUARY 1970, page 54. 3. CACM OCTOBER 1970, page 624. 1. JACM JANUARY 1961, page 41.
CC0-1.0
Nemo Release 3.1 | sort (3) | February 23, 2025 |