009. Fortran array sections contain both endpoints#
topic: Arrays
Fortran array sections contain both endpoints like Julia, Matlab and R, unlike Python.
integer, parameter :: v(3) = [10, 20, 30]
print *, v(1:2) ! output: 10 20
print *, v(:2) ! 10 20
print *, v(2:3) ! 20 30
print *, v(2:) ! 20 30
print *, v(::2) ! 10 30 -- stride of 2
end
10 20
10 20
20 30
20 30
10 30
Fortran array sections contain both endpoints like Julia, Matlab and R, unlike Python.
— FortranTip (@fortrantip) December 18, 2021
integer, parameter :: v(3) = [10,20,30]
print*,v(1:2) ! output 10 20
print*,v(:2) ! 10 20
print*,v(2:3) ! 20 30
print*,v(2:) ! 20 30
print*,v(::2) ! 10 30 -- stride of 2
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags