Arrays with parameter and data statements in fortran 77

In summary, to declare an array A and a variable B (both reals), you cannot use the parameter statement with A and must instead use the data statement. However, this can cause issues when trying to declare B as a parameter. To avoid this issue, B can be set as the actual value of A(3) or simply not declared as a parameter. Declaring B as a parameter is meant to protect against unintended modifications, but it is not essential and may not be necessary in all cases.
  • #1
JoAuSc
198
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
  • #2
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...)
 

1. What is an array in Fortran 77?

An array in Fortran 77 is a data structure that allows you to store multiple values of the same data type in a single variable. It is defined using the DIMENSION statement and can have one or more dimensions. Arrays are commonly used in scientific and engineering applications for storing large amounts of data.

2. How do you declare an array with parameters in Fortran 77?

To declare an array with parameters in Fortran 77, you can use the PARAMETER statement followed by the array name, dimensions, and the values for each element. For example, PARAMETER A(10) = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) will declare an array A with 10 elements and assign the values 1 to 10 to each element.

3. What is the purpose of using data statements in Fortran 77?

Data statements in Fortran 77 are used to initialize variables, including arrays, with specific values. This can save time and effort by allowing you to assign values to multiple variables at once without having to use individual assignment statements.

4. How do you access elements in an array with parameters in Fortran 77?

To access elements in an array with parameters in Fortran 77, you can use the array name followed by the index value in parentheses. For example, A(3) will access the third element in the array A. You can also use the DO loop to iterate through the array and access each element.

5. Can you change the values of an array with parameters in Fortran 77 during program execution?

No, the values of an array with parameters cannot be changed during program execution in Fortran 77. The values specified in the PARAMETER statement are considered constants and cannot be modified. If you need to change the values of an array, you can declare it without parameters and use assignment statements to change the values during program execution.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
4
Views
15K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
612
  • Programming and Computer Science
Replies
16
Views
1K
Replies
2
Views
918
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
15
Views
3K
Back
Top