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.
29284 Discussions

Function calls and allocatable arrays: console vs windows application

chandrika
Beginner
858 Views

Dear members,

I have written code in a console application and it compiles and works, however when I try to compile the same code in a fortran windows application I am flooded with warnings. The code is a subroutine which calls several functions and the agruments that are passed to the functions include allocatable arrays. The return values of the functions are also arrays. The warnings that I am getting tell me that the 'actual argument does not match the type and kind of the corresponding dunmmy argument ' and that 'an explicit-shaped array is being passed to a routine that expects a pointer or assumed-shape array'. The form of the code is as follows:


subroutine GenData(num)

external function1

integer num
real, allocatable :: Array1(:), Array2(:)

allocate(Array1(num))

Array2 = function1(Array1, num)

end subroutine

Any suggestions as to the source of the warnings that I getting as well as how to remedy my problem would be greatly appreciated.

Regards
Chandrika

0 Kudos
6 Replies
anthonyrichards
New Contributor III
858 Views
Surely you mst use a SUBROUTINE FUNCTION1 as a FUNCTION returns a single value?
Also, you have not ALLOCATEd Array2 before it is referenced.
I assume you would have something like the following in Subroutine Function1
AFTER allocating Array2, for which you need a value for its maximum dimension..
num2= ???
ALLOCATE (Array2(num2))
call Functuion1(array1, num1,Array2,num2)
SUBROUTINE Function1 (array1,num1,array2,num2)
REAL array1(num1), array2(num2)
...
...
etc...
END SUBROUTINE FUNCTION1
0 Kudos
Steven_L_Intel1
Employee
858 Views
I can't see how the code would work given what you've told us. If you call a routine which returns an array, or which has a deferred-shape array argument, you MUST have an explicit interface visible to the caller. See my article on this topic.
Anthony, I don't understand your comment about a SUBROUTINE declaration. Subroutines don't return any values.
0 Kudos
anthonyrichards
New Contributor III
858 Views
Er,with certainty that I am going to tell Grandma how to suck eggs...the subroutine communicates by its arguments, and so returns values by populating/altering values at the memory address of one or more of its arguments. According to the FORTRAN language reference, a FUNCTION returns a single value, so to return an array of values, I think you need to use an array argument to a subroutine. The poster's code clearly indicates that he wishes to populate an ALLOCATABLE array, array2.....
0 Kudos
Steven_L_Intel1
Employee
858 Views
Er, no. In Fortran 90 you can have a function that returns an array. Doing so does require that an explicit interface be used, so that the compiler can do the right things behind the curtain. In F90, such arrays can be fixed-size, with bounds determined by a specification expression, or deferred shape as a POINTER. F2003 allows the result to be ALLOCATABLE as well, and Intel Fortran supports this feature.
0 Kudos
anthonyrichards
New Contributor III
858 Views
Er..point taken, thanks. The poster still hadn't allocated the array before referencing it...
0 Kudos
chandrika
Beginner
858 Views
Thank you for all your help, the interface was what I needed to implement.
0 Kudos
Reply