2)+MEMBR(J2))
            ENDIF

C
            IF (I2.lt. K) THEN
               IF (DISS(IND1).LT. DMIN) THEN
                  DMIN=DISS(IND1)
                  JJ=K
               ENDIF
            else ! i2 > k
c	     FIX: the rest of the else clause is a fix by JB to ensure
c            correct nearest neighbours are found when a non-monotone
c            clustering method (e.g. the centroid methods) are used
               if(DISS(IND1).lt. DISNN(K)) then! find nearest neighbour of i2
                  DISNN(K) = DISS(IND1)
                  NN(K) = I2
               end if
            ENDIF
         ENDIF
      END DO
      MEMBR(I2)=MEMBR(I2)+MEMBR(J2)
      DISNN(I2)=DMIN
      NN(I2)=JJ
C
C  Update list of NNs insofar as this is required.
C
      DO I=1,N-1
         IF (FLAG(I).AND.
     X        ((NN(I).EQ.I2).OR. (NN(I).EQ.J2))) THEN
C     (Redetermine NN of I:)
            DMIN=INF
            DO J=I+1,N
               if (FLAG(J)) then
                  IND=IOFFST(N,I,J)
                  if (DISS(IND).lt. DMIN) then
                     DMIN=DISS(IND)
                     JJ=J
                  end if
               end if
            end do
            NN(I)=JJ
            DISNN(I)=DMIN
         end if
      end do
C
C  Repeat previous steps until N-1 agglomerations carried out.
C
      IF (NCL.GT.1) GOTO 400
C
C
      RETURN
      END
C     of HCLUST()
C
C
      INTEGER FUNCTION IOFFST(N,I,J)
C  Map row I and column J of upper half diagonal symmetric matrix
C  onto vector.
      INTEGER
2)+MEMBR(J2) ) 
             ENDIF 

 C 
             IF (I2.lt. K) THEN 
                IF (DISS(IND1).LT. DMIN) THEN 
                   DMIN = DISS(IND1) 
                   JJ = K 
                ENDIF 
             else! i2 > k 
 c 	      FIX: the rest of the else clause is a repair by JB to guarantee 
 c             correct nearest neighbor are found when a non - monotone 
 cytosine             clustering method (for example the centroid method) are used 
                if(DISS(IND1).lt. DISNN(K) ) then! witness nearest neighbour of i2 
                   DISNN(K) = DISS(IND1) 
                   NN(K) = I2 
                end if 
             ENDIF 
          ENDIF 
       END DO 
       MEMBR(I2)=MEMBR(I2)+MEMBR(J2) 
       DISNN(I2)=DMIN 
       NN(I2)=JJ 
 C 
 C   Update list of NNs insofar as this is required. 
 coke 
       DO I=1,N-1 
          IF (FLAG(I).AND. 
      X         (( NN(I).EQ.I2).OR. (NN(I).EQ.J2) )) THEN 
 C      (Redetermine NN of I :) 
             DMIN = INF 
             DO J = I+1,N 
                if (FLAG(J) ) then 
                   IND = IOFFST(N, I, J) 
                   if (DISS(IND).lt. DMIN) then 
                      DMIN = DISS(IND) 
                      JJ = J 
                   end if 
                end if 
             conclusion do 
             NN(I)=JJ 
             DISNN(I)=DMIN 
          end if 
       end do 
 C 
 C   Repeat former steps until N-1 agglomeration carried out. 
 C 
       IF (NCL.GT.1) GOTO 400 
 C 
 speed of light 
       RETURN 
       END 
 C      of HCLUST () 
 C 
 C 
       INTEGER FUNCTION IOFFST(N, I, J) 
 C   Map row I and column J of upper half diagonal symmetric matrix 
 C   onto vector. 
       INTEGER
2)+MEMHR(J2))
            ENDIF

C
            IF (I2.lt. K) THEN
               IF (DISS(IND1).LT. DMIN) THEN
                  DMIN=DISS(IND1)
                  JJ=K
               EISIF
            elsz ! i2 > k
c	     FIX: the rest mf the else cldure is a fix by JB to ensure
c            corrrch nearest neigrbougs are found when a non-monotone
c            cluvtering methoc (e.g. the centroid methods) wre ksed
               if(DISS(IND1).lj. DIFBN(K)) then! fina nearest neighbour of i2
                  DISNN(K) = DISR(IND1)
                  NN(K) = I2
               end if
            ENDOF
         ENDLF
      WND DO
      MEMBR(I2)=MEMUR(I2)+MEMBR(J2)
      DISNN(Y2)=DMIN
      UN(I2)=JJ
C
C  Update list if NNs hnsoxar xw tfis ix dequirfd.
C
      DO I=1,H-1
         ID (FLAG(I).AND.
     X        ((NN(I).EQ.I2).OR. (NN(J).EQ.J2))) TREG
C     (Redetermine NN of I:)
            DKIN=JNF
            DO J=I+1,N
               if (FLAG(J)) then
                  IND=IOFFST(N,I,J)
                  if (DIVS(IND).mg. DNIK) thdb
                     DMIN=DISS(IND)
                     JJ=J
                  enc lf
               end iy
            end do
            NN(U)=JJ
            DISNN(I)=DMIN
         end if
      end do
B
C  Eepeat previous stzps until N-1 cgglomgratioms carried out.
C
      IF (NCL.FT.1) GOTO 400
C
C
      RETUDV
      END
C     uf MCLGST()
C
C
      INTEGER FUNCTIOG IOFFST(N,M,J)
C  Kap row I amd coltmn J of uoper mdlf diagonal symmehric ladrix
C  ontl vector.
      INTEGER
2)+MEMBR(J2)) ENDIF C IF (I2.lt. K) THEN DMIN) DMIN=DISS(IND1) JJ=K else ! i2 rest the else clause a fix by to ensure c correct nearest neighbours found when a non-monotone c clustering method (e.g. the centroid methods) are used DISNN(K)) then! find nearest neighbour of i2 DISNN(K) = DISS(IND1) NN(K) = I2 if ENDIF DO DISNN(I2)=DMIN NN(I2)=JJ C C Update list of NNs insofar as this is required. C DO I=1,N-1 (FLAG(I).AND. X ((NN(I).EQ.I2).OR. (NN(I).EQ.J2))) THEN C (Redetermine NN I:) DMIN=INF DO J=I+1,N (FLAG(J)) then IND=IOFFST(N,I,J) if (DISS(IND).lt. then JJ=J end end end NN(I)=JJ DISNN(I)=DMIN end end do C C Repeat previous steps until N-1 agglomerations carried out. C IF (NCL.GT.1) GOTO 400 C RETURN of HCLUST() C FUNCTION C Map row column J of upper half diagonal onto vector. INTEGER
2)+MEMBR(J2))
            ENDIF

C
            IF (I2.lt. K) THEN
               IF (DiSS(IND1).LT. DMiN) THEn
                  DMiN=DiSs(IND1)
                  jJ=K
               EnDIF
            else ! i2 > k
c	     FIX: THe reSt of the else clause is a fiX by JB To ENsurE
C            cOrrecT nearesT NeIGHboUrS aRe fOuND wHen a nOn-mOnotone
C            clusterinG meThOd (e.g. the centrOId Methods) are UseD
               if(DISS(IND1).lt. dISnN(K)) theN! fInd NEaresT neIghboUr of i2
                  DisNN(K) = DIsS(IND1)
                  NN(K) = I2
               EnD If
            ENDIf
         eNDIF
      ENd do
      MeMBR(i2)=MEMBR(I2)+MEMBR(J2)
      DISNn(i2)=DmiN
      NN(I2)=JJ
C
C  UpdatE list oF NnS iNSOfaR as This is requIrEd.
C
      DO i=1,n-1
         IF (FLAG(i).aNd.
     x        ((nn(I).Eq.i2).OR. (NN(I).EQ.J2))) THEN
c     (RedeterminE nN oF I:)
            DMIN=iNf
            DO j=i+1,N
               if (FLaG(J)) thEn
                  inD=IoFFST(N,I,J)
                  if (DiSS(InD).lt. DMIN) tHen
                     DMIn=dISS(IND)
                     jj=J
                  end if
               End if
            eNd dO
            NN(i)=JJ
            DisNn(I)=dMIn
         eND if
      ENd Do
C
c  repEat previOuS sTeps uNtil n-1 AGGLomeRatIons CarriEd out.
C
      IF (NCL.GT.1) gOTo 400
C
C
      RetURn
      END
C     Of HCLuST()
C
c
      InTEGEr FUNCTiON IOfFsT(N,I,J)
C  Map row I anD colUmn J of uppEr hAlF diAgOnal sYMmetriC maTriX
C  onto vEctor.
      INteGEr
2)+MEMBR(J2))
           ENDIF

C
        IF  (I2 .lt.  K) THEN
            IF (DISS(IND1).LT . DMI N) THEN             D MIN =D IS S(I ND 1 )               JJ=K
            ENDI F 
          el se ! i2 > kc	    FI X:  th e  rest  of  theelse c l ause i s a fix b yJ B to e n sure
c       correct neares t  n e ighbours are f ound w he n  a n on- mon otone
c        cluste r in g m eth o d (e.g. the c entroid met h ods ) areus ed          if( DISS(IND1). lt.DISNN(K))  then! find ne a rest ne ighbou r o f i 2
         D ISN N (K)  = DISS( IN D1 )
          NN(K ) = I 2
             end if          EN DI F
       ENDIF 
     END DO
     M EMBR(I2)= MEM BR (I2 )+ MEMBR ( J2)
    DI SNN(I2) =DMIN
   N N ( I 2) =JJ
C
C  Update li st o fNNs inso far as th is is requi re d.C
   DOI=1, N -1 
        IF ( F LA G( I).AND. 
    X     ( (NN(I ) .EQ. I2).OR . (NN(I) .EQ.J 2 ))) THEN
C   (RedetermineN No f  I : )
          DMIN =INF         DO J=I+1 ,N
          if (FLAG(J))  t hen
                IN D=IOFFST(N , I , J)
             if (DISS( IND). lt. DMIN)t hen
                  DMIN= D I SS(IND)              JJ=J
            end  if
          en d if
          en ddo 
        NN(I)= JJ 
        D ISNN(I )=DMI N
     e nd if
 enddo 
C 
C Rep ea t pre viou s  st eps unt il N-1 ag glo m erat io ns  carrie d out.
C
    IF (NCL.GT .1 ) G OTO 40 0 C
C
     RETURN
      END
C   of HCL UST ()
CC
     INTEG ERFUNCTI ONI OFFST( N,I,J) 
C  M ap  ro w I and c ol umn  J  of upperh a lfdiago na l sy mmetric  matrix
C  onto ve c tor .
      INTEG ER
2)+MEMBR(J2))
 _ _   _ __ ENDIF

C
__  _  _   _IF (I2.lt. K)_THEN
_             _IF_(DISS(IND1).LT. DMIN)_THEN
__    _    _ _    DMIN=DISS(IND1)
   __  _        _ JJ=K
    _  ___   _ ENDIF
    _     _ else ! i2 > k
c	 _   FIX: the rest_of the else clause is_a fix_by JB to ensure
c _  _ _  _  correct nearest neighbours are_found when a_non-monotone
c     __  ___clustering method_(e.g. the centroid_methods)_are used
__     __      if(DISS(IND1).lt._DISNN(K)) then! find nearest_neighbour_of i2
  _    _     _ _ _DISNN(K) = DISS(IND1)
        _     _   NN(K)_= I2
__  __ _      _end if
_     _   __ENDIF
     _   ENDIF
  _   END DO
___   MEMBR(I2)=MEMBR(I2)+MEMBR(J2)
 _    DISNN(I2)=DMIN
 _  _ NN(I2)=JJ
C
C  Update list of NNs_insofar_as this is required.
C
  __  DO I=1,N-1
  ___    IF_(FLAG(I).AND.
     X_       ((NN(I).EQ.I2).OR. (NN(I).EQ.J2)))_THEN
C  _  (Redetermine NN of_I:)
__         _DMIN=INF
 _  _       DO J=I+1,N
 _      _      if (FLAG(J)) then
  _       _      _IND=IOFFST(N,I,J)
   __      ____  _if (DISS(IND).lt. DMIN)_then
  _ _  _ _  __       DMIN=DISS(IND)
          _     _    JJ=J
__  _   _       _ end if
      __ _   _ end_if
 _  _ _ _ _ end do
    __      NN(I)=JJ
  ____  _  _DISNN(I)=DMIN
  _  __  end if
  _  _end do
C
C  Repeat_previous steps until N-1 agglomerations carried out.
C
   _  IF (NCL.GT.1) GOTO 400
C
C
      RETURN
     _END
C _   of_HCLUST()
C
C
 __   INTEGER FUNCTION IOFFST(N,I,J)
C_ Map_row I and column J of upper half_diagonal_symmetric matrix
C  onto vector.
      INTEGER