I have some allocatable array which their size is determined in the subroutine. How can I introduce them in the main block which I lately not have any problems with it? Symbolic code is:
Main PROG
IMPLICIT NONE
REAL, DIMENSION(:,:), ALLOCATABLE :: A
REAL, DIMENSION(:,:), ALLOCATABLE :: B
REAL, DIMENSION(:,:), ALLOCATABLE :: C
CALL SUB(A,B,C)
!Continue the program
END MAIN PROG
-------------------
SUB(A,B,C)
IMPLICIT NONE
REAL, DIMENSION(:,:) :: A
REAL, DIMENSION(:,:) :: B
REAL, DIMENSION(:,:) :: C
!OPERATION ON A AND B WHICH DETERMINE THE DIMENSION OF C
END SUB
I also read these:
Array allocation in Fortran subroutine
But, none of them is practical in my case.
I consider them as below:
ALLOCATE/DEALLOCATE solution:
If a variable allocated in the main then you have two choices:
None introduce it in the variable declaration and deallocate it then you have the error: The variable is not allocatable or dummy
Introduce it in the variable declaration and deallocate it then you have the error: The variable is a dummy argument so cannot allocatable.
INTERFACE solution:
The main application of it in the module if you don't have a module or the variable read and allocate in subroutine it doesn't work.
Vladimir F solution:
His solution has two limitations. It works in case you read the variable in the subroutine. This solution is workable with the module because you need to add a subroutine just for reading the variable.
If my argument has a fault, or you have another solution, or you have a description to mention the solution to be applicable please note me.