F77: Different COMMON blocks with same variable names 
Author Message
 F77: Different COMMON blocks with same variable names

Hi,

Let there be two sets of subroutines/functions with two common blocks  
with different names. All or at least some of the variables between the  
different blocks have the same names and types. There is only one common  
block per routine, so there is no direct variable mix-up (and the program  
compiles without any problems). But other variables, not in one of the  
common blocks mentioned above, are derived from both and used in  
calculations. Could this configuration still pose a problem?

The reason is that I have a program (self-written, under construction)  
where this is the case. The program shows weird behaviour which I cannot  
explain. Variables seem to become undefined or have strange values (or  
not-a-number's)

Unfortunately the program is too complex to simplify the problem to a few  
lines. But maybe someone already knows whether this configuration  
actually IS illegal in F77 or the problem must be something else.

Thanks...

--
Ingo



Wed, 16 Jan 2008 00:23:00 GMT  
 F77: Different COMMON blocks with same variable names


Quote:
> Let there be two sets of subroutines/functions with two common blocks  
> with different names. All or at least some of the variables between the  
> different blocks have the same names and types. There is only one common  
> block per routine, so there is no direct variable mix-up (and the program  
> compiles without any problems). But other variables, not in one of the  
> common blocks mentioned above, are derived from both and used in  
> calculations. Could this configuration still pose a problem?

Yes. It can cause huge problems, but.... they all have to do with
confusing humans. The names of the variables in a common block have no
direct impact on anything outside of the scope where the common block
appears (or nested scopes). In particular, it has no impact on names of
variables used in other common blocks in other scopes.

At the highest level, a common block is just a chunk of storage. The
common block itself may have a name, but the variables in the common
block do not have globally known names. So you are ok, except...

Don't ignore the human problems. They are *VERY* important in a program
of substantial size and complexity (as you say that yours is).

Quote:
> The reason is that I have a program (self-written, under construction)...
> Unfortunately the program is too complex to simplify the problem...

I'll note that my personal recommendation for new code (which
"self-written, under construction" sounds like to me) is to avoid common
blocks altogether and use f90 features instead. The more complicated the
code, the more emphasis I would put to that recommendation. Common
blocks are the tools of several decades ago and they have lots of
"issues" and complications that make working with them painful in large
and complicated programs. I've worked with them, as have many other
people in the past; they were pretty much the only viable option. The
scars of those experiences contributed a lot to the design of subsequent
features. (My signature seems relevant here).

Common blocks will be with us for a long time in large legacy codes and
in new modifications done to those codes. For simple small codes, the
problems aren't as bad. But if you are writing a new program that is
"too complex to simplify the problem..." I'd posit that you are
handicapping the future of the program by writing it with the tools of
the past.

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Wed, 16 Jan 2008 01:12:32 GMT  
 F77: Different COMMON blocks with same variable names

Quote:
> Yes. It can cause huge problems, but.... they all have to do with
> confusing humans. The names of the variables in a common block have no
> direct impact on anything outside of the scope where the common block
> appears (or nested scopes). In particular, it has no impact on names of
> variables used in other common blocks in other scopes.

Actually I have solved the problem. It had nothing to do with common-
block mix-up but very much with human confusion when trying to stick two  
(working and well-tested) components quickly and dirtily together.

The new code is only an experimental one, so there is no problem with  
lack of transparency.

On the other hand, I am a bit sceptic about using F90 features unless  
there are well-tested and freely available F90 compilers (e.g. as part of  
the GCC) for different platforms (Linux, Windows and maybe Mac).

Quote:
> Don't ignore the human problems. They are *VERY* important in a program
> of substantial size and complexity (as you say that yours is).

Well, it is too complex to extract the carious tooth within the few  
minutes of writing a posting. However, compared to other codes it is  
still tiny (about 1000 lines), but different consisting of files.

But thanks anyway

--
Ingo



Wed, 16 Jan 2008 01:44:00 GMT  
 F77: Different COMMON blocks with same variable names


Quote:

> > Don't ignore the human problems. They are *VERY* important in a program
> > of substantial size and complexity (as you say that yours is).

> Well, it is too complex to extract the carious tooth within the few  
> minutes of writing a posting. However, compared to other codes it is  
> still tiny (about 1000 lines), but different consisting of files.

Ah. Ok. I'd agree that 1000 lines is "tiny compared to other codes".
That's not big enough for namespace management to be a major factor.
There was a time when I considered 1000 lines to be a substantial
program (heck, that would be 2/3 of a box of cards. :-)), but not any
more.

I don't write new code in f77 anyway, for other reasons that I don't
think I'll divert off into in this thread, but I agree that 1000 lines
doesn't push you into the area where namespace management is a big deal.

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Wed, 16 Jan 2008 03:43:48 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Linking routines with different length common blocks?

2. Finding the end of a common block (f77)

3. f77 and dynamic arrays in common blocks

4. f77 common blocks and shared libraries

5. Sun F90 mixing with F77: Common Blocks

6. pointers in common blocks (Absoft vs. SGI F77)

7. f77 from C common block

8. IBM AIX problem: Fortran common blocks in C++/F77 shared lib

9. Q: C , f77 and COMMON BLOCK

10. Common blocks in F95 and F77

11. Using the same common block name twice

12. F90 name conflicts with common block

 

 
Powered by phpBB® Forum Software