Showing results for 
Search instead for 
Did you mean: 

Issue with calling function



I am trying to call a function to my program. The function name is poisson and it has 3 variables. I put together a shorter version of my code(bellow) using the same setup and it still won't work. What am I doing wrong?


Thanks so much!


module f_module
    implicit none


 function poisson(rho,dx,n_x) result(X)
    implicit none
    integer :: i
    real, intent(in) :: dx,n_x
    real, dimension(n_x) , intent(in) :: rho
    real, dimension(n_x) :: X
    do i=2,n_x
    end do

end function poisson

end module f_module


program test

implicit none 

  real :: dx,n_x, pi,L, i, beta
    real, dimension(n_x,1) :: rho
    real, dimension(1,n_x) ::  x,E





dx= L/n_x

do i=1,n_x


end do

E= poisson(rho,dx,n_x)

print*, "The field is", E

end program test

0 Kudos
3 Replies
Black Belt

Your program has many errors.

Your program has many errors, and you would do well to read each syntax error reported by the compiler and consult a Fortran text to understand the nature of that error.

Here is a modified version that can be compiled and run. Please check it to see if the results are correct.

    Module f_module
      Implicit None
      Function poisson(rho, dx, n_x) Result (x)
        Implicit None
        Integer :: i, n_x
        Real, Intent (In) :: dx
        Real, Dimension (n_x), Intent (In) :: rho
        Real, Dimension (n_x) :: x

        x(1) = -0.5*rho(1)*dx
        Do i = 2, n_x
          x(i) = x(i-1) - 0.5*(rho(i-1)+rho(i))*dx
        End Do
      End Function poisson
    End Module f_module
    Program test
      Use f_module
      Implicit None
      Integer, Parameter :: n_x = 20
      Integer :: i
      Real :: dx, pi, l, beta
      Real, Dimension (n_x) :: rho, e

      pi = 3.1415927
      beta = 0.01
      l = sqrt(3*pi**2/beta)
      dx = l/n_x
      Do i = 1, n_x
        rho(i) = i
      End Do
      e = poisson(rho, dx, n_x)
      Print *, 'The field is', e
    End Program test


0 Kudos

Thanks so much for the replay

Thanks so much for the replay.  Your code is very help full.

Any specific text you could recommend me?


 I am using "Guide to FORTRAN 2003" by Brainerd, and I think it does not much the Intel compiler perfectly. 


0 Kudos
Black Belt

Quote:Erez K. wrote:

Erez K. wrote:

 I am using "Guide to FORTRAN 2003" by Brainerd, and I think it does not much the Intel compiler perfectly. 

That is a good companion book, and it is actually good that it does not match any particular compiler. At this stage, you need to get a good grasp of the standard features of Fortran. The code that you write should be portable, so that you can compile it with alternative compilers and use their wording of error messages to understand the nature of the errors.

0 Kudos