Fortran Subroutine Extractor
2018 July 15

I've been working on a fortran codebase with a lot of code duplicated between subroutines, so I came up with this little bash function using awk to extract subroutines, so I can find the difference between them.

# $1 - complete exact name of subroutine, not a partial name or wildcard
# $2 - name of the file to extract subroutine from
function extract_f_sub() {
    awk "/subroutine $1\(/,/end subroutine/" $2
}

The awk in the function dumps the text from a file between the 2 given deliminators to standard output. In this case we look for the begining of the subroutine, then find the ending block of the subroutine.

I would use this to extract 2 similar subroutines to files, and then compare them using vimdiff. This allowed me to quickly spot the similarlarities between them and remove the duplicated code.

*****
Written by Henry J Schmale on 2018 July 15