-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombineSU2meshes.sh
executable file
·80 lines (65 loc) · 2.34 KB
/
combineSU2meshes.sh
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
#!/bin/bash
# ---------------------------------------------------------------------------- #
# Kattmann, 02.07.2019
# This script combines a number of .su2 meshes given over the command line.
# ---------------------------------------------------------------------------- #
display_usage() {
echo "usage: combine -f <mesh1.su2> -f <mesh2.su2> -f ... -o <output filename> -d <dimension 2|3>"
exit 0
}
# If no argument is given, display help
if [ $# == 0 ]; then
display_usage; exit 0
fi
# ---------------------------------------------------------------------------- #
# Read in files via command line
while getopts hf:o:d: option; do
case $option
in
h) display_usage;;
f) FILES+=(${OPTARG});;
o) OUTPUT=${OPTARG};;
d) DIMENSION=${OPTARG};;
\?) echo "Wrong usage."; display_usage
exit 1;;
esac
done
# ---------------------------------------------------------------------------- #
# Error checks for the input
# min 2 FILES required which have to exist
if [ ${#FILES[@]} -le 1 ]; then
echo "Provide at least 2 input files."; display_usage; exit 1
else
for i in `seq 1 ${#FILES[@]}`; do
if [ ! -e ${FILES[$i-1]} ]; then
echo "Input file '${FILES[$i-1]}' does not exists."; display_usage; exit 1
fi
done
fi
# OUTPUT mustn't exists in the directory but has to prescribed
if [ -z $OUTPUT ]; then
echo "Prescribe an outputfilename."; display_usage; exit 1
elif [ -e $OUTPUT ]; then
echo "Output file '$OUTPUT' already exists."; display_usage; exit 1
fi
# DIMENSION has to be prescribed and be either <2|3>
if [ -z "$DIMENSION" ]; then
echo "Dimension has to be given."; display_usage; exit 1
elif [ ! "$DIMENSION" -eq 2 ] && [ ! "$DIMENSION" -eq 3 ]; then
echo "Dimension has to 2 or 3."; display_usage; exit 1
fi
# ---------------------------------------------------------------------------- #
touch $OUTPUT
# Write .su2 header once
echo "NDIME= $DIMENSION" >> $OUTPUT
echo -e "NZONE= ${#FILES[@]}" >> $OUTPUT
# Loop through FILES and paste them into to OUTPUT
for i in `seq 1 ${#FILES[@]}`; do
echo -e "\nIZONE= $i\n" >> $OUTPUT
cat ${FILES[$i-1]} >> $OUTPUT
done
# ---------------------------------------------------------------------------- #
# Get rid of all ^M characters if single-zone mesh file were written under windows.
# This is useful if file is displayed in vim under linux.
sed -i -e "s///" $OUTPUT