      subroutine histog(icomp,histo,ihisto,nhisto,ipr,ibhist,           HIST001
     &                  title,avern,iwater)                             HIST002
c ----------------------------------------------------------------------HIST003
c     This program module is part of the author's X-ray Library         HIST004
c     and may not be sold or reproduced for commercial purposes.        HIST005
c     Although it has been tested carefully, there is no warranty       HIST006
c     regarding accuracy or freedom from side-effects.                  HIST007
c                   (C) 1986-1994 Bernhard Rupp                         HIST008
c ----------------------------------------------------------------------HIST009
c     HISTOG prints a simple histogram to screen and dumps more detailedHIST010
c       radial distribution function (0.02 A boxes) into DHISTORGR.DAT  HIST011
c ----------------------------------------------------------------------HIST012
      parameter(iline=19)                                               HIST013
                                                                        HIST014
      character an,lv,icomp*4,title*60, avern*3                         HIST015
      dimension histo(nhisto),ihisto(nhisto),ibhist(50:500)             HIST016
                                                                        HIST017
      if (icomp.eq.'IBM ') then                                         HIST018
         lv=char(179)                                                   HIST019
         an=char(143)                                                   HIST020
      else                                                              HIST021
         lv='|'                                                         HIST022
         an='A'                                                         HIST023
      end if                                                            HIST024
                                                                        HIST025
c --- scale the print data to 100 --                                    HIST026
      do 0009 i=50,500                                                  HIST027
         radius=i*0.02                                                  HIST028
         rdis=ibhist(i)/(radius**3)                                     HIST029
         if (rdis.gt.bighis) bighis=rdis                                HIST030
 0009 continue                                                          HIST031
      scale=100/bighis                                                  HIST032
                                                                        HIST033
c --- print the raw histogram data for further processing --            HIST034
      open(20,file='DHISTOGR.DAT',status='unknown')                     HIST035
      write(20,'(a,1x,a)')                                              HIST036
     &   ' Radial distribution function data generated by SEXIE',avern  HIST037
      write(20,'(a,a)') ' for ',title                                   HIST038
      do 0010 i=50,500                                                  HIST039
         radius=i*0.02                                                  HIST040
         rdis=ibhist(i)/(radius**3)                                     HIST041
         write(20,'(1x,f6.3,1x,i8,1x,f10.6,1x,f6.2)') radius,ibhist(i), HIST042
     &              rdis, rdis*scale                                    HIST043
 0010 continue                                                          HIST044
      close(20)                                                         HIST045
                                                                        HIST046
c --- prepare the distribution function --                              HIST047
      bighis=0.0                                                        HIST048
      do 0001 i=1,nhisto                                                HIST049
c ---    first element 1.1 A --                                         HIST050
         radius=1.0+(i/10.0)                                            HIST051
c ---    divide by raduis cubed --                                      HIST052
         histo(i)=histo(i)/(radius**3)                                  HIST053
c ---    find max raduis for scaling --                                 HIST054
         if(histo(i).gt.bighis) bighis=histo(i)                         HIST055
 0001 continue                                                          HIST056
                                                                        HIST057
c --- scale data --                                                     HIST058
      scale=iline/bighis                                                HIST059
      do 0002 i=1,nhisto                                                HIST060
         ihisto(i)=int(histo(i)*scale)                                  HIST061
 0002 continue                                                          HIST062
                                                                        HIST063
c --- print the histogram                                               HIST064
      do 0003 ip=ipr,ipr+1+iwater                                       HIST065
         write(ip,*) ' '                                                HIST066
         call frames(ip,1,icomp)                                        HIST067
         do 0004 i=iline,1,-1                                           HIST068
            write(ip,'(1x,a1$)') lv                                     HIST069
            do 0005 j=1,77                                              HIST070
               if(ihisto(j).ge.i) then                                  HIST071
                 write(ip,'(a1$)')'*'                                   HIST072
               else                                                     HIST073
                 write(ip,'(a1$)')' '                                   HIST074
               endif                                                    HIST075
 0005       continue                                                    HIST076
            write(ip,'(a1)') lv                                         HIST077
 0004    continue                                                       HIST078
         write(ip,'(1x,a1,7(8x,i1,1x),7x,a1)') lv,2,3,4,5,6,7,8,lv      HIST079
         write(ip,'(1x,a1,8x,a,8x,a1)') lv,                             HIST080
     &'Radial distance distribution calculated for all central atoms',lvHIST081
         call frames(ip,3,icomp)                                        HIST082
 0003 continue                                                          HIST083
      return                                                            HIST084
      end                                                               HIST085
