This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
forked from geoschem/geos-chem-unittest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanRunDirs
executable file
·209 lines (185 loc) · 5.58 KB
/
cleanRunDirs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/perl -w
#------------------------------------------------------------------------------
# GEOS-Chem Global Chemical Transport Model !
#------------------------------------------------------------------------------
#BOP
#
# !MODULE: cleanRunDirs
#
# !DESCRIPTION: This Perl script removes all output files from the
# GEOS-Chem Unit Test run directories.
#\\
#\\
# !USES:
#
require 5.003; # Need this version of Perl or newer
use strict; # Force IMPLICIT NONE-style declarations
use FindBin qw/$RealBin/; # Look for perl modules
use lib $RealBin; # in the current folder
use UtUtils qw/&cleanDir
&parse/; # Get routines from module UtUtils.pm
#
# !PUBLIC MEMBER FUNCTIONS:
#
# &getDirs($)
# &cleanDir($)
# &main(@)
#
# !CALLING SEQUENCE:
# cleanRunDirs [ OPTIONS-FILENAME ]
#
# !REVISION HISTORY:
# 01 Oct 2015 - M. Sulprizio- Initial version based on cleanFiles
#EOP
#------------------------------------------------------------------------------
# GEOS-Chem Global Chemical Transport Model !
#------------------------------------------------------------------------------
#BOP
#
# !IROUTINE: getDefaults
#
# !DESCRIPTION: Reads the input file and returns the name of the directory
# where run directories are stored.
#\\
#\\
# !INTERFACE:
#
sub getDirs($) {
#
# !INPUT PARAMETERS:
#
my ( $fileName ) = @_; # File with unit test input options
#
# !RETURN VALUE:
#
my $runDir = ""; # Run directory
#
# !CALLING SEQUENCE:
# &getDirs( $fileName ); # Saves values to global variables
#
# !REVISION HISTORY:
# 01 Oct 2015 - M. Sulprizio- Initial version based on getDirs in cleanFiles
#EOP
#------------------------------------------------------------------------------
#BOC
#
# !LOCAL VARIABLES:
#
# Scalars
my $home = "";
my $utRoot = "";
my $user = "";
# Arrays
my @txt = ();
#-------------------------------------------------------------------------
# If no filename is passed, return relative data paths
#-------------------------------------------------------------------------
if ( $fileName eq "RELATIVE" ) {
$runDir = "../runs";
return( $runDir );
}
#-------------------------------------------------------------------------
# Otherwise, read the data paths from the specified input filename
#-------------------------------------------------------------------------
# Read data from input file
open( I, "<$fileName" ) or die "Cannot open $fileName!\n";
chomp( @txt = <I> );
close( I );
# Get home directory
$home = $ENV{"HOME"};
# Get username
$user = $ENV{"USER"};
# Parse each line until we find the log directory
for ( my $i = 0; $i < scalar( @txt ); $i++ ) {
if ( $txt[$i] =~ "RUN_ROOT" ) { $runDir = &parse( $txt[$i] ); }
if ( $txt[$i] =~ "UNIT_TEST_ROOT" ) { $utRoot = &parse( $txt[$i] ); }
}
# Replace directory tokens
$utRoot =~ s/{HOME}/$home/g;
$runDir =~ s/{HOME}/$home/g;
$runDir =~ s/{USER}/$user/g;
$runDir =~ s/{UTROOT}/$utRoot/g;
# Return to main program
return( $runDir );
}
#EOC
#------------------------------------------------------------------------------
# GEOS-Chem Global Chemical Transport Model !
#------------------------------------------------------------------------------
#BOP
#
# !IROUTINE: main
#
# !DESCRIPTION: Removes files from the GEOS-Chem Unit Test run directories.
#\\
#\\
# !INTERFACE:
#
sub main() {
#
# !CALLING SEQUENCE:
# cleanRunDirs [ OPTIONS-FILENAME ]
#
# !REVISION HISTORY:
# 01 Oct 2015 - M. Sulprizio- Initial version based on main in cleanFiles
#EOP
#------------------------------------------------------------------------------
#BOC
#
# !LOCAL VARIABLES:
#
# Scalars
my $cmd = "";
my $dir = "";
my $optFile = "";
my $runDir = "";
my $runRoot = "";
my $result = "";
# Arrays
my @dirs = ();
# If the user passes a filename from the command line, use it
# Otherwise, default to "UnitTest.input"
if ( scalar( @ARGV ) == 1 ) { $optFile = $ARGV[0]; }
else { $optFile = "RELATIVE"; }
# Get the local directories
( $runRoot ) = &getDirs( $optFile );
# Get all of the subdirectories of $runDir
opendir( D, "$runRoot" ) or die "$runRoot is an invalid directory!\n";
chomp( @dirs = readdir( D ) );
closedir( D );
# Loop over all contents in the root run directory ($RUN_ROOT)
foreach $dir ( @dirs ) {
# Construct full path name for subdirectory $dir
$runDir = "$runRoot/$dir";
# Make sure each directory is a directory and not a file
if ( -d $runDir ) {
# Also Skip over . and ..
if ( !( $dir =~ m/^\./ ) ) {
# Skip over chem_inputs/
if ( !( $dir =~ m/chem_inputs/ ) ) {
# Remove files in each run directory ...
print "==> Removing files in $runDir\n";
$cmd = "cd $runDir; ";
$cmd .= "rm -f input.geos HEMCO_Config.rc HEMCO.log ";
$cmd .= "HEMCO_diagnostics.* HISTORY.rc Ox.mass.* Makefile ";
$cmd .= "lastbuild* *.sp *.mp *info.dat input.geos.g* ";
$cmd .= "input.geos.m* GEOSChem.Restart* core.* *.nc4 ";
$cmd .= "HEMCO_Config.rc.g* HEMCO_Config.rc.m* trac_avg.* ";
$cmd .= "Rn.mass.* GEOS-Chem_Species_Database.json;";
$cmd .= "rm -rf OutputDir;";
$cmd .= "cd ..";
#print "$cmd\n";
qx/$cmd/;
}
}
}
}
# Return w/ status
return( $? );
}
#EOC
#------------------------------------------------------------------------------
# Call main driver routine
main();
# Exit and pass status code to Unix shell
exit( $? );