forked from SPECFEM/specfem2d
-
Notifications
You must be signed in to change notification settings - Fork 1
/
replace_use_mpi_with_include_mpif_dot_h.pl
executable file
·79 lines (55 loc) · 2.49 KB
/
replace_use_mpi_with_include_mpif_dot_h.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl
#
# replace "use mpi" with include "mpif.h" in all source files;
# also swap it with the "implicit none" line, which must be located after
# in the case of "use mpi" but before in the case of include "mpif.h"
#
# Author : Dimitri Komatitsch, EPS - Harvard University, January 1998 and CNRS Marseille, France, July 2013
#
#
# first clean trailing white spaces in all f90 files in the src/ sub-directories
#
@objects = `ls src/*/*.f90 src/*/*.F90`;
foreach $name (@objects) {
chop $name;
# change tabs to white spaces
system("expand -2 < $name > _____dummy08_____");
$f90name = $name;
print STDOUT "Cleaning trailing white spaces in $f90name ...\n";
open(FILE_INPUT,"<_____dummy08_____");
open(FILEF90,">$f90name");
# open the input f90 file
while($line = <FILE_INPUT>) {
# suppress trailing white spaces and carriage return
$line =~ s/\s*$//;
print FILEF90 "$line\n";
}
close(FILE_INPUT);
close(FILEF90);
}
#
# then perform the replacement in all f90 and F90 files in the src/ sub-directories
#
@objects = `ls src/*/*.f90 src/*/*.F90`;
foreach $name (@objects) {
chop $name;
# change tabs to white spaces
system("expand -2 < $name > _____dummy08_____");
$f90name = $name;
print STDOUT "Replacing 'use mpi' (if any) in $f90name ...\n";
open(FILE_INPUT,"<_____dummy08_____");
open(FILEF90,">$f90name");
# to read the whole file in the variable instead of a single line
undef $/;
# read the whole input file
$whole_file = <FILE_INPUT>;
# make the replacement (we look for "use mpi", "use:: mpi", "use :: mpi" etc.; we also handle the case of a #endif for the preprocessor between the two lines)
$whole_file =~ s/\n\s*use\s*mpi\s*\n*\s*implicit\s*none\s*\n/\n\n implicit none\n\n include 'mpif.h'\n\n/og;
$whole_file =~ s/\n\s*use\s*::\s*mpi\s*\n*\s*implicit\s*none\s*\n/\n\n implicit none\n\n include 'mpif.h'\n\n/og;
$whole_file =~ s/\n\s*use\s*mpi\s*\n*\s*#endif\s*\n*\s*implicit\s*none\s*\n/\n\n#endif\n\n implicit none\n\n include 'mpif.h'\n\n/og;
$whole_file =~ s/\n\s*use\s*::\s*mpi\s*\n*\s*#endif\s*\n*\s*implicit\s*none\s*\n/\n\n#endif\n\n implicit none\n\n include 'mpif.h'\n\n/og;
print FILEF90 "$whole_file";
close(FILE_INPUT);
close(FILEF90);
}
system("rm -f _____dummy08_____");