3 # Script to replace all incorrect "include" statements in WRF trunk. For user-defined files,
4 # include statements must use quotes, not brackets, according to the C standard:
7 # #include <model_data_order.inc>
10 # #include "model_data_order.inc"
13 # use "--search_path" to specify the search pattern for files you want to edit.
14 # - Separate different search patterns with spaces
15 # - Be sure to escape wildcard characters with a backslash!
16 # - Default is --search_path="../\*/\*.F ../\*/\*/\*.F ../\*/\*/\*/\*.F ../\*/\*/\*/\*/\*.F ../\*/\*.inc ../\*/\*/\*.f90 ../\*/\*/\*/\*.f90"
17 # use "--dryrun=yes" to do a dry run, where all the output of what would be changed is printed out, but no changes are made.
19 # Created by Michael Kavulich, November 2015
29 my $search_path = "../\*/\*.F ../\*/\*/\*.F ../\*/\*/\*/\*.F ../\*/\*/\*/\*/\*.F ../\*/\*.inc ../\*/\*/\*.f90 ../\*/\*/\*/\*.f90";
30 GetOptions
('search_path=s' => \
$search_path,
31 "dryrun:s" => \
$dryrun ) or die "\nInvalid option(s) specified, view script comments for help\n";
33 print "\nSearching for brackets in file(s): $search_path\n\n";
35 my @source_files=glob("$search_path");
40 foreach my $filename (@source_files) {
41 open (IN
, $filename) or die "Cannot open file $filename for read: $!";
45 if (grep(/#(\s*)(include|INCLUDE)(\s*)</,@lines)) {
46 print "Brackets found in file: $filename\n";
49 # print "Brackets NOT found in file: $filename\n";
54 open (OUT
, ">", $filename) or die "Cannot open file $filename for write: $!";
55 foreach my $line (@lines) {
56 if ($line =~ /#(\s*)(include|INCLUDE)(\s*)</) {
57 print "Found line with brackets: $line\n";
58 my @inc_files = split /[<>]/,$line;
59 if ($inc_files[1] =~ /<mpi.*/) {
60 print "Skipping line that contains 'mpi':\n";
63 if ( $dryrun =~ /y/i ) {
65 $linetemp =~ s/<$inc_files[1]>/\"$inc_files[1]\"/;
66 print "Changed line to: $linetemp\n";
68 $line =~ s/<$inc_files[1]>/\"$inc_files[1]\"/;
69 print "Changed line to: $line\n";
79 print "\nBrackets found in $found files.\n";
80 print "\nBrackets NOT found in $notfound files.\n";
81 print "\n$changed lines changed\n";