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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method for calling a C function from Fortran 90 1

Status
Not open for further replies.

stathakis39

Technical User
Jun 22, 2009
1
US
Should be a pretty simple problem--I'm trying to figure out how to take a portion of our Fortran 90-based simulation and run it in C.
Any assistance would be much appreciated, as my only recourse at this point is the Internet, though I have been unable to find any Fortran 90 examples.
 
Hi

Maybe the following web-page can help you:

I also got the code below from a Fortran/C programmer a while ago. This is an example of how to call a C subroutine and a C function from Fortran:

(1) The Fortran file:

INTEGER CR2
N=10
CALL CR1(N,M)
WRITE(6,20) N,M
20 FORMAT(' The square of',I3,' is',I4)
K=CR2(N)
WRITE(6,30) N,K
30 FORMAT(' The cube of',I3,' is',I15)
CALL EXIT
END

(2) The C++ files:

extern "C"
{
void __stdcall CR1(int *,int *);
int __stdcall CR2(int *);
}
void __stdcall CR1(int *n, int *m)
{
// Compute the square of n, return in m
int k;
k=*n;
*m=k*k;
return;
}
int __stdcall CR2(int *n)
// Compute the cube of n
{
int m,k;
k=*n;
m=k*k*k;
return m;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top