Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | lstring | |||
character(len=*), | intent(in) | :: | lset |
integer function set_query(lstring,lset) !--------------------------------------------------------------------------- ! Scans a string for any character from a SET of characters. Returns zero ! if none of the elements of the set occur in the string or if the set or ! string is empty. !--------------------------------------------------------------------------- ! arguments character(len=*), intent(in) :: lstring character(len=*), intent(in) :: lset ! local variables integer :: k, klast, ncount integer :: len_string, len_set ! initialize variables ncount = 0 klast = 0 len_string = len(lstring) len_set = len( trim(adjustL(lset) )) !--------------------------------------------------------------------------- ! error check - conduct the scan only if the set and string are not empty !--------------------------------------------------------------------------- if( (len_set > 0) .and. (len_string > 0) ) then !------------------------------------------------------------------------ ! examine the string to find the find the FIRST instance of an ! element in the set. !------------------------------------------------------------------------ k = scan(lstring(klast+1:len_string), trim(adjustL(lset) )) do while( k > 0 ) !--------------------------------------------------------------------- ! if scan is nonzero, there is at least one match, increment ! through the string checking for additional matches. !--------------------------------------------------------------------- ncount = ncount + 1 ! count match klast = k + klast ! slide forward in string looking for next match k = scan(lstring(klast+1:len_string), trim(adjustL(lset) )) enddo ! while endif set_query = ncount !--------------------------------------------------------------------------- end function set_query