Fortran Arrays with parameter and data statements in fortran 77

Click For Summary
In Fortran 77, declaring an array A as a parameter using the syntax "parameter (A = (/1.2, 3.4, .../))" is illegal; instead, a data statement must be used. However, if you attempt to declare a variable B as a parameter based on an element of A, it leads to illegal declarations since parameters can only be defined using other parameters. One alternative is to set B directly to the value of A(3), but this approach raises concerns about maintaining consistency if the array A is modified later. Hard-coding B as a parameter can prevent accidental changes, but it is considered bad practice to compile code with varying parameter values. Ultimately, careful consideration is needed when deciding how to declare and manage parameters in 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...)
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 25 ·
Replies
25
Views
3K
  • · 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