NCEPLIBS-bufr icon indicating copy to clipboard operation
NCEPLIBS-bufr copied to clipboard

use implicit none in all Fortran codes

Open edwardhartnett opened this issue 2 years ago • 3 comments

implicit none guards against one of the most common programming bugs: mispelling a varaible.

When we misspell a fortran variable, and a new one is created, it's extremely easy to introduce a bug. For example:

C           Store this message into MODULE MSGMEM.

            ICT = ICT + 1
            IF ( ( NDXM + ICT ) .GT. MXDXM ) GOTO 902
            IPDXM(NDXM+ICT) = LDXM + 1
            LMEM = NMWRD(MGWA)
            IF ( ( LDXM + LMEM ) .GT. MXDYW ) GOTO 903
            DO J = 1, LMEM
              MDX(LDXM+J) = MGWA(J)
            ENDDO
            LDXM = LDXM + LMEM

Where is the bug in this code? If it's obvious to you, it certainly is not to me, nor will it be to most programmers.

The good news is that the Fortran compiler will tell us exactly where the bug is, and will refuse to let us build the code at all, until we fix it. All we need to do is use implicit none to get this fantastic, automatic, and infallible bug finder.

edwardhartnett avatar Feb 18 '23 08:02 edwardhartnett