Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help updating a program from f77 to f95

Status
Not open for further replies.

doggod22

Technical User
Jun 16, 2010
4
US
We recently changed servers and I have this program I need to get to work on the new server.
Under the old server it never had a problem.
On this server it gives no errors when compiling but when I attempt to run the output file it keeps giving a Segmentation fault (core dumped) error message
I've tried changing just about everything I can think of but keep getting the same result.


program gaussian
implicit none
! This program will calculate pollutant concentration profile
! in x direction based on down wind distance from the source

Real q, u, s, t, h, i, j, k, l, o
Character p, a, b, c, d, e, f
Double precision w
Real g(21,21,7)
Integer n, m, x, y, z
integer ix, iy, iz
real dx, dy, dz
real pi

! The variables used are as follows:
! q=Emission Rate (g/s) ,u= wind velocity, s=sigma y (m),
! t=sigma z calculation (m), i=Ry, j=ry k=Rz, l=rz coefficient
! w=concentration (g/m^3), o= placeholder variable in w calc
! (a-f) = stability estimate p=placeholder (ph) coefficient
! n= ph for intensity of solar radiation, m= ph for day/night
! x= dist in plume direction (m), y= horiz dist off plume axis (m)
! z=height (m), h= emission height (m)

u = 2
q = 200000
pi=3.14
h=10
l=.273
i=.594
j=.262
k=.500

dx = 25
dy = 1
dz = 1

Write(3,*), ' Xdist Ydist Zdist Pollutant Conc '
do 5000 ix = 1, 2000

x = ix*dx
y = 0
z = 0

s=l*(x**i)
t=j*(x**k)


o=exp(-((z-h)**2)/(2*(t**2)))+exp(-((z+h)**2)/(2*(t**2)))
w=q/(2*pi*u*s*t)*exp(-(y**2)/(2*(s**2)))*o
Write(3,*), ' ',x,' ',y, ' ',z, ' ', w
Write(3,*), '*', s, ' ', t, '*'

g(ix,iy,iz)=w
Write(4,*), 'The array value is ...', g(ix,iy,iz)
Print*, g(ix,iy,iz), x,y, z

5000 CONTINUE
END



 
IMO the segmentation fault error is caused by incorrect handling of array g

Look, you have declared this array
Code:
Real g([highlight]21[/highlight],21,7)
that is g should have the size of 21x21x7, but you try to compute the 1.dimension until 2000 here in the loop
Code:
do 5000 ix = 1, [highlight]2000[/highlight]
   ...
   o=exp(-((z-h)**2)/(2*(t**2)))+exp(-((z+h)**2)/(2*(t**2)))
   w=q/(2*pi*u*s*t)*exp(-(y**2)/(2*(s**2)))*o
   ...
   g(ix,iy,iz)=w
   ...
5000 CONTINUE
and you never set other dimensions i.e. the variables iy and iz are never set in the code you posted above.
 
When I try to compile it it gives me these warnings
Code:
$ gfortran doggod22.f95 -o doggod22 -W
doggod22.f95: In function 'gaussian':
doggod22.f95:53:0: warning: 'iz' may be used uninitialized in this function [-Wm
aybe-uninitialized]
 g(ix,iy,iz)=w
 ^
doggod22.f95:53:0: warning: 'iy' may be used uninitialized in this function [-Wm
aybe-uninitialized]
and when I try to run it I get this error
Code:
$ doggod22

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  6f610f4e
#1  6f6913eb
#2  004010f8
 
Your previous compiler probably inicialized the variables iy and iz implicitly.
Now I tried to do that before the DO-loop
Code:
[highlight]
iy = 0
iz = 0[/highlight]
do 5000 ix = 1, 2000
...
and the program runs giving me this output on the screen
Code:
$ doggod22
   3.09397240E+33          25           0           0
   2.90514459E-03          50           0           0
  0.239577621              75           0           0
   1.98254716             100           0           0
   6.66623592             125           0           0
   14.4225092             150           0           0
   24.3823528             175           0           0
   35.4477119             200           0           0
   46.7057991             225           0           0
....
and producing 2 output files
Code:
  Xdist Ydist Zdist Pollutant Conc 
            25             0             0     2.9223233524615912E-009
 *   1.84730661         1.30999994     *
            50             0             0     2.9051446733346920E-003
 *   2.78837252         1.85261977     *
...
and
Code:
The array value is ...   3.09397240E+33
The array value is ...   2.90514459E-03
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top