-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.sh
More file actions
executable file
·143 lines (132 loc) · 4.56 KB
/
Copy pathmain.sh
File metadata and controls
executable file
·143 lines (132 loc) · 4.56 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# This is the main script that will call the other scripts
#!/bin/bash
# Default values
REALTIME=false
SKIP_COMPILE=false
LAYOUT=""
ARCHITECTURE=""
# Function to display usage
usage() {
echo "usage: $0 [-l LAYOUT] [-r] [-a ARCHITECTURE] input output"
echo ""
echo "Compile and animate neutral atom instruction. This script depends on the following scripts:"
echo " - compile.py: Compiles the input file into a format that can be used by the animation script."
echo " - animate.R: Animates the compiled file and produces a movie file [.mp4]."
echo ""
echo "positional arguments:"
echo " input .na file to animate or .csv if already compiled."
echo " output File name of the movie [.mp4]."
echo ""
echo "options:"
echo " -x, --skipCompile Skip the compilation step if the input file is already compiled."
echo " This is useful if the input file is already compiled and you only want to animate it."
echo " Provide the compiled csv file as the input file."
echo " -r, --realtime Use real time specification for operations."
echo " Necessitates the specification of an architecture file."
echo " Otherwise every operation will take 1 time unit."
echo " -s, --speed SPEED Speed of the animation. Default is 1."
echo " -a ARCHITECTURE, --architecture ARCHITECTURE"
echo " The architecture file to use for realtime mode [.json]."
echo " In particular, this has to specify the durations of the different operations."
echo " For an example of such a file see config/wide.json."
echo " This is necessary for the real time mode."
echo " -l LAYOUT, --layout LAYOUT"
echo " Layout file [.csv]. This specifies the location of traps and their color based on"
echo " their type. See config/wide.csv for an example."
}
# Parse options
while [[ $# -gt 0 ]]; do
case "$1" in
-x|--skipCompile)
SKIP_COMPILE=true
shift
;;
-r|--realtime)
REALTIME=true
shift
;;
-s|--speed)
SPEED="$2"
shift 2
;;
-a|--architecture)
ARCHITECTURE="$(realpath "$2")"
shift 2
;;
-l|--layout)
LAYOUT="$(realpath "$2")"
shift 2
;;
*)
break
;;
esac
done
# Validate that input file is csv if skip compile is specified
if [[ "$SKIP_COMPILE" = true && ! "$1" =~ \.csv$ ]]; then
usage
echo "Error: Input file must be a .csv file if skip compile is specified."
exit 1
fi
# Validate if realtime is specified without architecture
if [[ "$REALTIME" = true && -z "$ARCHITECTURE" ]]; then
usage
echo "Error: Realtime option specified without an architecture."
exit 1
fi
# Set default speed if not specified
if [[ -z "$SPEED" ]]; then
SPEED=1
fi
# set speed to its inverse times 50
SPEED=$(echo "scale=2; 1/$SPEED*50" | bc)
# Validate if realtime is specified without architecture
if [[ -z "$LAYOUT" ]]; then
usage
echo "Error: Layout must be specified."
exit 1
fi
# Check if input and output file names are provided
if [[ $# -ne 2 ]]; then
usage
echo "Error: Input and output file names are required."
exit 1
fi
# Assign positional arguments
INPUT="$(realpath "$1")"
COMPILED="$(dirname "$INPUT")/$(basename "$INPUT" .na).csv"
if [[ "$SKIP_COMPILE" = true ]]; then
COMPILED="$INPUT"
fi
touch "$2"
OUTPUT="$(realpath "$2")"
# set working directory to the directory of the source file
# This step is important for the python and R script to be availale
cd "$(dirname "$0")"
if [[ "$SKIP_COMPILE" = false ]]; then
echo "Compiling the input file..."
echo ""
if [[ "$REALTIME" = true ]]; then
python3 compile.py --realtime --architecture $ARCHITECTURE $INPUT $COMPILED
else
python3 compile.py $INPUT $COMPILED
fi
result=$?
if [[ $result -ne 0 ]]; then
echo "Error: Compilation failed with exit code: $result."
exit 1
fi
fi
echo ""
Rscript animate.R --layout $LAYOUT --ratio $SPEED $COMPILED $OUTPUT
result=$?
if [[ $result -ne 0 ]]; then
echo "Error: Animation failed with exit code: $result."
exit 1
fi
# rm -f $COMPILED
echo ""
echo "Successfully compiled the input file and created the neutral atom animation."
echo "Input file: $INPUT"
echo "Output file: $OUTPUT"