      INTEGER FUNCTION MCSTR_INDEX(STR,SUBSTR,N)
C
C  FIND THE NTH OCCURRENCE OF SUBSTR IN STR
C  RETURN ZERO IF NOT FOUND;
C  RETURN THE CHARACTER INDEX OF THE START OF NTH OCCURRENCE OF SUBSTR
C  IN STR IF FOUND
C
C  ALL OF SUBSTR IS USED I.E. TRAILING BLANKS COUNT
C
      CHARACTER*(*) STR
      CHARACTER*(*) SUBSTR
C
      LSTR=LEN(STR)
C
      IFIND=0
      ICT=N+1
C
C  LOOP -----
C
 10   CONTINUE
C
      ICT=ICT-1
      IF(ICT.LE.0) GO TO 100
C
      ISTART=IFIND+1
C
      IF(ISTART.GT.LSTR) THEN
        IFIND=0
        GO TO 100
      ELSE
C  NEXT OCCURRENCE
        IFIND=INDEX(STR(ISTART:LSTR),SUBSTR)
        IF(IFIND.EQ.0) GO TO 100
        IFIND=IFIND+ISTART
      ENDIF
      GO TO 10
C
C  EXIT -----
C
 100  CONTINUE
      MCSTR_INDEX=IFIND
      RETURN
      END
