Comp Sci Am I using interfaces in Fortran correctly?

  • Thread starter Thread starter ASGtFT
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The user is encountering a compilation error in Fortran when trying to use interfaces with the NAG Fortran Compiler Release 5.2. The error message indicates an issue with importing the subroutine 'my_sub' from the module 'test_mod'. The provided code shows that the subroutine in 'subroutines.f90' is named the same as the one defined in the module, which may cause confusion. Clarification is sought on whether the code is correct or if there is a fundamental issue with the naming and usage of the subroutine. Proper naming conventions and understanding of module interfaces in Fortran are essential for resolving this compilation problem.
ASGtFT
Messages
10
Reaction score
0
I'm having problems compiling files with interfaces in Fortran. My compiler is NAG Fortran Compiler Release 5.2. I get this error:

-------------------------------------
Error: subroutines.f90, line 2: USE TEST_MOD in program-unit MY_SUB imports
symbol MY_SUB
detected at TEST_MOD@<end-of-statement
---------------------------------------

This happens when I try to compile this file, called 'subroutines.f90':

Code:
subroutine my_sub (a)
  use test_mod
  real a
  print *, a
end subroutine

The mod file 'test_mod' it refers to compiles correctly, and its code is here:

Code:
module test_mod interface
  subroutine my_sub (a)
    real a
  end subroutine
end interface
end module

END

Am I using the correct code, or is something wrong here? Thanks!
 
Physics news on Phys.org
I'm not really a Fortran programmer, but it seems like you're importing a subroutine called my_sub into another one of the same name. What exactly are you trying to do?
 
Back
Top