      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
c         path                                                          GETN035
          ELSE IF (ISTATE.EQ.2) THEN                                    GETN036
                                                                        GETN037
C----         If character is a dot, and is the first dot, then note    GETN038
c             position                                                  GETN039
              IF (PCHAR.EQ.'.' .AND. .NOT.GOTDOT) THEN                  GETN040
                  IEND = IPOS - 1                                       GETN041
                  GOTDOT = .TRUE.                                       GETN042
                                                                        GETN043
C----         If character signifies the end of a directory path, note  GETN044
c             position                                                  GETN045
              ELSE IF (PCHAR.EQ.'/' .OR. PCHAR.EQ.'$$'                  GETN046
     &            .OR. PCHAR.EQ.']') THEN                               GETN047
                  ISTART = IPOS + 1                                     GETN048
                  FINISH = .TRUE.                                       GETN049
              ENDIF                                                     GETN050
          ENDIF                                                         GETN051
                                                                        GETN052
C----     Step back a character                                         GETN053
          IPOS = IPOS - 1                                               GETN054
                                                                        GETN055
C---- Loop back for next character                                      GETN056
      IF (.NOT.FINISH .AND. IPOS.GT.0) GO TO 100                        GETN057
                                                                        GETN058
C---- Check whether file name is sensible                               GETN059
      IF (ISTART.GT.IEND) GO TO 900                                     GETN060
                                                                        GETN061
      GO TO 999                                                         GETN062
                                                                        GETN063
C---- Error in file name                                                GETN064
900   CONTINUE                                                          GETN065
      IEND = 40                                                         GETN066
      IF (PDBFIL(41:78).NE.' ') IEND = 78                               GETN067
      PRINT*,' *** ERROR in supplied name of file: [', PDBFIL(1:IEND),  GETN068
     &    ']'                                                           GETN069
      IERROR = .TRUE.                                                   GETN070
                                                                        GETN071
999   CONTINUE                                                          GETN072
      RETURN                                                            GETN073
      END                                                               GETN074
