!+ Subroutine to perform a shell sort.
!
! Method:
!	The standard shell sorting algorithm is implemented.
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	Version		Date			Comment
!	1.0		12-04-95		First Version under RCS
!						(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77  with extensions listed in documentation.
!
!- ---------------------------------------------------------------------
      SUBROUTINE SHELL_SORT(N, POINTER, KEY)
!
!
      IMPLICIT NONE
!
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(IN)
     &     N
!             NUMBER OF ELEMENTS
      INTEGER	!, INTENT(INOUT)
     &     POINTER(N)
!             POINTER TO SUCCEEDING ELEMENTS
      REAL*8	!, INTENT(IN)
     &     KEY(N)
!             KEY FOR SORTING
!
!     LOCAL VARIABLES.
      INTEGER
     &     GAP
!             SEARCHING INTERVAL
     &   , POINTER_TEMP
!             TEMPORARY VALUE OF POINTER
     &   , J
!             LOOP VARIABLE
     &   , K
!             LOOP VARIABLE
!
!
      GAP=N
1     GAP=GAP/2
         DO J=GAP, N-1
            DO K=J-GAP+1, 1, -GAP
               IF (KEY(POINTER(K)).GT.KEY(POINTER(K+GAP))) THEN
                  POINTER_TEMP=POINTER(K)
                  POINTER(K)=POINTER(K+GAP)
                  POINTER(K+GAP)=POINTER_TEMP
               ENDIF
            ENDDO
         ENDDO
      IF (GAP.GE.2) GOTO 1
!
!
      RETURN
      END
