-
Notifications
You must be signed in to change notification settings - Fork 2
/
psims
executable file
·150 lines (129 loc) · 4.18 KB
/
psims
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
#!/bin/bash
#
# Usage: psims -s <sitename> -p <paramfile> -g <gridlist> [ -t test_result ]
# crash: Report a problem and exit
crash()
{
echo "$@" >&2
exit 1
}
# Find absolute path
abspath()
{
readlink -f $1
}
# Process command line arguments
while [ $# -gt 0 ]; do
case $1 in
-g) gridlist=$2; shift 2;;
-p) paramfile=$2; shift 2;;
-s) site=$2; shift 2;;
-t) test_result=$2; shift 2;;
*) crash "Usage: $0 -s <sitename> -p <paramfile> -g <gridlist> [ -t test_result ]";;
esac
done
if [ ! -f "conf/$site.xml" ]; then
crash "Unable to find configuration file conf/$site.xml"
fi
if [ -n "$test_result" ]; then
if [ ! -d "$test_result" ]; then
crash "Unable to find test result directory $test_result"
fi
fi
# Create next unique run id and run directory
export rundir=$( abspath $( echo run??? | sed -e 's/^.*run//' | awk '{ printf("run%03d\n", $1+1)}' ))
mkdir $rundir || crash "Unable to create run directory"
workdir=$rundir
# Set parameters
if [ ! -f $paramfile ]; then
crash "Could not find parameter file $paramfile in params!"
fi
sed -e '/^[[:space:]]*\(#.*\)*$/d' -e 's/#.*//' -e 's/ */=/' -e 's/^/export /' $paramfile > $rundir/params.psims
source $rundir/params.psims
export PATH=$PWD/bin:$PWD/tapps:$PWD/tapps/pdssat:$PWD/tapps/papsim:$PWD/tapps/pcenw:$PWD/tapps/pepic:$PATH
export SWIFT_HEAP_MAX=5120M
export SWIFT_USERHOME=$PWD
# Check for work_directory location
if [ -n "$work_directory" ]; then
workdir="$( abspath $work_directory )/$( basename $rundir )"
if [ -d "$workdir" ]; then
crash "Work directory $workdir already exists"
fi
mkdir -p $workdir
cp $rundir/params.psims $workdir
fi
# Copy required files to the work_directory
cp $campaign/*.nc4 $workdir/
cp $gridlist $workdir/gridList.txt
cp RunpSIMS.swift $workdir
cp combine.swift $workdir
cp bin/RunpSIMS.sh $workdir
cp conf/swift.properties $workdir
cp conf/$site.xml $workdir/sites.xml
cp conf/$site.cf $workdir/cf
cp $paramfile $workdir/paramfile
chmod a+rw $workdir/*
cd $workdir
source params.psims
# Record arguments in ABOUT file
cat << EOF > ABOUT
Site $site
Parameter file $( abspath $paramfile )
Gridlist $( abspath $gridlist )
Run directory $rundir
Work directory $workdir
EOF
# Echo parameters
cat ABOUT
echo -e "\nParameters:"
cat $workdir/params.psims
echo
# Extract input_tars
if [ -n "$tar_inputs" ]; then
echo "Setting up data..."
tar_files=$( echo $tar_inputs | sed s/,/' '/g )
for file in $tar_files; do
echo "Extracting $file"
tar xvf $file 2>&1 | while read line; do
x=$((x+1))
echo -en "$x files extracted\r"
done
done
fi
for param in $( awk '{print $1}' paramfile )
do
arguments="$arguments -$param=${!param}"
done
# Generate restart scripts
echo "swift -minimal.logging -sites.file sites.xml -tc.file tc.data -config cf -resume RunpSIMS*.rlog RunpSIMS.swift $arguments -workdir=$workdir 2>&1 | tee -a swift.out" > restart.sh
echo "swift -minimal.logging -sites.file sites.xml -tc.file tc.data -config cf -resume combine*.rlog combine.swift $arguments -workdir=$workdir 2>&1 | tee -a swift.out" > restart.combine.sh
chmod +x restart.sh restart.combine.sh
# Generate parts
gensites -p cf $rundir/../conf/$site.xml > sites.xml
swift -minimal.logging -sites.file sites.xml -tc.file tc.data -config cf RunpSIMS.swift $arguments -workdir=$workdir 2>&1 | tee -a swift.out
# Post processing
swift -minimal.logging -sites.file sites.xml -tc.file tc.data -config cf combine.swift $arguments -workdir=$workdir 2>&1 | tee -a swift.out
# Plots
echo Generating plots...
$rundir/../bin/activityplot.pl combine-2*.log plot-combine.png &> /dev/null
$rundir/../bin/activityplot.pl RunpSIMS-2*.log plot-psims.png &> /dev/null
echo -e "Done\n"
# Testing
if [ -n "$test_result" ]; then
echo Comparing results to test data at $test_result
$rundir/../bin/cmp_output.py $rundir $test_result
if [ "$?" == "0" ]; then
echo "Test passed"
else
echo "Test failed"
fi
fi
# Move data back to original run directory
if [ "$rundir" != "$workdir" ]; then
echo Cleaning up data in $workdir...
echo rm -rf $workdir/data
echo Moving data from $workdir to $rundir...
echo mv $workdir/* $rundir/
echo rm -r $workdir
echo Done
fi