Arrays with parameter and data statements in fortran 77

Click For Summary
SUMMARY

In Fortran 77, declaring an array with a parameter statement is illegal, necessitating the use of a data statement instead. Specifically, the syntax data A /1.2, 3.4, .../ is required for initializing the array A. However, this creates a conflict when attempting to declare another parameter B as parameter (B = A(3)), since parameters can only reference other parameters. A recommended approach is to set parameter B to the actual value of A(3) directly, although this may lead to concerns regarding code maintainability and consistency.

PREREQUISITES
  • Understanding of Fortran 77 syntax and semantics
  • Familiarity with parameter and data statements in Fortran
  • Knowledge of array initialization in Fortran
  • Awareness of best practices in coding and parameter management
NEXT STEPS
  • Research Fortran 77 array initialization techniques
  • Explore the implications of using parameters versus data statements in Fortran
  • Learn about best practices for managing constants and parameters in Fortran
  • Investigate the impact of hard-coded values on code maintainability
USEFUL FOR

Fortran developers, software engineers working with legacy code, and anyone involved in numerical computing or scientific programming using Fortran 77.

JoAuSc
Messages
197
Reaction score
1
Let's say you have an array A and a variable B (both reals). Apparently

parameter (A = (/1.2, 3.4, .../) )

is illegal, so you have to do

data A /1.2, 3.4, .../

instead. However, what if you have a statement afterwards like this?

1 parameter (A = (/1.2, 3.4, .../) )
...
2 parameter (B = A(3))

If you change 1 to a data statement, 2 becomes illegal since you can only declare parameters with other parameters, but 1 is illegal as is. How would I declare something like this that's legal?
 
Technology news on Phys.org
Treating something as a parameter is a protection against modifying that variable by mistake. There is nothing essential about it, so you could simply not declare B as a parameter.

Alternatively, you could set the parameter B to the actual value of A(3). (What is the risk here? If it is set as a hard-coded parameter, it shouldn't be expected to change. I would say it is bad practice to compile the same version of a code with different values of the parameters...)
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
17K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
7
Views
3K