pure subroutine generate_next_string(string, ras, ras_class, none_left)
type(ras_parameters), intent(in) :: ras
type(ras_class_data), intent(in) :: ras_class
integer, intent(inout) :: string(ras_class%nelec_1 + ras_class%nelec_2 + &
ras_class%nelec_3)
logical, intent(out) :: none_left
integer :: string_1(ras_class%nelec_1)
integer :: string_2(ras_class%nelec_2)
integer :: string_3(ras_class%nelec_3)
! The strings in the 3 RAS spaces, shifted so that the first orbital in each space would
! be labelled 1 (this is needed for the routine that generates all combinations).
string_1 = string(1:ras_class%nelec_1)
string_2 = string(ras_class%nelec_1 + 1:ras_class%nelec_1 + ras_class%nelec_2) - ras%size_1
string_3 = string(ras_class%nelec_1 + ras_class%nelec_2 + 1:tot_nelec) - &
(ras%size_1 + ras%size_2)
loop1: do ! Over RAS1.
loop2: do ! Over RAS2.
loop3: do ! Over RAS3.
call find_next_comb(string_3, ras_class%nelec_3, ras%size_3, none_left)
if (.not. none_left) exit loop1
! If we had the last string last time, go back to the first one.
call generate_first_subspace_string(string_3, ras_class%nelec_3)
exit loop3
end do loop3
call find_next_comb(string_2, ras_class%nelec_2, ras%size_2, none_left)
if (.not. none_left) exit loop1
call generate_first_subspace_string(string_2, ras_class%nelec_2)
exit loop2
end do loop2
call find_next_comb(string_1, ras_class%nelec_1, ras%size_1, none_left)
exit loop1
end do loop1
! If the last string in RAS1, RAS2 and RAS3 was found last time, then last_time will be
! equal to .true. at this point and this value will be returned, signalling the end.
string(1:ras_class%nelec_1) = string_1
string(ras_class%nelec_1 + 1:ras_class%nelec_1 + ras_class%nelec_2) = string_2 + ras%size_1
string(ras_class%nelec_1 + ras_class%nelec_2 + 1:tot_nelec) = string_3 + (ras%size_1 + ras%size_2)
end subroutine generate_next_string