#!/bin/bash

# Undoes the changes that are automatically made to the source files when multiple special
# modules are used. See target special_preps in Makefile.src.

for file in $1; do
    sed -e '/module  *procedure/ ! s/^\( *module  *\)[a-zA-Z0-9_]* */\1Special/' \
        -e 's/^\( *endmodule  *\)[a-zA-Z0-9_]* *$/\1Special/' \
        -e 's/[a-zA-Z0-9_]*\.inc/special_dummies.inc/' \
        -e 's/namelist *\/[a-zA-Z0-9_]*[a-zA-Z0-9]_\([ir][a-z]*_pars\)/namelist \/special_\1/' \
        -e 's/NML *= *[a-zA-Z0-9_]*_\([a-z][a-z]*_pars\)/NML=special_\1/' $file > $file.tmp

    mv -f $file.tmp $PENCIL_HOME/src/$file
done
