Am I using interfaces in Fortran correctly?

  • Comp Sci
  • Thread starter ASGtFT
  • Start date
  • Tags
    Fortran
In summary, the conversation is about a problem with compiling files in Fortran using the NAG Fortran Compiler Release 5.2. The error occurs when trying to compile a file called 'subroutines.f90' which imports a module called 'test_mod'. The module compiles correctly and its code is provided. The individual is unsure if they are using the correct code or if there is something wrong. They are not a Fortran programmer and are asking for clarification on what they are trying to accomplish.
  • #1
ASGtFT
10
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
  • #2
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?
 

1. What is an interface in Fortran?

An interface in Fortran is a set of definitions that allows a program to communicate with other programs or libraries. It specifies the input and output variables, data types, and calling conventions for a particular routine or procedure.

2. How do I know if I am using interfaces correctly in Fortran?

You can ensure that you are using interfaces correctly in Fortran by carefully defining the interface for each routine or procedure, including all necessary input and output variables and their data types, and following the correct calling conventions. It is also important to test your program thoroughly to ensure that it is functioning as expected.

3. What are the benefits of using interfaces in Fortran?

Using interfaces in Fortran allows for easier communication between different parts of a program or between different programs. It also helps to avoid errors and ensure that all variables and data types are consistent throughout the program.

4. Can interfaces be used in all versions of Fortran?

Interfaces are a standard feature in modern versions of Fortran, such as Fortran 90 and above. However, they may not be available in older versions of the language.

5. Are there any common mistakes to avoid when using interfaces in Fortran?

One common mistake to avoid when using interfaces in Fortran is not properly defining the interface for each routine or procedure. This can lead to errors and unexpected results. It is also important to make sure that all variables and data types are consistent between the interface and the actual routine or procedure.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Nuclear Engineering
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
Back
Top