IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C++ Discussion :

Appel d'une subroutine fortran en c++


Sujet :

C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Janvier 2012
    Messages : 3
    Par défaut 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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 :
    -------------- 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

  2. #2
    Membre émérite
    Avatar de Ekleog
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2012
    Messages : 448
    Par défaut
    Au vu des messages d'erreur, c'est un problème dans le code fortran.

    Je n'ai jamais utilisé ce langage, mais le compilateur fortran semble t'annoncer qu'il s'attend à un nombre à la place de "real*8".

Discussions similaires

  1. Problème de performance d'une subroutine FORTRAN
    Par Kercheur dans le forum Fortran
    Réponses: 3
    Dernier message: 15/02/2011, 16h54
  2. Réponses: 2
    Dernier message: 18/02/2010, 09h56
  3. Réponses: 4
    Dernier message: 27/11/2008, 18h02
  4. Utiliser une subroutine fortran en C
    Par chaponinho dans le forum Linux
    Réponses: 1
    Dernier message: 28/04/2008, 20h08
  5. [Debutant] Appel d'une fonction FORTRAN depuis C++
    Par Amariel dans le forum Débuter
    Réponses: 2
    Dernier message: 10/07/2007, 13h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo