      subroutine adhist(itot,did,iclust,idim,histo,nhisto,ibhist,       ADHI001
     &           bad,ibadct,ibad,iwater,bump)                           ADHI002
c ----------------------------------------------------------------------ADHI003
c     This program module is part of the PhysiSoft X-ray Library        ADHI004
c     and may not be sold or reproduced for commercial purposes.        ADHI005
c     Although it has been tested carefully, there is no warranty       ADHI006
c     regarding accuracy or freedom from side-effects.                  ADHI007
c                        (C) 1994 Bernhard Rupp                         ADHI008
c ----------------------------------------------------------------------ADHI009
c     ADHIST adds into histogram memory for radial distribution functionADHI010
c            and flags bad contacts                                     ADHI011
c ----------------------------------------------------------------------ADHI012
                                                                        ADHI013
      dimension did(iclust,idim),histo(nhisto),ibhist(50:500)           ADHI014
      dimension bad(ibadct,3)                                           ADHI015
                                                                        ADHI016
c --- add into the histogram --                                         ADHI017
         do 0001 ihis=1,itot                                            ADHI018
            if (ihis.gt.1) then                                         ADHI019
               if ((iwater.eq.1).and.(did(ihis,4).lt.bump)) then        ADHI020
                  print*,' ALERT : bad contact found at : ',did(ihis,4) ADHI021
                  inew=1                                                ADHI022
                  do 0002 i=1,ibad                                      ADHI023
        if((bad(i,2).eq.did(1,5)).and.(bad(i,1).eq.did(ihis,5))) inew=0 ADHI024
 0002             continue                                              ADHI025
                  if ((ibad.lt.ibadct).and.(inew.eq.1)) then            ADHI026
                     ibad=ibad+1                                        ADHI027
                     bad(ibad,1)=did(1,5)                               ADHI028
                     bad(ibad,2)=did(ihis,5)                            ADHI029
                     bad(ibad,3)=did(ihis,4)                            ADHI030
                  end if                                                ADHI031
               elseif (did(ihis,4).lt.1.5) then                         ADHI032
                  print*,' ALERT : suspicious contact at : ',did(ihis,4)ADHI033
               end if                                                   ADHI034
            end if                                                      ADHI035
            if((did(ihis,4).ge.1.1).and.(did(ihis,4).le.8.9)) then      ADHI036
              ihit=int(did(ihis,4)*10)-11                               ADHI037
              histo(ihit)=histo(ihit)+1                                 ADHI038
            end if                                                      ADHI039
            if((did(ihis,4).ge.1.0).and.(did(ihis,4).le.10.0)) then     ADHI040
              ihit=int(did(ihis,4)*100/2)                               ADHI041
              ibhist(ihit)=ibhist(ihit)+1                               ADHI042
            end if                                                      ADHI043
 0001    continue                                                       ADHI044
      return                                                            ADHI045
      end                                                               ADHI046
