Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Array arrangement in Fortran 77

  1. Nov 19, 2011 #1

    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 (Text):

          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
                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

    The store code for a data file is probably where I am messing up:

          subroutine store(x,n,v)
          integer n,v,x(n)
          do j=1,v
             do i=1,n
                write(1,*) x(i)
             end do
          end do
          close (1)
    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.

    Last edited: Nov 19, 2011
  2. jcsd
  3. Nov 19, 2011 #2


    User Avatar

    Staff: Mentor

    Tip: wrap your code in "code" tags to preserve the formatting. Click on the little icon with <> on it, above the text-entry field, or add them by hand, which is what I do. Hit the "Quote" button on this post to see what they look like:

    Code (Text):

        do k = 1, 10
            print *, 'Hello, world!'
        end do
  4. Nov 19, 2011 #3

    Thanks JtBell
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook