source: BAORadio/AmasNancay/trunk/anarawonoffmaker.sh@ 632

Last change on this file since 632 was 626, checked in by campagne, 14 years ago

drift scan runs (jec)

  • Property svn:executable set to *
File size: 10.2 KB
RevLine 
[535]1#!/bin/sh -xvf
2#Perform the ON-OFF analysis
3DATE=/bin/date
4GREP=/bin/grep
5AWK=/bin/awk
6ECHO=/bin/echo
7WC=/usr/bin/wc
8CAT=/bin/cat
9PRINTF=/usr/bin/printf
10FIND=/usr/bin/find
11MKDIR=/bin/mkdir
12XARGS=/usr/bin/xargs
13SORT=/bin/sort
14RM=/bin/rm
15TR=/usr/bin/tr
16CP=/bin/cp
17LS=/bin/ls
18CHMOD=/bin/chmod
19
20DefaultIFS=$' \t\n'
21IFS=$DefaultIFS
22
23#set Irods environment
24. /usr/local/shared/bin/irods_env.sh -noverbose
25
26scriptName="`basename $0`"
27$ECHO "Processing script ${scriptName} at `date`"
28#which source to analyse
29
30#Process cmd line args: the -src option is mandatory (source name as Abell85)
31sourceRadio=
32dateSelected=
33#use -sim option to simulate processing (debug the script as if...)
34simulationMode=Off
35while [ $# -gt 0 ]
36 do
37 case "$1" in
38 -src) sourceRadio=$2; shift;;
[540]39 -date) dateSelected=$2; shift;;
40 -sim) simulationMode=On;;
41 -h)
42 echo >&2 \
43 "usage: $0 -src souce -date YYYYMMDD [-freq freq in MHz (default ${freqBAOCalib})] [-sim to trig simulation mode]"
44 exit 1;;
45 *) break;; # terminate while loop
46 esac
47 shift
[535]48done
49
50if [ ${simulationMode} = "On" ]; then
51 $ECHO "INFO ${scriptName} running in SIMUL mode"
52fi
53
54if [ "<${sourceRadio}>" = "<>" ]; then
55 $ECHO "FATAL: You have forgotten to select the source option (-src)"
56 exit 1
57fi
58
59case ${sourceRadio} in
60 Abell85) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
61 Abell2440) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
62 Abell1205) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
[601]63 NGC4383) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
[535]64 *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen"
65 exit 1;;
66esac
67
68srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
69
70#Path to public backupable path
71publicpath="/afs/in2p3.fr/home/c/campagne/public"
72
73
74#temporary files to synchronize scripts
75tmppublicpath=${TMPPUBLICPATH}
76#wakeup the NFS disk
77$LS -l ${tmppublicpath} > /dev/null
78#clean previous spurious files
79$RM -f ${tmppublicpath}/*.finished
80
81#Path where the job will do temporary IO
[579]82. ${SCRIPTPATH}/isInteractive.sh
83isInteractive=$(isInteractive)
84if [ ${isInteractive} == "1" ]; then
85 $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!"
86 exit 0;
[535]87fi
[579]88
89. ${SCRIPTPATH}/set_iojobpath.sh
90iojobpath=$(set_iojobpath)
[535]91cd ${iojobpath}
92
93localpath="${sourceRadio}"
94$MKDIR -p ./${localpath}
95cd ./${localpath}
96
97#save the top directory
98topDir=`pwd`
99
100#Path of the utility scripts
[575]101scriptpath=${SCRIPTPATH}
[535]102
[540]103#JEC 1/10/11 Use generic baodaqstatus name
[535]104#get the daq current irod status
[540]105#tag=`${DATE} +%F`
106#OUT1=${publicpath}/baodaqstatus-${tag}.txt
107OUT1=${publicpath}/baodaqstatus-current.txt
[535]108
109if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
[540]110 $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
111 exit 1
[535]112fi
113
114
115
116$ECHO "You have selected sourceRadio = ${sourceRadio} [date = ${dateSelected}]"
[626]117#JEC 14/12/11 One should take care of DR extension for Drift Scan
118#tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
119tableau=( `$GREP -i "${sourceRadio}/${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
[535]120IFS='
121'
122tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
123IFS=$DefaultIFS
124
125
126for i in ${tableau[@]}
127 do
128#
129# start a "fresh" session
130 cd ${topDir}
131 $LS | $XARGS -i $RM -rf {}
132
133 $ECHO "DEBUG: (${scriptName}) irods root dir $i"
134 dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
135
136 $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}"
137 $LS -lrt
138
139 gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l`
140 if [ ! ${gainDone} -gt 0 ]; then
141 $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` "
142 continue
143 fi
144
145######
146 $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}"
147#go to the .../source/date-sourcelowercase directory
148#download Off/datacycle<> and On/datacycle<> directories
149 $MKDIR -p ${topDir}/${dateDAQ}${srclower}
150 cd ${topDir}/${dateDAQ}${srclower}
151 aboveOnOffDir=`pwd`
152 $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>"
153#
154 mode="Off"
155 $ECHO "DEBUG (${scriptName}): START download the ${mode} data fits files"
156 inFileDirectory="./${mode}"
157 $MKDIR -p ${inFileDirectory}
158 listOfDataCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "datacycle"|$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` )
159 IFS='
160'
161 listOfDataCycle=( $( $PRINTF "%s\n" "${listOfDataCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
162 IFS=$DefaultIFS
163
164 firstCycleOff=`$ECHO ${listOfDataCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
165 nCyclesOff=`expr ${#listOfDataCycle[*]} - 1`
166
167 if [ ${nCyclesOff} -eq -1 ]; then
168 continue
169 fi
170
171 lastCycleOff=`$ECHO ${listOfDataCycle[${nCyclesOff}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
172
173 listOfDataCycle=( "${listOfDataCycle[@]/#/${i}/${mode}/}" )
174
175
176 for j in ${listOfDataCycle[@]}
177 do
178 irodsDownDir="${j}"
179 OUT=./getInFits.$$
180 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
181 igetStatus=`$GREP "^ERROR" ${OUT}`
182 if [ "<$igetStatus>" != "<>" ]; then
183 $ECHO "FATAL (${scriptName}): error while iget fits files:"
184 $ECHO $igetStatus
185 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
186 continue
187 fi
188 $RM -f ${OUT}
189 done
190 $ECHO "DEBUG (${scriptName}): END download the ${mode} data fits files"
191#
192 mode="On"
193 $ECHO "DEBUG (${scriptName}): START download the ${mode} data fits files"
194 inFileDirectory="./${mode}"
195 $MKDIR -p ${inFileDirectory}
196
197 listOfDataCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "datacycle" |$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` )
198 IFS='
199'
200 listOfDataCycle=( $( $PRINTF "%s\n" "${listOfDataCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
201 IFS=$DefaultIFS
202
203 firstCycleOn=`$ECHO ${listOfDataCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
204 nCyclesOn=`expr ${#listOfDataCycle[*]} - 1`
205
206 if [ ${nCyclesOn} -eq -1 ]; then
207 continue
208 fi
209
210 lastCycleOn=`$ECHO ${listOfDataCycle[${nCyclesOn}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
211
212 listOfDataCycle=( "${listOfDataCycle[@]/#/${i}/${mode}/}" )
213
214#
215#Check if there is the same number of cycles in Off and On mode
216#
217#first cycle = max(firstCycleOn, firstCycleOff)
218#last cycle = min(lastCycleOn,lastCycleOff)
219
220 if [ ${firstCycleOn} -eq ${firstCycleOff} -a ${lastCycleOn} -eq ${lastCycleOff} ]; then
221 firstCycle=${firstCycleOff}
222 lastCycle=${lastCycleOff}
223 else
224 $ECHO "INFO (${scriptName}): missmatch between Off and On mode"
225 $ECHO "${firstCycleOn} != ${firstCycleOff} OR ${lastCycleOn} != ${lastCycleOff}"
226 firstCycle=${firstCycleOff}
227 if [ ${firstCycleOn} -gt ${firstCycle} ]; then
228 firstCycle=${firstCycleOn}
229 fi
230 lastCycle=${lastCycleOff}
231 if [ ${lastCycleOn} -lt ${lastCycle} ]; then
232 lastCycle=${lastCycleOn}
233 fi
234 fi
235 $ECHO "INFO (${scriptName}): use cycles [${firstCycle}, ${lastCycle}]"
236
237
238 for j in ${listOfDataCycle[@]}
239 do
240 irodsDownDir="${j}"
241 OUT=./getInFits.$$
242 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
243 igetStatus=`$GREP "^ERROR" ${OUT}`
244 if [ "<$igetStatus>" != "<>" ]; then
245 $ECHO "FATAL (${scriptName}): error while iget fits files:"
246 $ECHO $igetStatus
247 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
248 continue
249 fi
250 $RM -f ${OUT}
251 done
252 $ECHO "DEBUG (${scriptName}): END download the ${mode} data fits files"
253#Get sca file
254 $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}"
255 OUT1=./getScaStatus.$$
[599]256# $RM -f ${tmppublicpath}/getscafiles.finished
[535]257 ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
[595]258# while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
259# $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
260# date +%T
261# sleep 30
262# done
[599]263# $RM ${tmppublicpath}/getscafiles.finished
[535]264 $ECHO "DEBUG (${scriptName}): END"
265#
266 getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
267#
268 if [ "<${getScaStatus}>" != "<>" ]; then
269 $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ"
270 $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
271 $CAT ${OUT1}
272 $ECHO "DEBUG (${scriptName}): END"
273 continue
274 fi
275 $RM -f ${OUT1}
276
277 scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}`
278
279
280#prepare job submission
281 cd ${aboveOnOffDir}
282#the default spectra name is medfiltmtx, otherwise use -specname <a_string>
283
284 logFile="analyse_RAWDATA_${sourceRadio}_${dateDAQ}.log"
285 $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`"
286 if [ ${simulationMode} = "On" ]; then
287 $ECHO "SIMUL: ${scriptpath}/Objs/analyse -act rawOnOff -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir datacycle -numcycle ${firstCycle},${lastCycle} -debug 1 >& ${logFile}"
288 cat > ${logFile} <<EOF
289 Ok rawOnOff finished
290EOF
291 else
292 ${scriptpath}/Objs/analyse -act rawOnOff -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir datacycle -numcycle ${firstCycle},${lastCycle} -debug 1 >& ${logFile}
293 fi
294 $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods"
295 rcstatus=`$GREP -i "Ok rawOnOff finished" ${logFile} | $WC -l`
296 if [ ${rcstatus} -eq 0 ]; then
297 $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}"
298 $ECHO " START logfile"
299 $CAT ${logFile}
300 $ECHO " END logFile"
301#clean and leave
302 cd ${aboveOnOffDir}
303 $LS | $XARGS -i $RM -rf {}
304 continue
305 fi
306#Save into Irods
307 $ECHO "DEBUG (${scriptName}): START save output files"
308 $LS ${aboveOnOffDir}
309#use -f option for iput ONLY to force override
310 if [ ${simulationMode} = "On" ]; then
311 $ECHO "SIMUL: here we look for output files and put them in Irods"
312 else
313 $LS -lrth
314 $FIND . -name "dataRaw_*" -print | $XARGS -i iput -f -v -K {} ${i}
315 $FIND . -name "diffOnOffRaw_*" -print | $XARGS -i iput -f -v -K {} ${i}
316 fi
317#save analysis logfile
318 $LS -l ${tmppublicpath} > /dev/null
319 $CP ${logFile} ${tmppublicpath}
320 $ECHO "DEBUG (${scriptName}): END save output files"
321#clean up to avoid scratch SIZE EXCEED LIMIT
322 cd ${aboveOnOffDir}
323 $LS | $XARGS -i $RM -rf {}
324
325done
326
327exit 0
Note: See TracBrowser for help on using the repository browser.