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!

Variable-length array output :D 2

Status
Not open for further replies.
Thanks, mikrom, I appreciate it. Glad I could help!

While I'm here, an explanation from Tobias regarding why the subroutine works, but the function doesn't:

in the main program:

real, dimension:)), allocatable :: vector_call
call random_vector(vector_call)


Here, you pass (effectively) the address of the array descriptor to the
subroutine "random_vector" - and that variable gets evaluated.

real, dimension:)), allocatable :: vector_call
vector_call = random_vector()


Whereas in the function case, you allocate the result variable "vector"
- but not the variable "vector_call". Fortran works such that first all
on the RHS of an assignment is evaluated and then the result assigned to
the LHS. Thus, the RHS is allocated, but gfortran assumes (as does
Fortran 90/95) that the LHS is allocated with the correct size - and
does not touch the allocation status or the size (rather: shape) of the LHS.

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top