010. Fortran arrays can have any lower bound (the default is 1)#
topic: Arrays
Fortran arrays can have any lower bound. The default is 1. Array functions have optional mask arguments to determine the elements used.
integer :: v(-1:1) = [1, -2, 3]
print *, lbound(v), ubound(v), size(v) ! -1 1 3
print *, sum(v) ! 2
print *, sum(v,mask=v>0) ! 4 -- sum excludes -2
end
-1 1 3
2
4
Fortran arrays can have any lower bound.
— FortranTip (@fortrantip) December 18, 2021
The default is 1. Array functions have optional mask arguments to determine the elements used.
integer :: v(-1:1) = [1,-2,3]
print*,lbound(v),ubound(v),size(v) ! -1 1 3
print*,sum(v) ! 2
print*,sum(v,mask=v>0) ! 4 -- sum excludes -2
end
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags