Re: Common variable....help me



<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
.



Relevant Pages

  • Re: use module to pass data between procedures
    ... it is equally true of common that you can't declare the ... those declarations elsewhere in the same scope. ... All the attributes come from the module and the compiler ... will bitch if you try to redeclare them. ...
    (comp.lang.fortran)
  • Re: How to use H-files
    ... In time I created some common, so called, units. ... You put all the declarations from that ... your Turbo Pascal system did as well, but it did it for you, in the ... How you perform this step depends on which compiler system ...
    (comp.lang.c)
  • Re: Is "volatile sig_atomic_t" redundant?
    ... >Dave Vandervies wrote: ... >It's pretty common to see declarations such as: ... >> Have you ever written code that used a signal handler? ...
    (comp.lang.c)
  • Re: Terminology: Are There Messages in Java?
    ...   classes«), even though they share a common signature (aka ... I would say that the two declarations declare two different ... *implementations* of the same interface method 'I#f'. ... The common base type is 'I'. ...
    (comp.lang.java.programmer)
  • Re: Bundling multiple objects into a single module?
    ... declarations. ... but suffice it to point out that if the code is really common you can ... bundle the objects together in a single module, ...
    (comp.lang.fortran)