Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28456 Discussions

How can I call the subroutine in a module twice?

hadesmajesty
Beginner
454 Views

How can I call the subroutine in a module twice?

I have a module as

Module name1

Contains


Subroutine name2()

End Subroutine name2


Subroutine name3()

Callname2()

Call name2()

End Subroutine name3


End Module name1

I try to call Subroutine name2() in Subroutine name3 twice as in above code, but there is an linking error, saying that name2 is an external function. However, if name2 is called one time only, the code can work. Why is that? Thanks.

Actually, in the code I am using 'Call name2()', rather than 'Call subroutine name2()'I've made a mistake in the previous post. Sorry about that.

Since my IDE is not in English, I cannot give the exact error message here, but it means that the code can not be linked to the subroutine name2()

0 Kudos
3 Replies
DavidWhite
Valued Contributor II
454 Views
Your code to call the subroutine is in error.

You should only have

Call name2()

Otherwise, you are trying to call an unknown subroutine called subroutinename2() - Fortran ignores the blanks in the name.

0 Kudos
bendel_boy1
Beginner
454 Views
I think you may need to post more of the actual code - and perhaps also the exact error message.
0 Kudos
John4
Valued Contributor I
454 Views

The "Call Subroutine name2()" part is wrong. It should only be "call name2()".

Had the code been in free source form, a syntax error message would have shown you that only one word is expected between the "Call" keyword and the "(", so that "name2" is considered redundant.

With code in fixed source form, spaces are ignored, so the compiler assumes there's a subroutine called Subroutinename2. The fact that the code compiles, doesn't mean that it works ---since the linker will have a hard time trying to find the symbol SUBROUTINENAME2 (or NAME3_MP_SUBROUTINENAME2, or something like that).

0 Kudos
Reply