Fortran 77 help making an empty array (or blank list if they exist in fortran)

In summary, you would have to use a different language to create an empty array in Fortran 77. If you need to store numbers, you could make an array of 0's in Fortran 95.
  • #1
1ytrewq
6
0
I need to create an empty array but the length of the array is determined by the start and end numbers entered by the user

for example if the range of numbers the user was interested in was 4-10 inclusive then i want the array to be of length 7

How to I go about doing this?

Other languages (Python for example) have the option to create an empty list and then values can be added to the list as many times as is required. Is there any similar function in fortran 77?

Thanks in advance for any help!
 
Technology news on Phys.org
  • #2
Fortran 77 doesn't have dynamically-allocated arrays. You have to anticipate the maximum bounds of the array, and declare it accordingly. You can declare

REAL MYARRAY(4:10)

which allocates memory for seven REALs, MYARRAY(4) through MYARRAY(10), but this allocation is fixed.
 
Last edited:
  • #3
1ytrewq said:
I need to create an empty array but the length of the array is determined by the start and end numbers entered by the user

for example if the range of numbers the user was interested in was 4-10 inclusive then i want the array to be of length 7

How to I go about doing this?

Other languages (Python for example) have the option to create an empty list and then values can be added to the list as many times as is required. Is there any similar function in fortran 77?

Thanks in advance for any help!

Remember that an interpreted language like python has somewhat of an advantage over a compiled language like fortran in this regard, since you don't have quite the same distinction between compile time and run time with an interpreter. In fortran array lengths have to be defined at compile time.
 
  • #4
Many implementations of Fortran 77 have extensions to handle dynamic memory allocation, using a POINTER statement to declare the variables and a function (probably called MALLOC} to allocate space. This isn't "ANSI standard Fortran 77", but enough compilers support for it to be a de facto portable standard. Of course if you only plan to run your code on your own computer system, you might not care if it is portable, so long as it works for you!
 
  • #5
1ytrewq said:
I need to create an empty array but the length of the array is determined by the start and end numbers entered by the user

for example if the range of numbers the user was interested in was 4-10 inclusive then i want the array to be of length 7

How to I go about doing this?

You should try that in Fortran 90 or later compiler,
which have allocatable arrays. Even later versions (after Fortran 95)
have allocate on assignment, arrays can grow.

There are several free Fortran 95 compilers.
 
  • #6
If you're going to use it to store numbers, then maybe you could make it an array of 0's. You could probably define an array of some large dimension, and then when you get the limits (4-10, in your example) from the user, you could calculate the difference between them and make a zeros array of that size. If your user inputs 4&10, say, then you could calculate the difference of the two (you might want to add 1 to it to make it inclusive). If d is the difference between the two, then maybe you could generate an array(d) with all zeros using a do-loop.

Hope this was useful.
 

1. What is an empty array in Fortran 77?

An empty array in Fortran 77 is an array that has no elements or has all its elements set to a default value. This is often used as a placeholder for arrays that will later be filled with data.

2. How do I declare an empty array in Fortran 77?

To declare an empty array in Fortran 77, you can use the DIMENSION statement and set the size of the array to 0. For example, DIMENSION A(0) will create an empty array named A with 0 elements. Alternatively, you can declare an array with a size greater than 0 and later set all its elements to a default value using the EQUIVALENCE statement.

3. Can I create an empty array without specifying its size in Fortran 77?

No, in Fortran 77, all arrays must have a specific size declared. However, as mentioned in the previous answer, you can declare an array with a size of 0 or a size greater than 0 and then set all its elements to a default value to create an empty array.

4. How do I check if an array is empty in Fortran 77?

In Fortran 77, you can check if an array is empty by comparing its size to 0. If the size is 0, then the array is empty. You can also use the EQUIVALENCE statement to set all the elements of the array to a default value, and then check if all the elements are equal to this default value.

5. Are empty arrays the same as blank lists in Fortran 77?

In Fortran 77, there is no concept of a "blank list." An empty array is an array with no elements, while a blank list is simply a list with no items. However, you can use an empty array as a placeholder for a blank list by setting its size to 0.

Similar threads

  • Programming and Computer Science
Replies
7
Views
273
  • Programming and Computer Science
Replies
17
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
17
Views
922
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top