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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

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