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

Superfluous if blocks due to FORTRAN 66 do statement semantics #37

Open
ivan-pi opened this issue Feb 15, 2022 · 0 comments
Open

Superfluous if blocks due to FORTRAN 66 do statement semantics #37

ivan-pi opened this issue Feb 15, 2022 · 0 comments

Comments

@ivan-pi
Copy link
Member

ivan-pi commented Feb 15, 2022

Here's a section of code from rwupdt:

        do j = 1, n
            rowj = w(j)
            jm1 = j - 1

            ! apply the previous transformations to
            ! r(i,j), i=1,2,...,j-1, and to w(j).

            if (jm1 >= 1) then
                do i = 1, jm1
                    temp = Cos(i)*r(i, j) + Sin(i)*rowj
                    rowj = -Sin(i)*r(i, j) + Cos(i)*rowj
                    r(i, j) = temp
                end do
            end if

As you may notice for j = 1, jm1 = 0, meaning the if loop surrounding the inner do loop is totally superfluous.

As @arjenmarkus kindly explained in his reply at Discourse, this is a "legacy" issue related to Fortran 66 DO semantics. Edit: See Section 7.1.2.8 in the ANSI X 3.9 Fortran 66 standard. The requirement to surround the DO loop with an IF block came from the line:

At time of execution of the DO statement, m1, m2, and m3 must be greater than zero.

The MINPACK source code in the present state remains full of this pattern. Maybe CamFort, plusFORT, or fpt have a tool which could fix this?

It would be a good idea to start a document or wiki- page collecting such legacy "gotchas" if we plan to do more "modernization".

@ivan-pi ivan-pi changed the title Superfluous if due to one pass do-loops Superfluous if blocks due to FORTRAN 66 do statement semantics Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant