C INDEX.FTN ACR/SCF:89.1 [223,1] 11/70 IAS C C 31-JUL-78 H.S.MILLER C C== C FUNCTION RETURN CHARACTER POSITION OF FIRST CHARACTER C IN STRING THAT MATCHES GIVEN SUBSTRING C== C C++ C INDEX FUNCTION C C THE ROUTINE IS USEFUL TO FIND THE OCCURRENCE (ACTUALLY THE C FIRST OCCURRENCE) OF A GIVEN SUBSTRING OF A KNOWN LENGTH C WITHIN A STRING BETWEEN GIVEN SUBSCRIPT POSITIONS C C CALLING FORMAT IS: K=INDEX (ARRAY,FIRST,LAST,STRING,LENGTH) C C K (THE RETURNED VALUE) IS 0 IF NO MATCH IS FOUND C IS THE ACTUAL SUBSCRIPT IF NO ERRORS C IS -1 IF A SUBSCRIPTING ERROR OCCURS C (CALLED WITH LAST < FIRST) C NOTE: THE LENGTH OF THE SUBSTRING MAY BE 1 C C INTEGER FUNCTION INDEX (ARRAY,FIRST,LAST,STRING,IMAX) C C--- ENTRY POINT "INDEX" PROVIDED FOR EASY CALLS C ENTRY TJU63 (ARRAY,FIRST,LAST,STRING,IMAX) BYTE ARRAY(1),STRING(1),SUB(100) INTEGER HERE, FIRST,TJU63 CALL MOVE (STRING,1,IMAX,SUB,1) C C---- COMPUTE THE LENGTH OF ARRAY OF INTEREST TO DETERMINE ERROR C ITER=LAST-FIRST+1 IF (ITER.LT. 1 .OR. ITER .LT. IMAX) GO TO 6 C C---- START FROM LEFT USING A CHAR-BY-CHAR SCAN WHERE: C C MATCH IS THE POSSIBLE INDEX VALUE C NOW IS THE CURRENT POSITION IN THE ARRAY C HERE IS THE CURRENT POSITION IN THE STRING NOW=FIRST-1 1 MATCH=NOW+1 2 NOW=NOW+1 HERE=1 3 IF (NOW .GT. LAST) GO TO 5 IF (ARRAY(NOW) .NE. SUB(HERE)) GO TO 1 HERE = HERE + 1 IF (HERE .GT. IMAX) GO TO 4 NOW = NOW + 1 GO TO 3 C C---- SUCCESS STRING BEGINS AT MATCH... C 4 INDEX=MATCH TJU63=MATCH RETURN C C---- NO MATCH WITHIN GIVEN ARRAY BOUNDS C 5 INDEX=0 TJU63=0 RETURN C C---- SUBSCRIPTING ERROR (LENGTH OF ARRAY OR STRING) C 6 INDEX=-1 TJU63=-1 RETURN END