C
C SUBROUTINE 'FILEXT'
C ===================
C
C ADD A FILE EXTENSION TO A FILE NAME IF IT DOES NOT ALREADY HAVE ONE
C
      SUBROUTINE FILEXT (FIN, EXT, FOUT, IEND)
C
C PARAMETERS
C
C         FIN (I)   INPUT FILE NAME (WITH OR WITHOUT EXTENSION)
C         EXT (I)   EXTENSION TO BE ADDED TO THE FILE NAME IF NONE
C                   WAS PRESENT (THIS MUST NOT INCLUDE THE LEADING
C                   DOT WHICH WILL BE SUPPLIED BY THE ROUTINE AND
C                   MUST NOT HAVE ANY LEADING SPACES - TRAILING
C                   SPACES ARE OK)
C        FOUT (O)   THE RETURNED FILE NAME WITH EXTENSION
C        IEND (O)   POSITION OF LAST CHARACTER BEFORE THE EXTENSION IN
C                   THE RETURNED FILE NAME
C
C====== Specification statements
C
      CHARACTER*(*) FIN, EXT, FOUT
C
C====== See if extension present
C
      L = LEN(FIN)
      DO 100 I = L,1,-1
         IF (FIN(I:I).EQ.'.') GO TO 120
         IF (FIN(I:I).EQ.'/'.OR.FIN(I:I).EQ.']') GO TO 120
100   CONTINUE
      I = 1
120   IF (FIN(I:I).EQ.'.') THEN
         FOUT = FIN
         IEND = I-1
         RETURN
      END IF
C
C====== No extension present, add extension
C
      DO 200 I = L,1,-1
         IF (FIN(I:I).NE.' ') GO TO 220
200   CONTINUE
      I = 0
220   IEND = I
      FOUT = FIN(1:IEND)//'.'//EXT
      RETURN
      END
