C #TAGSA   V1A   22-FEB-72.
C LAST UPDATE:
C  
      SUBROUTINE TAGSA(A,ITAG,N)
      DIMENSION  A(N),ITAG(N)
C 
C *PURPOSE.
C 	TO SET UP AN ARRAY OF INDICES ITAG(I) WHICH WILL
C ORDER THE REAL ARRAY A(I).  EXPLICITLY THE VALUES
C A( ITAG(I) ) WILL BE ALGEBRAICALLY INCREASING WITH I.
C  
C *PARAMETERS:
C  
C  A   - THE REAL ARRAY OF DIMENSION "N" OR MORE WHOSE FIRST "N"
C 	ELEMENTS DIRECT THE SORT.  THE ARRAY "A" IS NOT CHANGED
C 	IN ANY WAY.
C  ITAG- AN INTEGER ARRAY OF DIMENSION "N" OR MORE WHOSE FIRST "N"
C 	ELEMENTS WILL BE SET TO THE INTEGERS 1 TO N IN THE REQUIRED
C 	ORDER.
C  N   - THE LOGICAL LENGTH OF THE VECTOR TO BE SORTED.
C  
C INPUT PARAMETERS:
C 	A, N
C OUTPUT PARAMETERS:
C 	ITAG
C  
C *METHOD.
C       A SLIGHT ADAPTION OF THE STANDARD "SINKING SORT" METHOD IS
C USED.
C  
C *ACCURACY.
C  
C *RESTRICTIONS.
C  
C *ERROR CONDITIONS.
C  
C *NONSTANDARD ROUTINES CALLED.
C  
C *TYPICAL TIMES.
C  
C *ORIGIN   M.R.MANNING.
C  
C *COMMENTS.
C       AS WITH SORTA AND SORTB THE ROUTINE TAGSB WILL BE
C SIGNIFICANTLY FASTER FOR LARGE AND POORLY ORDERED ARRAYS.
C  
C #END.
C
C #START.
      I=1
      ITAG(1)=1
10    IF(I.GE.N) RETURN
      J=I+1
      ITAG(J)=J
      L=ITAG(I)
      T=A(J)
      IF(A(L).LE.T) GO TO 30
      K=I
20    ITAG(K+1)=L
      K=K-1
      IF(K) 25,25,24
24    L=ITAG(K)
      IF(T.LT.A(L) ) GO TO 20
25    ITAG(K+1)=J
30    I= J
      GO TO 10
C
      END

