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

Passing a matrix to a subroutine !

donkarnage
Beginner
263 Views
Hello eveyone !

So i am trying to port some simulation code i wrote in M***** to Fortran and having had myself spoilt, the journey is turning out to be reasonably tedious (hence some recent queries). Anyway - here is one more from me.

I am trying to pass a matrix with dimension(3*6) to a subroutine. Now if my memory (i used to code in F77 a long time back), in the call to the subroutine, i need to pass the address to the first location...

so what i did was :

call function(x,y,z,array(1,1),..)


then in the subroutine...

subroutine function(xx,yy,apass,...)

dimension apass(1,1)



However, there is no value being passed...what to do. Any hints ?

Regards!

ps: I know such queries should make me feel ashamed ..and i am borderline so... :-(

Message Edited by donkarnage on 07-28-2005 05:24 PM

0 Kudos
1 Reply
Steven_L_Intel1
Employee
263 Views
I'm unsure what you want to see in the subroutine. You have declared the subroutine argument as a 1x1 array. Surely that isn't what you intended?

There's not really any difference in passing array(1,1) and passing array - at least as long as you're not using explicit interfaces. In the subroutine, you'll need to either declare apass as (3,6) or, if the last dimension could change, (3,*). Only the last bound can be "assumed size", which was the old F66 trick of making the last bound 1. Doesn't work for more than one bound.

Now if you might pass arrays of different first and second extents to the routine, you need to use an assumed-shape array and explicit interfaces. For example:

subroutine function (xx,yy,apass)
...
dimension apass(:,:)
...

Now calling this requires an explicit interface. Best is to put the routine in a module and USE the module. Another choice is to make it a contained routine. A third choice is to create an interface block and make it visible to the caller, as follows:

interface
subroutine function (xx,yy,apass)
real xx,yy
real apass(:.:)
end subroutine function
end interface

This block can go in the declaration section of the calling routine. You would then just pass the whole array, and not the first element.
0 Kudos
Reply