      PROGRAM TPLOT                                                     TPLO0001
c ----------------------------------------------------------------------TPLO0002
c                                                                       TPLO0003
c  Windows NT / Win 95 code                                             TPLO0004
c                                                                       TPLO0005
c  Bernhard Rupp 1996 - minor modifications.                            TPLO0006
c                                                                       TPLO0007
c  1.  comment lines restricted to 72 columns                           TPLO0008
c  2.  source code lines numbered                                       TPLO0009
c  3.  to read file name of input file as parameter otherwise ask       TPLO0010
c  4.  taken apart into subroutines                                     TPLO0011
c                                                                       TPLO0012
c      Changes are annotated by WINNT at the beginning of comment lines TPLO0013
c                                                                       TPLO0014
C-----------------------------------------------------------------------TPLO0015
C                                                                       TPLO0016
C  TPLOT.F - Program to plot torsion angle distributions, including     TPLO0017
C            Ramachandran plots, and to calculate torsion angle         TPLO0018
C            G-factors                                                  TPLO0019
C                                                                       TPLO0020
C            Written by Roman Laskowski, University College, London,    TPLO0021
C            November 1993.                                             TPLO0022
C                                                                       TPLO0023
C            Original version was part of v.3.0 of the PROCHECK suite   TPLO0024
C            of programs.                                               TPLO0025
C                                                                       TPLO0026
C            Subsequent amendments will be labelled by CHECK v.m.n-->   TPLO0027
C            and CHECK v.m.n<-- where m.n is the version number         TPLO0028
C            corresponding to the change                                TPLO0029
C                                                                       TPLO0030
C  v.3.0.1 - Minor bug-fix: array out of bounds causing program to hang TPLO0031
C            on SG machines.                                            TPLO0032
C            Correction of integer variables incorrectly defined real   TPLO0033
C            Correction of another array-bound problem.                 TPLO0034
C            Commented out unreferenced labels (producing compiler      TPLO0035
C            warnings when compiling on Convex).                        TPLO0036
C               Roman Laskowski (29 Mar 1994)                           TPLO0037
C  v.3.1   - Transfer of FINKEY, GETCOL and GETNAM routines to ps.f.    TPLO0038
C            Unit number for procheck.prm file changed to 10 for        TPLO0039
C            consistency. Addition of plot description to display of    TPLO0040
C            plot file name.                                            TPLO0041
C               Roman Laskowski (8-19 Apr 1994)                         TPLO0042
C  v.3.2   - Addition of identifying plot handle to each plot filename. TPLO0043
C            Addition of descriptive plot title to header of PostScript TPLO0044
C            file. Addition of .sum file holding a summary page.        TPLO0045
C            Addition of option to print plot filename on the plot      TPLO0046
C            itself.                                                    TPLO0047
C            Chain ID made case-insensitive.                            TPLO0048
C               Roman Laskowski (22-30 Apr 1994)                        TPLO0049
C            Addition of option allowing plots of same type to be       TPLO0050
C            combined      in a single PostScript file.                 TPLO0051
C            Amendments for PROCHECK-NMR:                               TPLO0052
C               Pick up of parameters from the procheck_nmr.prm file    TPLO0053
C               Read in the individual .rin files listed in mplot.in.   TPLO0054
C               Print in title of number of models in the ensemble.     TPLO0055
C               Roman Laskowski (11-18 Oct 1994)                        TPLO0056
C            Minor amendments to various statements to make them        TPLO0057
C            acceptable to f2c, and to deal with various uninitialised  TPLO0058
C            variables.(Amendments supplied by Dave Love at Daresbury). TPLO0059
C               David Love/Roman Laskowski (18 Oct 1994)                TPLO0060
C            Print of model-numbers for ensembles.                      TPLO0061
C               Roman Laskowski (3 Nov 1994)                            TPLO0062
C            Addition of PROCHECK-COMP heading for plots when the       TPLO0063
C            ensemble version is run, and use of procheck_comp.prm      TPLO0064
C            parameter file.                                            TPLO0065
C               Roman Laskowski (10 Nov 1994)                           TPLO0066
C  v.3.3   - Additon of option to split the Ramachandrans onto a        TPLO0067
C            separate      page for each member of the ensemble.        TPLO0068
C               Roman Laskowski (13 Feb 1995)                           TPLO0069
C                                                                       TPLO0070
C  v.3.3.2 - Output of summary statistics in html format                TPLO0071
C               Roman Laskowski (21 Aug 1995)                           TPLO0072
C  v.3.4   - Additional options for Ramachandran plot based on          TPLO0073
C            suggestions by Ton Rullmann, including smaller boxes,      TPLO0074
C            filled boxes and      removal of model numbers.            TPLO0075
C               Ton Rullmann (Jun 1995) Roman Laskowski (12 Feb 1996)   TPLO0076
C            Implementation of option to split the Ramachandrans onto a TPLO0077
C            separate page for each member of the ensemble.             TPLO0078
C            Addition of range-selection allowing outputs to be limited TPLO0079
C            for certain models and certain ranges of residue-numbers.  TPLO0080
C               Roman Laskowski (22 Mar 1996)                           TPLO0081
C            Amendments of plot headings where model- or residue-ranges TPLO0082
C            apply.                                                     TPLO0083
C               Roman Laskowski (25 Mar 1996)                           TPLO0084
C            Increase of number of colours that can be user-defined.    TPLO0085
C            Bug-fix to datapoint colours on Ramachandran plot when     TPLO0086
C            printed in colour.                                         TPLO0087
C               Roman Laskowski (24 Apr 1996)                           TPLO0088
C                                                                       TPLO0089
C                                                                       TPLO0090
C-----------------------------------------------------------------------TPLO0091
C                                                                       TPLO0092
C Compilation and linking (on unix)                                     TPLO0093
C -----------------------                                               TPLO0094
C                                                                       TPLO0095
C f77 -u -c tplot.f                                                     TPLO0096
C f77 -u -c ps.f                                                        TPLO0097
C f77 -o tplot tplot.o ps.o                                             TPLO0098
C                                                                       TPLO0099
C Compilation and linking (on VAX VMS)                                  TPLO0100
C -----------------------                                               TPLO0101
C                                                                       TPLO0102
C FORT TPLOT                                                            TPLO0103
C FORT PS                                                               TPLO0104
C LINK TPLOT, PS                                                        TPLO0105
C                                                                       TPLO0106
C-----------------------------------------------------------------------TPLO0107
C                                                                       TPLO0108
C     Files                                                             TPLO0109
C     -----                                                             TPLO0110
C                                                                       TPLO0111
C  1  mplot.in       - File holding list of input .rin file making up   TPLO0112
C                      an ensemble of NMR structures                    TPLO0113
C  2  prodata        - File holding the torsion angle distributions for TPLO0114
C                      phi-psi and chi1-chi2 combinations. Data genrted TPLO0115
C                      by program gentors from a given database of high TPLO0116
C                      resolution protein structures. (Latest versn is  TPLO0117
C                      163 non-homologous structures from the Apr 93    TPLO0118
C                      release of the Brookhaven databank)              TPLO0119
C  3  <filename>.rin - File generated by program SECSTR, holding all theTPLO0120
C                      residue-by-residue torsion angle information     TPLO0121
C  4  <filename>.lan - File generated by program ANGLEN, holding all theTPLO0122
C                      mainchain bond lengths and bond angles           TPLO0123
C  7  <filename>.sdh - Output file holding the residue-by-residue       TPLO0124
C                      log-odds scores calculated here                  TPLO0125
C  10 procheck.prm   - Input parameter file containing user-defined     TPLO0126
C                      options governing the plots produced. Name of    TPLO0127
C                      file might be:                                   TPLO0128
C                         procheck_nmr.prm - when NMR option being run  TPLO0129
C                         procheck_comp.prm - when COMP option run      TPLO0130
C                         on an ensemble of structures                  TPLO0131
C  11 <filename>_nn.ps - Output PostScript files, numbered nn = 01, 02, TPLO0132
C  12  ps.number     - Input file holding last-used number for the      TPLO0133
C                      PostScript files                                 TPLO0134
C  14 <filename>.sum - Output summary page showing summarised results   TPLO0135
C                      from all the plots                               TPLO0136
C  15 <filename>.html- Output html file giving summary statistics in    TPLO0137
C                      htlm format                                      TPLO0138
C  16 <user-defined> - Optional input file holding the model- and       TPLO0139
C                      residue-number ranges to be included in the plotsTPLO0140
C                                                                       TPLO0141
C-----------------------------------------------------------------------TPLO0142
C                                                                       TPLO0143
C     Subroutine calling tree                                           TPLO0144
C     -----------------------                                           TPLO0145
C                                                                       TPLO0146
C     MAIN    --> INITS                                                 TPLO0147
C                                                                       TPLO0148
C                 Get filename and resolution of structure, and read in TPLO0149
C                 plot parameters                                       TPLO0150
C             --> GETCOD  --> GETNAM                                    TPLO0151
C                         --> GETFIL                                    TPLO0152
C             --> PARAMS  --> FINKEY                                    TPLO0153
C                         --> GETCOL                                    TPLO0154
C             --> GETRNG  --> GETOKN                                    TPLO0155
C                         --> INTOKN  --> LENSTR                        TPLO0156
C                         --> DELTOK                                    TPLO0157
C                         --> STOTOK                                    TPLO0158
C                         --> PRNRNG                                    TPLO0159
C             --> GETWNT  --> INMODL                                    TPLO0160
C             --> NORMGS  --> CALCOV                                    TPLO0161
C             --> OPESUM                                                TPLO0162
C             --> OPEHTM                                                TPLO0163
C                                                                       TPLO0164
C                 Read in and uncompress the torsion angle distributionsTPLO0165
C             --> GETDAT                                                TPLO0166
C                                                                       TPLO0167
C                 Read in the data points from the structure            TPLO0168
C             --> GETPTS  --> RAMOPE   --> PSNAME                       TPLO0169
C                                      --> PSOPEN                       TPLO0170
C                         --> RAMACH   --> PSPAGE                       TPLO0171
C                                      --> PSTEXT                       TPLO0172
C                                      --> PSCTXT                       TPLO0173
C                                      --> RAMSHD -> PSLWID             TPLO0174
C                                                 -> PSLINE             TPLO0175
C                                                 -> RAMFIL  --> PSLWID TPLO0176
C                                                            --> RAMREG TPLO0177
C                                                            --> PSHADE TPLO0178
C                                                            --> PSUBOX TPLO0179
C                                                            --> PSCOLR TPLO0180
C                                                 -> RAMLIN  --> PSLWID TPLO0181
C                                                            --> RAMREG TPLO0182
C                                                            --> PSLINE TPLO0183
C                                                 -> INCLET  --> PSHADE TPLO0184
C                                                            --> PSCTXT TPLO0185
C                                      --> RAMAXE -> AXES    --> PSLWID TPLO0186
C                                                            --> PSLINE TPLO0187
C                                                            --> PSCTXT TPLO0188
C                                                  --> PSLWID           TPLO0189
C                                                  --> PSDASH           TPLO0190
C                                                  --> PSLINE           TPLO0191
C                                                  --> PSCTXT           TPLO0192
C                                                  --> PSRTXT           TPLO0193
C                          --> INRANG  --> LENSTR                       TPLO0194
C                          --> RAMREG                                   TPLO0195
C                          --> RAMPLT  --> PSMARK  --> PSBBOX           TPLO0196
C                                                  --> PSTRIA           TPLO0197
C                                      --> PSCTXT                       TPLO0198
C                          --> FILKEY  --> PSLWID                       TPLO0199
C                                      --> PSHADE                       TPLO0200
C                                      --> PSBBOX                       TPLO0201
C                                      --> PSCTXT                       TPLO0202
C                                      --> PSTEXT                       TPLO0203
C                          --> MSTATS                                   TPLO0204
C                          --> RAMEND  --> RMSTAT  -> RAMPUT -> PSCTXT  TPLO0205
C                                                            -> PSTEXT  TPLO0206
C                                                  -> PSCTXT            TPLO0207
C                                      --> PSENDP                       TPLO0208
C                          --> PSCLOS                                   TPLO0209
C                                                                       TPLO0210
C                 Plot the torsion angle distributions                  TPLO0211
C             --> PLOTS   --> PSNAME                                    TPLO0212
C                         --> PSOPEN                                    TPLO0213
C                         --> PSPAGE                                    TPLO0214
C                         --> PLTGRD  --> PLTDIS --> PSLWID             TPLO0215
C                                                --> PSCALE             TPLO0216
C                                                --> PSUBOX             TPLO0217
C                                                --> PSLWID             TPLO0218
C                                                --> PSDASH             TPLO0219
C                                                --> PSLINE             TPLO0220
C                                     --> AXES   --> PSLWID             TPLO0221
C                                                --> PSLINE             TPLO0222
C                                                --> PSCTXT             TPLO0223
C                                     --> PSCTXT                        TPLO0224
C                                     --> PSRTXT                        TPLO0225
C                         --> PROCPT  --> CALC1D                        TPLO0226
C                                     --> CALC2D                        TPLO0227
C                                     --> PSLWID                        TPLO0228
C                                     --> PSLINE                        TPLO0229
C                                     --> PSCTXT                        TPLO0230
C                         --> FILKEY  --> PSLWID                        TPLO0231
C                                     --> PSHADE                        TPLO0232
C                                     --> PSBBOX                        TPLO0233
C                                     --> PSCTXT                        TPLO0234
C                                     --> PSTEXT                        TPLO0235
C                         --> PLTEND  --> PSTEXT                        TPLO0236
C                                     --> PSCTXT                        TPLO0237
C                         --> PSENDP                                    TPLO0238
C                         --> PSCLOS                                    TPLO0239
C                                                                       TPLO0240
C                 Calculate covalent quality scores from main-chain bondTPLO0241
C                 lengths and angles                                    TPLO0242
C             --> GETLAN                                                TPLO0243
C             --> COVSCO  --> CALCOV                                    TPLO0244
C                         --> RESCOR                                    TPLO0245
C                                                                       TPLO0246
C                 Write out the calculated, residue-by-residue log-odds TPLO0247
C                 scores                                                TPLO0248
C             --> WRISDH                                                TPLO0249
C             --> PUTPSN                                                TPLO0250
C                                                                       TPLO0251
C-----------------------------------------------------------------------TPLO0252
                                                                        TPLO0253
      INCLUDE 'tplot.inc'                                               TPLO0254
                                                                        TPLO0255
CHECK v.3.2-->                                                          TPLO0256
C      INTEGER       DISTRB                                             TPLO0257
      INTEGER       DISTRB, LOOPS                                       TPLO0258
WINNT  - added logical newfil                                           TPLO0259
      LOGICAL       BOTHND, newfil                                      TPLO0260
CHECK v.3.2<--                                                          TPLO0261
                                                                        TPLO0262
C---- Initialise variables                                              TPLO0263
      CALL INITS                                                        TPLO0264
WINNT - newfil is true for TPLOT                                        TPLO0265
      newfil=.true.                                                     TPLO0266
      IF (IFAIL) GO TO 999                                              TPLO0267
                                                                        TPLO0268
CHECK v.3.2-->                                                          TPLO0269
C---- Read in the code of the Brookhaven file and the structure's       TPLO0270
C     resolution                                                        TPLO0271
      CALL GETCOD                                                       TPLO0272
      IF (IFAIL) GO TO 999                                              TPLO0273
CHECK v.3.2<--                                                          TPLO0274
                                                                        TPLO0275
C---- Read in the program parameters                                    TPLO0276
      CALL PARAMS                                                       TPLO0277
      IF (IFAIL) GO TO 999                                              TPLO0278
                                                                        TPLO0279
CHECK v.3.4-->                                                          TPLO0280
C---- Read in the model- and residue-ranges in the supplied ranges file,TPLO0281
C     if there is one                                                   TPLO0282
      IF (HAVRAN) THEN                                                  TPLO0283
          CALL GETRNG(FILRNG,MODFRM,MODTO,RESFRM,RESTO,MAXRNG,MRANGE,   TPLO0284
     &        NRANGE,BOTHND,IFAIL)                                      TPLO0285
          IFAIL = .FALSE.                                               TPLO0286
                                                                        TPLO0287
C----     Check whether the user has selected a range of residues       TPLO0288
          IF (RESFRM(1).NE.'*ALL  ') RSELEC = .TRUE.                    TPLO0289
      ENDIF                                                             TPLO0290
                                                                        TPLO0291
C---- If this is an NMR structure, then find which of the files         TPLO0292
C     contain the wanted models                                         TPLO0293
      IF (NMR) THEN                                                     TPLO0294
          CALL GETWNT(MXFILE,NFILE,FILRIN,FFILE,MAXRNG,MODFRM,MODTO,    TPLO0295
     &        MRANGE,RSELEC,MWANT,NMODEL,MODNUM,ACTNUM,TOPMOD,          TPLO0296
     &        BRCODE,NAMLEN,BLEN,IFAIL)                                 TPLO0297
          IF (IFAIL) GO TO 999                                          TPLO0298
                                                                        TPLO0299
C---- Model ranges only apply to NMR ensembles, so set to default       TPLO0300
C     if this is not an NMR structure                                   TPLO0301
      ELSE                                                              TPLO0302
          MRANGE = 1                                                    TPLO0303
          MODFRM(MRANGE) = -99999                                       TPLO0304
          MODTO(MRANGE) = 99999                                         TPLO0305
      ENDIF                                                             TPLO0306
CHECK v.3.4<--                                                          TPLO0307
                                                                        TPLO0308
C---- Calculate normalization factors for the Gaussian distribs used forTPLO0309
C     bond lengths and bond angles                                      TPLO0310
      CALL NORMGS                                                       TPLO0311
                                                                        TPLO0312
CHECK v.3.2-->                                                          TPLO0313
CC---- Read in the code of the Brookhaven file and the structure's      TPLO0314
CC     resolution                                                       TPLO0315
C      CALL GETCOD                                                      TPLO0316
C      IF (IFAIL) GO TO 999                                             TPLO0317
CHECK v.3.2<--                                                          TPLO0318
                                                                        TPLO0319
CHECK v.3.2-->                                                          TPLO0320
C---- Open the summary file                                             TPLO0321
WINNT - newfil is parameter to OPESUM now                               TPLO0322
      CALL OPESUM(FILSUM,newfil,IFAIL)                                  TPLO0323
      IF (IFAIL) GO TO 999                                              TPLO0324
                                                                        TPLO0325
C---- For NMR or ensemble, only need to loop over the distributions to  TPLO0326
C     be plotted                                                        TPLO0327
      IF (NMR .OR. ENSEMB) THEN                                         TPLO0328
          LOOPS = 2                                                     TPLO0329
      ELSE                                                              TPLO0330
          LOOPS = NDISTR                                                TPLO0331
      ENDIF                                                             TPLO0332
CHECK v.3.2<--                                                          TPLO0333
                                                                        TPLO0334
CHECK v.3.3.2-->                                                        TPLO0335
C---- Open the html file                                                TPLO0336
WINNT - newfil is parameter to OPEHTM now                               TPLO0337
      CALL OPEHTM(FILHTM,newfil,IFAIL)                                  TPLO0338
      IF (IFAIL) GO TO 999                                              TPLO0339
CHECK v.3.3.2<--                                                        TPLO0340
                                                                        TPLO0341
C---- Loop for the different types of distributions to be plotted       TPLO0342
CHECK v.3.2-->                                                          TPLO0343
C      DO 100, DISTRB = 1, NDISTR                                       TPLO0344
      DO 100, DISTRB = 1, LOOPS                                         TPLO0345
CHECK v.3.2<--                                                          TPLO0346
                                                                        TPLO0347
C----     Read in the torsion angle distributions and uncompress the    TPLO0348
C         data                                                          TPLO0349
          CALL GETDAT(DISTRB)                                           TPLO0350
          IF (IFAIL) GO TO 999                                          TPLO0351
                                                                        TPLO0352
C----     Read in the data points from the .rin file                    TPLO0353
          CALL GETPTS(DISTRB)                                           TPLO0354
          IF (IFAIL) GO TO 999                                          TPLO0355
                                                                        TPLO0356
C----     Plot the data superimposed on the distributions               TPLO0357
          CALL PLOTS(DISTRB)                                            TPLO0358
                                                                        TPLO0359
 100  CONTINUE                                                          TPLO0360
                                                                        TPLO0361
C---- Read through the main-chain bond lengths and bond angles file to  TPLO0362
C     calculate mean values                                             TPLO0363
CHECK v.3.2-->                                                          TPLO0364
      IF (.NOT.NMR .AND. .NOT.ENSEMB) THEN                              TPLO0365
CHECK v.3.2<--                                                          TPLO0366
          CALL GETLAN                                                   TPLO0367
          IF (IFAIL) GO TO 999                                          TPLO0368
                                                                        TPLO0369
C----     Calculate covalent quality scores from main-chain bond lengthsTPLO0370
C         and angles                                                    TPLO0371
          CALL COVSCO                                                   TPLO0372
                                                                        TPLO0373
C----     Write out the calculated residue-by-residue log-odds scores   TPLO0374
          CALL WRISDH                                                   TPLO0375
CHECK v.3.2-->                                                          TPLO0376
      ENDIF                                                             TPLO0377
CHECK v.3.2<--                                                          TPLO0378
                                                                        TPLO0379
C---- Write out the current PostScript plot number                      TPLO0380
      CALL PUTPSN(IPLOT)                                                TPLO0381
                                                                        TPLO0382
 999  CONTINUE                                                          TPLO0383
      IF (IFAIL) THEN                                                   TPLO0384
          PRINT*, '*** Program tplot terminated with error'             TPLO0385
CHECK v.3.2-->                                                          TPLO0386
          WRITE(14,*)                                                   TPLO0387
          WRITE(14,*) '*** Program tplot terminated with error. See lo',TPLO0388
     &        'g file:  tplot.log'                                      TPLO0389
          WRITE(14,*)                                                   TPLO0390
CHECK v.3.2<--                                                          TPLO0391
      ELSE                                                              TPLO0392
         PRINT*, '* Program complete'                                   TPLO0393
      ENDIF                                                             TPLO0394
      END                                                               TPLO0395
                                                                        TPLO0396
      SUBROUTINE INITS                                                  INIT0001
C-----------------------------------------------------------------------INIT0002
C                                                                       INIT0003
C  SUBROUTINE INITS  -  Initialise variables                            INIT0004
C                                                                       INIT0005
C----------------------------------------------------------------------+INIT0006
                                                                        INIT0007
      INCLUDE 'tplot.inc'                                               INIT0008
                                                                        INIT0009
      CHARACTER*3   AMNAME(NAMINO)                                      INIT0010
WINNT - the dat file is procheck.dat now                                INIT0011
      character prodat*20                                               INIT0012
WINNT - end                                                             INIT0013
                                                                        INIT0014
CHECK v.3.4-->                                                          INIT0015
C      INTEGER       IAMINO, IDISTR, IRESID, ITYPE                      INIT0016
      INTEGER       IAMINO, IDISTR, IFILE, IRESID, ITYPE                INIT0017
CHECK v.3.4<--                                                          INIT0018
                                                                        INIT0019
      DATA AMNAME /'ALA', 'ARG', 'ASN', 'ASP', 'CYS', 'GLN', 'GLU',     INIT0020
     &             'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE',     INIT0021
     &             'PRO', 'SER', 'THR', 'TRP', 'TYR', 'VAL' /           INIT0022
                                                                        INIT0023
C---- Initialise variables                                              INIT0024
      ALLRAM = .FALSE.                                                  INIT0025
      DO 50, IAMINO = 1, NAMINO                                         INIT0026
          AMINO(IAMINO) = AMNAME(IAMINO)                                INIT0027
 50   CONTINUE                                                          INIT0028
      CHAIN = ' '                                                       INIT0029
CHECK v.3.2-->                                                          INIT0030
      COMBPS = .FALSE.                                                  INIT0031
CHECK v.3.2<--                                                          INIT0032
      CRONLY = .FALSE.                                                  INIT0033
      DO 60, ITYPE = 1, 3                                               INIT0034
          COVAVE(ITYPE) = 0.0                                           INIT0035
          NUMAVE(ITYPE) = 0                                             INIT0036
 60   CONTINUE                                                          INIT0037
      DO 80, IDISTR = 1, NDISTR                                         INIT0038
          IF (IDISTR.GT.2) THEN                                         INIT0039
              DOPLOT(IDISTR) = .FALSE.                                  INIT0040
          ELSE                                                          INIT0041
              DOPLOT(IDISTR) = .TRUE.                                   INIT0042
          ENDIF                                                         INIT0043
 80   CONTINUE                                                          INIT0044
CHECK v.3.4-->                                                          INIT0045
      FFILE = 1                                                         INIT0046
      HAVRAN = .FALSE.                                                  INIT0047
CHECK v.3.4<--                                                          INIT0048
      IFAIL = .FALSE.                                                   INIT0049
      INCOLR = .FALSE.                                                  INIT0050
      INCOLG = .FALSE.                                                  INIT0051
      INCOLC = .FALSE.                                                  INIT0052
      IPLOT = 0                                                         INIT0053
      LABRES = 1                                                        INIT0054
      LIMCHI = -2.0                                                     INIT0055
      LIMGP = -2.0                                                      INIT0056
      INCLET = .TRUE.                                                   INIT0057
CHECK v.3.2-->                                                          INIT0058
      NFILE = 1                                                         INIT0059
      ENSEMB = .FALSE.                                                  INIT0060
      NMR = .FALSE.                                                     INIT0061
CHECK v.3.2<--                                                          INIT0062
      NOLINE = .FALSE.                                                  INIT0063
      NOSHAD = .FALSE.                                                  INIT0064
CHECK v.3.4-->                                                          INIT0065
      MRANGE = 1                                                        INIT0066
      MODFRM(MRANGE) = -99999                                           INIT0067
      MODTO(MRANGE) = 99999                                             INIT0068
      DO 100, IFILE = 1, MXFILE                                         INIT0069
          MWANT(IFILE) = .TRUE.                                         INIT0070
 100  CONTINUE                                                          INIT0071
      NRANGE = 1                                                        INIT0072
      NMODEL = 1                                                        INIT0073
      RESFRM(NRANGE) = '*ALL  '                                         INIT0074
      RESTO(NRANGE) = 'XXXXXX'                                          INIT0075
CHECK v.3.4<--                                                          INIT0076
CHECK v.3.2-->                                                          INIT0077
      PLABEL = .TRUE.                                                   INIT0078
CHECK v.3.2<--                                                          INIT0079
      PLOTRM = .TRUE.                                                   INIT0080
CHECK v.3.4-->                                                          INIT0081
      RBXFIL = .FALSE.                                                  INIT0082
      RBXMOD = .TRUE.                                                   INIT0083
      RBXSIZ = 1.0                                                      INIT0084
      RSELEC = .FALSE.                                                  INIT0085
CHECK v.3.4<--                                                          INIT0086
      DO 300, IRESID = 1, MXRES                                         INIT0087
CHECK v.3.2-->                                                          INIT0088
          MODEL(IRESID) = 0                                             INIT0089
CHECK v.3.2<--                                                          INIT0090
          SAVRES(IRESID) = 0                                            INIT0091
          DO 150, ITYPE = 1, 3                                          INIT0092
              SCOVAL(ITYPE,IRESID) = 0.0                                INIT0093
 150      CONTINUE                                                      INIT0094
          DO 200, IDISTR = 1, NDISTR                                    INIT0095
              SCORE(IDISTR,IRESID) = 999.99                             INIT0096
 200      CONTINUE                                                      INIT0097
 300  CONTINUE                                                          INIT0098
      USENGH = .TRUE.                                                   INIT0099
CHECK v.3.2-->                                                          INIT0100
      WITHAN = .FALSE.                                                  INIT0101
CHECK v.3.2<--                                                          INIT0102
                                                                        INIT0103
C---- Open data file, prodata                                           INIT0104
WINNT - the data file is procheck.dat now                               INIT0105
c      OPEN(UNIT=2, FILE='prodata', STATUS='OLD',                       INIT0106
c     &     FORM='FORMATTED', ACCESS='SEQUENTIAL',                      INIT0107
CVAX     -     CARRIAGECONTROL = 'LIST', READONLY,                      INIT0108
c     &     ERR=900)                                                    INIT0109
      prodat='procheck.dat'                                             INIT0110
      OPEN(UNIT=2, FILE=prodat,STATUS='OLD',ERR=900)                    INIT0111
WINNT - end                                                             INIT0112
      GO TO 999                                                         INIT0113
                                                                        INIT0114
900   CONTINUE                                                          INIT0115
      PRINT*, '*** ERROR. Unable to open parameter file, prodata'       INIT0116
      GO TO 990                                                         INIT0117
                                                                        INIT0118
 990  CONTINUE                                                          INIT0119
      IFAIL = .TRUE.                                                    INIT0120
                                                                        INIT0121
999   CONTINUE                                                          INIT0122
      RETURN                                                            INIT0123
      END                                                               INIT0124
                                                                        INIT0125
      SUBROUTINE GETCOD                                                 GETC0001
C-----------------------------------------------------------------------GETC0002
C                                                                       GETC0003
C  SUBROUTINE GETCOD  -  Read in the name of the .rin file to be processGETC0004
C                                                                       GETC0005
C----------------------------------------------------------------------+GETC0006
                                                                        GETC0007
      INCLUDE 'tplot.inc'                                               GETC0008
                                                                        GETC0009
WINNT - needed for system call to getarg                                GETC0010
      integer(2)  n1,status                                             GETC0011
WINNT - end                                                             GETC0012
CHECK v.3.2-->                                                          GETC0013
C      CHARACTER*80  PDBFIL                                             GETC0014
C      INTEGER       LINE                                               GETC0015
c      CHARACTER*1   LOWERA, YESNO                                      GETC0016
WINNT      - unused variables removed                                   GETC0017
      CHARACTER   NUMBER*3                                              GETC0018
      character cres*8                                                  GETC0019
c      CHARACTER*26  UPPER                                              GETC0020
CHECK v.3.4-->                                                          GETC0021
C      INTEGER       IPOS, LINE, N                                      GETC0022
      INTEGER       IPOS, LENSTR, LINE !, N WINNT - not needed          GETC0023
CHECK v.3.4<--                                                          GETC0024
CHECK v.3.2<--                                                          GETC0025
      LOGICAL       IERROR                                              GETC0026
                                                                        GETC0027
CHECK v.3.2-->                                                          GETC0028
c      DATA  LOWERA / 'a' /                                             GETC0029
c      DATA  UPPER  / 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /                    GETC0030
CHECK v.3.2<--                                                          GETC0031
                                                                        GETC0032
C---- Initialise variables                                              GETC0033
      LINE = 0                                                          GETC0034
                                                                        GETC0035
WINNT - accept file name, cahain id and resol from command line if      GETC0036
c       provided else ask for it  GETC035                               GETC0037
      write(*,*) 'TPLOT - Windows NT version B.Rupp 1996'               GETC0038
      n1 = 1                                                            GETC0039
      CALL GETARG(n1, pdbfil, status)                                   GETC0040
      if (status.lt.1) then                                             GETC0041
         PRINT*, 'Enter filename containing coordinates of structure '  GETC0042
CHECK v.3.2-->                                                          GETC0043
         PRINT*, '  (for file containing ensemble of NMR structures en',GETC0044
     &    'ter @filename;'                                              GETC0045
         PRINT*, '   for set of separate PDB files to be processed, en',GETC0046
     &    'ter %filelist,'                                              GETC0047
         PRINT*, '   where filelist contains a list of PDB files to be',GETC0048
     &    ' cleaned up)'                                                GETC0049
CHECK v.3.2<--                                                          GETC0050
         READ(*,10) PDBFIL                                              GETC0051
10       FORMAT(A)                                                      GETC0052
      else                                                              GETC0053
         write(*,*) 'File name parsed from command line : ',pdbfil      GETC0054
      end if                                                            GETC0055
CHECK v.3.2-->                                                          GETC0056
      IF (PDBFIL(1:1).EQ.'%') THEN                                      GETC0057
          PDBFIL = PDBFIL(2:)                                           GETC0058
          ENSEMB = .TRUE.                                               GETC0059
          NMR = .FALSE.                                                 GETC0060
      ENDIF                                                             GETC0061
      IF (PDBFIL(1:1).EQ.'@') THEN                                      GETC0062
          PDBFIL = PDBFIL(2:)                                           GETC0063
          ENSEMB = .TRUE.                                               GETC0064
          NMR = .TRUE.                                                  GETC0065
      ENDIF                                                             GETC0066
CHECK v.3.2<--                                                          GETC0067
c --- get second parameter from command line                            GETC0068
      n1 = 2                                                            GETC0069
      CALL GETARG(n1, chain, status)                                    GETC0070
c --- if missing, get the chain id                                      GETC0071
      if (status.lt.1) then                                             GETC0072
C----   Accept chain-ID                                                 GETC0073
        write(*,'(a$)')' Enter chain-ID letter or leave blank for all: 'GETC0074
        READ(*,'(a)',ERR=906) CHAIN                                     GETC0075
WINNT - subroutine call to new subroutine UPSTRG                        GETC0076
        call upstrg (chain,1)                                           GETC0077
C----   Accept resolution                                               GETC0078
 9015   write(*,'(a$)')' Enter resolution : '                           GETC0079
        READ(*,*,ERR=9015) RESOL                                        GETC0080
      else                                                              GETC0081
c ---   there is something but what                                     GETC0082
        call upstrg (chain,1)                                           GETC0083
c ---   if it's a number it must be the resolution so use blank for all GETC0084
WINNT - new function ISNUM returns true if character is a number        GETC0085
        if (isnum(chain)) then                                          GETC0086
           chain=' '                                                    GETC0087
           write(*,*)'All chains included '                             GETC0088
c ---      must be the resolution then                                  GETC0089
           CALL GETARG(n1, cres, status)                                GETC0090
           read(cres,'(f5.0)') resol                                    GETC0091
           write (*,'(a,f5.2)')' Resolution is ',resol                  GETC0092
        else                                                            GETC0093
           write(*,*)'Chain processed : ',chain                         GETC0094
c ---      get third parameter from command line                        GETC0095
           n1 = 3                                                       GETC0096
           CALL GETARG(n1, cres, status)                                GETC0097
           read(cres,'(f8.0)') resol                                    GETC0098
           write (*,'(a,f5.2)')' Resolution is ',resol                  GETC0099
c ---      if missing, get the resolution                               GETC0100
           if (status.lt.1) then                                        GETC0101
C----         Accept resolution                                         GETC0102
 9014         write(*,'(a$)')' Enter resolution : '                     GETC0103
              READ(*,*,ERR=9014) RESOL                                  GETC0104
           end if                                                       GETC0105
        end if                                                          GETC0106
      end if                                                            GETC0107
                                                                        GETC0108
C---- Accept name of original .pdb file holding the structure           GETC0109
CHECK v.3.4-->                                                          GETC0110
C      PRINT*, 'Enter filename of coordinates'                          GETC0111
c      PRINT*, 'Enter filename of coordinates (prefix with a % for',    GETC0112
c     &    ' a non-NMR ensemble'                                        GETC0113
CHECK v.3.4<--                                                          GETC0114
c      READ(*,110,ERR=900) PDBFIL                                       GETC0115
CHECK v.3.2-->                                                          GETC0116
c      IF (PDBFIL(1:1).EQ.'%') THEN                                     GETC0117
c          PDBFIL = PDBFIL(2:)                                          GETC0118
c          ENSEMB = .TRUE.                                              GETC0119
c          NMR = .FALSE.                                                GETC0120
c      ENDIF                                                            GETC0121
CHECK v.3.2<--                                                          GETC0122
c 110  FORMAT(A)                                                        GETC0123
                                                                        GETC0124
C---- Accept chain-ID                                                   GETC0125
c      PRINT*, 'Enter required chain-ID, or leave blank for all'        GETC0126
c      READ(*,110,ERR=906) CHAIN                                        GETC0127
                                                                        GETC0128
CHECK v.3.2-->                                                          GETC0129
C---- Convert chain ID to upper-case if necessary                       GETC0130
c      N = ICHAR(CHAIN) - ICHAR(LOWERA) + 1                             GETC0131
c      IF (N.GE.1 .AND. N.LE.26) CHAIN = UPPER(N:N)                     GETC0132
CHECK v.3.2<--                                                          GETC0133
                                                                        GETC0134
C---- Accept structure's resolution                                     GETC0135
c      PRINT*, 'Enter resolution'                                       GETC0136
c      READ(*,*,ERR=904) RESOL                                          GETC0137
                                                                        GETC0138
CHECK v.3.2-->                                                          GETC0139
C---- Accept whether processing an ensemble of structures               GETC0140
c      PRINT*, 'Is this an ensemble of structures (Y/N)?'               GETC0141
c      READ(*,110) YESNO                                                GETC0142
c      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                         GETC0143
c          IF (.NOT.ENSEMB) NMR = .TRUE.                                GETC0144
c      ENDIF                                                            GETC0145
CHECK v.3.2<--                                                          GETC0146
                                                                        GETC0147
C---- Peel off directory path and extension                             GETC0148
      CALL GETNAM(PDBFIL,ISTART,IEND,IERROR)                            GETC0149
      IF (IERROR) GO TO 990                                             GETC0150
                                                                        GETC0151
C---- Form names of other files that will be required in default directoGETC0152
      BRCODE = PDBFIL(ISTART:IEND)                                      GETC0153
      FILLAN = PDBFIL(ISTART:IEND) // '.lan'                            GETC0154
CHECK v.3.2-->                                                          GETC0155
C      FILRIN = PDBFIL(ISTART:IEND) // '.rin'                           GETC0156
      FILRIN(1) = PDBFIL(ISTART:IEND) // '.rin'                         GETC0157
CHECK v.3.2<--                                                          GETC0158
      FILSDH = PDBFIL(ISTART:IEND) // '.sdh'                            GETC0159
CHECK v.3.2-->                                                          GETC0160
      FILSUM = PDBFIL(ISTART:IEND) // '.sum'                            GETC0161
CHECK v.3.2<--                                                          GETC0162
CHECK v.3.3.2-->                                                        GETC0163
      FILHTM = PDBFIL(ISTART:IEND) // '.html'                           GETC0164
CHECK v.3.3.2<--                                                        GETC0165
      FILPS = BRCODE                                                    GETC0166
      PSLEN = IEND - ISTART + 1                                         GETC0167
      BLEN = PSLEN                                                      GETC0168
      IF (CHAIN.NE.' ') THEN                                            GETC0169
          BRCODE = BRCODE(1:BLEN) // ' - Chain ' // CHAIN               GETC0170
          BLEN = BLEN + 10                                              GETC0171
          IF (BLEN.GT.78) BLEN = 78                                     GETC0172
      ENDIF                                                             GETC0173
                                                                        GETC0174
CHECK v.3.4-->                                                          GETC0175
C---- If separate Ramachandran for each model, then will label          GETC0176
C     each one with the appropriate model number                        GETC0177
      RAMHED = BRCODE(1:BLEN) // ' (Model '                             GETC0178
      RLEN = BLEN + 14                                                  GETC0179
                                                                        GETC0180
C---- Save the length of the PDB code plus chain ID (if relevant)       GETC0181
      NAMLEN = BLEN                                                     GETC0182
CHECK v.3.4<--                                                          GETC0183
                                                                        GETC0184
CHECK v.3.2-->                                                          GETC0185
C---- If this is an ensemble, read in the list of .rin filenames        GETC0186
      IF (NMR .OR. ENSEMB) THEN                                         GETC0187
          CALL GETFIL                                                   GETC0188
          IF (IFAIL) GO TO 999                                          GETC0189
                                                                        GETC0190
C----     Add number of models to plot title                            GETC0191
          IF (BLEN.LT.65) THEN                                          GETC0192
              WRITE(NUMBER,120) NFILE                                   GETC0193
 120          FORMAT(I3)                                                GETC0194
              IPOS = 1                                                  GETC0195
              IF (NUMBER(1:1).EQ.' ') IPOS = 2                          GETC0196
              IF (NUMBER(2:2).EQ.' ') IPOS = 3                          GETC0197
              BRCODE = BRCODE(1:BLEN) // ' (' // NUMBER(IPOS:) //       GETC0198
     &            ' models)'                                            GETC0199
              BLEN = BLEN + 14 - IPOS                                   GETC0200
          ENDIF                                                         GETC0201
                                                                        GETC0202
C---- Otherwise, if only a single .rin file, then open it               GETC0203
      ELSE                                                              GETC0204
CHECK v.3.2-->                                                          GETC0205
C      OPEN(UNIT=3,FILE=FILRIN,STATUS='OLD',ACCESS='SEQUENTIAL',        GETC0206
CCVAX     -     READONLY,                                               GETC0207
C     -    FORM='FORMATTED',ERR=902)                                    GETC0208
          OPEN(UNIT=3,FILE=FILRIN(1),STATUS='OLD',ACCESS='SEQUENTIAL',  GETC0209
CVAX     -     READONLY,                                                GETC0210
     &    FORM='FORMATTED',ERR=902)                                     GETC0211
      ENDIF                                                             GETC0212
CHECK v.3.2<--                                                          GETC0213
                                                                        GETC0214
CHECK v.3.4-->                                                          GETC0215
C---- Read in (optional) name of ranges file                            GETC0216
      FILRNG = ' '                                                      GETC0217
      IF (NMR) THEN                                                     GETC0218
          PRINT*, 'Enter name of ranges file (blank if none)'           GETC0219
          READ(*,10,ERR=900) FILRNG                                     GGETC0220
      ENDIF                                                             GETC0221
      IF (FILRNG.EQ.' ') THEN                                           GETC0222
          HAVRAN = .FALSE.                                              GETC0223
      ELSE                                                              GETC0224
          HAVRAN = .TRUE.                                               GETC0225
      ENDIF                                                             GETC0226
CHECK v.3.4<--                                                          GETC0227
                                                                        GETC0228
      GO TO 999                                                         GETC0229
                                                                        GETC0230
C---- Fatal errors                                                      GETC0231
 900  CONTINUE                                                          GETC0232
      PRINT*, '*** ERROR. Data error in entered filename'               GETC0233
      GO TO 990                                                         GETC0234
                                                                        GETC0235
 902  CONTINUE                                                          GETC0236
      PRINT*, '*** Error opening .rin file.'                            GETC0237
CHECK v.3.2-->                                                          GETC0238
CHECK v.3.4-->                                                          GETC0239
C      PRINT*, FILRIN(1)                                                GETC0240
      PRINT*, '* [', FILRIN(1)(1:LENSTR(FILRIN(1))), ']'                GETC0241
CHECK v.3.4<--                                                          GETC0242
CHECK v.3.2<--                                                          GETC0243
      GO TO 990                                                         GETC0244
                                                                        GETC0245
 904  CONTINUE                                                          GETC0246
      PRINT*, '*** Error in entered resolution'                         GETC0247
      GO TO 990                                                         GETC0248
                                                                        GETC0249
 906  CONTINUE                                                          GETC0250
      PRINT*, '*** ERROR. Data error in entered chain-ID'               GETC0251
      GO TO 990                                                         GETC0252
                                                                        GETC0253
990   CONTINUE                                                          GETC0254
      IFAIL = .TRUE.                                                    GETC0255
                                                                        GETC0256
999   CONTINUE                                                          GETC0257
      RETURN                                                            GETC0258
      END                                                               GETC0259
                                                                        GETC0260
      SUBROUTINE GETFIL                                                 GETF0001
C-----------------------------------------------------------------------GETF0002
CHECK v.3.2-->                                                          GETF0003
C                                                                       GETF0004
C  SUBROUTINE GETFIL  -  Read in the list of input .rin files in mplot.iGETF0005
C                                                                       GETF0006
C----------------------------------------------------------------------+GETF0007
                                                                        GETF0008
      INCLUDE 'tplot.inc'                                               GETF0009
                                                                        GETF0010
      CHARACTER*80  FNAME                                               GETF0011
      INTEGER       IPOS                                                GETF0012
      LOGICAL       FOUND                                               GETF0013
                                                                        GETF0014
C---- Initialise variables                                              GETF0015
      NFILE = 0                                                         GETF0016
                                                                        GETF0017
C---- Open input file, mplot.in                                         GETF0018
      OPEN(UNIT=1, FILE='mplot.in', STATUS='OLD', FORM='FORMATTED',     GETF0019
     &     ACCESS='SEQUENTIAL',                                         GETF0020
CVAX     -     CARRIAGECONTROL = 'LIST', READONLY,                      GETF0021
     &     ERR=900)                                                     GETF0022
                                                                        GETF0023
C---- Read through the file                                             GETF0024
 100  CONTINUE                                                          GETF0025
                                                                        GETF0026
C----     Read in the next filename                                     GETF0027
          READ(1,120,END=500,ERR=902) FNAME                             GETF0028
 120      FORMAT(A)                                                     GETF0029
          IF (FNAME(1:1).EQ.' ') GO TO 100                              GETF0030
                                                                        GETF0031
C----     Initialise variables for extraction of filename               GETF0032
          IEND = 80                                                     GETF0033
          IPOS = 0                                                      GETF0034
          FOUND = .FALSE.                                               GETF0035
                                                                        GETF0036
C----     Search the line for end of filename                           GETF0037
 200      CONTINUE                                                      GETF0038
              IPOS = IPOS + 1                                           GETF0039
              IF (FNAME(IPOS:IPOS).EQ.' ') THEN                         GETF0040
                  FOUND = .TRUE.                                        GETF0041
                  IEND = IPOS - 1                                       GETF0042
              ENDIF                                                     GETF0043
          IF (.NOT.FOUND .AND. IPOS.LT.IEND) GO TO 200                  GETF0044
                                                                        GETF0045
C----     If have located the filename, add extension and store         GETF0046
          IF (FOUND) THEN                                               GETF0047
              PDBFIL = FNAME(1:IEND)                                    GETF0048
              CALL GETNAM(PDBFIL,ISTART,IEND,IFAIL)                     GETF0049
              IF (IFAIL) GO TO 999                                      GETF0050
                                                                        GETF0051
C----         Form full filename                                        GETF0052
              NFILE = NFILE + 1                                         GETF0053
              IF (NFILE.GT.MXFILE) GO TO 908                            GETF0054
              FILRIN(NFILE) = PDBFIL(ISTART:IEND) // '.rin'             GETF0055
                                                                        GETF0056
C----         Store identifying code                                    GETF0057
              LENID(NFILE) = IEND - ISTART + 1                          GETF0058
              IF (LENID(NFILE).GT.MXLEND) THEN                          GETF0059
                  LENID(NFILE) = MXLEND                                 GETF0060
                  FILID(NFILE) = PDBFIL(IEND - MXLEND + 1:IEND)         GETF0061
              ELSE                                                      GETF0062
                  FILID(NFILE) = PDBFIL(ISTART:IEND)                    GETF0063
              ENDIF                                                     GETF0064
          ENDIF                                                         GETF0065
      GO TO 100                                                         GETF0066
                                                                        GETF0067
C---- Close the mplot.in file                                           GETF0068
 500  CONTINUE                                                          GETF0069
      CLOSE(1)                                                          GETF0070
      IF (NFILE.EQ.0) GO TO 910                                         GETF0071
CHECK v.3.4-->                                                          GETF0072
      NMODEL = NFILE                                                    GETF0073
      TOPMOD = NFILE                                                    GETF0074
CHECK v.3.4<--                                                          GETF0075
                                                                        GETF0076
      GO TO 999                                                         GETF0077
                                                                        GETF0078
C---- Fatal errors                                                      GETF0079
 900  CONTINUE                                                          GETF0080
      PRINT*, '**** Unable to open input file, mplot.in'                GETF0081
      GO TO 990                                                         GETF0082
                                                                        GETF0083
 902  CONTINUE                                                          GETF0084
      PRINT*, '**** File error reading file mplot.in at line',          GETF0085
     &    NFILE + 1                                                     GETF0086
      GO TO 990                                                         GETF0087
                                                                        GETF0088
 908  CONTINUE                                                          GETF0089
      PRINT*, '**** Maximum number of files exceeded. Amend parameter ',GETF0090
     &    'MXFILE =', MXFILE                                            GETF0091
      GO TO 990                                                         GETF0092
                                                                        GETF0093
 910  CONTINUE                                                          GETF0094
      PRINT*, 'No files found in mplot.in list'                         GETF0095
      GO TO 990                                                         GETF0096
                                                                        GETF0097
 990  CONTINUE                                                          GETF0098
      IFAIL = .TRUE.                                                    GETF0099
                                                                        GETF0100
 999  CONTINUE                                                          GETF0101
      RETURN                                                            GETF0102
      END                                                               GETF0103
                                                                        GETF0104
      SUBROUTINE PARAMS                                                 PARA0001
C-----------------------------------------------------------------------PARA0002
CHECK v.3.2<--                                                          PARA0003
C                                                                       PARA0004
C  SUBROUTINE PARAMS  -  Read in program parameters from parameter file PARA0005
C                                                                       PARA0006
C----------------------------------------------------------------------+PARA0007
                                                                        PARA0008
      INCLUDE 'tplot.inc'                                               PARA0009
                                                                        PARA0010
      CHARACTER*1   YESNO                                               PARA0011
CHECK v.3.2-->                                                          PARA0012
CHECK v.3.4-->                                                          PARA0013
C      CHARACTER*80  FNAME                                              PARA0014
      CHARACTER*80  FNAME, IREC                                         PARA0015
CHECK v.3.4<--                                                          PARA0016
CHECK v.3.2<--                                                          PARA0017
      INTEGER       I, ICOL, INUMB, LINE                                PARA0018
CHECK v.3.4-->                                                          PARA0019
C      LOGICAL       ALLCOL, FINERR                                     PARA0020
      LOGICAL       ALLCOL, ENDCOL, FINERR                              PARA0021
CHECK v.3.4<--                                                          PARA0022
      REAL          RNUMB                                               PARA0023
                                                                        PARA0024
C---- Open parameter file                                               PARA0025
CHECK v.3.1-->                                                          PARA0026
C      OPEN(UNIT=1, FILE='procheck.prm', STATUS='OLD',                  PARA0027
CHECK v.3.2-->                                                          PARA0028
C      OPEN(UNIT=10, FILE='procheck.prm', STATUS='OLD',                 PARA0029
      IF (NMR) THEN                                                     PARA0030
          FNAME = 'procheck_nmr.prm'                                    PARA0031
      ELSE IF (ENSEMB) THEN                                             PARA0032
          FNAME = 'procheck_comp.prm'                                   PARA0033
      ELSE                                                              PARA0034
          FNAME = 'procheck.prm'                                        PARA0035
      ENDIF                                                             PARA0036
      OPEN(UNIT=10, FILE=FNAME, STATUS='OLD',                           PARA0037
CHECK v.3.2<--                                                          PARA0038
CHECK v.3.1<--                                                          PARA0039
     &     FORM='FORMATTED', ACCESS='SEQUENTIAL',                       PARA0040
CVAX     -     CARRIAGECONTROL = 'LIST', READONLY,                      PARA0041
     &     ERR=900)                                                     PARA0042
      FINERR = .FALSE.                                                  PARA0043
      LINE = 0                                                          PARA0044
                                                                        PARA0045
C---- Read in the parameters                                            PARA0046
                                                                        PARA0047
C---- Check that have the right version number in the parameter file    PARA0048
CHECK v.3.2-->                                                          PARA0049
C      CALL FINKEY('PROCHECK v.3.0',14,LINE,FINERR)                     PARA0050
      IF (NMR) THEN                                                     PARA0051
CHECK v.3.4-->                                                          PARA0052
C          CALL FINKEY('PROCHECK-NMR. PROCHECK v.3.3',28,LINE,FINERR)   PARA0053
C      ELSE IF (ENSEMB) THEN                                            PARA0054
C          CALL FINKEY('PROCHECK-COMP. PROCHECK v.3.3',29,LINE,FINERR)  PARA0055
          CALL FINKEY('PROCHECK-NMR. PROCHECK v.3.4',28,LINE,FINERR)    PARA0056
      ELSE IF (ENSEMB) THEN                                             PARA0057
          CALL FINKEY('PROCHECK-COMP. PROCHECK v.3.4',29,LINE,FINERR)   PARA0058
CHECK v.3.4<--                                                          PARA0059
      ELSE                                                              PARA0060
          CALL FINKEY('PROCHECK v.3.3',14,LINE,FINERR)                  PARA0061
          IF (FINERR) THEN                                              PARA0062
              CALL FINKEY('PROCHECK v.3',12,LINE,FINERR)                PARA0063
              IF (FINERR) THEN                                          PARA0064
                  GO TO 901                                             PARA0065
              ELSE                                                      PARA0066
                  PRINT*, '* Warning. Parameter file not up-to-date'    PARA0067
                  PRINT*, '*          Defaults will be used for',       PARA0068
     &                ' missing items'                                  PARA0069
              ENDIF                                                     PARA0070
          ENDIF                                                         PARA0071
      ENDIF                                                             PARA0072
CHECK v.3.2<--                                                          PARA0073
      IF (FINERR) GO TO 901                                             PARA0074
                                                                        PARA0075
C---- Find the colours key-word                                         PARA0076
      CALL FINKEY('Colours',7,LINE,FINERR)                              PARA0077
      IF (FINERR) GO TO 990                                             PARA0078
                                                                        PARA0079
C---- Read in all the RGB colours and corresponding colour names        PARA0080
CHECK v.3.4-->                                                          PARA0081
C      DO 100, ICOL = 1, MXCOLR                                         PARA0082
C          LINE = LINE + 1                                              PARA0083
CCHECK v.3.1-->                                                         PARA0084
CC          READ(1,*,END=902,ERR=904) (RGB(I, ICOL), I = 1, 3),         PARA0085
C          READ(10,*,END=902,ERR=904) (RGB(I, ICOL), I = 1, 3),         PARA0086
CCHECK v.3.1<--                                                         PARA0087
C     -        COLNAM(ICOL)                                             PARA0088
C 100  CONTINUE                                                         PARA0089
      ENDCOL = .FALSE.                                                  PARA0090
      NCOLOR = MXCOLR                                                   PARA0091
      DO 100, ICOL = 1, MXCOLR                                          PARA0092
          IF (.NOT.ENDCOL) THEN                                         PARA0093
              LINE = LINE + 1                                           PARA0094
              READ(10,20,END=902,ERR=904) IREC                          PARA0095
 20           FORMAT(A)                                                 PARA0096
              IF (IREC.EQ.' ') THEN                                     PARA0097
                  ENDCOL = .TRUE.                                       PARA0098
              ELSE                                                      PARA0099
                  READ(IREC,*,ERR=904) (RGB(I,ICOL), I = 1, 3),         PARA0100
     &                COLNAM(ICOL)                                      PARA0101
                  NCOLOR = ICOL                                         PARA0102
              ENDIF                                                     PARA0103
          ENDIF                                                         PARA0104
                                                                        PARA0105
C----     If have reached end of colours then insert default            PARA0106
          IF (ENDCOL) THEN                                              PARA0107
              RGB(1,ICOL) = 0.0                                         PARA0108
              RGB(2,ICOL) = 0.0                                         PARA0109
              RGB(3,ICOL) = 0.0                                         PARA0110
              COLNAM(ICOL) = 'WHITE'                                    PARA0111
          ENDIF                                                         PARA0112
 100  CONTINUE                                                          PARA0113
CHECK v.3.4<--                                                          PARA0114
                                                                        PARA0115
C---- Determine whether all plots are to be in colour                   PARA0116
                                                                        PARA0117
C---- Find the colour-all-plots keywords                                PARA0118
      CALL FINKEY('Colour all plots?',17,LINE,FINERR)                   PARA0119
      IF (FINERR) GO TO 990                                             PARA0120
                                                                        PARA0121
C---- Determine whether all plots are to be in colour                   PARA0122
      LINE = LINE + 1                                                   PARA0123
CHECK v.3.1-->                                                          PARA0124
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0125
      READ(10,120,END=902,ERR=904) YESNO                                PARA0126
CHECK v.3.1<--                                                          PARA0127
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0128
          ALLCOL = .TRUE.                                               PARA0129
      ELSE                                                              PARA0130
          ALLCOL = .FALSE.                                              PARA0131
      ENDIF                                                             PARA0132
                                                                        PARA0133
C---- Determine which plots are to be produced                          PARA0134
                                                                        PARA0135
C---- Find the "Which plots" keyword                                    PARA0136
CHECK v.3.4-->                                                          PARA0137
C      CALL FINKEY('Which plots',11,LINE,FINERR)                        PARA0138
      IF (NMR) THEN                                                     PARA0139
          CALL FINKEY('a. Geometry plots',17,LINE,FINERR)               PARA0140
      ELSE                                                              PARA0141
          CALL FINKEY('Which plots',11,LINE,FINERR)                     PARA0142
      ENDIF                                                             PARA0143
CHECK v.3.4<--                                                          PARA0144
      IF (FINERR) GO TO 990                                             PARA0145
                                                                        PARA0146
C---- 1. Produce the main Ramachandran plot (Y/N)                       PARA0147
      LINE = LINE + 1                                                   PARA0148
CHECK v.3.1-->                                                          PARA0149
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0150
      READ(10,120,END=902,ERR=904) YESNO                                PARA0151
CHECK v.3.1<--                                                          PARA0152
 120  FORMAT(A)                                                         PARA0153
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0154
          PLOTRM = .TRUE.                                               PARA0155
      ELSE                                                              PARA0156
          PLOTRM = .FALSE.                                              PARA0157
      ENDIF                                                             PARA0158
                                                                        PARA0159
C---- 2. Plot the Gly & Pro Ramachandran plots? (Y/N)                   PARA0160
      LINE = LINE + 1                                                   PARA0161
CHECK v.3.1-->                                                          PARA0162
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0163
      READ(10,120,END=902,ERR=904) YESNO                                PARA0164
CHECK v.3.1<--                                                          PARA0165
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0166
          DOPLOT(1) = .TRUE.                                            PARA0167
      ELSE                                                              PARA0168
          DOPLOT(1) = .FALSE.                                           PARA0169
      ENDIF                                                             PARA0170
                                                                        PARA0171
C---- 3. Plot the chi1-chi2 plots? (Y/N)                                PARA0172
      LINE = LINE + 1                                                   PARA0173
CHECK v.3.1<--                                                          PARA0174
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0175
      READ(10,120,END=902,ERR=904) YESNO                                PARA0176
CHECK v.3.1-->                                                          PARA0177
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0178
          DOPLOT(2) = .TRUE.                                            PARA0179
      ELSE                                                              PARA0180
          DOPLOT(2) = .FALSE.                                           PARA0181
      ENDIF                                                             PARA0182
                                                                        PARA0183
C---- Read in the plot parameters                                       PARA0184
                                                                        PARA0185
C---- Find the Ramachandran plot key-word                               PARA0186
      CALL FINKEY('1. Ramachandran plot',20,LINE,FINERR)                PARA0187
      IF (FINERR) GO TO 990                                             PARA0188
                                                                        PARA0189
C---- Ramachandran plot options                                         PARA0190
CHECK v.3.4-->                                                          PARA0191
      RMSPLT = .FALSE.                                                  PARA0192
CHECK v.3.4<--                                                          PARA0193
                                                                        PARA0194
CHECK v.3.3-->                                                          PARA0195
C---- Show the Ramachandran plots on separate pages                     PARA0196
      IF (NMR .OR. ENSEMB) THEN                                         PARA0197
          LINE = LINE + 1                                               PARA0198
          READ(10,120,END=902,ERR=904) YESNO                            PARA0199
          IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                      PARA0200
              RMSPLT = .TRUE.                                           PARA0201
          ELSE                                                          PARA0202
              RMSPLT = .FALSE.                                          PARA0203
          ENDIF                                                         PARA0204
      ENDIF                                                             PARA0205
                                                                        PARA0206
C---- If not splitting Ramachandrans, then just use standard subheading PARA0207
C     for the Ramachandran plot                                         PARA0208
      IF (.NOT.RMSPLT) THEN                                             PARA0209
          RAMHED = BRCODE                                               PARA0210
          RLEN = BLEN                                                   PARA0211
      ENDIF                                                             PARA0212
CHECK v.3.3<--                                                          PARA0213
                                                                        PARA0214
C---- Shade in the regions of the Ramachandran plot (Y/N)               PARA0215
      LINE = LINE + 1                                                   PARA0216
CHECK v.3.1-->                                                          PARA0217
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0218
      READ(10,120,END=902,ERR=904) YESNO                                PARA0219
CHECK v.3.1<--                                                          PARA0220
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0221
          NOSHAD = .FALSE.                                              PARA0222
      ELSE                                                              PARA0223
          NOSHAD = .TRUE.                                               PARA0224
      ENDIF                                                             PARA0225
                                                                        PARA0226
C---- Print letter-codes in the regions of the Ramachandran plot (Y/N)  PARA0227
      LINE = LINE + 1                                                   PARA0228
CHECK v.3.1-->                                                          PARA0229
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0230
      READ(10,120,END=902,ERR=904) YESNO                                PARA0231
CHECK v.3.1<--                                                          PARA0232
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0233
          INCLET = .TRUE.                                               PARA0234
      ELSE                                                              PARA0235
          INCLET = .FALSE.                                              PARA0236
      ENDIF                                                             PARA0237
                                                                        PARA0238
C---- Draw borders round the regions of the Ramachandran plot (Y/N)     PARA0239
      LINE = LINE + 1                                                   PARA0240
CHECK v.3.1-->                                                          PARA0241
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0242
      READ(10,120,END=902,ERR=904) YESNO                                PARA0243
CHECK v.3.1<--                                                          PARA0244
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0245
          NOLINE = .FALSE.                                              PARA0246
      ELSE                                                              PARA0247
          NOLINE = .TRUE.                                               PARA0248
      ENDIF                                                             PARA0249
                                                                        PARA0250
C---- Show core region of Ramachandran plot only (Y/N)                  PARA0251
      LINE = LINE + 1                                                   PARA0252
CHECK v.3.1-->                                                          PARA0253
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0254
      READ(10,120,END=902,ERR=904) YESNO                                PARA0255
CHECK v.3.1<--                                                          PARA0256
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0257
          CRONLY = .TRUE.                                               PARA0258
      ELSE                                                              PARA0259
          CRONLY = .FALSE.                                              PARA0260
      ENDIF                                                             PARA0261
                                                                        PARA0262
C---- Which points are to be labelled on Ramachandran plot: (0 = disalloPARA0263
C     1 = generous, 2 = allowed, 3 = core)                              PARA0264
      LINE = LINE + 1                                                   PARA0265
CHECK v.3.1-->                                                          PARA0266
C      READ(1,*,END=902,ERR=904) INUMB                                  PARA0267
      READ(10,*,END=902,ERR=904) INUMB                                  PARA0268
CHECK v.3.1<--                                                          PARA0269
      LABRES = INUMB                                                    PARA0270
                                                                        PARA0271
CHECK v.3.4-->                                                          PARA0272
C---- Read in new parameters specific to ensemble plots                 PARA0273
      IF (NMR .OR. ENSEMB) THEN                                         PARA0274
                                                                        PARA0275
C----     Get size of data points (0.0-2.0)                             PARA0276
          LINE = LINE + 1                                               PARA0277
          READ(10,*,END=902,ERR=904) RNUMB                              PARA0278
          RBXSIZ = RNUMB                                                PARA0279
          IF (RBXSIZ.LT.0.0) RBXSIZ = 0.0                               PARA0280
          IF (RBXSIZ.GT.2.0) RBXSIZ = 2.0                               PARA0281
                                                                        PARA0282
C----     Fill in the data points (Y/N)                                 PARA0283
          LINE = LINE + 1                                               PARA0284
          READ(10,120,END=902,ERR=904) YESNO                            PARA0285
          IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                      PARA0286
              RBXFIL = .TRUE.                                           PARA0287
          ELSE                                                          PARA0288
              RBXFIL = .FALSE.                                          PARA0289
          ENDIF                                                         PARA0290
                                                                        PARA0291
C----     Show model numbers inside the data points (Y/N)               PARA0292
          LINE = LINE + 1                                               PARA0293
          READ(10,120,END=902,ERR=904) YESNO                            PARA0294
          IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                      PARA0295
              RBXMOD = .TRUE.                                           PARA0296
          ELSE                                                          PARA0297
              RBXMOD = .FALSE.                                          PARA0298
          ENDIF                                                         PARA0299
      ENDIF                                                             PARA0300
CHECK v.3.4<--                                                          PARA0301
                                                                        PARA0302
C---- Produce a black-and-white or colour PostScript file               PARA0303
      LINE = LINE + 1                                                   PARA0304
CHECK v.3.1-->                                                          PARA0305
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0306
      READ(10,120,END=902,ERR=904) YESNO                                PARA0307
CHECK v.3.1<--                                                          PARA0308
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0309
          INCOLR = .TRUE.                                               PARA0310
      ELSE                                                              PARA0311
          INCOLR = .FALSE.                                              PARA0312
      ENDIF                                                             PARA0313
                                                                        PARA0314
C---- Get each of the user-defined colours for this plot                PARA0315
      DO 200, ICOL = 1, 7                                               PARA0316
          CALL GETCOL(COLRAM(ICOL),LINE,COLNAM,MXCOLR)                  PARA0317
 200  CONTINUE                                                          PARA0318
                                                                        PARA0319
C---- Gly & Pro Ramachandran plots                                      PARA0320
                                                                        PARA0321
C---- Find the Gly & Pro Ramachandran plots key-word                    PARA0322
      CALL FINKEY('2. Gly & Pro',12,LINE,FINERR)                        PARA0323
      IF (FINERR) GO TO 990                                             PARA0324
                                                                        PARA0325
C---- Cutoff value for labelling of residues on the plots               PARA0326
      LINE = LINE + 1                                                   PARA0327
CHECK v.3.1-->                                                          PARA0328
C      READ(1,*,END=902,ERR=904) RNUMB                                  PARA0329
      READ(10,*,END=902,ERR=904) RNUMB                                  PARA0330
CHECK v.3.1<--                                                          PARA0331
      LIMGP = RNUMB                                                     PARA0332
      IF (LIMGP.LT.-9.9) LIMGP = -9.9                                   PARA0333
      IF (LIMGP.GT.99.9) LIMGP = 99.9                                   PARA0334
                                                                        PARA0335
C---- Plot all 20 Ramachandran plots or just the Gly & Pro              PARA0336
      LINE = LINE + 1                                                   PARA0337
CHECK v.3.1-->                                                          PARA0338
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0339
      READ(10,120,END=902,ERR=904) YESNO                                PARA0340
CHECK v.3.1<--                                                          PARA0341
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0342
          ALLRAM = .TRUE.                                               PARA0343
      ELSE                                                              PARA0344
          ALLRAM = .FALSE.                                              PARA0345
      ENDIF                                                             PARA0346
                                                                        PARA0347
C---- Produce a black-and-white or colour PostScript file               PARA0348
      LINE = LINE + 1                                                   PARA0349
CHECK v.3.1-->                                                          PARA0350
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0351
      READ(10,120,END=902,ERR=904) YESNO                                PARA0352
CHECK v.3.1<--                                                          PARA0353
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0354
          INCOLG = .TRUE.                                               PARA0355
      ELSE                                                              PARA0356
          INCOLG = .FALSE.                                              PARA0357
      ENDIF                                                             PARA0358
                                                                        PARA0359
C---- Get each of the user-defined colours for this plot                PARA0360
      DO 300, ICOL = 1, 5                                               PARA0361
          CALL GETCOL(COLRGP(ICOL),LINE,COLNAM,MXCOLR)                  PARA0362
 300  CONTINUE                                                          PARA0363
                                                                        PARA0364
C---- Chi1-Chi2 plots                                                   PARA0365
                                                                        PARA0366
C---- Find the Chi1-Chi2 plots key-word                                 PARA0367
      CALL FINKEY('3. Chi1-Chi2 plots',18,LINE,FINERR)                  PARA0368
      IF (FINERR) GO TO 990                                             PARA0369
                                                                        PARA0370
C---- Cutoff value for labelling of residues on the plots               PARA0371
      LINE = LINE + 1                                                   PARA0372
CHECK v.3.1-->                                                          PARA0373
C      READ(1,*,END=902,ERR=904) RNUMB                                  PARA0374
      READ(10,*,END=902,ERR=904) RNUMB                                  PARA0375
CHECK v.3.1<--                                                          PARA0376
      LIMCHI = RNUMB                                                    PARA0377
      IF (LIMCHI.LT.-9.9) LIMCHI = -9.9                                 PARA0378
      IF (LIMCHI.GT.99.9) LIMCHI = 99.9                                 PARA0379
                                                                        PARA0380
C---- Produce a black-and-white or colour PostScript file               PARA0381
      LINE = LINE + 1                                                   PARA0382
CHECK v.3.1-->                                                          PARA0383
C      READ(1,120,END=902,ERR=904) YESNO                                PARA0384
      READ(10,120,END=902,ERR=904) YESNO                                PARA0385
CHECK v.3.1<--                                                          PARA0386
      IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                          PARA0387
          INCOLC = .TRUE.                                               PARA0388
      ELSE                                                              PARA0389
          INCOLC = .FALSE.                                              PARA0390
      ENDIF                                                             PARA0391
                                                                        PARA0392
C---- Get each of the user-defined colours for this plot                PARA0393
      DO 400, ICOL = 1, 5                                               PARA0394
          CALL GETCOL(COLCHI(ICOL),LINE,COLNAM,MXCOLR)                  PARA0395
 400  CONTINUE                                                          PARA0396
                                                                        PARA0397
C---- Find G-factor parameters                                          PARA0398
CHECK v.3.2-->                                                          PARA0399
      IF (.NOT.NMR .AND. .NOT.ENSEMB) THEN                              PARA0400
CHECK v.3.2<--                                                          PARA0401
          CALL FINKEY('G-factors',9,LINE,FINERR)                        PARA0402
          IF (FINERR) GO TO 990                                         PARA0403
                                                                        PARA0404
C----     See whether Engh & Huber means to be used for G-factor        PARA0405
C         calculations                                                  PARA0406
          LINE = LINE + 1                                               PARA0407
CHECK v.3.1-->                                                          PARA0408
C          READ(1,120,END=902,ERR=904) YESNO                            PARA0409
          READ(10,120,END=902,ERR=904) YESNO                            PARA0410
CHECK v.3.1<--                                                          PARA0411
          IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                      PARA0412
              USENGH = .TRUE.                                           PARA0413
          ELSE                                                          PARA0414
              USENGH = .FALSE.                                          PARA0415
          ENDIF                                                         PARA0416
CHECK v.3.2-->                                                          PARA0417
      ENDIF                                                             PARA0418
CHECK v.3.2<--                                                          PARA0419
                                                                        PARA0420
CHECK v.3.2-->                                                          PARA0421
C---- Find whether file-handles are required or not                     PARA0422
      CALL FINKEY('File-handles',12,LINE,FINERR)                        PARA0423
      IF (.NOT.FINERR) THEN                                             PARA0424
                                                                        PARA0425
C----     See whether the file-handle is required                       PARA0426
          LINE = LINE + 1                                               PARA0427
          READ(10,120,END=902,ERR=904) YESNO                            PARA0428
          IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                      PARA0429
              WITHAN = .TRUE.                                           PARA0430
          ELSE                                                          PARA0431
              WITHAN = .FALSE.                                          PARA0432
          ENDIF                                                         PARA0433
                                                                        PARA0434
C----     See whether plot filename to be printed on the plot itself    PARA0435
          LINE = LINE + 1                                               PARA0436
          READ(10,*,END=902,ERR=904)                                    PARA0437
          LINE = LINE + 1                                               PARA0438
          READ(10,120,END=902,ERR=904) YESNO                            PARA0439
          IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                      PARA0440
              PLABEL = .TRUE.                                           PARA0441
          ELSE                                                          PARA0442
              PLABEL = .FALSE.                                          PARA0443
          ENDIF                                                         PARA0444
                                                                        PARA0445
C----     See whether all pages of same plot to be combined in one      PARA0446
C         paginated PostScript file                                     PARA0447
          LINE = LINE + 1                                               PARA0448
          READ(10,120,END=902,ERR=904) YESNO                            PARA0449
          IF (YESNO.EQ.'Y' .OR. YESNO.EQ.'y') THEN                      PARA0450
              COMBPS = .TRUE.                                           PARA0451
          ELSE                                                          PARA0452
              COMBPS = .FALSE.                                          PARA0453
          ENDIF                                                         PARA0454
      ENDIF                                                             PARA0455
CHECK v.3.2<--                                                          PARA0456
                                                                        PARA0457
C---- If all plots are required to be in colour, then set all the       PARA0458
C     appropriate flags to TRUE                                         PARA0459
      IF (ALLCOL) THEN                                                  PARA0460
          INCOLR = .TRUE.                                               PARA0461
          INCOLC = .TRUE.                                               PARA0462
          INCOLG = .TRUE.                                               PARA0463
      ENDIF                                                             PARA0464
                                                                        PARA0465
      GO TO 999                                                         PARA0466
                                                                        PARA0467
                                                                        PARA0468
C---- Errors reading parameter file                                     PARA0469
900   CONTINUE                                                          PARA0470
CHECK v.3.2-->                                                          PARA0471
C      PRINT*, '*** ERROR Parameters file (procheck.prm) not found.'    PARA0472
      IF (NMR) THEN                                                     PARA0473
          PRINT*, '*** ERROR Parameters file (procheck_nmr.prm) not',   PARA0474
     &        ' found.'                                                 PARA0475
      ELSE IF (ENSEMB) THEN                                             PARA0476
          PRINT*, '*** ERROR Parameters file (procheck_comp.prm) not',  PARA0477
     &        ' found.'                                                 PARA0478
      ELSE                                                              PARA0479
          PRINT*, '*** ERROR Parameters file (procheck.prm) not found.' PARA0480
      ENDIF                                                             PARA0481
CHECK v.3.2<--                                                          PARA0482
      GO TO 990                                                         PARA0483
                                                                        PARA0484
 901  CONTINUE                                                          PARA0485
CHECK v.3.2-->                                                          PARA0486
C       PRINT*, '*** Failed to find correct version number in ',        PARA0487
C     -        'parameters file, procheck.prm'                          PARA0488
      IF (NMR) THEN                                                     PARA0489
CHECK v.3.4-->                                                          PARA0490
C          PRINT*, '*** Failed to find correct version number in ',     PARA0491
C     -            'parameters file, procheck_nmr.prm'                  PARA0492
C      ELSE IF (ENSEMB) THEN                                            PARA0493
C          PRINT*, '*** Failed to find correct version number in ',     PARA0494
C     -            'parameters file, procheck_comp.prm'                 PARA0495
C      ELSE                                                             PARA0496
C          PRINT*, '*** Failed to find correct version number in ',     PARA0497
C     -            'parameters file, procheck.prm'                      PARA0498
          PRINT*, '*** Old version of parameter file, ',                PARA0499
     &            'procheck_nmr.prm, found'                             PARA0500
      ELSE IF (ENSEMB) THEN                                             PARA0501
          PRINT*, '*** Old version of parameter file, ',                PARA0502
     &            'procheck_comp.prm, found'                            PARA0503
      ELSE                                                              PARA0504
          PRINT*, '*** Old version of parameter file, ',                PARA0505
     &            'procheck.prm, found'                                 PARA0506
      ENDIF                                                             PARA0507
      PRINT*, '*** Please delete the file and re-run the program'       PARA0508
      PRINT*, '*** ---------------------------------------------'       PARA0509
CHECK v.3.4<--                                                          PARA0510
CHECK v.3.2<--                                                          PARA0511
      GO TO 990                                                         PARA0512
                                                                        PARA0513
902   CONTINUE                                                          PARA0514
CHECK v.3.2-->                                                          PARA0515
C      PRINT*, '*** Premature end of parameters file, procheck.prm, ',  PARA0516
C     -        'encountered at line', LINE                              PARA0517
      IF (NMR) THEN                                                     PARA0518
          PRINT*, '*** Premature end of parameters file, procheck_nmr', PARA0519
     &            '.prm, encountered at line', LINE                     PARA0520
      ELSE IF (ENSEMB) THEN                                             PARA0521
          PRINT*, '*** Premature end of parameters file, procheck_comp',PARA0522
     &            '.prm, encountered at line', LINE                     PARA0523
      ELSE                                                              PARA0524
          PRINT*, '*** Premature end of parameters file, procheck',     PARA0525
     &            '.prm, encountered at line', LINE                     PARA0526
      ENDIF                                                             PARA0527
CHECK v.3.2<--                                                          PARA0528
CHECK v.3.4-->                                                          PARA0529
      PRINT*, '*** Please delete the file and re-run the program'       PARA0530
      PRINT*, '*** ---------------------------------------------'       PARA0531
CHECK v.3.4<--                                                          PARA0532
      GO TO 990                                                         PARA0533
                                                                        PARA0534
904   CONTINUE                                                          PARA0535
CHECK v.3.2-->                                                          PARA0536
C      PRINT*, '*** Error reading parameter file, procheck.prm, at',    PARA0537
C     -    ' line', LINE                                                PARA0538
      IF (NMR) THEN                                                     PARA0539
          PRINT*, '*** Error reading parameter file, procheck_nmr.prm', PARA0540
     &        ', at line', LINE                                         PARA0541
      ELSE IF (ENSEMB) THEN                                             PARA0542
          PRINT*, '*** Error reading parameter file, procheck_comp.prm',PARA0543
     &        ', at line', LINE                                         PARA0544
      ELSE                                                              PARA0545
          PRINT*, '*** Error reading parameter file, procheck.prm, at', PARA0546
     &        ' line', LINE                                             PARA0547
      ENDIF                                                             PARA0548
CHECK v.3.2<--                                                          PARA0549
CHECK v.3.4-->                                                          PARA0550
      PRINT*, '*** Please delete the file and re-run the program'       PARA0551
      PRINT*, '*** ---------------------------------------------'       PARA0552
CHECK v.3.4<--                                                          PARA0553
      GO TO 990                                                         PARA0554
                                                                        PARA0555
C---- Close the parameter file                                          PARA0556
 990  CONTINUE                                                          PARA0557
      IFAIL = .TRUE.                                                    PARA0558
                                                                        PARA0559
999   CONTINUE                                                          PARA0560
      RETURN                                                            PARA0561
      END                                                               PARA0562
                                                                        PARA0563
      SUBROUTINE NORMGS                                                 NORM0001
C-----------------------------------------------------------------------NORM0002
C                                                                       NORM0003
C  SUBROUTINE NORMGS  -  Calculate the normalization factors for the    NORM0004
C                        Gaussian distributions used for the bond lengthNORM0005
C                        and bond angles                                NORM0006
C                                                                       NORM0007
C----------------------------------------------------------------------+NORM0008
                                                                        NORM0009
      INCLUDE 'tplot.inc'                                               NORM0010
                                                                        NORM0011
      REAL          MAXSTD                                              NORM0012
      PARAMETER    (MAXSTD = 6.0)                                       NORM0013
                                                                        NORM0014
      INTEGER       ISTEP, NSTEPS                                       NORM0015
      REAL          AVSCOR, CALCOV, COUNT, PROBAB, RSCORE, STDEV,       NORM0016
     &              TCOUNT, TOTAV2                                      NORM0017
                                                                        NORM0018
C---- Calculate number of steps required                                NORM0019
      AVSCOR = 0.0                                                      NORM0020
      NSTEPS = 2.0 * MAXSTD / GSTEP + 1                                 NORM0021
      STDEV = -MAXSTD + GSTEP / 2.0                                     NORM0022
      TCOUNT = 0.0                                                      NORM0023
      TOTAV2 = 0.0                                                      NORM0024
                                                                        NORM0025
C---- Loop for the required number of steps                             NORM0026
      DO 500, ISTEP = 1, NSTEPS                                         NORM0027
          RSCORE = CALCOV(STDEV,GSTEP)                                  NORM0028
          PROBAB = EXP(RSCORE)                                          NORM0029
          COUNT = 1000.0 * PROBAB                                       NORM0030
          AVSCOR = AVSCOR + RSCORE * COUNT                              NORM0031
          TCOUNT = TCOUNT + COUNT                                       NORM0032
          TOTAV2 = TOTAV2 + RSCORE * RSCORE * COUNT                     NORM0033
                                                                        NORM0034
C----     Increment value of standard deviation                         NORM0035
          STDEV = STDEV + GSTEP                                         NORM0036
 500  CONTINUE                                                          NORM0037
                                                                        NORM0038
C---- Calculate average score and standard deviation                    NORM0039
      AVSCOR = AVSCOR / TCOUNT                                          NORM0040
      TOTAV2 = TOTAV2 / TCOUNT                                          NORM0041
      STDEV = SQRT(TOTAV2 - AVSCOR * AVSCOR)                            NORM0042
      GAUMEA = AVSCOR                                                   NORM0043
      GAUSTD = STDEV                                                    NORM0044
                                                                        NORM0045
      RETURN                                                            NORM0046
      END                                                               NORM0047
                                                                        NORM0048
      SUBROUTINE GETDAT(DISTRB)                                         GETD0001
C-----------------------------------------------------------------------GETD0002
C                                                                       GETD0003
C  SUBROUTINE GETDAT  -  Read in the torsion angle distributions        GETD0004
C                                                                       GETD0005
C----------------------------------------------------------------------+GETD0006
                                                                        GETD0007
      INCLUDE 'tplot.inc'                                               GETD0008
                                                                        GETD0009
      CHARACTER*1   CH                                                  GETD0010
      CHARACTER*10  CNUMB, RNUMB                                        GETD0011
      CHARACTER*52  LETTER                                              GETD0012
      CHARACTER*80  IREC                                                GETD0013
      INTEGER       IAMINO, ICELL, ILOOP, IDISTR, IPOS, ISTATE, IVALUE, GETD0014
     &              JCELL, LINE, LVALUE, NPOS, NVALUE, NZERO, DISTRB    GETD0015
      LOGICAL       ENDFIL, GOTLET, GOTNUM, INEW, INORM, UPDATE         GETD0016
      REAL          MEAN, STDEV                                         GETD0017
CTESTING                                                                GETD0018
C      INTEGER       IARRAY(NCELL*NCELL)                                GETD0019
C      REAL          ANGLE, ASTEP                                       GETD0020
CTESTING                                                                GETD0021
                                                                        GETD0022
      DATA LETTER( 1:26) / 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/                GETD0023
      DATA LETTER(27:52) / 'abcdefghijklmnopqrstuvwxyz'/                GETD0024
                                                                        GETD0025
C---- Rewind the compressed distributions file, procheck.dat            GETD0026
      REWIND(2)                                                         GETD0027
                                                                        GETD0028
C---- Initialise variables                                              GETD0029
      IDISTR = 0                                                        GETD0030
      LINE = 0                                                          GETD0031
      TWODEE = .FALSE.                                                  GETD0032
      IF (DISTRB.EQ.1) THEN                                             GETD0033
          VALBEG(1) = -180.0                                            GETD0034
          VALBEG(2) = -180.0                                            GETD0035
          VALEND(1) =  180.0                                            GETD0036
          VALEND(2) =  180.0                                            GETD0037
          TWODEE = .TRUE.                                               GETD0038
      ELSE IF (DISTRB.EQ.2) THEN                                        GETD0039
          VALBEG(1) =    0.0                                            GETD0040
          VALBEG(2) =    0.0                                            GETD0041
          VALEND(1) =  360.0                                            GETD0042
          VALEND(2) =  360.0                                            GETD0043
          TWODEE = .TRUE.                                               GETD0044
      ELSE IF (DISTRB.EQ.3) THEN                                        GETD0045
          VALBEG(1) =    0.0                                            GETD0046
          VALEND(1) =  360.0                                            GETD0047
      ELSE IF (DISTRB.EQ.4) THEN                                        GETD0048
          VALBEG(1) =    0.0                                            GETD0049
          VALEND(1) =  360.0                                            GETD0050
      ELSE IF (DISTRB.EQ.5) THEN                                        GETD0051
          VALBEG(1) =    0.0                                            GETD0052
          VALEND(1) =  360.0                                            GETD0053
      ELSE IF (DISTRB.EQ.6) THEN                                        GETD0054
          VALBEG(1) =    0.0                                            GETD0055
          VALEND(1) =  360.0                                            GETD0056
      ENDIF                                                             GETD0057
                                                                        GETD0058
C---- Determine cell-size in each direction                             GETD0059
      IF (TWODEE) THEN                                                  GETD0060
          STEP(1) = (VALEND(1) - VALBEG(1)) / NCELL                     GETD0061
          STEP(2) = (VALEND(2) - VALBEG(2)) / NCELL                     GETD0062
      ELSE                                                              GETD0063
          STEP(1) = (VALEND(1) - VALBEG(1)) / NCELL1                    GETD0064
      ENDIF                                                             GETD0065
                                                                        GETD0066
C---- Search for the start of the data for the current distribution     GETD0067
 10   CONTINUE                                                          GETD0068
          LINE = LINE + 1                                               GETD0069
          READ(2,120,ERR=904,END=902) IREC                              GETD0070
          IF (IREC(1:13).EQ.'Distribution ') THEN                       GETD0071
              READ(IREC,20,ERR=904) IDISTR                              GETD0072
 20           FORMAT(13X,I1)                                            GETD0073
          ENDIF                                                         GETD0074
      IF (IDISTR.NE.DISTRB) GO TO 10                                    GETD0075
                                                                        GETD0076
C---- Initialise variables                                              GETD0077
      ENDFIL = .FALSE.                                                  GETD0078
      INEW =  .TRUE.                                                    GETD0079
      INORM = .FALSE.                                                   GETD0080
      ISTATE = 0                                                        GETD0081
      DO 50, IAMINO = 1, NAMINO + 1                                     GETD0082
          NCOUNT(IAMINO) = 0                                            GETD0083
          NRMEAN(IAMINO) = 0.0                                          GETD0084
          NRMSTD(IAMINO) = 0.0                                          GETD0085
 50   CONTINUE                                                          GETD0086
                                                                        GETD0087
C---- Read through the data file                                        GETD0088
 100  CONTINUE                                                          GETD0089
          LINE = LINE + 1                                               GETD0090
          READ(2,120,END=800,ERR=904) IREC                              GETD0091
 120      FORMAT(A)                                                     GETD0092
          IF (IREC(1:13).EQ.'Distribution ') GO TO 800                  GETD0093
                                                                        GETD0094
C----     If looking for the current amino acid's normalization factors,GETD0095
C         then read them in                                             GETD0096
          IF (INORM) THEN                                               GETD0097
              IF (IREC(1:4).NE.'Norm') GO TO 916                        GETD0098
              READ(IREC,130,ERR=904) MEAN, STDEV                        GETD0099
 130          FORMAT(15X,2F10.0)                                        GETD0100
              INEW = .TRUE.                                             GETD0101
              INORM = .FALSE.                                           GETD0102
              NRMEAN(IAMINO) = MEAN                                     GETD0103
              NRMSTD(IAMINO) = STDEV                                    GETD0104
                                                                        GETD0105
C----     If looking for next amino acid, read its details in           GETD0106
          ELSE IF (INEW) THEN                                           GETD0107
              READ(IREC,140,ERR=904) IAMINO                             GETD0108
 140          FORMAT(5X,I2)                                             GETD0109
                                                                        GETD0110
C----         If have a valid amino acid, then initialise variables     GETD0111
              IF (IAMINO.GT.0 .AND.IAMINO.LE.NAMINO) THEN               GETD0112
                  INEW = .FALSE.                                        GETD0113
                  ICELL = NCELL                                         GETD0114
                  ISTATE = 0                                            GETD0115
                  JCELL = 0                                             GETD0116
                  LVALUE = 0                                            GETD0117
                  NVALUE = 0                                            GETD0118
                  NZERO = 0                                             GETD0119
                  UPDATE = .FALSE.                                      GETD0120
              ELSE                                                      GETD0121
                  GO TO 906                                             GETD0122
              ENDIF                                                     GETD0123
                                                                        GETD0124
C----     Otherwise, process the current record                         GETD0125
          ELSE                                                          GETD0126
                                                                        GETD0127
C----         Loop through the characters in this record                GETD0128
              DO 500, IPOS = 1, 80                                      GETD0129
                  CH = IREC(IPOS:IPOS)                                  GETD0130
                                                                        GETD0131
C----             Check if this is a letter and, if so, extract its valuGETD0132
CHECK v.3.2-->                                                          GETD0133
C                  IF ((CH.GE.'A' .AND. CH.LE.'Z') .OR.                 GETD0134
C     -                (CH.GE.'a' .AND. CH.LE.'z')) THEN                GETD0135
                  IF ((LGE(CH,'A') .AND. LLE(CH,'Z')) .OR.              GETD0136
     &                (LGE(CH,'a') .AND. LLE(CH,'z'))) THEN             GETD0137
CHECK v.3.2<--                                                          GETD0138
                      IVALUE = INDEX(LETTER,CH)                         GETD0139
                      GOTLET = .TRUE.                                   GETD0140
                  ELSE                                                  GETD0141
                      GOTLET = .FALSE.                                  GETD0142
                  ENDIF                                                 GETD0143
                                                                        GETD0144
C----             Check for a number                                    GETD0145
CHECK v.3.2-->                                                          GETD0146
C                  IF (CH.GE.'0' .AND. CH.LE.'9') THEN                  GETD0147
                  IF (LGE(CH,'0') .AND. LLE(CH,'9')) THEN               GETD0148
CHECK v.3.2<--                                                          GETD0149
                      GOTNUM = .TRUE.                                   GETD0150
                  ELSE                                                  GETD0151
                      GOTNUM = .FALSE.                                  GETD0152
                  ENDIF                                                 GETD0153
                                                                        GETD0154
C----             Process character depending on current state          GETD0155
                                                                        GETD0156
C----             State 0: Looking at first character. Check to see whatGETD0157
C                 it is                                                 GETD0158
                  IF (ISTATE.EQ.0) THEN                                 GETD0159
                                                                        GETD0160
C----                 If a letter, then can update straight away        GETD0161
                      IF (GOTLET) THEN                                  GETD0162
                          UPDATE = .TRUE.                               GETD0163
                                                                        GETD0164
C----                 Otherwise, if the start of a number, will need to GETD0165
C                     build it up                                       GETD0166
                      ELSE                                              GETD0167
                                                                        GETD0168
C----                     If a hash-number, prepare to build it up      GETD0169
                          IF (CH.EQ.'#') THEN                           GETD0170
                              ISTATE = 1                                GETD0171
                                                                        GETD0172
C----                     Otherwise, if it's the start of the number of GETD0173
C                         zeros, get ready to build that up             GETD0174
                          ELSE IF (GOTNUM) THEN                         GETD0175
                              ISTATE = 3                                GETD0176
                              CNUMB = ' '                               GETD0177
                              NPOS = 0                                  GETD0178
                          ENDIF                                         GETD0179
                      ENDIF                                             GETD0180
                  ENDIF                                                 GETD0181
                                                                        GETD0182
C----             State 1: Have a hash, so skip to next state for first GETD0183
C                          digit                                        GETD0184
                  IF (ISTATE.EQ.1) THEN                                 GETD0185
                      ISTATE = 2                                        GETD0186
                      CNUMB = ' '                                       GETD0187
                      NPOS = 0                                          GETD0188
                                                                        GETD0189
C----             State 2: Bulding up the hash number                   GETD0190
                  ELSE IF (ISTATE.EQ.2) THEN                            GETD0191
                                                                        GETD0192
C----                 If this is a hash, an asterisk or a letter, then  GETD0193
C                     have come to the end of the number                GETD0194
                      IF (CH.EQ.'#' .OR. CH.EQ.'*' .OR. GOTLET) THEN    GETD0195
                          UPDATE = .TRUE.                               GETD0196
                          IF (NPOS.GT.0 .AND. NPOS.LE.10) THEN          GETD0197
                              RNUMB = ' '                               GETD0198
                              RNUMB(10 - NPOS + 1:10) = CNUMB(1:NPOS)   GETD0199
                              READ(RNUMB,220,ERR=910) LVALUE            GETD0200
 220                          FORMAT(I10)                               GETD0201
                              UPDATE = .TRUE.                           GETD0202
                          ELSE                                          GETD0203
                              GO TO 910                                 GETD0204
                          ENDIF                                         GETD0205
                                                                        GETD0206
C----                 Otherwise, it must be a continuation of the       GETD0207
C                     repetition number                                 GETD0208
                      ELSE IF (GOTNUM) THEN                             GETD0209
                          NPOS = NPOS + 1                               GETD0210
                          IF (NPOS.LE.10) CNUMB(NPOS:NPOS) = CH         GETD0211
                      ELSE                                              GETD0212
                          GO TO 908                                     GETD0213
                      ENDIF                                             GETD0214
                                                                        GETD0215
C----             State 3: Bulding up the number of zeros               GETD0216
                  ELSE IF (ISTATE.EQ.3) THEN                            GETD0217
                                                                        GETD0218
C----                 If this is a hash an asterisk or a letter,        GETD0219
C                     then have come to the end of the number           GETD0220
                      IF (CH.EQ.'#' .OR. CH.EQ.'*' .OR. GOTLET) THEN    GETD0221
                          IF (NPOS.GT.0 .AND. NPOS.LE.10) THEN          GETD0222
                              RNUMB = ' '                               GETD0223
                              RNUMB(10 - NPOS + 1:10) = CNUMB(1:NPOS)   GETD0224
                              READ(RNUMB,220,ERR=910) NZERO             GETD0225
                              UPDATE = .TRUE.                           GETD0226
                          ELSE                                          GETD0227
                              GO TO 910                                 GETD0228
                          ENDIF                                         GETD0229
                                                                        GETD0230
C----                 Otherwise, it must be a continuation of the       GETD0231
C                     number                                            GETD0232
                      ELSE IF (GOTNUM) THEN                             GETD0233
                          NPOS = NPOS + 1                               GETD0234
                          IF (NPOS.LE.10) CNUMB(NPOS:NPOS) = CH         GETD0235
                      ELSE                                              GETD0236
                          GO TO 908                                     GETD0237
                      ENDIF                                             GETD0238
                  ENDIF                                                 GETD0239
                                                                        GETD0240
C----             If have a value to update, then do so                 GETD0241
                  IF (UPDATE) THEN                                      GETD0242
                     ISTATE = 0                                         GETD0243
                     UPDATE = .FALSE.                                   GETD0244
                                                                        GETD0245
C----                Update number of zeros or uncompressed number      GETD0246
                     IF (NZERO.GT.0 .OR. LVALUE.GT.0) THEN              GETD0247
                         IF (NZERO.GT.0) THEN                           GETD0248
                             LVALUE = 0                                 GETD0249
                             NVALUE = NZERO                             GETD0250
                         ELSE                                           GETD0251
                             NVALUE = 1                                 GETD0252
                         ENDIF                                          GETD0253
                                                                        GETD0254
C----                    Perform the update                             GETD0255
                         DO 300, ILOOP = 1, NVALUE                      GETD0256
                                                                        GETD0257
C----                        Calculate subscripts for current cell      GETD0258
                             ICELL = ICELL + 1                          GETD0259
                             IF (ICELL.GT.NCELL) THEN                   GETD0260
                                 ICELL = 1                              GETD0261
                                 JCELL = JCELL + 1                      GETD0262
                                 IF (JCELL.GT.NCELL) GO TO 912          GETD0263
                             ENDIF                                      GETD0264
                             ARRAY(ICELL,JCELL,IAMINO) = LVALUE         GETD0265
                             NCOUNT(IAMINO) = NCOUNT(IAMINO) + LVALUE   GETD0266
 300                     CONTINUE                                       GETD0267
                                                                        GETD0268
C----                    Reinitialise                                   GETD0269
                         LVALUE = 0                                     GETD0270
                         NZERO = 0                                      GETD0271
                     ENDIF                                              GETD0272
                                                                        GETD0273
C----                If have a letter, then update its value            GETD0274
                     IF (GOTLET) THEN                                   GETD0275
                                                                        GETD0276
C----                    Calculate subscripts for current cell          GETD0277
                         ICELL = ICELL + 1                              GETD0278
                         IF (ICELL.GT.NCELL) THEN                       GETD0279
                             ICELL = 1                                  GETD0280
                             JCELL = JCELL + 1                          GETD0281
                             IF (JCELL.GT.NCELL) GO TO 912              GETD0282
                         ENDIF                                          GETD0283
                         ARRAY(ICELL,JCELL,IAMINO) = IVALUE             GETD0284
                         NCOUNT(IAMINO) = NCOUNT(IAMINO) + IVALUE       GETD0285
                      ENDIF                                             GETD0286
                  ENDIF                                                 GETD0287
                                                                        GETD0288
C----             If asterisk, then have reached the end                GETD0289
                  IF (CH.EQ.'*') THEN                                   GETD0290
                      ISTATE = 10                                       GETD0291
                      INORM = .TRUE.                                    GETD0292
                      IF (ICELL.NE.NCELL .AND. JCELL.NE.NCELL) GO TO 914GETD0293
                  ELSE IF (CH.EQ.'#') THEN                              GETD0294
                      ISTATE = 2                                        GETD0295
                      CNUMB = ' '                                       GETD0296
                      NPOS = 0                                          GETD0297
                  ENDIF                                                 GETD0298
 500          CONTINUE                                                  GETD0299
          ENDIF                                                         GETD0300
      GO TO 100                                                         GETD0301
                                                                        GETD0302
C---- End of file reached                                               GETD0303
 800  CONTINUE                                                          GETD0304
      IF (.NOT.INEW) GO TO 902                                          GETD0305
                                                                        GETD0306
CTESTING                                                                GETD0307
C---- Write out all the arrays to test that OK - and check vs gentorsn.dGETD0308
C     file generated by gentors.f when creating the compressed file     GETD0309
C      DO 850, IAMINO = 1, NAMINO                                       GETD0310
C          IF (NCOUNT(IAMINO).GT.0) THEN                                GETD0311
                                                                        GETD0312
C----         Write out amino acid number                               GETD0313
C              WRITE(9,*) DISTRB, IAMINO, '   ', AMINO(IAMINO)          GETD0314
                                                                        GETD0315
C----         Convert current array to set of integers                  GETD0316
C              IPOS = 0                                                 GETD0317
C              DO 802, JCELL = 1, NCELL                                 GETD0318
C                  DO 801, ICELL = 1, NCELL                             GETD0319
C                      IPOS = IPOS + 1                                  GETD0320
C                      IARRAY(IPOS) = NINT(ARRAY(ICELL,JCELL,IAMINO))   GETD0321
C 801              CONTINUE                                             GETD0322
C 802          CONTINUE                                                 GETD0323
                                                                        GETD0324
C----         Write out the integer version of the array                GETD0325
C              WRITE(9,260) (IARRAY(IPOS), IPOS = 1, NCELL * NCELL)     GETD0326
C 260          FORMAT(36I4)                                             GETD0327
C          ENDIF                                                        GETD0328
C 850  CONTINUE                                                         GETD0329
CTESTING                                                                GETD0330
                                                                        GETD0331
      GO TO 999                                                         GETD0332
                                                                        GETD0333
                                                                        GETD0334
C---- Errors reading parameter file                                     GETD0335
902   CONTINUE                                                          GETD0336
      PRINT*, '*** ERROR. Premature end of parameters file,',           GETD0337
     &        ' prodata, encountered at line', LINE                     GETD0338
      GO TO 990                                                         GETD0339
                                                                        GETD0340
904   CONTINUE                                                          GETD0341
      PRINT*, '*** Error reading parameter file, prodata, at',          GETD0342
     &     ' line', LINE                                                GETD0343
      GO TO 990                                                         GETD0344
                                                                        GETD0345
 906  CONTINUE                                                          GETD0346
      PRINT*, '*** ERROR. Invalid amino acid code in parameter file,',  GETD0347
     &    ' prodata, at line', LINE, '       :', IAMINO                 GETD0348
      GO TO 990                                                         GETD0349
                                                                        GETD0350
 908  CONTINUE                                                          GETD0351
      PRINT*, '*** ERROR. Invalid character in parameter file,',        GETD0352
     &    ' prodata, at line', LINE, '    Pstn:', IPOS,                 GETD0353
     &    '   [', IREC(IPOS:IPOS), ']'                                  GETD0354
      GO TO 990                                                         GETD0355
                                                                        GETD0356
 910  CONTINUE                                                          GETD0357
      PRINT*, '*** ERROR. Invalid repetition number in parameter',      GETD0358
     &    ' file, prodata, at line', LINE, '    Pstn:', IPOS,           GETD0359
     &    '   [', IREC(IPOS:IPOS), ']', CNUMB, NPOS                     GETD0360
      GO TO 990                                                         GETD0361
                                                                        GETD0362
 912  CONTINUE                                                          GETD0363
      PRINT*, '*** ERROR. Cell-size too large in parameter',            GETD0364
     &    ' file, prodata, at line', LINE, '    Pstn:', IPOS,           GETD0365
     &    '   [', IREC(IPOS:IPOS), ']', ICELL, JCELL                    GETD0366
      PRINT*, IREC                                                      GETD0367
      GO TO 990                                                         GETD0368
                                                                        GETD0369
 914  CONTINUE                                                          GETD0370
      PRINT*, '*** ERROR. Array not completed from parameter',          GETD0371
     &    ' file, prodata. Size:', ICELL, JCELL                         GETD0372
      GO TO 990                                                         GETD0373
                                                                        GETD0374
 916  CONTINUE                                                          GETD0375
      PRINT*, '*** ERROR. Missing normalization factor in parameter',   GETD0376
     &    ' file, prodata, at line', LINE                               GETD0377
      GO TO 990                                                         GETD0378
                                                                        GETD0379
 990  CONTINUE                                                          GETD0380
      IFAIL = .TRUE.                                                    GETD0381
                                                                        GETD0382
999   CONTINUE                                                          GETD0383
      RETURN                                                            GETD0384
      END                                                               GETD0385
                                                                        GETD0386
      SUBROUTINE GETPTS(DISTRB)                                         GETP0001
C-----------------------------------------------------------------------GETP0002
C                                                                       GETP0003
C  SUBROUTINE GETPTS  -  Read in the data from the .rin file for the    GETP0004
C                        appropriate distribution                       GETP0005
C                                                                       GETP0006
C----------------------------------------------------------------------+GETP0007
                                                                        GETP0008
      INCLUDE 'tplot.inc'                                               GETP0009
                                                                        GETP0010
      CHARACTER*1   INCHN, SECSTR                                       GETP0011
      CHARACTER*2   REGION                                              GETP0012
      CHARACTER*3   RESDUE                                              GETP0013
CHECK v.3.2-->                                                          GETP0014
C      CHARACTER*5   SEQNO                                              GETP0015
CHECK v.3.4-->                                                          GETP0016
C      CHARACTER*5   CNUMB, SEQNO                                       GETP0017
C      CHARACTER*79  BLNKLN, SUMLIN                                     GETP0018
      CHARACTER*5   CNUMB, NUMBER, SEQNO                                GETP0019
      CHARACTER*79  BLNKLN, IREC, SUMLIN                                GETP0020
CHECK v.3.4<--                                                          GETP0021
CHECK v.3.2<--                                                          GETP0022
CHECK v.3.2-->                                                          GETP0023
C      INTEGER       IRESID, DISTRB, REGNO, REGTYP, SERNO               GETP0024
CHECK v.3.4-->                                                          GETP0025
C      INTEGER       IFILE, IPOS, IRESID, DISTRB, MXIPOS, RLABEL, REGNO,GETP0026
C     -              REGTYP, SERNO                                      GETP0027
      INTEGER       DISTRB, IERR, IFILE, IMODEL, IPAGE, IPOS, IRESID,   GETP0028
     &              LENSTR, MALLOW, MCORE, MENDCH, MGENER, MGLY, MONPG, GETP0029
     &              MOUTSI, MPRO, MRAMPL, MRESID, MXIPOS, RLABEL, REGNO,GETP0030
     &              REGTYP, SERNO                                       GETP0031
      LOGICAL       INRANG, WANTED                                      GETP0032
CHECK v.3.4<--                                                          GETP0033
CHECK v.3.2<--                                                          GETP0034
      REAL          CGAMB, CHI1, CHI2, CHI3, CHI4, DISULF, ENHB, MCBVAL,GETP0035
     &              OMEGA, PHI, PSI, SCBVAL, ZETA                       GETP0036
CHECK v.3.2-->                                                          GETP0037
      DATA BLNKLN( 1:40) / ' |                                      ' / GETP0038
      DATA BLNKLN(41:79) / '                                      |'  / GETP0039
CHECK v.3.2<--                                                          GETP0040
                                                                        GETP0041
C---- Initialise variables                                              GETP0042
      IRESID = 0                                                        GETP0043
CHECK v.3.4-->                                                          GETP0044
      IPAGE = 0                                                         GETP0045
      MALLOW = 0                                                        GETP0046
      MCORE = 0                                                         GETP0047
      MENDCH = 0                                                        GETP0048
      MGENER = 0                                                        GETP0049
      MGLY = 0                                                          GETP0050
      MONPG = 0                                                         GETP0051
      MOUTSI = 0                                                        GETP0052
      MPRO = 0                                                          GETP0053
      MRAMPL = 0                                                        GETP0054
      MRESID = 0                                                        GETP0055
CHECK v.3.4<--                                                          GETP0056
      NALLOW = 0                                                        GETP0057
      NCORE = 0                                                         GETP0058
      NENDCH = 0                                                        GETP0059
      NGENER = 0                                                        GETP0060
      NGLY = 0                                                          GETP0061
      NONPG = 0                                                         GETP0062
      NOUTSI = 0                                                        GETP0063
      NPRO = 0                                                          GETP0064
      NRAMPL = 0                                                        GETP0065
      NRESID = 0                                                        GETP0066
CHECK v.3.2-->                                                          GETP0067
      RLABEL = 0                                                        GETP0068
CHECK v.3.2<--                                                          GETP0069
                                                                        GETP0070
CHECK v.3.2-->                                                          GETP0071
C---- If this is an ensemble, open the first of the .rin files          GETP0072
      IF (NMR .OR. ENSEMB) THEN                                         GETP0073
CHECK v.3.4-->                                                          GETP0074
C          IFILE = 1                                                    GETP0075
          IFILE = FFILE                                                 GETP0076
CHECK v.3.4<--                                                          GETP0077
          OPEN(UNIT=3,FILE=FILRIN(IFILE),STATUS='OLD',                  GETP0078
     &        ACCESS='SEQUENTIAL',                                      GETP0079
CVAX     -     READONLY,                                                GETP0080
     &        FORM='FORMATTED',ERR=900)                                 GETP0081
                                                                        GETP0082
C---- Otherwise rewind the single .rin file                             GETP0083
      ELSE                                                              GETP0084
CHECK v.3.2<--                                                          GETP0085
          REWIND(3)                                                     GETP0086
CHECK v.3.2-->                                                          GETP0087
      ENDIF                                                             GETP0088
CHECK v.3.2<--                                                          GETP0089
                                                                        GETP0090
CHECK v.3.4-->                                                          GETP0091
C---- Check whether the first record contains the actual model number   GETP0092
      READ(3,120,END=900) IREC                                          GETP0093
 120  FORMAT(A)                                                         GETP0094
      IF (IREC(1:5).EQ.'MODEL') THEN                                    GETP0095
          READ(IREC,160,IOSTAT=IERR) IMODEL                             GETP0096
 160      FORMAT(9X,I5)                                                 GETP0097
          IF (IERR.NE.0) THEN                                           GETP0098
              IMODEL = IFILE                                            GETP0099
          ENDIF                                                         GETP0100
      ELSE                                                              GETP0101
          IMODEL = IFILE                                                GETP0102
          BACKSPACE(3)                                                  GETP0103
      ENDIF                                                             GETP0104
CHECK v.3.4<--                                                          GETP0105
                                                                        GETP0106
C---- Initialise Ramachandran plot                                      GETP0107
      IF (PLOTRM) THEN                                                  GETP0108
CHECK v.3.4-->                                                          GETP0109
C----     If plotting a separate Ramachandran plot for each model,      GETP0110
C         prepare header information for the next .rin file             GETP0111
          IF (RMSPLT) THEN                                              GETP0112
              WRITE(NUMBER,520) IFILE                                   GETP0113
 520          FORMAT(I5)                                                GETP0114
              IPOS = 1                                                  GETP0115
              IF (NUMBER(1:1).EQ.' ') IPOS = 2                          GETP0116
              IF (NUMBER(2:2).EQ.' ') IPOS = 3                          GETP0117
              IF (NUMBER(3:3).EQ.' ') IPOS = 4                          GETP0118
              IF (NUMBER(4:4).EQ.' ') IPOS = 5                          GETP0119
              RAMHED = RAMHED(1:RLEN - 6) // NUMBER(IPOS:) // ')'       GETP0120
              IF (HAVRAN .AND. RESFRM(1).NE.'*ALL  ') THEN              GETP0121
                  RAMHED = RAMHED(1:RLEN - IPOS + 1) // '**'            GETP0122
              ENDIF                                                     GETP0123
          ELSE                                                          GETP0124
              RAMHED = BRCODE                                           GETP0125
              RLEN = BLEN                                               GETP0126
          ENDIF                                                         GETP0127
                                                                        GETP0128
C----     Open the Ramachandran file                                    GETP0129
          CALL RAMOPE                                                   GETP0130
CHECK v.3.4<--                                                          GETP0131
                                                                        GETP0132
C----     Plot the Ramachandran file headings                           GETP0133
CHECK v.3.4-->                                                          GETP0134
C          CALL RAMACH                                                  GETP0135
          CALL RAMACH(IPAGE)                                            GETP0136
CHECK v.3.4<--                                                          GETP0137
      ENDIF                                                             GETP0138
                                                                        GETP0139
C---- Read through the residues file                                    GETP0140
 100  CONTINUE                                                          GETP0141
          READ(3,110,END=500,ERR=902) SERNO, RESDUE, INCHN, SEQNO,      GETP0142
     &        SECSTR, PHI, PSI, OMEGA, CHI1, CHI2, CHI3, CHI4, ENHB,    GETP0143
     &        DISULF, ZETA, CGAMB, MCBVAL, SCBVAL                       GETP0144
 110      FORMAT(I4,A3,1X,A1,A5,A1,11F7.2,2F7.3)                        GETP0145
                                                                        GETP0146
CHECK v.3.4-->                                                          GETP0147
C----     Test whether the current residue is within one of the         GETP0148
C         user-defined ranges                                           GETP0149
          WANTED = INRANG(SEQNO,INCHN,RESFRM,RESTO,MAXRNG,NRANGE)       GETP0150
CHECK v.3.4<--                                                          GETP0151
                                                                        GETP0152
C----     Only process this residue if it belongs to the required chain GETP0153
C         or residue is within one of the selected ranges               GETP0154
CHECK v.3.4-->                                                          GETP0155
C          IF (CHAIN.EQ.' ' .OR. INCHN.EQ.CHAIN) THEN                   GETP0156
          IF (WANTED .AND. (CHAIN.EQ.' ' .OR. INCHN.EQ.CHAIN)) THEN     GETP0157
CHECK v.3.4<--                                                          GETP0158
                                                                        GETP0159
C----         Increment residue-count                                   GETP0160
              IRESID = IRESID + 1                                       GETP0161
              IF (IRESID.GT.MXRES) GO TO 904                            GETP0162
CHECK v.3.4-->                                                          GETP0163
              MRESID = MRESID + 1                                       GETP0164
CHECK v.3.4<--                                                          GETP0165
                                                                        GETP0166
C----         Save the serial number of this residue                    GETP0167
              SAVRES(IRESID) = SERNO                                    GETP0168
                                                                        GETP0169
CHECK v.3.2-->                                                          GETP0170
C----         For ensemble structures save the model number             GETP0171
              MODEL(IRESID) = IFILE                                     GETP0172
CHECK v.3.2<--                                                          GETP0173
                                                                        GETP0174
C----         Chi-1 torsion angle                                       GETP0175
              IF (RESDUE.EQ.'PRO') CHI1 = 999.9                         GETP0176
              IF (CHI1.LT.0.0) CHI1 = CHI1 + 360.0                      GETP0177
              IF (CHI1.EQ.360.0) CHI1 = 0.0                             GETP0178
                                                                        GETP0179
C----         Chi-2 torsion angle                                       GETP0180
              IF (CHI2.LE.0.0) CHI2 = CHI2 + 360.0                      GETP0181
              IF (CHI2.EQ.360.0) CHI2 = 0.0                             GETP0182
                                                                        GETP0183
C----         Chi-3 torsion angle                                       GETP0184
              IF (CHI3.LE.0.0) CHI3 = CHI3 + 360.0                      GETP0185
              IF (CHI3.EQ.360.0) CHI3 = 0.0                             GETP0186
                                                                        GETP0187
C----         Chi-4 torsion angle                                       GETP0188
              IF (CHI4.LE.0.0) CHI4 = CHI4 + 360.0                      GETP0189
              IF (CHI4.EQ.360.0) CHI4 = 0.0                             GETP0190
                                                                        GETP0191
C----         Omega torsion angle                                       GETP0192
              IF (OMEGA.LE.0.0) OMEGA = OMEGA + 360.0                   GETP0193
              IF (OMEGA.EQ.360.0) OMEGA = 0.0                           GETP0194
                                                                        GETP0195
C----         Zeta torsion angle                                        GETP0196
              IF (ZETA.LE.0.0) ZETA = ZETA + 360.0                      GETP0197
              IF (ZETA.EQ.360.0) ZETA = 0.0                             GETP0198
                                                                        GETP0199
C----         Store required value(s)                                   GETP0200
              IF (DISTRB.EQ.1) THEN                                     GETP0201
                  VALUE(1,IRESID) = PHI                                 GETP0202
                  VALUE(2,IRESID) = PSI                                 GETP0203
              ELSE IF (DISTRB.EQ.2) THEN                                GETP0204
                  VALUE(1,IRESID) = CHI1                                GETP0205
                  VALUE(2,IRESID) = CHI2                                GETP0206
              ELSE IF (DISTRB.EQ.3) THEN                                GETP0207
                  VALUE(1,IRESID) = CHI1                                GETP0208
              ELSE IF (DISTRB.EQ.4) THEN                                GETP0209
                  VALUE(1,IRESID) = CHI3                                GETP0210
              ELSE IF (DISTRB.EQ.5) THEN                                GETP0211
                  VALUE(1,IRESID) = CHI4                                GETP0212
              ELSE IF (DISTRB.EQ.6) THEN                                GETP0213
                  VALUE(1,IRESID) = OMEGA                               GETP0214
              ENDIF                                                     GETP0215
                                                                        GETP0216
C----         Save the residue name                                     GETP0217
              RESID(IRESID) = INCHN // ' ' // RESDUE // SEQNO           GETP0218
                                                                        GETP0219
C----         Determine which region of Ramachandran plot residue lies iGETP0220
              CALL RAMREG(PHI,PSI,REGION,REGNO,REGTYP)                  GETP0221
                                                                        GETP0222
C----         Increment count of different types of residues            GETP0223
              IF (RESDUE.EQ.'GLY') NGLY = NGLY + 1                      GETP0224
              IF (RESDUE.EQ.'PRO') NPRO = NPRO + 1                      GETP0225
CHECK v.3.4-->                                                          GETP0226
              IF (RESDUE.EQ.'GLY') MGLY = MGLY + 1                      GETP0227
              IF (RESDUE.EQ.'PRO') MPRO = MPRO + 1                      GETP0228
CHECK v.3.4<--                                                          GETP0229
                                                                        GETP0230
C----         If residue is neither a glycine nor a proline, then determGETP0231
C             in which region of the Ramachandran plot its phi-psi valueGETP0232
C             fall                                                      GETP0233
              IF (RESDUE.NE.'GLY' .AND. RESDUE.NE.'PRO') THEN           GETP0234
                                                                        GETP0235
C----             Check whether this is an end-residue at a chain break GETP0236
                  IF (PHI.EQ.999.9 .OR. PSI.EQ.999.9) THEN              GETP0237
                      NENDCH = NENDCH + 1                               GETP0238
CHECK v.3.4-->                                                          GETP0239
                      MENDCH = MENDCH + 1                               GETP0240
CHECK v.3.4<--                                                          GETP0241
                                                                        GETP0242
C----             If valid phi-psi, then determine region type          GETP0243
                  ELSE                                                  GETP0244
                      NONPG = NONPG + 1                                 GETP0245
CHECK v.3.4-->                                                          GETP0246
                      MONPG = MONPG + 1                                 GETP0247
CHECK v.3.4<--                                                          GETP0248
                                                                        GETP0249
C----                 Increment counts of residues in each region type  GETP0250
                      IF (REGION.EQ.'XX') THEN                          GETP0251
                          NOUTSI = NOUTSI + 1                           GETP0252
CHECK v.3.4-->                                                          GETP0253
                          MOUTSI = MOUTSI + 1                           GETP0254
CHECK v.3.4<--                                                          GETP0255
                          DISALL = .TRUE.                               GETP0256
                      ELSE IF (REGION.EQ.'B ' .OR. REGION.EQ.'A ' .OR.  GETP0257
     &                    REGION.EQ.'L ') THEN                          GETP0258
                          NCORE = NCORE + 1                             GETP0259
CHECK v.3.4-->                                                          GETP0260
                          MCORE = MCORE + 1                             GETP0261
CHECK v.3.4<--                                                          GETP0262
                      ELSE IF (REGION.EQ.'b ' .OR. REGION.EQ.'a ' .OR.  GETP0263
     &                    REGION.EQ.'l ' .OR. REGION.EQ.'p ') THEN      GETP0264
                          NALLOW = NALLOW + 1                           GETP0265
CHECK v.3.4-->                                                          GETP0266
                          MALLOW = MALLOW + 1                           GETP0267
CHECK v.3.4<--                                                          GETP0268
                      ELSE IF (REGION.EQ.'~b' .OR. REGION.EQ.'~a' .OR.  GETP0269
     &                    REGION.EQ.'~l' .OR. REGION.EQ.'~p') THEN      GETP0270
                          NGENER = NGENER + 1                           GETP0271
CHECK v.3.4-->                                                          GETP0272
                          MGENER = MGENER + 1                           GETP0273
CHECK v.3.4<--                                                          GETP0274
                      ENDIF                                             GETP0275
                  ENDIF                                                 GETP0276
              ENDIF                                                     GETP0277
                                                                        GETP0278
C----         Plot this residue on the Ramachandran plot                GETP0279
              IF (PLOTRM .AND. PHI.NE.999.9 .AND. PSI.NE.999.9) THEN    GETP0280
                  NRAMPL = NRAMPL + 1                                   GETP0281
CHECK v.3.4-->                                                          GETP0282
                  MRAMPL = MRAMPL + 1                                   GETP0283
CHECK v.3.4<--                                                          GETP0284
CHECK v.3.2-->                                                          GETP0285
C                  CALL RAMPLT(PHI,PSI,RESDUE,REGTYP,SEQNO)             GETP0286
                  CALL RAMPLT(PHI,PSI,RESDUE,REGTYP,SEQNO,IFILE,RLABEL, GETP0287
     &                INCHN)                                            GETP0288
CHECK v.3.2<--                                                          GETP0289
              ENDIF                                                     GETP0290
                                                                        GETP0291
          ENDIF                                                         GETP0292
                                                                        GETP0293
C---- Loop back for next record in file                                 GETP0294
      GO TO 100                                                         GETP0295
                                                                        GETP0296
C---- End of file reached                                               GETP0297
 500  CONTINUE                                                          GETP0298
      NRESID = IRESID                                                   GETP0299
                                                                        GETP0300
C---- Check that file wasn't empty                                      GETP0301
      IF (NRESID.EQ.0) GO TO 906                                        GETP0302
CHECK v.3.2-->                                                          GETP0303
      IF (.NOT.NMR .AND. .NOT.ENSEMB) THEN                              GETP0304
CHECK v.3.2<--                                                          GETP0305
          PRINT*, NRESID, ' residues read in'                           GETP0306
CHECK v.3.2-->                                                          GETP0307
      ENDIF                                                             GETP0308
CHECK v.3.2<--                                                          GETP0309
                                                                        GETP0310
CHECK v.3.2-->                                                          GETP0311
C---- If this is an ensemble, compute statistics for model just processeGETP0312
C     and then get the next .rin file                                   GETP0313
      IF (NMR .OR. ENSEMB) THEN                                         GETP0314
                                                                        GETP0315
C----     Close the .rin file                                           GETP0316
          CLOSE(3)                                                      GETP0317
                                                                        GETP0318
CHECK v.3.4-->                                                          GETP0319
C----     If plotting a separate Ramachandran plot for each model,      GETP0320
C         then close off this one and open the next                     GETP0321
          IF (PLOTRM .AND. RMSPLT) THEN                                 GETP0322
                                                                        GETP0323
C----         Calculate Ramachandran plot statistics for last model     GETP0324
              CALL MSTATS(MALLOW,MCORE,MENDCH,MGENER,MGLY,MONPG,MOUTSI, GETP0325
     &            MPRO,MRAMPL,MRESID)                                   GETP0326
                                                                        GETP0327
              IF (ENSEMB) THEN                                          GETP0328
                  CALL FILKEY(XRAMC2 + 4.0 * HWIDX,YRAMC2 - 2.0 * HWIDY,GETP0329
     &                2.0 * HWIDX,2.0 * HWIDY,8.0,5.0)                  GETP0330
              ENDIF                                                     GETP0331
                                                                        GETP0332
C----         Print statistics and close file                           GETP0333
              CALL RAMEND(BBOXX1,BBOXX2,BBOXY1,BBOXY2,MALLOW,MCORE,     GETP0334
     &            MENDCH,MGENER,MGLY,MONPG,MOUTSI,MPRO,MRAMPL,MRESID)   GETP0335
                                                                        GETP0336
C----         Reinitialise the counts                                   GETP0337
              MALLOW = 0                                                GETP0338
              MCORE = 0                                                 GETP0339
              MENDCH = 0                                                GETP0340
              MGENER = 0                                                GETP0341
              MGLY = 0                                                  GETP0342
              MONPG = 0                                                 GETP0343
              MOUTSI = 0                                                GETP0344
              MPRO = 0                                                  GETP0345
              MRAMPL = 0                                                GETP0346
              MRESID = 0                                                GETP0347
          ENDIF                                                         GETP0348
CHECK v.3.4<--                                                          GETP0349
                                                                        GETP0350
C----     If there's another .rin file to go, open it                   GETP0351
CHECK v.3.4-->                                                          GETP0352
 550      CONTINUE                                                      GETP0353
CHECK v.3.4<--                                                          GETP0354
          IF (IFILE.LT.NFILE) THEN                                      GETP0355
              IFILE = IFILE + 1                                         GETP0356
CHECK v.3.4-->                                                          GETP0357
              IF (MWANT(IFILE)) THEN                                    GETP0358
CHECK v.3.4<--                                                          GETP0359
                  OPEN(UNIT=3,FILE=FILRIN(IFILE),STATUS='OLD',          GETP0360
     &                ACCESS='SEQUENTIAL',                              GETP0361
CVAX     -             READONLY,                                        GETP0362
     &                FORM='FORMATTED',ERR=900)                         GETP0363
CHECK v.3.4-->                                                          GETP0364
C                  GO TO 100                                            GETP0365
                                                                        GETP0366
C----             If plotting a separate Ramachandran plot for each modeGETP0367
C                 prepare header information for the next .rin file     GETP0368
                  IF (PLOTRM .AND. RMSPLT) THEN                         GETP0369
                      WRITE(NUMBER,520) IFILE                           GETP0370
                      IPOS = 1                                          GETP0371
                      IF (NUMBER(1:1).EQ.' ') IPOS = 2                  GETP0372
                      IF (NUMBER(2:2).EQ.' ') IPOS = 3                  GETP0373
                      IF (NUMBER(3:3).EQ.' ') IPOS = 4                  GETP0374
                      IF (NUMBER(4:4).EQ.' ') IPOS = 5                  GETP0375
                      RAMHED = RAMHED(1:RLEN - 6) // NUMBER(IPOS:) //   GETP0376
     &                    ')'                                           GETP0377
                      IF (HAVRAN .AND. RESFRM(1).NE.'*ALL  ') THEN      GETP0378
                          RAMHED = RAMHED(1:RLEN - IPOS + 1) // '**'    GETP0379
                      ENDIF                                             GETP0380
                      CALL RAMACH(IPAGE)                                GETP0381
                  ENDIF                                                 GETP0382
                  GO TO 100                                             GETP0383
              ELSE                                                      GETP0384
                  GO TO 550                                             GETP0385
              ENDIF                                                     GETP0386
CHECK v.3.4<--                                                          GETP0387
          ENDIF                                                         GETP0388
          PRINT*, NRESID, ' residues read in for entire ensemble'       GETP0389
      ENDIF                                                             GETP0390
CHECK v.3.2<--                                                          GETP0391
                                                                        GETP0392
C---- Calculate percentages for residues in the different regions of theGETP0393
C     Ramachandran plot                                                 GETP0394
      IF (NONPG.GT.0) THEN                                              GETP0395
          ALLOWP = 100.0 * REAL(NALLOW) / REAL(NONPG)                   GETP0396
          COREPC = 100.0 * REAL(NCORE) / REAL(NONPG)                    GETP0397
          GENERP = 100.0 * REAL(NGENER) / REAL(NONPG)                   GETP0398
          OUTSIP = 100.0 * REAL(NOUTSI) / REAL(NONPG)                   GETP0399
      ELSE                                                              GETP0400
          ALLOWP = 0.0                                                  GETP0401
          COREPC = 0.0                                                  GETP0402
          GENERP = 0.0                                                  GETP0403
          OUTSIP = 0.0                                                  GETP0404
      ENDIF                                                             GETP0405
                                                                        GETP0406
C---- Print statistics for Ramachandran plot                            GETP0407
      IF (PLOTRM) THEN                                                  GETP0408
CHECK v.3.2-->                                                          GETP0409
C----     If this is an ensemble of structures from separate files      GETP0410
C         (ie rather than a set of NMR models in a single file), then   GETP0411
C         print key                                                     GETP0412
          IF (ENSEMB) THEN                                              GETP0413
              CALL FILKEY(XRAMC2 + 4.0 * HWIDX,YRAMC2 - 2.0 * HWIDY,    GETP0414
     &            2.0 * HWIDX,2.0 * HWIDY,8.0,5.0)                      GETP0415
          ENDIF                                                         GETP0416
CHECK v.3.2<--                                                          GETP0417
                                                                        GETP0418
C----     Print statistics and close file                               GETP0419
CHECK v.3.4-->                                                          GETP0420
C          CALL RAMEND(BBOXX1,BBOXX2,BBOXY1,BBOXY2)                     GETP0421
          IF (.NOT.RMSPLT) THEN                                         GETP0422
              CALL RAMEND(BBOXX1,BBOXX2,BBOXY1,BBOXY2,NALLOW,NCORE,     GETP0423
     &            NENDCH,NGENER,NGLY,NONPG,NOUTSI,NPRO,NRAMPL,NRESID)   GETP0424
          ENDIF                                                         GETP0425
                                                                        GETP0426
C----     Close the Ramachandran plot file                              GETP0427
          CALL PSCLOS(BBOXX1,BBOXX2,BBOXY1,BBOXY2)                      GETP0428
CHECK v.3.4<--                                                          GETP0429
      ENDIF                                                             GETP0430
                                                                        GETP0431
C---- Set Ramachandran plot flag off so that don't plot this again      GETP0432
      PLOTRM = .FALSE.                                                  GETP0433
                                                                        GETP0434
CHECK v.3.2-->                                                          GETP0435
C---- If this is the first pass through this routine, write out the     GETP0436
C     Ramachandran statistics to the .sum summary file                  GETP0437
      IF (DISTRB.EQ.1) THEN                                             GETP0438
                                                                        GETP0439
C----     File name, resolution, chain-ID and number of residues        GETP0440
                                                                        GETP0441
C----     Blank out the output line                                     GETP0442
          SUMLIN = BLNKLN                                               GETP0443
                                                                        GETP0444
C----     Determine length of filename of original PDB file             GETP0445
          IPOS = 79                                                     GETP0446
 600      CONTINUE                                                      GETP0447
              IPOS = IPOS - 1                                           GETP0448
          IF (IPOS.GT.1 .AND. PDBFIL(IPOS:IPOS).EQ.' ') GO TO 600       GETP0449
                                                                        GETP0450
C----     Determine the maximum length of filename that we can fit in   GETP0451
          IF (CHAIN.EQ.' ') THEN                                        GETP0452
              MXIPOS = 54                                               GETP0453
          ELSE                                                          GETP0454
              MXIPOS = 51                                               GETP0455
          ENDIF                                                         GETP0456
          IF (IPOS.GT.MXIPOS) IPOS = MXIPOS                             GETP0457
                                                                        GETP0458
C----     Fill the output line with the relevant data                   GETP0459
          WRITE(CNUMB,620) RESOL                                        GETP0460
 620      FORMAT(F5.1)                                                  GETP0461
          SUMLIN(4:4 + IPOS - 1) = PDBFIL(1:IPOS)                       GETP0462
          SUMLIN(4 + IPOS + 1:4 + IPOS + 5) = CNUMB                     GETP0463
          IF (CHAIN.NE.' ') SUMLIN(4 + IPOS + 8:4 + IPOS + 8) = CHAIN   GETP0464
          WRITE(CNUMB,640) NRESID                                       GETP0465
 640      FORMAT(I5)                                                    GETP0466
          SUMLIN(64:68) = CNUMB                                         GETP0467
          SUMLIN(70:77) = 'residues'                                    GETP0468
                                                                        GETP0469
C----     Write the line out to the summary file                        GETP0470
          WRITE(14,660) SUMLIN                                          GETP0471
 660      FORMAT(A)                                                     GETP0472
          WRITE(14,660) BLNKLN                                          GETP0473
                                                                        GETP0474
C----     Ramachandran plot statisticsm                                 GETP0475
                                                                        GETP0476
C----     Blank out the output line                                     GETP0477
          SUMLIN = BLNKLN                                               GETP0478
                                                                        GETP0479
C----     Fill the line with the percentages in the various regions of tGETP0480
C         Ramachandran plot                                             GETP0481
          SUMLIN(4:77) = 'Ramachandran plot:       % core       % al' //GETP0482
     &        'low       % gener       % disall'                        GETP0483
          WRITE(CNUMB,680) COREPC                                       GETP0484
 680      FORMAT(F5.1)                                                  GETP0485
          SUMLIN(24:28) = CNUMB                                         GETP0486
          WRITE(CNUMB,680) ALLOWP                                       GETP0487
          SUMLIN(37:41) = CNUMB                                         GETP0488
          WRITE(CNUMB,680) GENERP                                       GETP0489
          SUMLIN(51:55) = CNUMB                                         GETP0490
          WRITE(CNUMB,680) OUTSIP                                       GETP0491
          SUMLIN(65:69) = CNUMB                                         GETP0492
                                                                        GETP0493
C----     Determine whether to highlight the line with a + or a *       GETP0494
          IF (GENERP.GT.0.0 .OR. COREPC.LT.90.0) THEN                   GETP0495
              SUMLIN(1:1) = '+'                                         GETP0496
          ENDIF                                                         GETP0497
          IF (OUTSIP.GT.0.0 .OR. COREPC.LT.80.0) THEN                   GETP0498
              SUMLIN(1:1) = '*'                                         GETP0499
          ENDIF                                                         GETP0500
                                                                        GETP0501
C----     Write the line out to the summary file                        GETP0502
          WRITE(14,660) SUMLIN                                          GETP0503
          WRITE(14,660) BLNKLN                                          GETP0504
      ENDIF                                                             GETP0505
CHECK v.3.2<--                                                          GETP0506
                                                                        GETP0507
      GO TO 999                                                         GETP0508
                                                                        GETP0509
C---- Fatal errors                                                      GETP0510
CHECK v.3.0.1-->                                                        GETP0511
C900   CONTINUE                                                         GETP0512
C      PRINT*, '*** ERROR. Unable to open data file'                    GETP0513
C      GO TO 990                                                        GETP0514
CHECK v.3.0.1<--                                                        GETP0515
                                                                        GETP0516
CHECK v.3.2-->                                                          GETP0517
 900  CONTINUE                                                          GETP0518
CHECK v.3.4-->                                                          GETP0519
C      PRINT*, '*** Error opening .rin file.', FILRIN(IFILE)            GETP0520
      PRINT*, '*** Error opening .rin file.'                            GETP0521
      PRINT*, '* [', FILRIN(IFILE)(1:LENSTR(FILRIN(IFILE))), ']'        GETP0522
CHECK v.3.4<--                                                          GETP0523
      GO TO 990                                                         GETP0524
CHECK v.3.2<--                                                          GETP0525
                                                                        GETP0526
902   CONTINUE                                                          GETP0527
      PRINT*, '*** ERROR. Data error in .rin file at line:', IRESID + 1 GETP0528
      GO TO 990                                                         GETP0529
                                                                        GETP0530
 904  CONTINUE                                                          GETP0531
      PRINT*, '*** ERROR. Maximum number of residues exceeded:', MXRES  GETP0532
      GO TO 990                                                         GETP0533
                                                                        GETP0534
 906  CONTINUE                                                          GETP0535
      PRINT*, '*** Warning. No data points point in .rin file.'         GETP0536
      GO TO 990                                                         GETP0537
                                                                        GETP0538
990   CONTINUE                                                          GETP0539
      IFAIL = .TRUE.                                                    GETP0540
                                                                        GETP0541
999   CONTINUE                                                          GETP0542
      RETURN                                                            GETP0543
      END                                                               GETP0544
                                                                        GETP0545
      SUBROUTINE RAMOPE                                                 RAMO0001
C-----------------------------------------------------------------------RAMO0002
CHECK v.3.4-->                                                          RAMO0003
C                                                                       RAMO0004
C  SUBROUTINE RAMOPE  -  Open the Ramachandran plots file               RAMO0005
C                                                                       RAMO0006
C----------------------------------------------------------------------+RAMO0007
                                                                        RAMO0008
      INCLUDE 'tplot.inc'                                               RAMO0009
                                                                        RAMO0010
      CHARACTER*30  PLDESC                                              RAMO0011
      CHARACTER*60  PTITLE                                              RAMO0012
                                                                        RAMO0013
C---- Open PostScript file                                              RAMO0014
      PLDESC = 'Main Ramachandran plot'                                 RAMO0015
      CALL PSNAME(FILPS,PSLEN,IPLOT,PLDESC,'ramachand',WITHAN)          RAMO0016
      PTITLE = 'Ramachandran plot'                                      RAMO0017
CHECK v.3.4-->                                                          RAMO0018
C      CALL PSOPEN(FILPS,MXCOLR,RGB,INCOLR,PTITLE,1)                    RAMO0019
      CALL PSOPEN(FILPS,MXCOLR,RGB,NCOLOR,INCOLR,PTITLE,1)              RAMO0020
CHECK v.3.4<--                                                          RAMO0021
                                                                        RAMO0022
      RETURN                                                            RAMO0023
      END                                                               RAMO0024
                                                                        RAMO0025
      SUBROUTINE RAMACH(IPAGE)                                          RAMA0001
C-----------------------------------------------------------------------RAMA0002
CHECK v.3.4<--                                                          RAMA0003
C                                                                       RAMA0004
C  SUBROUTINE RAMACH  -  Print headings, etc for Ramachandran plot      RAMA0005
C                                                                       RAMA0006
C----------------------------------------------------------------------+RAMA0007
                                                                        RAMA0008
CHECK v.3.4-->                                                          RAMA0009
C      SUBROUTINE RAMACH                                                RAMA0010
CHECK v.3.4<--                                                          RAMA0011
                                                                        RAMA0012
      INCLUDE 'tplot.inc'                                               RAMA0013
                                                                        RAMA0014
CHECK v.3.4-->                                                          RAMA0015
      CHARACTER*7   PAGE                                                RAMA0016
CHECK v.3.4<--                                                          RAMA0017
CHECK v.3.1-->                                                          RAMA0018
CHECK v.3.4-->                                                          RAMA0019
C      CHARACTER*30  PLDESC                                             RAMA0020
CHECK v.3.4<--                                                          RAMA0021
CHECK v.3.1<--                                                          RAMA0022
CHECK v.3.2-->                                                          RAMA0023
CHECK v.3.4-->                                                          RAMA0024
C      CHARACTER*60  PTITLE                                             RAMA0025
CHECK v.3.4<--                                                          RAMA0026
CHECK v.3.2<--                                                          RAMA0027
CHECK v.3.4-->                                                          RAMA0028
      INTEGER       IPAGE                                               RAMA0029
CHECK v.3.4<--                                                          RAMA0030
                                                                        RAMA0031
C---- Open PostScript file                                              RAMA0032
CHECK v.3.4-->                                                          RAMA0033
CCHECK v.3.1-->                                                         RAMA0034
CC      CALL PSNAME(FILPS,PSLEN,IPLOT)                                  RAMA0035
C      PLDESC = 'Main Ramachandran plot'                                RAMA0036
CCHECK v.3.2-->                                                         RAMA0037
CC      CALL PSNAME(FILPS,PSLEN,IPLOT,PLDESC)                           RAMA0038
C      CALL PSNAME(FILPS,PSLEN,IPLOT,PLDESC,'ramachand',WITHAN)         RAMA0039
CCHECK v.3.2<--                                                         RAMA0040
CCHECK v.3.1<--                                                         RAMA0041
CCHECK v.3.2-->                                                         RAMA0042
CC      CALL PSOPEN(FILPS,BBOXX1,BBOXX2,BBOXY1,BBOXY2,MXCOLR,RGB,       RAMA0043
CC     -    INCOLR,COLRAM(1))                                           RAMA0044
C      PTITLE = 'Ramachandran plot'                                     RAMA0045
C      CALL PSOPEN(FILPS,MXCOLR,RGB,INCOLR,PTITLE,1)                    RAMA0046
CHECK v.3.4<--                                                          RAMA0047
      CALL PSPAGE(FILPS,BBOXX1,BBOXX2,BBOXY1,BBOXY2,MXCOLR,RGB,         RAMA0048
CHECK v.3.4-->                                                          RAMA0049
C     -    INCOLR,COLRAM(1),1,PLABEL)                                   RAMA0050
     &    INCOLR,COLRAM(1),1,PLABEL,RSELEC)                             RAMA0051
CHECK v.3.4<--                                                          RAMA0052
                                                                        RAMA0053
C---- Print program name in top left-hand corner                        RAMA0054
      IF (NMR) THEN                                                     RAMA0055
          CALL PSTEXT(BBOXX1 + 15.0,BBOXY2 - 10.0,10.0,                 RAMA0056
     &        'PROCHECK-NMR')                                           RAMA0057
      ELSE IF (ENSEMB) THEN                                             RAMA0058
          CALL PSTEXT(BBOXX1 + 15.0,BBOXY2 - 10.0,10.0,                 RAMA0059
     &        'PROCHECK-COMP')                                          RAMA0060
      ELSE                                                              RAMA0061
          CALL PSTEXT(BBOXX1 + 15.0,BBOXY2 - 10.0,10.0,                 RAMA0062
     &        'PROCHECK')                                               RAMA0063
      ENDIF                                                             RAMA0064
CHECK v.3.2<--                                                          RAMA0065
                                                                        RAMA0066
CHECK v.3.4-->                                                          RAMA0067
C---- If splitting Ramachandran plots, print page number                RAMA0068
      IF (RMSPLT) THEN                                                  RAMA0069
          IPAGE = IPAGE + 1                                             RAMA0070
          WRITE(PAGE,120) IPAGE                                         RAMA0071
 120      FORMAT('Page ',I2)                                            RAMA0072
          CALL PSCTXT(BBOXX2 - 40.0,BBOXY2 - 20.0,12.0,PAGE)            RAMA0073
      ENDIF                                                             RAMA0074
CHECK v.3.4<--                                                          RAMA0075
                                                                        RAMA0076
C---- Shade in the different regions of the Ramachandran plot           RAMA0077
      CALL RAMSHD                                                       RAMA0078
                                                                        RAMA0079
C---- Generate axes and labels for Ramachandran plot                    RAMA0080
      CALL RAMAXE                                                       RAMA0081
                                                                        RAMA0082
      RETURN                                                            RAMA0083
      END                                                               RAMA0084
                                                                        RAMA0085
      SUBROUTINE MSTATS(MALLOW,MCORE,MENDCH,MGENER,MGLY,MONPG,MOUTSI,   MSTA0001
     &    MPRO,MRAMPL,MRESID)                                           MSTA0002
C-----------------------------------------------------------------------MSTA0003
CHECK v.3.4-->                                                          MSTA0004
C                                                                       MSTA0005
C  SUBROUTINE MSTATS  -  Calculate Ramachandran plot statistics for currMSTA0006
C                        model only                                     MSTA0007
C                                                                       MSTA0008
C----------------------------------------------------------------------+MSTA0009
                                                                        MSTA0010
WINNT - warning unused dummy argument MRESID                            MSTA0011
WINNT - warning unused dummy argument MRAMPL                            MSTA0012
WINNT - warning unused dummy argument MPRO                              MSTA0013
WINNT - warning unused dummy argument MGLY                              MSTA0014
WINNT - warning unused dummy argument MENDCH                            MSTA0015
WINNT - warning unused dummy argument MRESID                            MSTA0016
      INCLUDE 'tplot.inc'                                               MSTA0017
                                                                        MSTA0018
      INTEGER       MALLOW, MCORE, MENDCH, MGENER, MGLY, MONPG, MOUTSI, MSTA0019
     &              MPRO, MRAMPL, MRESID                                MSTA0020
                                                                        MSTA0021
C---- Calculate percentages for residues in the different regions of theMSTA0022
C     Ramachandran plot                                                 MSTA0023
      IF (NONPG.GT.0) THEN                                              MSTA0024
          ALLOWP = 100.0 * REAL(MALLOW) / REAL(MONPG)                   MSTA0025
          COREPC = 100.0 * REAL(MCORE) / REAL(MONPG)                    MSTA0026
          GENERP = 100.0 * REAL(MGENER) / REAL(MONPG)                   MSTA0027
          OUTSIP = 100.0 * REAL(MOUTSI) / REAL(MONPG)                   MSTA0028
      ELSE                                                              MSTA0029
          ALLOWP = 0.0                                                  MSTA0030
          COREPC = 0.0                                                  MSTA0031
          GENERP = 0.0                                                  MSTA0032
          OUTSIP = 0.0                                                  MSTA0033
      ENDIF                                                             MSTA0034
                                                                        MSTA0035
      RETURN                                                            MSTA0036
      END                                                               MSTA0037
                                                                        MSTA0038
      SUBROUTINE RAMSHD                                                 RAMS0001
C-----------------------------------------------------------------------RAMS0002
CHECK v.3.4<--                                                          RAMS0003
C                                                                       RAMS0004
C  SUBROUTINE RAMSHD  -  Mark the different Ramachandran plot regions, uRAMS0005
C                        lines/borders and lettering, as required       RAMS0006
C                                                                       RAMS0007
C----------------------------------------------------------------------+RAMS0008
                                                                        RAMS0009
      INCLUDE 'tplot.inc'                                               RAMS0010
                                                                        RAMS0011
      INTEGER        MAPSIZ                                             RAMS0012
      PARAMETER     (MAPSIZ = 36)                                       RAMS0013
                                                                        RAMS0014
      REAL           PGAP, XGAP, YGAP                                   RAMS0015
                                                                        RAMS0016
C---- Write out background shade for the plot                           RAMS0017
      CALL PSLWID(0.1)                                                  RAMS0018
      IF (.NOT.NOSHAD) THEN                                             RAMS0019
          CALL PSHADE(0.975,COLRAM(2),RGB,MXCOLR,INCOLR)                RAMS0020
          CALL PSUBOX(XRAMC1,YRAMC1,XRAMC1,YRAMC2,XRAMC2,YRAMC2,        RAMS0021
     &        XRAMC2,YRAMC1)                                            RAMS0022
      ENDIF                                                             RAMS0023
                                                                        RAMS0024
C---- Initialise variables for shading                                  RAMS0025
      PGAP = 360.0 / MAPSIZ                                             RAMS0026
      XGAP = (XRAMC2 - XRAMC1) / MAPSIZ                                 RAMS0027
      YGAP = (YRAMC2 - YRAMC1) / MAPSIZ                                 RAMS0028
                                                                        RAMS0029
C---- Shade in the different regions, if required                       RAMS0030
      CALL RAMFIL(PGAP,XGAP,YGAP)                                       RAMS0031
                                                                        RAMS0032
C---- If borders round regions required, then draw them in              RAMS0033
      IF (.NOT.NOLINE) THEN                                             RAMS0034
          CALL RAMLIN(PGAP,XGAP,YGAP)                                   RAMS0035
      ENDIF                                                             RAMS0036
                                                                        RAMS0037
C---- Print labels for each of the major regions, if required           RAMS0038
      IF (INCLET) THEN                                                  RAMS0039
          CALL RAMLET(XGAP,YGAP)                                        RAMS0040
      ENDIF                                                             RAMS0041
                                                                        RAMS0042
      RETURN                                                            RAMS0043
      END                                                               RAMS0044
                                                                        RAMS0045
      SUBROUTINE RAMFIL(PGAP,XGAP,YGAP)                                 RAMF0001
C-----------------------------------------------------------------------RAMF0002
C                                                                       RAMF0003
C  SUBROUTINE RAMFIL  -  Shade in the different Ramachandran plot regionRAMF0004
C                                                                       RAMF0005
C----------------------------------------------------------------------+RAMF0006
                                                                        RAMF0007
      INCLUDE 'tplot.inc'                                               RAMF0008
                                                                        RAMF0009
      INTEGER        MAPSIZ                                             RAMF0010
      PARAMETER     (MAPSIZ = 36)                                       RAMF0011
                                                                        RAMF0012
      CHARACTER*2    REGION                                             RAMF0013
      INTEGER        I, J, IREG, LSTREG, RCOL(12), REGTYP, RTYPE        RAMF0014
      REAL           COLOUR(3,12), FACTOR(12), PGAP, PHI, PSI,          RAMF0015
     &               SHADE(12), X, XGAP, XLEFT, Y, YGAP, YLEFT          RAMF0016
                                                                        RAMF0017
      DATA FACTOR  / 1.0, 0.95, 1.0, 0.95,0.95, 1.0, 1.0, 1.0,          RAMF0018
     &               1.0,0.95,0.95,0.95 /                               RAMF0019
      DATA RCOL    /   2,   5,   4,    5,   4,   5,   4,   4,           RAMF0020
     &                 3,   3,   3,   3 /                               RAMF0021
      DATA SHADE   / 1.0, 0.45, 0.7, 0.45, 0.6, 0.5, 0.7, 0.7,          RAMF0022
     &               0.9, 0.8, 0.8, 0.8 /                               RAMF0023
                                                                        RAMF0024
                                                                        RAMF0025
C---- If no shading required, then blank out all the different          RAMF0026
C     shade-codes                                                       RAMF0027
      DO 100, I = 1, 12                                                 RAMF0028
          IF (NOSHAD) THEN                                              RAMF0029
              COLOUR(1,I) = 1.0                                         RAMF0030
              COLOUR(2,I) = 1.0                                         RAMF0031
              COLOUR(3,I) = 1.0                                         RAMF0032
              SHADE(I) = 1.0                                            RAMF0033
          ELSE                                                          RAMF0034
              COLOUR(1,I) = FACTOR(I) * RGB(1,COLRAM(RCOL(I)))          RAMF0035
              COLOUR(2,I) = FACTOR(I) * RGB(2,COLRAM(RCOL(I)))          RAMF0036
              COLOUR(3,I) = FACTOR(I) * RGB(3,COLRAM(RCOL(I)))          RAMF0037
          ENDIF                                                         RAMF0038
 100  CONTINUE                                                          RAMF0039
                                                                        RAMF0040
C---- Loop through all the map-points                                   RAMF0041
      CALL PSLWID(0.0)                                                  RAMF0042
      RTYPE = 0                                                         RAMF0043
      Y = YRAMC1                                                        RAMF0044
      PSI = -180.0 + PGAP / 2.0                                         RAMF0045
      DO 300, I = 1, MAPSIZ                                             RAMF0046
          X = XRAMC1                                                    RAMF0047
          XLEFT = X                                                     RAMF0048
          YLEFT = Y                                                     RAMF0049
          LSTREG = 0                                                    RAMF0050
          PHI = -180.0 + PGAP / 2.0                                     RAMF0051
          DO 200, J = 1, MAPSIZ                                         RAMF0052
                                                                        RAMF0053
C----         Determine which region this point is in                   RAMF0054
              CALL RAMREG(PHI,PSI,REGION,IREG,REGTYP)                   RAMF0055
                                                                        RAMF0056
C----         If region is a new one, write out strip corresponding to  RAMF0057
C             previous region                                           RAMF0058
              IF (LSTREG.NE.0 .AND. IREG.NE.LSTREG) THEN                RAMF0059
                                                                        RAMF0060
C----             Write out the appropriate shade                       RAMF0061
                  IF (LSTREG.GT.1) THEN                                 RAMF0062
                      IF (.NOT.CRONLY .OR. RTYPE.EQ.4) THEN             RAMF0063
                          IF (INCOLR) THEN                              RAMF0064
                              CALL PSCOLR(COLOUR(1,LSTREG),             RAMF0065
     &                            COLOUR(2,LSTREG),COLOUR(3,LSTREG))    RAMF0066
                          ELSE                                          RAMF0067
                              CALL PSHADE(SHADE(LSTREG),0,RGB,MXCOLR,   RAMF0068
     &                            INCOLR)                               RAMF0069
                          ENDIF                                         RAMF0070
                          CALL PSUBOX(XLEFT, Y, X, Y, X,                RAMF0071
     &                        Y + YGAP, XLEFT, Y + YGAP)                RAMF0072
                      ENDIF                                             RAMF0073
                  ENDIF                                                 RAMF0074
                  XLEFT = X                                             RAMF0075
              ENDIF                                                     RAMF0076
              LSTREG = IREG                                             RAMF0077
              RTYPE = REGTYP                                            RAMF0078
              X = X + XGAP                                              RAMF0079
              PHI = PHI + PGAP                                          RAMF0080
 200      CONTINUE                                                      RAMF0081
                                                                        RAMF0082
C----     Write out strip corresponding to last region, if required     RAMF0083
          IF (LSTREG.GT.1) THEN                                         RAMF0084
              IF (.NOT.CRONLY .OR. RTYPE.EQ.4) THEN                     RAMF0085
                  IF (INCOLR) THEN                                      RAMF0086
                      CALL PSCOLR(COLOUR(1,LSTREG),                     RAMF0087
     &                    COLOUR(2,LSTREG),COLOUR(3,LSTREG))            RAMF0088
                  ELSE                                                  RAMF0089
                      CALL PSHADE(SHADE(LSTREG),0,RGB,MXCOLR,           RAMF0090
     &                    INCOLR)                                       RAMF0091
                  ENDIF                                                 RAMF0092
                  CALL PSUBOX(XLEFT, Y, X, Y, X,                        RAMF0093
     &                Y + YGAP, XLEFT, Y + YGAP)                        RAMF0094
              ENDIF                                                     RAMF0095
          ENDIF                                                         RAMF0096
                                                                        RAMF0097
C----     Increment y-value                                             RAMF0098
          Y = Y + YGAP                                                  RAMF0099
          PSI = PSI + PGAP                                              RAMF0100
 300  CONTINUE                                                          RAMF0101
                                                                        RAMF0102
      RETURN                                                            RAMF0103
      END                                                               RAMF0104
                                                                        RAMF0105
      SUBROUTINE RAMLIN(PGAP,XGAP,YGAP)                                 RAML0001
C-----------------------------------------------------------------------RAML0002
C                                                                       RAML0003
C  SUBROUTINE RAMLIN  -  Draw in the lines separating the different     RAML0004
C                        Ramachandran plot regions                      RAML0005
C                                                                       RAML0006
C----------------------------------------------------------------------+RAML0007
                                                                        RAML0008
      INCLUDE 'tplot.inc'                                               RAML0009
                                                                        RAML0010
      INTEGER        MAPSIZ, NHATCH                                     RAML0011
      PARAMETER     (MAPSIZ = 36, NHATCH=50)                            RAML0012
                                                                        RAML0013
      CHARACTER*2    REGION                                             RAML0014
      INTEGER        I, J, IREG, ITYPE, LSTREG, LTYPE(MAPSIZ), REGTYP   RAML0015
      REAL           PGAP, PHI, PSI, X, XGAP, Y, YGAP                   RAML0016
                                                                        RAML0017
C---- Initialise region-types (ie core, allowed, generous, disallowed)  RAML0018
      DO 100, I = 1, MAPSIZ                                             RAML0019
          LTYPE(I) = 0                                                  RAML0020
 100  CONTINUE                                                          RAML0021
                                                                        RAML0022
C---- Loop through all the map-points                                   RAML0023
      IF (NOSHAD) THEN                                                  RAML0024
          CALL PSLWID(0.2)                                              RAML0025
      ELSE                                                              RAML0026
          CALL PSLWID(0.8)                                              RAML0027
      ENDIF                                                             RAML0028
      Y = YRAMC1                                                        RAML0029
      PSI = -180.0 + PGAP / 2.0                                         RAML0030
      DO 300, I = 1, MAPSIZ                                             RAML0031
          X = XRAMC1                                                    RAML0032
          LSTREG = 0                                                    RAML0033
          PHI = -180.0 + PGAP / 2.0                                     RAML0034
          DO 200, J = 1, MAPSIZ                                         RAML0035
                                                                        RAML0036
C----         Determine which region this point is in                   RAML0037
              CALL RAMREG(PHI,PSI,REGION,IREG,REGTYP)                   RAML0038
                                                                        RAML0039
C----         Determine region-type                                     RAML0040
              ITYPE = REGTYP                                            RAML0041
                                                                        RAML0042
C----         If region is a new one, then may need to draw a line betweRAML0043
C             it and the last                                           RAML0044
              IF (J.GT.1 .AND. ITYPE.NE.LTYPE(J - 1)) THEN              RAML0045
                                                                        RAML0046
C----             Write out the appropriate line                        RAML0047
                  IF (NOSHAD .OR. ITYPE.LT.LTYPE(J - 1)) THEN           RAML0048
                      IF (.NOT.CRONLY .OR. (ITYPE.EQ.4 .OR.             RAML0049
     &                    LTYPE(J - 1).EQ.4)) THEN                      RAML0050
                          CALL PSLINE(X, Y, X, Y + YGAP)                RAML0051
                      ENDIF                                             RAML0052
                  ENDIF                                                 RAML0053
              ENDIF                                                     RAML0054
                                                                        RAML0055
C----         Check whether to draw line between region and one above itRAML0056
              IF (I.GT.1) THEN                                          RAML0057
                  IF (ITYPE.NE.LTYPE(J)) THEN                           RAML0058
                      IF (NOSHAD .OR. ITYPE.GT.LTYPE(J)) THEN           RAML0059
                          IF (.NOT.CRONLY .OR. (ITYPE.EQ.4 .OR.         RAML0060
     &                        LTYPE(J).EQ.4)) THEN                      RAML0061
                              CALL PSLINE(X, Y, X + XGAP, Y)            RAML0062
                          ENDIF                                         RAML0063
                      ENDIF                                             RAML0064
                  ENDIF                                                 RAML0065
              ENDIF                                                     RAML0066
                                                                        RAML0067
C----         Store current details and prepare for next square         RAML0068
              LSTREG = IREG                                             RAML0069
              LTYPE(J) = ITYPE                                          RAML0070
              X = X + XGAP                                              RAML0071
              PHI = PHI + PGAP                                          RAML0072
 200      CONTINUE                                                      RAML0073
                                                                        RAML0074
C----     Increment y-value                                             RAML0075
          Y = Y + YGAP                                                  RAML0076
          PSI = PSI + PGAP                                              RAML0077
 300  CONTINUE                                                          RAML0078
                                                                        RAML0079
      RETURN                                                            RAML0080
      END                                                               RAML0081
                                                                        RAML0082
      SUBROUTINE RAMLET(XGAP,YGAP)                                      RAML0001
C-----------------------------------------------------------------------RAML0002
C                                                                       RAML0003
C  SUBROUTINE RAMLET  -  Write in the letter-codes identifying the      RAML0004
C                        different Ramachandran plot regions            RAML0005
C                                                                       RAML0006
C----------------------------------------------------------------------+RAML0007
                                                                        RAML0008
      INCLUDE 'tplot.inc'                                               RAML0009
                                                                        RAML0010
      REAL          XGAP, YGAP                                          RAML0011
                                                                        RAML0012
C---- Print labels for each of the major regions                        RAML0013
                                                                        RAML0014
C---- Core regions                                                      RAML0015
      CALL PSCTXT(XRAMC1 +  2.0 * XGAP,YRAMC2 -  1.0 * YGAP,15.0,'B')   RAML0016
      CALL PSCTXT(XRAMC1 +  7.0 * XGAP,YRAMC2 - 17.0 * YGAP,15.0,'A')   RAML0017
      CALL PSCTXT(XRAMC1 + 23.5 * XGAP,YRAMC2 - 13.5 * YGAP,10.0,'L')   RAML0018
                                                                        RAML0019
C---- Other regions, of required                                        RAML0020
      IF (CRONLY) GO TO 999                                             RAML0021
      CALL PSCTXT(XRAMC1 +  1.0 * XGAP,YRAMC2 -  5.0 * YGAP,15.0,'b')   RAML0022
      CALL PSCTXT(XRAMC1 +  2.0 * XGAP,YRAMC2 - 15.0 * YGAP,15.0,'a')   RAML0023
      CALL PSCTXT(XRAMC1 + 21.5 * XGAP,YRAMC2 - 10.0 * YGAP,10.0,'l')   RAML0024
      CALL PSCTXT(XRAMC1 + 23.5 * XGAP,YRAMC2 - 33.0 * YGAP,10.0,'p')   RAML0025
      CALL PSCTXT(XRAMC1 + 21.5 * XGAP,YRAMC2 - 31.0 * YGAP,10.0,'~p')  RAML0026
      CALL PSCTXT(XRAMC1 + 16.5 * XGAP,YRAMC2 -  5.0 * YGAP,10.0,'~b')  RAML0027
      CALL PSCTXT(XRAMC1 + 16.5 * XGAP,YRAMC2 - 19.5 * YGAP,10.0,'~a')  RAML0028
      CALL PSCTXT(XRAMC1 + 22.5 * XGAP,YRAMC2 -  7.0 * YGAP,10.0,'~l')  RAML0029
      CALL PSCTXT(XRAMC1 +  2.0 * XGAP,YRAMC2 - 33.0 * YGAP,10.0,'b')   RAML0030
      CALL PSCTXT(XRAMC1 +  0.5 * XGAP,YRAMC2 - 31.0 * YGAP,10.0,'~b')  RAML0031
      CALL PSCTXT(XRAMC1 + 35.0 * XGAP,YRAMC2 -  2.0 * YGAP,10.0,'b')   RAML0032
      CALL PSCTXT(XRAMC1 + 31.5 * XGAP,YRAMC2 -  1.0 * YGAP,10.0,'~b')  RAML0033
      CALL PSCTXT(XRAMC1 + 33.5 * XGAP,YRAMC2 - 34.0 * YGAP,10.0,'~b')  RAML0034
                                                                        RAML0035
 999  CONTINUE                                                          RAML0036
      RETURN                                                            RAML0037
      END                                                               RAML0038
                                                                        RAML0039
      SUBROUTINE RAMAXE                                                 RAMA0001
C-----------------------------------------------------------------------RAMA0002
C                                                                       RAMA0003
C  SUBROUTINE RAMAXE  -  Draw axes and axis-labels of Ramachandran plot,RAMA0004
C                        writing out to PostScript file                 RAMA0005
C                                                                       RAMA0006
C----------------------------------------------------------------------+RAMA0007
                                                                        RAMA0008
      INCLUDE 'tplot.inc'                                               RAMA0009
                                                                        RAMA0010
      REAL           XCENTR, YCENTR                                     RAMA0011
                                                                        RAMA0012
C---- Initialise variables                                              RAMA0013
      XCENTR = (XRAMC1 + XRAMC2) / 2.0                                  RAMA0014
      YCENTR = (YRAMC1 + YRAMC2) / 2.0                                  RAMA0015
                                                                        RAMA0016
C---- Draw box round graph and label axes                               RAMA0017
      CALL AXES(XRAMC1,XRAMC2,YRAMC1,YRAMC2,8,8,-180.0,180.0,           RAMA0018
     &    -180.0,180.0,15.0,0,0,22.0,.TRUE.,.TRUE.,.FALSE.,.FALSE.,     RAMA0019
     &    .FALSE.)                                                      RAMA0020
                                                                        RAMA0021
C---- Draw axes                                                         RAMA0022
      CALL PSLWID(0.2)                                                  RAMA0023
      CALL PSDASH(1)                                                    RAMA0024
      CALL PSLINE(XCENTR,YRAMC1,XCENTR,YRAMC2)                          RAMA0025
      CALL PSLINE(XRAMC1,YCENTR,XRAMC2,YCENTR)                          RAMA0026
      CALL PSDASH(0)                                                    RAMA0027
                                                                        RAMA0028
C---- Graph heading and x-axis title                                    RAMA0029
CHECK v.3.2-->                                                          RAMA0030
C      CALL PSCTXT(XCENTR,YRAMC2 + 45.0,30.0,'Ramachandran Plot')       RAMA0031
      IF (ENSEMB) THEN                                                  RAMA0032
          CALL PSCTXT(XCENTR,YRAMC2 + 45.0,30.0,                        RAMA0033
     &        'Ensemble Ramachandran Plot')                             RAMA0034
      ELSE                                                              RAMA0035
          CALL PSCTXT(XCENTR,YRAMC2 + 45.0,30.0,'Ramachandran Plot')    RAMA0036
      ENDIF                                                             RAMA0037
CHECK v.3.2<--                                                          RAMA0038
CHECK v.3.4-->                                                          RAMA0039
C      CALL PSCTXT(XCENTR,YRAMC2 + 16.0,25.0,BRCODE(1:BLEN))            RAMA0040
      CALL PSCTXT(XCENTR,YRAMC2 + 16.0,25.0,RAMHED(1:RLEN + 2))         RAMA0041
CHECK v.3.4<--                                                          RAMA0042
      CALL PSCTXT(XCENTR,YRAMC1 - 30.0,15.0,'Phi (degrees)')            RAMA0043
                                                                        RAMA0044
C---- y-axis title                                                      RAMA0045
      CALL PSRTXT(XRAMC1 - 48.0,YCENTR,15.0,'Psi (degrees)')            RAMA0046
                                                                        RAMA0047
C---- Set line-thickness for point-markers                              RAMA0048
      CALL PSLWID(0.2)                                                  RAMA0049
                                                                        RAMA0050
      RETURN                                                            RAMA0051
      END                                                               RAMA0052
                                                                        RAMA0053
      SUBROUTINE RAMPLT(PHI,PSI,RESDUE,RTYPE,SEQNO,IMODEL,RLABEL,INCHN) RAMP0001
C-----------------------------------------------------------------------RAMP0002
C                                                                       RAMP0003
C  SUBROUTINE RAMPLT  -  Print point on Ramachandran plot               RAMP0004
C                                                                       RAMP0005
C----------------------------------------------------------------------+RAMP0006
                                                                        RAMP0007
CHECK v.3.2-->                                                          RAMP0008
C      SUBROUTINE RAMPLT(PHI,PSI,RESDUE,RTYPE,SEQNO)                    RAMP0009
CHECK v.3.2<--                                                          RAMP0010
                                                                        RAMP0011
      INCLUDE 'tplot.inc'                                               RAMP0012
                                                                        RAMP0013
CHECK v.3.2-->                                                          RAMP0014
C      CHARACTER*3   RESDUE                                             RAMP0015
      CHARACTER*1   INCHN                                               RAMP0016
      CHARACTER*3   NUMBER, RESDUE                                      RAMP0017
CHECK v.3.2<--                                                          RAMP0018
      CHARACTER*5   SEQNO                                               RAMP0019
CHECK v.3.2-->                                                          RAMP0020
C      CHARACTER*5   SEQNO                                              RAMP0021
C      INTEGER       RTYPE                                              RAMP0022
C      REAL          PHI, PSI, SHADE, X, Y                              RAMP0023
      CHARACTER*13  STRING                                              RAMP0024
      INTEGER       ICOLR, IMODEL, IPOS, LEN, RLABEL, RTYPE             RAMP0025
      REAL          DX, DY, PHI, PSI, SHADE, TSIZE, X, Y                RAMP0026
CHECK v.3.2<--                                                          RAMP0027
                                                                        RAMP0028
C---- Calculate appropriate position on graph                           RAMP0029
      X = XRAMC1 + (XRAMC2 - XRAMC1) * (PHI + 180.0) / 360.0            RAMP0030
      Y = YRAMC1 + (YRAMC2 - YRAMC1) * (PSI + 180.0) / 360.0            RAMP0031
                                                                        RAMP0032
C---- Adjust colour of marker, as appropriate                           RAMP0033
      IF (INCOLR) THEN                                                  RAMP0034
          IF (RTYPE.LE.LABRES + 1 .AND. RESDUE.NE.'GLY') THEN           RAMP0035
              CALL PSCOLB(RGB(1,COLRAM(7)),RGB(2,COLRAM(7)),            RAMP0036
     &            RGB(3,COLRAM(7)))                                     RAMP0037
CHECK v.3.4-->                                                          RAMP0038
              ICOLR = COLRAM(7)                                         RAMP0039
CHECK v.3.4<--                                                          RAMP0040
          ELSE                                                          RAMP0041
              CALL PSCOLB(RGB(1,COLRAM(6)),RGB(2,COLRAM(6)),            RAMP0042
     &            RGB(3,COLRAM(6)))                                     RAMP0043
CHECK v.3.4-->                                                          RAMP0044
              ICOLR = COLRAM(6)                                         RAMP0045
CHECK v.3.4<--                                                          RAMP0046
          ENDIF                                                         RAMP0047
      ENDIF                                                             RAMP0048
                                                                        RAMP0049
C---- Plot appropriate marker depending on whether glycine or otherwise RAMP0050
CHECK v.3.2-->                                                          RAMP0051
C      IF (RESDUE.EQ.'GLY') THEN                                        RAMP0052
C          CALL PSMARK(X,Y,2,HWIDX,HWIDY)                               RAMP0053
C      ELSE                                                             RAMP0054
C          IF (RTYPE.EQ.1) THEN                                         RAMP0055
C              CALL PSMARK(X,Y,3,HWIDX,HWIDY)                           RAMP0056
C          ELSE                                                         RAMP0057
C              CALL PSMARK(X,Y,1,HWIDX,HWIDY)                           RAMP0058
C          ENDIF                                                        RAMP0059
C      ENDIF                                                            RAMP0060
                                                                        RAMP0061
C---- For ensembles, print empty squares and boxes                      RAMP0062
CHECK v.3.4-->                                                          RAMP0063
C      IF ((ENSEMB .OR. NMR) .AND. NFILE.GT.1) THEN                     RAMP0064
C          SHADE = 1.0                                                  RAMP0065
C          ICOLR = COLRAM(1)                                            RAMP0066
C          DX = 2.0 * HWIDX                                             RAMP0067
C          DY = 2.0 * HWIDY                                             RAMP0068
      IF ((ENSEMB .OR. NMR) .AND. NMODEL.GT.1) THEN                     RAMP0069
          DX = 2.0 * HWIDX * RBXSIZ                                     RAMP0070
          DY = 2.0 * HWIDY * RBXSIZ                                     RAMP0071
          IF (RBXFIL) THEN                                              RAMP0072
              SHADE = 0.0                                               RAMP0073
              ICOLR = COLRAM(7)                                         RAMP0074
          ELSE                                                          RAMP0075
              SHADE = 1.0                                               RAMP0076
              ICOLR = COLRAM(1)                                         RAMP0077
          ENDIF                                                         RAMP0078
CHECK v.3.4<--                                                          RAMP0079
                                                                        RAMP0080
C---- For single structure, print filled-in squares and triangles       RAMP0081
      ELSE                                                              RAMP0082
          SHADE = 0.0                                                   RAMP0083
CHECK v.3.4-->                                                          RAMP0084
C          ICOLR = COLRAM(7)                                            RAMP0085
C          DX = HWIDX                                                   RAMP0086
C          DY = HWIDY                                                   RAMP0087
          DX = HWIDX * RBXSIZ                                           RAMP0088
          DY = HWIDY * RBXSIZ                                           RAMP0089
CHECK v.3.4<--                                                          RAMP0090
      ENDIF                                                             RAMP0091
                                                                        RAMP0092
C---- Plot the marker                                                   RAMP0093
      CALL PSLWID(0.2)                                                  RAMP0094
      CALL PSHADE(SHADE,ICOLR,RGB,MXCOLR,INCOLR)                        RAMP0095
      IF (RESDUE.EQ.'GLY') THEN                                         RAMP0096
          CALL PSTRIA(X - DX,Y - 0.6 * DY,                              RAMP0097
     &        X + DX,Y - 0.6 * DY,X,Y + 1.2 * DY)                       RAMP0098
      ELSE                                                              RAMP0099
          CALL PSBBOX(X - DX,Y - DY,X - DX,Y + DY,                      RAMP0100
     &                X + DX,Y + DY,X + DX,Y - DY)                      RAMP0101
      ENDIF                                                             RAMP0102
                                                                        RAMP0103
C---- For ensembles, print the model number inside the marker           RAMP0104
CHECK v.3.4-->                                                          RAMP0105
C      IF ((ENSEMB .OR. NMR) .AND. NFILE.GT.1) THEN                     RAMP0106
      IF ((ENSEMB .OR. NMR) .AND. RBXMOD .AND. NMODEL.GT.1) THEN        RAMP0107
CHECK v.3.4<--                                                          RAMP0108
          WRITE(NUMBER,110) IMODEL                                      RAMP0109
 110      FORMAT(I3)                                                    RAMP0110
          IF (NUMBER(2:2).EQ.' ') THEN                                  RAMP0111
              IPOS = 3                                                  RAMP0112
          ELSE IF (NUMBER(1:1).EQ.' ') THEN                             RAMP0113
              IPOS = 2                                                  RAMP0114
          ELSE                                                          RAMP0115
              IPOS = 1                                                  RAMP0116
          ENDIF                                                         RAMP0117
CHECK v.3.4-->                                                          RAMP0118
C          IF (NFILE.LT.10) THEN                                        RAMP0119
          IF (TOPMOD.LT.10) THEN                                        RAMP0120
CHECK v.3.4<--                                                          RAMP0121
              TSIZE = 8.0                                               RAMP0122
          ELSE                                                          RAMP0123
              TSIZE = 5.0                                               RAMP0124
          ENDIF                                                         RAMP0125
          IF (RESDUE.EQ.'GLY') TSIZE = TSIZE * 0.75                     RAMP0126
CHECK v.3.4-->                                                          RAMP0127
          TSIZE = TSIZE * RBXSIZ                                        RAMP0128
CHECK v.3.4<--                                                          RAMP0129
          CALL PSCTXT(X,Y,TSIZE,NUMBER(IPOS:))                          RAMP0130
      ENDIF                                                             RAMP0131
CHECK v.3.2<--                                                          RAMP0132
                                                                        RAMP0133
C---- Label point, if necessary                                         RAMP0134
      IF (RTYPE.LE.LABRES + 1 .AND. RESDUE.NE.'GLY') THEN               RAMP0135
CHECK v.3.2-->                                                          RAMP0136
C          CALL PSCTXT(X,Y + 3.5 * DY,10.0,RESDUE // SEQNO)             RAMP0137
          IF (SEQNO(3:3).EQ.' ') THEN                                   RAMP0138
              IPOS = 4                                                  RAMP0139
          ELSE IF (SEQNO(2:2).EQ.' ') THEN                              RAMP0140
              IPOS = 3                                                  RAMP0141
          ELSE IF (SEQNO(1:1).EQ.' ') THEN                              RAMP0142
              IPOS = 2                                                  RAMP0143
          ELSE                                                          RAMP0144
              IPOS = 1                                                  RAMP0145
          ENDIF                                                         RAMP0146
          STRING = RESDUE // ' ' // SEQNO(IPOS:)                        RAMP0147
          LEN = 4 + (6 - IPOS)                                          RAMP0148
          IF (INCHN.NE.' ') THEN                                        RAMP0149
              STRING(LEN+1:LEN+3) = '(' // INCHN // ')'                 RAMP0150
              LEN = LEN + 3                                             RAMP0151
          ENDIF                                                         RAMP0152
          CALL PSCTXT(X,Y + 3.5 * DY,10.0,STRING(1:LEN))                RAMP0153
          RLABEL = RLABEL + 1                                           RAMP0154
CHECK v.3.2<--                                                          RAMP0155
      ENDIF                                                             RAMP0156
                                                                        RAMP0157
C---- Reset background colour to black                                  RAMP0158
      IF (INCOLR) CALL PSCOLB(0.0,0.0,0.0)                              RAMP0159
                                                                        RAMP0160
      RETURN                                                            RAMP0161
      END                                                               RAMP0162
                                                                        RAMP0163
      SUBROUTINE RAMEND(BBOXX1,BBOXX2,BBOXY1,BBOXY2,MALLOW,MCORE,MENDCH,RAME0001
     &    MGENER,MGLY,MONPG,MOUTSI,MPRO,MRAMPL,MRESID)                  RAME0002
C-----------------------------------------------------------------------RAME0003
C                                                                       RAME0004
C  SUBROUTINE RAMEND  -  Print statistics for Ramachandran plot         RAME0005
C                                                                       RAME0006
C----------------------------------------------------------------------+RAME0007
                                                                        RAME0008
WINNT - warning unused dummy argument BBOXX1                            RAME0009
WINNT - warning unused dummy argument BBOXY1                            RAME0010
WINNT - warning unused dummy argument BBOXX2                            RAME0011
WINNT - warning unused dummy argument BBOXY2                            RAME0012
CHECK v.3.4-->                                                          RAME0013
C      SUBROUTINE RAMEND(BBOXX1,BBOXX2,BBOXY1,BBOXY2)                   RAME0014
CHECK v.3.4<--                                                          RAME0015
                                                                        RAME0016
CHECK v.3.0.1-->                                                        RAME0017
C      REAL           BBOXX1, BBOXX2, BBOXY1, BBOXY2                    RAME0018
      INTEGER        BBOXX1, BBOXX2, BBOXY1, BBOXY2                     RAME0019
CHECK v.3.4-->                                                          RAME0020
      INTEGER       MALLOW, MCORE, MENDCH, MGENER, MGLY, MONPG, MOUTSI, RAME0021
     &              MPRO, MRAMPL, MRESID                                RAME0022
CHECK v.3.4<--                                                          RAME0023
CHECK v.3.0.1<--                                                        RAME0024
                                                                        RAME0025
C---- Print the overall statistics on the Ramachandran plot             RAME0026
CHECK v.3.4-->                                                          RAME0027
C      CALL RMSTAT                                                      RAME0028
      CALL RMSTAT(MALLOW,MCORE,MENDCH,MGENER,MGLY,MONPG,MOUTSI,         RAME0029
     &    MPRO,MRAMPL,MRESID)                                           RAME0030
CHECK v.3.4<--                                                          RAME0031
                                                                        RAME0032
C---- End of PostScript file                                            RAME0033
CHECK v.3.2-->                                                          RAME0034
      CALL PSENDP                                                       RAME0035
CHECK v.3.2<--                                                          RAME0036
CHECK v.3.4-->                                                          RAME0037
C      CALL PSCLOS(BBOXX1,BBOXX2,BBOXY1,BBOXY2)                         RAME0038
CHECK v.3.4<--                                                          RAME0039
                                                                        RAME0040
      RETURN                                                            RAME0041
      END                                                               RAME0042
                                                                        RAME0043
      SUBROUTINE RMSTAT(MALLOW,MCORE,MENDCH,MGENER,MGLY,MONPG,MOUTSI,   RMST0001
     &    MPRO,MRAMPL,MRESID)                                           RMST0002
C-----------------------------------------------------------------------RMST0003
C                                                                       RMST0004
C  SUBROUTINE RMSTAT  -  Print the overall statistics on the RamachandraRMST0005
C                        plot                                           RMST0006
C                                                                       RMST0007
C----------------------------------------------------------------------+RMST0008
                                                                        RMST0009
WINNT - warning unused dummy argument MRESID                            RMST0010
WINNT - warning unused dummy argument MRAMPL                            RMST0011
CHECK v.3.4-->                                                          RMST0012
C      SUBROUTINE RMSTAT                                                RMST0013
CHECK v.3.4<--                                                          RMST0014
                                                                        RMST0015
      INCLUDE 'tplot.inc'                                               RMST0016
                                                                        RMST0017
      CHARACTER*100 IREC                                                RMST0018
CHECK v.3.4-->                                                          RMST0019
C      INTEGER       NTOTAL                                             RMST0020
      INTEGER       MALLOW, MCORE, MENDCH, MGENER, MGLY, MONPG, MOUTSI, RMST0021
     &              MPRO, MRAMPL, MRESID, NTOTAL                        RMST0022
CHECK v.3.4<--                                                          RMST0023
CHECK v.3.4-->                                                          RMST0024
C      REAL          X, XCENTR, XPOS1, XPOS2, XSTART, Y, YCENTR, YGAP,  RMST0025
C     -              YSTART                                             RMST0026
      REAL          X, XCENTR, XFPOS1, XFPOS2, XPOS1, XPOS2, XSTART, Y, RMST0027
     &              YCENTR, YGAP, YSTART                                RMST0028
CHECK v.3.4<--                                                          RMST0029
                                                                        RMST0030
CHECK v.3.4-->                                                          RMST0031
C      DATA XSTART, XPOS1, XPOS2, YGAP / 50.0, 300.0, 340.0, 10.0 /     RMST0032
      DATA XSTART, XFPOS1, XFPOS2, YGAP / 50.0, 300.0, 340.0, 10.0 /    RMST0033
CHECK v.3.4<--                                                          RMST0034
                                                                        RMST0035
C---- Initialise variables                                              RMST0036
CHECK v.3.4-->                                                          RMST0037
C      NTOTAL = NCORE + NALLOW + NGENER + NOUTSI + NGLY + NPRO + NENDCH RMST0038
      NTOTAL = MCORE + MALLOW + MGENER + MOUTSI + MGLY + MPRO + MENDCH  RMST0039
CHECK v.3.4<--                                                          RMST0040
      XCENTR = (XRAMC1 + XRAMC2) / 2.0                                  RMST0041
      YCENTR = (YRAMC1 + YRAMC2) / 2.0                                  RMST0042
      X = XRAMC1 + XSTART                                               RMST0043
CHECK v.3.4-->                                                          RMST0044
C      XPOS1 = XPOS1 + XRAMC1                                           RMST0045
C      XPOS2 = XPOS2 + XRAMC1                                           RMST0046
      XPOS1 = XFPOS1 + XRAMC1                                           RMST0047
      XPOS2 = XFPOS2 + XRAMC1                                           RMST0048
CHECK v.3.4<--                                                          RMST0049
      YSTART = YRAMC1 - 52.0                                            RMST0050
      Y = YSTART                                                        RMST0051
                                                                        RMST0052
C---- Print statistics                                                  RMST0053
      CALL PSCTXT(XCENTR,Y,12.0,'Plot statistics')                      RMST0054
      Y = Y - 2 * YGAP                                                  RMST0055
                                                                        RMST0056
C---- Numbers in each of the four different region types                RMST0057
CHECK v.3.4-->                                                          RMST0058
C      WRITE(IREC,100) NCORE, COREPC                                    RMST0059
      WRITE(IREC,100) MCORE, COREPC                                     RMST0060
CHECK v.3.4<--                                                          RMST0061
 100  FORMAT('Residues in most favoured regions  [A,B,L]           ',   RMST0062
     &    I6,6X,F5.1,'%')                                               RMST0063
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0064
CHECK v.3.4-->                                                          RMST0065
C      WRITE(IREC,120) NALLOW, ALLOWP                                   RMST0066
      WRITE(IREC,120) MALLOW, ALLOWP                                    RMST0067
CHECK v.3.4<--                                                          RMST0068
 120  FORMAT('Residues in additional allowed regions  [a,b,l,p]    ',   RMST0069
     &    I6,6X,F5.1,'%')                                               RMST0070
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0071
CHECK v.3.4-->                                                          RMST0072
C      WRITE(IREC,140) NGENER, GENERP                                   RMST0073
      WRITE(IREC,140) MGENER, GENERP                                    RMST0074
CHECK v.3.4<--                                                          RMST0075
 140  FORMAT('Residues in generously allowed regions  [~a,~b,~l,~p]',   RMST0076
     &    I6,6X,F5.1,'%')                                               RMST0077
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0078
CHECK v.3.4-->                                                          RMST0079
C      WRITE(IREC,160) NOUTSI, OUTSIP                                   RMST0080
      WRITE(IREC,160) MOUTSI, OUTSIP                                    RMST0081
CHECK v.3.4<--                                                          RMST0082
 160  FORMAT('Residues in disallowed regions                       ',   RMST0083
     &    I6,6X,F5.1,'%')                                               RMST0084
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0085
      WRITE(IREC,180)                                                   RMST0086
 180  FORMAT(55X,'----',6X,'------')                                    RMST0087
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0088
CHECK v.3.4-->                                                          RMST0089
C      WRITE(IREC,200) NONPG, 100.0                                     RMST0090
      WRITE(IREC,200) MONPG, 100.0                                      RMST0091
CHECK v.3.4<--                                                          RMST0092
 200  FORMAT('Number of non-glycine and non-proline residues       ',   RMST0093
     &    I6,6X,F5.1,'%')                                               RMST0094
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0095
      Y = Y - YGAP / 2.0                                                RMST0096
                                                                        RMST0097
C---- Numbers of end-residues                                           RMST0098
CHECK v.3.4-->                                                          RMST0099
C      WRITE(IREC,300) NENDCH                                           RMST0100
      WRITE(IREC,300) MENDCH                                            RMST0101
CHECK v.3.4<--                                                          RMST0102
 300  FORMAT('Number of end-residues (excl. Gly and Pro)           ',   RMST0103
     &    I6)                                                           RMST0104
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0105
      Y = Y - YGAP / 2.0                                                RMST0106
                                                                        RMST0107
C---- Numbers oF glycines and prolines                                  RMST0108
CHECK v.3.4-->                                                          RMST0109
C      WRITE(IREC,320) NGLY                                             RMST0110
      WRITE(IREC,320) MGLY                                              RMST0111
CHECK v.3.4<--                                                          RMST0112
 320  FORMAT('Number of glycine residues (shown as triangles)      ',   RMST0113
     &    I6)                                                           RMST0114
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0115
CHECK v.3.4-->                                                          RMST0116
C      WRITE(IREC,340) NPRO                                             RMST0117
      WRITE(IREC,340) MPRO                                              RMST0118
CHECK v.3.4<--                                                          RMST0119
 340  FORMAT('Number of proline residues                           ',   RMST0120
     &    I6)                                                           RMST0121
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0122
      WRITE(IREC,360)                                                   RMST0123
 360  FORMAT(55X,'----')                                                RMST0124
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0125
      WRITE(IREC,380) NTOTAL                                            RMST0126
 380  FORMAT('Total number of residues                             ',   RMST0127
     &    I6)                                                           RMST0128
      CALL RAMPUT(X,XPOS1,XPOS2,Y,YGAP,IREC)                            RMST0129
      Y = Y - 2.0 * YGAP                                                RMST0130
                                                                        RMST0131
C---- Print final explanatory text                                      RMST0132
      IREC = 'Based on an analysis of 118 structures'//                 RMST0133
     &    ' of resolution of at least 2.0 Angstroms'                    RMST0134
      CALL PSCTXT(XCENTR,Y,8.0,IREC(1:78))                              RMST0135
      Y = Y - YGAP                                                      RMST0136
      IREC = 'and R-factor no greater than 20%,' //                     RMST0137
     &    ' a good quality model would be expected'                     RMST0138
      CALL PSCTXT(XCENTR,Y,8.0,IREC(1:73))                              RMST0139
      Y = Y - YGAP                                                      RMST0140
      IREC = 'to have over 90% in the most favoured regions.'           RMST0141
      CALL PSCTXT(XCENTR,Y,8.0,IREC(1:46))                              RMST0142
                                                                        RMST0143
CHECK v.3.2-->                                                          RMST0144
CHECK v.3.4-->                                                          RMST0145
C      IF ((ENSEMB .OR. NMR) .AND. NFILE.GT.1) THEN                     RMST0146
      IF ((ENSEMB .OR. NMR) .AND. NMODEL.GT.1) THEN                     RMST0147
CHECK v.3.4<--                                                          RMST0148
          Y = Y - YGAP                                                  RMST0149
          IREC = 'Model numbers shown inside each data point.'          RMST0150
          CALL PSCTXT(XCENTR,Y,8.0,IREC(1:43))                          RMST0151
      ENDIF                                                             RMST0152
CHECK v.3.2<--                                                          RMST0153
                                                                        RMST0154
      RETURN                                                            RMST0155
      END                                                               RMST0156
                                                                        RMST0157
      SUBROUTINE RAMPUT(X,X1,X2,Y,YGAP,IREC)                            RAMP0001
C-----------------------------------------------------------------------RAMP0002
C                                                                       RAMP0003
C  SUBROUTINE RAMPUT  -  Print statistics line for Ramachandran plot    RAMP0004
C                                                                       RAMP0005
C----------------------------------------------------------------------+RAMP0006
                                                                        RAMP0007
      CHARACTER*(*) IREC                                                RAMP0008
      REAL          X, X1, X2, Y, YGAP                                  RAMP0009
                                                                        RAMP0010
C---- Print the text and numbers                                        RAMP0011
      CALL PSTEXT(X,Y,9.0,IREC(1:53))                                   RAMP0012
      CALL PSCTXT(X1,Y,9.0,IREC(54:59))                                 RAMP0013
      CALL PSCTXT(X2,Y,9.0,IREC(66:71))                                 RAMP0014
                                                                        RAMP0015
C---- Increment y-value                                                 RAMP0016
      Y = Y - YGAP                                                      RAMP0017
                                                                        RAMP0018
      RETURN                                                            RAMP0019
      END                                                               RAMP0020
                                                                        RAMP0021
      SUBROUTINE FILKEY(XSTART,YSTART,DX,DY,TBIG,TSMALL)                FILK0001
C-----------------------------------------------------------------------FILK0002
CHECK v.3.2-->                                                          FILK0003
C                                                                       FILK0004
C  SUBROUTINE FILKEY  -  Print out a key cross-referencing the model    FILK0005
C                        numbers to the corresponding filenames         FILK0006
C                                                                       FILK0007
C----------------------------------------------------------------------+FILK0008
                                                                        FILK0009
      INCLUDE 'tplot.inc'                                               FILK0010
                                                                        FILK0011
      CHARACTER*3   NUMBER                                              FILK0012
      INTEGER       IFILE, IPOS                                         FILK0013
      REAL          DX, DY, TBIG, TSIZE, TSMALL, X, XSEP, XSTART, Y,    FILK0014
     &              YSEP, YSTART                                        FILK0015
                                                                        FILK0016
C---- Initialise coordinate positions and text size                     FILK0017
      X = XSTART                                                        FILK0018
      Y = YSTART                                                        FILK0019
      XSEP = 2.0 * DX                                                   FILK0020
      IF (NFILE.LT.30) THEN                                             FILK0021
          YSEP = DY                                                     FILK0022
      ELSE                                                              FILK0023
          YSEP = 0.5 * DY                                               FILK0024
      ENDIF                                                             FILK0025
CHECK v.3.4-->                                                          FILK0026
C      IF (NFILE.LT.10) THEN                                            FILK0027
      IF (TOPMOD.LT.10) THEN                                            FILK0028
CHECK v.3.4<--                                                          FILK0029
          TSIZE = TBIG                                                  FILK0030
      ELSE                                                              FILK0031
          TSIZE = TSMALL                                                FILK0032
      ENDIF                                                             FILK0033
                                                                        FILK0034
C---- Print heading                                                     FILK0035
      CALL PSTEXT(X - DX,Y + 2.0 * DY + YSEP,TSIZE,'Files:')            FILK0036
                                                                        FILK0037
C---- Loop through all the files in the ensemble                        FILK0038
      DO 500, IFILE = 1, NFILE                                          FILK0039
                                                                        FILK0040
C----     Draw marker box                                               FILK0041
          CALL PSLWID(0.2)                                              FILK0042
          CALL PSHADE(1.0,0,RGB,MXCOLR,.FALSE.)                         FILK0043
          CALL PSBBOX(X - DX,Y - DY,X - DX,Y + DY,                      FILK0044
     &                X + DX,Y + DY,X + DX,Y - DY)                      FILK0045
                                                                        FILK0046
C----     Form and print the model number inside the marker             FILK0047
          WRITE(NUMBER,110) IFILE                                       FILK0048
 110      FORMAT(I3)                                                    FILK0049
          IF (NUMBER(2:2).EQ.' ') THEN                                  FILK0050
              IPOS = 3                                                  FILK0051
          ELSE IF (NUMBER(1:1).EQ.' ') THEN                             FILK0052
              IPOS = 2                                                  FILK0053
          ELSE                                                          FILK0054
              IPOS = 1                                                  FILK0055
          ENDIF                                                         FILK0056
          CALL PSCTXT(X,Y,TSIZE,NUMBER(IPOS:))                          FILK0057
                                                                        FILK0058
C----     Print file name                                               FILK0059
          CALL PSTEXT(X + XSEP,Y,TSIZE,                                 FILK0060
     &        FILID(IFILE)(1:LENID(IFILE)))                             FILK0061
                                                                        FILK0062
C----     Move y-position down for next file                            FILK0063
          Y = Y - 2.0 * DY - YSEP                                       FILK0064
 500  CONTINUE                                                          FILK0065
                                                                        FILK0066
      RETURN                                                            FILK0067
      END                                                               FILK0068
                                                                        FILK0069
      SUBROUTINE PLOTS(DISTRB)                                          PLOT0001
C-----------------------------------------------------------------------PLOT0002
CHECK v.3.2<--                                                          PLOT0003
C                                                                       PLOT0004
C  SUBROUTINE PLOTS  -  Plot the distributions and data values          PLOT0005
C                                                                       PLOT0006
C----------------------------------------------------------------------+PLOT0007
                                                                        PLOT0008
      INCLUDE 'tplot.inc'                                               PLOT0009
                                                                        PLOT0010
CHECK v.3.2-->                                                          PLOT0011
      CHARACTER*4    CNUMB                                              PLOT0012
CHECK v.3.2<--                                                          PLOT0013
      CHARACTER*7    PAGE                                               PLOT0014
CHECK v.3.2-->                                                          PLOT0015
      CHARACTER*9    PLHAND                                             PLOT0016
CHECK v.3.2<--                                                          PLOT0017
CHECK v.3.1-->                                                          PLOT0018
      CHARACTER*30   PLDESC                                             PLOT0019
CHECK v.3.1<--                                                          PLOT0020
      CHARACTER*40   HEADIN                                             PLOT0021
CHECK v.3.2-->                                                          PLOT0022
      CHARACTER*60   PTITLE                                             PLOT0023
      CHARACTER*79   BLNKLN, SUMLIN                                     PLOT0024
CHECK v.3.2<--                                                          PLOT0025
      INTEGER        BAKCOL, HLEN, IAMINO, ICELL, ICOL, IPAGE, IROW,    PLOT0026
     &               JCELL, NCOL, NROW, DISTRB                          PLOT0027
CHECK v.3.2-->                                                          PLOT0028
C      LOGICAL        GENPLT, INCOL                                     PLOT0029
C      REAL           PERCEN, XCENTR, XCORN1, XCORN2, YCORN1, YCORN2    PLOT0030
      LOGICAL        FIRST, GENPLT, INCOL, LAST                         PLOT0031
      REAL           KEYPSX, KEYPSY, PERCEN, XCENTR, XCORN1, XCORN2,    PLOT0032
     &               YCORN1, YCORN2                                     PLOT0033
CHECK v.3.2<--                                                          PLOT0034
CHECK v.3.2-->                                                          PLOT0035
      DATA BLNKLN( 1:40) / ' |                                      ' / PLOT0036
      DATA BLNKLN(41:79) / '                                      |'  / PLOT0037
CHECK v.3.2<--                                                          PLOT0038
                                                                        PLOT0039
C---- Initialise variables                                              PLOT0040
      IF (DISTRB.EQ.1) THEN                                             PLOT0041
          BAKCOL = COLRGP(1)                                            PLOT0042
          IF (ALLRAM) THEN                                              PLOT0043
CHECK v.3.4-->                                                          PLOT0044
C              HEADIN = 'Ramachandran plots for all residues'           PLOT0045
              HEADIN = 'Ramachandran plots for all residue types'       PLOT0046
CHECK v.3.4<--                                                          PLOT0047
              HLEN = 40                                                 PLOT0048
CHECK v.3.1-->                                                          PLOT0049
              PLDESC = 'All-residue Ramachandran plots'                 PLOT0050
CHECK v.3.1<--                                                          PLOT0051
CHECK v.3.2-->                                                          PLOT0052
              PLHAND = 'allramach'                                      PLOT0053
              PTITLE = PLDESC                                           PLOT0054
CHECK v.3.2<--                                                          PLOT0055
          ELSE                                                          PLOT0056
              HEADIN = 'Ramachandran plots for Gly & Pro'               PLOT0057
              HLEN = 32                                                 PLOT0058
CHECK v.3.1-->                                                          PLOT0059
              PLDESC = 'Gly & Pro Ramachandran plots'                   PLOT0060
CHECK v.3.1<--                                                          PLOT0061
CHECK v.3.2-->                                                          PLOT0062
              PLHAND = 'ramglypro'                                      PLOT0063
              PTITLE = PLDESC                                           PLOT0064
CHECK v.3.2<--                                                          PLOT0065
          ENDIF                                                         PLOT0066
          INCOL = INCOLG                                                PLOT0067
      ELSE IF (DISTRB.EQ.2) THEN                                        PLOT0068
          BAKCOL = COLCHI(1)                                            PLOT0069
          HEADIN = 'Chi1-Chi2 plots'                                    PLOT0070
          HLEN = 15                                                     PLOT0071
          INCOL = INCOLC                                                PLOT0072
CHECK v.3.1-->                                                          PLOT0073
          PLDESC = 'All-residue chi1-chi2 plots'                        PLOT0074
CHECK v.3.1<--                                                          PLOT0075
CHECK v.3.2-->                                                          PLOT0076
          PLHAND = 'chi1_chi2'                                          PLOT0077
          PTITLE = PLDESC                                               PLOT0078
CHECK v.3.2<--                                                          PLOT0079
      ENDIF                                                             PLOT0080
      IF (DISTRB.EQ.1 .AND. .NOT.ALLRAM) THEN                           PLOT0081
          NCOL = 1                                                      PLOT0082
          NROW = 2                                                      PLOT0083
      ELSE                                                              PLOT0084
          NCOL = 3                                                      PLOT0085
          NROW = 3                                                      PLOT0086
      ENDIF                                                             PLOT0087
      ICOL = 0                                                          PLOT0088
      IPAGE = 0                                                         PLOT0089
      IROW = 1                                                          PLOT0090
      XCENTR = (BBOXX1 + BBOXX2) / 2.0                                  PLOT0091
                                                                        PLOT0092
CHECK v.3.2-->                                                          PLOT0093
C---- Initialise counts of labelled, and total, points on the graphs    PLOT0094
      NLABEL = 0                                                        PLOT0095
      NPOINT = 0                                                        PLOT0096
      FIRST = .TRUE.                                                    PLOT0097
      KEYPSX = 0.0                                                      PLOT0098
      KEYPSY = 0.0                                                      PLOT0099
      LAST = .FALSE.                                                    PLOT0100
CHECK v.3.2<--                                                          PLOT0101
                                                                        PLOT0102
C---- Determine the maximum and minimum values across all graphs        PLOT0103
      PERMAX = -999999.99                                               PLOT0104
      PERMIN = 999999.99                                                PLOT0105
      IF (DOPLOT(DISTRB)) THEN                                          PLOT0106
          DO 300, IAMINO = 1, NAMINO                                    PLOT0107
              IF (NCOUNT(IAMINO).NE.0) THEN                             PLOT0108
                  DO 200, JCELL = 1, NCELL                              PLOT0109
                      DO 100, ICELL = 1, NCELL                          PLOT0110
                          PERCEN = ARRAY(ICELL,JCELL,IAMINO)            PLOT0111
     &                        * 100.0 / REAL(NCOUNT(IAMINO))            PLOT0112
                          PERMIN = MIN(PERMIN,PERCEN)                   PLOT0113
                          PERMAX = MAX(PERMAX,PERCEN)                   PLOT0114
100                   CONTINUE                                          PLOT0115
200               CONTINUE                                              PLOT0116
              ENDIF                                                     PLOT0117
300       CONTINUE                                                      PLOT0118
      ENDIF                                                             PLOT0119
                                                                        PLOT0120
C---- Loop through all the amino acid types to be plotted               PLOT0121
      DO 500, IAMINO = 1, NAMINO                                        PLOT0122
                                                                        PLOT0123
C----     Determine whether 2D distribution is to be plotted            PLOT0124
          GENPLT = .FALSE.                                              PLOT0125
          IF (DOPLOT(DISTRB) .AND. NCOUNT(IAMINO).GT.0) THEN            PLOT0126
              GENPLT = .TRUE.                                           PLOT0127
          ENDIF                                                         PLOT0128
                                                                        PLOT0129
C----     For phi-psi distribution, plot only the Gly and Pro distrib   PLOT0130
C         as have already plotted the Ramachandran plot for the other   PLOT0131
C         residue types                                                 PLOT0132
          IF (DISTRB.EQ.1 .AND. .NOT.ALLRAM .AND. IAMINO.NE.8 .AND.     PLOT0133
     &        IAMINO.NE.15) THEN                                        PLOT0134
              GENPLT = .FALSE.                                          PLOT0135
          ENDIF                                                         PLOT0136
                                                                        PLOT0137
C----     Plot if the plot is required                                  PLOT0138
          IF (GENPLT) THEN                                              PLOT0139
                                                                        PLOT0140
C----         Increment column number on page (1-3) throwing new page ifPLOT0141
C             necessary                                                 PLOT0142
              ICOL = ICOL + 1                                           PLOT0143
              IF (ICOL.GT.NCOL) THEN                                    PLOT0144
                  IROW = IROW + 1                                       PLOT0145
                  ICOL = 1                                              PLOT0146
              ENDIF                                                     PLOT0147
              IF (IPAGE.EQ.0 .OR. IROW.GT.NROW) THEN                    PLOT0148
                                                                        PLOT0149
C----             If this is not the first page, then close current     PLOT0150
C                 PostScript file                                       PLOT0151
                  IF (IPAGE.GT.0) THEN                                  PLOT0152
CHECK v.3.2-->                                                          PLOT0153
C                      CALL PLTEND(DISTRB)                              PLOT0154
                                                                        PLOT0155
C----                 For ensemble, plot a file-key to the right of     PLOT0156
C                     the Gly/Pro Ramachandran plot                     PLOT0157
                      IF (DISTRB.EQ.1 .AND. .NOT.ALLRAM) THEN           PLOT0158
                          IF (ENSEMB) THEN                              PLOT0159
                              CALL FILKEY(KEYPSX,KEYPSY,MKSZ,MKSZ,      PLOT0160
     &                            8.0,5.0)                              PLOT0161
                          ENDIF                                         PLOT0162
                      ENDIF                                             PLOT0163
                      CALL PLTEND(DISTRB,LAST)                          PLOT0164
CHECK v.3.2<--                                                          PLOT0165
                  ENDIF                                                 PLOT0166
                                                                        PLOT0167
C----             Open PostScript file and print page-number            PLOT0168
CHECK v.3.1-->                                                          PLOT0169
C                  CALL PSNAME(FILPS,PSLEN,IPLOT)                       PLOT0170
CHECK v.3.2-->                                                          PLOT0171
C                  CALL PSNAME(FILPS,PSLEN,IPLOT,PLDESC)                PLOT0172
C                  PLDESC = ' '                                         PLOT0173
C                  CALL PSOPEN(FILPS,BBOXX1,BBOXX2,BBOXY1,BBOXY2,MXCOLR,PLOT0174
C     -                RGB,INCOL,BAKCOL)                                PLOT0175
                  IF (.NOT.COMBPS .OR. FIRST) THEN                      PLOT0176
                      CALL PSNAME(FILPS,PSLEN,IPLOT,PLDESC,PLHAND,      PLOT0177
     &                    WITHAN)                                       PLOT0178
CHECK v.3.4-->                                                          PLOT0179
C                      CALL PSOPEN(FILPS,MXCOLR,RGB,INCOL,PTITLE,       PLOT0180
C     -                    IPAGE + 1)                                   PLOT0181
                      CALL PSOPEN(FILPS,MXCOLR,RGB,NCOLOR,INCOL,PTITLE, PLOT0182
     &                    IPAGE + 1)                                    PLOT0183
CHECK v.3.4<--                                                          PLOT0184
                      FIRST = .FALSE.                                   PLOT0185
                  ENDIF                                                 PLOT0186
                  PLDESC = ' '                                          PLOT0187
                  CALL PSPAGE(FILPS,BBOXX1,BBOXX2,BBOXY1,BBOXY2,        PLOT0188
CHECK v.3.4-->                                                          PLOT0189
C     -                MXCOLR,RGB,INCOL,BAKCOL,IPAGE + 1,PLABEL)        PLOT0190
     &                MXCOLR,RGB,INCOL,BAKCOL,IPAGE + 1,PLABEL,RSELEC)  PLOT0191
CHECK v.3.4<--                                                          PLOT0192
CHECK v.3.2<--                                                          PLOT0193
CHECK v.3.1<--                                                          PLOT0194
                  IPAGE = IPAGE + 1                                     PLOT0195
                  WRITE(PAGE,420) IPAGE                                 PLOT0196
 420              FORMAT('Page ',I2)                                    PLOT0197
                  CALL PSCTXT(BBOXX2 - 40.0,BBOXY2 - 20.0,12.0,PAGE)    PLOT0198
                  IROW = 1                                              PLOT0199
                                                                        PLOT0200
CHECK v.3.2-->                                                          PLOT0201
C----             Print program name in top left-hand corner            PLOT0202
                  IF (NMR) THEN                                         PLOT0203
                      CALL PSTEXT(BBOXX1 + 15.0,BBOXY2 - 10.0,10.0,     PLOT0204
     &                    'PROCHECK-NMR')                               PLOT0205
                  ELSE IF (ENSEMB) THEN                                 PLOT0206
                      CALL PSTEXT(BBOXX1 + 15.0,BBOXY2 - 10.0,10.0,     PLOT0207
     &                    'PROCHECK-COMP')                              PLOT0208
                  ELSE                                                  PLOT0209
                      CALL PSTEXT(BBOXX1 + 15.0,BBOXY2 - 10.0,10.0,     PLOT0210
     &                    'PROCHECK')                                   PLOT0211
                  ENDIF                                                 PLOT0212
CHECK v.3.2<--                                                          PLOT0213
                                                                        PLOT0214
C----             Print graph headings                                  PLOT0215
                  CALL PSCTXT(XCENTR,BBOXY2 - 40.0,25.0,HEADIN(1:HLEN)) PLOT0216
CHECK v.3.4-->                                                          PLOT0217
C                  CALL PSCTXT(XCENTR,BBOXY2 - 70.0,18.0,BRCODE(1:BLEN))PLOT0218
                  CALL PSCTXT(XCENTR,BBOXY2 - 70.0,18.0,                PLOT0219
     &                BRCODE(1:BLEN + 2))                               PLOT0220
CHECK v.3.4<--                                                          PLOT0221
              ENDIF                                                     PLOT0222
                                                                        PLOT0223
C----         Initialise variables                                      PLOT0224
              IF (DISTRB.EQ.1 .AND. .NOT.ALLRAM) THEN                   PLOT0225
                  XCORN1 = XLEFT1                                       PLOT0226
                  XCORN2 = XCORN1 + XWID1                               PLOT0227
                  YCORN1 = YBOTT1 + (NROW - IROW) * (YHIGH1 + YSEP1)    PLOT0228
                  YCORN2 = YCORN1 + YHIGH1                              PLOT0229
CHECK v.3.2-->                                                          PLOT0230
                  KEYPSX = XCORN2 + 10.0 * MKSZ                         PLOT0231
                  KEYPSY = YBOTT1 + 2.0 * YHIGH1 + YSEP1 - MKSZ         PLOT0232
CHECK v.3.2<--                                                          PLOT0233
              ELSE                                                      PLOT0234
                  XCORN1 = XLEFT3 + (ICOL - 1) * (XWID3 + XSEP3)        PLOT0235
                  XCORN2 = XCORN1 + XWID3                               PLOT0236
                  YCORN1 = YBOTT3 + (NROW - IROW) * (YHIGH3 + YSEP3)    PLOT0237
                  YCORN2 = YCORN1 + YHIGH3                              PLOT0238
              ENDIF                                                     PLOT0239
                                                                        PLOT0240
C----         Plot the current graph                                    PLOT0241
              CALL PLTGRD(XCORN1,XCORN2,YCORN1,YCORN2,IAMINO,ICOL,      PLOT0242
     &            DISTRB)                                               PLOT0243
CHECK v.3.2-->                                                          PLOT0244
          ELSE                                                          PLOT0245
              XCORN1 = 0.0                                              PLOT0246
              XCORN2 = 0.0                                              PLOT0247
              YCORN1 = 0.0                                              PLOT0248
              YCORN2 = 0.0                                              PLOT0249
CHECK v.3.2<--                                                          PLOT0250
          ENDIF                                                         PLOT0251
                                                                        PLOT0252
C----     Plot all the data points on the current graph, calculating    PLOT0253
C         log-odds score for each one                                   PLOT0254
          IF (NCOUNT(IAMINO).GT.0) THEN                                 PLOT0255
              CALL PROCPT(XCORN1,XCORN2,YCORN1,YCORN2,IAMINO,DISTRB,    PLOT0256
     &            GENPLT)                                               PLOT0257
          ENDIF                                                         PLOT0258
 500  CONTINUE                                                          PLOT0259
                                                                        PLOT0260
C---- Close the current PostScript file                                 PLOT0261
      IF (DOPLOT(DISTRB)) THEN                                          PLOT0262
CHECK v.3.2-->                                                          PLOT0263
C          CALL PLTEND(DISTRB)                                          PLOT0264
                                                                        PLOT0265
C----     For ensemble, plot a file-key to the right of                 PLOT0266
C         the Gly/Pro Ramachandran plot                                 PLOT0267
          IF (DISTRB.EQ.1 .AND. .NOT.ALLRAM) THEN                       PLOT0268
              IF (ENSEMB) THEN                                          PLOT0269
                  CALL FILKEY(KEYPSX,KEYPSY,MKSZ,MKSZ,                  PLOT0270
     &                8.0,5.0)                                          PLOT0271
              ENDIF                                                     PLOT0272
          ENDIF                                                         PLOT0273
          LAST = .TRUE.                                                 PLOT0274
          CALL PLTEND(DISTRB,LAST)                                      PLOT0275
CHECK v.3.2<--                                                          PLOT0276
      ENDIF                                                             PLOT0277
                                                                        PLOT0278
CHECK v.3.2-->                                                          PLOT0279
C---- Write out the distribution statistics to the .sum summary file    PLOT0280
      IF (DOPLOT(DISTRB)) THEN                                          PLOT0281
                                                                        PLOT0282
C----     Blank out the output line                                     PLOT0283
          SUMLIN = BLNKLN                                               PLOT0284
                                                                        PLOT0285
C----     Set up line label according to graph type                     PLOT0286
          IF (DISTRB.EQ.1) THEN                                         PLOT0287
                                                                        PLOT0288
C----         All 20 amino acid Ramachandrans                           PLOT0289
              IF (ALLRAM) THEN                                          PLOT0290
                  SUMLIN(4:21) = 'All Ramachandrans:'                   PLOT0291
                                                                        PLOT0292
C----         Gly & Pro Ramachandran plots                              PLOT0293
              ELSE                                                      PLOT0294
                  SUMLIN(4:21) = 'Gly & Pro Ramach: '                   PLOT0295
              ENDIF                                                     PLOT0296
          ELSE IF (DISTRB.EQ.2) THEN                                    PLOT0297
              SUMLIN(4:21) = 'Chi1-chi2 plots:  '                       PLOT0298
          ENDIF                                                         PLOT0299
                                                                        PLOT0300
C----     Show the number of labelled residues found in the low-probabilPLOT0301
C         regions of the plots                                          PLOT0302
          WRITE(CNUMB,620) NLABEL                                       PLOT0303
 620      FORMAT(I4)                                                    PLOT0304
          SUMLIN(23:26) = CNUMB                                         PLOT0305
          SUMLIN(28:57) = 'labelled residues (out of    )'              PLOT0306
                                                                        PLOT0307
C----     Show the total number of values plotted                       PLOT0308
          WRITE(CNUMB,620) NPOINT                                       PLOT0309
          SUMLIN(53:56) = CNUMB                                         PLOT0310
                                                                        PLOT0311
C----     Determine whether to highlight the line with a + or a *       PLOT0312
          IF (NLABEL.GT.0) THEN                                         PLOT0313
              SUMLIN(1:1) = '+'                                         PLOT0314
          ENDIF                                                         PLOT0315
          IF (NPOINT.GT.0) THEN                                         PLOT0316
              IF (100.0 * REAL(NLABEL) / REAL(NPOINT).GT.3.0) THEN      PLOT0317
                  SUMLIN(1:1) = '*'                                     PLOT0318
              ENDIF                                                     PLOT0319
          ENDIF                                                         PLOT0320
                                                                        PLOT0321
C----     Write the line out to the summary file                        PLOT0322
          WRITE(14,660) SUMLIN                                          PLOT0323
 660      FORMAT(A)                                                     PLOT0324
      ENDIF                                                             PLOT0325
                                                                        PLOT0326
C---- Write out blank line to summary file after chi1-ch2 line          PLOT0327
      IF (DISTRB.EQ.2) THEN                                             PLOT0328
          WRITE(14,660) BLNKLN                                          PLOT0329
      ENDIF                                                             PLOT0330
CHECK v.3.2<--                                                          PLOT0331
                                                                        PLOT0332
      RETURN                                                            PLOT0333
      END                                                               PLOT0334
                                                                        PLOT0335
      SUBROUTINE PLTGRD(X1,X2,Y1,Y2,IAMINO,ICOL,DISTRB)                 PLTG0001
C-----------------------------------------------------------------------PLTG0002
C                                                                       PLTG0003
C  SUBROUTINE PLTGRD  -  Plot graph boxes containing the distributions aPLTG0004
C                        obtained from a high-resolution data set, and tPLTG0005
C                        individual values seen in the structure        PLTG0006
C                                                                       PLTG0007
C----------------------------------------------------------------------+PLTG0008
                                                                        PLTG0009
      INCLUDE 'tplot.inc'                                               PLTG0010
                                                                        PLTG0011
      CHARACTER*6    XAXIS, YAXIS                                       PLTG0012
      INTEGER        ICOL, IAMINO, DISTRB                               PLTG0013
      REAL           LDROP, LSIZE, TWID, XCENTR, XL1, XL2, X1, X2,      PLTG0014
     &               YCENTR, YL1, YL2, Y1, Y2                           PLTG0015
                                                                        PLTG0016
C---- Initialise variables                                              PLTG0017
      XCENTR = (X1 + X2) / 2.0                                          PLTG0018
      YCENTR = (Y1 + Y2) / 2.0                                          PLTG0019
      IF (DISTRB.EQ.1) THEN                                             PLTG0020
          XAXIS = 'Phi'                                                 PLTG0021
          YAXIS = 'Psi'                                                 PLTG0022
      ELSE IF (DISTRB.EQ.2) THEN                                        PLTG0023
          XAXIS = 'Chi-1'                                               PLTG0024
          YAXIS = 'Chi-2'                                               PLTG0025
      ENDIF                                                             PLTG0026
      IF (DISTRB.EQ.1 .AND. .NOT.ALLRAM) THEN                           PLTG0027
          LDROP = 24.0                                                  PLTG0028
          LSIZE = 11.0                                                  PLTG0029
          TWID = 18.0                                                   PLTG0030
      ELSE                                                              PLTG0031
          LDROP = 20.0                                                  PLTG0032
          LSIZE = 8.0                                                   PLTG0033
          TWID = 12.0                                                   PLTG0034
      ENDIF                                                             PLTG0035
                                                                        PLTG0036
C---- Plot the distribution if not empty                                PLTG0037
      IF (NCOUNT(IAMINO).GT.0) THEN                                     PLTG0038
          CALL PLTDIS(X1,X2,Y1,Y2,IAMINO,DISTRB)                        PLTG0039
      ENDIF                                                             PLTG0040
                                                                        PLTG0041
C---- Draw box round graph and label axes                               PLTG0042
      CALL AXES(X1,X2,Y1,Y2,NTICKX,NTICKY,VALBEG(1),VALEND(1),          PLTG0043
     &    VALBEG(2),VALEND(2),LSIZE,0,0,TWID,.TRUE.,.TRUE.,.FALSE.,     PLTG0044
     &    .FALSE.,.FALSE.)                                              PLTG0045
                                                                        PLTG0046
C---- Print x-axis title                                                PLTG0047
      CALL PSCTXT(XCENTR,Y1 - LDROP,12.0,XAXIS)                         PLTG0048
                                                                        PLTG0049
C---- y-axis title                                                      PLTG0050
      IF (ICOL.EQ.1) CALL PSRTXT(X1 - LDROP - 5.0,YCENTR,12.0,YAXIS)    PLTG0051
                                                                        PLTG0052
C---- For Chi1-Chi2 plots, draw in dotted lines for the favourable      PLTG0053
C     positions                                                         PLTG0054
      IF (DISTRB.EQ.2) THEN                                             PLTG0055
          XL1 = X1 + (X2 - X1) / 6.0                                    PLTG0056
          XL2 = X1 + (X2 - X1) * (5.0 / 6.0)                            PLTG0057
          YL1 = Y1 + (Y2 - Y1) / 6.0                                    PLTG0058
          YL2 = Y1 + (Y2 - Y1) * (5.0 / 6.0)                            PLTG0059
          CALL PSDASH(3)                                                PLTG0060
          CALL PSLWID(0.1)                                              PLTG0061
          CALL PSLINE(X1,YL1,X2,YL1)                                    PLTG0062
          CALL PSLINE(X1,YCENTR,X2,YCENTR)                              PLTG0063
          CALL PSLINE(X1,YL2,X2,YL2)                                    PLTG0064
          CALL PSLINE(XL1,Y1,XL1,Y2)                                    PLTG0065
          CALL PSLINE(XCENTR,Y1,XCENTR,Y2)                              PLTG0066
          CALL PSLINE(XL2,Y1,XL2,Y2)                                    PLTG0067
          CALL PSDASH(0)                                                PLTG0068
      ENDIF                                                             PLTG0069
                                                                        PLTG0070
      RETURN                                                            PLTG0071
      END                                                               PLTG0072
                                                                        PLTG0073
      SUBROUTINE PLTDIS(XCORN1,XCORN2,YCORN1,YCORN2,IAMINO,DISTRB)      PLTD0001
C-----------------------------------------------------------------------PLTD0002
C                                                                       PLTD0003
C  SUBROUTINE PLTDIS  -  Plot the distribution as different-shaded regioPLTD0004
C                                                                       PLTD0005
C----------------------------------------------------------------------+PLTD0006
                                                                        PLTD0007
      INCLUDE 'tplot.inc'                                               PLTD0008
                                                                        PLTD0009
      INTEGER        DISTRB, IAMINO, ICELL, JCELL, MAXCOL, MINCOL       PLTD0010
      LOGICAL        INCOL                                              PLTD0011
      REAL           ANGLE, LSHADE, PERCEN, PI, PIBY2, SHADE, X, XCORN1,PLTD0012
     &               XCORN2, XGAP, XLEFT, X1, Y, YCORN1, YCORN2, YGAP,  PLTD0013
     &               YLEFT                                              PLTD0014
                                                                        PLTD0015
      PARAMETER     (PI = 3.141592654, PIBY2 = PI / 2.0)                PLTD0016
                                                                        PLTD0017
C---- Initialise variables for shading                                  PLTD0018
      IF (DISTRB.EQ.1) THEN                                             PLTD0019
          INCOL = INCOLG                                                PLTD0020
          MINCOL = COLRGP(2)                                            PLTD0021
          MAXCOL = COLRGP(3)                                            PLTD0022
      ELSE                                                              PLTD0023
          INCOL = INCOLC                                                PLTD0024
          MINCOL = COLCHI(2)                                            PLTD0025
          MAXCOL = COLCHI(3)                                            PLTD0026
      ENDIF                                                             PLTD0027
      XGAP = (XCORN2 - XCORN1) / NCELL                                  PLTD0028
      YGAP = (YCORN2 - YCORN1) / NCELL                                  PLTD0029
                                                                        PLTD0030
C---- Loop through all the cells in this graph                          PLTD0031
      CALL PSLWID(0.0)                                                  PLTD0032
      Y = YCORN1                                                        PLTD0033
      DO 300, JCELL = 1, NCELL                                          PLTD0034
          LSHADE = 1.0                                                  PLTD0035
          XLEFT = XCORN1                                                PLTD0036
          X = XLEFT + XGAP                                              PLTD0037
          YLEFT = Y                                                     PLTD0038
          X1 = XLEFT                                                    PLTD0039
          DO 200, ICELL = 1, NCELL                                      PLTD0040
                                                                        PLTD0041
C----         Determine the shade to be plotted                         PLTD0042
              IF (NCOUNT(IAMINO).NE.0) THEN                             PLTD0043
                  PERCEN = 100.0 * ARRAY(ICELL,JCELL,IAMINO)            PLTD0044
     &                / REAL(NCOUNT(IAMINO))                            PLTD0045
                  ANGLE = PIBY2 * SQRT(PERCEN / PERMAX)                 PLTD0046
                  SHADE = 1.0 - SIN(ANGLE)                              PLTD0047
                  IF (SHADE.LT.0.0) SHADE = 0.0                         PLTD0048
                  IF (SHADE.GT.1.0) SHADE = 1.0                         PLTD0049
              ELSE                                                      PLTD0050
                  SHADE = 0.0                                           PLTD0051
              ENDIF                                                     PLTD0052
                                                                        PLTD0053
C----         Write out the appropriate shade                           PLTD0054
              IF (SHADE.NE.LSHADE) THEN                                 PLTD0055
                  CALL PSCALE(LSHADE,INCOL,MXCOLR,RGB,MINCOL,MAXCOL)    PLTD0056
                  CALL PSUBOX(X1, Y, XLEFT, Y, XLEFT, Y + YGAP,         PLTD0057
     &                X1, Y + YGAP)                                     PLTD0058
                  LSHADE = SHADE                                        PLTD0059
                  X1 = XLEFT                                            PLTD0060
              ENDIF                                                     PLTD0061
                                                                        PLTD0062
C----         If the final cell of this row, then write out             PLTD0063
              IF (ICELL.EQ.NCELL) THEN                                  PLTD0064
                  CALL PSCALE(LSHADE,INCOL,MXCOLR,RGB,MINCOL,MAXCOL)    PLTD0065
                  CALL PSUBOX(X1, Y, X, Y, X, Y + YGAP,                 PLTD0066
     &                X1, Y + YGAP)                                     PLTD0067
              ENDIF                                                     PLTD0068
                                                                        PLTD0069
C----         Increment x-value                                         PLTD0070
              XLEFT = X                                                 PLTD0071
              X = X + XGAP                                              PLTD0072
 200      CONTINUE                                                      PLTD0073
                                                                        PLTD0074
C----     Increment y-value                                             PLTD0075
          Y = Y + YGAP                                                  PLTD0076
 300  CONTINUE                                                          PLTD0077
      CALL PSLWID(0.2)                                                  PLTD0078
                                                                        PLTD0079
      RETURN                                                            PLTD0080
      END                                                               PLTD0081
                                                                        PLTD0082
      SUBROUTINE PROCPT(XCORN1,XCORN2,YCORN1,YCORN2,IAMINO,DISTRB,      PROC0001
     &    GENPLT)                                                       PROC0002
C-----------------------------------------------------------------------PROC0003
C                                                                       PROC0004
C  SUBROUTINE PROCPT  -  Process the individual data points for this amiPROC0005
C                        acid type                                      PROC0006
C                                                                       PROC0007
C----------------------------------------------------------------------+PROC0008
                                                                        PROC0009
      INCLUDE 'tplot.inc'                                               PROC0010
                                                                        PROC0011
CHECK v.3.2-->                                                          PROC0012
C      CHARACTER*3    AMNAME(NAMINO+1), RESNAM, RESRQD                  PROC0013
      CHARACTER*3    AMNAME(NAMINO+1), NUMBER, RESNAM, RESRQD           PROC0014
CHECK v.3.2<--                                                          PROC0015
      CHARACTER*6    CHPTS                                              PROC0016
CHECK v.3.2-->                                                          PROC0017
C      CHARACTER*10   ACTEXT, RIDTXT                                    PROC0018
      CHARACTER*15   ACTEXT, RIDTXT                                     PROC0019
CHECK v.3.2<--                                                          PROC0020
      CHARACTER*17   HEADTX                                             PROC0021
CHECK v.3.2-->                                                          PROC0022
C      INTEGER        HEND, IAMINO, IRESID, I1, I2, NBLANK, NDONE,      PROC0023
C     -               DISTRB                                            PROC0024
      INTEGER        DISTRB, HEND, IAMINO, ICOLB, ICOLBK, ICOLG, ICOLR, PROC0025
     &               IPOS, IRESID, I1, I2, NBLANK, NDONE                PROC0026
CHECK v.3.2<--                                                          PROC0027
      LOGICAL        GENPLT, INCOL, VALOK                               PROC0028
      REAL           CALC1D, CALC2D, CBAD(3), CGOOD(3), LIMSCR, MSIZ,   PROC0029
CHECK v.3.2-->                                                          PROC0030
C     -               SC, SCALEX, SCALEY, SHADE, TSIZ, X, XANG, XCENTR, PROC0031
C     -               XCORN1, XCORN2, Y, YANG, YCORN1, YCORN2           PROC0032
     &               SC, SCALEX, SCALEY, SHADE, TSIZ, TSIZE, X, XANG,   PROC0033
     &               XCENTR, XCORN1, XCORN2, Y, YANG, YCORN1, YCORN2    PROC0034
CHECK v.3.2<--                                                          PROC0035
                                                                        PROC0036
      DATA AMNAME /'Ala', 'Arg', 'Asn', 'Asp', 'Cys', 'Gln', 'Glu',     PROC0037
     &             'Gly', 'His', 'Ile', 'Leu', 'Lys', 'Met', 'Phe',     PROC0038
     &             'Pro', 'Ser', 'Thr', 'Trp', 'Tyr', 'Val', 'ALL' /    PROC0039
                                                                        PROC0040
C---- Initialise variables                                              PROC0041
      IF (DISTRB.EQ.1) THEN                                             PROC0042
          CGOOD(1) = RGB(1,COLRGP(4))                                   PROC0043
          CGOOD(2) = RGB(2,COLRGP(4))                                   PROC0044
          CGOOD(3) = RGB(3,COLRGP(4))                                   PROC0045
          CBAD(1) = RGB(1,COLRGP(5))                                    PROC0046
          CBAD(2) = RGB(2,COLRGP(5))                                    PROC0047
          CBAD(3) = RGB(3,COLRGP(5))                                    PROC0048
CHECK v.3.2-->                                                          PROC0049
          ICOLBK = COLRGP(1)                                            PROC0050
          ICOLG = COLRGP(4)                                             PROC0051
          ICOLB = COLRGP(5)                                             PROC0052
CHECK v.3.2<--                                                          PROC0053
          INCOL = INCOLG                                                PROC0054
          LIMSCR = LIMGP                                                PROC0055
CHECK v.3.2-->                                                          PROC0056
C          MSIZ = MKSZ * 1.5                                            PROC0057
          MSIZ = MKSZ                                                   PROC0058
CHECK v.3.2<--                                                          PROC0059
          TSIZ = TXTSZ * 1.75                                           PROC0060
      ELSE                                                              PROC0061
          CGOOD(1) = RGB(1,COLCHI(4))                                   PROC0062
          CGOOD(2) = RGB(2,COLCHI(4))                                   PROC0063
          CGOOD(3) = RGB(3,COLCHI(4))                                   PROC0064
          CBAD(1) = RGB(1,COLCHI(5))                                    PROC0065
          CBAD(2) = RGB(2,COLCHI(5))                                    PROC0066
          CBAD(3) = RGB(3,COLCHI(5))                                    PROC0067
CHECK v.3.2-->                                                          PROC0068
          ICOLBK = COLCHI(1)                                            PROC0069
          ICOLG = COLCHI(4)                                             PROC0070
          ICOLB = COLCHI(5)                                             PROC0071
CHECK v.3.2<--                                                          PROC0072
          INCOL = INCOLC                                                PROC0073
          LIMSCR = LIMCHI                                               PROC0074
CHECK v.3.2-->                                                          PROC0075
C          MSIZ = MKSZ                                                  PROC0076
          MSIZ = MKSZ * 0.75                                            PROC0077
CHECK v.3.2<--                                                          PROC0078
          TSIZ = TXTSZ                                                  PROC0079
      ENDIF                                                             PROC0080
      NDONE = 0                                                         PROC0081
      RESRQD = AMINO(IAMINO)                                            PROC0082
      SCALEX = (XCORN2 - XCORN1) / (VALEND(1) - VALBEG(1))              PROC0083
      SCALEY = (YCORN2 - YCORN1) / (VALEND(2) - VALBEG(2))              PROC0084
CHECK v.3.2-->                                                          PROC0085
CHECK v.3.4-->                                                          PROC0086
C      IF ((ENSEMB .OR. NMR) .AND. NFILE.GT.1) THEN                     PROC0087
      IF ((ENSEMB .OR. NMR) .AND. NMODEL.GT.1) THEN                     PROC0088
CHECK v.3.4<--                                                          PROC0089
          MSIZ = MSIZ * 1.5                                             PROC0090
      ENDIF                                                             PROC0091
CHECK v.3.2<--                                                          PROC0092
                                                                        PROC0093
C---- Loop through all the residues in the structure                    PROC0094
      DO 300, IRESID = 1, NRESID                                        PROC0095
                                                                        PROC0096
C----     Check whether this residue is one of those required           PROC0097
          RESNAM = RESID(IRESID)(3:5)                                   PROC0098
          IF (RESNAM.EQ.RESRQD) THEN                                    PROC0099
              XANG = VALUE(1,IRESID)                                    PROC0100
              IF (XANG.GE.VALBEG(1) .AND. XANG.LE.VALEND(1)) THEN       PROC0101
                  IF (TWODEE) THEN                                      PROC0102
                      YANG = VALUE(2,IRESID)                            PROC0103
                      IF (YANG.GE.VALBEG(2) .AND.                       PROC0104
     &                    YANG.LE.VALEND(2)) THEN                       PROC0105
                          VALOK = .TRUE.                                PROC0106
                      ELSE                                              PROC0107
                          VALOK = .FALSE.                               PROC0108
                      ENDIF                                             PROC0109
                  ELSE                                                  PROC0110
                      VALOK = .TRUE.                                    PROC0111
                  ENDIF                                                 PROC0112
              ELSE                                                      PROC0113
                  VALOK = .FALSE.                                       PROC0114
              ENDIF                                                     PROC0115
                                                                        PROC0116
C----         If falls within plot area, then plot it                   PROC0117
              IF (VALOK) THEN                                           PROC0118
                                                                        PROC0119
C----             Calculate the log-odds score for this value           PROC0120
                  IF (TWODEE) THEN                                      PROC0121
                      SC = CALC2D(IAMINO,XANG,YANG)                     PROC0122
                  ELSE                                                  PROC0123
                      SC = CALC1D(IAMINO,XANG)                          PROC0124
                                                                        PROC0125
C----                 If this is a Chi-1 distribution and already have  PROC0126
C                     a score for this residue from the Chi1-Chi2       PROC0127
C                     distribution, then discard this score             PROC0128
                      IF (DISTRB.EQ.3 .AND. SCORE(2,IRESID).LT.999.0)   PROC0129
     &                    SC = 0.0                                      PROC0130
                  ENDIF                                                 PROC0131
                                                                        PROC0132
C----             Apply normalisation factor to the score               PROC0133
                  IF (SC.NE.0.0 .AND.NRMSTD(IAMINO).NE.0.0) THEN        PROC0134
                      SC = (SC - NRMEAN(IAMINO)) / NRMSTD(IAMINO)       PROC0135
                  ELSE                                                  PROC0136
                      SC = 999.99                                       PROC0137
                  ENDIF                                                 PROC0138
                  SCORE(DISTRB,IRESID) = SC                             PROC0139
                                                                        PROC0140
C----             Set the colour according to where the point is        PROC0141
                  IF (INCOL) THEN                                       PROC0142
                      IF (GENPLT) THEN                                  PROC0143
                          IF (SC.LT.LIMSCR) THEN                        PROC0144
                              CALL PSCOLB(CBAD(1),CBAD(2),CBAD(3))      PROC0145
                          ELSE                                          PROC0146
                              CALL PSCOLB(CGOOD(1),CGOOD(2),CGOOD(3))   PROC0147
                          ENDIF                                         PROC0148
                      ENDIF                                             PROC0149
                  ENDIF                                                 PROC0150
                                                                        PROC0151
C----             Calculate plot coordinates                            PROC0152
                  IF (GENPLT) THEN                                      PROC0153
                      X = XCORN1 + SCALEX * (XANG - VALBEG(1))          PROC0154
                      Y = YCORN1 + SCALEY * (YANG - VALBEG(2))          PROC0155
CHECK v.3.2-->                                                          PROC0156
C                      CALL PSLWID(0.6)                                 PROC0157
C                      CALL PSLINE(X - MSIZ,Y - MSIZ,X + MSIZ,Y + MSIZ) PROC0158
C                      CALL PSLINE(X - MSIZ,Y + MSIZ,X + MSIZ,Y - MSIZ) PROC0159
                      IF (SC.LT.LIMSCR) THEN                            PROC0160
                          SHADE = 1.0                                   PROC0161
                          ICOLR = ICOLB                                 PROC0162
                      ELSE                                              PROC0163
                          SHADE = 0.0                                   PROC0164
                          ICOLR = ICOLG                                 PROC0165
                      ENDIF                                             PROC0166
CHECK v.3.4-->                                                          PROC0167
C                      IF ((ENSEMB .OR. NMR) .AND. NFILE.GT.1) THEN     PROC0168
                      IF ((ENSEMB .OR. NMR) .AND. NMODEL.GT.1) THEN     PROC0169
CHECK v.3.4<--                                                          PROC0170
                          CALL PSLWID(0.4)                              PROC0171
                          SHADE = 1.0                                   PROC0172
                          ICOLR = ICOLBK                                PROC0173
                      ELSE                                              PROC0174
                          CALL PSLWID(0.1)                              PROC0175
                      ENDIF                                             PROC0176
                      CALL PSHADE(SHADE,ICOLR,RGB,MXCOLR,INCOL)         PROC0177
                      CALL PSBBOX(X - MSIZ,Y - MSIZ,X - MSIZ,Y + MSIZ,  PROC0178
     &                            X + MSIZ,Y + MSIZ,X + MSIZ,Y - MSIZ)  PROC0179
                                                                        PROC0180
C----                 For ensembles, print the model number inside the mPROC0181
CHECK v.3.4-->                                                          PROC0182
C                      IF ((ENSEMB .OR. NMR) .AND. NFILE.GT.1) THEN     PROC0183
                      IF ((ENSEMB .OR. NMR) .AND. NMODEL.GT.1) THEN     PROC0184
CHECK v.3.4<--                                                          PROC0185
                          WRITE(NUMBER,110) MODEL(IRESID)               PROC0186
 110                      FORMAT(I3)                                    PROC0187
                          IF (NUMBER(2:2).EQ.' ') THEN                  PROC0188
                              IPOS = 3                                  PROC0189
                          ELSE IF (NUMBER(1:1).EQ.' ') THEN             PROC0190
                              IPOS = 2                                  PROC0191
                          ELSE                                          PROC0192
                              IPOS = 1                                  PROC0193
                          ENDIF                                         PROC0194
CHECK v.3.4-->                                                          PROC0195
C                          IF (NFILE.LT.10) THEN                        PROC0196
                          IF (TOPMOD.LT.10) THEN                        PROC0197
CHECK v.3.4<--                                                          PROC0198
                              TSIZE = 8.0                               PROC0199
                          ELSE                                          PROC0200
                              TSIZE = 5.0                               PROC0201
                          ENDIF                                         PROC0202
                          CALL PSCTXT(X,Y,TSIZE,NUMBER(IPOS:))          PROC0203
                      ENDIF                                             PROC0204
CHECK v.3.2<--                                                          PROC0205
                  ENDIF                                                 PROC0206
                  NDONE = NDONE + 1                                     PROC0207
                                                                        PROC0208
C----             If the point is in an unfavourable region, then print PROC0209
C                 its residue ID                                        PROC0210
                  IF (GENPLT .AND. SC.LT.LIMSCR) THEN                   PROC0211
                      Y = Y + 2.5 * MSIZ                                PROC0212
                      RIDTXT = RESID(IRESID)                            PROC0213
                                                                        PROC0214
C----                 Check for blank spaces at the start and end of    PROC0215
C                     the residue ID                                    PROC0216
                      IF (RIDTXT(1:1).EQ.' ') THEN                      PROC0217
                          I1 = 3                                        PROC0218
                      ELSE                                              PROC0219
                          I1 = 1                                        PROC0220
                      ENDIF                                             PROC0221
                      IF (RIDTXT(9:10).EQ.'  ') THEN                    PROC0222
                          I2 = 8                                        PROC0223
                      ELSE IF (RIDTXT(10:10).EQ.' ') THEN               PROC0224
                          I2 = 9                                        PROC0225
                      ELSE                                              PROC0226
                          I2 = 10                                       PROC0227
                      ENDIF                                             PROC0228
                                                                        PROC0229
C----                 For the chi1-chi2 plot cut out the residue name   PROC0230
C                     from the ID                                       PROC0231
                      IF (DISTRB.EQ.1 .AND. .NOT.ALLRAM) THEN           PROC0232
                          ACTEXT = RIDTXT                               PROC0233
                      ELSE                                              PROC0234
CHECK v.3.2-->                                                          PROC0235
C                          ACTEXT = RIDTXT(1:1) // RIDTXT(6:10)         PROC0236
                          ACTEXT = RIDTXT(1:1) // RIDTXT(6:15)          PROC0237
CHECK v.3.2<--                                                          PROC0238
                          IF (I1.EQ.3) I1 = 2                           PROC0239
                          I2 = I2 - 4                                   PROC0240
                      ENDIF                                             PROC0241
                      CALL PSCTXT(X,Y,TSIZ,ACTEXT(I1:I2))               PROC0242
                                                                        PROC0243
CHECK v.3.2-->                                                          PROC0244
C----                 Increment count of labelled residues              PROC0245
                      NLABEL = NLABEL + 1                               PROC0246
CHECK v.3.2<--                                                          PROC0247
                  ENDIF                                                 PROC0248
                  IF (GENPLT .AND. INCOL) CALL PSCOLB(0.0,0.0,0.0)      PROC0249
              ENDIF                                                     PROC0250
          ENDIF                                                         PROC0251
 300  CONTINUE                                                          PROC0252
                                                                        PROC0253
C---- Print graph heading showing amino acid name and number of data    PROC0254
C     points                                                            PROC0255
      IF (DOPLOT(DISTRB) .AND. GENPLT) THEN                             PROC0256
          WRITE(CHPTS,20) NDONE                                         PROC0257
 20       FORMAT(I6)                                                    PROC0258
          IF (NDONE.EQ.0) CHPTS = '     -'                              PROC0259
          NBLANK = 5                                                    PROC0260
          IF (CHPTS(5:5).NE.' ') NBLANK = 4                             PROC0261
          IF (CHPTS(4:4).NE.' ') NBLANK = 3                             PROC0262
          IF (CHPTS(3:3).NE.' ') NBLANK = 2                             PROC0263
          IF (CHPTS(2:2).NE.' ') NBLANK = 1                             PROC0264
          IF (CHPTS(1:1).NE.' ') NBLANK = 0                             PROC0265
          HEADTX = AMNAME(IAMINO) // ' (' // CHPTS(NBLANK + 1:6) // ')' PROC0266
          HEND = 6 + (6 - NBLANK)                                       PROC0267
          XCENTR = (XCORN1 + XCORN2) / 2.0                              PROC0268
          CALL PSCTXT(XCENTR,YCORN2 + YTITGP,15.0,HEADTX(1:HEND))       PROC0269
                                                                        PROC0270
CHECK v.3.2-->                                                          PROC0271
C----     Increment count of points plotted on the distributions        PROC0272
          NPOINT = NPOINT + NDONE                                       PROC0273
CHECK v.3.2<--                                                          PROC0274
      ENDIF                                                             PROC0275
                                                                        PROC0276
      RETURN                                                            PROC0277
      END                                                               PROC0278
                                                                        PROC0279
      REAL FUNCTION CALC1D(IAMINO,XANG)                                 CALC0001
C-----------------------------------------------------------------------CALC0002
C                                                                       CALC0003
C  FUNCTION CALC1D  -  Calculate log-odds score for the properties of   CALC0004
C                      this residue for a 1D distribution               CALC0005
C                                                                       CALC0006
C----------------------------------------------------------------------+CALC0007
                                                                        CALC0008
      INCLUDE 'tplot.inc'                                               CALC0009
                                                                        CALC0010
      INTEGER        CELL1, IAMINO, IBACKX, ICELL, IDX,                 CALC0011
     &               IWIDTH, IX, IY, JCELL, LOOPX, NOBS                 CALC0012
      LOGICAL        ENOUGH                                             CALC0013
      REAL           PROBAB, XANG, XVALUE                               CALC0014
                                                                        CALC0015
                                                                        CALC0016
C---- Determine in which cell the current pair of values falls and      CALC0017
C     calculate the log-odds score                                      CALC0018
      CELL1 = (XANG - VALBEG(1)) / STEP(1) + 1                          CALC0019
                                                                        CALC0020
C---- If value falls outside plot-region, then return zero              CALC0021
      IF (CELL1.LT.1 .OR. CELL1.GT.NCELL1) THEN                         CALC0022
          CALC1D = 0.0                                                  CALC0023
                                                                        CALC0024
C---- Otherwise, calculate log-odds value                               CALC0025
      ELSE                                                              CALC0026
                                                                        CALC0027
C----     Calculate cell's physical position in the array               CALC0028
          JCELL = 1 + (CELL1 - 1) / NCELL                               CALC0029
          ICELL = CELL1 - (JCELL - 1) * NCELL                           CALC0030
                                                                        CALC0031
C----     Determine which side of the current cell is the nearest       CALC0032
          XVALUE = VALBEG(1) + (CELL1 - 1) * STEP(1)                    CALC0033
          IF (XANG - XVALUE.LT.0.5 * STEP(1)) THEN                      CALC0034
              IDX = 0                                                   CALC0035
          ELSE                                                          CALC0036
              IDX = 1                                                   CALC0037
          ENDIF                                                         CALC0038
                                                                        CALC0039
C----     If the current cell doesn't have more than the minimum no. of CALC0040
C         observations to calculate a sensible probability, then will   CALC0041
C         need to accumulate values from surrounding cells until net    CALC0042
C         no. of observations is enough                                 CALC0043
                                                                        CALC0044
C----     Initialise values                                             CALC0045
          ENOUGH = .FALSE.                                              CALC0046
          IWIDTH = 0                                                    CALC0047
                                                                        CALC0048
C----     Loop to accumulate cells from around the current one (startingCALC0049
C         from cell itself) until have more than the minimum required   CALC0050
C         number of observations                                        CALC0051
 200      CONTINUE                                                      CALC0052
                                                                        CALC0053
C----         Increase number of cells to be put together               CALC0054
              IWIDTH = IWIDTH + 1                                       CALC0055
              IF (IWIDTH.GT.NCELL1) THEN                                CALC0056
                  CALC1D = 0.0                                          CALC0057
                  RETURN                                                CALC0058
              ENDIF                                                     CALC0059
                                                                        CALC0060
C----         Calculate relative start-positions for the loops          CALC0061
              IBACKX = (IWIDTH - IDX) / 2 + 1                           CALC0062
                                                                        CALC0063
C----         Initialise count                                          CALC0064
              NOBS = 0                                                  CALC0065
                                                                        CALC0066
C----         Loop through all the cells                                CALC0067
              DO 300, LOOPX = 1, IWIDTH                                 CALC0068
                  IX = CELL1 - IBACKX + LOOPX                           CALC0069
                  IF (IX.LT.1) IX = IX + NCELL1                         CALC0070
                  IF (IX.GT.NCELL1) IX = IX - NCELL1                    CALC0071
                                                                        CALC0072
C----             Calculate array position of this cell                 CALC0073
                  IY = 1 + (IX - 1) / NCELL                             CALC0074
                  IX = IX - (IY - 1) * NCELL                            CALC0075
                  NOBS = NOBS + ARRAY(IX,IY,IAMINO)                     CALC0076
 300          CONTINUE                                                  CALC0077
                                                                        CALC0078
C----         Check whether have enough observations to calculate a     CALC0079
C             probability                                               CALC0080
              IF (NOBS.GE.MINOBS) THEN                                  CALC0081
                  ENOUGH = .TRUE.                                       CALC0082
                                                                        CALC0083
C----             Calculate the probability and associated log-odds scorCALC0084
                  PROBAB = REAL(NOBS) / REAL(NCOUNT(IAMINO))            CALC0085
                  PROBAB = PROBAB / REAL(IWIDTH)                        CALC0086
                                                                        CALC0087
C----             Return the calculated value                           CALC0088
                  CALC1D = LOG(PROBAB)                                  CALC0089
              ENDIF                                                     CALC0090
                                                                        CALC0091
C----     Loop back if don't have enough observations                   CALC0092
          IF (.NOT.ENOUGH) GO TO 200                                    CALC0093
                                                                        CALC0094
      ENDIF                                                             CALC0095
                                                                        CALC0096
      RETURN                                                            CALC0097
      END                                                               CALC0098
                                                                        CALC0099
      REAL FUNCTION CALC2D(IAMINO,XANG,YANG)                            CALC0001
C-----------------------------------------------------------------------CALC0002
C                                                                       CALC0003
C  FUNCTION CALC2D  -  Calculate log-odds score for the properties of   CALC0004
C                      this residue for a 2D distribution               CALC0005
C                                                                       CALC0006
C----------------------------------------------------------------------+CALC0007
                                                                        CALC0008
      INCLUDE 'tplot.inc'                                               CALC0009
                                                                        CALC0010
      INTEGER        IAMINO, IBACKX, IBACKY, ICELL, IDX, IDY, IWIDTH,   CALC0011
     &               IX, IY, JCELL, LOOPX, LOOPY, NOBS                  CALC0012
      LOGICAL        ENOUGH                                             CALC0013
      REAL           PROBAB, XANG, XVALUE, YANG, YVALUE                 CALC0014
                                                                        CALC0015
                                                                        CALC0016
C---- Determine in which cell the current pair of values falls and      CALC0017
C     calculate the log-odds score                                      CALC0018
      ICELL = (XANG - VALBEG(1)) / STEP(1) + 1                          CALC0019
      JCELL = (YANG - VALBEG(2)) / STEP(2) + 1                          CALC0020
                                                                        CALC0021
C---- If value falls outside plot-region, then return zero              CALC0022
      IF (ICELL.LT.1 .OR. ICELL.GT.NCELL .OR. JCELL.LT.1 .OR.           CALC0023
     &    JCELL.GT.NCELL) THEN                                          CALC0024
          CALC2D = 0.0                                                  CALC0025
                                                                        CALC0026
C---- Otherwise, calculate log-odds value                               CALC0027
      ELSE                                                              CALC0028
                                                                        CALC0029
C----     Determine which corner of the current cell is the nearest     CALC0030
          XVALUE = VALBEG(1) + (ICELL - 1) * STEP(1)                    CALC0031
          IF (XANG - XVALUE.LT.0.5 * STEP(1)) THEN                      CALC0032
              IDX = 0                                                   CALC0033
          ELSE                                                          CALC0034
              IDX = 1                                                   CALC0035
          ENDIF                                                         CALC0036
          YVALUE = VALBEG(2) + (JCELL - 1) * STEP(2)                    CALC0037
          IF (YANG - YVALUE.LT.0.5 * STEP(2)) THEN                      CALC0038
              IDY = 0                                                   CALC0039
          ELSE                                                          CALC0040
              IDY = 1                                                   CALC0041
          ENDIF                                                         CALC0042
                                                                        CALC0043
C----     If the current cell doesn't have more than the minimum no. of CALC0044
C         observations to calculate a sensible probability, then will   CALC0045
C         need to accumulate values from surrounding cells until net    CALC0046
C         no. of observations is enough                                 CALC0047
                                                                        CALC0048
C----     Initialise values                                             CALC0049
          ENOUGH = .FALSE.                                              CALC0050
          IWIDTH = 0                                                    CALC0051
                                                                        CALC0052
C----     Loop to accumulate cells from around the current one (startingCALC0053
C         from cell itself) until have more than the minimum required   CALC0054
C         number of observations                                        CALC0055
 200      CONTINUE                                                      CALC0056
                                                                        CALC0057
C----         Increase number of cells to be put together               CALC0058
              IWIDTH = IWIDTH + 1                                       CALC0059
              IF (IWIDTH.GT.NCELL) THEN                                 CALC0060
                  CALC2D = 0.0                                          CALC0061
                  RETURN                                                CALC0062
              ENDIF                                                     CALC0063
                                                                        CALC0064
C----         Calculate relative start-positions for the loops          CALC0065
              IBACKX = (IWIDTH - IDX) / 2 + 1                           CALC0066
              IBACKY = (IWIDTH - IDY) / 2 + 1                           CALC0067
                                                                        CALC0068
C----         Initialise count                                          CALC0069
              NOBS = 0                                                  CALC0070
                                                                        CALC0071
C----         Loop through all the cells                                CALC0072
              DO 400, LOOPY = 1, IWIDTH                                 CALC0073
                  IY = JCELL - IBACKY + LOOPY                           CALC0074
                  IF (IY.LT.1) IY = IY + NCELL                          CALC0075
                  IF (IY.GT.NCELL) IY = IY - NCELL                      CALC0076
                  DO 300, LOOPX = 1, IWIDTH                             CALC0077
                      IX = ICELL - IBACKX + LOOPX                       CALC0078
                      IF (IX.LT.1) IX = IX + NCELL                      CALC0079
                      IF (IX.GT.NCELL) IX = IX - NCELL                  CALC0080
                      NOBS = NOBS + ARRAY(IX,IY,IAMINO)                 CALC0081
 300              CONTINUE                                              CALC0082
 400          CONTINUE                                                  CALC0083
                                                                        CALC0084
C----         Check whether have enough observations to calculate a     CALC0085
C             probability                                               CALC0086
              IF (NOBS.GE.MINOBS) THEN                                  CALC0087
                  ENOUGH = .TRUE.                                       CALC0088
                                                                        CALC0089
C----             Calculate the probability and associated log-odds scorCALC0090
                  PROBAB = REAL(NOBS) / REAL(NCOUNT(IAMINO))            CALC0091
                  PROBAB = PROBAB / (REAL(IWIDTH * IWIDTH))             CALC0092
                                                                        CALC0093
C----             Return the calculated value                           CALC0094
                  CALC2D = LOG(PROBAB)                                  CALC0095
              ENDIF                                                     CALC0096
                                                                        CALC0097
C----     Loop back if don't have enough observations                   CALC0098
          IF (.NOT.ENOUGH) GO TO 200                                    CALC0099
                                                                        CALC0100
      ENDIF                                                             CALC0101
                                                                        CALC0102
      RETURN                                                            CALC0103
      END                                                               CALC0104
                                                                        CALC0105
      SUBROUTINE PLTEND(DISTRB,LAST)                                    PLTE0001
C-----------------------------------------------------------------------PLTE0002
C                                                                       PLTE0003
C  SUBROUTINE PLTEND  -  Finish current page                            PLTE0004
C                                                                       PLTE0005
C----------------------------------------------------------------------+PLTE0006
                                                                        PLTE0007
CHECK v.3.2-->                                                          PLTE0008
C      SUBROUTINE PLTEND(DISTRB)                                        PLTE0009
CHECK v.3.2<--                                                          PLTE0010
                                                                        PLTE0011
      INCLUDE 'tplot.inc'                                               PLTE0012
                                                                        PLTE0013
      CHARACTER*120 IREC                                                PLTE0014
      INTEGER       DISTRB                                              PLTE0015
CHECK v.3.2-->                                                          PLTE0016
      LOGICAL       LAST                                                PLTE0017
CHECK v.3.2<--                                                          PLTE0018
      REAL          LIMSCR, X1, Y1                                      PLTE0019
                                                                        PLTE0020
C---- Print explanatory note about highlighted residues                 PLTE0021
      IF (DISTRB.EQ.1) THEN                                             PLTE0022
          LIMSCR = LIMGP                                                PLTE0023
      ELSE                                                              PLTE0024
          LIMSCR = LIMCHI                                               PLTE0025
      ENDIF                                                             PLTE0026
      X1 = BBOXX1 + 30.0                                                PLTE0027
      Y1 = BBOXY1 + 30.0                                                PLTE0028
      WRITE(IREC,20) LIMSCR                                             PLTE0029
 20   FORMAT('Numbers of residues are shown in brackets. Those in unfa',PLTE0030
     &    'vourable conformations (score < ',F5.2,') are labelled.')    PLTE0031
      CALL PSTEXT(X1,Y1,10.0,IREC)                                      PLTE0032
                                                                        PLTE0033
C---- Print explanatory note at bottom of page                          PLTE0034
      X1 = BBOXX1 + 30.0                                                PLTE0035
      Y1 = BBOXY1 + 20.0                                                PLTE0036
      CALL PSTEXT(X1,Y1,10.0,'Shading shows favourable conforma' //     PLTE0037
     &    'tions as obtained from an analysis of 163 structures' //     PLTE0038
     &    ' at resolution 2.0A or better.')                             PLTE0039
                                                                        PLTE0040
CHECK v.3.2-->                                                          PLTE0041
CHECK v.3.4-->                                                          PLTE0042
C      IF ((ENSEMB .OR. NMR) .AND. NFILE.GT.1) THEN                     PLTE0043
      IF ((ENSEMB .OR. NMR) .AND. NMODEL.GT.1) THEN                     PLTE0044
CHECK v.3.4<--                                                          PLTE0045
          X1 = BBOXX1 + 30.0                                            PLTE0046
          Y1 = BBOXY1 + 10.0                                            PLTE0047
          CALL PSTEXT(X1,Y1,10.0,'Model numbers shown inside ea' //     PLTE0048
     &        'ch data point.')                                         PLTE0049
      ENDIF                                                             PLTE0050
CHECK v.3.2<--                                                          PLTE0051
                                                                        PLTE0052
C---- Close the current PostScript file                                 PLTE0053
CHECK v.3.2-->                                                          PLTE0054
C      CALL PSCLOS(BBOXX1,BBOXX2,BBOXY1,BBOXY2)                         PLTE0055
      CALL PSENDP                                                       PLTE0056
      IF (.NOT.COMBPS .OR. LAST) THEN                                   PLTE0057
          CALL PSCLOS(BBOXX1,BBOXX2,BBOXY1,BBOXY2)                      PLTE0058
      ENDIF                                                             PLTE0059
CHECK v.3.2<--                                                          PLTE0060
                                                                        PLTE0061
      RETURN                                                            PLTE0062
      END                                                               PLTE0063
                                                                        PLTE0064
      SUBROUTINE GETLAN                                                 GETL0001
C-----------------------------------------------------------------------GETL0002
C                                                                       GETL0003
C  SUBROUTINE GETLAN  -  Read through the bond lengths and angles file  GETL0004
C                        to calculate mean values                       GETL0005
C                                                                       GETL0006
C----------------------------------------------------------------------+GETL0007
                                                                        GETL0008
      INCLUDE 'tplot.inc'                                               GETL0009
                                                                        GETL0010
      CHARACTER*1   INCHN                                               GETL0011
      CHARACTER*3   RESNAM                                              GETL0012
      CHARACTER*80  IREC                                                GETL0013
      INTEGER       IMAIN, IRESID, LINEA                                GETL0014
      REAL          LENANG                                              GETL0015
                                                                        GETL0016
C---- Initialise variables                                              GETL0017
      LINEA = 0                                                         GETL0018
      DO 20, IMAIN = 1, NMAIN                                           GETL0019
          MCHMEA(IMAIN) = 0.0                                           GETL0020
          MCHNUM(IMAIN) = 0                                             GETL0021
 20   CONTINUE                                                          GETL0022
                                                                        GETL0023
C---- Open lengths and angles file, <filename>.lan                      GETL0024
      OPEN(UNIT=4, FILE=FILLAN, STATUS='OLD', FORM='FORMATTED',         GETL0025
     &    ACCESS='SEQUENTIAL',                                          GETL0026
CVAX     -    READONLY,                                                 GETL0027
     &    ERR=900)                                                      GETL0028
                                                                        GETL0029
C---- Read through the header records                                   GETL0030
      DO 50, IMAIN = 1, NALP                                            GETL0031
          READ(4,*)                                                     GETL0032
 50   CONTINUE                                                          GETL0033
                                                                        GETL0034
C---- Loop while reading in records                                     GETL0035
 100  CONTINUE                                                          GETL0036
          READ(4,200,END=500,ERR=904) IREC                              GETL0037
 200      FORMAT(A)                                                     GETL0038
          LINEA = LINEA + 1                                             GETL0039
                                                                        GETL0040
C----     Only process this record if it is not a planar group          GETL0041
          IF (IREC(29:33).NE.'PLANE') THEN                              GETL0042
              READ(IREC,210,ERR=906) IRESID, INCHN, RESNAM, IMAIN,      GETL0043
     &            LENANG                                                GETL0044
 210          FORMAT(I6,A1,5X,A3,I2,F9.4)                               GETL0045
                                                                        GETL0046
C----         Only process this residue if it belongs to the required   GETL0047
C             chain                                                     GETL0048
              IF (CHAIN.EQ.' ' .OR. INCHN.EQ.CHAIN) THEN                GETL0049
                                                                        GETL0050
C----             Accumulate mean values                                GETL0051
                  MCHMEA(IMAIN) = MCHMEA(IMAIN) + LENANG                GETL0052
                  MCHNUM(IMAIN) = MCHNUM(IMAIN) + 1                     GETL0053
              ENDIF                                                     GETL0054
          ENDIF                                                         GETL0055
                                                                        GETL0056
C---- Loop back for next record in file                                 GETL0057
      GO TO 100                                                         GETL0058
                                                                        GETL0059
C---- End of file reached                                               GETL0060
 500  CONTINUE                                                          GETL0061
                                                                        GETL0062
C---- Calculate mean values                                             GETL0063
      DO 800, IMAIN = 1, NMAIN                                          GETL0064
          IF (MCHNUM(IMAIN).GT.0) THEN                                  GETL0065
              MCHMEA(IMAIN) = MCHMEA(IMAIN) / REAL(MCHNUM(IMAIN))       GETL0066
          ENDIF                                                         GETL0067
 800  CONTINUE                                                          GETL0068
                                                                        GETL0069
      GO TO 999                                                         GETL0070
                                                                        GETL0071
C---- Fatal errors                                                      GETL0072
 900  CONTINUE                                                          GETL0073
      PRINT*, '*** ERROR. Unable to open .lan file'                     GETL0074
      GO TO 990                                                         GETL0075
                                                                        GETL0076
 904  CONTINUE                                                          GETL0077
      PRINT*, '*** ERROR. Error reading .lan file at line:', LINEA + 1  GETL0078
      GO TO 990                                                         GETL0079
                                                                        GETL0080
 906  CONTINUE                                                          GETL0081
      PRINT*, '*** ERROR. Data error in .lan file at line:', LINEA + 1  GETL0082
      PRINT*, IREC                                                      GETL0083
      GO TO 990                                                         GETL0084
                                                                        GETL0085
990   CONTINUE                                                          GETL0086
      IFAIL = .TRUE.                                                    GETL0087
                                                                        GETL0088
999   CONTINUE                                                          GETL0089
      RETURN                                                            GETL0090
      END                                                               GETL0091
                                                                        GETL0092
      SUBROUTINE COVSCO                                                 COVS0001
C-----------------------------------------------------------------------COVS0002
C                                                                       COVS0003
C  SUBROUTINE COVSCO  -  Read in the main-chain bond lengths and bond   COVS0004
C                        angles and calculate a covalent quality score  COVS0005
C                                                                       COVS0006
C----------------------------------------------------------------------+COVS0007
                                                                        COVS0008
      INCLUDE 'tplot.inc'                                               COVS0009
                                                                        COVS0010
      CHARACTER*1   AL(NMAIN), INCHN, OLDCHN                            COVS0011
      CHARACTER*3   OLDRES, RESNAM                                      COVS0012
      CHARACTER*5   OLDSEQ, SEQNO                                       COVS0013
      CHARACTER*8   INLANG, LASTLA                                      COVS0014
      CHARACTER*13  ENCODE(NMAIN)                                       COVS0015
      CHARACTER*16  INDESC                                              COVS0016
      CHARACTER*132 AREC, IREC                                          COVS0017
      INTEGER       BANUMB, BLNUMB, IMAIN, IRESID, JRESID, LINE,        COVS0018
     &              SRESID                                              COVS0019
      REAL          BAMEAN, BLMEAN, CALCOV, ENGMEA(NMAIN),              COVS0020
     &              ENGSTD(NMAIN), LENANG, NSTDEV, SVAL                 COVS0021
                                                                        COVS0022
C---- Initialise variables                                              COVS0023
      AREC = ' '                                                        COVS0024
      BAMEAN = 0.0                                                      COVS0025
      BANUMB = 0                                                        COVS0026
      BLMEAN = 0.0                                                      COVS0027
      BLNUMB = 0                                                        COVS0028
      JRESID = 0                                                        COVS0029
      LASTLA = ' '                                                      COVS0030
      LINE = 0                                                          COVS0031
      OLDCHN = ' '                                                      COVS0032
      OLDRES = ' '                                                      COVS0033
      OLDSEQ = ' '                                                      COVS0034
      SRESID = 0                                                        COVS0035
      IREC = ' '                                                        COVS0036
      SVAL = 0.0                                                        COVS0037
                                                                        COVS0038
C---- Rewind the main-chain bond-lengths and angles file                COVS0039
      REWIND(4)                                                         COVS0040
                                                                        COVS0041
C---- Read through the header records and pick up the small-molecule    COVS0042
C     data                                                              COVS0043
      DO 100, IMAIN = 1, NMAIN                                          COVS0044
          READ(4,40,ERR=904) AL(IMAIN), INLANG, ENCODE(IMAIN),          COVS0045
     &        INDESC, ENGMEA(IMAIN), ENGSTD(IMAIN)                      COVS0046
 40       FORMAT(A1,1X,A8,6X,A13,4X,A16,2F8.3)                          COVS0047
 100  CONTINUE                                                          COVS0048
                                                                        COVS0049
C---- Skip all the records giving data on the planar groups             COVS0050
      DO 200, IMAIN = 1, NPLANE                                         COVS0051
          READ(4,*)                                                     COVS0052
 200  CONTINUE                                                          COVS0053
                                                                        COVS0054
C---- Loop while reading in records                                     COVS0055
 300  CONTINUE                                                          COVS0056
          READ(4,320,END=800,ERR=904) IREC                              COVS0057
 320      FORMAT(A)                                                     COVS0058
          LINE = LINE + 1                                               COVS0059
                                                                        COVS0060
C----     Only process this record if it is not a planar group          COVS0061
          IF (IREC(29:33).NE.'PLANE') THEN                              COVS0062
                                                                        COVS0063
C----         Read in the required data                                 COVS0064
              READ(IREC,340,ERR=906) IRESID, INCHN, SEQNO, RESNAM,      COVS0065
     &            IMAIN, LENANG                                         COVS0066
 340          FORMAT(I6,A1,A5,A3,I2,F9.4)                               COVS0067
                                                                        COVS0068
C----         Only process this record if it belongs to the required chaCOVS0069
              IF (CHAIN.EQ.' ' .OR. INCHN.EQ.CHAIN) THEN                COVS0070
                                                                        COVS0071
C----             Calculate number of standard deviations that value difCOVS0072
C                 either from the small-molecule mean, or from protein mCOVS0073
                  IF (USENGH) THEN                                      COVS0074
                      NSTDEV = ABS(LENANG - ENGMEA(IMAIN))              COVS0075
     &                    / ENGSTD(IMAIN)                               COVS0076
                  ELSE                                                  COVS0077
                      NSTDEV = ABS(LENANG - MCHMEA(IMAIN))              COVS0078
     &                    / ENGSTD(IMAIN)                               COVS0079
                  ENDIF                                                 COVS0080
                                                                        COVS0081
C----             Calculate log-odds score for this value and normalize COVS0082
                  SVAL = CALCOV(NSTDEV,GSTEP)                           COVS0083
                  SVAL = (SVAL - GAUMEA) / GAUSTD                       COVS0084
                                                                        COVS0085
C----             Accumulate bond length/angle means                    COVS0086
                  IF (AL(IMAIN).EQ.'L') THEN                            COVS0087
                      BLMEAN = BLMEAN + SVAL                            COVS0088
                      BLNUMB = BLNUMB + 1                               COVS0089
                      COVAVE(1) = COVAVE(1) + SVAL                      COVS0090
                      NUMAVE(1) = NUMAVE(1) + 1                         COVS0091
                  ELSE                                                  COVS0092
                      BAMEAN = BAMEAN + SVAL                            COVS0093
                      BANUMB = BANUMB + 1                               COVS0094
                      COVAVE(2) = COVAVE(2) + SVAL                      COVS0095
                      NUMAVE(2) = NUMAVE(2) + 1                         COVS0096
                  ENDIF                                                 COVS0097
                  COVAVE(3) = COVAVE(3) + SVAL                          COVS0098
                  NUMAVE(3) = NUMAVE(3) + 1                             COVS0099
                                                                        COVS0100
C----             If residue has changed, then calculate average score  COVS0101
                  IF (SRESID.GT.0 .AND. IRESID.NE.SRESID) THEN          COVS0102
                      JRESID = JRESID + 1                               COVS0103
                      CALL RESCOR(BANUMB,BLNUMB,BAMEAN,BLMEAN,JRESID)   COVS0104
                                                                        COVS0105
C----                 Reinitialise stored values                        COVS0106
                      SVAL = 0.0                                        COVS0107
                      BAMEAN = 0.0                                      COVS0108
                      BANUMB = 0                                        COVS0109
                      BLMEAN = 0.0                                      COVS0110
                      BLNUMB = 0                                        COVS0111
                  ENDIF                                                 COVS0112
                                                                        COVS0113
C----             Store current value                                   COVS0114
                  OLDCHN = INCHN                                        COVS0115
                  OLDRES = RESNAM                                       COVS0116
                  OLDSEQ = SEQNO                                        COVS0117
                  SVAL = LENANG                                         COVS0118
                  SRESID = IRESID                                       COVS0119
              ENDIF                                                     COVS0120
          ENDIF                                                         COVS0121
                                                                        COVS0122
C---- Loop back for next record in file                                 COVS0123
      GO TO 300                                                         COVS0124
                                                                        COVS0125
C---- End of file reached                                               COVS0126
 800  CONTINUE                                                          COVS0127
                                                                        COVS0128
C---- Process final residue                                             COVS0129
      IF (SRESID.GT.0) THEN                                             COVS0130
          JRESID = JRESID + 1                                           COVS0131
          CALL RESCOR(BANUMB,BLNUMB,BAMEAN,BLMEAN,JRESID)               COVS0132
      ENDIF                                                             COVS0133
                                                                        COVS0134
C---- Calculate overall mean scores                                     COVS0135
      IF (NUMAVE(1).NE.0) COVAVE(1) = COVAVE(1) / NUMAVE(1)             COVS0136
      IF (NUMAVE(2).NE.0) COVAVE(2) = COVAVE(2) / NUMAVE(2)             COVS0137
      IF (NUMAVE(3).NE.0) COVAVE(3) = COVAVE(3) / NUMAVE(3)             COVS0138
                                                                        COVS0139
      GO TO 999                                                         COVS0140
                                                                        COVS0141
C---- Fatal errors                                                      COVS0142
 904  CONTINUE                                                          COVS0143
      PRINT*, '*** ERROR. Error reading .lan file at line:', LINE + 1   COVS0144
      GO TO 990                                                         COVS0145
                                                                        COVS0146
 906  CONTINUE                                                          COVS0147
      PRINT*, '*** ERROR. Data error in .lan file at line:', LINE + 1   COVS0148
      PRINT*, IREC                                                      COVS0149
                                                                        COVS0150
 990  CONTINUE                                                          COVS0151
      IFAIL = .TRUE.                                                    COVS0152
                                                                        COVS0153
 999  CONTINUE                                                          COVS0154
      RETURN                                                            COVS0155
      END                                                               COVS0156
                                                                        COVS0157
      REAL FUNCTION CALCOV(NSTDEV,GSTEP)                                CALC0001
C-----------------------------------------------------------------------CALC0002
C                                                                       CALC0003
C  FUNCTION CALCOV  -  Calculate log-odds score for the supplied number CALC0004
C                      of st.devs from mean and supplied interval width CALC0005
C                                                                       CALC0006
C----------------------------------------------------------------------+CALC0007
                                                                        CALC0008
      REAL           STLIM, TWOPI                                       CALC0009
      PARAMETER     (                                                   CALC0010
     &               STLIM  = 12.0,                                     CALC0011
     &               TWOPI  = 2.0 * 3.14159265                          CALC0012
     &              )                                                   CALC0013
                                                                        CALC0014
      REAL           AREA, GSTEP, NSTDEV, X1, X2, Y1, Y2                CALC0015
                                                                        CALC0016
C---- Check that not an extreme outlier                                 CALC0017
      IF (NSTDEV.GT.STLIM) NSTDEV = STLIM                               CALC0018
                                                                        CALC0019
C---- Calculate height of Normal distribution on either side of the giveCALC0020
C     number of standard deviations                                     CALC0021
      X1 = NSTDEV - GSTEP / 2.0                                         CALC0022
      X2 = NSTDEV + GSTEP / 2.0                                         CALC0023
      Y1 = (1.0 / SQRT(TWOPI)) * EXP (- X1 * X1 / 2.0)                  CALC0024
      Y2 = (1.0 / SQRT(TWOPI)) * EXP (- X2 * X2 / 2.0)                  CALC0025
                                                                        CALC0026
C---- Calculate approximate area between these two points               CALC0027
      AREA = Y1 * GSTEP - (Y1 - Y2) * GSTEP / 2.0                       CALC0028
                                                                        CALC0029
C---- Taking area to be proportional to the probability of the value    CALC0030
C     being at this point on the Normal distribution, return the log-oddCALC0031
C     score                                                             CALC0032
      CALCOV = LOG(AREA)                                                CALC0033
                                                                        CALC0034
      RETURN                                                            CALC0035
      END                                                               CALC0036
                                                                        CALC0037
      SUBROUTINE RESCOR(BANUMB,BLNUMB,BAMEAN,BLMEAN,IRESID)             RESC0001
C-----------------------------------------------------------------------RESC0002
C                                                                       RESC0003
C  SUBROUTINE RESCOR  -  Calculate the average score for current residueRESC0004
C                                                                       RESC0005
C----------------------------------------------------------------------+RESC0006
                                                                        RESC0007
      INCLUDE 'tplot.inc'                                               RESC0008
                                                                        RESC0009
      INTEGER       BANUMB, BLNUMB, IRESID                              RESC0010
      REAL          BAMEAN, BLMEAN                                      RESC0011
                                                                        RESC0012
C---- Calculate mean values for this residue                            RESC0013
      SCOVAL(3,IRESID) = BLMEAN + BAMEAN                                RESC0014
      IF (BLNUMB + BANUMB.NE.0)                                         RESC0015
     &    SCOVAL(3,IRESID) = SCOVAL(3,IRESID) / (BLNUMB + BANUMB)       RESC0016
      IF (BLNUMB.NE.0) BLMEAN = BLMEAN / BLNUMB                         RESC0017
      IF (BANUMB.NE.0) BAMEAN = BAMEAN / BANUMB                         RESC0018
      SCOVAL(1,IRESID) = BLMEAN                                         RESC0019
      SCOVAL(2,IRESID) = BAMEAN                                         RESC0020
                                                                        RESC0021
      RETURN                                                            RESC0022
      END                                                               RESC0023
                                                                        RESC0024
      SUBROUTINE WRISDH                                                 WRIS0001
C-----------------------------------------------------------------------WRIS0002
C                                                                       WRIS0003
C  SUBROUTINE WRISDH  -  Write out the log-odds scores for each residue WRIS0004
C                                                                       WRIS0005
C----------------------------------------------------------------------+WRIS0006
                                                                        WRIS0007
      INCLUDE 'tplot.inc'                                               WRIS0008
                                                                        WRIS0009
      CHARACTER*1   BRCLOS, BROPEN                                      WRIS0010
CHECK v.3.0.1-->                                                        WRIS0011
C      INTEGER       ICOUNT(NDISTR + 1), IDISTR, IPOS, IRESID, RCOUNT,  WRIS0012
      INTEGER       ICOUNT(NDISTR + 2), IDISTR, IPOS, IRESID, RCOUNT,   WRIS0013
CHECK v.3.0.1<--                                                        WRIS0014
     &              TCOUNT                                              WRIS0015
      REAL          AVERGE, MEAN(NDISTR + 2), TOTAV                     WRIS0016
                                                                        WRIS0017
C---- Initialise accumulators for overall means                         WRIS0018
      DO 50, IDISTR = 1, NDISTR + 2                                     WRIS0019
          ICOUNT(IDISTR) = 0                                            WRIS0020
          MEAN(IDISTR) = 0.0                                            WRIS0021
 50   CONTINUE                                                          WRIS0022
                                                                        WRIS0023
C---- Open output .sdh file                                             WRIS0024
      OPEN(UNIT=7,FILE=FILSDH,STATUS='UNKNOWN',ACCESS='SEQUENTIAL',     WRIS0025
CVAX     -     CARRIAGECONTROL='LIST',                                  WRIS0026
     &    FORM='FORMATTED',ERR=900)                                     WRIS0027
                                                                        WRIS0028
C---- Loop through all the residues, writing the log-odds scores out    WRIS0029
      DO 200, IRESID = 1, NRESID                                        WRIS0030
          AVERGE = 0.0                                                  WRIS0031
          RCOUNT = 0                                                    WRIS0032
          TOTAV = 0.0                                                   WRIS0033
          TCOUNT = 0                                                    WRIS0034
                                                                        WRIS0035
C----     Calculate average for this residue                            WRIS0036
          DO 100, IDISTR = 1, NDISTR                                    WRIS0037
              IF (SCORE(IDISTR,IRESID).LT.999.0) THEN                   WRIS0038
                  AVERGE = AVERGE + SCORE(IDISTR,IRESID)                WRIS0039
                  RCOUNT = RCOUNT + 1                                   WRIS0040
                  TOTAV = TOTAV + SCORE(IDISTR,IRESID)                  WRIS0041
                  TCOUNT = TCOUNT + 1                                   WRIS0042
                  IF (IDISTR.LT.5) THEN                                 WRIS0043
                      IPOS = IDISTR                                     WRIS0044
                  ELSE                                                  WRIS0045
                      IPOS = IDISTR - 1                                 WRIS0046
                  ENDIF                                                 WRIS0047
                  ICOUNT(IPOS) = ICOUNT(IPOS) + 1                       WRIS0048
                  MEAN(IPOS) = MEAN(IPOS) + SCORE(IDISTR,IRESID)        WRIS0049
                  ICOUNT(NDISTR) = ICOUNT(NDISTR) + 1                   WRIS0050
                  MEAN(NDISTR) = MEAN(NDISTR)                           WRIS0051
     &                + SCORE(IDISTR,IRESID)                            WRIS0052
                  ICOUNT(NDISTR+1) = ICOUNT(NDISTR+1) + 1               WRIS0053
                  MEAN(NDISTR+1) = MEAN(NDISTR+1)                       WRIS0054
     &                + SCORE(IDISTR,IRESID)                            WRIS0055
                                                                        WRIS0056
C----             Combine the chi-3 and chi-4 scores together           WRIS0057
                  IF (IDISTR.EQ.5) THEN                                 WRIS0058
                      IF (SCORE(IDISTR - 1,IRESID).GT.999.0) THEN       WRIS0059
                          SCORE(IDISTR - 1,IRESID)                      WRIS0060
     &                        = SCORE(IDISTR,IRESID)                    WRIS0061
                      ELSE                                              WRIS0062
                          SCORE(IDISTR - 1,IRESID)                      WRIS0063
     &                        = (SCORE(IDISTR - 1,IRESID)               WRIS0064
     &                        + SCORE(IDISTR,IRESID)) / 2.0             WRIS0065
                      ENDIF                                             WRIS0066
                  ENDIF                                                 WRIS0067
              ENDIF                                                     WRIS0068
                                                                        WRIS0069
C----         For omega distribution, move it back one position         WRIS0070
              IF (IDISTR.EQ.6) THEN                                     WRIS0071
                  SCORE(IDISTR - 1,IRESID) = SCORE(IDISTR,IRESID)       WRIS0072
              ENDIF                                                     WRIS0073
 100      CONTINUE                                                      WRIS0074
          IF (RCOUNT.NE.0) AVERGE = AVERGE / RCOUNT                     WRIS0075
                                                                        WRIS0076
C----     Add in the mean bond-lengths and bond angles scores           WRIS0077
          IF (SCOVAL(1,IRESID).LT.999.0) THEN                           WRIS0078
              TOTAV = TOTAV + SCOVAL(1,IRESID)                          WRIS0079
              TCOUNT = TCOUNT + 1                                       WRIS0080
              ICOUNT(NDISTR+1) = ICOUNT(NDISTR+1) + 1                   WRIS0081
              MEAN(NDISTR+1) = MEAN(NDISTR+1) + SCOVAL(1,IRESID)        WRIS0082
          ENDIF                                                         WRIS0083
          IF (SCOVAL(2,IRESID).LT.999.0) THEN                           WRIS0084
              TOTAV = TOTAV + SCOVAL(2,IRESID)                          WRIS0085
              TCOUNT = TCOUNT + 1                                       WRIS0086
              ICOUNT(NDISTR+1) = ICOUNT(NDISTR+1) + 1                   WRIS0087
              MEAN(NDISTR+1) = MEAN(NDISTR+1) + SCOVAL(2,IRESID)        WRIS0088
          ENDIF                                                         WRIS0089
          IF (TCOUNT.NE.0) TOTAV = TOTAV / TCOUNT                       WRIS0090
                                                                        WRIS0091
C----     Write the log-odds scores and average out                     WRIS0092
          WRITE(7,120) SAVRES(IRESID), RESID(IRESID),                   WRIS0093
     &        (SCORE(IDISTR,IRESID), IDISTR = 1, NDISTR - 1),           WRIS0094
     &        AVERGE, (SCOVAL(IDISTR,IRESID), IDISTR = 1, 3), TOTAV     WRIS0095
 120      FORMAT(I6,1X,A10,10F9.4)                                      WRIS0096
 200  CONTINUE                                                          WRIS0097
                                                                        WRIS0098
C---- Calculate overall means                                           WRIS0099
      DO 300, IDISTR = 1, NDISTR + 1                                    WRIS0100
          IF (ICOUNT(IDISTR).NE.0) THEN                                 WRIS0101
              MEAN(IDISTR) = MEAN(IDISTR) / ICOUNT(IDISTR)              WRIS0102
          ENDIF                                                         WRIS0103
 300  CONTINUE                                                          WRIS0104
                                                                        WRIS0105
C---- Write the overall means out to file                               WRIS0106
      BROPEN = '('                                                      WRIS0107
      BRCLOS = ')'                                                      WRIS0108
      IF (CHAIN.EQ.' ') THEN                                            WRIS0109
          BROPEN = ' '                                                  WRIS0110
          BRCLOS = ' '                                                  WRIS0111
      ENDIF                                                             WRIS0112
      WRITE(7,320) (MEAN(IDISTR), IDISTR = 1, NDISTR),                  WRIS0113
     &    (COVAVE(IDISTR), IDISTR = 1, 3), MEAN(NDISTR + 1),RESOL,      WRIS0114
     &    BRCODE(1:PSLEN), BROPEN, CHAIN, BRCLOS                        WRIS0115
 320  FORMAT('Means:           ',10F9.4,F6.2,2X,A,3A1)                  WRIS0116
                                                                        WRIS0117
C---- Close the output file                                             WRIS0118
      CLOSE(7)                                                          WRIS0119
                                                                        WRIS0120
      GO TO 999                                                         WRIS0121
                                                                        WRIS0122
 900  CONTINUE                                                          WRIS0123
      PRINT*, '*** ERROR. Unable to open output file: '                 WRIS0124
      PRINT*, FILSDH, '*'                                               WRIS0125
      GO TO 990                                                         WRIS0126
                                                                        WRIS0127
990   CONTINUE                                                          WRIS0128
      IFAIL = .TRUE.                                                    WRIS0129
                                                                        WRIS0130
999   CONTINUE                                                          WRIS0131
      RETURN                                                            WRIS0132
      END                                                               WRIS0133
