source: BAORadio/AmasNancay/trunk/select.sh@ 589

Last change on this file since 589 was 579, checked in by torrento, 14 years ago

version adaptee a grid engin (ana)

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