      INTEGER FUNCTION MCSTR_LASTX(STR,SUBSTR)
C
C  SIMILAR TO FORTRAN INDEX(STR,SUBSTR) FCN BUT INSTEAD OF RETURNING
C  THE ADDRESS OF THE FIRST OCCURRENCE OF THE SUBSTR IN STR THIS
C  RETURNS THE ADDRESS OF THE *LAST* OCCURRENCE
C
      CHARACTER*(*) STR
      CHARACTER*(*) SUBSTR
C
      L=LEN(STR)
      LSUB=LEN(SUBSTR)
C
      ICHECK=L-LSUB+1
C
      IFND=0
      IF(ICHECK.LE.0) GO TO 100
C
C  MATCH TEST LOOP
C
      DO 10 I=ICHECK,1,-1
        I2=I+LSUB-1
        IF(STR(I:I2).EQ.SUBSTR) THEN
          IFND=I
          GO TO 100
        ENDIF
 10   CONTINUE
C
 100  CONTINUE
      MCSTR_LASTX=IFND
      RETURN
      END
