source: BAORadio/AmasNancay/trunk/anacalibmaker.sh@ 628

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

drift scan runs (jec)

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