index, rindex, lnblnk, len - get index or length of substring
CHARACTER*(*) string, substr n = INDEX (string, substr)
INTEGER*4 FUNCTION rindex CHARACTER*(*) string, substr n = rindex (string, substr)
INTEGER*4 FUNCTION lnblnk CHARACTER*(*) string n = lnblnk (string)
CHARACTER*(*) string n = LEN (string)
INDEX(a1,a2) returns the index of the first occurrence of string a2 in string a1, or zero if it does not occur (intrinsic function).
rindex(a1,a2) returns the index of the last occurrence of string a2 in string a1, or zero if it does not occur.
lnblnk( a1 ) returns the index of the last non-blank character in a1. This function is useful since all f77 character objects are of fixed length and blank-padded.
LEN returns the declared size of the character string argument (intrinsic function).
When compiling for 64-bit environments (with compiler option -m64 routines len, index, rindex, and lnblnk could return values greater than the data range of INTEGER*4 data when applied to very large character strings (greater than 2 Gbytes). In this situation, these functions must be declared INTEGER*8, as well as the variables receiving their results.
Example: LEN(), INDEX(), rindex() , lnblnk()(): CHARACTER s*32 / '123456789 123456789 1234' / INTEGER*4 declen, first, last, lnblnk, rindex declen = LEN( s ) first = INDEX( s, '123' ) last = rindex( s, '123' ) lastnb = lnblnk( s ) PRINT*, declen, lastnb, first, last END demo% f77 -silent tindex.f demo% a.out 32 24 1 21 demo%
In the above example, declen is 32, not 24. This is the declared length of the character variable, not the length of the string it contains.
libfsu.a