Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dimension an array after the call of a subroutine

Status
Not open for further replies.

sergio87

Programmer
Nov 10, 2011
1
Hi guys
I've got a problem and didn't manage to solve it up to now. I have a main program and a subroutine, which is called from the main program. The subroutine is storing data in an array, whose length is determined right in the subroutine, and therefore depends on the inputs of the subroutine. This array is then sent back again to the main program. But the main program does not know the length of this array from the beginning, but only after the subroutine is called. How is it possible to allocate this array in the main method, after the subroutine is called?

thank you
 
I am not sure I understand your problem or maybe I do and don't understand why you are looking at this backwards?

If the dimension of the array depends on inputs to the subroutine, it means that you know what the dimension of the array should be BEFORE you call the subroutine...thus, why don't you allocate the array BEFORE you call the subroutine and THEN pass the dimension AND the array to the subroutine?

Or, if you insist...is it possible to declare an array to be allocate-able in the main program and pass it to the subroutine without it being allocated? I am asking this because I know that Fortran by default passes by reference and I am not sure if an array not yet allocated has at least some kind of address or not...in any case, you then allocate the array inside the subroutine and that's it...then, I presume there is a way to find out what the size of the array is after it has been allocated.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top