-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbencheval.sh
More file actions
executable file
·120 lines (100 loc) · 3.78 KB
/
bencheval.sh
File metadata and controls
executable file
·120 lines (100 loc) · 3.78 KB
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
#!/bin/bash
# Script to iterate through variables, change a line in a file, execute make, and move files.
# The script will revert the haskell file after running make eval
# and generate an xlsx file from the results.
# Function to display usage instructions.
usage() {
echo "Usage: $0 [-h]"
echo " -h, --help Display this help message."
echo " -b, --branch X Branch in Rebound repo."
echo ""
echo " This script will iterate through predefined variables, changing the line"
echo " 'import Rebound.Env.Internal' in ../Rebound/src/Rebound/Env.hs,"
echo " executing 'make normalize', moving files accordingly, generating txt files"
exit 1
}
# Define the file to modify.
file="../rebound/src/Rebound/Env.hs"
# define the branch to use
# branch="wip/phantom-snat-fin-vec"
branch="main"
# Parse command-line options.
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
-h|--help)
usage
;;
*)
usage
exit 1
;;
esac
done
# Check if the file exists.
if [ ! -f "$file" ]; then
echo "Error: File '$file' not found."
exit 1
fi
# checkout the corresponding branch on both repos
git checkout "$branch"
pushd "../rebound"; git checkout "$branch"; popd
# Define the list of variables.
valid_variables=("Internal" "InternalA" "Functional" "InternalB" "InternalLazy")
# Iterate through the variables.
for variable in "${valid_variables[@]}"; do
# Use sed to change the line. Use a different sed syntax.
new_string="import Rebound.Env.$variable"
sed -i -e "s/import Rebound.Env.Internal/$new_string/" "$file"
# Check the exit status of sed.
if [ $? -ne 0 ]; then
echo "Error: Failed to change line in '$file' for variable '$variable'."
exit 1
fi
echo "Successfully changed line in '$file' to '$new_string'."
# Execute 'make eval'.
make normalize
if [ $? -ne 0 ]; then
echo "Error: 'make normalize' failed for variable '$variable'."
# Revert the file even if make eval fails
sed -i -e "s/import Rebound.Env.$variable/import Rebound.Env.Internal/" "$file"
exit 1
fi
echo "'make eval' executed successfully for variable '$variable'."
# Move files.
source_dir="results/Stephanie-Weirich-MBP/rebound_strict_envV"
dest_dir="results/ablate/rebound_strict_envV/$branch/$variable"
# Check if the source directory exists.
if [ ! -d "$source_dir" ]; then
echo "Error: Source directory '$source_dir' not found for variable '$variable'."
# Revert the file even if the directory is not found
sed -i -e "s/import Rebound.Env.$variable/import Rebound.Env.Internal/" "$file"
exit 1
fi
# Create the destination directory if it doesn't exist.
mkdir -p "$dest_dir"
if [ $? -ne 0 ]; then
echo "Error: Failed to create destination directory '$dest_dir' for variable '$variable'."
# Revert the file even if directory creation fails
sed -i -e "s/import Rebound.Env.$variable/import Rebound.Env.Internal/" "$file"
exit 1
fi
# Move the files
mv $source_dir/* $dest_dir/
# find "$source_dir" -type f -exec sh -c 'mv "$1" "${1%.txt}.csv"' _ {} \;
if [ $? -ne 0 ]; then
echo "Error: Failed to move files from '$source_dir' to '$dest_dir' and convert to CSV for variable '$variable'."
# Revert the file even if file moving fails.
sed -i -e "s/import Rebound.Env.$variable/import Rebound.Env.Internal/" "$file"
exit 1
fi
echo "Successfully moved and converted files to CSV in '$dest_dir' for variable '$variable'."
# Revert the Haskell file to its original state.
sed -i -e "s/import Rebound.Env.$variable/import Rebound.Env.Internal/" "$file"
if [ $? -ne 0 ]; then
echo "Error: Failed to revert the Haskell file '$file' after processing variable '$variable'."
exit 1
fi
echo "Successfully reverted '$file' to its original state after processing variable '$variable'."
done
exit 0