CHECK v.3.2-->                                                          GETM001
C      SUBROUTINE GETMOD(BRKFI,OUTFI,IMODEL,MXMODL,ENDFIL,IERROR)       GETM002
      SUBROUTINE GETMOD(BRKFI,OUTFI,IMODEL,MXMODL,ENDFIL,IERROR,NMR)    GETM001
CHECK v.3.2<--                                                          GETM002
                                                                        GETM003
      SAVE                                                              GETM004
                                                                        GETM005
      CHARACTER*80  IREC                                                GETM006
      INTEGER       BRKFI, IMODEL, LINE, MXMODL, OUTFI                  GETM007
CHECK v.3.2-->                                                          GETM008
C      LOGICAL       ENDFIL, FOUND, IERROR                              GETM009
      LOGICAL       ENDFIL, FOUND, IERROR, NMR                          GETM010
CHECK v.3.2<--                                                          GETM011
                                                                        GETM012
C---- Initialise variables                                              GETM013
      ENDFIL = .FALSE.                                                  GETM014
      FOUND = .FALSE.                                                   GETM015
      IERROR = .FALSE.                                                  GETM016
      LINE = 0                                                          GETM017
                                                                        GETM018
C---- Loop through the file until hit a MODEL record or the EOF         GETM019
 100  CONTINUE                                                          GETM020
                                                                        GETM021
C----     Read in the next record                                       GETM022
          READ(BRKFI,120,ERR=900,END=500) IREC                          GETM023
 120      FORMAT(A)                                                     GETM024
                                                                        GETM025
C----     Write it out to the .new file                                 GETM026
CHECK v.3.3.3-->                                                        GETM027
         IF (IREC(1:6).NE.'ATOM  ') THEN                                GETM028
CHECK v.3.3.3<--                                                        GETM029
             WRITE(OUTFI,120) IREC                                      GETM030
CHECK v.3.3.3-->                                                        GETM031
         ENDIF                                                          GETM032
CHECK v.3.3.3<--                                                        GETM033
                                                                        GETM034
C----     Test if this is a MODEL record                                GETM035
          IF (IREC(1:5).EQ.'MODEL') THEN                                GETM036
              LINE = LINE + 1                                           GETM037
              READ(IREC,140,ERR=902) IMODEL                             GETM038
 140          FORMAT(11X,I3)                                            GETM039
              FOUND = .TRUE.                                            GETM040
              IF (IMODEL.GT.MXMODL) GO TO 904                           GETM041
CHECK v.3.2-->                                                          GETM042
              NMR = .TRUE.                                              GETM043
          ELSE IF (IREC(1:6).EQ.'ATOM  ') THEN                          GETM044
              IMODEL = 1                                                GETM045
              FOUND = .TRUE.                                            GETM046
              BACKSPACE(BRKFI)                                          GETM047
CHECK v.3.2<--                                                          GETM048
          ENDIF                                                         GETM049
                                                                        GETM050
C---- Loop back for next record                                         GETM051
      IF (.NOT.FOUND) GO TO 100                                         GETM052
      GO TO 999                                                         GETM053
                                                                        GETM054
C---- End of file reached                                               GETM055
 500  CONTINUE                                                          GETM056
      ENDFIL = .TRUE.                                                   GETM057
                                                                        GETM058
      GO TO 999                                                         GETM059
                                                                        GETM060
C---- Error in file                                                     GETM061
900   CONTINUE                                                          GETM062
      PRINT*, ' *** ERROR reading NMR file while looking for MODEL',    GETM063
     &    ' record'                                                     GETM064
      IF (IMODEL.EQ.0) THEN                                             GETM065
          PRINT*, ' *** Error at line', LINE                            GETM066
      ELSE                                                              GETM067
          PRINT*, ' *** Error at line', LINE, '  after ENDMDL record',  GETM068
     &        ' for model', IMODEL                                      GETM069
      ENDIF                                                             GETM070
      GO TO 990                                                         GETM071
                                                                        GETM072
 902  CONTINUE                                                          GETM073
      PRINT*, ' *** Data error in MODEL number'                         GETM074
      IF (IMODEL.EQ.0) THEN                                             GETM075
          PRINT*, ' *** Error at line', LINE                            GETM076
      ELSE                                                              GETM077
          PRINT*, ' *** Error at line', LINE, '  after ENDMDL record',  GETM078
     &        ' for model', IMODEL                                      GETM079
      ENDIF                                                             GETM080
      GO TO 990                                                         GETM081
                                                                        GETM082
 904  CONTINUE                                                          GETM083
      PRINT*, ' *** Maximum number of models exceeded'                  GETM084
      PRINT*, ' *** Model found:', IMODEL, '     Maxmimum allowed:',    GETM085
     &    MXMODL                                                        GETM086
      GO TO 990                                                         GETM087
                                                                        GETM088
                                                                        GETM089
 990  CONTINUE                                                          GETM090
      IERROR = .TRUE.                                                   GETM091
                                                                        GETM092
999   CONTINUE                                                          GETM093
      RETURN                                                            GETM094
      END                                                               GETM095
