Register to reply

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

by 1ytrewq
Tags: blank array, fortran
Share this thread:
1ytrewq
#1
Aug9-11, 10:59 AM
P: 6
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!!
Phys.Org News Partner Science news on Phys.org
NASA team lays plans to observe new worlds
IHEP in China has ambitions for Higgs factory
Spinach could lead to alternative energy more powerful than Popeye
jtbell
#2
Aug9-11, 11:47 AM
Mentor
jtbell's Avatar
P: 11,602
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.
uart
#3
Aug9-11, 01:47 PM
Sci Advisor
P: 2,751
Quote Quote by 1ytrewq View Post
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.

AlephZero
#4
Aug9-11, 02:52 PM
Engineering
Sci Advisor
HW Helper
Thanks
P: 6,929
Fortran 77 help making an empty array (or blank list if they exist in fortran)

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!
Louisa
#5
Aug14-11, 03:51 AM
P: 24
Quote Quote by 1ytrewq View Post
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.
sue132
#6
Mar15-12, 12:32 AM
P: 14
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.


Register to reply

Related Discussions
FORTRAN 90 array problem Programming & Computer Science 4
Printing 1D array in Fortran as 2D array... Programming & Computer Science 7
Co-Array Fortran Programming & Computer Science 2
Array shuffling in fortran Programming & Computer Science 1
Accessing Fortran Modules within a Fortran library from Fortran Programming & Computer Science 0