      SUBROUTINE ISORTS(A,IDX,N)  ! Shell sort (integer)
*     integer keys A(*), unchanged at return 
*     N indices IDX(1) ... IDX(N), changed at return such that
*        A(IDX(L)) <= A(IDX(L+1)) 
      INTEGER I,J,M,IDXT,N,IDX(*)
      INTEGER A(*)                ! array of keys 
      M=4
 10   IF(3*M+1.LT.N) THEN    ! determine initial increment
         M=3*M+1
         GOTO 10
      END IF
 20   M=M/3                  ! next increment
      DO I=1+M,N             ! ... used in insert sort
       IDXT=IDX(I) 
       J=I
 30    IF(A(IDX(J-M)).GT.A(IDXT)) THEN
          IDX(J)=IDX(J-M)
          J=J-M
          IF(J.GT.M) GOTO 30 
       END IF
       IDX(J)=IDXT
      END DO 
      IF(M.GT.1) GOTO 20
      END
