      PROGRAM HPHI
      integer*1 nxi,nci
      ALLOCATABLE::Q(:,:),XI(:),NXI(:,:),LAST(:),NCI(:),NCMEM(:)
      ALLOCATABLE::NTEMP(:),MSUM(:),SUMX(:),BSET(:,:),NBSET(:,:)
      ALLOCATABLE::NP(:),NQ(:),MEMBER(:,:),STORE(:,:,:),NSTORE(:,:)
      DIMENSION NSTIR(20,20),NA(20),NB(20),Y(20),NENDPT(2,20),NU(20)
      ALLOCATABLE::NCSIZE(:),TMP(:)
      COMMON/PARAM/NOPT,N,MOPT,MGREED
      CHARACTER*80 FNAME,GNAME,INFORM
      LOGICAL MTC
C**********************INPUT SETUP***********
      WRITE(*,*) 'MAIN MENU'
      WRITE(*,*) '1  AVERAGE PROXIMITY WITHIN SUBSET (USING TWICE'
      WRITE(*,*) '   THE NUMBER OF OBJECTS)'
      WRITE(*,*) '2  AVERAGE PROXIMITY WITHIN SUBSET (USING THE'
      WRITE(*,*) '   NUMBER OF OBJECT PAIRS)'
      WRITE(*,*) '3  SUM OF PROXIMITIES WITHIN SUBSET'
      WRITE(*,*) '4  MAXIMUM PROXIMITY WITHIN SUBSET'
      WRITE(*,*) '5  AVERAGE WITHIN MINUS AVERAGE BETWEEN'
      WRITE(*,*) '6  NUMBER OF PROXIMITIES WITHIN GREATER THAN BETWEEN'
      WRITE(*,*) '7  NORMALIZED OPTION 6'
      WRITE(*,*) '8  COMMON OBJECT INCONSISTENCIES WITHIN VERSUS'
      WRITE(*,*) '   BETWEEN'
      WRITE(*,*) '9  NORMALIZED OPTION 8'
      WRITE(*,*) '10 NEGATIVE OF THE AVERAGE BETWEEN'
      WRITE(*,*) '11 MINIMUM CONNECTIVITY PROXIMITY'
      WRITE(*,*) '12 SPANNING TREE LENGTH'
      WRITE(*,*) '13 BETWEEN SUM OF SQUARES FROM MEAN WITH ORDER '
      WRITE(*,*) '   CONSTRAINTS PLUS LATER UNION CONSTRAINTS'
      WRITE(*,*) '14 BETWEEN SUM OF SQUARES FROM MEAN WITH ORDER'
      WRITE(*,*) '   CONSTRAINTS ONLY'
      WRITE(*,*) '15 ABSOLUTE SUM OF DEVIATIONS FROM MEDIAN WITH ORDER'
      WRITE(*,*) '   CONSTRAINTS PLUS LATER UNION CONSTRAINTS'
      WRITE(*,*) '16 SAME AS 15 BUT NO LATER UNION CONSTRAINTS'
      WRITE(*,*) '17 LARGEST ABSOLUTE DEVIATION FROM THE AVERAGE OF'
      WRITE(*,*) '   TWO EXTREMES PLUS LATER UNION CONSTRAINTS'
      WRITE(*,*) '18 SAME AS 17 BUT NO LATER UNION CONSTRAINTS'
      WRITE(*,*) '19 ULTRAMETRIC ORDER INCONSISTENCIES --- COMMON'
      WRITE(*,*) '   OBJECTS ARE NECESSARY'
      WRITE(*,*) '20 ULTRAMETRIC ORDER INCONSISTENCIES --- COMMON'
      WRITE(*,*) '   OBJECTS ARE UNNECESSARY'
      WRITE(*,*) 'CHOICE'
      READ(*,1) NOPT
      WRITE(*,552)
      MOPT=1
      IF(((((((NOPT.NE.1)).AND.(NOPT.NE.2)).AND.(NOPT.NE.3))
     &.AND.(NOPT.NE.4)).AND.(NOPT.NE.11)).AND.(NOPT.NE.12)) GO TO 444
      WRITE(*,*) 'IMPOSITION OF NEW SUBSET ORDER CONSTRAINTS'
      WRITE(*,*) ' 1 NO'
      WRITE(*,*) ' 2 YES'
      WRITE(*,*) 'CHOICE?'
      READ(*,1) MOPT
      WRITE(*,552)
444   MGREED = 2
      IF((NOPT.EQ.5).OR.(NOPT.EQ.10)) MGREED=3
      IF(NOPT.GE.13) MGREED=1
1     FORMAT(BN,I6)
552   FORMAT(1H )
      WRITE(*,*) 'NUMBER OF ROWS/COLUMNS FOR THE LOWER TRIANGULAR'
      WRITE(*,*) 'MATRIX-- NO DIAGONAL'
      READ(*,1) N
      WRITE(*,*) 'NUMBER OF INITIAL OBJECT CLASSES TO BE PARTITIONED?'
      READ(*,*) NCLAS
      IF((NCLAS.GE.3).AND.(NCLAS.LE.15)) GO TO 503
      WRITE(*,*) 'MATRIX OUT OF RANGE'
      STOP
503   DO 200 I=1,NCLAS
      NSTIR(I,1) = 1
      NSTIR(I,I) = 1
200   CONTINUE
      DO 2011 I=3,NCLAS
      DO 2011 J=2,I-1
      NSTIR(I,J)=J*NSTIR(I-1,J)+NSTIR(I-1,J-1)
2011  CONTINUE
      NA(NCLAS) = 1
      NSUM=1
      DO 202 I=2,NCLAS
      NA(NCLAS-I+1) = NSTIR(NCLAS,NCLAS-I+2) + NA(NCLAS-I+2)
      NSUM=NSUM+NSTIR(NCLAS,NCLAS-I+2)
202   CONTINUE
      DO 203 I=1,NCLAS
203   NB(I)=NA(I)
      NN=NSUM
      ALLOCATE(Q(N,N),XI(NN),NXI(NN,NCLAS),NQ(N),STAT=IERR)
      IF(IERR.NE.0) WRITE(*,*) 'ARRAY ALLOCATION ERROR'
      IF(IERR.NE.0) STOP
      IF(IERR.EQ.0) WRITE(*,*) 'ARRAYS SUCCESSFULLY ALLOCATED'
      ALLOCATE(LAST(NN),NCI(NN),NTEMP(N),NCMEM(N),MEMBER(N,N),
     &NCSIZE(N),STAT=IERR)
      IF(IERR.NE.0) WRITE(*,*) 'ARRAY ALLOCATION ERROR'
      IF(IERR.NE.0) STOP
      IF(IERR.EQ.0) WRITE(*,*) 'ARRAYS SUCCESSFULLY ALLOCATED'
      ALLOCATE(MSUM(N),SUMX(N),BSET(N,N),NBSET(N,N),NP(N),STAT=IERR)
      IF(IERR.NE.0) WRITE(*,*) 'ARRAY ALLOCATION ERROR'
      IF(IERR.NE.0) STOP
      IF(IERR.EQ.0) WRITE(*,*) 'ARRAYS SUCCESSFULLY ALLOCATED'
      IF(NOPT.GE.15) ALLOCATE(STORE(NCLAS,NCLAS,N**2),
     &NSTORE(NCLAS,NCLAS),TMP(N**2),STAT=IERR)
      IF(IERR.NE.0) WRITE(*,*) 'ARRAY ALLOCATION ERROR'
      IF(IERR.NE.0) STOP
      IF(IERR.EQ.0) WRITE(*,*) 'ARRAYS SUCCESSFULLY ALLOCATED'
      WRITE(*,*) 'FILE NAME FOR THE INPUT MATRIX'
      READ(*,'(A)') FNAME
      WRITE(*,552)
      WRITE(*,*) 'FILE NAME FOR THE OUTPUT MATRIX'
      READ(*,'(A)') GNAME
      WRITE(*,552)
      OPEN(1,FILE=FNAME,STATUS='OLD')
      OPEN(2,FILE=GNAME)
      WRITE(*,*) 'PROVIDE FORMAT FOR THE INPUT MATRIX'
      READ(*,'(A)') INFORM
      WRITE(2,1100) NOPT
1100  FORMAT( 'TRANSITION CRITERION USED', I4)
      WRITE(2,552)
      WRITE(2,*) 'MINIMIZATION OF THE SUM'
      WRITE(2,552)
      IF(MOPT.EQ.1) WRITE(2,*)'NO SUBSET ORDER CONSTRAINTS IMPOSED'
      IF(MOPT.EQ.2) WRITE(2,*) 'SUBSET ORDER CONSTRAINTS IMPOSED'
      WRITE(2,552)
      IF(MGREED.EQ.3)
     &WRITE(2,*) 'NO PRELIMINARY GREEDY ALGORITHM USED FOR A BOUND'
      IF(MGREED.EQ.2)
     &WRITE(2,*) 'PRELIMINARY GREEDY ALGORITHM USED FOR A BOUND'
      WRITE(2,552)
      WRITE(2,*) 'INPUT MATRIX'
      DO 1002 I=2,N
      ISTOP=I-1
      READ(1,INFORM) (Q(I,J),J=1,ISTOP)
      WRITE(2,552)
      WRITE(2,1008) (Q(I,J),J=1,ISTOP)
1008  FORMAT(10F8.3)
1002  CONTINUE
      DO 1004 I=1,N
      Q(I,I)=0.0
      DO 1004 J=1,N
      Q(I,J)=Q(J,I)
1004  CONTINUE
      WRITE(2,552)
      WRITE(*,*) 'OBJECT CLASSES TO BE PARTITIONED?'
      WRITE(*,*) '1 THE SAME AS THE NUMBER OF OBJECTS'
      WRITE(*,*) '2 OBJECT CLASS MEMBERSHIP TO BE INPUT'
      READ(*,*) NOBCL
      IF(NOBCL.EQ.2) GO TO 4000
      DO 4001 I=1,N
      NCSIZE(I)=1
4001  MEMBER(I,1)=I
      GO TO 4002
4000  WRITE(*,*) 'INPUT CLASS MEMBERSHIP(SEPARATED BY BLANKS)'
      WRITE(*,*) 'WITH ZEROS INDICATING A DELETED OBJECT'
      READ(*,*) (NCMEM(I),I=1,N)
4003  FORMAT(40I2)
      DO 4004 I=1,N
4004  NCSIZE(I)=0
      DO 4005 I=1,N
      DO 4006 J=1,N
      IF(NCMEM(I).EQ.J) NCSIZE(J)=NCSIZE(J)+1
      IF(NCMEM(I).EQ.J) MEMBER(J,NCSIZE(J))=I
4006  CONTINUE
4005  CONTINUE
4002  WRITE(2,*) 'CLASS NUMBER / OBJECT MEMBERSHIP IN CLASS'
      DO 4009 I=1,NCLAS
4009  WRITE(2,4008) I,(MEMBER(I,J),J=1,NCSIZE(I))
4008  FORMAT(I3,10X,20I3)
      WRITE(2,552)
      WRITE(*,*) 'PROGRAM RUNNING'
C*********************INITIALIZING ARRAYS**********
      mtc=(n.eq.n)
      Z=1.0E+20
      NZ=0
      DO 1000 I=1,NSUM
      NCI(I) = NZ
      XI(I)=Z
      LAST(I)=1
      DO 6001 J=1,NCLAS
6001  NXI(I,J) = NZ
1000  CONTINUE
      XI(1)=0.0
C*************CONSTRUCTING AND STORING PARTITIONS********
      NN=NSUM
      NLAST=0
      KK=1
900   CONTINUE
10    IF(NCLAS.EQ.NLAST) GO TO 20
30    NLAST=NCLAS
      KK=1
      NC=1
      DO 35 I=1,NCLAS
35    NQ(I) = 1
      NP(1) = NCLAS
      NCI(NN)=NC
      DO 2001 J=1,NCLAS
2001  NXI(NN,J)=NQ(J)
40    MTC=(NC.NE.NCLAS)
      GO TO 901
20    IF(.NOT.MTC) GO TO 30
70    M=NCLAS
80    L=NQ(M)
90    IF(NP(L).NE.1) GO TO 100
95    NQ(M)=1
      M=M-1
      GO TO 80
100   NC=NC+M-NCLAS
      NP(1)=NP(1)+NCLAS-M
110   IF(L.NE.NC) GO TO 130
120   NC=NC+1
      NP(NC)=0
130   NQ(M)=L+1
      NP(L)=NP(L)-1
      NP(L+1)=NP(L+1)+1
      INDEX=NB(NC)
      NCI(INDEX)=NC
      DO 201 I=1,NCLAS
201   NXI(INDEX,I)=NQ(I)
      KK=KK+1
      NB(NC)=NB(NC)+1
      GO TO 40
901   IF(MTC) go to 900
C*********************PROCESSING THE RECURSION*********
      BOUND=1.0E+19
      NBINDEX=0
      I=1
824   IF((MGREED.EQ.1).AND.(XI(I).GT.(BOUND+.0000001))) GO TO 603
      IF(MGREED.GE.2) BOUND=1.0E+19
      write(*,*) i
      NC=NCI(I)
      GO TO (800,800,800,951,800,801,801,802,802,800,803,803,800,
     &951,6000,6000,6000,6000,951,951) NOPT
6000  DO 6081 K1=1,NC
      DO 6081 K2=1,NC
      NSTORE(K1,K2)=0
6081  CONTINUE
      DO 6002 J1=1,NCLAS
      DO 6002 J2=J1,NCLAS
      DO 6002 L1=1,NCSIZE(J1)
      DO 6002 L2=1,NCSIZE(J2)
      IF(MEMBER(J1,L1).EQ.MEMBER(J2,L2)) GO TO 6002
      IF(NXI(I,J1).LE.NXI(I,J2)) NSTORE(NXI(I,J1),NXI(I,J2)) =
     &NSTORE(NXI(I,J1),NXI(I,J2))+1
      IF(NXI(I,J1).GT.NXI(I,J2)) NSTORE(NXI(I,J2),NXI(I,J1)) =
     &NSTORE(NXI(I,J2),NXI(I,J1))+1
      IF(NXI(I,J1).LE.NXI(I,J2)) STORE(NXI(I,J1),NXI(I,J2),
     &NSTORE(NXI(I,J1),NXI(I,J2))) =
     &Q(MEMBER(J1,L1),MEMBER(J2,L2))
      IF(NXI(I,J1).GT.NXI(I,J2)) STORE(NXI(I,J2),NXI(I,J1),
     &NSTORE(NXI(I,J2),NXI(I,J1))) =
     &Q(MEMBER(J1,L1),MEMBER(J2,L2))
6002  CONTINUE
      DO 6003 J1=1,NC
      DO 6003 J2=J1,NC
      IF(NSTORE(J1,J2).LE.1) GO TO 6003
      DO 6004 I1=1,NSTORE(J1,J2)-1
      DO 6005 I2=I1+1,NSTORE(J1,J2)
      IF(STORE(J1,J2,I1).LE.STORE(J1,J2,I2)) GO TO 6005
      TEMP=STORE(J1,J2,I1)
      STORE(J1,J2,I1)=STORE(J1,J2,I2)
      STORE(J1,J2,I2) = TEMP
6005  CONTINUE
6004  CONTINUE
6003  CONTINUE
      GO TO 951
800   DO 950 K1=1,NC
      DO 950 K2=1,NC
      BSET(K1,K2)=0.0
950   NBSET(K1,K2)=0
      DO 952 J1=1,NCLAS
      DO 952 J2=J1,NCLAS
      DO 952 L1=1,NCSIZE(J1)
      DO 952 L2=1,NCSIZE(J2)
      IF(MEMBER(J1,L1).EQ.MEMBER(J2,L2)) GO TO 952
      BSET(NXI(I,J1),NXI(I,J2))=BSET(NXI(I,J1),NXI(I,J2))+
     &Q(MEMBER(J1,L1),MEMBER(J2,L2))
      NBSET(NXI(I,J1),NXI(I,J2))=NBSET(NXI(I,J1),NXI(I,J2))+1
952   CONTINUE
      DO 953 K1=1,NC-1
      DO 953 K2=K1+1,NC
      BSET(K1,K2)=BSET(K1,K2)+BSET(K2,K1)+BSET(K1,K1)+BSET(K2,K2)
      NBSET(K1,K2)=NBSET(K1,K2)+NBSET(K2,K1)+NBSET(K1,K1)+NBSET(K2,K2)
      BSET(K2,K1)=BSET(K1,K2)
      NBSET(K2,K1)=NBSET(K1,K2)
953   CONTINUE
      GO TO 951
801   DO 804 K1=1,NC
      DO 804 K2=1,NC
      BSET(K1,K2)=0.0
      NBSET(K1,K2)=0
804   CONTINUE
      DO 1500 K1=1,NC
      DO 1500 K2=K1,NC
      DO 805 J1=1,NCLAS
      DO 805 J2=J1,NCLAS
      DO 805 L1=1,NCSIZE(J1)
      DO 805 L2=1,NCSIZE(J2)
      DO 806 I1=1,NCLAS
      DO 806 I2=I1,NCLAS
      DO 806 M1=1,NCSIZE(I1)
      DO 806 M2=1,NCSIZE(I2)
      IF((MEMBER(J1,L1).EQ.MEMBER(J2,L2)).OR.  
     &(MEMBER(I1,M1).EQ.MEMBER(I2,M2))) GO TO 806
      IF(((((NXI(I,J1).EQ.K1).OR.(NXI(I,J1).EQ.K2)).AND.
     &((NXI(I,J2).EQ.K1).OR.(NXI(I,J2).EQ.K2))).AND.  
     &((((NXI(I,I1).EQ.K1).OR.(NXI(I,I1).EQ.K2)).AND.  
     &((NXI(I,I2).NE.K1).AND.(NXI(I,I2).NE.K2))).OR.  
     &(((NXI(I,I2).EQ.K1).OR.(NXI(I,I2).EQ.K2)).AND.  
     &((NXI(I,I1).NE.K1).AND.(NXI(I,I1).NE.K2))))).AND.  
     &(Q(MEMBER(J1,L1),MEMBER(J2,L2)).GT.
     &Q(MEMBER(I1,M1),MEMBER(I2,M2))))
     &BSET(K1,K2)=BSET(K1,K2)+1.0
      IF((((NXI(I,J1).EQ.K1).OR.(NXI(I,J1).EQ.K2)).AND.
     &((NXI(I,J2).EQ.K1).OR.(NXI(I,J2).EQ.K2))).AND.  
     &((((NXI(I,I1).EQ.K1).OR.(NXI(I,I1).EQ.K2)).AND.  
     &((NXI(I,I2).NE.K1).AND.(NXI(I,I2).NE.K2))).OR.  
     &(((NXI(I,I2).EQ.K1).OR.(NXI(I,I2).EQ.K2)).AND.  
     &((NXI(I,I1).NE.K1).AND.(NXI(I,I1).NE.K2)))))
     &NBSET(K1,K2)=NBSET(K1,K2)+1
806   CONTINUE
805   CONTINUE
1500  CONTINUE
      DO 807 K1=1,NC-1
      DO 807 K2=K1+1,NC
      BSET(K2,K1)=BSET(K1,K2)
      NBSET(K2,K1)=NBSET(K1,K2)
807   CONTINUE
      GO TO 951
802   DO 808 K1=1,NC
      DO 808 K2=1,NC
      BSET(K1,K2) = 0.0
      NBSET(K1,K2) = 0
808   CONTINUE
      DO 1501 K1=1,NC
      DO 1501 K2=K1,NC
      DO 809 J1=1,NCLAS
      DO 809 J2=1,NCLAS
      DO 809 L1=1,NCSIZE(J1)
      DO 809 L2=1,NCSIZE(J2)
      IF(MEMBER(J1,L1).EQ.MEMBER(J2,L2)) GO TO 809
      DO 810 I1=1,NCLAS
      DO 810 M1=1,NCSIZE(I1)
      IF(MEMBER(J1,L1).EQ.MEMBER(I1,M1)) GO TO 810
      IF(((((NXI(I,J1).EQ.K1).OR.(NXI(I,J1).EQ.K2)).AND.
     &((NXI(I,J2).EQ.K1).OR.(NXI(I,J2).EQ.K2))).AND.  
     &((NXI(I,I1).NE.K1).AND.(NXI(I,I1).NE.K2))).AND.  
     &(Q(MEMBER(J1,L1),MEMBER(J2,L2)).GT. 
     &Q(MEMBER(J1,L1),MEMBER(I1,M1))))
     &BSET(K1,K2)=BSET(K1,K2)+1.
      IF((((NXI(I,J1).EQ.K1).OR.(NXI(I,J1).EQ.K2)).AND.
     &((NXI(I,J2).EQ.K1).OR.(NXI(I,J2).EQ.K2))).AND.  
     &((NXI(I,I1).NE.K1).AND.(NXI(I,I1).NE.K2)))
     &NBSET(K1,K2)=NBSET(K1,K2)+1.  
810   CONTINUE
809   CONTINUE
1501  CONTINUE
      DO 830 K1=1,NC-1
      DO 830 K2=K1+1,NC
      BSET(K2,K1)=BSET(K1,K2)
      NBSET(K2,K1)=NBSET(K1,K2)
830   CONTINUE
      GO TO 951
803   DO 811 K1=1,NC
      DO 811 K2=1,NC
      BSET(K1,K2)=0.0
811   CONTINUE
      DO 812 K1=1,NC
      DO 812 K2=K1,NC
      NUMBER=0
      DO 813 JJ=1,NCLAS
      DO 813 J1=1,NCSIZE(JJ)
      IF((NXI(I,JJ).EQ.K1).OR.(NXI(I,JJ).EQ.K2)) NB(NUMBER+1)=
     &MEMBER(JJ,J1)
      IF((NXI(I,JJ).EQ.K1).OR.(NXI(I,JJ).EQ.K2)) NUMBER=NUMBER+1
813   CONTINUE
      IF(NUMBER.EQ.1) GO TO 812
      L=0
      DO 2100 II=2,NUMBER
      NU(II)=1
2100  Y(II)=Q(NB(1),NB(II))
3000  DMIN=Z
      DO 4100 II=2,NUMBER
      IF(Y(II).EQ.(-Z)) GO TO 4100
      IF(Y(II).GE.DMIN) GO TO 4100
      DMIN=Y(II)
      IMIN=II
4100  CONTINUE
      L=L+1
      NENDPT(1,L)=IMIN
      NENDPT(2,L)=NU(IMIN)
      IF(L.EQ.(NUMBER-1)) GO TO 870
      Y(IMIN)=-Z
      DO 1110 II=2,NUMBER
      IF(Y(II).EQ.(-Z)) GO TO 1110
      D1=Q(NB(II),NB(IMIN))
      IF(Y(II).LE.D1) GO TO 1110
      NU(II)=IMIN
      Y(II)=D1
1110  CONTINUE
      GO TO 3000
870   SUM=0.0
      SUMMAX=0.0
      DO 851 II=1,NUMBER-1
      J1=NENDPT(1,II)
      J2=NENDPT(2,II)
      SUM=SUM+Q(NB(J1),NB(J2))
      IF(Q(NB(J1),NB(J2)).GT.SUMMAX) SUMMAX=Q(NB(J1),NB(J2))
851   CONTINUE
      IF(NOPT.EQ.11) BSET(K1,K2) = SUMMAX
      IF(NOPT.EQ.11) BSET(K2,K1) = SUMMAX
      IF(NOPT.EQ.12) BSET(K1,K2) = SUM
      IF(NOPT.EQ.12) BSET(K2,K1) = SUM
812   CONTINUE
      GO TO 951
951   DO 604 I1=1,NC-1
      DO 604 I2=I1+1,NC
      SUM=0.0
      GO TO (605,605,605,610,817,605,605,605,605,817,605,605,
     &609,609,6006,6006,6006,6006,7000,7000) NOPT
6006  IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) NLOW=INT((NSTORE(I1,I2)+1)/2)
      IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) NUP=INT(NSTORE(I1,I2)/2) + 1
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) NLOW=1
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) NUP=NSTORE(I1,I2)
      AVER=(STORE(I1,I2,NLOW)+STORE(I1,I2,NUP))/2.0
      DO 6007 JJ=1,NSTORE(I1,I2)
      IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) SUM=SUM+
     &ABS(STORE(I1,I2,JJ)-AVER)
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) SUM=
     &MAX(SUM,ABS(STORE(I1,I2,JJ)-AVER))
6007  CONTINUE
      SMAX=0.0
      DO 6008 JJ=1,NC
      IF(NSTORE(JJ,JJ).EQ.0) GO TO 6008
      IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) NLOW=INT((NSTORE(JJ,JJ)+1)/2)
      IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) NUP=INT(NSTORE(JJ,JJ)/2) + 1
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) NLOW =1
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) NUP=NSTORE(JJ,JJ)
      WAVER=(STORE(JJ,JJ,NLOW)+STORE(JJ,JJ,NUP))/2.0
      IF(WAVER.GE.SMAX) SMAX=WAVER
6008  CONTINUE
      IF((NC.GE.2).AND.(SMAX.GT.AVER)) GO TO 604
      IF(NC.EQ.2) GO TO 607
      NTMP=0
      DO 6009 J1=1,NC-1
      DO 6009 J2=J1+1,NC
      IF(((J1.EQ.I1).AND.(J2.EQ.I2)).OR.((J1.EQ.I2).AND.(J2.EQ.I1)))
     & GO TO 6009
      DO 6010 JJ=1,NSTORE(J1,J2)
      NTMP=NTMP+1
      TMP(NTMP)=STORE(J1,J2,JJ)
6010  CONTINUE
6009  CONTINUE
      DO 6012 J1=1,NTMP-1
      DO 6013 J2=J1+1,NTMP
      IF(TMP(J1).LE.TMP(J2)) GO TO 6013
      TEMP=TMP(J1)
      TMP(J1)=TMP(J2)
      TMP(J2)=TEMP
6013  CONTINUE
6012  CONTINUE
      IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) NLOW = INT((NTMP+1)/2)
      IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) NUP=INT(NTMP/2) +1
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) NLOW=1
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) NUP=NTMP
      WAVER=(TMP(NLOW)+TMP(NUP))/2.0
      IF(WAVER.LT.AVER) GO TO 604
6011  IF((NOPT.EQ.16).OR.(NOPT.EQ.18)) GO TO 607
      SMIN=1.0E+20
      DO 6014 JJ=1,NC
      IF((JJ.EQ.I1).OR.(JJ.EQ.I2)) GO TO 6014
      NTMP=0
      IF(I1.GT.JJ) GO TO 6015
      DO 6016 KK1=1,NSTORE(I1,JJ)
      NTMP=NTMP+1
6016  TMP(NTMP)=STORE(I1,JJ,KK1)
6021  IF(I2.GT.JJ) GO TO 6017
      DO 6018 KK1=1,NSTORE(I2,JJ)
      NTMP=NTMP+1
6018  TMP(NTMP)=STORE(I2,JJ,KK1)
      GO TO 6019
6015  DO 6020 KK1=1,NSTORE(JJ,I1)
      NTMP=NTMP+1
6020  TMP(NTMP)=STORE(JJ,I1,KK1)
      GO TO 6021
6017  DO 6082 KK1=1,NSTORE(JJ,I2)
      NTMP=NTMP+1
6082  TMP(NTMP)=STORE(JJ,I2,KK1)
      GO TO 6019
6019  DO 6022 J1=1,NTMP-1
      DO 6023 J2=J1+1,NTMP
      IF(TMP(J1).LE.TMP(J2)) GO TO 6023
      TEMP=TMP(J1)
      TMP(J1)=TMP(J2)
      TMP(J2)=TEMP
6023  CONTINUE
6022  CONTINUE
      IF(NOPT.EQ.15) NLOW=INT((NTMP+1)/2)
      IF(NOPT.EQ.15) NUP=INT(NTMP/2) +1
      IF(NOPT.EQ.17) NLOW=1
      IF(NOPT.EQ.17) NUP=NTMP
      WAVER=(TMP(NLOW)+TMP(NUP))/2.0
      IF(WAVER.LT.SMIN) SMIN=WAVER
6014  CONTINUE
      IF(SMIN.LT.AVER) GO TO 604
      GO TO 607
817   BSUM=0.0
      NBSUM=0
      DO 819 JJ=1,NC
      IF((JJ.EQ.I1).OR.(JJ.EQ.I2)) GO TO 819
      BSUM=BSUM+BSET(I1,JJ)+BSET(I2,JJ)-BSET(I1,I1)-2.0*BSET(JJ,JJ)
     &-BSET(I2,I2)
      NBSUM=NBSUM+NBSET(I1,JJ)+NBSET(I2,JJ)-NBSET(I1,I1)-NBSET(I2,I2)
     &-2*NBSET(JJ,JJ)
819   CONTINUE
      IF((NBSUM.EQ.0).AND.(NOPT.EQ.5)) SUM=
     &BSET(I1,I2)/FLOAT(NBSET(I1,I2))
      IF((NBSUM.EQ.0).AND.(NOPT.EQ.5)) GO TO 850
      IF(NOPT.EQ.5) SUM=(BSET(I1,I2)/FLOAT(NBSET(I1,I2)))-
     &(BSUM/FLOAT(NBSUM))
      IF((NOPT.EQ.10).AND.(NBSUM.NE.0)) SUM=-BSUM/FLOAT(NBSUM)
      IF((NOPT.EQ.10).AND.(NBSUM.EQ.0)) SUM=0.0
850   GO TO 607
605   DO 440 JJ=1,NC
      SUMX(JJ)=BSET(JJ,JJ)
440   MSUM(JJ)=NBSET(JJ,JJ)
      IF(NOPT.NE.1) GO TO 860
      DO 814 JJ=1,NC
814   NB(JJ)=0
      DO 815 JJ=1,NCLAS
      DO 815 J1=1,NCSIZE(JJ)
      NB(NXI(I,JJ))=NB(NXI(I,JJ))+1
815   CONTINUE
      DO 816 JJ=1,NC
816   MSUM(JJ)=NB(JJ)
      NBSET(I1,I2)=(NB(I1)+NB(I2))
860   SUM=BSET(I1,I2)
      NSUM=NBSET(I1,I2)
      IF(((((NOPT.EQ.1).OR.(NOPT.EQ.2)).OR.(NOPT.EQ.7)).OR.(NOPT.EQ.9))
     &.AND.(NSUM.NE.0)) SUM = SUM/FLOAT(NSUM)
      IF(MOPT.EQ.1) GO TO 607
      SMAX=0.0
      DO 442 JJ=1,NC
      IF(((((NOPT.EQ.1).OR.(NOPT.EQ.2)).OR.(NOPT.EQ.7)).OR.(NOPT.EQ.9))
     &.AND.(MSUM(JJ).NE.0)) SUMX(JJ)=SUMX(JJ)/FLOAT(MSUM(JJ))
      IF(SUMX(JJ).GT.SMAX) SMAX=SUMX(JJ)
442   CONTINUE
      IF(SUM.LT.SMAX) GO TO 604
      GO TO 607
610   SUM=0.0
      DO 441 JJ=1,NC
441   SUMX(JJ)=0.0
      DO 608 J1=1,NCLAS
      DO 608 J2=J1,NCLAS
      DO 608 M1=1,NCSIZE(J1)
      DO 608 M2=1,NCSIZE(J2)
      IF(MEMBER(J1,M1).EQ.MEMBER(J2,M2)) GO TO 608
      IF(((NXI(I,J1).EQ.I1).OR.(NXI(I,J1).EQ.I2)).AND.
     &((NXI(I,J2).EQ.I1).OR.(NXI(I,J2).EQ.I2))) SUM=MAX(SUM,
     &Q(MEMBER(J1,M1),MEMBER(J2,M2)))
      IF(NXI(I,J1).EQ.NXI(I,J2)) SUMX(NXI(I,J1))=
     &MAX(SUMX(NXI(I,J1)),Q(MEMBER(J1,M1),MEMBER(J2,M2)))
608   CONTINUE
      SUM=MAX(SUM,SUMX(I1),SUMX(I2))
      IF(MOPT.EQ.1) GO TO 607
      SMAX=0.0
      DO 445 JJ=1,NC
      SMAX=MAX(SMAX,SUMX(JJ))
445   CONTINUE
      IF(SUM.LT.SMAX) GO TO 604
      GO TO 607
7000  SUMTR=0.0
      SUMQU=0.0
      DO 7001 J1=1,NCLAS
      DO 7001 J2=J1,NCLAS
      DO 7001 M1=1,NCSIZE(J1)
      DO 7001 M2=1,NCSIZE(J2)
c      write(2,9000) j1,j2,m1,m2,ncsize(j1),ncsize(j2),nclas,
c     &nxi(i,j1),nxi(i,j2),member(j1,m1),member(j2,m2)
      IF(MEMBER(J1,M1).EQ.MEMBER(J2,M2)) GO TO 7001
      IF(((NXI(I,J1).EQ.I1).AND.(NXI(I,J2).EQ.I2)).OR.
     &((NXI(I,J1).EQ.I2).AND.(NXI(I,J2).EQ.I1))) GO TO 7002
c      write(2,*) 'going to 7001'
      GO TO 7001
7002  DO 7003 J3=1,NCLAS
      DO 7003 J4=1,NCLAS
      DO 7003 M3=1,NCSIZE(J3)
      DO 7003 M4=1,NCSIZE(J4)
c      write(2,9000) j3,j4,m3,m4,ncsize(j3),ncsize(j4),nclas,
c     &nxi(i,j3),nxi(i,j4)
      IF(MEMBER(J3,M3).EQ.MEMBER(J4,M4)) GO TO 7003
      IF((NXI(I,J3).EQ.I1).OR.(NXI(I,J3).EQ.I2)) GO TO 7003
      IF((NXI(I,J4).EQ.I1).OR.(NXI(I,J4).EQ.I2)) GO TO 7004
c      write(2,9000) member(j1,m1),member(j2,m2),member(j3,m3),
c     &member(j4,m4)
      GO TO 7003
7004  IF(Q(MEMBER(J1,M1),MEMBER(J2,M2)).GT.
     &Q(MEMBER(J3,M3),MEMBER(J4,M4))) SUMQU=SUMQU+1.0  
      IF((Q(MEMBER(J1,M1),MEMBER(J2,M2)).GT.
     &Q(MEMBER(J3,M3),MEMBER(J4,M4))).AND.
     &((MEMBER(J1,M1).EQ.MEMBER(J4,M4)).OR.
     &(MEMBER(J2,M2).EQ.MEMBER(J4,M4)))) SUMTR=SUMTR+1.0  
c      write(2,9000) j1,j2,j3,j4
c      write(2,9001) q(member(j1,m1),member(j2,m2)),
c     &q(member(j3,m3),member(j4,m4))
c9000  format(12i4)
c9001  format(4f8.3)
7003  CONTINUE
7001  CONTINUE
      IF(NOPT.EQ.19) SUM=SUMTR
      IF(NOPT.EQ.20) SUM=SUMQU
c      write(2,9000) i,i1,i2,(nxi(i,j),j=1,nclas)
c      write(2,9001) sumtr, sumqu
      GO TO 607
609   SUM=0.0
      SUMSQ=0.0
      SUMA=0.0
      SUMB=0.0
      NSUMA=0
      NSUMB=0
      NSUM=0
      DO 430 JJ=1,NC
      MSUM(JJ)=0
430   SUMX(JJ)=0.0
      DO 611 J1=1,NCLAS
      DO 611 J2=J1,NCLAS
      DO 611 M1=1,NCSIZE(J1)
      DO 611 M2=1,NCSIZE(J2)
      IF(MEMBER(J1,M1).EQ.MEMBER(J2,M2)) GO TO 611
      IF(((NXI(I,J1).EQ.I1).AND.(NXI(I,J2).EQ.I2)).OR.  
     &((NXI(I,J1).EQ.I2).AND.(NXI(I,J2).EQ.I1))) SUM=SUM+
     &Q(MEMBER(J1,M1),MEMBER(J2,M2))
      IF(((NXI(I,J1).EQ.I1).AND.(NXI(I,J2).EQ.I2)).OR.
     &((NXI(I,J1).EQ.I2).AND.(NXI(I,J2).EQ.I1))) NSUM=NSUM+1
      IF(((NXI(I,J1).EQ.I1).AND.(NXI(I,J2).EQ.I2)).OR.
     &((NXI(I,J1).EQ.I2).AND.(NXI(I,J2).EQ.I1)))
     &SUMSQ=SUMSQ+Q(MEMBER(J1,M1),MEMBER(J2,M2))**2
      IF(((NXI(I,J1).EQ.I1).AND.(NXI(I,J2).EQ.I2)).OR.  
     &((NXI(I,J1).EQ.I2).AND.(NXI(I,J2).EQ.I1))) GO TO 611
      IF(NXI(I,J1).EQ.NXI(I,J2)) SUMA=SUMA+
     &Q(MEMBER(J1,M1),MEMBER(J2,M2))
      IF(NXI(I,J1).EQ.NXI(I,J2)) NSUMA=NSUMA+1
      IF(NXI(I,J1).NE.NXI(I,J2)) SUMB=SUMB+
     &Q(MEMBER(J1,M1),MEMBER(J2,M2))
      IF(NXI(I,J1).NE.NXI(I,J2)) NSUMB=NSUMB+1
      DO 431 JJ=1,NC
      IF((NXI(I,J1).EQ.NXI(I,J2)).AND.(NXI(I,J1).EQ.JJ))
     &SUMX(JJ)=SUMX(JJ)+Q(MEMBER(J1,M1),MEMBER(J2,M2))
      IF((NXI(I,J1).EQ.NXI(I,J2)).AND.(NXI(I,J1).EQ.JJ))
     &MSUM(JJ)=MSUM(JJ)+1
431   CONTINUE
611   CONTINUE
      DO 432 JJ=1,NC
432   IF(MSUM(JJ).NE.0) SUMX(JJ)=SUMX(JJ)/FLOAT(MSUM(JJ))
      SMAX=0.0
      DO 433 JJ=1,NC
433   IF(SUMX(JJ).GT.SMAX) SMAX=SUMX(JJ)
      IF(NSUMA.NE.0) SUMA=SUMA/FLOAT(NSUMA)
      IF(NSUMB.NE.0) SUMB=SUMB/FLOAT(NSUMB)
      TT=SUM/FLOAT(NSUM)
      IF((NC.GT.2).AND.((SUMA.GT.TT).OR.(SUMB.LT.TT))) GO TO 604
      IF((NC.EQ.2).AND.(SUMA.GT.TT)) GO TO 604
      IF((NC.GE.2).AND.(SMAX.GT.TT)) GO TO 604
      IF(NC.EQ.2) GO TO 956
      IF(NOPT.EQ.14) GO TO 956
      SMIN=1.0E+20
      DO 955 JJ=1,NC
      IF((JJ.EQ.I1).OR.(JJ.EQ.I2)) GO TO 955
      TMIN=BSET(I1,JJ)+BSET(I2,JJ)
     &-BSET(I1,I1)-BSET(I2,I2)-2.0*BSET(JJ,JJ)
      NTMIN=NBSET(I1,JJ)+NBSET(I2,JJ)
     &-NBSET(I1,I1)-NBSET(I2,I2)-2*NBSET(JJ,JJ)
      IF(NTMIN.NE.0) TMIN=TMIN/FLOAT(NTMIN)
      IF(TMIN.LE.SMIN) SMIN=TMIN
955   CONTINUE
      IF(SMIN.LT.TT) GO TO 604
956   SUM=SUMSQ-(((SUM)**2)/FLOAT(NSUM))
      GO TO 607
607   DO 612 JJ=1,NCLAS
      NTEMP(JJ)=NXI(I,JJ)
      IF(NXI(I,JJ).EQ.I2) NTEMP(JJ)=I1
612   IF(NXI(I,JJ).GT.I2) NTEMP(JJ)=NTEMP(JJ)-1
      INDEX=NA(NC-1)
614   IF(NCI(INDEX).NE.(NC-1)) GO TO 613
      IF(NXI(INDEX,1).NE.NTEMP(1)) GO TO 613
      IF(NXI(INDEX,2).NE.NTEMP(2)) GO TO 613
      IF(NXI(INDEX,3).NE.NTEMP(3)) GO TO 613
      IF(NCLAS.EQ.3) GO TO 615
      IF(NXI(INDEX,4).NE.NTEMP(4)) GO TO 613
      IF(NCLAS.EQ.4) GO TO 615
      IF(NXI(INDEX,5).NE.NTEMP(5)) GO TO 613
      IF(NCLAS.EQ.5) GO TO 615
      IF(NXI(INDEX,6).NE.NTEMP(6)) GO TO 613
      IF(NCLAS.EQ.6) GO TO 615
      IF(NXI(INDEX,7).NE.NTEMP(7)) GO TO 613
      IF(NCLAS.EQ.7) GO TO 615
      IF(NXI(INDEX,8).NE.NTEMP(8)) GO TO 613
      IF(NCLAS.EQ.8) GO TO 615
      IF(NXI(INDEX,9).NE.NTEMP(9)) GO TO 613
      IF(NCLAS.EQ.9) GO TO 615
      IF(NXI(INDEX,10).NE.NTEMP(10)) GO TO 613
      IF(NCLAS.EQ.10) GO TO 615
      IF(NXI(INDEX,11).NE.NTEMP(11)) GO TO 613
      IF(NCLAS.EQ.11) GO TO 615
      IF(NXI(INDEX,12).NE.NTEMP(12)) GO TO 613
      IF(NCLAS.EQ.12) GO TO 615
      IF(NXI(INDEX,13).NE.NTEMP(13)) GO TO 613
      IF(NCLAS.EQ.13) GO TO 615
      IF(NXI(INDEX,14).NE.NTEMP(14)) GO TO 613
      IF(NCLAS.EQ.14) GO TO 615
      IF(NXI(INDEX,15).NE.NTEMP(15)) GO TO 613
      IF(NCLAS.EQ.15) GO TO 615
      STOP
613   INDEX=INDEX+1
      GO TO 614
615   TEMP=XI(I)+SUM
      IF(TEMP.LT.XI(INDEX)) GO TO 9011
      GO TO 604
9011  XI(INDEX) = TEMP
      LAST(INDEX)=I
      IF((MGREED.GE.2).AND.(TEMP.LT.BOUND)) NBINDEX=INDEX
      IF((MGREED.GE.2).AND.(TEMP.LT.BOUND)) BOUND=TEMP
604   CONTINUE
      IF(MGREED.GE.2) I=NBINDEX
603   IF(MGREED.EQ.1) I=I+1
      IF(I.LT.KK) GO TO 824
C****************PRODUCE OUTPUT*********
      WRITE(2,552)
      WRITE(2,552)
      IF(MGREED.EQ.2) BOUND=XI(LAST(NBINDEX))
      IF(MGREED.EQ.2) WRITE(2,1077) BOUND
1077  FORMAT( 'BOUND USED',F18.6)
      IF(MGREED.EQ.2)
     &WRITE(2,*) 'GREEDY PARTITION HIERARCHY TO OBTAIN THE BOUND'
      IF(MGREED.EQ.3) WRITE(2,*) 'GREEDY PARTITION HIERARCHY'
      IF(MGREED.EQ.1) WRITE(2,*) 'OPTIMAL PARTITION HIERARCHY'
      WRITE(2,620) NCI(KK),XI(KK),(NXI(KK,J),J=1,NCLAS)
620   FORMAT('SUBSETS ',I3, '  INDEX', F14.4, ' MEMBERSHIP ',15I3)
      JJ=KK
      DO 621 I=1,NCLAS-1
      JJ=LAST(JJ)
      IF((NOPT.LT.13).or.(nopt.ge.19)) GO TO 621
      IF(NOPT.GT.14) GO TO 6090
      DO 960 I1=1,NCI(JJ)-1
      DO 960 I2=I1+1,NCI(JJ)
      SUM=0.0
      NSUM=0
      DO 961 J1=1,NCLAS
      DO 961 J2=J1,NCLAS
      DO 961 M1=1,NCSIZE(J1)
      DO 961 M2=1,NCSIZE(J2)
      IF(MEMBER(J1,M1).EQ.MEMBER(J2,M2)) GO TO 961
      IF(((NXI(JJ,J1).EQ.I1).AND.(NXI(JJ,J2).EQ.I2)).OR.  
     &((NXI(JJ,J1).EQ.I2).AND.(NXI(JJ,J2).EQ.I1))) SUM=SUM+
     &Q(MEMBER(J1,M1),MEMBER(J2,M2))
      IF(((NXI(JJ,J1).EQ.I1).AND.(NXI(JJ,J2).EQ.I2)).OR.  
     &((NXI(JJ,J1).EQ.I2).AND.(NXI(JJ,J2).EQ.I1))) NSUM=NSUM+1
961   CONTINUE
      SUM=SUM/FLOAT(NSUM)
      WRITE(2,962) I1,I2,SUM
962   FORMAT(2I5,F10.5)
960   CONTINUE
      GO TO 621
6090  DO 6051 I1=1,NCI(JJ)-1
      DO 6051 I2=I1+1,NCI(JJ)
      NTMP=0
      DO 6052 J1=1,NCLAS
      DO 6052 J2=J1,NCLAS
      DO 6052 M1=1,NCSIZE(J1)
      DO 6052 M2=1,NCSIZE(J2)
      IF(MEMBER(J1,M1).EQ.MEMBER(J2,M2)) GO TO 6052
      IF(((NXI(JJ,J1).EQ.I1).AND.(NXI(JJ,J2).EQ.I2)).OR.  
     &((NXI(JJ,J1).EQ.I2).AND.(NXI(JJ,J2).EQ.I1))) NTMP=NTMP+1
      IF(((NXI(JJ,J1).EQ.I1).AND.(NXI(JJ,J2).EQ.I2)).OR.  
     &((NXI(JJ,J1).EQ.I2).AND.(NXI(JJ,J2).EQ.I1)))
     &TMP(NTMP)=Q(MEMBER(J1,M1),MEMBER(J2,M2))
6052  CONTINUE
      DO 6053 J1=1,NTMP-1
      DO 6054 J2=J1+1,NTMP
      IF(TMP(J1).LE.TMP(J2)) GO TO 6054
      TEMP=TMP(J1)
      TMP(J1)=TMP(J2)
      TMP(J2)=TEMP
6054  CONTINUE
6053  CONTINUE
      IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) NLOW=INT((NTMP+1)/2)
      IF((NOPT.EQ.15).OR.(NOPT.EQ.16)) NUP=INT(NTMP/2) +1
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) NLOW=1
      IF((NOPT.EQ.17).OR.(NOPT.EQ.18)) NUP=NTMP
      WAVER=(TMP(NLOW)+TMP(NUP))/2.0
      WRITE(2,962) I1,I2,WAVER
6051  CONTINUE
621   WRITE(2,620) NCI(JJ),XI(JJ),(NXI(JJ,J),J=1,NCLAS)
      WRITE(2,552)
      IF((NOPT.NE.13).AND.(NOPT.NE.14)) GO TO 825
      SUM=0.0
      SUMSQ=0.0
      NCOUNT=0
      DO 740 J1=1,NCLAS
      DO 740 J2=J1,NCLAS
      DO 740 I1=1,NCSIZE(J1)
      DO 740 I2=1,NCSIZE(J2)
      IF(MEMBER(J1,I1).EQ.MEMBER(J2,I2)) GO TO 740
      NCOUNT=NCOUNT+1
      SUM=SUM+Q(MEMBER(J1,I1),MEMBER(J2,I2))
      SUMSQ=SUMSQ+Q(MEMBER(J1,I1),MEMBER(J2,I2))**2
740   CONTINUE
      SSD=SUMSQ-((SUM*SUM)/FLOAT(NCOUNT))
      WRITE(2,741) XI(KK),SSD
741   FORMAT('OPTIMAL INDEX',F10.4,' SUM SQUARES DEVIATION FROM MEAN
     &PROXIMITY',F10.4)
825   IF(MGREED.EQ.1) GO TO 1650
      MGREED=1
      DO 895 I=1,NN
      XI(I)=Z
895   LAST(I)=1
      XI(1)=0.0
      I=1
      IF(((((NOPT.EQ.5)).OR.(NOPT.EQ.10)).OR.(NOPT.EQ.13))
     &.OR.(NOPT.GE.14)) BOUND = 1.0E+19
      GO TO 824
1650  DO 1651 KK=2,NCLAS-1
      BOUND=Z
      NBOUND=1
      NLB=NA(KK)
      NUB=NA(KK-1)-1
      DO 1652 I = NLB,NUB
      IF(XI(I).GE.BOUND) GO TO 1652
      BOUND=XI(I)
      NBOUND=I
1652  CONTINUE
      WRITE(2,552)
      WRITE(2,1653) KK
1653  FORMAT('OPTIMAL PARTITION HIERARCHY STARTING WITH',I3,' SUBSETS')
      JJ=NBOUND
      DO 1654 I=1,NCLAS-KK+1
      WRITE(2,620) NCI(JJ),XI(JJ),(NXI(JJ,J),J=1,NCLAS)
      JJ=LAST(JJ)
1654  CONTINUE
1651  CONTINUE
      STOP
      END
