utility to replace "end" with "end subroutine foo"



Has anyone written a utility to replace "end" statements with "end
program/subroutine/function" statements as appropriate? When I use
someone else's Fortran code one of the first things I want to do is
put it in a module, but this does not work if plain "end" statements
are present.

.