I'm new to Fortran and I already have a hard time understanding the concept of broadcasting of arrays in Python, so it is even more difficult for me to implement it in Fortran
Fortran code:
program test
implicit none
integer,parameter::N=6,t_size=500
real,dimension(t_size,N,2)::array1
contains
pure function f(a) result(dr)
real::dr(N,N,2)
real,intent(in)::a(N,2)
real::b(N,N,2)
real::c(N,N,2)
b=spread(a,1,N)
c=spread(a,2,N)
dr=c-b
end function f
end program
Now N would be the number of points and t_size is just the number of different time steps. I came up with this function which uses spread in two different dimensions to create a NxNx2 array.
Now I thought of using a line like for example r=f(array1(1,:,:) in order to get an array which holds all differences of spatial coordinates of every 2 points.
I already wrote code that does this in Python (taken from a physics textbook for Python)
r = np.empty((t.size, N, 2))
r[0] = r0
def f(r):
dr=r.reshape(N,1,2)-r
where I can write later for example f(r[i]. (In this case, I left the line r[0] = r0, because it shows that an initial condition is given - later I plan to do this in Fortran by using the random_number subroutine.)
Now I hope it is clear what my question is. If anyone has a better idea (which I am sure there is) to implement broadcasting in Fortran, please let me know.
Please have a little patience with someone new to Fortran and also programming in general - thanks in advance for your replies.
I already tried it with the random_number subroutine and it worked, but I have no way of checking if the output is true.