Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need help updating a program from f77 to f95

Need help updating a program from f77 to f95

Need help updating a program from f77 to f95

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

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


Write(3,*), ' ',x,' ',y, ' ',z, ' ', w
Write(3,*), '*', s, ' ', t, '*'

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


RE: Need help updating a program from f77 to f95

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

Look, you have declared this array


Real g(21,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


do 5000 ix = 1, 2000
and you never set other dimensions i.e. the variables iy and iz are never set in the code you posted above.

RE: Need help updating a program from f77 to f95

When I try to compile it it gives me these warnings


$ 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
doggod22.f95:53:0: warning: 'iy' may be used uninitialized in this function [-Wm
and when I try to run it I get this error


$ doggod22

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

Backtrace for this error:
#0  6f610f4e
#1  6f6913eb
#2  004010f8 

RE: Need help updating a program from f77 to f95

Your previous compiler probably inicialized the variables iy and iz implicitly.
Now I tried to do that before the DO-loop


iy = 0
iz = 0
do 5000 ix = 1, 2000
and the program runs giving me this output on the screen


$ 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


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     *


The array value is ...   3.09397240E+33
The array value is ...   2.90514459E-03

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close