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

Fortran Discussion :

Programme court calculant la FFT en 2D


Sujet :

Fortran

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Octobre 2017
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : Santé

    Informations forums :
    Inscription : Octobre 2017
    Messages : 6
    Points : 5
    Points
    5
    Par défaut Programme court calculant la FFT en 2D
    Bonjour, j'aimerais utiliser le programme suivant pour calculer la FFT 2d ( trouvé sur https://wiki.oulu.fi/download/attach...0154000&api=v2, qui me semble très bien fait et clair, il utilise la FFT 1d ). Cependant, je n'arrive pas à le compiler, j'ai bien vérifié le code et tout me semble correct ( ici je le teste avec un exemple très simple d'une matrice remplie de 1 de taille 10x10):

    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     program fft2
     implicit none
     integer, parameter :: N=10,M=10,S=1
     integer :: i,j
     complex, dimension(n1,n2) :: A
     
     do i=1,M
     do j=1,N
     A(i,j)=1.
     end do 
     end do
     
     call ft2d(N,M,A,S)
     
     
     
      subroutine ft2d(n1,n2,cp,isig)
        implicit none
        integer :: n1,n2,isig,i1,i2
        complex :: cp(n1,n2),cw(n2)
        external fork
     
        do i2= 1,n2
          call fork(n1,cp(1,i2),isig)
        end do
     
        do i1= 1,n1
          do i2= 1,n2
            cw(i2)= cp(i1,i2)
          end do
          call fork(n2,cw,isig)
          do i2= 1,n2
            cp(i1,i2)= cw(i2)
          end do
        end do
     
        return
      end subroutine ft2d
     
     
      subroutine fork(lx,cx,isig)
     
        implicit none
        integer :: lx,isig,i,j,l,m,istep
        complex :: cx(lx),carg,cexp,cw,ctemp
        real :: pii,sc
        pii= 4.*atan(1.)
     
        j= 1
        sc= sqrt(1./lx)
        do i= 1,lx
          if(i <= j) then
            ctemp= cx(j)*sc
            cx(j)= cx(i)*sc
            cx(i)= ctemp
          end if
          m= lx/2
          do while (m >= 1 .and. j > m)
            j= j-m
            m= m/2
          end do
          j= j+m
        end do
        l= 1
        do while (l < lx)
          istep= 2*l
          do m= 1,l
            carg= cmplx(0.,1.)*(pii*isig*(m-1))/l
            cw= cexp(carg)
            do i= m,lx,istep
              ctemp= cw*cx(i+l)
              cx(i+l)= cx(i)-ctemp
              cx(i)= cx(i)+ctemp
            end do
          end do
          l= istep
        end do
        return
      end subroutine fork
     
     
    end program fft2
    Il m'annonce que la plupart de mes variables ne sont pas déclarées et ne comprend pas les subroutines. Pourquoi?

    Merci d'avance

  2. #2
    Membre régulier
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Août 2008
    Messages
    57
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2008
    Messages : 57
    Points : 91
    Points
    91
    Par défaut
    PArce que les SUBROUTINE doivent être écrites après le programme principal, donc après le END PROGRAM.

    Bon courage

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Octobre 2017
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : Santé

    Informations forums :
    Inscription : Octobre 2017
    Messages : 6
    Points : 5
    Points
    5
    Par défaut
    Merci de ta réponse. En effet, erreur d'inattention de ma part, j'ai écrit trop vite. J'arrive à compiler mais j'ai cependant cette erreur:

    *** Error in `./testf': malloc(): memory corruption: 0x000000000072cfc0 ***

    Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

    Backtrace for this error:


    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
     
     
     program fft2
     implicit none
     integer, parameter :: N=10,M=10,S=1
     integer :: i,j
     complex :: A(N,M)
     
     do i=1,M
     do j=1,N
     A(i,j)=1.
     end do 
     end do
     
     call ft2d(N,M,A,S)
     
    end program fft2
     
      subroutine ft2d(n1,n2,cp,isig)
        implicit none
        integer :: n1,n2,isig,i1,i2
        complex :: cp(n1,n2),cw(n2)
        external fork
     
        do i2= 1,n2
          call fork(n1,cp(1,i2),isig)
        end do
     
        do i1= 1,n1
          do i2= 1,n2
            cw(i2)= cp(i1,i2)
          end do
          call fork(n2,cw,isig)
          do i2= 1,n2
            cp(i1,i2)= cw(i2)
          end do
        end do
        print*,cp
        return
      end subroutine ft2d
     
     
      subroutine fork(lx,cx,isig)
     
        implicit none
        integer :: lx,isig,i,j,l,m,istep
        complex :: cx(lx),carg,cexp,cw,ctemp
        real :: pii,sc
        pii= 4.*atan(1.)
     
        j= 1
        sc= sqrt(1./lx)
        do i= 1,lx
          if(i <= j) then
            ctemp= cx(j)*sc
            cx(j)= cx(i)*sc
            cx(i)= ctemp
          end if
          m= lx/2
          do while (m >= 1 .and. j > m)
            j= j-m
            m= m/2
          end do
          j= j+m
        end do
        l= 1
        do while (l < lx)
          istep= 2*l
          do m= 1,l
            carg= cmplx(0.,1.)*(pii*isig*(m-1))/l
            cw= cexp(carg)
            do i= m,lx,istep
              ctemp= cw*cx(i+l)
              cx(i+l)= cx(i)-ctemp
              cx(i)= cx(i)+ctemp
            end do
          end do
          l= istep
        end do
        return
      end subroutine fork
    Comment la résoudre?

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 488
    Points : 593
    Points
    593
    Par défaut
    Bonjour,

    Citation Envoyé par jimino Voir le message
    J'arrive à compiler mais j'ai cependant cette erreur:

    *** Error in `./testf': malloc(): memory corruption: 0x000000000072cfc0 ***

    Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

    Backtrace for this error:


    Comment la résoudre?
    En compilant avec le plus d'options de débogage possible. par exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    gfortran -ffpe-trap=invalid,zero,overflow -fbounds-check -g3 -O0 -fbacktrace prog.f90 -o prog
    Ce qui permet d'obtenir à l'exécution:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    ./prog
    At line 73 of file test.f90
    Fortran runtime error: Array reference out of bounds for array 'cx', upper bound of dimension 1 exceeded (11 > 10)
     
    Backtrace for this error:
      + function fork_ (0x40177E)
        at line 73 of file prog.f90
      + function ft2d_ (0x400C8D)
        at line 25 of file prog.f90
      + in the main program
        at line 17 of file prog.f90
      + /lib64/libc.so.6(__libc_start_main+0xfd) [0x3cf1e1ed1d]

Discussions similaires

  1. programme pour calculer la date
    Par zoheir13 dans le forum Delphi
    Réponses: 3
    Dernier message: 05/05/2007, 19h33
  2. Recherche langage et logiciel pour programme de calcul
    Par guismoman33 dans le forum Basic
    Réponses: 8
    Dernier message: 01/02/2007, 14h04
  3. Programme de calcul d'une factorielle
    Par hassen_I3 dans le forum Assembleur
    Réponses: 1
    Dernier message: 14/12/2006, 18h35
  4. comment faire un programme qui calcul la somme ?
    Par jahjouna dans le forum C++
    Réponses: 18
    Dernier message: 13/12/2006, 00h33
  5. Algo de calcul de FFT
    Par djlex03 dans le forum Traitement du signal
    Réponses: 15
    Dernier message: 02/08/2002, 17h45

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