Fortran Array arrangement in Fortran 77

  • Thread starter Thread starter jic1892
  • Start date Start date
  • Tags Tags
    Array Fortran
AI Thread Summary
The discussion revolves around a Fortran 77 program designed for a computational physics course, focusing on averaging distances walked by multiple walkers. The user has successfully implemented a pseudo-random number generator to facilitate the walks but is struggling with two main issues: saving the positions of each walker at every step to a file and calculating the average squared position for each walker.The code includes a subroutine for the calculations, which generates random numbers and determines walker movement based on these values. However, the user encounters difficulties in the subroutine meant for storing walker positions in a data file, as the current implementation does not correctly associate the walker data with the number of walks performed.Suggestions from the community emphasize the need to correctly structure the data storage to capture all walker positions and to ensure that the averaging logic is implemented effectively. The user is encouraged to refine the file-writing process and clarify the relationship between the walker index and the steps taken.
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
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
3
Views
2K
Replies
20
Views
4K
Replies
4
Views
2K
Replies
12
Views
2K
Replies
8
Views
4K
Replies
12
Views
3K
Back
Top