1 |
heimbach |
1.1 |
#!/bin/bash |
2 |
|
|
file=$1 |
3 |
|
|
wantMPI=$2 |
4 |
|
|
needMpi=false |
5 |
|
|
cp ${file} ${file}.tmp |
6 |
|
|
for includeFile in `egrep "\# *include *\"" ${file} | sed 's/# *include *\"\(.*\)\"/\1/' | sort | uniq` |
7 |
|
|
do |
8 |
|
|
modFileName=${includeFile%.h}_mod.h |
9 |
|
|
if [ -f ${modFileName} ] |
10 |
|
|
then |
11 |
|
|
echo "s/\# *include *\(\"${includeFile}\"\)/\#include \"${modFileName}\"/" > temp.sed |
12 |
|
|
# add in the mpi include here since we filtered it from the module |
13 |
|
|
if [ "$modFileName" == "EESUPPORT_mod.h" ] |
14 |
|
|
then |
15 |
|
|
needMpi=true |
16 |
|
|
fi |
17 |
|
|
cat ${file}.tmp | sed -f temp.sed | sed 's/IMPLICIT NONE//' | sed 's/implicit none//' > ${file}.tmp.1 |
18 |
|
|
mv ${file}.tmp.1 ${file}.tmp |
19 |
|
|
fi |
20 |
|
|
done |
21 |
|
|
if [ "$needMpi" == "true" -a -n "$wantMPI" ] |
22 |
|
|
then |
23 |
|
|
cat > cb2mUseMPI.awk <<EOF |
24 |
|
|
BEGIN { useSeq = 0; inSR=0} |
25 |
|
|
/^ *SUBROUTINE/ { inSR=1 } |
26 |
|
|
/^#include / { if (inSR == 1) { useSeq = 1 ; print } } |
27 |
|
|
/^#ifdef/ || /^#endif/ { if (useSeq == 1) print } |
28 |
|
|
!/^#include / && !/^#ifdef/ && !/^#endif/ { if (useSeq == 1) { printf("#include \"mpif.h\"\n"); useSeq=0; inSR=0 } } |
29 |
|
|
{if (useSeq == 0) print } |
30 |
|
|
END {} |
31 |
|
|
EOF |
32 |
|
|
awk -f cb2mUseMPI.awk ${file}.tmp > ${file}.tmp.1 |
33 |
|
|
mv ${file}.tmp.1 ${file}.tmp |
34 |
jmc |
1.2 |
rm -f cb2mUseMPI.awk |
35 |
heimbach |
1.1 |
fi |
36 |
|
|
mv ${file}.tmp ${file%.F}_cb2m.FF90 |