Array arrangement in Fortran 77

  • Context: Fortran 
  • Thread starter Thread starter jic1892
  • Start date Start date
  • Tags Tags
    Array Fortran
Click For Summary
SUMMARY

The forum discussion centers on implementing a Fortran 77 program for averaging distances walked by multiple walkers using pseudo-random number generation. The user, James, successfully generates random numbers but struggles with storing the calculated positions of each walker in a file. The provided subroutine for storing data, named store, fails to correctly save the walker positions due to improper indexing. The discussion highlights the need for a proper understanding of array indexing and file I/O in Fortran 77.

PREREQUISITES
  • Understanding of Fortran 77 syntax and structure
  • Knowledge of pseudo-random number generation techniques
  • Familiarity with file I/O operations in Fortran
  • Basic concepts of array indexing and manipulation
NEXT STEPS
  • Review Fortran 77 file I/O operations to correctly implement data storage
  • Learn about array indexing in Fortran to resolve indexing issues in the store subroutine
  • Explore techniques for averaging values in arrays in Fortran
  • Investigate debugging strategies for Fortran programs to identify logical errors
USEFUL FOR

This discussion is beneficial for computational physicists, Fortran developers, and students learning programming concepts in Fortran 77, particularly those working with random number generation and data storage techniques.

jic1892
Messages
2
Reaction score
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.

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:
Technology news on Phys.org
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
 
:cool:

Thanks JtBell
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
1
Views
2K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K