      SUBROUTINE HBOUND                                                 HBOU001
C-----------------------------------------------------------------------HBOU002
C                                                                       HBOU003
C  SUBROUTINE HBOUND  -  Compute bounds for each bond length/bond angle HBOU004
C                                                                       HBOU005
C----------------------------------------------------------------------+HBOU006
                                                                        HBOU007
      INCLUDE 'bplot.inc'                                               HBOU008
                                                                        HBOU009
      INTEGER       IMAIN, IPOS, NGAP                                   HBOU010
      REAL          FPOS, SEP, WIDTH                                    HBOU011
                                                                        HBOU012
C---- Loop through all the main chain bond lengths and angles           HBOU013
      DO 200, IMAIN = 1, NMAIN                                          HBOU014
                                                                        HBOU015
C----     Determine whether this is a bond length or bond angle and     HBOU016
C         use the appropriate histogram-bar width                       HBOU017
          IF (AL(IMAIN).EQ.'L') THEN                                    HBOU018
              FPOS = FPOSL                                              HBOU019
              NGAP = NGAPL                                              HBOU020
              SEP = LSEP                                                HBOU021
              WIDTH = LWIDTH                                            HBOU022
          ELSE                                                          HBOU023
              FPOS = FPOSA                                              HBOU024
              NGAP = NGAPA                                              HBOU025
              SEP = ASEP                                                HBOU026
              WIDTH = AWIDTH                                            HBOU027
          ENDIF                                                         HBOU028
                                                                        HBOU029
C----     Adjust minimum and maximum values so that range is a          HBOU030
C         sensible one and that starts and ends on an integral          HBOU031
C         number of bar-widths                                          HBOU032
          IPOS = MCHMIN(IMAIN) / FPOS                                   HBOU033
          MCHMIN(IMAIN) = IPOS * FPOS                                   HBOU034
          MCHMAX(IMAIN) = MCHMIN(IMAIN) + NGAP * SEP                    HBOU035
                                                                        HBOU036
C----     Calculate the number of bars and ticks this gives             HBOU037
          NBARS(IMAIN) = (MCHMAX(IMAIN) - MCHMIN(IMAIN)) / WIDTH + 0.1  HBOU038
          NTICKS(IMAIN) = (MCHMAX(IMAIN) - MCHMIN(IMAIN)) / SEP + 1.1   HBOU039
                                                                        HBOU040
C----     If this number exceeds the maximum allowed, then have not     HBOU041
C         allowed a big enough array in the program. Programmer's fault!HBOU042
          IF (NBARS(IMAIN).GT.MXBARS) THEN                              HBOU043
              PRINT*, '*** PROGRAM ERROR! Array parameter MXBARS is ',  HBOU044
     &            'too small:', MXBARS, NBARS(IMAIN), IMAIN             HBOU045
              PRINT*, '    Adjust in bplot.inc and recompile'           HBOU046
              IFAIL = .TRUE.                                            HBOU047
              RETURN                                                    HBOU048
          ENDIF                                                         HBOU049
 200  CONTINUE                                                          HBOU050
                                                                        HBOU051
      RETURN                                                            HBOU052
      END                                                               HBOU053
