source: BAORadio/AmasNancay/trunk/select.sh

Last change on this file was 626, checked in by campagne, 13 years ago

drift scan runs (jec)

File size: 6.6 KB
Line 
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
35tmppublicpath=${TMPPUBLICPATH}
36$LS -l ${tmppublicpath} > /dev/null
37
38
39#Path of the utility scripts
40scriptpath=${SCRIPTPATH}
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    ONDS) 
60    $ECHO "INFO (${scriptName}): filter signal files for ON Drift Scan phases";;
61    OFF) 
62    $ECHO "INFO (${scriptName}): filter signal files for OFF phases";;
63    MEANON) 
64    $ECHO "INFO (${scriptName}): filter signal files for MEANON phases";;
65    MEANOFF) 
66    $ECHO "INFO (${scriptName}): filter signal files for MEANOFF phases";;
67    CALIBON) 
68    $ECHO "INFO (${scriptName}): filter signal files for CALIBRATION ON phases";;
69    CALIBOFF) 
70    $ECHO "INFO (${scriptName}): filter signal files for CALIBRATION OFF phases";;
71    GAIN) 
72    $ECHO "INFO (${scriptName}): filter signal files for GAIN = CALIB OFF phases";;
73    GAINNF)
74    $ECHO "INFO (${scriptName}): filter signal files for GAINNF = GAIN wo filt. freq.";;
75    GAINDS)
76    $ECHO "INFO (${scriptName}): filter signal files for GAINDS = GAIN for Drift Scan";;
77    *) 
78    $ECHO "FATAL (${scriptName}): use ON|OFF|MEANON|MEANOFF|CALIBON|CALIBOFF phase tags."
79    exit 1
80    ;;
81esac
82
83
84#################
85#fill the arrays association header file with start/end date&time
86# arrays
87declare -a sigStart
88declare -a sigEnd
89declare -a sigFile
90
91for fullfile in $( $FIND $inFiberDir -name "header*" | $XARGS -i basename {} | $SORT -k1.7n)
92  do
93  filename=$(basename $fullfile)
94  extension=${filename##*.}
95  filename=${filename%.*}
96  ffn=${inFiberDir}/${filename}.${extension}
97#  echo "process $ffn"
98  while read -n80 L
99    do
100    [ "${L::3}" = "END" ] && break
101    echo $L
102  done < $ffn > $OUT1
103 
104  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];}' `
105 
106  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];}' `
107 
108  if [[ -n "$strStart"  &&  -n "$strEnd" ]]; then
109      timeStart=`${DATE} +%s -d "${strStart}"`
110      timeEnd=`${DATE} +%s -d "${strEnd}"`
111#      echo "$fullfile start $strStart   <$timeStart>, end  $strEnd <$timeEnd>"
112      sigStart[${#sigStart[*]}]=$timeStart
113      sigEnd[${#sigEnd[*]}]=$timeEnd
114      sigFile[${#sigFile[*]}]=$filename
115  else
116      $ECHO "WARNING (${scriptName}): $ffn PATHOLOGIQUE"
117  fi
118done
119
120############
121#scan all the cycles
122#  calib1start=$2; calib1end=$3;
123#  data1start=$4; data1end=$5;
124#  calib2start=$6; calib2end=$7;
125#  data2start=$8; data2end=$9;
126#to pass to awk: use a "," as field separator
127awk_sigStart=$( printf "%s," "${sigStart[@]}" )
128awk_sigEnd=$( printf "%s," "${sigEnd[@]}" )
129awk_sigFile=$( printf "%s," "${sigFile[@]}" )
130
131#attention a la derniere "," pour le calcul de nfile
132OUT1=./tmpselect1.$$
133#selection d'une seul cycle pour debug
134$AWK -v datesys=$DATE -v type=$inTypeOfPhase -v str_sigStart="$awk_sigStart"  -v str_sigEnd="$awk_sigEnd"  -v str_sigFile="$awk_sigFile" '
135BEGIN {
136  FS=",";
137  split(str_sigStart,a_sigStart,",");
138  split(str_sigEnd,a_sigEnd,",");
139  nfile=split(str_sigFile,a_sigFile,",");
140  delete a_sigFile[nfile];
141  delete a_sigStart[nfile];
142  delete a_sigEnd[nfile];
143  nfile--; 
144
145}
146
147 {
148  cycle=$1;
149
150  if ( (type == "ON") || (type == "MEANON" || (type == "ONDS")) ) {
151    phaseStart=$4; phaseEnd=$5;
152    cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
153    (cmd | getline phstart);
154    close(cmd);
155    cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd);
156    (cmd | getline phend);
157    close(cmd);
158    # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">";
159    deltaStartSafety=4;
160    deltaEndSafety=-4;
161  }
162  else if ( (type == "OFF") || (type == "MEANOFF") ) {
163    phaseStart=$8; phaseEnd=$9;
164    cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
165    (cmd | getline phstart);
166    close(cmd);
167    cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd);
168    (cmd | getline phend);
169    close(cmd);
170    # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">";
171    deltaStartSafety=4;
172    deltaEndSafety=-4;
173  }
174  else if ( (type == "CALIBON") || (type == "GAINDS") ) {
175    phaseStart=$2; phaseEnd=$3;
176    print "Phase: ",type," cycle: ",cycle,": <",phaseStart,">:<",phaseEnd,">";
177    cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
178    (cmd | getline phstart);
179    close(cmd);
180    cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd);
181    (cmd | getline phend);
182    close(cmd);
183#    print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">";
184    deltaStartSafety=-6;
185    deltaEndSafety=6;
186  }
187  else if ( (type == "CALIBOFF") || (type == "GAIN") || (type == "GAINNF")) {
188    phaseStart=$6; phaseEnd=$7;
189    cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
190    (cmd | getline phstart);
191    close(cmd);
192    cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd);
193    (cmd | getline phend);
194    close(cmd);
195    # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">";
196    deltaStartSafety=-6;
197    deltaEndSafety=6;
198  }
199  else {
200    print "FATAL: ",type," NOT YET SUPPORTED"; exit 1;
201  }
202
203  for (i=1; i<=nfile; i++) {
204    diffstart = a_sigStart[i] - phstart;
205    diffend   = a_sigEnd[i] - phend;
206#     print "file ",i," start ",a_sigStart[i],": diff <" diffstart ">:<" diffend ">";
207    if ( diffstart >= deltaStartSafety && diffend <= deltaEndSafety )
208       print "cycle ",cycle," file ",i-1," accepted ",a_sigFile[i];
209  } 
210     
211
212}' $inScaFile > ${OUT1}
213
214OUT2=./tmpselect2.$$
215$AWK '
216BEGIN { max=0; min=999999; };
217
218($1=="cycle") { table[$2] = table[$2]","$4; if($2>max){max=$2}; if($2<min){min=$2} };
219
220END { for (j=min;j<=max;j++) {print j,table[j];} }
221' ${OUT1} > ${OUT2}
222
223$AWK '
224BEGIN { FS=","}
225{
226 print "#"$1,$2","$NF",1";
227}
228' ${OUT2}
229
230$RM $OUT1
231$RM $OUT2
232
233exit 0
Note: See TracBrowser for help on using the repository browser.