arctica
Joined: 10 Sep 2006 Posts: 105 Location: United Kingdom
|
Posted: Fri Dec 22, 2023 9:28 am Post subject: Fortran equivalent to linspace |
|
|
Hello
Is there an efficient method to generate linearly-spaced values, i.e. using start, end and number of required values? An example would be start=0, end=100, number of values=1000
This works but not very elegant:
Code: |
program main
implicit none
real,allocatable,dimension(:) :: vec
real :: a,inc
integer :: n ,i
a = 0. ! initial value
inc = 0.5 ! increment value
n = 100 ! number of values
allocate(vec(n))
vec = [(a + (i-1) * inc, i=1,n)] ! array constructor
write(*,'(11f7.2)') vec
end program main
|
A simple function like: linspace(start, end, number_of_values) would be great!
Lester |
|