-
Notifications
You must be signed in to change notification settings - Fork 4
/
join_multiple.sh
executable file
·62 lines (47 loc) · 1.68 KB
/
join_multiple.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
#!/bin/bash
in_dir=$1
out_dir=$2
function usage {
print "$0 <input_directory> <output_directory>"
}
function spectral_range {
h5dump -d Extent_Ranges -y -A 0 $1 | awk '/DATA {/,/}/ { out=$0; sub(/^.*DATA.*$/, "", out); sub(/.*}/, "", out); sub(/^[ ]+/, "", out) ; sub(/,/, "", out); print out;}' | xargs
}
if [ -z "$in_dir" ]; then
echo "No input directory supplied"
usage
exit 1
fi
if [ -z "$out_dir" ]; then
print "No output directory supplied"
usage
exit 1
fi
# Create output directory if it does not already exist
mkdir -p $out_dir
mol_names=$(find $in_dir -name "*.nc" -exec basename {} \; | sed 's/_.*$//g' | sort | uniq | xargs)
echo -e "Found the following molecule names:\n$mol_names"
for mol in $mol_names; do
mol_files=( $(find $in_dir -name "${mol}_*.nc" | sort) )
num_files=${#mol_files[@]}
echo -e "\nFound $num_files files for $mol:"
for fn in ${mol_files[@]}; do
echo -e "\t$fn"
done
first_fn=${mol_files[0]}
last_fn=${mol_files[-1]}
if [ $num_files -gt 1 ]; then
# Parse out the beginning and ending wn range to put into the output filename
first_range=($(spectral_range $first_fn))
last_range=($(spectral_range $last_fn))
new_range=$(printf "%05.0f-%05.0f" ${first_range[0]} ${last_range[-1]})
first_base=$(basename $first_fn)
first_parts=(${first_base//_/ })
postfix_parts=${first_parts[@]:2}
new_postfix=${postfix_parts// /_}
output_fn="${mol}_${new_range}_${new_postfix}"
$(dirname $0)/join_tables.py ${mol_files[@]} -o $out_dir/$output_fn
else
ln -svf $(readlink -f $first_fn) $out_dir/$(basename $first_fn)
fi
done