cphyc / fortran-linter

A simple fortran syntax checker, including automatic fixing of the code.
Other
31 stars 12 forks source link

Replace end with end subroutine foo, end function foo, end program foo, end module foo as appropriate #111

Open Beliavsky opened 3 weeks ago

Beliavsky commented 3 weeks ago

I would like a bare end statement at the end of a subroutine, function, program, or module to be replaced by a statement with end followed by the name. For example, the linter leaves the code

module m
    implicit none
contains
    real function twice(x)
        real, intent(in) :: x
        twice = 2 * x
    end

    subroutine sub(x, y)
        implicit none
        real, intent(in) :: x
        real, intent(out) :: y
        y = 2 * x + 4.5
    end
end

program main
use m
implicit none
real :: x, y
x = 10.0
call sub(x, y)
print *, y
print *, twice(y)
end

I would like it to be changed to

module m
    implicit none
contains
    real function twice(x)
        real, intent(in) :: x
        twice = 2 * x
    end function twice

    subroutine sub(x, y)
        implicit none
        real, intent(in) :: x
        real, intent(out) :: y
        y = 2 * x + 4.5
    end subroutine sub
end module m

program main
use m
implicit none
real :: x, y
x = 10.0
call sub(x, y)
print *, y
print *, twice(y)
end program main
cphyc commented 3 weeks ago

Can you try the content of #112?