Jpp  master_rocky
the software that should make you happy
archive-put-pmt.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 script=${0##*/}
3 
4 if [ -z $JPP_DIR ]; then
5  echo "Variable JPP_DIR undefined."
6  exit
7 fi
8 
9 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
10 
11 set_variable: DEBUG ARCHIVE_DEBUG 2
12 set_variable: WORKDIR ARCHIVE_WORKDIR ${TMPDIR:-/tmp}/
13 set_variable TYPE pmt
14 
15 if 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."
19 fi
20 
21 if (( $# == 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]
27 else
28  fatal "Wrong number of arguments."
29 fi
30 
31 set_variable DETECTOR_ID $(getDetector -D $DETECTOR_ID -O int)
32 set_variable PREFIX KM3NeT_${(l:8::0::0:)DETECTOR_ID}
33 set_variable SUFFIX ${VERSION}_${SUFFIX}
34 
35 typeset -A DATABASE
36 typeset -T BUFFER ARRAY _
37 
38 for 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
46 done
47 
48 if (( ${#DATABASE} == 0 )); then
49  fatal "No input files at ${DIR}/${PREFIX}_*\.${SUFFIX}.txt."
50 fi
51 
52 MINRUN=`echo ${(k)DATABASE} | tr ' ' '\n' | sort -g | head -n 1`
53 MAXRUN=`echo ${(k)DATABASE} | tr ' ' '\n' | sort -g | tail -n 1`
54 
55 for (( 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
87 done
88 
89 rm -f $WORKDIR/i{0,1}.txt