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
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 3K views
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:
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.