      PROGRAM CALTEST
      CHARACTER*20 FILENAME
      INTEGER*4 LEN1, LEN2, LENGTH
      EXTERNAL LEN1

    1 WRITE(6,*) ' ENTER FILENAME:  '
      READ(5,*) FILENAME
      LENGTH=LEN1(FILENAME)
      LEN2=LENGTH-2
      WRITE(6,'(A,I2)') ' LENGTH = ',LEN2
      WRITE(6,'(A,A)') 
     1    ' LAST THREE LETTERS ARE: ',FILENAME(LEN2:LENGTH)
      IF(FILENAME(LEN2:LENGTH).EQ.'CAL' .OR. FILENAME(LEN2:LENGTH).EQ.'CAL') THEN
          WRITE(6,*) ' LAST THREE LETTERS ARE ''CAL''. '
      ELSE
          WRITE(6,'(1X,A)') FILENAME
      END IF
      GO TO 1
      STOP
      END
