      SUBROUTINE BARPLT(BTYPE)                                          BARP001
C-----------------------------------------------------------------------BARP002
C                                                                       BARP003
C  SUBROUTINE BARPLT  -  Plot this set of graphs                        BARP004
C                                                                       BARP005
C----------------------------------------------------------------------+BARP006
                                                                        BARP007
      INCLUDE 'bplot.inc'                                               BARP008
                                                                        BARP009
      INTEGER      NBOUND                                               BARP010
      PARAMETER   (NBOUND = 18)                                         BARP011
                                                                        BARP012
      CHARACTER*1  BTYPE                                                BARP013
CHECK v.3.2-->                                                          BARP014
      CHARACTER*5   CNUMB                                               BARP015
      CHARACTER*9   PLHAND                                              BARP016
CHECK v.3.2<--                                                          BARP017
CHECK v.3.1-->                                                          BARP018
      CHARACTER*30  PLDESC                                              BARP019
CHECK v.3.1<--                                                          BARP020
CHECK v.3.2-->                                                          BARP021
      CHARACTER*60  PTITLE                                              BARP022
      CHARACTER*79  BLNKLN, SUMLIN                                      BARP023
CHECK v.3.2<--                                                          BARP024
      INTEGER      IACROS, IBOUND, IDOWN, IMAIN, MFREQ, IPAGE, NDECPT,  BARP025
CHECK v.3.2-->                                                          BARP026
C     -             NTICKX, NTICKY, TBOUND(NBOUND), TICKY(NBOUND)       BARP027
     &             NHIGHL, NOFFGR, NTICKX, NTICKY, NTOTAL, NWITHN,      BARP028
     &             TBOUND(NBOUND), TICKY(NBOUND)                        BARP029
CHECK v.3.2<--                                                          BARP030
CHECK v.3.2-->                                                          BARP031
C      LOGICAL      DONE, NOEND, NUMBEX, NUMBEY, ZEROS                  BARP032
C      REAL         SCALEX,WIDTH,  XL, XMAX, XR, XSTART,                BARP033
C     -             YB, YMIN, YT, YTOP                                  BARP034
      LOGICAL      DONE, FIRST, LAST, NOEND, NUMBEX, NUMBEY, ZEROS      BARP035
      REAL         PERCEN, SCALEX, WIDTH,  XL, XMAX, XR, XSTART, YB,    BARP036
     &             YMIN, YT, YTOP                                       BARP037
CHECK v.3.2<--                                                          BARP038
                                                                        BARP039
CHECK v.3.2-->                                                          BARP040
      DATA BLNKLN( 1:40) / ' |                                      ' / BARP041
      DATA BLNKLN(41:79) / '                                      |'  / BARP042
CHECK v.3.2<--                                                          BARP043
      DATA TBOUND / 3, 5, 8, 10, 12, 15, 20, 25, 30, 40, 50, 60, 70,    BARP044
     &             80, 90, 100, 150, 200 /                              BARP045
      DATA TICKY  / 4, 6, 5,  6,  7,  6,  5,  6,  7,  5,  6,  7,  8,    BARP046
     &              5,  4,   6,   6,   5 /                              BARP047
                                                                        BARP048
C---- Initialise variables according to the type of plot                BARP049
      IF (BTYPE.EQ.'L') THEN                                            BARP050
          HEADIN = 'Main-chain bond lengths'                            BARP051
          HLEN = 23                                                     BARP052
          NDECPT = 2                                                    BARP053
          PLTYPE = 1                                                    BARP054
          WIDTH = LWIDTH                                                BARP055
CHECK v.3.1-->                                                          BARP056
          PLDESC = HEADIN                                               BARP057
CHECK v.3.1<--                                                          BARP058
CHECK v.3.2-->                                                          BARP059
          PLHAND = 'bondlenth'                                          BARP060
          PTITLE = PLDESC                                               BARP061
CHECK v.3.2<--                                                          BARP062
      ELSE IF (BTYPE.EQ.'A') THEN                                       BARP063
          HEADIN = 'Main-chain bond angles'                             BARP064
          HLEN = 22                                                     BARP065
          NDECPT = 0                                                    BARP066
          PLTYPE = 2                                                    BARP067
          WIDTH = AWIDTH                                                BARP068
CHECK v.3.1-->                                                          BARP069
          PLDESC = HEADIN                                               BARP070
CHECK v.3.1<--                                                          BARP071
CHECK v.3.2-->                                                          BARP072
          PLHAND = 'bondangle'                                          BARP073
          PTITLE = PLDESC                                               BARP074
CHECK v.3.2<--                                                          BARP075
      ELSE                                                              BARP076
          HEADIN = 'RMS distances from planarity'                       BARP077
          HLEN = 28                                                     BARP078
          NDECPT = 2                                                    BARP079
          PLTYPE = 3                                                    BARP080
          WIDTH = PWIDTH                                                BARP081
CHECK v.3.1-->                                                          BARP082
          PLDESC = HEADIN                                               BARP083
CHECK v.3.1<--                                                          BARP084
CHECK v.3.2-->                                                          BARP085
          PLHAND = 'planargps'                                          BARP086
          PTITLE = PLDESC                                               BARP087
CHECK v.3.2<--                                                          BARP088
      ENDIF                                                             BARP089
                                                                        BARP090
C---- Calculate maximum frequency                                       BARP091
      MFREQ = 0                                                         BARP092
      DO 100, IMAIN = 1, NALP                                           BARP093
          IF (AL(IMAIN).EQ.BTYPE) THEN                                  BARP094
              MAXFRQ(IMAIN) = MAXFRQ(IMAIN) + 1                         BARP095
              MFREQ = MAX(MAXFRQ(IMAIN),MFREQ)                          BARP096
          ENDIF                                                         BARP097
 100  CONTINUE                                                          BARP098
                                                                        BARP099
C---- Initialise variables                                              BARP100
      IACROS = NACROS                                                   BARP101
      IDOWN = NDOWN                                                     BARP102
      IPAGE = 0                                                         BARP103
      NFGAPY = 5                                                        BARP104
      NUMBEX = .TRUE.                                                   BARP105
      NUMBEY = .TRUE.                                                   BARP106
      XSTART = BBOXX1 + XFQLMG                                          BARP107
      YTOP = BBOXY2 - YFQTMG                                            BARP108
                                                                        BARP109
CHECK v.3.2-->                                                          BARP110
C---- Initialise counts of points in the different parts of the graph   BARP111
      NHIGHL = 0                                                        BARP112
      NOFFGR = 0                                                        BARP113
      NWITHN = 0                                                        BARP114
      FIRST = .TRUE.                                                    BARP115
      LAST = .FALSE.                                                    BARP116
CHECK v.3.2<--                                                          BARP117
                                                                        BARP118
C---- Calculate maximum y-value and number of ticks                     BARP119
      NTICKY = 2                                                        BARP120
      IBOUND = 0                                                        BARP121
      DONE = .FALSE.                                                    BARP122
 200  CONTINUE                                                          BARP123
          IBOUND = IBOUND + 1                                           BARP124
          IF (MFREQ.LE.TBOUND(IBOUND)) THEN                             BARP125
              MFREQ = TBOUND(IBOUND)                                    BARP126
              NTICKY = TICKY(IBOUND)                                    BARP127
              DONE = .TRUE.                                             BARP128
          ENDIF                                                         BARP129
      IF (.NOT.DONE .AND. IBOUND.LT.NBOUND) GO TO 200                   BARP130
                                                                        BARP131
C---- Loop through the graphs                                           BARP132
      DO 1000, IMAIN = 1, NALP                                          BARP133
                                                                        BARP134
C----     Check that this is the right graph type                       BARP135
          IF (AL(IMAIN).EQ.BTYPE) THEN                                  BARP136
                                                                        BARP137
C----         Calculate x-axis scale                                    BARP138
              SCALEX = XFQWID / (NBARS(IMAIN) * WIDTH)                  BARP139
              NTICKX = NTICKS(IMAIN)                                    BARP140
                                                                        BARP141
C----         Increment graph-count                                     BARP142
              IACROS = IACROS + 1                                       BARP143
              IF (IACROS.GT.NACROS) THEN                                BARP144
                  IDOWN = IDOWN + 1                                     BARP145
                                                                        BARP146
C----             If off the end of the page, start a new one           BARP147
                  IF (IDOWN.GT.NDOWN) THEN                              BARP148
                                                                        BARP149
C----                 If this is not the first page, then finish off    BARP150
C                     previous page                                     BARP151
                      IF (IPAGE.GT.0) THEN                              BARP152
CHECK v.3.2-->                                                          BARP153
C                          CALL BAREND(BTYPE)                           BARP154
                          CALL BAREND(BTYPE,LAST)                       BARP155
CHECK v.3.2<--                                                          BARP156
                      ENDIF                                             BARP157
                                                                        BARP158
C----                 Open new PostScript file and print headings       BARP159
CHECK v.3.1-->                                                          BARP160
C                      CALL BARHED(IPAGE)                               BARP161
CHECK v.3.2-->                                                          BARP162
C                      CALL BARHED(IPAGE,PLDESC)                        BARP163
                      CALL BARHED(IPAGE,PLDESC,PLHAND,PTITLE,FIRST)     BARP164
                      FIRST = .FALSE.                                   BARP165
CHECK v.3.2<--                                                          BARP166
                      PLDESC = ' '                                      BARP167
CHECK v.3.1<--                                                          BARP168
                      IDOWN = 1                                         BARP169
                      XMAX = XSTART                                     BARP170
                      YMIN = YTOP                                       BARP171
                  ENDIF                                                 BARP172
                  IACROS = 1                                            BARP173
              ENDIF                                                     BARP174
                                                                        BARP175
C----         Calculate graph position and draw axes                    BARP176
              XL = XSTART + (IACROS - 1) * (XFQWID + XDAYLT)            BARP177
              XR = XL + XFQWID                                          BARP178
              YT = YTOP - (IDOWN - 1) * YFQWID                          BARP179
              YB = YT - YFQWID + YDAYLT                                 BARP180
              XMAX = MAX(XR,XMAX)                                       BARP181
              YMIN = MIN(YB,YMIN)                                       BARP182
                                                                        BARP183
C----         Draw in the shading                                       BARP184
              CALL PSLWID(0.1)                                          BARP185
              IF (BSHADE(PLTYPE)) THEN                                  BARP186
                  CALL PSHADE(0.98,COLPLT(PLTYPE,2),RGB,MXCOLR,         BARP187
     &                INCOLR(PLTYPE))                                   BARP188
                  CALL PSBBOX(XL,YB,XL,YT,XR,YT,XR,YB)                  BARP189
              ENDIF                                                     BARP190
                                                                        BARP191
C----         Plot the axes                                             BARP192
              CALL AXES(XL,XR,YB,YT,NTICKX - 1,NTICKY - 1,              BARP193
     &            MCHMIN(IMAIN),MCHMAX(IMAIN),0.0,REAL(MFREQ),          BARP194
     &            8.0,NDECPT,0,12.0,NUMBEX,NUMBEY,ZEROS,NOEND,.TRUE.)   BARP195
                                                                        BARP196
C----         Plot the Engh & Huber mean and standard deviations        BARP197
              CALL BARLIN(XL,XR,YB,YT,IMAIN,SCALEX)                     BARP198
                                                                        BARP199
C----         Plot the graph title                                      BARP200
              CALL BARTXT(XL,XR,YB,YT,IMAIN)                            BARP201
                                                                        BARP202
C----         Plot the bar graph                                        BARP203
CHECK v.3.2-->                                                          BARP204
C              CALL BARDRW(XL,YB,YT,SCALEX,IMAIN,WIDTH,MFREQ)           BARP205
              CALL BARDRW(XL,YB,YT,SCALEX,IMAIN,WIDTH,MFREQ,NHIGHL,     BARP206
     &            NWITHN)                                               BARP207
CHECK v.3.2<--                                                          BARP208
                                                                        BARP209
C----         Plot marker indicating there are data points off the      BARP210
C             graph                                                     BARP211
              CALL BAROFF(XL,XR,YB,YT,IMAIN)                            BARP212
                                                                        BARP213
CHECK v.3.2-->                                                          BARP214
C----         Increment counts of points off the graphs                 BARP215
              NOFFGR = NOFFGR + BCOUNT(MXBARS+1,IMAIN)                  BARP216
     &            + BCOUNT(MXBARS+2,IMAIN)                              BARP217
CHECK v.3.2<--                                                          BARP218
          ENDIF                                                         BARP219
 1000 CONTINUE                                                          BARP220
                                                                        BARP221
C---- Finish off the last page                                          BARP222
CHECK v.3.2-->                                                          BARP223
C      IF (IPAGE.GT.0) CALL BAREND(BTYPE)                               BARP224
      LAST = .TRUE.                                                     BARP225
      IF (IPAGE.GT.0) CALL BAREND(BTYPE,LAST)                           BARP226
CHECK v.3.2<--                                                          BARP227
                                                                        BARP228
CHECK v.3.2-->                                                          BARP229
C---- Write the percentages of data points in good, bad, and terrible   BARP230
C     regions out                                                       BARP231
                                                                        BARP232
C---- Blank out the output line                                         BARP233
      SUMLIN = BLNKLN                                                   BARP234
                                                                        BARP235
C---- Prepare summary line's title according to type of distribution jusBARP236
C     produced                                                          BARP237
      IF (BTYPE.EQ.'L') THEN                                            BARP238
          SUMLIN(4:20) = 'M/c bond lengths:'                            BARP239
      ELSE IF (BTYPE.EQ.'A') THEN                                       BARP240
          SUMLIN(4:20) = 'M/c bond angles: '                            BARP241
      ELSE                                                              BARP242
          SUMLIN(4:20) = 'Planar groups:   '                            BARP243
      ENDIF                                                             BARP244
                                                                        BARP245
C---- Insert text for remainder of the line                             BARP246
      SUMLIN(26:40) = '% within limits'                                 BARP247
      SUMLIN(47:59) = '% highlighted'                                   BARP248
                                                                        BARP249
C---- Calculate percentages and insert into line                        BARP250
      NTOTAL = NWITHN + NHIGHL + NOFFGR                                 BARP251
                                                                        BARP252
C---- Percentage within the specified limits                            BARP253
      IF (NTOTAL.GT.0) THEN                                             BARP254
          PERCEN = 100.0 * REAL(NWITHN) / REAL(NTOTAL)                  BARP255
      ELSE                                                              BARP256
          PERCEN = 0.0                                                  BARP257
      ENDIF                                                             BARP258
      WRITE(CNUMB,1010) PERCEN                                          BARP259
 1010 FORMAT(F5.1)                                                      BARP260
      SUMLIN(21:25) = CNUMB                                             BARP261
                                                                        BARP262
C---- Percentage highlighted                                            BARP263
      IF (NTOTAL.GT.0) THEN                                             BARP264
          PERCEN = 100.0 * REAL(NHIGHL + NOFFGR) / REAL(NTOTAL)         BARP265
      ELSE                                                              BARP266
          PERCEN = 0.0                                                  BARP267
      ENDIF                                                             BARP268
      WRITE(CNUMB,1010) PERCEN                                          BARP269
      SUMLIN(42:46) = CNUMB                                             BARP270
                                                                        BARP271
C---- Number off the graph                                              BARP272
      IF (NOFFGR.GT.0) THEN                                             BARP273
          WRITE(CNUMB,1020) NOFFGR                                      BARP274
 1020     FORMAT(I5)                                                    BARP275
          SUMLIN(63:67) = CNUMB                                         BARP276
          SUMLIN(69:77) = 'off graph'                                   BARP277
      ENDIF                                                             BARP278
                                                                        BARP279
C---- Determine whether to highlight the line with a + or a *           BARP280
      IF (PERCEN.GT.40.0) THEN                                          BARP281
          SUMLIN(1:1) = '+'                                             BARP282
      ENDIF                                                             BARP283
      IF (NOFFGR.GT.0 .OR. PERCEN.GT.50.0) THEN                         BARP284
          SUMLIN(1:1) = '*'                                             BARP285
      ENDIF                                                             BARP286
      IF (BTYPE.EQ.'P') THEN                                            BARP287
          IF (PERCEN.GT.0.0) SUMLIN(1:1) = '+'                          BARP288
          IF (PERCEN.GT.10.0) SUMLIN(1:1) = '*'                         BARP289
      ENDIF                                                             BARP290
                                                                        BARP291
C---- Write the line out to the summary file                            BARP292
      WRITE(14,1060) SUMLIN                                             BARP293
 1060 FORMAT(A)                                                         BARP294
CHECK v.3.2<--                                                          BARP295
                                                                        BARP296
      RETURN                                                            BARP297
      END                                                               BARP298
