      PROGRAM CLEAN                                                     CLEA0001
c ----------------------------------------------------------------------CLEA0002
c                                                                       CLEA0003
c  Windows NT / Win 95 code                                             CLEA0004
c                                                                       CLEA0005
c  Bernhard Rupp 1996 - minor modifications.                            CLEA0006
c                                                                       CLEA0007
c  1.  comment lines restricted to 72 columns                           CLEA0008
c  2.  source code lines numbered                                       CLEA0009
c  3.  to read file name of input file as parameter otherwise ask       CLEA0010
c  4.  taken apart into subroutines                                     CLEA0011
c                                                                       CLEA0012
c       Changes are annotated by WINNT at the beginning of comment linesCLEA0013
c                                                                       CLEA0014
C-----------------------------------------------------------------------CLEA0015
C                                                                       CLEA0016
C CLEAN.F - Amended version of brkcln.f for use with structure-checking CLEA0017
C           suite      of programs, PROCHECK                            CLEA0018
C                                                                       CLEA0019
C           Amendments identified by CHECK v.m.n--> and CHECK v.m.n<--  CLEA0020
C           comment lines, where m.n is the version number.             CLEA0021
C                                                                       CLEA0022
C v.1.0   - Original amendments                                         CLEA0023
C           Roman Laskowski (Apr 1992)                                  CLEA0024
C                                                                       CLEA0025
C v.2.0   - Rewrite to allow entry of any filename for the coordinates  CLEA0026
C           file rather than just the 4-letter Brookhaven code          CLEA0027
C           Roman Laskowski (Jul/Aug 1992)                              CLEA0028
C                                                                       CLEA0029
C v.2.0.1 - Minor amendment to highlight bad chirality of isoleucine    CLEA0030
C           residues                                                    CLEA0031
C           Gail Hutchinson (14 Aug 1992)                               CLEA0032
C                                                                       CLEA0033
C v.2.1   - Write out zero-occupancy atoms to .new file marked with     CLEA0034
C           ATZERO and HEZERO, rather than ATOM and HETATM.             CLEA0035
C         - Write out alternate occupancies to .new file marked with    CLEA0036
C           ATALTand HEALT, rather than ATOM and HETATM.                CLEA0037
C           Roman Laskowski (4-9 Dec 1992)                              CLEA0038
C                                                                       CLEA0039
C v.2.1.1 - Amendment to treat case where occupancy field is blank      CLEA0040
C           (rather than explicitly zero) as being equivalent to        CLEA0041
C           occupancy of 1.0                                            CLEA0042
c           Roman Laskowski (1 Feb 1993)                                CLEA0043
C                                                                       CLEA0044
C v.2.1.3 - Addition of asterisks to error prints so that can be        CLEA0045
C           plucked out of the log files and displayed by the script    CLEA0046
C           file. Removal of .clnlog file and transfer of all its       CLEA0047
C           output messages to the standard output                      CLEA0048
C           Display of counts of number of zero occupancy and alternate CLEA0049
C           position atoms written out                                  CLEA0050
C           Roman Laskowski (26 Mar 1993)                               CLEA0051
C                                                                       CLEA0052
C v.2.1.4 - Minor change to error message where chirality of ILE        CLEA0053
c           residue is wrong. Crude change to limit number of 'unknown  CLEA0054
c           amino acid' error      messages displayed (particularly     CLEA0055
c           irritating for lots of waters)                              CLEA0056
C           Roman Laskowski (12 May 1993)                               CLEA0057
C                                                                       CLEA0058
C v.2.3   - Tiny change so that VAX .COM routines don't show error if   CLEA0059
c           no asterisks found in log file                              CLEA0060
C           Roman Laskowski (14 Nov 1993)                               CLEA0061
C                                                                       CLEA0062
C v.3.0.1 - Changed order of DATA statements in one routine so that     CLEA0063
c           they follow the variable declarations (was causing problems CLEA0064
c           when compiling with the f2c compiler).                      CLEA0065
C           Commented out unreferenced labels (producing compiler       CLEA0066
c           warnings when compiling on Convex).                         CLEA0067
C           Roman Laskowski (29/30 Mar 1994)                            CLEA0068
C                                                                       CLEA0069
C v.3.1   - Amendments for PROCHECK-NMR to deal with each MODEL in an   CLEA0070
C           ensemble separately.                                        CLEA0071
C           Roman Laskowski (18/19 Apr 1994)                            CLEA0072
C                                                                       CLEA0073
C v.3.2   - Residue sequence number replaced by residue ID in display   CLEA0074
c           of which residues have had side-chain atoms swapped.        CLEA0075
C           Roman Laskowski (30 Apr 1994)                               CLEA0076
c                                                                       CLEA0077
C         - Amendment to make NMR pseudo-atoms (labelled with a Q in    CLEA0078
C           pstn 2 of the atom name) be written straight out to the     CLEA0079
c           .new file (eg like hydrogens are).                          CLEA0080
C         - Amendment to deal with slightly non-standard atom names     CLEA0081
C           output by X-PLOR.                                           CLEA0082
C           Roman Laskowski (13 May 1994)                               CLEA0083
c                                                                       CLEA0084
C         - Minor amendments to various statements to make them         CLEA0085
C           acceptable to f2c, and to deal with various uninitialised   CLEA0086
C           variables. SAVE statements for variables moved prior to     CLEA0087
C           declaration of those variables in the routine. (Amendments  CLEA0088
C           supplied by Dave Love at Daresbury).                        CLEA0089
C           David Love/Roman Laskowski (13 Oct 1994)                    CLEA0090
c                                                                       CLEA0091
C         - Amendment for case where one one model in the PDB file and  CLEA0092
C           hence no MODEL and ENDMDL records                           CLEA0093
C           Roman Laskowski (25 Oct 1994)                               CLEA0094
c                                                                       CLEA0095
C         - Reinstatement of facility to process a list of PDB files    CLEA0096
c           in a single run. (For use with PROCOMP when comparing a     CLEA0097
c           set of similar structures).                                 CLEA0098
C           Roman Laskowski (4-7 Nov 1994)                              CLEA0099
c                                                                       CLEA0100
C         - Amendment so that zero-occupancy atoms are not rejected     CLEA0101
c           for NMR structures.                                         CLEA0102
C           Roman Laskowski (28 Nov 1994)                               CLEA0103
C                                                                       CLEA0104
C v.3.3.1 - Increased number of chain-breaks allowed, and checked for   CLEA0105
C           overflow. (Can get a large number of apparent chain-breaks  CLEA0106
C           in structures where one chain is normal, and the other has  CLEA0107
C           C-alpha coordinates only)                                   CLEA0108
C           Roman Laskowski (5 Jun 1995)                                CLEA0109
C                                                                       CLEA0110
C v.3.3.3 - Bug-fix to stop program writing first atom out twice.       CLEA0111
C           Roman Laskowski (1 Feb 1996)                                CLEA0112
C                                                                       CLEA0113
C v.3.4   - Amendment for NMR structures to show which atoms are        CLEA0114
C           incorrectly labelled, but not to actually perform the swap. CLEA0115
C           Roman Laskowski (1 Feb 1996)                                CLEA0116
C                                                                       CLEA0117
C----------------------------------------------------------------------+CLEA0118
                                                                        CLEA0119
WINNT - needed for system call to getarg                                CLEA0120
      integer(2)  n1,status                                             CLEA0121
WINNT - end                                                             CLEA0122
                                                                        CLEA0123
CHECK v.1.0-->                                                          CLEA0124
C      program brkcln                                                   CLEA0125
CHECK v.1.0<--                                                          CLEA0126
c     copyright by David Keith Smith, 1989                              CLEA0127
c***********************************************************************CLEA0128
c     filename:      brkcln.f                                           CLEA0129
c     last modified: 26th april 1991                                    CLEA0130
c***********************************************************************CLEA0131
c     global variables                                                  CLEA0132
c                                                                       CLEA0133
      include  'brkcln.par'                                             CLEA0134
c                                                                       CLEA0135
CHECK v.3.2-->                                                          CLEA0136
C      character aacod1*(abetsz), aacod3*(3*abetsz),                    CLEA0137
C     +          atname*((4*mnchna)-4), seqbcd(maxres)*6,               CLEA0138
C     +          ssord*21, brksym(maxres)*1, headln*132,                CLEA0139
C     +          altcod(maxres)*1, aastd(maxres)*1, atpres(3,maxres)*1, CLEA0140
C     +          thmprs(maxres)*1, hetcod*63, outsty*1, dudcod*105,     CLEA0141
C     +          modcod*(nmod*3), stdmod*(nmod+1), nstdmd*(nmod+1),     CLEA0142
C     +          modpl*(nmod), scname(sideaa)*44, altnam(3)*44, cbet*4, CLEA0143
      character aacod3*(3*abetsz),                                      CLEA0144
     &          atname*((4*mnchna)-4), seqbcd(maxres)*6,                CLEA0145
     &          brksym(maxres)*1,                                       CLEA0146
     &          altcod(maxres)*1, aastd(maxres)*1, atpres(3,maxres)*1,  CLEA0147
     &          thmprs(maxres)*1, hetcod*63, outsty*1, dudcod*105,      CLEA0148
     &          modcod*(nmod*3), stdmod*(nmod+1), nstdmd*(nmod+1),      CLEA0149
     &          modpl*(nmod), scname(sideaa)*44, altnam(3)*44,          CLEA0150
CHECK v.3.2<--                                                          CLEA0151
     &          allspc*44, lab(maxres)*1, extdat(maxlin)*66,            CLEA0152
     &          tphnam*((4*mnchna)-4), olenam*((4*mnchna)-4),           CLEA0153
     &          pphnam*((4*mnchna)-4), chstop(maxres)*1,                CLEA0154
     &          chstrt(maxres)*1, mcalt(mnchna,maxres)*1,               CLEA0155
     &          scalt(sdchna,maxres)*1, altmcc(maxres)*1,               CLEA0156
     &          altscc(maxres)*1, brcode*4,                             CLEA0157
     &          pyrnam*((4*mnchna)-4), altdat(maxalt)*66,               CLEA0158
     &          batnam*((4*mnchna)-4)                                   CLEA0159
c                                                                       CLEA0160
c     character autsum(maxres)*1, dsdef(maxrse)*1,                      CLEA0161
c    +          ssbond(nstruc,maxres)*1, summpl(maxres)*1,              CLEA0162
c    +          sssumm(maxres)*1                                        CLEA0163
c                                                                       CLEA0164
      integer   seqcod(maxres), seqlen, chnsz(maxchn), chnct, hedlen,   CLEA0165
     &          chnend(maxchn), nscats(sideaa), mcser(mnchna,maxres),   CLEA0166
     &          scser(sdchna,maxres), naltmc, naltsc, strlen,           CLEA0167
     &          altsci(3,altmax), altmci(3,altmax), extres(maxlin),     CLEA0168
     &          nline, nrec, totswp(sideaa), ntot, restot(sideaa),      CLEA0169
     &          hist(17), hismin(17), chnlt, altlin, altres(maxalt)     CLEA0170
c                                                                       CLEA0171
c     integer   hbond(maxbnd,maxres), bridpt(2,maxres), dspart(maxres), CLEA0172
c    +          oois(2,maxres), j                                       CLEA0173
c                                                                       CLEA0174
      real      mcaaat(ncoord,mnchna,maxres),                           CLEA0175
     &          scaaat(ncoord,sdchna,maxres), mcangs(nmnang,maxres),    CLEA0176
     &          scangs(nsdang,maxres), mcocc(mnchna,maxres),            CLEA0177
     &          mcthrm(mnchna,maxres), scocc(sdchna,maxres),            CLEA0178
     &          scthrm(sdchna,maxres), altmcr(2,altmax),                CLEA0179
     &          altscr(2,altmax), altmca(3,altmax), altsca(3,altmax),   CLEA0180
     &          sx2, sx, ave, sd                                        CLEA0181
c                                                                       CLEA0182
c     real      hbonde(maxbnd,maxres), cadsts(11,maxres),               CLEA0183
c    +          dsdsts(3,maxres)                                        CLEA0184
c                                                                       CLEA0185
      logical   atomin(mnchna,maxres), scatin(sdchna,maxres), caonly,   CLEA0186
     &          readok, astruc, altern                                  CLEA0187
c                                                                       CLEA0188
      parameter (                                                       CLEA0189
     &          allspc = '                                            ')CLEA0190
c                                                                       CLEA0191
c     local variables                                                   CLEA0192
c                                                                       CLEA0193
      integer   finish, opnera, opnerb, opnerc, opnerd,                 CLEA0194
     &          opnere, opnerf, opnerg, opnerh, fiend, ok, endnfi       CLEA0195
c                                                                       CLEA0196
      character indirn*1, logfil*80                                     CLEA0197
c                                                                       CLEA0198
      parameter (finish = 2, opnera = 1, opnerb = 3, fiend = 4, ok = 0, CLEA0199
     &           indirn = '@', opnerc = 5, endnfi = 6, opnerd=7,        CLEA0200
     &           opnere=9, opnerf=11, opnerg=13, opnerh=15)             CLEA0201
c                                                                       CLEA0202
      logical   finuse                                                  CLEA0203
c                                                                       CLEA0204
c     integer   filety                                                  CLEA0205
c                                                                       CLEA0206
CHECK v.2.1-->                                                          CLEA0207
C      integer   fistat, namlen, iocode, i, corepl, corend,             CLEA0208
C     +          logpl, dirpl, nodepl, outlen                           CLEA0209
      integer   fistat, namlen, iocode, i,                              CLEA0210
     &          outlen                                                  CLEA0211
CHECK v.2.1<--                                                          CLEA0212
c                                                                       CLEA0213
      character finam*(fnamln), brknam*(fnamln), outnam*(fnamln),       CLEA0214
CHECK v.2.1-->                                                          CLEA0215
C     +          altnm*(fnamln), outdir*(fnamln)                        CLEA0216
     &          altnm*(fnamln)                                          CLEA0217
CHECK v.2.1<--                                                          CLEA0218
CHECK v.2.1-->                                                          CLEA0219
C      integer   ifail, outln, brklen, lastsl                           CLEA0220
CHECK v.2.1<--                                                          CLEA0221
      character wkres*3                                                 CLEA0222
      character pronam*11                                               CLEA0223
      character chnnam*9                                                CLEA0224
CHECK v.2.1-->                                                          CLEA0225
C      character brkid*4                                                CLEA0226
CHECK v.2.1<--                                                          CLEA0227
                                                                        CLEA0228
CHECK v.2.0-->                                                          CLEA0229
      CHARACTER*78  PDBFIL                                              CLEA0230
      INTEGER       IEND, ILEN, ISTART                                  CLEA0231
      LOGICAL       IERROR                                              CLEA0232
CHECK v.2.0<--                                                          CLEA0233
                                                                        CLEA0234
CHECK v.2.1.3-->                                                        CLEA0235
      INTEGER       NATALT, NATZER, NHEALT, NHEZER                      CLEA0236
CHECK v.2.1.3<--                                                        CLEA0237
                                                                        CLEA0238
CHECK v.3.1-->                                                          CLEA0239
      INTEGER       IMODEL, NMODEL                                      CLEA0240
CHECK v.3.2-->                                                          CLEA0241
C      LOGICAL       ENDFIL, FIRST, NMR                                 CLEA0242
      LOGICAL       ENDFIL, ENSEMB, FIRST, NMR                          CLEA0243
CHECK v.3.2<--                                                          CLEA0244
CHECK v.3.1<--                                                          CLEA0245
                                                                        CLEA0246
CHECK v.3.2-->                                                          CLEA0247
      integer mcsern, scsern, sctn                                      CLEA0248
      parameter (mcsern=(mnchna*maxres), scsern=(sdchna*maxres),        CLEA0249
     &     sctn=(ncoord*sdchna*maxres))                                 CLEA0250
CHECK v.3.2<--                                                          CLEA0251
c                                                                       CLEA0252
c     input file control loop                                           CLEA0253
c                                                                       CLEA0254
      data hismin(1) / -60 /                                            CLEA0255
      data hismin(2) / -50 /                                            CLEA0256
      data hismin(3) / -40 /                                            CLEA0257
      data hismin(4) / -30 /                                            CLEA0258
      data hismin(5) / -20 /                                            CLEA0259
      data hismin(6) / -10 /                                            CLEA0260
      data hismin(7) /   0 /                                            CLEA0261
      data hismin(8) /  10 /                                            CLEA0262
      data hismin(9) /  20 /                                            CLEA0263
      data hismin(10) / 30 /                                            CLEA0264
      data hismin(11) / 40 /                                            CLEA0265
      data hismin(12) / 50 /                                            CLEA0266
      data hismin(13) / 60 /                                            CLEA0267
      data hismin(14) / 70 /                                            CLEA0268
      data hismin(15) / 80 /                                            CLEA0269
      data hismin(16) / 90 /                                            CLEA0270
      data hismin(17) / 100 /                                           CLEA0271
      data sx2 / 0.0 /                                                  CLEA0272
      data sx / 0.0 /                                                   CLEA0273
      data ntot / 0 /                                                   CLEA0274
CHECK v.3.2-->                                                          CLEA0275
C      data aacod1(1:29) / 'ABCDEFGHIXKLMNXPQRSTXVWXYZX--' /            CLEA0276
CHECK v.3.2<--                                                          CLEA0277
      data aacod3(1:39) / 'ALAASXCYSASPGLUPHEGLYHISILEXXXLYSLEUMET' /   CLEA0278
      data aacod3(40:78) / 'ASNXXXPROGLNARGSERTHRXXXVALTRPXXXTYRGLX' /  CLEA0279
      data aacod3(79:87) / 'UNKPCAINI' /                                CLEA0280
      data hetcod(1:39) / 'AIBPHLSECALMMPRFRDPYRLYMGLMPPHPGLOLETPH' /   CLEA0281
      data hetcod(40:63) / 'ABANLEB2VB2IB1FBNOB2AB2F' /                 CLEA0282
      data modcod(1:39) / 'ACEANIBZOCBZCLTFORNH2PHORHATFATOS NHMYR' /   CLEA0283
      data modcod(40:42) / 'BOC' /                                      CLEA0284
CDEBUG                                                                  CLEA0285
C      data dudcod(1:39) / '  A  C  G  T  U1MA5MCOMC1MG2MGM2G7MGOMG' /  CLEA0286
C      data dudcod(40:78) / ' YG  I +UH2U5MUPSU +C +AGALAGLGCUASGMAN' / CLEA0287
C      data dudcod(79:105) / 'GLCCEGG4SAGSNAGGLSNGSNAMEXC' /            CLEA0288
      data dudcod(1:39) / '                                       ' /   CLEA0289
      data dudcod(40:78) / '                                       ' /  CLEA0290
      data dudcod(79:105) / '                           ' /             CLEA0291
CDEBUG                                                                  CLEA0292
      data stdmod / 'ABCDEFGHIJKLZ' /                                   CLEA0293
      data nstdmd / 'abcdefghijklz' /                                   CLEA0294
      data modpl / '+0++++0++++0' /                                     CLEA0295
CHECK v.3.2-->                                                          CLEA0296
C      data ssord / 'HEheBbGgIiJKLMNOPTtS ' /                           CLEA0297
CHECK v.3.2<--                                                          CLEA0298
      data atname / ' N   CA  C   O      ' /                            CLEA0299
      data tphnam / ' N   CA  C   O1  O2 ' /                            CLEA0300
      data pphnam / ' N   CA  P   OP1 OP2' /                            CLEA0301
      data olenam / ' ON  CA  C   O      ' /                            CLEA0302
      data pyrnam / ' ON  CA  C   O      ' /                            CLEA0303
      data batnam / ' N   CA  B   O1  O2 ' /                            CLEA0304
      data atomin / 34200*.false. /                                     CLEA0305
      data mcaaat / 102600*0 /                                          CLEA0306
      data nscats / 1, 4, 2, 4, 5, 7, 0, 10, 4, -1, 5, 3*4, -1, 3, 5,   CLEA0307
     &              7, 2, 3, -1, 3, 10, -1, 8, 5, -1, 4, 12, 3, 7, 4,   CLEA0308
     &              2*2, 7, 8, 6, 2, 10, 4, 5, 9, 2, 4, 3, 4, 7, 4,     CLEA0309
     &              1, 7 /                                              CLEA0310
      data scname(1) / allspc /                                         CLEA0311
      data scname(2) / ' CG  AD1 AD2                                ' / CLEA0312
      data scname(3) / ' SG                                         ' / CLEA0313
      data scname(4) / ' CG  OD1 OD2                                ' / CLEA0314
      data scname(5) / ' CG  CD  OE1 OE2                            ' / CLEA0315
      data scname(6) / ' CG  CD1 CD2 CE1 CE2 CZ                     ' / CLEA0316
      data scname(7) / allspc /                                         CLEA0317
      data scname(8) / ' CG  ND1 CD2 CE1 NE2 AD1 AD2 AE1 AE2        ' / CLEA0318
      data scname(9) / ' CG1 CG2 CD1                                ' / CLEA0319
      data scname(10) / allspc /                                        CLEA0320
      data scname(11) / ' CG  CD  CE  NZ                             ' /CLEA0321
      data scname(12) / ' CG  CD1 CD2                                ' /CLEA0322
      data scname(13) / ' CG  SD  CE                                 ' /CLEA0323
      data scname(14) / ' CG  OD1 ND2                                ' /CLEA0324
      data scname(15) / allspc /                                        CLEA0325
      data scname(16) / ' CG  CD                                     ' /CLEA0326
      data scname(17) / ' CG  CD  OE1 NE2                            ' /CLEA0327
      data scname(18) / ' CG  CD  NE  CZ  NH1 NH2                    ' /CLEA0328
      data scname(19) / ' OG                                         ' /CLEA0329
      data scname(20) / ' OG1 CG2                                    ' /CLEA0330
      data scname(21) / allspc /                                        CLEA0331
      data scname(22) / ' CG1 CG2                                    ' /CLEA0332
      data scname(23) / ' CG  CD1 CD2 NE1 CE2 CE3 CZ2 CZ3 CH2        ' /CLEA0333
      data scname(24) / allspc /                                        CLEA0334
      data scname(25) / ' CG  CD1 CD2 CE1 CE2 CZ  OH                 ' /CLEA0335
      data scname(26) / ' CG  CD  AE1 AE2                            ' /CLEA0336
      data scname(27) / allspc /                                        CLEA0337
      data scname(28) / ' CG  CD  OE                                 ' /CLEA0338
      data scname(29) / ' CG  CD  CE  NZ  CI1 CI2 CI3 CI4 NI2 CI5 CI6' /CLEA0339
      data scname(30) / ' CB1 CB2                                    ' /CLEA0340
      data scname(31) / ' CG  CD1 CD2 CE1 CE2 CZ                     ' /CLEA0341
      data scname(32) / 'SEG  OD1 OD2                                ' /CLEA0342
      data scname(33) / ' CM                                         ' /CLEA0343
      data scname(34) / ' SG                                         ' /CLEA0344
      data scname(35) / ' CG  CD1 CD2 CE1 CE2 CZ                     ' /CLEA0345
      data scname(36) / '                                            ' /CLEA0346
      data scname(37) / ' CG  CD  CE  NZ  CM                         ' /CLEA0347
      data scname(38) / ' CM                                         ' /CLEA0348
      data scname(39) / ' CG  CD1 CD2 CE1 CE2 CZ                     ' /CLEA0349
      data scname(40) / ' P   O1P O2P                                ' /CLEA0350
      data scname(41) / ' CG  CD1 CD2                                ' /CLEA0351
      data scname(42) / ' CG  CD1 CD2 CE1 CE2 CZ                     ' /CLEA0352
      data scname(43) / ' CG                                         ' /CLEA0353
      data scname(44) / ' CG  CD  CE                                 ' /CLEA0354
      data scname(45) / ' CG1 CG2                                    ' /CLEA0355
      data scname(46) / ' CG1 CG2 CD1                                ' /CLEA0356
      data scname(47) / ' CG  CD1 CD2 CE1 CE2 CZ                     ' /CLEA0357
      data scname(48) / ' CG  CD  CE                                 ' /CLEA0358
      data scname(49) / allspc /                                        CLEA0359
      data scname(50) / ' CG  CD1 CD2 CE1 CE2 CZ                     ' /CLEA0360
      data altnam(1) / ' CG  AD1 AD2                                ' / CLEA0361
      data altnam(2) / ' CG  AD1 AD2                                ' / CLEA0362
      data altnam(3) / ' CG  CD  AE1 AE2                            ' / CLEA0363
CHECK v.3.2-->                                                          CLEA0364
C      data cbet / ' CB ' /                                             CLEA0365
CHECK v.3.2<--                                                          CLEA0366
      data fistat / 0 /                                                 CLEA0367
      data finuse / .false. /                                           CLEA0368
      data pronam / 'ldamino.dat' /                                     CLEA0369
      data chnnam / 'chain.dat' /                                       CLEA0370
CHECK v.3.2-->                                                          CLEA0371
      data scaaat /sctn*0.0/,  mcser /mcsern*0/, scser/scsern*0/,       CLEA0372
     &     mcalt /mcsern*' '/, mcthrm /mcsern*0.0/, hist /17*0/,        CLEA0373
     &     scthrm /scsern*0.0/, extdat /maxlin*' '/,                    CLEA0374
     &     scalt /scsern*' '/, nrec/0/                                  CLEA0375
CHECK v.3.2<--                                                          CLEA0376
c                                                                       CLEA0377
CHECK v.3.0.1-->                                                        CLEA0378
C  209 format (a4, 1x, i2, 1x, i2, 1x, f5.2, 1x, f5.2)                  CLEA0379
C  210 format (a4, 1x, i4)                                              CLEA0380
C  211 format (a4, 1x, i2, 1x, i2, 1x, f5.2, 1x, f5.2, 1x, a2)          CLEA0381
CHECK v.3.0.1<--                                                        CLEA0382
                                                                        CLEA0383
CHECK v.1.0-->                                                          CLEA0384
C 1000 format (' Brookhaven clean-up program BRKCLN - copyright by',    CLEA0385
C     + ' David Keith Smith, 1989')                                     CLEA0386
C 1010 format (/,' Enter the name of the next file to be processed.',/, CLEA0387
C     + '  Just a file name for a Brookhaven format file,',/,           CLEA0388
C     + '  ', A1, 'filename for a file holding names of Brookhaven',    CLEA0389
C     + ' format files,',/,                                             CLEA0390
C     + '  <RETURN> to exit.')                                          CLEA0391
CHECK v.1.0<--                                                          CLEA0392
                                                                        CLEA0393
CHECK v.3.0.1-->                                                        CLEA0394
C 1020 format (A)                                                       CLEA0395
C 1030 format (' Working on Brookhaven file ',A,' . . . ')              CLEA0396
CHECK v.3.0.1<--                                                        CLEA0397
                                                                        CLEA0398
CHECK v.3.2-->                                                          CLEA0399
 1020 format (A)                                                        CLEA0400
 1030 format (' Working on Brookhaven file ',A,' . . . ')               CLEA0401
CHECK v.3.2<--                                                          CLEA0402
                                                                        CLEA0403
CHECK v.2.1.3-->                                                        CLEA0404
C 1040 format (' Unable to open output file "',A, '"')                  CLEA0405
C 1050 format (' Unable to open the list file "', A, '"')               CLEA0406
C 1060 format (' Unable to open the Brookhaven file "', A, '"')         CLEA0407
C 1070 format (' Unable to open output file "', A, '"')                 CLEA0408
 1040 format (' **** Unable to open output file "',A, '"')              CLEA0409
CHECK v.3.2-->                                                          CLEA0410
C 1050 format (' **** Unable to open the list file "', A, '"')          CLEA0411
CHECK v.3.2<--                                                          CLEA0412
 1060 format (' **** Unable to open the Brookhaven file "', A, '"')     CLEA0413
 1070 format (' **** Unable to open output file "', A, '"')             CLEA0414
CHECK v.2.1.3<--                                                        CLEA0415
CHECK v.3.4-->                                                          CLEA0416
 1080 format (' Total number of residues changed and total number',     CLEA0417
     & ' of residues:')                                                 CLEA0418
 1082 format (' Total number of residues that need to be changed and t',CLEA0419
     & 'otal number of residues:')                                      CLEA0420
CHECK v.3.4<--                                                          CLEA0421
 1090 format (5X, A3, 2i6)                                              CLEA0422
CHECK v.2.1.3-->                                                        CLEA0423
C 1100 format (' C-alpha only file')                                    CLEA0424
C 1110 format (' Error while reading file')                             CLEA0425
C 3001 format (' Error reading input file on unit ',i3,                 CLEA0426
C     +        ' after ',i5,' lines')                                   CLEA0427
C 7000 format ('Error opening file "',A,'" for input.')                 CLEA0428
C 7001 format ('Error opening file "',A,'" for output.')                CLEA0429
 1100 format (' **** C-alpha only file')                                CLEA0430
 1110 format (' **** Error while reading file')                         CLEA0431
CHECK v.3.0.1-->                                                        CLEA0432
C 3001 format (' **** Error reading input file on unit ',i3,            CLEA0433
C     +        ' after ',i5,' lines')                                   CLEA0434
C 7000 format ('**** Error opening file "',A,'" for input.')            CLEA0435
CHECK v.3.0.1<--                                                        CLEA0436
 7001 format ('**** Error opening file "',A,'" for output.')            CLEA0437
CHECK v.2.1.3<--                                                        CLEA0438
c                                                                       CLEA0439
                                                                        CLEA0440
CHECK v.2.1.3-->                                                        CLEA0441
C---- Initialise counts of zero- and alternate-occupancy atoms written oCLEA0442
      NATZER = 0                                                        CLEA0443
      NHEZER = 0                                                        CLEA0444
      NATALT = 0                                                        CLEA0445
      NHEALT = 0                                                        CLEA0446
CHECK v.2.1.3<--                                                        CLEA0447
CHECK v.3.1-->                                                          CLEA0448
      NMODEL = 0                                                        CLEA0449
CHECK v.3.1<--                                                          CLEA0450
                                                                        CLEA0451
                                                                        CLEA0452
CHECK v.1.0-->                                                          CLEA0453
C---- Print initial heading                                             CLEA0454
WINNT - header statement modified --                                    CLEA0455
 1000 FORMAT (//,                                                       CLEA0456
     &    ' Clean-up program CLEAN - Written by David Keith Smith,',    CLEA0457
     &    ' 1989.',/,                                                   CLEA0458
     &    '                          Amended by Roman Laskowski,',      CLEA0459
     &    ' 1992.',/,                                                   CLEA0460
     &    '                          Windows NT-Version B.Rupp 1996'//) CLEA0461
                                                                        CLEA0462
      write (*, 1000)                                                   CLEA0463
WINNT - end                                                             CLEA0464
CHECK v.2.0-->                                                          CLEA0465
C---- Accept 4-letter Brookhaven code                                   CLEA0466
C      WRITE (*, 1010)                                                  CLEA0467
C 1010 FORMAT (' Enter 4-letter Brookhaven code of structure:')         CLEA0468
C      READ (*,1020) BRCODE                                             CLEA0469
                                                                        CLEA0470
C---- Accept full path to input .pdb file                               CLEA0471
C      WRITE (*, 1015)                                                  CLEA0472
C 1015 FORMAT (//,                                                      CLEA0473
C     -    ' Enter full path to .pdb file holding coordinates.',/,      CLEA0474
C     -    ' Note: File name must be of the form [path]p<code>.pdb')    CLEA0475
C      READ (*,1020) FINAM                                              CLEA0476
C      NAMLEN = INDEX(FINAM,SPACE) - 1                                  CLEA0477
C      IF (NAMLEN.LE.0) THEN                                            CLEA0478
C          BRKNAM = 'p' // BRCODE // '.pdb'                             CLEA0479
C          NAMLEN = 0                                                   CLEA0480
C      ELSE                                                             CLEA0481
C          BRKNAM = FINAM(1:NAMLEN) // 'p' // BRCODE // '.pdb'          CLEA0482
C      ENDIF                                                            CLEA0483
C      NAMLEN = NAMLEN + 9                                              CLEA0484
C      WRITE (*,1018) BRKNAM(1:NAMLEN)                                  CLEA0485
C 1018 FORMAT(//,                                                       CLEA0486
C     -    ' Processing file: ',A,/)                                    CLEA0487
                                                                        CLEA0488
C---- Form the names of the output files                                CLEA0489
C      OUTNAM = 'p' // BRCODE // '.new'                                 CLEA0490
C      ALTNM  = 'p' // BRCODE // '.alt'                                 CLEA0491
C      LOGFIL = 'p' // BRCODE // '.clnlog'                              CLEA0492
C      OUTLEN = 9                                                       CLEA0493
CHECK v.2.0<--                                                          CLEA0494
CHECK v.1.0<--                                                          CLEA0495
                                                                        CLEA0496
CHECK v.2.0-->                                                          CLEA0497
C---- Accept name of original .pdb file holding the structure           CLEA0498
                                                                        CLEA0499
WINNT - accept file name from command line if provided else ask for it  CLEA0500
      n1 = 1                                                            CLEA0501
      CALL GETARG(n1, pdbfil, status)                                   CLEA0502
      if (status.lt.1) then                                             CLEA0503
         PRINT*, 'Enter filename containing coordinates of structure'   CLEA0504
CHECK v.3.2-->                                                          CLEA0505
         PRINT*, '  (for file containing ensemble of NMR structures en',CLEA0506
     &    'ter @filename;'                                              CLEA0507
         PRINT*, '   for set of separate PDB files to be processed, en',CLEA0508
     &    'ter %filelist,'                                              CLEA0509
         PRINT*, '   where filelist contains a list of PDB files to be',CLEA0510
     &    ' cleaned up)'                                                CLEA0511
CHECK v.3.2<--                                                          CLEA0512
         READ(*,10) PDBFIL                                              CLEA0513
10       FORMAT(A)                                                      CLEA0514
      else                                                              CLEA0515
         write(*,*) 'File name parsed from command line : ',pdbfil      CLEA0516
      end if                                                            CLEA0517
WINNT - end                                                             CLEA0518
                                                                        CLEA0519
CHECK v.3.1-->                                                          CLEA0520
C---- If the very first character of the file-name is an @, then the    CLEA0521
C     PDB file is an NMR file containing several models of the structureCLEA0522
      IF (PDBFIL(1:1).EQ.'@') THEN                                      CLEA0523
          NMR = .TRUE.                                                  CLEA0524
          PDBFIL = PDBFIL(2:)                                           CLEA0525
          FIRST = .TRUE.                                                CLEA0526
CHECK v.3.2-->                                                          CLEA0527
          ENSEMB = .FALSE.                                              CLEA0528
      ELSE IF (PDBFIL(1:1).EQ.'%') THEN                                 CLEA0529
          ENSEMB = .TRUE.                                               CLEA0530
          FIRST = .TRUE.                                                CLEA0531
          NMR = .FALSE.                                                 CLEA0532
CHECK v.3.2<--                                                          CLEA0533
      ELSE                                                              CLEA0534
CHECK v.3.2-->                                                          CLEA0535
          ENSEMB = .FALSE.                                              CLEA0536
          FIRST = .TRUE.                                                CLEA0537
CHECK v.3.2<--                                                          CLEA0538
          NMR = .FALSE.                                                 CLEA0539
      ENDIF                                                             CLEA0540
CHECK v.3.1<--                                                          CLEA0541
                                                                        CLEA0542
CHECK v.3.2-->                                                          CLEA0543
C---- If processing a set of PDB files listed in the %filelist specifiedCLEA0544
C     by the user, open the file-list                                   CLEA0545
      fistat = ok                                                       CLEA0546
      IF (ENSEMB) THEN                                                  CLEA0547
          finam = PDBFIL                                                CLEA0548
          finuse = .true.                                               CLEA0549
          namlen = INDEX(finam,space)                                   CLEA0550
          do 180 i = 1, namlen - 1                                      CLEA0551
              finam(i:i) = finam(i+1:i+1)                               CLEA0552
  180     continue                                                      CLEA0553
          finam(namlen:namlen) = space                                  CLEA0554
          open (namfi, file=finam, status='old',                        CLEA0555
CVAX     -        READONLY,                                             CLEA0556
     &        iostat=iocode)                                            CLEA0557
          if (iocode .ne. 0) fistat = opnera                            CLEA0558
          if (fistat.eq.opnera) GO TO 902                               CLEA0559
      ENDIF                                                             CLEA0560
CHECK v.3.2<--                                                          CLEA0561
                                                                        CLEA0562
CHECK v.3.2-->                                                          CLEA0563
C---- If processing a list of structures, get the name of the next one  CLEA0564
C     from the file list                                                CLEA0565
 200  CONTINUE                                                          CLEA0566
      IF (ENSEMB .AND. fistat .eq. ok) then                             CLEA0567
          read (namfi, 1020, iostat=iocode) brknam                      CLEA0568
          if (iocode .lt. 0) then                                       CLEA0569
             close (namfi)                                              CLEA0570
             finuse = .false.                                           CLEA0571
             fistat = endnfi                                            CLEA0572
          else                                                          CLEA0573
             namlen = index(brknam,space) - 1                           CLEA0574
             write (*, 1030) brknam(1:namlen)                           CLEA0575
          end if                                                        CLEA0576
          PDBFIL = brknam                                               CLEA0577
          NMR = .FALSE.                                                 CLEA0578
      ENDIF                                                             CLEA0579
CHECK v.3.2<--                                                          CLEA0580
                                                                        CLEA0581
C---- Peel off directory path and extension                             CLEA0582
      CALL GETNAM(PDBFIL,ISTART,IEND,IERROR)                            CLEA0583
      IF (IERROR) GO TO 990                                             CLEA0584
                                                                        CLEA0585
C---- Form names of other files that will be required in default dir    CLEA0586
      ILEN = IEND - ISTART + 1                                          CLEA0587
      BRCODE = ' '                                                      CLEA0588
      brknam = PDBFIL                                                   CLEA0589
      NAMLEN = 78                                                       CLEA0590
      OUTNAM = PDBFIL(ISTART:IEND) // '.new'                            CLEA0591
CHECK v.3.2-->                                                          CLEA0592
      outlen = ILEN + 4                                                 CLEA0593
CHECK v.3.2<--                                                          CLEA0594
      ALTNM = PDBFIL(ISTART:IEND) // '.alt'                             CLEA0595
      LOGFIL = PDBFIL(ISTART:IEND) // '.clnlog'                         CLEA0596
CHECK v.2.0<--                                                          CLEA0597
                                                                        CLEA0598
WINNT - output file name printed just as a reminder                     CLEA0599
      write(*,*) 'New PDB output file name will be   : ',outnam         CLEA0600
WINNT - end                                                             CLEA0601
c                                                                       CLEA0602
c     write (*, *) 'Do you require Standard or Full output (<S> or F)'  CLEA0603
c     read (*, '(A1)') outsty                                           CLEA0604
c     if ((outsty .eq. 'F') .or. (outsty .eq. 'f')) then                CLEA0605
c        outsty = 'F'                                                   CLEA0606
c     else                                                              CLEA0607
c        outsty = 'S'                                                   CLEA0608
c      end if                                                           CLEA0609
c                                                                       CLEA0610
CHECK v.3.2-->                                                          CLEA0611
C      fistat = ok                                                      CLEA0612
CHECK v.3.2<--                                                          CLEA0613
                                                                        CLEA0614
CHECK v.1.0-->                                                          CLEA0615
C      call getstr ('Enter output directory',                           CLEA0616
C     +             '/home/bsm/naylor/data/', outdir, outln, ifail)     CLEA0617
C      if (ifail .ne. 0)  then                                          CLEA0618
C         write(6,*)'Error in GETSTR: Ifail = ', ifail                  CLEA0619
C         stop                                                          CLEA0620
C      end if                                                           CLEA0621
CHECK v.1.0<--                                                          CLEA0622
                                                                        CLEA0623
      outsty = 'F'                                                      CLEA0624
                                                                        CLEA0625
CHECK v.1.0-->                                                          CLEA0626
C      open (protfi, file=pronam, status='unknown', iostat=iocode)      CLEA0627
C      if (iocode .ne. 0) fistat = opnerd                               CLEA0628
C      open (chnfi,  file=chnnam, status='unknown', iostat=iocode)      CLEA0629
C      if (iocode .ne. 0) fistat = opnere                               CLEA0630
CHECK v.1.0<--                                                          CLEA0631
                                                                        CLEA0632
c                                                                       CLEA0633
c     Get the name of the next Brookhaven file or file of names from    CLEA0634
c     the user, finish is set when they've had enough.                  CLEA0635
c                                                                       CLEA0636
                                                                        CLEA0637
CHECK v.1.0-->                                                          CLEA0638
C  100 continue                                                         CLEA0639
C      write (*, 1010) indirn                                           CLEA0640
C      read  (*, 1020) finam                                            CLEA0641
C      namlen = index(finam,space) - 1                                  CLEA0642
C      if (namlen .le. 0) then                                          CLEA0643
C         fistat = finish                                               CLEA0644
C      else                                                             CLEA0645
C         if (finam(1:1) .eq. indirn) then                              CLEA0646
Cc           open the list file if necessary                            CLEA0647
C            finuse = .true.                                            CLEA0648
C            do 180 i = 1, namlen - 1                                   CLEA0649
C            finam(i:i) = finam(i+1:i+1)                                CLEA0650
C  180       continue                                                   CLEA0651
C            finam(namlen:namlen) = space                               CLEA0652
C            open (namfi, file=finam, status='old', iostat=iocode)      CLEA0653
C            if (iocode .ne. 0) fistat = opnera                         CLEA0654
C         end if                                                        CLEA0655
C      end if                                                           CLEA0656
CHECK v.1.0<--                                                          CLEA0657
                                                                        CLEA0658
c                                                                       CLEA0659
c     Get the next Brookhaven file name, either from the list file or   CLEA0660
c     from what the user just typed in, and load it into BRKNAM.        CLEA0661
c                                                                       CLEA0662
                                                                        CLEA0663
CHECK v.1.0-->                                                          CLEA0664
C  200 continue                                                         CLEA0665
C      if (fistat .eq. ok) then                                         CLEA0666
C         if (finuse) then                                              CLEA0667
C            read (namfi, 1020, iostat=iocode) brknam                   CLEA0668
C            if (iocode .lt. 0) then                                    CLEA0669
C               close (namfi)                                           CLEA0670
C               finuse = .false.                                        CLEA0671
C               fistat = endnfi                                         CLEA0672
C            else                                                       CLEA0673
C               namlen = index(brknam,space) - 1                        CLEA0674
C               write (*, 1030) brknam(1:namlen)                        CLEA0675
C            end if                                                     CLEA0676
C         else                                                          CLEA0677
C            brknam = finam                                             CLEA0678
C         end if                                                        CLEA0679
C      end if                                                           CLEA0680
CHECK v.1.0<--                                                          CLEA0681
                                                                        CLEA0682
c                                                                       CLEA0683
c     Open the Brookhaven file if everything ok                         CLEA0684
c                                                                       CLEA0685
      if (fistat .eq. ok) then                                          CLEA0686
CHECK v.1.0-->                                                          CLEA0687
C         open (brkfi, file=brknam, status='old', iostat=iocode)        CLEA0688
CHECK v.1.0<--                                                          CLEA0689
         open (brkfi, file=brknam, status='old', iostat=iocode          CLEA0690
CVAX     -        , READONLY                                            CLEA0691
     &        )                                                         CLEA0692
         if (iocode .ne. 0) fistat = opnerb                             CLEA0693
      end if                                                            CLEA0694
c                                                                       CLEA0695
c     Parse the file name to strip off nodenames, logical names,        CLEA0696
c     directory names and file extensions. Then open the corresponding  CLEA0697
c     ".NEW" and ".ALT" output files. NB: This code seems still to be   CLEA0698
c     VAX specific for files NOT in the user's current working directoryCLEA0699
c                                                                       CLEA0700
      if (fistat .eq. ok) then                                          CLEA0701
                                                                        CLEA0702
CHECK v.1.0-->                                                          CLEA0703
C         nodepl = index(brknam,'::')                                   CLEA0704
C         if (nodepl .ne. 0) then                                       CLEA0705
C            logpl = (nodepl+1) + index(brknam(nodepl+2:),':')          CLEA0706
C         else                                                          CLEA0707
C            logpl = index(brknam,':')                                  CLEA0708
C         end if                                                        CLEA0709
C         dirpl = index(brknam,']')                                     CLEA0710
C         corepl = max(logpl,dirpl) + 1                                 CLEA0711
C         corepl = lastsl(brknam) + 1                                   CLEA0712
C         corend = ( (corepl-1) + index(brknam(corepl:),'.') ) - 1      CLEA0713
C         if (corend .eq. (corepl-2)) corend = namlen                   CLEA0714
C         if (corend .lt. corepl) then                                  CLEA0715
C            write (6,*) brknam(1:namlen)                               CLEA0716
C            fistat = opnerc                                            CLEA0717
C         end if                                                        CLEA0718
C         brklen = corend - corepl +1                                   CLEA0719
C         outnam = outdir(1:outln)//brknam(corepl:corend)// '.new'      CLEA0720
C         altnm  = outdir(1:outln)//brknam(corepl:corend)// '.alt'      CLEA0721
C         logfil = outdir(1:outln)//brknam(corepl:corend)// '.clnlog'   CLEA0722
C         outlen = outln + brklen + 4                                   CLEA0723
CHECK v.1.0<--                                                          CLEA0724
                                                                        CLEA0725
CHECK v.2.1.3-->                                                        CLEA0726
C         open (logfi, file=logfil, status='unknown', iostat=iocode)    CLEA0727
C         if (iocode .ne. 0) fistat = opnerf                            CLEA0728
CHECK v.2.1.3<--                                                        CLEA0729
CHECK v.1.0-->                                                          CLEA0730
C         open (outfi, file=outnam, status='unknown', iostat=iocode)    CLEA0731
         open (outfi, file=outnam, status='unknown', iostat=iocode      CLEA0732
CVAX     -       , CARRIAGECONTROL='LIST'                               CLEA0733
     &   )                                                              CLEA0734
CHECK v.1.0<--                                                          CLEA0735
         if (iocode .ne. 0) fistat = opnerg                             CLEA0736
      end if                                                            CLEA0737
                                                                        CLEA0738
CHECK v.3.1-->                                                          CLEA0739
C---- If this is an NMR structure, then will loop back to here until    CLEA0740
C     all models have been individually processed                       CLEA0741
 100  CONTINUE                                                          CLEA0742
                                                                        CLEA0743
CHECK v.3.2-->                                                          CLEA0744
C      IF (NMR) THEN                                                    CLEA0745
      if (fistat.eq.ok) then                                            CLEA0746
CHECK v.3.2<--                                                          CLEA0747
                                                                        CLEA0748
C----     If this is not the first model encountered, write out the     CLEA0749
C         ENDMDL record for the previous one                            CLEA0750
CHECK v.3.2-->                                                          CLEA0751
C          IF (.NOT.FIRST) THEN                                         CLEA0752
          IF (NMR .AND. .NOT.FIRST) THEN                                CLEA0753
CHECK v.3.2<--                                                          CLEA0754
              WRITE(OUTFI,110) ENDMDL                                   CLEA0755
 110          FORMAT(A)                                                 CLEA0756
          ENDIF                                                         CLEA0757
          FIRST = .FALSE.                                               CLEA0758
                                                                        CLEA0759
C----     Loop until first ATOM record encountered, or a MODEL record   CLEA0760
C         is found (indicating an NMR structure) or end-of-file         CLEA0761
c         encountered                                                   CLEA0762
CHECK v.3.2-->                                                          CLEA0763
C          CALL GETMOD(BRKFI,OUTFI,IMODEL,MXMODL,ENDFIL,IERROR)         CLEA0764
          CALL GETMOD(BRKFI,OUTFI,IMODEL,MXMODL,ENDFIL,IERROR,NMR)      CLEA0765
CHECK v.3.2<--                                                          CLEA0766
                                                                        CLEA0767
C----     Check whether end of file or data error encountered           CLEA0768
          IF (ENDFIL) GO TO 500                                         CLEA0769
          IF (IERROR) GO TO 990                                         CLEA0770
CHECK v.3.2-->                                                          CLEA0771
          IF (NMR) THEN                                                 CLEA0772
CHECK v.3.2<--                                                          CLEA0773
              NMODEL = NMODEL + 1                                       CLEA0774
              PRINT*                                                    CLEA0775
              PRINT*, '   Processing NMR model', IMODEL                 CLEA0776
          ENDIF                                                         CLEA0777
CHECK v.3.1<--                                                          CLEA0778
CHECK v.3.2-->                                                          CLEA0779
      endif                                                             CLEA0780
CHECK v.3.2<--                                                          CLEA0781
                                                                        CLEA0782
c                                                                       CLEA0783
c     If we have survived this far, we have a file to process otherwise CLEA0784
c     provide error messages.                                           CLEA0785
c                                                                       CLEA0786
      if (fistat .eq. ok) then                                          CLEA0787
c        process file                                                   CLEA0788
c        open (errfi, status='SCRATCH')                                 CLEA0789
         readok = .true.                                                CLEA0790
         caonly = .true.                                                CLEA0791
         astruc = .false.                                               CLEA0792
         altern = .false.                                               CLEA0793
         nline  = 0                                                     CLEA0794
         ave    = -9.99                                                 CLEA0795
         sd     = -9.99                                                 CLEA0796
         do 345 i = 1,sideaa                                            CLEA0797
         totswp(i) = 0                                                  CLEA0798
         restot(i) = 0                                                  CLEA0799
  345    continue                                                       CLEA0800
         call rdbrk (mcaaat, atname, atomin, aacod3, hetcod, seqcod,    CLEA0801
     &               seqbcd, scaaat, scatin, altcod, aastd,  atpres,    CLEA0802
CHECK v.3.2-->                                                          CLEA0803
C     +               thmprs, caonly, astruc, headln, hedlen, readok,   CLEA0804
     &               thmprs, caonly, astruc, hedlen, readok,            CLEA0805
CHECK v.3.2<--                                                          CLEA0806
     &               dudcod, modcod, stdmod, nstdmd, modpl,  seqlen,    CLEA0807
     &               nscats, mcser,  scser,  mcocc,  mcthrm, scocc,     CLEA0808
     &               scthrm, scname, altnam, naltmc, naltsc, altmci,    CLEA0809
     &               altsci, altmcr, altscr, altmca, altsca, lab,       CLEA0810
     &               extdat, extres, nline,  tphnam, olenam, pphnam,    CLEA0811
     &               nrec,   mcalt,  scalt,  altmcc, altscc, pyrnam,    CLEA0812
CHECK v.3.1-->                                                          CLEA0813
C     +               restot, altdat, altlin, altres, batnam, brcode)   CLEA0814
     &               restot, altdat, altlin, altres, batnam, brcode,    CLEA0815
     &               NMR)                                               CLEA0816
CHECK v.3.1<--                                                          CLEA0817
         if (naltmc .gt. 0 .or. naltsc .gt. 0 .or. altlin .gt. 0)       CLEA0818
     &          altern = .true.                                         CLEA0819
c        open file for alternates if there are any                      CLEA0820
         if (altern) open (altfi, file=altnm, status='unknown',         CLEA0821
     &                     iostat=iocode)                               CLEA0822
         if (iocode .ne. 0) fistat = opnerh                             CLEA0823
         if (readok .and. (.not. caonly)) then                          CLEA0824
c           look for breaks across the peptide bonds                    CLEA0825
            call chnbrk (mcaaat, atomin, seqbcd, brksym, chnsz,  chnct, CLEA0826
     &                   chnend, caonly, seqlen, chstop, chstrt, chnlt) CLEA0827
c           find main chain torsion angles                              CLEA0828
CHECK v.3.2-->                                                          CLEA0829
C            call mkangl (mcaaat, mcangs, atomin, chnsz,  chnct,  caonlyCLEA0830
C     +                   seqlen, scaaat, scatin, seqcod, aacod3, hetcodCLEA0831
C     +                   sx2,    sx,     ntot,   hist,   hismin, ave,  CLEA0832
C     +                   sd)                                           CLEA0833
            call mkangl (mcaaat, mcangs, atomin, chnsz,  chnct,  caonly,CLEA0834
     &                   scaaat, scatin, seqcod, aacod3, hetcod,        CLEA0835
     &                   sx2,    sx,     ntot,   hist,   hismin, ave,   CLEA0836
     &                   sd)                                            CLEA0837
CHECK v.3.2<--                                                          CLEA0838
                                                                        CLEA0839
CHECK v.1.0-->                                                          CLEA0840
C            write (protfi, 209) brcode, chnct, chnlt, ave, sd          CLEA0841
C            do 220 i = 1, chnct                                        CLEA0842
C            write (chnfi, 210) brcode, chnsz(i)                        CLEA0843
C  220       continue                                                   CLEA0844
CHECK v.1.0<--                                                          CLEA0845
                                                                        CLEA0846
c           find sidechain chi angles                                   CLEA0847
            if (outsty .eq. 'F') call mksang (mcaaat, atomin, scaaat,   CLEA0848
     &                                        scangs, scatin, seqcod,   CLEA0849
     &                                        aacod3, hetcod, seqlen,   CLEA0850
     &                                        nscats, chstop, chstrt,   CLEA0851
     &                                        seqbcd, mcser,  scser,    CLEA0852
     &                                        mcocc,  mcthrm, scocc,    CLEA0853
CHECK v.3.2-->                                                          CLEA0854
C     +                                        scthrm, scname, altnam,  CLEA0855
     &                                        scthrm, scname,           CLEA0856
CHECK v.3.2<--                                                          CLEA0857
     &                                        naltmc, naltsc, altmci,   CLEA0858
     &                                        altsci, altmcr, altscr,   CLEA0859
     &                                        altmca, altsca, lab,      CLEA0860
     &                                        extdat, extres, nline,    CLEA0861
     &                                        tphnam, olenam, pphnam,   CLEA0862
     &                                        atname, mcangs, nrec,     CLEA0863
     &                                        mcalt,  scalt,  altmcc,   CLEA0864
     &                                        altscc, pyrnam, totswp,   CLEA0865
     &                                        altdat, altlin, altres,   CLEA0866
CHECK v.2.1.3-->                                                        CLEA0867
C     +                                        batnam)                  CLEA0868
     &                                        batnam, NATALT, NATZER,   CLEA0869
CHECK v.3.2-->                                                          CLEA0870
C     +                                        NHEALT, NHEZER)          CLEA0871
     &                                        NHEALT, NHEZER,NMR)       CLEA0872
CHECK v.3.2<--                                                          CLEA0873
CHECK v.2.1.3<--                                                        CLEA0874
CHECK v.3.1-->                                                          CLEA0875
C            close (outfi)                                              CLEA0876
            IF (.NOT.NMR) close (outfi)                                 CLEA0877
CHECK v.3.1<--                                                          CLEA0878
            if (altern) close (altfi)                                   CLEA0879
         else                                                           CLEA0880
            if (readok .and. caonly .and. outsty .eq. 'F') then         CLEA0881
               if (fistat .ne. ok) then                                 CLEA0882
                  write (*, 1040) outnam(1:outlen)                      CLEA0883
c                 close (errfi)                                         CLEA0884
               else                                                     CLEA0885
                  call chnbrk (mcaaat, atomin, seqbcd, brksym, chnsz,   CLEA0886
     &                         chnct,  chnend, caonly, seqlen, chstop,  CLEA0887
     &                         chstrt, chnlt)                           CLEA0888
                  call calout (mcaaat, atomin, seqcod, aacod3, hetcod,  CLEA0889
     &                         seqlen, chstop, chstrt, seqbcd, mcser,   CLEA0890
     &                         mcocc,  mcthrm, extdat, nline,  extres,  CLEA0891
     &                         nrec)                                    CLEA0892
                                                                        CLEA0893
CHECK v.1.0-->                                                          CLEA0894
C                  write (protfi, 211) brcode, chnct, chnlt, ave,       CLEA0895
C     +                                sd, 'CA'                         CLEA0896
C                  do 230 i = 1, chnct                                  CLEA0897
C                  write (chnfi, 210) brcode, chnsz(i)                  CLEA0898
C  230             continue                                             CLEA0899
CHECK v.1.0<--                                                          CLEA0900
                                                                        CLEA0901
CHECK v.3.1-->                                                          CLEA0902
C                  close (outfi)                                        CLEA0903
                  IF (.NOT.NMR) close (outfi)                           CLEA0904
CHECK v.3.1<--                                                          CLEA0905
                  if (altern) close (altfi)                             CLEA0906
               end if                                                   CLEA0907
c              close (errfi)                                            CLEA0908
            else                                                        CLEA0909
               close (outfi, status='delete')                           CLEA0910
               if (altern) close (altfi, status='delete')               CLEA0911
c              close (errfi)                                            CLEA0912
            end if                                                      CLEA0913
            if (astruc) close (authfi)                                  CLEA0914
            if (caonly .and. readok) write (*, 1100)                    CLEA0915
            if (.not. readok) then                                      CLEA0916
               write (*, 1110)                                          CLEA0917
            end if                                                      CLEA0918
         end if                                                         CLEA0919
CHECK v.2.1.3-->                                                        CLEA0920
C         write (logfi, 1080)                                           CLEA0921
CHECK v.3.4-->                                                          CLEA0922
C         write (*, 1080)                                               CLEA0923
         IF (.NOT.NMR) THEN                                             CLEA0924
             write (*, 1080)                                            CLEA0925
         ELSE                                                           CLEA0926
             write (*, 1082)                                            CLEA0927
         ENDIF                                                          CLEA0928
CHECK v.3.4<--                                                          CLEA0929
CHECK v.2.1.3<--                                                        CLEA0930
         do 300 i = 1, sideaa                                           CLEA0931
         if (i .le. abetsz) then                                        CLEA0932
            wkres = aacod3((i*3)-2:i*3)                                 CLEA0933
         else                                                           CLEA0934
            wkres = hetcod(((i-abetsz)*3)-2:(i-abetsz)*3)               CLEA0935
         end if                                                         CLEA0936
                                                                        CLEA0937
CHECK v.1.0-->                                                          CLEA0938
C         write (logfi, 1090) wkres, totswp(i), restot(i)               CLEA0939
         IF (RESTOT(I).GT.0) THEN                                       CLEA0940
CHECK v.2.1.3-->                                                        CLEA0941
C             write (logfi, 1090) wkres, totswp(i), restot(i)           CLEA0942
             write (*, 1090) wkres, totswp(i), restot(i)                CLEA0943
CHECK v.2.1.3<--                                                        CLEA0944
         ENDIF                                                          CLEA0945
CHECK v.1.0<--                                                          CLEA0946
                                                                        CLEA0947
  300    continue                                                       CLEA0948
CHECK v.2.1.3-->                                                        CLEA0949
C         close (logfi)                                                 CLEA0950
CHECK v.2.1.3<--                                                        CLEA0951
      else if (fistat .eq. opnera) then                                 CLEA0952
CHECK v.3.2-->                                                          CLEA0953
C         write (*, 1050) finam(1:namlen)                               CLEA0954
CHECK v.3.2<--                                                          CLEA0955
         finuse = .false.                                               CLEA0956
      else if (fistat .eq. opnerb) then                                 CLEA0957
         write (*, 1060) brknam(1:namlen)                               CLEA0958
      else if (fistat .eq. opnerc) then                                 CLEA0959
         write (*, 1070) outnam(1:outlen)                               CLEA0960
      else if (fistat .eq. opnerd) then                                 CLEA0961
         write (*, 7001) pronam(1:strlen(pronam))                       CLEA0962
      else if (fistat .eq. opnere) then                                 CLEA0963
         write (*, 7001) chnnam(1:strlen(chnnam))                       CLEA0964
      else if (fistat .eq. opnerf) then                                 CLEA0965
         write (*, 7001) logfil(1:strlen(logfil))                       CLEA0966
      else if (fistat .eq. opnerg) then                                 CLEA0967
         write (*, 7001) outnam(1:strlen(outnam))                       CLEA0968
      else if (fistat .eq. opnerh) then                                 CLEA0969
         write (*, 7001) altnm(1:strlen(altnm))                         CLEA0970
      end if                                                            CLEA0971
c                                                                       CLEA0972
c     if they want more we'll cooperate                                 CLEA0973
c                                                                       CLEA0974
                                                                        CLEA0975
CHECK v.1.0-->                                                          CLEA0976
C      if (fistat .ne. finish) then                                     CLEA0977
C         fistat = ok                                                   CLEA0978
C         if (finuse) then                                              CLEA0979
C            goto 200                                                   CLEA0980
C         else                                                          CLEA0981
C            goto 100                                                   CLEA0982
C         end if                                                        CLEA0983
C      end if                                                           CLEA0984
C      close (protfi)                                                   CLEA0985
C      close (chnfi)                                                    CLEA0986
CHECK v.1.0<--                                                          CLEA0987
                                                                        CLEA0988
c                                                                       CLEA0989
c     compute total standard deviation and average dihedral angle       CLEA0990
c     call tsdev(sx2,sx,ntot)                                           CLEA0991
c     write (*,*)' distribution of dihedral angles'                     CLEA0992
c     do 400 i=1,17                                                     CLEA0993
c     write (*,*) hismin(i),'-',hismin(i)+10, hist(i)                   CLEA0994
c 400 continue                                                          CLEA0995
c                                                                       CLEA0996
                                                                        CLEA0997
CHECK v.2.1.3-->                                                        CLEA0998
C---- Print numbers of alternate and zero occupancies written out       CLEA0999
      IF (NATZER.GT.0) THEN                                             CLEA1000
          PRINT*, ' * Number of zero-occupancy atoms (labelled',        CLEA1001
     &        ' ATZERO)   ', NATZER                                     CLEA1002
      ENDIF                                                             CLEA1003
      IF (NHEZER.GT.0) THEN                                             CLEA1004
          PRINT*, ' * Number of zero-occupancy hetatoms (labelled',     CLEA1005
     &        ' HEZERO)', NHEZER                                        CLEA1006
      ENDIF                                                             CLEA1007
      IF (NATALT.GT.0) THEN                                             CLEA1008
          PRINT*, ' * Number of alternate atoms (labelled',             CLEA1009
     &        ' ATALT)      ', NATALT                                   CLEA1010
      ENDIF                                                             CLEA1011
      IF (NHEALT.GT.0) THEN                                             CLEA1012
          PRINT*, ' * Number of alternate hetatoms (labelled',          CLEA1013
     &        ' HEALT)   ', NHEALT                                      CLEA1014
      ENDIF                                                             CLEA1015
CHECK v.2.1.3<--                                                        CLEA1016
                                                                        CLEA1017
CHECK v.3.1-->                                                          CLEA1018
C---- If this is an NMR structure, then loop back for next model        CLEA1019
      IF (NMR) GO TO 100                                                CLEA1020
                                                                        CLEA1021
C---- If this is an NMR structure, show how many models have been       CLEA1022
c     processed                                                         CLEA1023
 500  CONTINUE                                                          CLEA1024
      IF (NMR) THEN                                                     CLEA1025
          PRINT*                                                        CLEA1026
          PRINT*, '* NMR ensemble comprises', NMODEL, ' model ',        CLEA1027
     &        'structures'                                              CLEA1028
      ENDIF                                                             CLEA1029
                                                                        CLEA1030
CHECK v.3.2-->                                                          CLEA1031
      if (fistat .ne. finish) then                                      CLEA1032
         fistat = ok                                                    CLEA1033
         if (finuse) then                                               CLEA1034
            goto 200                                                    CLEA1035
         end if                                                         CLEA1036
      end if                                                            CLEA1037
      close (protfi)                                                    CLEA1038
      close (chnfi)                                                     CLEA1039
CHECK v.3.2<--                                                          CLEA1040
                                                                        CLEA1041
      GO TO 990                                                         CLEA1042
                                                                        CLEA1043
CHECK v.3.2-->                                                          CLEA1044
C---- Error opening mplot.in file                                       CLEA1045
C 900  CONTINUE                                                         CLEA1046
C      PRINT*, '*** ERROR opening mplot.in file. Program aborted'       CLEA1047
CHECK v.3.2<--                                                          CLEA1048
CHECK v.3.1<--                                                          CLEA1049
                                                                        CLEA1050
CHECK v.3.2-->                                                          CLEA1051
 902  CONTINUE                                                          CLEA1052
      PRINT*, '*** ERROR opening file:', finam(1:namlen)                CLEA1053
CHECK v.3.2<--                                                          CLEA1054
                                                                        CLEA1055
CHECK v.2.0-->                                                          CLEA1056
990   CONTINUE                                                          CLEA1057
CHECK v.2.0<--                                                          CLEA1058
CHECK v.2.3-->                                                          CLEA1059
      PRINT*, '* Program completed'                                     CLEA1060
CHECK v.2.3<--                                                          CLEA1061
      end                                                               CLEA1062
