C   12/03/84 406222013  MEMBER NAME  SORT1    (S)           FORTRAN
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C
       SUBROUTINE SORT1(ISTART,IEND,IWRITE)
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C THIS ROUTINE SORTS THE CONTENTS OF CATAG INTO ORDER OF ENERGY AND
C PUTS THE ESULTING LIST IN SADC(32,2) WHERE SADC(I,1) = ADDRESS OF BLOC
C AND SADC(I,2) = CONTENTS
C
C ISTART - INPUT - FIRST ADDRESS IN CATAG FROM WHICH DATA SHOULD BE TAKE
C IEND  - INPUT - LAST ADDRESS IN CATAG FROM WHICH DATA SHOULD BE TAKEN
C
C IWRITE - INPUT - FLAG TO TURN ON DEBUGGING INFO IF SET TO 1
C
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
#include "cwktag.for"
C
       DIMENSION STEMP(2)
C
C                                   COPY THE CONTENTS OF PART OF
C                                   CATAG TO BE SORTED INTO SADC
C                                   PLUS ADC ADDRESSES
C
       L = 1
C
       DO 5 I = ISTART,IEND
          SADC(L,1) = I
          SADC(L,2) = CATAG(I)
          L = L + 1
    5  CONTINUE
C
C---DEBUG--------------------------------DEBUG  START-------------------
C
       IF ( IWRITE .EQ. 0) GOTO 101
       WRITE(6,601)
  601  FORMAT('  CONTENTS OF SADC BEFORE SORT ')
       DO 91 I = 1,IENDMZ,8
          WRITE(6,901) SADC(I,2),SADC(I+1,2),SADC(I+2,2),SADC(I+3,2),
     *                 SADC(I+4,2 ),SADC(I+5,2),SADC(I+6,2),SADC(I+7,2)
   91  CONTINUE
C
C---DEBUG--------------------------------DEBUG  END---------------------
C
  101  CONTINUE
C
C
C                                   NOW DO SORT ON SADC
C
       IELOO = IEND - ISTART
       DO 10 J = 1 ,IELOO
          DO 11 K = 1,IELOO
             IF ( SADC(K,2) .GT. SADC(K+1,2) )  GOTO 11
             STEMP(1)    = SADC(K,1)
             STEMP(2)    = SADC(K,2)
             SADC(K,1)   = SADC(K+1,1)
             SADC(K,2)   = SADC(K+1,2)
             SADC(K+1,1) = STEMP(1)
             SADC(K+1,2) = STEMP(2)
   11     CONTINUE
   10  CONTINUE
C
C
       IF ( IWRITE .EQ. 0) GOTO 100
C
C
C---DEBUG ONLY---------------------------DEBUG  ONLY--------------------
C
C
       WRITE(6,600)
  600  FORMAT('  CONTENTS OF SADC AFTER SORT ')
       DO 80 I = 1,IENDMZ,8
          WRITE(6,901) SADC(I,2),SADC(I+1,2),SADC(I+2,2),SADC(I+3,2),
     *                 SADC(I+4,2),SADC(I+5,2),SADC(I+6,2),SADC(I+7,2)
   80  CONTINUE
  901  FORMAT(8(3X,F10.2) )
C
C
  100  RETURN
       END
