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 | TMP="/tmp" |
---|
16 | |
---|
17 | OUT1=${TMP}/selectFits.$$ |
---|
18 | |
---|
19 | if [ ! $# = 3 ]; then |
---|
20 | $ECHO "usage: ./select.sh <scaXYZ.sum> <signalXYZDirectory> <type of phase:ON|OFF|CALIBON|CALIBOFF>" |
---|
21 | exit 0 |
---|
22 | fi |
---|
23 | |
---|
24 | #inputs x-chexk sca file |
---|
25 | inScaFile=$1 |
---|
26 | if [ ! -e $inScaFile ]; then |
---|
27 | $ECHO "$inScaFile not found: FATAL" |
---|
28 | exit 1 |
---|
29 | fi |
---|
30 | |
---|
31 | #scan the Fiber1 directory only |
---|
32 | inFiberDir=$2/Fiber1 |
---|
33 | |
---|
34 | inTypeOfPhase=$3 |
---|
35 | case "$inTypeOfPhase" in |
---|
36 | ON) |
---|
37 | $ECHO "filter signal files for ON phases";; |
---|
38 | OFF) |
---|
39 | $ECHO "filter signal files for OFF phases";; |
---|
40 | CALIBON) |
---|
41 | $ECHO "filter signal files for CALIBRATION ON phases";; |
---|
42 | CALIBOFF) |
---|
43 | $ECHO "filter signal files for CALIBRATION OFF phases";; |
---|
44 | *) |
---|
45 | $ECHO "use ON|OFF|CALIBON|CALIBOFF phase tags." |
---|
46 | exit 1 |
---|
47 | ;; |
---|
48 | esac |
---|
49 | |
---|
50 | |
---|
51 | ################# |
---|
52 | #fill the arrays association signal file with start/end date&time |
---|
53 | # arrays |
---|
54 | declare -a sigStart |
---|
55 | declare -a sigEnd |
---|
56 | declare -a sigFile |
---|
57 | |
---|
58 | for fullfile in $(find $inFiberDir -name "signal*" | xargs -i basename {} | sort -k1.7n) |
---|
59 | do |
---|
60 | filename=$(basename $fullfile) |
---|
61 | extension=${filename##*.} |
---|
62 | filename=${filename%.*} |
---|
63 | ffn=${inFiberDir}/${filename}.${extension} |
---|
64 | # echo "process $ffn" |
---|
65 | while read -n80 L |
---|
66 | do |
---|
67 | [ "${L::3}" = "END" ] && break |
---|
68 | echo $L |
---|
69 | done < $ffn > $OUT1 |
---|
70 | |
---|
71 | 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];}' ` |
---|
72 | |
---|
73 | 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];}' ` |
---|
74 | |
---|
75 | if [[ -n "$strStart" && -n "$strEnd" ]]; then |
---|
76 | timeStart=`${DATE} +%s -d "${strStart}"` |
---|
77 | timeEnd=`${DATE} +%s -d "${strEnd}"` |
---|
78 | # echo "$fullfile start $strStart <$timeStart>, end $strEnd <$timeEnd>" |
---|
79 | sigStart[${#sigStart[*]}]=$timeStart |
---|
80 | sigEnd[${#sigEnd[*]}]=$timeEnd |
---|
81 | sigFile[${#sigFile[*]}]=$filename |
---|
82 | else |
---|
83 | echo "$ffn PATHOLOGIQUE" |
---|
84 | fi |
---|
85 | done |
---|
86 | |
---|
87 | ############ |
---|
88 | #scan all the cycles |
---|
89 | # calib1start=$2; calib1end=$3; |
---|
90 | # data1start=$4; data1end=$5; |
---|
91 | # calib2start=$6; calib2end=$7; |
---|
92 | # data2start=$8; data2end=$9; |
---|
93 | #to pass to awk: use a "," as field separator |
---|
94 | awk_sigStart=$( printf "%s," "${sigStart[@]}" ) |
---|
95 | awk_sigEnd=$( printf "%s," "${sigEnd[@]}" ) |
---|
96 | awk_sigFile=$( printf "%s," "${sigFile[@]}" ) |
---|
97 | |
---|
98 | #attention a la derniere "," pour le calcul de nfile |
---|
99 | OUT1=${TMP}/tmpselect1.$$ |
---|
100 | #selection d'une seul cycle pour debug |
---|
101 | $AWK -v datesys=$DATE -v type=$inTypeOfPhase -v str_sigStart="$awk_sigStart" -v str_sigEnd="$awk_sigEnd" -v str_sigFile="$awk_sigFile" ' |
---|
102 | BEGIN { |
---|
103 | FS=","; |
---|
104 | split(str_sigStart,a_sigStart,","); |
---|
105 | split(str_sigEnd,a_sigEnd,","); |
---|
106 | nfile=split(str_sigFile,a_sigFile,","); |
---|
107 | delete a_sigFile[nfile]; |
---|
108 | delete a_sigStart[nfile]; |
---|
109 | delete a_sigEnd[nfile]; |
---|
110 | nfile--; |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | { |
---|
115 | cycle=$1; |
---|
116 | |
---|
117 | if ( type == "ON" ) { |
---|
118 | phaseStart=$4; phaseEnd=$5; |
---|
119 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart); |
---|
120 | (cmd | getline phstart); |
---|
121 | close(cmd); |
---|
122 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd); |
---|
123 | (cmd | getline phend); |
---|
124 | close(cmd); |
---|
125 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">"; |
---|
126 | deltaStartSafety=4; |
---|
127 | deltaEndSafety=-4; |
---|
128 | } |
---|
129 | else if ( type == "OFF" ) { |
---|
130 | phaseStart=$8; phaseEnd=$9; |
---|
131 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart); |
---|
132 | (cmd | getline phstart); |
---|
133 | close(cmd); |
---|
134 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd); |
---|
135 | (cmd | getline phend); |
---|
136 | close(cmd); |
---|
137 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">"; |
---|
138 | deltaStartSafety=4; |
---|
139 | deltaEndSafety=-4; |
---|
140 | } |
---|
141 | else if ( type == "CALIBON" ) { |
---|
142 | phaseStart=$2; phaseEnd=$3; |
---|
143 | print "Phase: ",type," cycle: ",cycle,": <",phaseStart,">:<",phaseEnd,">"; |
---|
144 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart); |
---|
145 | (cmd | getline phstart); |
---|
146 | close(cmd); |
---|
147 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd); |
---|
148 | (cmd | getline phend); |
---|
149 | close(cmd); |
---|
150 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">"; |
---|
151 | deltaStartSafety=-6; |
---|
152 | deltaEndSafety=6; |
---|
153 | } |
---|
154 | else if ( type == "CALIBOFF" ) { |
---|
155 | phaseStart=$6; phaseEnd=$7; |
---|
156 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart); |
---|
157 | (cmd | getline phstart); |
---|
158 | close(cmd); |
---|
159 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd); |
---|
160 | (cmd | getline phend); |
---|
161 | close(cmd); |
---|
162 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">"; |
---|
163 | deltaStartSafety=-6; |
---|
164 | deltaEndSafety=6; |
---|
165 | } |
---|
166 | else { |
---|
167 | print type,"NOT YET SUPPORTED"; exit 1; |
---|
168 | } |
---|
169 | |
---|
170 | for (i=1; i<=nfile; i++) { |
---|
171 | diffstart = a_sigStart[i] - phstart; |
---|
172 | diffend = a_sigEnd[i] - phend; |
---|
173 | # print "file ",i," start ",a_sigStart[i],": diff <" diffstart ">:<" diffend ">"; |
---|
174 | if ( diffstart >= deltaStartSafety && diffend <= deltaEndSafety ) |
---|
175 | print "cycle ",cycle," file ",i-1," accepted ",a_sigFile[i]; |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | }' $inScaFile >> ${OUT1} |
---|
180 | |
---|
181 | OUT2=${TMP}/tmpselect2.$$ |
---|
182 | $AWK ' |
---|
183 | BEGIN { max=0 }; |
---|
184 | |
---|
185 | ($1=="cycle") { table[$2] = table[$2]","$4; if($2>max){max=$2} }; |
---|
186 | |
---|
187 | END { for (j=1;j<=max;j++) {print j,table[j];} } |
---|
188 | ' ${OUT1} >> ${OUT2} |
---|
189 | |
---|
190 | $AWK ' |
---|
191 | BEGIN { FS=","} |
---|
192 | { |
---|
193 | print "#"$1,$2","$NF",1"; |
---|
194 | } |
---|
195 | ' ${OUT2} |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | #for elem in ${!sigStart[*]} ; do |
---|
202 | # echo "index <${elem}>: file "${sigFile[${elem}]}" : start <"${sigStart[${elem}]}"> end <"${sigEnd[${elem}]}">" ; |
---|
203 | #done |
---|
204 | |
---|
205 | |
---|