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

  • Thread starter Thread starter ted_kingdom
  • Start date Start date
  • Tags Tags
    Fortran Modules
AI Thread Summary
The discussion focuses on resolving compilation errors in Fortran 90/95 when using MODULEs for function definitions and INTERFACEs. The user encountered multiple errors while trying to separate FUNCTION definitions and INTERFACEs into different modules. Suggestions included ensuring the correct use of the 'use' statement and avoiding unnecessary explicit INTERFACE declarations, as MODULEs automatically generate interfaces. The user successfully resolved the issue by removing the explicit INTERFACE in the second MODULE, leading to smooth compilation. Best practices for module usage, such as using 'only' statements, were also highlighted to prevent confusion in variable access.
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Replies
5
Views
15K
Replies
4
Views
2K
Replies
1
Views
2K
Replies
16
Views
6K
Replies
7
Views
3K
Back
Top