Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Compiling multiple files of fortran 77 code

628 views
Skip to first unread message

wayn...@carolina.rr.com

unread,
Apr 25, 2009, 10:43:37 AM4/25/09
to
I am trying to compile some fortran 77 code which consists of two
files, one is the main program and the other contains several
subroutines. Following the instructions on the gfortran getting
started page I compiled the file containing the subroutines first:

gfortran -c sub144.f

and then linked them together for the final executable

gfortran pcayer.f sub144.o -o pcayer.exe

The resulting executable launches and reads an input file correctly,
but it does not finish executing the problem (heat transfer problem).
The problem should be solved within seconds, but the program just
keeps running without yielding any results. I tried to specify that
it was fortran 77 code using the -std=f77, but the compiler would not
accept it as a command line argument.

Any comments or suggestions would be appreciated.

Richard Maine

unread,
Apr 25, 2009, 11:49:40 AM4/25/09
to
<wayn...@carolina.rr.com> wrote:

> Any comments or suggestions would be appreciated.

My comment is that this is one of the most severe cases I've seen of the
number one error made when asking for help with a program.

When you ask for help, it is by definition because you don't understand
something. Therefore, you need to show us the actual data instead of
just what you think is relevant. Odds are high that you are looking in
the wrong place, which is why you need help.

In this case, you seem focussed entirely on what command lines are used
to build the program. Insomuch as you say that an executable program was
apparently built, runs and reads its input file correctly, and since the
command lines you showed seem plausible, I'd say that the odds of the
problem being anything even close to that are approximately zero.

I see zero data on which to base a diagnosis.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain

e p chandler

unread,
Apr 25, 2009, 12:30:51 PM4/25/09
to

Check for these:

1. mismatch of arguments between main routine and subroutines. Putting
all source code in one file and compiling it MAY help.
2. trying to access an array element beyond its boundaries. compile
with -fbounds-check and run.
3. mis-typing of a variable name. add IMPLICIT NONE at the top and
write out declarations for ALL of your variables. Otherwise you might
assign a value to an un-used variable.
4. un-initialized variables. Standard Fortran does NOT set all
variables to zero when the program starts.

Other than those you could have made ANY possible programming or logic
or algorithmic error.

It often helps to

1. add WRITE (or PRINT) statements to your code so you can see more
exactly WHEN it fails. For example, if you have an interation counter,
print it.

2. remove or comment out parts of the program until the bug goes away.
Using the divide and conquer approach you can often narrow down a
large program to a much smaller program that exhibits the bug.

3. Print out a program listing and "bench check" it. Go over the
listing and follow the program flow.

4. Explain how the program works to someone else as though that person
knows nothing about your problem or programming. Often by walking
through the problem you will discover the problem for yourself.

5. Once you have narrowed down the problem, post the code here. Try to
post the MINIMAL program that shows the bug.

6. The only possible relevance of using the command line as you did is
that by separating files you MIGHT have hidden a programming error
that MAY appear when the source files are combined.

7. An even better way to check for main program / sub-program
mismatches is to put subprograms in MODULES. This is a Fortran 90+
construct which is now available to you as you are using gfortran.

HTH

--- e

kar...@comcast.net

unread,
Apr 25, 2009, 4:14:15 PM4/25/09
to

Richard's advise is always good to follow. Of course, my advise
of heedings Richard's advise might be considered controversial
by some.

Anyhow. You're using gfortran, which has large set of useful
options. Try compiling with '-Wall -fbounds-check -ffpe-trap=invalid'
There are other options, but you fix any problems found with these
options, you'll be a step closer to having something that runs.

Because the code is purported to be F77, try pass the code through
FTNCHEK. Fix any problems found.

--
steve

Ian Bush

unread,
Apr 26, 2009, 3:45:10 AM4/26/09
to
On Apr 25, 3:43 pm, wayneb...@carolina.rr.com wrote:
> I am trying to compile some fortran 77 code which consists of two
> files, one is the main program and the other contains several
> subroutines.  

Just to address a couple of things which may or may not be concerning
you ...

1) That gfortran is a f95 compiler and you ( think you ) have f77 code
is not an issue. f95 is a superset of f77, so any conforming f77
program is also a conforming f95 program ( there are a few, uncommon,
exceptions, but this does not sound like one of those )

2) Just because the code worked elsewhere, even with gfortran, does
not necessarily mean it is free of bugs. In fact a good way of looking
for bugs is compiling and running using as many different compiler/
architecture combinations as possible. You may be surprised about how
much you can get away with under certain circumstances,

Ian

robin

unread,
Apr 26, 2009, 8:20:34 PM4/26/09
to
"Ian Bush" <ianbush.thro...@googlemail.com> wrote in message
news:638366d9-6822-46e7...@x29g2000prf.googlegroups.com...
+On Apr 25, 3:43 pm, wayneb...@carolina.rr.com wrote:
+> I am trying to compile some fortran 77 code which consists of two
+> files, one is the main program and the other contains several
+> subroutines.

+Just to address a couple of things which may or may not be concerning
+you ...

+1) That gfortran is a f95 compiler and you ( think you ) have f77 code
+is not an issue. f95 is a superset of f77, so any conforming f77
+program is also a conforming f95 program ( there are a few, uncommon,
+exceptions, but this does not sound like one of those )

+2) Just because the code worked elsewhere, even with gfortran, does
+not necessarily mean it is free of bugs. In fact a good way of looking
+for bugs is compiling and running using as many different compiler/
+architecture combinations as possible. You may be surprised about how
+much you can get away with under certain circumstances,

An even better way is to turn on all the checking.


0 new messages