Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29297 Discussions

Passing allocatable arrays to subroutines

sang186
Beginner
324 Views
I need help with passing allocatable arrays among different subroutines where the dummy arguments within subroutines have the same name as the actual arguments.

Currently this is what I am doing
! ************ Code sample begins here ***********!
Main_Subroutine
use mod ! (mod contains the declarations to the global variables. m and n assigned in a different subroutine)
real,dimension(:,:),allocatable :: arg1,arg2
allocate(arg1(m,n),arg2(m,n))
call Sub1(arg1,arg2)
end Main_Subroutine
!--------------------------------------------------------------!
subroutine Sub1(arg1,arg2)
use mod
real,dimension(:,:),allocatable :: arg1,arg2
allocate(arg1(m,n),arg2(m,n))
!! processing code
end Sub1
! ************ Code sample ends here ***********!
The code compiles correctly when this is done, but I get the following warning message
Warning: In the call to SUB1, actual argument #1 does not match the type and kind of the corresponding dummy argument.
Warning: In the call to SUB1, actual argument #2 does not match the type and kind of the corresponding dummy argument.
Could someone tell me as to where am I going wrong here ? Is there a way to proceed without changing the variable name of the dummy arguments, as i have numerous subroutines with the same dummy arguments declared and changing them is going to be really tedious.
Thank you,

Regards,
Sangeetha Chandrasekaran
Univerisity of Illinois
0 Kudos
1 Reply
jimdempseyatthecove
Honored Contributor III
324 Views
First, you are doubly allocating arg1 and arg2. Once before the call to Sub1 and once at the beginning of Sub1. You must decide where you want to do the allocations.

Second, in order to pass an array descriptor (required for allocatable array to be allocated within Sub1), Sub1 needs to have an interface block. You could place the interface block into module mod or in some other module (mod_subs) used for this purpose.

Jim Dempsey
0 Kudos
Reply