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

Last change on this file since 624 was 601, checked in by campagne, 14 years ago

add NGC4383 src (jec)

  • Property svn:executable set to *
File size: 10.5 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}]"
123tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
124IFS='
125'
126tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
127IFS=$DefaultIFS
128
129
130for i in ${tableau[@]}
131 do
132#
133# start a "fresh" session
134 cd ${topDir}
135 $LS | $XARGS -i $RM -rf {}
136
137
138 $ECHO "DEBUG: (${scriptName}) irods root dir $i"
139 dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
140
141 $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}"
142 $LS -lrt
143
144
145# alreadyDone=`ils ${i} 2>&1 | $GREP -i "calib_.*\.txt" | $WC -l`
146# if [ ${alreadyDone} -gt 0 ]; then
147# $ECHO "INFO (${scriptName}): calibration coef files already exist"
148# continue
149# fi
150
151 gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l`
152 if [ ! ${gainDone} -gt 0 ]; then
153 $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` "
154 continue
155 fi
156
157######
158 $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}"
159#go to the .../source/date-sourcelowercase directory
160#download Off/calibcycle<> and On/calibcycle<> directories
161 $MKDIR -p ${topDir}/${dateDAQ}${srclower}
162 cd ${topDir}/${dateDAQ}${srclower}
163 aboveOnOffDir=`pwd`
164 $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>"
165#
166 mode="Off"
167 $ECHO "DEBUG (${scriptName}): START download the ${mode} calib fits files"
168 inFileDirectory="./${mode}"
169 $MKDIR -p ${inFileDirectory}
170 listOfCalibCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "calibcycle"|$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.11n` )
171 IFS='
172'
173 listOfCalibCycle=( $( $PRINTF "%s\n" "${listOfCalibCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
174 IFS=$DefaultIFS
175
176 firstCycleOff=`$ECHO ${listOfCalibCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
177 nCyclesOff=`expr ${#listOfCalibCycle[*]} - 1`
178
179 lastCycleOff=`$ECHO ${listOfCalibCycle[${nCyclesOff}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
180
181 listOfCalibCycle=( "${listOfCalibCycle[@]/#/${i}/${mode}/}" )
182
183
184 for j in ${listOfCalibCycle[@]}
185 do
186 irodsDownDir="${j}"
187 OUT=./getInFits.$$
188 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
189 igetStatus=`$GREP "^ERROR" ${OUT}`
190 if [ "<$igetStatus>" != "<>" ]; then
191 $ECHO "FATAL (${scriptName}): error while iget fits files:"
192 $ECHO $igetStatus
193 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
194 continue
195 fi
196 $RM -f ${OUT}
197 done
198 $ECHO "DEBUG (${scriptName}): END download the ${mode} calib fits files"
199#
200 mode="On"
201 $ECHO "DEBUG (${scriptName}): START download the ${mode} calib fits files"
202 inFileDirectory="./${mode}"
203 $MKDIR -p ${inFileDirectory}
204
205 listOfCalibCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "calibcycle" |$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.11n` )
206 IFS='
207 '
208 listOfCalibCycle=( $( $PRINTF "%s\n" "${listOfCalibCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
209 IFS=$DefaultIFS
210
211 firstCycleOn=`$ECHO ${listOfCalibCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
212 nCyclesOn=`expr ${#listOfCalibCycle[*]} - 1`
213
214 lastCycleOn=`$ECHO ${listOfCalibCycle[${nCyclesOn}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
215
216 listOfCalibCycle=( "${listOfCalibCycle[@]/#/${i}/${mode}/}" )
217
218
219#
220#Check if there is the same number of cycles in Off and On mode
221#
222#first cycle = max(firstCycleOn, firstCycleOff)
223#last cycle = min(lastCycleOn,lastCycleOff)
224
225 if [ ${firstCycleOn} -eq ${firstCycleOff} -a ${lastCycleOn} -eq ${lastCycleOff} ]; then
226 firstCycle=${firstCycleOff}
227 lastCycle=${lastCycleOff}
228 else
229 $ECHO "INFO (${scriptName}): missmatch between Off and On mode"
230 $ECHO "${firstCycleOn} != ${firstCycleOff} OR ${lastCycleOn} != ${lastCycleOff}"
231 firstCycle=${firstCycleOff}
232 if [ ${firstCycleOn} -gt ${firstCycle} ]; then
233 firstCycle=${firstCycleOn}
234 fi
235 lastCycle=${lastCycleOff}
236 if [ ${lastCycleOn} -lt ${lastCycle} ]; then
237 lastCycle=${lastCycleOn}
238 fi
239 fi
240 $ECHO "INFO (${scriptName}): use cycles [${firstCycle}, ${lastCycle}]"
241
242
243 for j in ${listOfCalibCycle[@]}
244 do
245 irodsDownDir="${j}"
246 OUT=./getInFits.$$
247 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
248 igetStatus=`$GREP "^ERROR" ${OUT}`
249 if [ "<$igetStatus>" != "<>" ]; then
250 $ECHO "FATAL (${scriptName}): error while iget fits files:"
251 $ECHO $igetStatus
252 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
253 continue
254 fi
255 $RM -f ${OUT}
256 done
257 $ECHO "DEBUG (${scriptName}): END download the ${mode} calib fits files"
258#Get sca file
259 $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}"
260 OUT1=./getScaStatus.$$
261 $RM -f ${tmppublicpath}/getscafiles.finished
262 ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
[584]263# while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
264# $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
265# date +%T
266# sleep 30
267# done
[570]268 $RM ${tmppublicpath}/getscafiles.finished
269 $ECHO "DEBUG (${scriptName}): END"
270#
271 getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
272#
273 if [ "<${getScaStatus}>" != "<>" ]; then
274 $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ"
275 $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
276 $CAT ${OUT1}
277 $ECHO "DEBUG (${scriptName}): END"
278 continue
279 fi
280 $RM -f ${OUT1}
281
282 scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}`
283
284#prepare job submission
285 cd ${aboveOnOffDir}
286#the default spectra name is medfiltmtx, otherwise use -specname <a_string>
287
288 logFile="analyse_CALIB_${sourceRadio}_${dateDAQ}.log"
289 $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`"
290 if [ ${simulationMode} = "On" ]; then
[584]291 $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]292 cat > ${logFile} <<EOF
293 Ok calibration finished
[572]294EOF
295#WARNING: the EOF must start at 1st column overwise the rest of the script is part of the file cat...
[570]296 else
[585]297 ${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]298 fi
[572]299#
[570]300 $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods"
301 rcstatus=`$GREP -i "Ok calibration finished" ${logFile} | $WC -l`
302 if [ ${rcstatus} -eq 0 ]; then
303 $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}"
304 $ECHO " START logfile"
305 $CAT ${logFile}
306 $ECHO " END logFile"
307#clean and leave
308 cd ${aboveOnOffDir}
309 $LS | $XARGS -i $RM -rf {}
310 continue
311 fi
312#Save into Irods
313 $ECHO "DEBUG (${scriptName}): START save output files"
314 $LS ${aboveOnOffDir}
315#use -f option for iput ONLY to force override
316 if [ ${simulationMode} = "On" ]; then
317 $ECHO "SIMUL: here we look for calib file and put them in Irods"
318 else
319 $LS -lrth
[585]320 $FIND . -name "calib_*" -print | $XARGS -i iput -f -v -K {} ${i}
[570]321 fi
322#save analysis logfile
323 $LS -l ${tmppublicpath} > /dev/null
324 $CP ${logFile} ${tmppublicpath}
325 $ECHO "DEBUG (${scriptName}): END save output files"
326#clean up to avoid scratch SIZE EXCEED LIMIT
327 cd ${aboveOnOffDir}
328 $LS | $XARGS -i $RM -rf {}
329
330done
331
332exit 0
Note: See TracBrowser for help on using the repository browser.