C+ C NAME: C SortI4 C PURPOSE: C Rearrange array into ascending numerical order C CATEGORY: C Math: sorting C CALLING SEQUENCE: subroutine SortI4(N1,N2,M1,M2,RA) C INPUTS: C N1,N2 integer logical dimensions of array RA C M1,M2 integer physical dimensions of array RA C RA(M1:M2) integer*4 array to be sorted C OUTPUTS: C RA integer*4 sorted array C RESTRICTIONS: C The logical range [N1,N2] must be a subset of physical range [M1,M2] C I.e. N1 >= M1 and N2 <= M2. C SEE ALSO: C SortI2, SortR4, SortR8, Sort2I4, Rank, IndexI4 C MODIFICATION HISTORY: C 1990, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C- integer N1 integer N2 integer M1 integer M2 integer*4 RA(M1:M2) integer*4 RRA L = (N2-N1+1)/2+N1 IR = N2 10 if (L .gt. N1) then L = L-1 RRA = RA(L) else RRA = RA(IR) RA(IR) = RA(N1) IR = max(N1,IR-1) ! 'max' needed to sort one element (N1=N2) if (IR .eq. N1) then RA(N1) = RRA return end if end if I = L J = L+L-N1+1 do while (J .le. IR) if (J .lt. IR) then if (RA(J) .lt. RA(J+1)) J=J+1 end if if (RRA .lt. RA(J)) then RA(I) = RA(J) I = J J = J+J-N1+1 else J = IR+1 end if end do RA(I) = RRA go to 10 end