General array slice-question

General array slice-question

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 :)

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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)

 

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

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today