Appel d'une subroutine fortran en c++
Bonjour tout le monde,
je suis débutant en c++, et dans mon stage je dois utiliser des programmes écrits en Fortran. J'ai trouvé des exemples d'appel de fonctions ou subroutines mais j'ai toujours des erreurs au niveau de la compliation !
voici mon code:
fonction main :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <cstdlib>
#include <cstdio>
#include <iostream>
extern "C" double fonction_somme_(long *fsize, double* fvec);
extern "C" void sousroutine_somme_(long *fsize, double* fvec, double *fsum);
int main()
{
long i,size;
double sum;
double *vec;
size = 5000;
vec = new double[size];
for(i=0;i<size;i++)
{
vec[i]=1.1234532;
}
// Appeler une fonction du fortran
sum = fonction_somme_(&size,vec);
cout << "Appeler une fonction Fortran" << endl;
cout << "============================" << endl;
cout << "size = " << size << endl;
cout << "sum = " << sum << endl << endl;
// Appeler une sous-routine du fortran
sousroutine_somme_(&size,vec,∑);
cout << "Appeler une sousroutine Fortran" << endl;
cout << "===============================" << endl;
cout << "size = " << size << endl;
cout << "sum = " << sum << endl << endl;
} |
la fonction et la subroutine écrites en fortran:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
real*8 function fonction_somme(fsize,fvec)
integer fsize,i
real*8 fvec(fsize)
real*8 sum
fonction_somme=0.0
do i=1,fsize
fonction_somme=fonction_somme+fvec(i)
end do
return
end
subroutine sousroutine_somme(fsize,fvec,sum)
integer fsize,i
real*8 fvec(fsize)
real*8 sum
sum=0.0
do i=1,fsize
sum=sum+fvec(i)
end do
end |
et voilà les erreurs que ça donne :
Citation:
-------------- Build: Debug in Appel_fction_subrout ---------------
Compiling: fction_subr.f
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:1.1:
real*8 function fonction_somme(fsize,fvec)
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:1.1:
real*8 function fonction_somme(fsize,fvec)
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:3.5:
integer fsize,i
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:3.5:
integer fsize,i
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:4.5:
real*8 fvec(fsize)
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:4.5:
real*8 fvec(fsize)
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:5.5:
real*8 sum
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:5.5:
real*8 sum
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:7.5:
fonction_somme=0.0
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:9.5:
do i=1,fsize
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:9.5:
do i=1,fsize
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:11.5:
end do
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:11.5:
end do
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:13.5:
return
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:13.5:
return
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:15.1:
end
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:15.1:
end
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:18.1:
subroutine sousroutine_somme(fsize,fvec,sum)
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:18.1:
subroutine sousroutine_somme(fsize,fvec,sum)
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:20.5:
integer fsize,i
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:20.5:
integer fsize,i
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:21.5:
real*8 fvec(fsize)
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:21.5:
real*8 fvec(fsize)
1
Error: Unclassifiable statement at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:22.5:
real*8 sum
1
Error: Non-numeric character in statement label at (1)
C:\Users\Anas\codeblocks_proj\Appel_fction_subrout\fction_subr.f:22.5:
real*8 sum
1
Error: Unclassifiable statement at (1)
Fatal Error: Error count reached limit of 25.
Process terminated with status 1 (0 minutes, 3 seconds)
0 errors, 0 warnings (0 minutes, 3 seconds)
Merci