# Array arrangement in Fortran 77

• Fortran
• jic1892
In summary, the program calculates the distances walked by a number of walkers for an nth step. The program starts by generating a sequence of pseudo-random numbers of j length. 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. The walk function is just repeating itself over each individual loop through the main "do" code. However, I am stumped on how to produce a file which stores the position calculated for each step of each walk. 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 walk

#### jic1892

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.

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:
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:
    do k = 1, 10
print *, 'Hello, world!'
end do Thanks JtBell

## 1. How do I declare an array in Fortran 77?

To declare an array in Fortran 77, you can use the DIMENSION statement, followed by the array name and the desired dimensions. For example, DIMENSION A(10) would declare an array named A with 10 elements.

## 2. How do I initialize an array in Fortran 77?

To initialize an array in Fortran 77, you can use the DATA statement, followed by the array name and the values to be assigned to each element. For example, DATA A /1, 2, 3, 4, 5/ would initialize the elements of array A with the given values.

## 3. What is the difference between a one-dimensional and a multi-dimensional array in Fortran 77?

A one-dimensional array in Fortran 77 is a simple list of elements, while a multi-dimensional array has multiple dimensions and can be thought of as a table or grid. For example, a one-dimensional array can be used to store a list of numbers, while a two-dimensional array can be used to store a matrix.

## 4. How do I access elements of an array in Fortran 77?

To access elements of an array in Fortran 77, you can use the array name followed by the index of the element you want to access. For example, A(3) would access the third element of array A. Keep in mind that Fortran 77 uses column-major order, so the first index varies fastest.

## 5. Can I resize an array in Fortran 77?

No, arrays cannot be resized in Fortran 77. Once an array is declared, its size cannot be changed. If you need to change the size of an array, you will need to declare a new array with the desired dimensions and copy the elements from the old array into the new one.