C....*...1.........2.........3.........4.........5.........6.........7.*.......8
C     DSORT    7/2/73
C
C     PURPOSE
C     SORT A VECTOR INTO AN ASCENDING SEQUENCE.
C
C     USAGE
C     CALL DSORT(A,N,R)
C
C     ARGUMENTS
C     A - INPUT VECTOR OF LENGTH N.
C         REAL*8
C     N - LENGTH OF X AND R.
C         INTEGER*4
C     R - VECTOR OF LENGTH N CONTAINING SORTED X'S ON RETURN.
C         REAL*8
C
C     REMARK
C     FOR A SORT IN PLACE USE:
C     CALL DSORT(A,N,A)
C
C
      SUBROUTINE DSORT(A,N,R)
      implicit real*8 (a-h,o-z)
      save
      REAL*8 A(1),R(1),B
      DO 10 I=1,N
10    R(I)=A(I)
C
C     SHELL SORT
C
      M=N
 20   M=M/2
      IF(M)30,40,30
 30   K=N-M
      J=1
 41   I=J
 49   L=I+M
      IF(R(I)-R(L))60,60,50
 50   B=R(I)
      R(I)=R(L)
      R(L)=B
      I=I-M
      IF(I-1)60,49,49
 60   J=J+1
      IF(J-K)41,41,20
 40   CONTINUE
C
C
      RETURN
      END
