-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamu_add_to_protocol
executable file
·81 lines (74 loc) · 1.65 KB
/
amu_add_to_protocol
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
#!/bin/bash
protocol=
mdin=
to=
me=amu_add_protocol
function usage
{
echo "$me <[-p|--protocol file> [-m|--mdin file] [-t|--to num]"
}
ARGS=$(getopt -o 'm:p:t:' --long 'mdin:,protocol:,to:' -n "${me}" -- "$@")
eval set -- "$ARGS"
unset ARGS
while true; do
case $1 in
'-m'|'--mdin')
mdin=$2
shift 2
continue
;;
'-p'|'--protocol')
protocol=$2
shift 2
continue
;;
'-t'|'--to')
to=$2
shift 2
continue
;;
'--')
shift
break
;;
'')
usage
exit 0
;;
*)
echo "Internal error" >&2
exit 1
;;
esac
done
[ $AMU_HOME ] || { echo "AMU_HOME not set. Exiting." ; exit ; }
[ "$protocol" ] || {
echo "protocol file not supplied." ;
usage ;
exit 1;
}
source $AMU_HOME/ambermd_util.bash
last=$(amu_protocol_rm_comment $protocol | tail -n 1 | awk '{print $1}' | egrep -o '[1-9][0-9]*' )
num=$(( last + 1 ))
s="steps $((last + 1)) to $to"
if [ -z $to ] ; then
s="one step"
to=$num
fi
(
for (( ; num < $((to + 1)) ; num=$((num + 1)) )) {
echo -e "$(printf %d $num)\t${mdin}\t# added `date +%Y/%m/%d`" >> $protocol || exit 1
mdin=""
}
)
if [ ! $num -gt $to ] ; then
if [ $? -eq 0 ] ; then
echo -n "Added $s on the protocol file $protocol"
if [ "$mdin" ] ; then echo -n " using mdin file $mdin" ; fi
echo
else
echo "Error on adding step ${num}. Exiting." >&2
fi
else
echo "First step to add is $num but --to=${to}. Exiting."
fi