Can't get Fortran code to give me desired output file

mercredi 31 juillet 2013

Hey everyone,



I have written a Fortran code for a project I am working on, but am having an issue: I can't get the code to output my data to the file I have opened. Here is what I am trying to do.



I am setting up a Monte-Carlo code that selects a random x- and y-value. These values are then used to calculate the value of a Gaussian distribution (gauu_dist) at that point. Then another random value (z) is found, and compared as 0 is greater than or equal to z, and z is less than equal to gauss_dist at that point. If so, then the x- and y- values are to be written to my file jet_dist.dat (I do not care what z is after this, nor do I care what the gauss_dist value is anymore. ) For some reason I cannot get the resulting data to be put into my .dat file. If I ask the code to wirte my x- and y-values as soon as they are found, and comment out the lines of my if/then statement and my gauss_dist line, I can get the code to write my x- and y-values. I really can't figure out what I am missing!



Hopefully this is clear enough for someone to assist me. The following is my code, if you need further clarification, please let me know. Oh, and I am compiling using gfortran on an Ubuntu (most recent distro) platform.









program jetdist



implicit none



integer N, i

real x, y, z, gauss_dist, a, a2, z_min, e

real x_acc, y_acc, z_max



real, dimension(1100, 1100, 1100, 1100) :: jet_dist



open(unit=3, file="jet_dist.dat", status="unknown")



N = 1000

a = 3

a2 = a*a

e = 2.718

! need to insert print/write command so that N/-values can be changed for different runs of code

a2 = a*a



x_acc = 0



y_acc = 0



z_min = 0



z_max = 1.25



do i = 1, N



x = (rand()-0.5) * 26



y = (rand()-0.5) * 26



z = (rand())



gauss_dist = e**(-(x*x + y*y)/a2)



if (z_min .ge. z .and. z .le. gauss_dist) then



write(3,*) x, y



end if



end do



close(3)



return



stop



end






via Physics Forums RSS Feed http://www.physicsforums.com/showthread.php?t=703758&goto=newpost

0 commentaires:

Enregistrer un commentaire