Короткий ответ: "Нет", в Фортране нет такой внутренней функции.
Обычно ожидается, что вы сами напишете что-то подобное. Например:
- начать с массива всех возможных начальных индексов
- определить условие сохранения индексов
- последовательно сохраняйте только те индексы, которые удовлетворяют вашему условию
Встроенная процедура pack
здесь весьма полезна, ее можно использовать только для сохранения значений из массива ( ваши стартовые локации), которые соответствуют определенному условию (вашему условию сохранения стартовых локаций).
Программа "test.f90" (не проверенная!) ниже иллюстрирует использование:
module mod_finder
implicit none
contains
subroutine find_start_locs(array, sub_array, start_locs)
integer, intent(in) :: array(:)
integer, intent(in) :: sub_array(:)
integer, allocatable, intent(out) :: start_locs(:)
integer :: i
! initialize result with all possible starting indices
start_locs = [(i, i = 1, size(array)-size(sub_array)+1)]
! sequentially keep only those indices that satisfy a condition
do i = 1, size(sub_array)
! condition for keeping: the value of array(start_locs + i - 1) must be equal to the value of sub_array(i)
! use PACK to only keep start_locs that satisfy this condition
start_locs = PACK(start_locs, array(start_locs + i - 1) == sub_array(i))
if (size(start_locs) == 0) then
exit
end if
end do
end subroutine find_start_locs
end module mod_finder
program test
use mod_finder
implicit none
integer, allocatable :: arr(:)
integer, allocatable :: seq(:)
integer, allocatable :: res(:)
! arr = [1, 5, 8, 56, 33, 56, 78, 123, 78, 8, 34, 33, 19, 25, 36]
arr = [1, 5, 8, 56, 33, 56, 78, 123, 78, 8, 56, 33, 19, 25, 36]
seq = [8, 56, 33]
call find_start_locs(arr, seq, res)
print *, "array: ", arr
print *, "sequence: ", seq
print *, "locations: ", res
print *, "# matches: ", size(res)
end program test
Для двух тестовых случаев в вашем вопросе компиляция и запуск дают следующий результат:
$ gfortran -O2 -g -Wall -Wextra -fcheck=all test.f90
$ ./a.out
array: 1 5 8 56 33 56 78 123 78 8 34 33 19 25 36
sequence: 8 56 33
locations: 3
# matches: 1
а также
array: 1 5 8 56 33 56 78 123 78 8 56 33 19 25 36
sequence: 8 56 33
locations: 3 10
# matches: 2
person
jbdv
schedule
18.09.2019