1 | #!/bin/sh
|
---|
2 |
|
---|
3 | #hypothesis: ON = data1 phase, OFF data2 phase
|
---|
4 |
|
---|
5 | #Basic tuning of system fuction used.
|
---|
6 | AWK=/bin/awk
|
---|
7 | SED=/bin/sed
|
---|
8 | GREP=/bin/grep
|
---|
9 | WC=/usr/bin/wc
|
---|
10 | RM=/bin/rm
|
---|
11 | CAT=/bin/cat
|
---|
12 | TOUCH=/bin/touch
|
---|
13 | DATE=/bin/date
|
---|
14 | ECHO=/bin/echo
|
---|
15 | FIND=/usr/bin/find
|
---|
16 | XARGS=/usr/bin/xargs
|
---|
17 | SORT=/bin/sort
|
---|
18 | MKDIR=/bin/mkdir
|
---|
19 | LS=/bin/ls
|
---|
20 | DefaultIFS=$' \t\n'
|
---|
21 | IFS=$DefaultIFS
|
---|
22 |
|
---|
23 | scriptName="`basename $0`"
|
---|
24 | $ECHO "Processing script ${scriptName} at `date`"
|
---|
25 |
|
---|
26 | if [ ! $# = 3 ]; then
|
---|
27 | $ECHO "usage: ${scriptName} <scaXYZ.sum> <signalXYZDirectory> <type of phase:ON|OFF|CALIBON|CALIBOFF>"
|
---|
28 | touch ${tmppublicpath}/select.finished
|
---|
29 | exit 0
|
---|
30 | fi
|
---|
31 |
|
---|
32 | #Path to public backupable path
|
---|
33 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
|
---|
34 |
|
---|
35 | #temporary files to synchronize scripts
|
---|
36 | tmppublicpath=${TMPPUBLICPATH}
|
---|
37 | $LS -l ${tmppublicpath} > /dev/null
|
---|
38 |
|
---|
39 |
|
---|
40 | #Path of the utility scripts
|
---|
41 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
|
---|
42 |
|
---|
43 |
|
---|
44 | OUT1=./selectFits.$$
|
---|
45 |
|
---|
46 | #inputs x-chexk sca file
|
---|
47 | inScaFile=$1
|
---|
48 | if [ ! -e $inScaFile ]; then
|
---|
49 | $ECHO "FATAL (${scriptName}): $inScaFile not found"
|
---|
50 | touch ${tmppublicpath}/select.finished
|
---|
51 | exit 1
|
---|
52 | fi
|
---|
53 |
|
---|
54 | #Where to look at
|
---|
55 | inFiberDir=$2
|
---|
56 |
|
---|
57 | inTypeOfPhase=$3
|
---|
58 | case "$inTypeOfPhase" in
|
---|
59 | ON)
|
---|
60 | $ECHO "INFO (${scriptName}): filter signal files for ON phases";;
|
---|
61 | OFF)
|
---|
62 | $ECHO "INFO (${scriptName}): filter signal files for OFF phases";;
|
---|
63 | CALIBON)
|
---|
64 | $ECHO "INFO (${scriptName}): filter signal files for CALIBRATION ON phases";;
|
---|
65 | CALIBOFF)
|
---|
66 | $ECHO "INFO (${scriptName}): filter signal files for CALIBRATION OFF phases";;
|
---|
67 | GAIN)
|
---|
68 | $ECHO "INFO (${scriptName}): filter signal files for GAIN = CALIB OFF phases";;
|
---|
69 | *)
|
---|
70 | $ECHO "FATAL (${scriptName}): use ON|OFF|CALIBON|CALIBOFF phase tags."
|
---|
71 | touch ${tmppublicpath}/select.finished
|
---|
72 | exit 1
|
---|
73 | ;;
|
---|
74 | esac
|
---|
75 |
|
---|
76 |
|
---|
77 | #################
|
---|
78 | #fill the arrays association header file with start/end date&time
|
---|
79 | # arrays
|
---|
80 | declare -a sigStart
|
---|
81 | declare -a sigEnd
|
---|
82 | declare -a sigFile
|
---|
83 |
|
---|
84 | for fullfile in $( $FIND $inFiberDir -name "header*" | $XARGS -i basename {} | $SORT -k1.7n)
|
---|
85 | do
|
---|
86 | filename=$(basename $fullfile)
|
---|
87 | extension=${filename##*.}
|
---|
88 | filename=${filename%.*}
|
---|
89 | ffn=${inFiberDir}/${filename}.${extension}
|
---|
90 | # echo "process $ffn"
|
---|
91 | while read -n80 L
|
---|
92 | do
|
---|
93 | [ "${L::3}" = "END" ] && break
|
---|
94 | echo $L
|
---|
95 | done < $ffn > $OUT1
|
---|
96 |
|
---|
97 | strStart=`$GREP TMSTART $OUT1 | $AWK '{split($0,a,"/"); split(a[1],b,"="); print b[2];}' | $SED 's/^[ \t]*//;s/[ \t]*$//' | $SED "s/^\([\"']\)\(.*\)\1\$/\2/g" | $AWK '{split($0,a,"T"); print a[1]" "a[2];}' `
|
---|
98 |
|
---|
99 | strEnd=`$GREP TMEND $OUT1 | $AWK '{split($0,a,"/"); split(a[1],b,"="); print b[2];}' | $SED 's/^[ \t]*//;s/[ \t]*$//' | $SED "s/^\([\"']\)\(.*\)\1\$/\2/g" | $AWK '{split($0,a,"T"); print a[1]" "a[2];}' `
|
---|
100 |
|
---|
101 | if [[ -n "$strStart" && -n "$strEnd" ]]; then
|
---|
102 | timeStart=`${DATE} +%s -d "${strStart}"`
|
---|
103 | timeEnd=`${DATE} +%s -d "${strEnd}"`
|
---|
104 | # echo "$fullfile start $strStart <$timeStart>, end $strEnd <$timeEnd>"
|
---|
105 | sigStart[${#sigStart[*]}]=$timeStart
|
---|
106 | sigEnd[${#sigEnd[*]}]=$timeEnd
|
---|
107 | sigFile[${#sigFile[*]}]=$filename
|
---|
108 | else
|
---|
109 | $ECHO "WARNING (${scriptName}): $ffn PATHOLOGIQUE"
|
---|
110 | fi
|
---|
111 | done
|
---|
112 |
|
---|
113 | ############
|
---|
114 | #scan all the cycles
|
---|
115 | # calib1start=$2; calib1end=$3;
|
---|
116 | # data1start=$4; data1end=$5;
|
---|
117 | # calib2start=$6; calib2end=$7;
|
---|
118 | # data2start=$8; data2end=$9;
|
---|
119 | #to pass to awk: use a "," as field separator
|
---|
120 | awk_sigStart=$( printf "%s," "${sigStart[@]}" )
|
---|
121 | awk_sigEnd=$( printf "%s," "${sigEnd[@]}" )
|
---|
122 | awk_sigFile=$( printf "%s," "${sigFile[@]}" )
|
---|
123 |
|
---|
124 | #attention a la derniere "," pour le calcul de nfile
|
---|
125 | OUT1=./tmpselect1.$$
|
---|
126 | #selection d'une seul cycle pour debug
|
---|
127 | $AWK -v datesys=$DATE -v type=$inTypeOfPhase -v str_sigStart="$awk_sigStart" -v str_sigEnd="$awk_sigEnd" -v str_sigFile="$awk_sigFile" '
|
---|
128 | BEGIN {
|
---|
129 | FS=",";
|
---|
130 | split(str_sigStart,a_sigStart,",");
|
---|
131 | split(str_sigEnd,a_sigEnd,",");
|
---|
132 | nfile=split(str_sigFile,a_sigFile,",");
|
---|
133 | delete a_sigFile[nfile];
|
---|
134 | delete a_sigStart[nfile];
|
---|
135 | delete a_sigEnd[nfile];
|
---|
136 | nfile--;
|
---|
137 |
|
---|
138 | }
|
---|
139 |
|
---|
140 | {
|
---|
141 | cycle=$1;
|
---|
142 |
|
---|
143 | if ( type == "ON" ) {
|
---|
144 | phaseStart=$4; phaseEnd=$5;
|
---|
145 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
|
---|
146 | (cmd | getline phstart);
|
---|
147 | close(cmd);
|
---|
148 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd);
|
---|
149 | (cmd | getline phend);
|
---|
150 | close(cmd);
|
---|
151 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">";
|
---|
152 | deltaStartSafety=4;
|
---|
153 | deltaEndSafety=-4;
|
---|
154 | }
|
---|
155 | else if ( type == "OFF" ) {
|
---|
156 | phaseStart=$8; phaseEnd=$9;
|
---|
157 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
|
---|
158 | (cmd | getline phstart);
|
---|
159 | close(cmd);
|
---|
160 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd);
|
---|
161 | (cmd | getline phend);
|
---|
162 | close(cmd);
|
---|
163 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">";
|
---|
164 | deltaStartSafety=4;
|
---|
165 | deltaEndSafety=-4;
|
---|
166 | }
|
---|
167 | else if ( type == "CALIBON" ) {
|
---|
168 | phaseStart=$2; phaseEnd=$3;
|
---|
169 | print "Phase: ",type," cycle: ",cycle,": <",phaseStart,">:<",phaseEnd,">";
|
---|
170 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
|
---|
171 | (cmd | getline phstart);
|
---|
172 | close(cmd);
|
---|
173 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd);
|
---|
174 | (cmd | getline phend);
|
---|
175 | close(cmd);
|
---|
176 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">";
|
---|
177 | deltaStartSafety=-6;
|
---|
178 | deltaEndSafety=6;
|
---|
179 | }
|
---|
180 | else if ( (type == "CALIBOFF") || (type == "GAIN") ) {
|
---|
181 | phaseStart=$6; phaseEnd=$7;
|
---|
182 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
|
---|
183 | (cmd | getline phstart);
|
---|
184 | close(cmd);
|
---|
185 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd);
|
---|
186 | (cmd | getline phend);
|
---|
187 | close(cmd);
|
---|
188 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">";
|
---|
189 | deltaStartSafety=-6;
|
---|
190 | deltaEndSafety=6;
|
---|
191 | }
|
---|
192 | else {
|
---|
193 | print "FATAL: ",type," NOT YET SUPPORTED"; exit 1;
|
---|
194 | }
|
---|
195 |
|
---|
196 | for (i=1; i<=nfile; i++) {
|
---|
197 | diffstart = a_sigStart[i] - phstart;
|
---|
198 | diffend = a_sigEnd[i] - phend;
|
---|
199 | # print "file ",i," start ",a_sigStart[i],": diff <" diffstart ">:<" diffend ">";
|
---|
200 | if ( diffstart >= deltaStartSafety && diffend <= deltaEndSafety )
|
---|
201 | print "cycle ",cycle," file ",i-1," accepted ",a_sigFile[i];
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | }' $inScaFile > ${OUT1}
|
---|
206 |
|
---|
207 | OUT2=./tmpselect2.$$
|
---|
208 | $AWK '
|
---|
209 | BEGIN { max=0; min=999999; };
|
---|
210 |
|
---|
211 | ($1=="cycle") { table[$2] = table[$2]","$4; if($2>max){max=$2}; if($2<min){min=$2} };
|
---|
212 |
|
---|
213 | END { for (j=min;j<=max;j++) {print j,table[j];} }
|
---|
214 | ' ${OUT1} > ${OUT2}
|
---|
215 |
|
---|
216 | $AWK '
|
---|
217 | BEGIN { FS=","}
|
---|
218 | {
|
---|
219 | print "#"$1,$2","$NF",1";
|
---|
220 | }
|
---|
221 | ' ${OUT2}
|
---|
222 |
|
---|
223 | $RM $OUT1
|
---|
224 | $RM $OUT2
|
---|
225 |
|
---|
226 | touch ${tmppublicpath}/select.finished
|
---|
227 | exit 0 |
---|