- #1
- 2
- 0
Hello,
I am working on a Fortran 77 program for my computational physics course in which
the program is an averaging of distances walked by a number of walkers for an nth step.
I have started the calculations of the program by having an input seed generate a sequence
of pseudo-random numbers of j length. This will be the amount of walks performed.
This "do" loop has a nested "do" loop within it, which takes the jth generated number and
uses it as the seed for the walk code in the nested loop.
This all works fine, but I am stumped on how to produce a file which stores the position
calculated for each step of each walk. Since the walk function is just repeating itself over
each individual loop through the main "do" code, I can't seem to get the store file to
save all the walks.
I am still having trouble with the logic of then how I would take the squared value of the
nth step for each walker and average the row of walkers positions at each step.
Code for the subroutine Calculate:
This does not have any attempt at the averaging part in it.
I've tried x(v,n) but that isn't correct since x is not directly a function of v.
Any help or suggestions is greatly appreciated, I am still quite the novice at programming.
James
I am working on a Fortran 77 program for my computational physics course in which
the program is an averaging of distances walked by a number of walkers for an nth step.
I have started the calculations of the program by having an input seed generate a sequence
of pseudo-random numbers of j length. This will be the amount of walks performed.
This "do" loop has a nested "do" loop within it, which takes the jth generated number and
uses it as the seed for the walk code in the nested loop.
This all works fine, but I am stumped on how to produce a file which stores the position
calculated for each step of each walk. Since the walk function is just repeating itself over
each individual loop through the main "do" code, I can't seem to get the store file to
save all the walks.
I am still having trouble with the logic of then how I would take the squared value of the
nth step for each walker and average the row of walkers positions at each step.
Code for the subroutine Calculate:
This does not have any attempt at the averaging part in it.
Code:
subroutine calculate(a,b,m,n,ran,d,r_ran,x,f,v)
integer a,b,m,n,d(n),x(n),v
real ran(n),r_ran(n),f(v)
do j=1,v
d(j)=(f(j)*a0+b0)/m0 }Basic arithmetic for the
f(j+1)=(f(j)*a0+b0)-d(j)*m0 }eq: (a*([seed #])+b)/Mod(m)
c }Gives the remainder for each calculation
do i=1,n
d(i)=(f(j)*a+b)/m
ran(i)=(f(j)*a+b)-d(i)*m
ran(i+1)=(ran(i)*a+b)-d(i)*m
r_ran(i)=(ran(i))/m
c
if (r_ran(i) .le. 0.5) then }Normalization of random number
x(i+1) = x(i)-1 }to set (0,1), which then determines
else }if walkers moves forward or back
x(i+1) = x(i)+1
end if
end do
end do
return
end
The store code for a data file is probably where I am messing up:
subroutine store(x,n,v)
integer n,v,x(n)
open(1,file='numbers.dat')
do j=1,v
do i=1,n
write(1,*) x(i)
end do
end do
close (1)
return
end
I've tried x(v,n) but that isn't correct since x is not directly a function of v.
Any help or suggestions is greatly appreciated, I am still quite the novice at programming.
James
Last edited: