Hi all, since it is mandatory to declare all subroutines as "external" in Fortran, is it possible for Modules to have subroutines? I'm unable to declare the subroutine external inside the module itself, nor in the program which is using it. Not declaring it external at all results in the following compilation error: /net/users/csg/csg4035/master/workdir/src/main.F:97: undefined reference to `__grid_MOD_readgrid' (the module is here is named "grid", the subroutine "readgrid" ) Thanks, Leo
On Sep 30, 2010, at 9:31 AM, Leo van Kampenhout wrote:
Hi all,
since it is mandatory to declare all subroutines as "external" in Fortran, is it possible for Modules to have subroutines? I'm unable to declare the subroutine external inside the module itself, nor in the program which is using it.
What happens when you try to declare it external in the "program which is using it" (I assume you mean subroutine that is using it). Barry
Not declaring it external at all results in the following compilation error:
/net/users/csg/csg4035/master/workdir/src/main.F:97: undefined reference to `__grid_MOD_readgrid'
(the module is here is named "grid", the subroutine "readgrid" )
Thanks, Leo
On 30/09/10 15:31, Leo van Kampenhout wrote:
Hi all,
since it is mandatory to declare all subroutines as "external" in Fortran, is it possible for Modules to have subroutines? I'm unable to declare the subroutine external inside the module itself, nor in the program which is using it. Not declaring it external at all results in the following compilation error:
/net/users/csg/csg4035/master/workdir/src/main.F:97: undefined reference to `__grid_MOD_readgrid'
(the module is here is named "grid", the subroutine "readgrid" )
Thanks, Leo
If you put your subroutine in a module, it should not be declared external. You can directly call it from within the module itself. When calling it inside any other module/program you need to add "use grid" before the "implicit none". Putting subroutines inside a module is highly recommended as it automatically provides an explicit interface so that the compiler can check the arguments in your subroutine call. Cheers Stephan
Declaring it external in the program/subroutine that is using the module results in main.F:65.43: external gridtest Error: Cannot change attributes of USE-associated symbol at (1) Thanks, Leo 2010/9/30 Stephan Kramer <[email protected]>
On 30/09/10 15:31, Leo van Kampenhout wrote:
Hi all,
since it is mandatory to declare all subroutines as "external" in Fortran, is it possible for Modules to have subroutines? I'm unable to declare the subroutine external inside the module itself, nor in the program which is using it. Not declaring it external at all results in the following compilation error:
/net/users/csg/csg4035/master/workdir/src/main.F:97: undefined reference to `__grid_MOD_readgrid'
(the module is here is named "grid", the subroutine "readgrid" )
Thanks, Leo
If you put your subroutine in a module, it should not be declared external. You can directly call it from within the module itself. When calling it inside any other module/program you need to add "use grid" before the "implicit none".
Putting subroutines inside a module is highly recommended as it automatically provides an explicit interface so that the compiler can check the arguments in your subroutine call.
Cheers Stephan
On 30/09/10 23:09, Leo van Kampenhout wrote:
Declaring it external in the program/subroutine that is using the module results in
main.F:65.43: external gridtest Error: Cannot change attributes of USE-associated symbol at (1)
Thanks, Leo
Yes, as I said before :) - module subroutines should *not* be declared external. You do not need that line. Cheers Stephan
2010/9/30 Stephan Kramer <[email protected] <mailto:[email protected]>>
On 30/09/10 15:31, Leo van Kampenhout wrote:
Hi all,
since it is mandatory to declare all subroutines as "external" in Fortran, is it possible for Modules to have subroutines? I'm unable to declare the subroutine external inside the module itself, nor in the program which is using it. Not declaring it external at all results in the following compilation error:
/net/users/csg/csg4035/master/workdir/src/main.F:97: undefined reference to `__grid_MOD_readgrid'
(the module is here is named "grid", the subroutine "readgrid" )
Thanks, Leo
If you put your subroutine in a module, it should not be declared external. You can directly call it from within the module itself. When calling it inside any other module/program you need to add "use grid" before the "implicit none".
Putting subroutines inside a module is highly recommended as it automatically provides an explicit interface so that the compiler can check the arguments in your subroutine call.
Cheers Stephan
Thank you Stephan, it is working now. I forgot to add the correct files to the makefile, for I put the module in a seperate file (grid.F). The correct makefile rule for the main program (main.F) is: main: grid.o main.o chkopts -${FLINKER} -o main grid.o main.o ${PETSC_KSP_LIB} ${RM} main.o grid.o Thanks again. Leo 2010/10/1 Stephan Kramer <[email protected]>
On 30/09/10 23:09, Leo van Kampenhout wrote:
Declaring it external in the program/subroutine that is using the module results in
main.F:65.43: external gridtest Error: Cannot change attributes of USE-associated symbol at (1)
Thanks, Leo
Yes, as I said before :) - module subroutines should *not* be declared external. You do not need that line.
Cheers Stephan
2010/9/30 Stephan Kramer <[email protected] <mailto:[email protected]>>
On 30/09/10 15:31, Leo van Kampenhout wrote:
Hi all,
since it is mandatory to declare all subroutines as "external" in Fortran, is it possible for Modules to have subroutines? I'm unable to declare the subroutine external inside the module itself, nor in the program which is using it. Not declaring it external at all results in the following compilation error:
/net/users/csg/csg4035/master/workdir/src/main.F:97: undefined reference to `__grid_MOD_readgrid'
(the module is here is named "grid", the subroutine "readgrid" )
Thanks, Leo
If you put your subroutine in a module, it should not be declared external. You can directly call it from within the module itself. When calling it inside any other module/program you need to add "use grid" before the "implicit none".
Putting subroutines inside a module is highly recommended as it automatically provides an explicit interface so that the compiler can check the arguments in your subroutine call.
Cheers Stephan
participants (3)
-
Barry Smith -
Leo van Kampenhout -
Stephan Kramer