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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

allocatable array allocated inside subroutine

Status
Not open for further replies.

jshine

Technical User
May 26, 2006
1
US
I'm curious what the best way to return an array of data from inside a subroutine is when the size of the array can't be determined until one is already inside the subroutine.

Due to the nature of the calculation, I can't predict how much storage space I will need before executing the subroutine.

Is it legal to have an allocatable array as a dummy argument of intent "out" and then allocate it inside the subroutine? Or is there a better way to handle this situation?

Thanks in advance!
-Jon
 
I have something similar, perhaps this will help?

In the calling routine have the allocatable array decalared
using dummy arguments

ALLOCATABLE :: TWARRY1:),:)


then I obtain the variable array arguments MAAX and MARD from other calculations


before I allocate, I make sure the temporary array does not exist

IF(ALLOCATED(TWARRY1)) DEALLOCATE(TWARRY1)

now I allocate my temporary array

ALLOCATE (TWARRY1(MAAX,MARD))

and pass it to another sub

CALL WADESC(MAAX,MARD,TWARRY1)

in sub WADESC I have

SUBROUTINE WADESC(NMAAX,NMARD,TWARRY)
INTEGER,INTENT(IN)::NMAAX
INTEGER,INTENT(IN)::NMARD
INTENT(OUT),DIMENSION(NMAAX,NMARD):: TWARRY

within WADESC I am building the detail of TWARRY
at the exit of WADESC, TWARRY is completed

END SUB WADESC

and on returning to the calling routine the temporary array
TWARRY1 is then completed.




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top