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