Wednesday, 15 May 2013

fortran90 - Where to put `implicit none` in Fortran -



fortran90 - Where to put `implicit none` in Fortran -

do need set implicit none within every function , subroutine?

or plenty set @ origin of module containing these functions , subroutines?

or plenty set @ origin of programme using these modules?

from observation of other's working code, implicit none included in these places. not sure if done redundantly because removing implicit none subroutines still compiled , produced same output.

by way, using gfortran fortran 90.

the implicit statement (including implicit none) applies scoping unit. such thing defined as

block construct, derived-type definition, interface body, programme unit, or subprogram, excluding nested scoping units in it

this "excluding nested scoping units in it" suggests may necessary/desirable have implicit none in each function , subroutine (collectively, procedures) defined in module. however, within procedures contained within module there default mapping based on host scoping unit. so, implicit none in module isn't necessary have in contained procedures.

this host scoping unit rule applies as internal programs. means implicit none in main programme covers procedures contained in it; , same applies internal programs of module procedures. block constructs see also, , implicit statement isn't allowed within 1 of these.

however, external functions/subroutines not inherit implicit behaviour programme or module, , modules don't inherit programs/other modules use them. makes sense implicit typing must known @ compile time , defined regardless of ultimate use.

further, 1 cannot do

implicit none utilize somemodule end programme

an implicit statement must follow use statements.

this host scoping unit rule notably doesn't apply interface bodies. ianh's answer motivates exception, it's of import plenty thing re-stress. has caused much confusion.

module mod implicit none interface subroutine external_sub() ! default implicit typing rules apply here unless there implicit ! statement, such implicit none. module aren't in forcefulness here. end subroutine end interface end module

regarding test of removing implicit none subroutine: if code valid implicit none must valid , identical without statement. entities must explicitly declared in former case, no implicit rules applied in latter.

fortran fortran90 gfortran

No comments:

Post a Comment