Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software Development Tools (Compilers, Debuggers, Profilers & Analyzers)
- Intel® Fortran Compiler
- Issue with calling function

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##

Erez_K_1

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-02-2016
08:25 AM

Issue with calling function

Hello,

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

contains

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

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

implicit none

real :: dx,n_x, pi,L, i, beta

real, dimension(n_x,1) :: rho

real, dimension(1,n_x) :: x,E

pi=3.14

beta=0.01

n_x=20

L=sqrt(3*pi**2/beta)

dx= L/n_x

do i=1,n_x

rho(I,1)=i

end do

E= poisson(rho,dx,n_x)

print*, "The field is", E

end program test

3 Replies

Highlighted
##

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-02-2016
08:40 AM

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 Contains 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

Highlighted
##

Erez_K_1

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-02-2016
04:25 PM

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.

Highlighted
##

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-02-2016
05:53 PM

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.

For more complete information about compiler optimizations, see our Optimization Notice.