pattern_query Function

public function pattern_query(lstring, lpattern)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: lstring
character(len=*), intent(in) :: lpattern

Return Value integer


Called by

proc~~pattern_query~~CalledByGraph proc~pattern_query pattern_query proc~construct_descriptor_string construct_descriptor_string proc~construct_descriptor_string->proc~pattern_query proc~create_distribution create_distribution proc~create_distribution->proc~pattern_query proc~dist_size dist_size proc~dist_size->proc~pattern_query proc~interpret_descriptor_string interpret_descriptor_string proc~interpret_descriptor_string->proc~pattern_query proc~memory_separate memory_separate proc~memory_separate->proc~pattern_query proc~parse_descriptor_string parse_descriptor_string proc~parse_descriptor_string->proc~pattern_query proc~parse_descriptor_string->proc~interpret_descriptor_string proc~parse_descriptor_string->proc~memory_separate proc~memory_topology memory_topology proc~parse_descriptor_string->proc~memory_topology proc~pattern_match pattern_match proc~pattern_match->proc~pattern_query proc~read_dist_specification read_dist_specification proc~read_dist_specification->proc~pattern_query proc~read_dist_specification->proc~dist_size proc~array_redist_test array_redist_test proc~array_redist_test->proc~create_distribution proc~field_redist_test field_redist_test proc~field_redist_test->proc~create_distribution proc~field_regrid_test field_regrid_test proc~field_regrid_test->proc~create_distribution proc~memory_topology->proc~pattern_match proc~read_testharness_specifier Read_TestHarness_Specifier proc~read_testharness_specifier->proc~construct_descriptor_string proc~read_testharness_specifier->proc~parse_descriptor_string proc~read_testharness_specifier->proc~read_dist_specification proc~runtests RunTests proc~runtests->proc~array_redist_test proc~runtests->proc~field_redist_test proc~runtests->proc~field_regrid_test program~esmf_test_harness esmf_test_harness program~esmf_test_harness->proc~read_testharness_specifier program~esmf_test_harness->proc~runtests

Source Code

    integer function pattern_query(lstring,lpattern)
    !---------------------------------------------------------------------------
    ! Searches a string for a PATTERN of characters. Returns zero if the pattern 
    ! is not found, or if the pattern or string is empty.
    !---------------------------------------------------------------------------

    ! arguments
    character(len=*), intent(in) :: lstring
    character(len=*), intent(in) :: lpattern

    ! local variables
    integer :: k, klast, ncount
    integer :: len_string, len_pattern

    ! initialize variables
    ncount = 0
    klast = 0
    len_string = len(lstring)
    len_pattern = len( trim(adjustL(lpattern)) )
    
    !---------------------------------------------------------------------------
    ! error check - conduct the search only if the pattern & string are not empty
    !---------------------------------------------------------------------------
    if( (len_pattern > 0) .and. (len_string > 0) ) then
       !------------------------------------------------------------------------
       ! examine the string to find the find the FIRST instance of the pattern 
       !------------------------------------------------------------------------
       k = index(lstring(klast+1:len_string), trim(adjustL(lpattern) ))
       do while( k > 0 )
          !---------------------------------------------------------------------
          ! if index 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 = index(lstring(klast+1:len_string), trim(adjustL(lpattern) ))
       enddo     ! while
    endif 
    
    pattern_query = ncount
    !---------------------------------------------------------------------------
    end function pattern_query