Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use implicit none in all Fortran codes #328

Closed
edwardhartnett opened this issue Feb 18, 2023 · 3 comments · Fixed by #602
Closed

use implicit none in all Fortran codes #328

edwardhartnett opened this issue Feb 18, 2023 · 3 comments · Fixed by #602
Labels
enhancement New feature or request

Comments

@edwardhartnett
Copy link
Contributor

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
Copy link
Contributor Author

I think we all agree that implicit none should be used in all new code (including tests). We will add implicit none to existing code after full testing, and as we refactor or change the code.

@edwardhartnett
Copy link
Contributor Author

@jbathegit are we adding implicit none to all codes? When I look at the code I don't see them, even in subroutines where it would be really easy to put it there.

Do you not agree with this issue?

@edwardhartnett edwardhartnett added the enhancement New feature or request label Jan 29, 2024
@jbathegit
Copy link
Collaborator

I do agree that this is a worthwhile goal, mostly for the reason you noted of more quickly finding a misspelled variable. I just haven't done any further work on this, because I've been prioritizing whatever time I have to work with NCEPLIBS-bufr on getting us to a more full level of testing, as you yourself noted above.

(And BTW, the bug in the above snippet is the misspelling MXDYW, which should be MXDXW :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants