program VectorExamples ! This file: ! http://ftp.aset.psu.edu/pub/ger/fortran/hdk/VectorSubscripts.f90 ! ! Vector-valued subscript example 1. ! by Arjen Markus ! as posted at comp.lang.fortran. implicit none integer, parameter :: n1 = 20 integer, parameter :: n2 = 20 integer, dimension(1:n1,1:n2) :: new_excitation integer :: i1, i2, i integer, dimension(1:3) :: iv1, iv2, a,b,c ! ! Testing the meaning of vector-valued subscripts for ! two-dimensional arrays ... ! iv1 = (/ 1, 2, 3 /) iv2 = (/ 1, 2, 3 /) new_excitation = -1 do i2 = 1,3 do i1 = 1,3 new_excitation(i1,i2) = i1 * 10 + i2 ! Michael Metcalf's note: new_excitation(::2, ::2), for example, is ! also valid. That is,strides of 2 and 2 yield the 100 elements: ! (1,1),(1,3), ... (1,n1-1), (3,1),(3,3), ... (3,n1-1), ... ! (n2-1,1) (n2-1,3) ... (n2-1,n1-1). ! enddo enddo print *, new_excitation(::2,::2) print *, new_excitation(iv1,iv2) ! Vector Subscript Example 2 ! by Christoph Arns and Aidan Heerdegen ! as posted at comp.lang.fortran. a = (/ 1, 2, 3 /) b = (/ 1, 2, 3 /) if (all(a==b)) print *,"a and b are the same!" print *, "a=",a do i=1,3 c(i)=10*i b(i)=i end do print *, "Vector c(b)=",c(b) ! Output: ! ! 11 31 -1 -1 -1 -1 ! -1 13 33 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 -1 -1 -1 -1 -1 ! -1 ! 11 21 31 12 22 32 !a and b are the same! !a= 1 2 3 !Vector c(b)= 10 20 30 end program VectorExamples