      SUBROUTINE GETNAM(PDBFIL,ISTART,IEND,IERROR)                      GETN001
                                                                        GETN002
      CHARACTER*1   PCHAR                                               GETN003
      CHARACTER*78  PDBFIL                                              GETN004
      INTEGER       IEND, IPOS, ISTART, ISTATE                          GETN005
      LOGICAL       FINISH, GOTDOT, IERROR                              GETN006
                                                                        GETN007
C---- Initialise variables                                              GETN008
      FINISH = .FALSE.                                                  GETN009
      IEND = 0                                                          GETN010
      IERROR = .FALSE.                                                  GETN011
      ISTART = 1                                                        GETN012
      ISTATE = 1                                                        GETN013
      IPOS = 78                                                         GETN014
      GOTDOT = .FALSE.                                                  GETN015
                                                                        GETN016
C---- Check through the filename from right to left                     GETN017
100   CONTINUE                                                          GETN018
                                                                        GETN019
C----     Pick off next character                                       GETN020
          PCHAR = PDBFIL(IPOS:IPOS)                                     GETN021
                                                                        GETN022
C----     State 1: Searching for first non-blank character              GETN023
          IF (ISTATE.EQ.1) THEN                                         GETN024
              IF (PCHAR.EQ.'/' .OR. PCHAR.EQ.'$$' .OR.                  GETN025
     &            PCHAR.EQ.']') THEN                                    GETN026
                  GO TO 900                                             GETN027
              ENDIF                                                     GETN028
              IF (PCHAR.NE.' ' .AND. PCHAR.NE.'.') THEN                 GETN029
                  IEND = IPOS                                           GETN030
                  ISTATE = 2                                            GETN031
              ENDIF                                                     GETN032
                                                                        GETN033
C----     State 2: Searching for end of extension, or end of directory  GETN034
          ELSE IF (ISTATE.EQ.2) THEN                                    GETN035
                                                                        GETN036
C----         If character is a dot, and is the first dot, then note posGETN037
              IF (PCHAR.EQ.'.' .AND. .NOT.GOTDOT) THEN                  GETN038
                  IEND = IPOS - 1                                       GETN039
                  GOTDOT = .TRUE.                                       GETN040
                                                                        GETN041
C----         If character signifies the end of a directory path, note pGETN042
              ELSE IF (PCHAR.EQ.'/' .OR. PCHAR.EQ.'$$'                  GETN043
     &            .OR. PCHAR.EQ.']') THEN                               GETN044
                  ISTART = IPOS + 1                                     GETN045
                  FINISH = .TRUE.                                       GETN046
              ENDIF                                                     GETN047
          ENDIF                                                         GETN048
                                                                        GETN049
C----     Step back a character                                         GETN050
          IPOS = IPOS - 1                                               GETN051
                                                                        GETN052
C---- Loop back for next character                                      GETN053
      IF (.NOT.FINISH .AND. IPOS.GT.0) GO TO 100                        GETN054
                                                                        GETN055
C---- Check whether file name is sensible                               GETN056
      IF (ISTART.GT.IEND) GO TO 900                                     GETN057
                                                                        GETN058
      GO TO 999                                                         GETN059
                                                                        GETN060
C---- Error in file name                                                GETN061
900   CONTINUE                                                          GETN062
      IEND = 40                                                         GETN063
      IF (PDBFIL(41:78).NE.' ') IEND = 78                               GETN064
      PRINT*,' *** ERROR in supplied name of file: [', PDBFIL(1:IEND),  GETN065
     &    ']'                                                           GETN066
      IERROR = .TRUE.                                                   GETN067
                                                                        GETN068
999   CONTINUE                                                          GETN069
      RETURN                                                            GETN070
      END                                                               GETN071
