Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

array valued functions

rahzan
Novice
3,635 Views
The follwoing code in cvf6.6b gives mismacthed arguments warning.
The function value itself is an array with some simlpe inputs

real,allocatable:: x(:),y(:)
allocate(x(4),y(4))
x=[1.,2.,3.,4.]
y=doubleAnArray(x,3)
write(*,*)x,y
read(*,*)
end
function doubleAnArray(inp,start) result (xx)
real,intent(in):: inp(:)
integer,intent(in):: start
real xx(4)
integer:: j,n
n=size(inP)
xx(:start-1)=0.
do j=start,n
xx(j)=2.*inp(j)
enddo
end function doubleAnArray
Any hints on how to do this will be appreciated.
0 Kudos
23 Replies
glyn
Beginner
888 Views

Steve,

Sorry, I'm still having some trouble with this, I've followed your advicebut I now getthemessages:

Warning: This name has not been given an explicit type. [CALCVECTORFORPLANE]

Error: The characteristics of the subroutine/function differ from those of the same subroutine/function that is specified in the INTERFACE statement. [CALCVECTORFORPLANE]

I don't understand this as I've checked that they are not different, and asked someone else here to have a look to check that I'm not missing anything obvious. The problem can be solved by moving my interfaces into seperate files, but that isn't what I really want and it work with them all being in one file for other functions.

I've installed the latest version of IVF and I've attached a small sample of the code to illustrate the problem.

Thanks in advance

Glyn.

0 Kudos
Steven_L_Intel1
Employee
888 Views
Glyn,

The fundamental problem here is that you INCLUDE an interface for a routine into the same routine. This is not legal, though the error you get from the compiler is confusing, I'll admit.

The recommended way of solving this is to put all your functions in a module and then USE the module where required. An alternative, which doesn't disturb your existing structure much, is to convert the INCLUDE file with the interfaces into a module and use the module. It is ok to use a module that defines the interface of the current routine - that is just ignored.

I have attached a zip file of my modification to your sources. It still doesn't build due to other issues, but you'll be on the right path.
0 Kudos
glyn
Beginner
888 Views

Steve,

Thank you very much.

Looks like I have some background reading on Modules to do now! :-)

Glyn.

0 Kudos
Reply