-
Notifications
You must be signed in to change notification settings - Fork 0
/
period_prefix.sh
78 lines (78 loc) · 2.85 KB
/
period_prefix.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
function prefix_by_period () {
#======= first, read period list ================
if [ -z ${hy_periods_names} ]; then
if [ -z $REPO_HYPERONMC_FACTORY ]; then
REPO_HYPERONMC_FACTORY=$(dirname $(realpath "${BASH_SOURCE[0]}"))
echo "No REPO_HYPERONMC_FACTORY setted. I set it to be ${REPO_HYPERONMC_FACTORY}"
fi
if /bin/ls $REPO_HYPERONMC_FACTORY/periods.list >& /dev/null ; then
i=0
for line in $(cat $REPO_HYPERONMC_FACTORY/periods.list)
do
if [ ! -z $line ] ; then
period=$(echo $line | awk -F: '{ print $1 }' )
if [ -z $period ] ; then
(1>&2 echo "$REPO_HYPERONMC_FACTORY/periods.list is wrongly formatted. Please check. Stopping...")
(1>&2 echo "It should be like that: ")
(1>&2 echo "period1:prefix1")
(1>&2 echo "period2:prefix2")
(1>&2 echo "period3:prefix3")
return 1
fi
prefix=$(echo $line | awk -F: '{ print $2 }' )
if [ -z $prefix ] ; then prefix='unknown'; (1>&2 echo "Unknown prefix for period $period"); fi
export hy_periods_names=$period:$hy_periods_names
export hy_periods_prefixes=$prefix:$hy_periods_prefixes
echo "I read period name $period, period prefix is $prefix">/dev/null
let i+=1
fi
done
export hy_periods_number=$i
echo "I read $hy_periods_number periods">/dev/null
else
(1>&2 echo "no periods.list found in $REPO_HYPERONMC_FACTORY. Aborting")
return 1
fi
fi
#======== iterate over inputs and find period prefix for every input=================
for input in "$@"
do
#echo 'input is' $input >/dev/null
i=1
while [ "$(echo $hy_periods_names | awk -F: -v pos=$i '{ print $pos }' )" != $input ] && [ $i -le $hy_periods_number ] ; do let i+=1 ; done
if [ $i -gt $hy_periods_number ] ; then echo 'unknown' ;
else echo $(echo $hy_periods_prefixes | awk -F: -v pos=$i '{ print $pos }' )
fi
done
return 0
}
export -f prefix_by_period
#for i in $(ls -d -1 20??-??); do ls $i/file_li*mm.dat ; done
#for i in $(ls -1 2008-11/file_list*) ; do if [ $i = ${i/empty} ] && [ $i != ${i/nov} ] ; then echo $i ; fi ; done
function list_periods () {
if prefix_by_period ;
then
i=1
while [ $i -le "$hy_periods_number" ] ; do echo $(echo $hy_periods_names | awk -F: -v pos=$i '{ print $pos }' ) ; let i+=1 ; done
else
echo 'no periods' ; return 1;
fi
return 0
}
export -f list_periods
function period_by_prefix () {
if prefix_by_period ; then
for input in "$@"
do
i=1
while [ "$(echo $hy_periods_prefixes | awk -F: -v pos=$i '{ print $pos }' )" != $input ] && [ $i -le $hy_periods_number ] ; do let i+=1 ; done
if [ $i -gt $hy_periods_number ] ; then echo 'unknown' ;
else echo $(echo $hy_periods_names | awk -F: -v pos=$i '{ print $pos }' )
fi
done
else
echo 'no periods' ; return 1;
fi
return 0
}
export -f period_by_prefix