Reputation: 685
I am learning Fortran, specifically modules. I wrote this simple code that should calculate the derivative of the sine function:
module constants
real, parameter::x=3.14
real, parameter::h=0.0001
end module constants
module derivata1
contains
real function der1(n)
use constants
real::der
der=(sin(x+h)-sin(x))/h
end function der1
end module derivata1
program derivate
use constants
use derivata1
implicit none
real der1
print *, der1(x)
end program derivate
I get the following error in gfortran.
der2.f90:40.10:
real der1
1
der2.f90:38.5:
use derivata1
2
Error: Symbol 'der1' at (1) conflicts with symbol from module 'derivata1', use-associated at (2)
der2.f90:44:15:
print *, der1(x)
1
Error: Type mismatch in argument ‘n’ at (1); passed REAL(4) to INTEGER(4)
I followed this and this posts, but with no result.
Where is my error?
Upvotes: 0
Views: 13872
Reputation: 60008
You should use IMPLICIT NONE
in all your compilation units.
Inside the module you have no IMPLICIT NONE
so the argument n
is implicitly integer because it is not declared to be otherwise.
Also, you should not do any
real der1
in the program where you want to use function der1
from a module, because that makes the function to be declared external. The compiler then thinks you are calling some other function der1
which is somewhere else, but not in that module.
Upvotes: 1