soccer jersey forums.silverfrost.com :: View topic - Fortran equivalent to linspace
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fortran equivalent to linspace

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
arctica



Joined: 10 Sep 2006
Posts: 105
Location: United Kingdom

PostPosted: Fri Dec 22, 2023 9:28 am    Post subject: Fortran equivalent to linspace Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group