Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

General array slice-question

canavanin
Beginner
706 Views

Is there a way of using array slices in Fortran that are not merely continuous segments of an array and that neither are made up of elements accessible by a constant stride value? (as an example, would it be possible to create an array slice comprising the array's elements 1, 3, 17, 18, 25?) If this cannot be accomplished using array slices, what would be the most elegant and/or efficient way of doing this?

Thanks a lot in advance :)

0 Kudos
2 Replies
mecej4
Honored Contributor III
706 Views

Does the following example address your question? Note the use of the integer array ix in the WRITE statement. The contents of the array can be any integers with acceptable values (less than 25)

 [fortran]

program idx
implicit none
integer, dimension(5) :: ix = [1, 3, 17, 18, 25]
integer, dimension(25) :: array
integer :: i

do i=1,25
   array(i)=i
end do

write(*,*)array(ix)
end program idx

[/fortran]

0 Kudos
canavanin
Beginner
706 Views

mecej4, thanks a lot for your reply, this is exactly what I've been looking for!

0 Kudos
Reply