Re: Common variable....help me
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Fri, 30 Dec 2005 21:38:50 -0800
<kithsiri@xxxxxxxxx> wrote:
> All my variables and arrays are "double precision" type.
Actually, no they aren't. :-( See below.
> All common
> variables are specified in the header file "common.fi" .
Since you are using f90 anyway, I recommend learning to use modules for
sharing data instead of using COMMON. Common is a bit of a relic. It is
still very widely used in old codes, but it has many quirks and is
notably error prone. You have run into one of the many typical errors.
(And no, it has nothing to do with SAVE. Although the standard sometimes
requires you to use it, there are no current compilers for which save
for commons actually makes any difference - for local variables, yes,
but not for common. Furthermore, your code has the common in the main
program, which makes save irrelevant anyway.)
> Program Main
>
> USE DFLIB
>
> include 'Common.fi'
>
> double precision rho_oil, miu
If you are going to use common, it is good to have the common statement
in an include file (as you have done) so that all procedures get the
exact same common statements. But it is also equally important to put
all the declarations for the variables in the common in that same
include file. Otherwise, the declarations can end up different in
different copies, which is what happened to you.
You declared miu double precision in the main program, but not in the
subroutine. This causes no end of havoc, not only for miu, but for
everything else after it in the common (because miu ends up being a
different size, which throws off the whole rest of the common).
Move that miu declaration inside of the include file (and likewise for
the rest of the declarations of the things in common).
I also recommend using "implicit none", which would have caught this
error, because it would have made teh compiler flag the fact that miu
(and others) were not explicitly declared with a type in the subroutine.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- References:
- Common variable....help me
- From: kithsiri
- Common variable....help me
- Prev by Date: Re: Common variable....help me
- Next by Date: Re: Common variable....help me
- Previous by thread: Re: Common variable....help me
- Next by thread: Re: Common variable....help me
- Index(es):
Relevant Pages
|