      SUBROUTINE STORAT(IRESID,RSNAME,INCHN,INSEQ,IBAT,COORDS,NEWCHN)   STOR001
C-----------------------------------------------------------------------STOR002
C                                                                       STOR003
C  SUBROUTINE STORAT Store atom coordinates for current atom and, when  STOR004
C                    have required bond length or angle, calculate its  STOR005
C                    value                                              STOR006
C                                                                       STOR007
C----------------------------------------------------------------------+STOR008
                                                                        STOR009
CHECK v.2.0.1-->                                                        STOR010
      SAVE                                                              STOR011
CHECK v.2.0.1<--                                                        STOR012
                                                                        STOR013
      INCLUDE 'anglen.inc'                                              STOR014
                                                                        STOR015
      CHARACTER*1   CHAIN(2), INCHN                                     STOR016
      CHARACTER*3   RNAME(2), RSNAME, RTEST                             STOR017
      CHARACTER*5   INSEQ, SEQNO(2)                                     STOR018
      INTEGER       CURRES, CURRNT, FOUND, I, IBAT, IMAIN, IPOINT,      STOR019
     &              IPOS, IRESID, ISLOT, LAST, NONSP, SRESID(2)         STOR020
CHECK v.3.2-->                                                          STOR021
C      LOGICAL       FILLED(2,NMATOM), FIRST, MATCH, NEWCHN, THISUN     STOR022
      LOGICAL       FILLED(2,NMATOM), FIRST, MATCH, NEWCHN, SPANER,     STOR023
     &              THISUN                                              STOR024
CHECK v.3.2<--                                                          STOR025
      REAL          COORDS(3), SAVXYZ(3,3), VALUE, XYZ(3,2,NMATOM)      STOR026
                                                                        STOR027
CHECK v.2.0.1-->                                                        STOR028
      DATA CURRES, CURRNT, LAST / 0, 1, 2 /                             STOR029
CHECK v.2.0.1<--                                                        STOR030
      DATA FIRST  / .TRUE. /                                            STOR031
                                                                        STOR032
CHECK v.2.1-->                                                          STOR033
C---- Initialise variables on first entry into routine                  STOR034
      IF (FIRST) THEN                                                   STOR035
          CHAIN(1) = ' '                                                STOR036
          CHAIN(2) = ' '                                                STOR037
          DO 100, I = 1, NMATOM                                         STOR038
              FILLED(1,I) = .FALSE.                                     STOR039
              FILLED(2,I) = .FALSE.                                     STOR040
              DO 50, IPOS = 1, 3                                        STOR041
                  XYZ(IPOS,1,I) = 0.0                                   STOR042
                  XYZ(IPOS,2,I) = 0.0                                   STOR043
 50           CONTINUE                                                  STOR044
 100      CONTINUE                                                      STOR045
          RNAME(1) = ' '                                                STOR046
          RNAME(2) = ' '                                                STOR047
          SEQNO(1) = ' '                                                STOR048
          SEQNO(2) = ' '                                                STOR049
          SRESID(1) = 0                                                 STOR050
          SRESID(2) = 0                                                 STOR051
      ENDIF                                                             STOR052
CHECK v.2.1<--                                                          STOR053
                                                                        STOR054
C---- If residue has changed, calculate all possible angles for previousSTOR055
C     residue and then re-initialise pointers                           STOR056
      IF (.NOT.FIRST .AND. (NEWCHN .OR. IRESID.NE.CURRES)) THEN         STOR057
                                                                        STOR058
C----     Loop through all bond lengths and angles to be tried          STOR059
          DO 200, IMAIN = 1, NMAIN                                      STOR060
                                                                        STOR061
C----         Test whether the current residue is appropriate for the   STOR062
C             current bond length/angle                                 STOR063
                                                                        STOR064
C----         Initialise variables                                      STOR065
              THISUN = .TRUE.                                           STOR066
              NONSP = 0                                                 STOR067
                                                                        STOR068
C----         Store the first exception definition (which will be one   STOR069
C             of: ALL, NOT, or blank)                                   STOR070
              RTEST = EXTYPE(1,EXCEPT(IMAIN))                           STOR071
                                                                        STOR072
C----         If the appropriate residue name belongs to the previous   STOR073
C             residue, set the name-pointer to that                     STOR074
              IF (INAME(IMAIN).EQ.-1) THEN                              STOR075
                  IPOINT = LAST                                         STOR076
                                                                        STOR077
C----         Otherwise, set the name-pointer to the current residue    STOR078
              ELSE                                                      STOR079
                  IPOINT = CURRNT                                       STOR080
              ENDIF                                                     STOR081
                                                                        STOR082
C----         If the name of the residue we're looking at is blank      STOR083
C             then skip the rest of the routines altogether             STOR084
              IF (RNAME(IPOINT).EQ.'   ') THEN                          STOR085
                  THISUN = .FALSE.                                      STOR086
                  GO TO 140                                             STOR087
              ENDIF                                                     STOR088
                                                                        STOR089
C----         If the exception test matches ALL residues, then keep     STOR090
              IF (RTEST.EQ.'ALL') GO TO 140                             STOR091
                                                                        STOR092
C----         If the excpetion test is blank, then the residue names    STOR093
C             that follow in the EXTYPE table are the required ones     STOR094
              IF (RTEST.EQ.'   ') MATCH = .TRUE.                        STOR095
                                                                        STOR096
C----         If the excpetion test is NOT, then the residue names      STOR097
C             that follow in the EXTYPE table are the exceptions        STOR098
              IF (RTEST.EQ.'NOT') MATCH = .FALSE.                       STOR099
                                                                        STOR100
C----         Check through the residue names in the remainder of the   STOR101
C             current exception definition to see if the current        STOR102
C             residue appears                                           STOR103
              DO 120, I = 2, MAXEXC                                     STOR104
                  RTEST = EXTYPE(I,EXCEPT(IMAIN))                       STOR105
                                                                        STOR106
C----             If the residue name is in the table, then can         STOR107
C                 proceed if we're looking for an exact match, or can   STOR108
C                 reject the current bond length/angle if we're looking STOR109
C                 for a NOT match                                       STOR110
                  IF (RTEST.EQ.RNAME(IPOINT)) THEN                      STOR111
                      IF (MATCH) THEN                                   STOR112
                          GO TO 140                                     STOR113
                      ELSE                                              STOR114
                          THISUN = .FALSE.                              STOR115
                          GO TO 140                                     STOR116
                      ENDIF                                             STOR117
                  ENDIF                                                 STOR118
 120          CONTINUE                                                  STOR119
                                                                        STOR120
C----         If looking for the given residue in the table and have gotSTOR121
C             to here, then a match was not found                       STOR122
              IF (MATCH) THISUN = .FALSE.                               STOR123
                                                                        STOR124
C----         If residue is appropriate, see if have all the required   STOR125
C             atoms                                                     STOR126
 140          CONTINUE                                                  STOR127
              IF (THISUN) THEN                                          STOR128
                                                                        STOR129
C----             Loop through the 2 or 3 atoms defining current bond   STOR130
C                 length/angle to determine if all are present          STOR131
CHECK v.3.2-->                                                          STOR132
                  SPANER = .FALSE.                                      STOR133
CHECK v.3.2<--                                                          STOR134
                  FOUND = 0                                             STOR135
                  DO 150, I = 1, NBAT(IMAIN)                            STOR136
                                                                        STOR137
C----                 Check whether the atom at this position in the    STOR138
C                     pair/triplet comes from the previous residue or   STOR139
C                     from the current one                              STOR140
                      IF (RELPOS(I,IMAIN).EQ.-1) THEN                   STOR141
                          IPOS = LAST                                   STOR142
CHECK v.3.2-->                                                          STOR143
                          SPANER = .TRUE.                               STOR144
CHECK v.3.2<--                                                          STOR145
                      ELSE                                              STOR146
                          IPOS = CURRNT                                 STOR147
                      ENDIF                                             STOR148
                                                                        STOR149
C----                 If have the appropriate atom, save its coordinatesSTOR150
                      IF (FILLED(IPOS,BATNUM(I,IMAIN))) THEN            STOR151
                          FOUND = FOUND + 1                             STOR152
                          SAVXYZ(1,I) = XYZ(1,IPOS,BATNUM(I,IMAIN))     STOR153
                          SAVXYZ(2,I) = XYZ(2,IPOS,BATNUM(I,IMAIN))     STOR154
                          SAVXYZ(3,I) = XYZ(3,IPOS,BATNUM(I,IMAIN))     STOR155
                      ENDIF                                             STOR156
 150              CONTINUE                                              STOR157
                                                                        STOR158
C----             If have all the atoms, calculate distance/angle       STOR159
                  IF (FOUND.EQ.NBAT(IMAIN)) THEN                        STOR160
                      CALL CALC(BANGLE(IMAIN),SAVXYZ,RADDEG,VALUE)      STOR161
                                                                        STOR162
CHECK v.3.2-->                                                          STOR163
CC----                 Write value to output file                       STOR164
C                      WRITE(2,180) SRESID(IPOINT), CHAIN(IPOINT),      STOR165
C     -                    SEQNO(IPOINT), RNAME(IPOINT), IMAIN, VALUE   STOR166
C 180                  FORMAT(I6,A1,A5,A3,I2,F9.4)                      STOR167
C                                                                       STOR168
C----                 If the bond length/angle spans two residues, writeSTOR169
C                     out the value, showing both residues              STOR170
                      IF (SPANER) THEN                                  STOR171
                          WRITE(2,180) SRESID(IPOINT), CHAIN(IPOINT),   STOR172
     &                        SEQNO(IPOINT), RNAME(IPOINT), IMAIN,      STOR173
     &                        VALUE, CHAIN(LAST), SEQNO(LAST),          STOR174
     &                        RNAME(LAST), CHAIN(CURRNT),               STOR175
     &                        SEQNO(CURRNT), RNAME(CURRNT)              STOR176
 180                      FORMAT(I6,A1,A5,A3,I2,F9.4,2(1X,A1,A5,A3))    STOR177
                                                                        STOR178
C----                 Otherwise, just write out the current residue     STOR179
                      ELSE                                              STOR180
                          WRITE(2,180) SRESID(IPOINT), CHAIN(IPOINT),   STOR181
     &                        SEQNO(IPOINT), RNAME(IPOINT), IMAIN,      STOR182
     &                        VALUE                                     STOR183
                      ENDIF                                             STOR184
CHECK v.3.2<--                                                          STOR185
                  ENDIF                                                 STOR186
              ENDIF                                                     STOR187
 200      CONTINUE                                                      STOR188
                                                                        STOR189
C----     Set current residue as previous residue and reinitialise      STOR190
c         pointers                                                      STOR191
          CURRNT = 3 - CURRNT                                           STOR192
          LAST = 3 - LAST                                               STOR193
          DO 300, ISLOT = 1, NMATOM                                     STOR194
              FILLED(CURRNT,ISLOT) = .FALSE.                            STOR195
 300      CONTINUE                                                      STOR196
      ENDIF                                                             STOR197
                                                                        STOR198
C---- If at start of new chain or at break in chain, then initialise    STOR199
c     variables                                                         STOR200
      IF (FIRST .OR. NEWCHN) THEN                                       STOR201
                                                                        STOR202
C----     Initialise flags showing whether have the 5 main-chain coords STOR203
C         for current and prior residues                                STOR204
          DO 400, ISLOT = 1, NMATOM                                     STOR205
              FILLED(1,ISLOT) = .FALSE.                                 STOR206
              FILLED(2,ISLOT) = .FALSE.                                 STOR207
 400      CONTINUE                                                      STOR208
          CURRNT = 1                                                    STOR209
          LAST = 2                                                      STOR210
          CHAIN(LAST) = ' '                                             STOR211
          CHAIN(CURRNT) = ' '                                           STOR212
          FIRST = .FALSE.                                               STOR213
          NEWCHN = .FALSE.                                              STOR214
          CURRES = IRESID                                               STOR215
          RNAME(LAST) = '   '                                           STOR216
          RNAME(CURRNT) = '   '                                         STOR217
          SEQNO(LAST) = '   '                                           STOR218
          SEQNO(CURRNT) = '   '                                         STOR219
      ENDIF                                                             STOR220
                                                                        STOR221
C---- Store coordinates of current atom                                 STOR222
      IF (IBAT.GT.0) THEN                                               STOR223
          CURRES = IRESID                                               STOR224
          CHAIN(CURRNT) = INCHN                                         STOR225
          FILLED(CURRNT,IBAT) = .TRUE.                                  STOR226
          RNAME(CURRNT) = RSNAME                                        STOR227
          SEQNO(CURRNT) = INSEQ                                         STOR228
          SRESID(CURRNT) = IRESID                                       STOR229
          XYZ(1,CURRNT,IBAT) = COORDS(1)                                STOR230
          XYZ(2,CURRNT,IBAT) = COORDS(2)                                STOR231
          XYZ(3,CURRNT,IBAT) = COORDS(3)                                STOR232
      ENDIF                                                             STOR233
                                                                        STOR234
      RETURN                                                            STOR235
      END                                                               STOR236
