This function is a CHARACTER intrinsic function.
This function searches a CHARACTER variable to see if it contains any one of a list of characters that you provide to the function. It will then return an INTEGER value giving the location of the leftmost or the rightmost of those characters, depending on the use of the "BACK=" optional argument.
scan ( string, set )
String can either be a character variable or a string of characters that you want to check for certain characters that are specified in the character variable or constant, set.
scan ( string, set, back )
The back specifier will be either a LOGICAL variable or constant ( value of .true. or .false.). The value .false. makes the function return the location of the leftmost character from set that appears in string ( this is also the default manner in which scan operates if the back attribute is omitted ). If .true. is specified instead, the function will return the rightmost location of a character in set that appears in string.
Depending on what is specified, this function can return various results. To illustrate this, various calls will be made to the scan function using the following character variable.
Word1 = 'greenhouse'
Now, suppose the following four references are made to the scan function:
1) i = scan(word1,'e') 2) j = scan(word1,'e',back = .false.) 3) k = scan(word1,'enh',back =.true.) 4) l = scan(word1,'abc')
The results of the first and second search are the same. Both i and j will contain the value of three. The reason for this is that the default mode ( when "back =" is not included ) and "back =.false." are the same. The result of these two searches will always be the position of the leftmost character specified in set that appears in string.
What the compiler returns in the third search is ten. With the "back = .true." specifier, the compiler will return the rightmost location of all the variables that are contained in the search set. Therefore, since the last appearance of either e, n or h is at the end of word1, then that position is what in returned.
Finally, the last search will return a value of zero. Since none of the characters specified in the search set are contained in word1, the function returns the location of zero. Also, a location of zero can be returned if either the length of string or set is zero.
Lecture twenty five
Written by Jason Wehr : firstname.lastname@example.org and Maintained by John Mahaffy : email@example.com