Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
archive-put-pmt.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2script=${0##*/}
3
4if [ -z $JPP_DIR ]; then
5 echo "Variable JPP_DIR undefined."
6 exit
7fi
8
9source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
10
11set_variable: DEBUG ARCHIVE_DEBUG 2
12set_variable: WORKDIR ARCHIVE_WORKDIR ${TMPDIR:-/tmp}/
13set_variable TYPE pmt
14
15if do_usage $*; then
16 usage "$script <source directory> <detector identifier> <suffix> <archive> <version>"\
17 "\nAuxiliary script to download online detector files from database and to store these in archive."\
18 "\nNote that the given suffix and version should match with that in the file names."
19fi
20
21if (( $# == 5 )); then
22 set_variable DIR $argv[1]
23 set_variable DETECTOR_ID $argv[2]
24 set_variable SUFFIX $argv[3]
25 set_variable ARCHIVE $argv[4]
26 set_variable VERSION $argv[5]
27else
28 fatal "Wrong number of arguments."
29fi
30
31set_variable DETECTOR_ID $(getDetector -D $DETECTOR_ID -O int)
32set_variable PREFIX KM3NeT_${(l:8::0::0:)DETECTOR_ID}
33set_variable SUFFIX ${VERSION}_${SUFFIX}
34
35typeset -A DATABASE
36typeset -T BUFFER ARRAY _
37
38for FILE_NAME in `ls ${DIR}/${PREFIX}_*\.${SUFFIX}.txt`; do
39
40 BUFFER=${${FILE_NAME:t}%%\.*}
41
42 let "ID = $ARRAY[2]"
43 let "RUN = $ARRAY[3]"
44
45 DATABASE[$RUN]=$FILE_NAME
46done
47
48if (( ${#DATABASE} == 0 )); then
49 fatal "No input files at ${DIR}/${PREFIX}_*\.${SUFFIX}.txt."
50fi
51
52MINRUN=`echo ${(k)DATABASE} | tr ' ' '\n' | sort -g | head -n 1`
53MAXRUN=`echo ${(k)DATABASE} | tr ' ' '\n' | sort -g | tail -n 1`
54
55for (( i0 = $MINRUN; $i0 <= $MAXRUN; )); do
56
57 if (( ${+DATABASE[$i0]} == 1 )); then
58
59 notice "Run $i0 $DATABASE[$i0]"
60
61 grep -E -v "^#" $DATABASE[$i0] > $WORKDIR/i0.txt
62
63 for (( i1 = $i0 + 1; $i1 <= $MAXRUN; i1 += 1 )); do
64
65 if (( ${+DATABASE[$i1]} == 0 )); then
66 continue
67 fi
68
69 notice "Run $i1 $DATABASE[$i1]"
70
71 grep -E -v "^#" $DATABASE[$i1] > $WORKDIR/i1.txt
72
73 diff $WORKDIR/i0.txt $WORKDIR/i1.txt >& /dev/null
74
75 if (( $? != 0 )); then
76 break
77 fi
78 done
79
80 putFile.sh ${DATABASE[$i0]} $ARCHIVE $DETECTOR_ID $i0 $(($i1 - 1)) $TYPE $VERSION
81
82 let "i0 = $i1"
83 else
84
85 let "i0 = $i0 + 1"
86 fi
87done
88
89rm -f $WORKDIR/i{0,1}.txt