How to Resolve Compilation Errors with Fortran 90/95 MODULEs?

  • Context: Fortran 
  • Thread starter Thread starter ted_kingdom
  • Start date Start date
  • Tags Tags
    Fortran Modules
Click For Summary

Discussion Overview

The discussion revolves around resolving compilation errors in Fortran 90/95 related to the use of MODULEs, specifically concerning the organization of FUNCTION definitions and INTERFACEs. Participants explore issues with assumed-shape arrays and module dependencies in the context of a sample program.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks help with compilation errors when defining FUNCTIONs in one module and INTERFACEs in another, presenting a sample code.
  • Another participant questions the Fortran version being used and suggests adding a 'use qwer' statement in the program, indicating potential issues with nesting modules.
  • A different participant mentions that some compilers may not accept actual numbers in arrays that are not defined with fixed sizes and recommends modifying array size declarations.
  • One participant advises using only the necessary modules in subroutines/functions for better clarity and to avoid confusion in compilers.
  • A later reply indicates that the original poster resolved their issue by removing the explicit INTERFACE in the second module, noting that the interface is automatically generated when using MODULEs.

Areas of Agreement / Disagreement

Participants express varying opinions on best practices for module usage and the specific causes of compilation errors. The discussion reflects multiple viewpoints and does not reach a consensus on the best approach to resolve the initial problem.

Contextual Notes

Limitations include the lack of clarity on which specific compilers are being referenced and the potential variability in behavior across different Fortran compilers regarding module and interface handling.

ted_kingdom
Messages
5
Reaction score
0
Hi!
I require help in writing a code where I want to put FUNCTION definitions in one module and INTERFACEs to the functions (as I use assumed-shape arrays in the functions) in another. But I get multiple errors when trying to compile. Could anyone assist me in solving this problem? Please see program below. Thanks in advance.
Code:
MODULE qwer
	CONTAINS
	PURE FUNCTION BMatVect(ShapeFuncDeriv,JacobiInv)
		IMPLICIT NONE
       Real, Intent(IN) :: JacobiInv(:,:),ShapeFuncDeriv(:,:)
       Real::BMatVect(size(ShapeFuncDeriv,1),size(ShapeFuncDeriv,2))
		BMatVect = Matmul(JacobiInv, ShapeFuncDeriv)
	END FUNCTION BMatVect
END MODULE qwer

MODULE ty
	USE qwer
	INTERFACE BMatVect_function
		PURE FUNCTION BMatVect(ShapeFuncDeriv,JacobiInv)
		 IMPLICIT NONE
       Real, Intent(IN) :: JacobiInv(:,:),ShapeFuncDeriv(:,:)
       Real::BMatVect(size(ShapeFuncDeriv,1),size(ShapeFuncDeriv,2))
		END FUNCTION BMatVect 
	END INTERFACE BMatVect_function
END MODULE ty

PROGRAM MyTest
	USE ty
	IMPLICIT NONE
	REAL :: A(2,2) = reshape((/1,1,1,1/),(/2,2/)), &
                   B(2,4) = reshape((/-0.5,-0.5,0.5,0.0,0.0,0.0,0.0,0.5/),(/2,4/)), &
	           C(2,4)
	C = BMatVect (B, A)
	PRINT*, C(1,:)
	PRINT*, C(2,:)
END PROGRAM MyTest
 
Last edited:
Technology news on Phys.org
What FORTRAN are you using?

Have you tried adding a 'use qwer' in the program? Not sure if that's the problem but maybe you can't nest things.

http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlf101l.doc%2Fxlflr%2Fmodproc.htm

Lastly, can you change your use of the spoiler tag to the the code tag? The spoiler is used for hints and makes your program listing flicker on and off with mouse movement.

Some more best practice comments on module usage:

http://stackoverflow.com/questions/...-modules-subroutines-and-functions-in-fortran
 
Last edited by a moderator:
Some compilers don't like you putting actual numbers in arrays which haven't been defined as a fixed size. I would try doing something with declaration of in quer by removing the 1 and 2 when determining array size.
Also, as good practice only use the modules that that sub/function/program requires, ideally with 'only' statements for robustness. Some compilers get confused if there are multiple routes to variables etc through different modules. This will also assist should decided to vectorise your code.
 
jedishrfu, Thanks a lot for the link to Stackoverflow! It helped. It turns out that when you use MODULE the interface is being generated automatically, so the program knows it. Ergo, the problem was in my second MODULE 'ty' with explicit INTERFACE. I got rid of it. Now everything runs smoothly. Thanks again!:thumbs:

P.S.: I already use CODE tag. If you mean vice versa, SPOILER tag doesn't hide anything for me.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
16K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 16 ·
Replies
16
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K