Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass an array to Fortran 95 from C??

Status
Not open for further replies.

vibe33

Programmer
Jul 1, 2010
2
US
I'm trying to call routines in the SHTOOLS library (written in fortran 95) from C. For example, one routine is:

subroutine PreCompute(lmax, zero, w, plx, wisdom_file, norm, csphase, cnorm)

integer, intent(in) :: lmax
real*8, intent(out) :: zero:)), w:))
real*8, intent(out), optional :: plx:),:)
integer, intent(in), optional :: norm, csphase, cnorm
character(*), intent(in), optional :: wisdom_file

if (size(zero) < lmax+1) then
print*, "Error --- PreCompute"
...

Now when I call from C, I use the standard:

int lmax;
double *zero = malloc(...);
precompute_(&lmax, zero, ...)

but apparantly fortran 95 needs to know the size of the 'zero' array since it checks size(zero) etc. Needless to say, this check fails since it doesn't have size information on 'zero'.

My question is, how do you properly pass arrays to fortran 95? How do you specify these size/dimension parameters in the call?
 
Which compiler are you using?

If your Fortran 95 compiler supports the 2003 standard then there already is a C interface.

If it does not support the 2003 standard, then there will be some vendor specific technique but we need to know which compiler you're using first.
 
Oh yes I'm using gfortran:

GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top