CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Siemens (https://www.cfd-online.com/Forums/siemens/)
-   -   Passing data/variables between subroutines (https://www.cfd-online.com/Forums/siemens/56243-passing-data-variables-between-subroutines.html)

Emmanuel Resch August 16, 2007 11:42

Passing data/variables between subroutines
 
Hello,

I'm having a bit of trouble passing variables and data between subroutines. Using v3.26, I understand that the procedure for declaring/passing an array "UARRAY" of variable size is the following:

First, a common block statement (req'd for every subroutine):

COMMON/UCOMM1/P_UARRAY

Then, in the first subroutine called, the array and its pointer need to be defined:

DIMENSION UARRAY(NCMAX)

POINTER(P_UARRAY,UARRAY)

With space in memory allocated by:

CALL CDMALLOC(P_UARRAY,IFLSIZ*NCMAX)

I am having difficulties with this... I am using the following subroutines which employ these arrays: sorsca.f, sorent.f, posdat.f

QUESTION: Which of these subroutines is called first, i.e. in which subroutine should I have the variable definition/memory allocation statements?

If anyone had some example files that would be a great help!

Thanks.

Richard August 16, 2007 12:44

Re: Passing data/variables between subroutines
 
You could do the memory allocation in your own subroutine, called from all three user subroutines. In that subroutine, have a logical with SAVE attribute, say INIT. Initialize INIT to false in a DATA statement. Just return if it is true, but allocate the memory and set INIT to true otherwise. Then you don't need to know the call sequence and you can guarantee that the memory will be allocated when needed, and just once. The subroutine could also initialize the memory as well as allocating it.


All times are GMT -4. The time now is 11:59.