- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi. Can anyone quickly teach me how to sort an array? (i.e. I want to transform x=[2,1,3,5] into x=[1,2,3,5] or x=[5,3,2,1]) Is there any intrinsic routine that does the job?
Thank you so much.
Thank you so much.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SUBROUTINE indexx (n,arrin,indx)
IMPLICIT NONE
INTEGER,INTENT(IN) :: n
REAL,INTENT(IN),DIMENSION(n) :: arrin
INTEGER,INTENT(OUT),DIMENSION(n) :: indx
INTEGER :: i,j,pivot,ir,indxt
REAL :: q
! builds a sorted index array INDX of the
! N input elements in array ARRIN
DO j = 1, n
indx(j) = j
END DO
pivot = n/2 + 1
ir = n
10 IF (pivot > 1) THEN
pivot = pivot - 1
indxt = indx(pivot)
q = arrin(indxt)
ELSE
indxt = indx(ir)
q = arrin(indxt)
indx(ir) = indx(1)
ir = ir-1
IF (ir == 1) THEN
indx(1) = indxt
RETURN
END IF
END IF
i = pivot
j = pivot + pivot
20 IF (j <= ir) THEN
IF (j < ir .AND. arrin(indx(j)) < arrin(indx(j+1))) j = j + 1
IF (q < arrin(indx(j))) THEN
indx(i) = indx(j)
i = j
j = j + j
ELSE
j = ir + 1
END IF
GOTO 20
END IF
indx(i) = indxt
GO TO 10
END SUBROUTINE indexx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know how big of sorting you need to do, but there is an excellent sorting & ranking package called ORDERPACK available for free. If you Google on ORDERPACK and sort you should find it.
HTH,
matt.
HTH,
matt.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page