Fortran 77 variable declaration issue

  • Context: Fortran 
  • Thread starter Thread starter AmenoParallax
  • Start date Start date
  • Tags Tags
    Fortran Variable
Click For Summary

Discussion Overview

The discussion revolves around a Fortran 77 variable declaration issue encountered while rewriting code for an astrophysics thesis. The focus is on the implications of changing variable declarations, specifically regarding the use of implicit declarations and common blocks, and how these changes affect computational results.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes their attempt to improve code readability and rigor by declaring all variables explicitly and using double precision, but encountered unexpected differences in results.
  • Another participant suggests that the issue may stem from the compiler's handling of common blocks, particularly regarding alignment and consistency across declarations.
  • A participant acknowledges not having modified all common block declarations yet, indicating a step-by-step approach to debugging.
  • One participant reports success after ensuring uniformity in common block declarations but expresses confusion over why the two declaration methods produced different results.

Areas of Agreement / Disagreement

Participants generally agree that the changes made should not have altered the results, but there is uncertainty regarding the compiler's behavior and the handling of common blocks. The discussion does not reach a consensus on the underlying cause of the issue.

Contextual Notes

There are limitations regarding the completeness of common block modifications across the code, which may affect the results. The discussion also highlights the potential for compiler-specific behavior that could influence outcomes.

AmenoParallax
Messages
11
Reaction score
0
Hi

I've been struggling with a fortran 77 code that I need for my astrophysics thesis... Since it's quite old, I'm trying to rewrite some features in order to make it more readable, and I'm trying to make it more rigorous by declaring all variables (I'm declaring "implicit none" everywhere), setting all real variable to double precision, and that kind of stuff. No main changes, and most importantly nothing that would alter the result of the computation.

However, something happened, and I got different results with respect to the original version. I spent hours debugging and looking for the exact place where the difference originated, and apparently the problem is due to the declaration of a variable (a double precision array) which is part of a common block.

More precisely, in the original version the variable was declared as:

IMPLICIT REAL*8 (A-H,L,M,O-Z)
COMMON /CMN1/ VA1(4),VA2(4),...

while in my updated version I changed it to:

IMPLICIT NONE
REAL*8 VA1(4),VA2(4),...
COMMON /CMN1/ VA1,VA2

Now, I wouldn't expect that this could change the calculations, but that's what happened... Anybody can explain why?

I don't think the rest of the code and the specific calculations performed are important in solving the issue, and beside that I can't post the code because it's not mine and anyway it's very long.

Any suggestion would be very appreciated. Thanks everybody!
 
Technology news on Phys.org
That should have worked. Maybe the compiler is doing something to the common blocks (aligning, etc.) that is causing an issue. Are the common blocks declared the same everywhere (have you modified them everywhere they appear in the code)?
 
DrClaude said:
That should have worked. Maybe the compiler is doing something to the common blocks (aligning, etc.) that is causing an issue. Are the common blocks declared the same everywhere (have you modified them everywhere they appear in the code)?
I have not modified the common blocks everywhere yet... I was trying to apply one change at a time in order to find the problematic part of the code. I'll try to uniform all the common block right away.
 
DrClaude said:
That should have worked. Maybe the compiler is doing something to the common blocks (aligning, etc.) that is causing an issue. Are the common blocks declared the same everywhere (have you modified them everywhere they appear in the code)?
I changed the way common blocks are declared everywhere, meaning that keeping the implicit declaration of double precision variables I explicitly declared the types of all variables belonging to any common blocks everywhere in the code.

It actually seems to have worked! But still it seems quite strange that the two ways of declaring a variables (apparently equivalent) give different results...

Anyway thanks, I think this solves my problem!
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K