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

AI Thread Summary
Creating an empty array in Fortran 77 based on user-defined start and end numbers poses challenges due to the language's lack of dynamic memory allocation. In Fortran 77, array sizes must be defined at compile time, meaning you can declare a fixed-size array, such as REAL MYARRAY(4:10), which allocates memory for seven elements but does not allow for flexibility based on user input. While some Fortran 77 implementations support extensions for dynamic memory allocation using POINTER and MALLOC, this is not standard and may affect portability.For more flexibility, transitioning to Fortran 90 or later is recommended, as these versions support allocatable arrays and dynamic sizing. Users can define an array of a larger fixed size and then calculate the required length based on user input, filling the array with zeros or other values as needed. This approach allows for a more adaptable solution while still adhering to the constraints of the language.
1ytrewq
Messages
5
Reaction score
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
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:
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.
 
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!
 
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.
 
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top