Am I using interfaces in Fortran correctly?

  • Context: Comp Sci 
  • Thread starter Thread starter ASGtFT
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary
SUMMARY

The discussion centers on a compilation error encountered while using the NAG Fortran Compiler Release 5.2 with interfaces in Fortran. The error arises from the subroutine 'my_sub' in 'subroutines.f90', which conflicts with the interface defined in the 'test_mod' module. The issue is due to the naming conflict between the subroutine and the interface, which leads to ambiguity during compilation. To resolve this, the user must rename either the subroutine or the interface to eliminate the conflict.

PREREQUISITES
  • Understanding of Fortran programming language syntax
  • Familiarity with NAG Fortran Compiler Release 5.2
  • Knowledge of Fortran modules and interfaces
  • Basic debugging skills in Fortran
NEXT STEPS
  • Research Fortran module and interface best practices
  • Learn about naming conventions in Fortran to avoid conflicts
  • Explore error handling and debugging techniques in NAG Fortran Compiler
  • Study examples of subroutine and module interactions in Fortran
USEFUL FOR

Fortran programmers, software developers working with scientific computing, and anyone troubleshooting compilation issues in Fortran using NAG Fortran Compiler.

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?
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K