1

This is a fortran 90 function that I have within a main program. As you can see several variables types such as ZLAMS are not declared at the top. But gfortran 5.2 does not report any error whatsoever. If however I move this code to a separate module and then call this function in the main module all the undeclared variables report a compilation error. Why ?

REAL(kind=sp) FUNCTION ABCTEST (PHIS, LAMS, POLPHI, POLLAM)
use k_parameters,ONLY:&
   sp

REAL(KIND=SP)        LAMS,PHIS,POLPHI,POLLAM

DATA        ZRPI18 , ZPIR18  / 57.2957795 , 0.0174532925 /

SINPOL = SIN(ZPIR18*POLPHI)
COSPOL = COS(ZPIR18*POLPHI)
ZPHIS  = ZPIR18*PHIS
ZLAMS  = LAMS
IF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0
ZLAMS  = ZPIR18*ZLAMS
ARG     = COSPOL*COS(ZPHIS)*COS(ZLAMS) + SINPOL*SIN(ZPHIS)

ABCTEST = ZRPI18*ASIN(ARG)

RETURN
END FUNCTION ABCTEST
1
  • 1
    Not explicitly declaring things isn't necessarily an error condition (read about implicit declaration) but as to why your case with a module doesn't work, we'll need to see an example of that. Commented Aug 15, 2017 at 8:51

1 Answer 1

3

You must use IMPLICIT NONE at the top of each compilation unit to get such error. Otherwise, the implicit typing rules are in effect.

No other type of the implicit statement except of IMPLICIT NONE is recommended in modern Fortran. It should be used in all modern code.

Each compilation unit means every external procedure, main program and each module or submodule. Module procedures will see the module's implicit statement due to host association. The same holds for internal procedures that are controlled by the host procedure's implicit statement.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks - fast answer ! Really appreciate. What about in the module though ? I do not have implicit none in the module as well.
It is sufficient to put IMPLICIT NONE at the top of the module.
Got it. So if I put IMPLICIT NONE at the top of the module that should suffice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.