source: BAORadio/AmasNancay/trunk/proc_specmfib.sh@ 580

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

version adaptee a grid engin (ana)

  • Property svn:executable set to *
File size: 15.3 KB
RevLine 
[535]1#!/bin/sh -xvf
2#Basic tuning of system fuction used.
3AWK=/bin/awk
4SED=/bin/sed
5GREP=/bin/grep
6WC=/usr/bin/wc
7RM=/bin/rm
8CAT=/bin/cat
9TOUCH=/bin/touch
10DATE=/bin/date
11ECHO=/bin/echo
12LS=/bin/ls
13MKDIR=/bin/mkdir
14TR=/usr/bin/tr
15FIND=/usr/bin/find
16PRINTF=/usr/bin/printf
17XARGS=/usr/bin/xargs
18SORT=/bin/sort
19QSUB=qsub
20
21DefaultIFS=$' \t\n'
22IFS=$DefaultIFS
23
24
25scriptName="`basename $0`"
26$ECHO "Processing script ${scriptName} at `date`"
27######
28# Local functions
29######
30usage() {
31 echo "usage: $scriptName <source> <YYYYMMDD-directory> <type of process>"
32 echo " -<source> as Abell85"
33 echo " -<YYYYMMDD-directory> as 20110428"
34 echo " -<type of process> as GAIN|CALIBON|CALIBOFF|ON|OFF"
35}
36######
37# argument test
38######
39
40#Process cmd line args: the -src option is mandatory (source name as Abell85)
[555]41#action: gain|mspec (gain: gain-like doucble median filtering
42# mspec: mean+sigma wo filetring)
43action="gain"
[535]44sourceRadio=
45dateSelected=
46typeofproc=
47#use -sim option to simulate processing (debug the script as if...)
48simulationMode=Off
49#
50#first and last cycle to process
51#
52firstCycle=
53lastCycle=
54while [ $# -gt 0 ]
55do
56 case "$1" in
[555]57 -act) action=$2; shift;;
[535]58 -src) sourceRadio=$2; shift;;
[555]59 -date) dateSelected=$2; shift;;
60 -type) typeofproc=$2; shift;;
61 -fcycle) firstCycle=$2; shift;;
62 -lcycle) lastCycle=$2; shift;;
[535]63 -sim) simulationMode=On;;
64 -h)
65 echo >&2 \
[575]66 "usage: $0 [-act <action> ] -src souce -date YYYYMMDD -type type [-fcycle firstCycle] [-lcycle lastCycle] [-sim to trig simulation mode]"
[535]67 exit 1;;
68 *) break;; # terminate while loop
69 esac
70 shift
71done
72
73#Check input
74
75if [ "<${sourceRadio}>" = "<>" ]; then
76 $ECHO "FATAL: You have forgotten to select the source option (-src)"
77 exit 1
78fi
79
80if [ "<${dateSelected}>" = "<>" ]; then
81 $ECHO "FATAL: You have forgotten to select the date option (-date)"
82 exit 1
83fi
84
85if [ "<${typeofproc}>" = "<>" ]; then
86 $ECHO "FATAL: You have forgotten to select the type option (-type)"
87 exit 1
[570]88
[535]89fi
[570]90#else
91# offtype=`$ECHO ${typeofproc} | $GREP -i OFF | $WC -l`
92# ontype=`$ECHO ${typeofproc} | $GREP -i ON | $WC -l`
93# if [ "<${offtype}>" = "<1>" -a "<${ontype}>" = "<0>" ]; then
94# datatype="OFF"
95# elif [ "<${offtype}>" = "<0>" -a "<${ontype}>" = "<1>" ]; then
96# datatype="ON"
97# else
98# $ECHO "FATAL: not supported: -type ${typeofproc}"
99# exit 1
100# fi
101#fi
[535]102
103
104srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
105
106
107#Path to public backupable path
108publicpath="/afs/in2p3.fr/home/c/campagne/public"
109
110#temporary files to synchronize scripts
111tmppublicpath=${TMPPUBLICPATH}
112$LS -l ${tmppublicpath} > /dev/null
113
114
115#Path where the job will do temporary IO
[579]116. ${SCRIPTPATH}/set_iojobpath.sh
117iojobpath=$(set_iojobpath)
[535]118cd ${iojobpath}
119
120localpath="${sourceRadio}/${dateSelected}${srclower}"
121$MKDIR -p ./${localpath}
122cd ./${localpath}
123mainDirectory=`pwd`
124
125
126#Path of the utility scripts
[575]127scriptpath=${SCRIPTPATH}
[535]128
129
130#select file per cycle
131#$ECHO "Select files process..."
132#keep only lines with structure: cycle_number first,last,step
133#Get sca files
134$ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateSelected}"
135OUT1=./getScaStatus.$$
[540]136#JEC 29/9/11 avoid finished stuff
137#$RM -f ${tmppublicpath}/getscafiles.finished
[535]138${scriptpath}/getscafiles.sh ${sourceRadio} ${dateSelected} > ${OUT1} 2>&1
[540]139#while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
140# $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
141# date +%T
142# sleep 30
143#done
144#$RM -f ${tmppublicpath}/getscafiles.finished
[535]145$ECHO "DEBUG (${scriptName}): END"
146
147
148getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
149
150if [ "<${getScaStatus}>" != "<>" ]; then
151 $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateSelected"
152 $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
153 $CAT ${OUT1}
154 $ECHO "DEBUG (${scriptName}): END"
155 exit 1
156fi
157
158
159scaFileSummarized=`$FIND . -name "sca*.sum" -print`
160if [ "<${scaFileSummarized}>" = "<>" ]; then
161 $ECHO "FATAL (${scriptName}): strange sca file summarized not available: $sourceRadio $dateSelected"
162 $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
163 $CAT ${OUT1}
164 $ECHO "DEBUG (${scriptName}): END"
165 exit 1
166fi
167$RM ${OUT1}
168
169scaFileSummarized=`basename $scaFileSummarized`
170
171#set Irods environment
172. /usr/local/shared/bin/irods_env.sh -noverbose
173#download header files to be used for signal files selction
174$MKDIR -p ./Fiber1
175dirFiberfile=`pwd`/Fiber1
176
177dirIrods="/baoradio/data/AmasNancay/${sourceRadio}/${dateSelected}${srclower}/Fiber1"
178
179listOfFiles=( `ils ${dirIrods} | $GREP -i "header" | $XARGS -i basename {} | $SORT -k1.7n` )
180IFS='
181'
182listOfFiles=( $( $PRINTF "%s\n" "${listOfFiles[@]}" | $AWK 'x[$0]++ == 0' ) )
183IFS=$DefaultIFS
184
185#
186$ECHO "DEBUG (${scriptName}): Download if necessary the headers"
187#
188for ifile in ${listOfFiles[@]}
189do
190#test if the headers have not yet been downloaded
191 if [ ! -e ${dirFiberfile}/${ifile} ]; then
192 OUT2=./getheaders.$$
193 iget -f -K ${dirIrods}/${ifile} ${dirFiberfile} >${OUT2} 2>&1
194 igetStatus=`$GREP "^ERROR" ${OUT2}`
195 if [ "<$igetStatus>" != "<>" ]; then
196 $ECHO "FATAL (${scriptName}): error while iget:"
197 $ECHO $igetStatus
198 exit 1
199 fi
200 $RM -f $OUT2
201 fi
202done
203#
204$ECHO "DEBUG (${scriptName}): START call select.sh ${scaFileSummarized} ${dirFiberfile} ${typeofproc}"
205#
206#Get list of file to process
207headerFileSelected=./selectSignal.$$
[540]208#JEC 29/9/11 avoid finished stuff
209#$RM -f ${tmppublicpath}/select.finished
[570]210${scriptpath}/select.sh ${scaFileSummarized} ${dirFiberfile} ${typeofproc} | $GREP "^#[0-9]" | $SED "s/^#//" > $headerFileSelected
[540]211#while [ ! -f "${tmppublicpath}/select.finished" ]; do
212# $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/select.finished"
213# date +%T
214# sleep 30
215#done
216#$RM ${tmppublicpath}/select.finished
[535]217#
218$ECHO "DEBUG (${scriptName}): END"
219#
220$ECHO "DEBUG (${scriptName}): START filling cycleArray, filesArray"
221#
222declare -a cycleArray
223declare -a filesArray
224$ECHO "DEBUG (${scriptName}): IFS value between<>: <$IFS>"
225IFS=$DefaultIFS
226$ECHO "DEBUG (${scriptName}): START cat $headerFileSelected"
227$CAT $headerFileSelected
228$ECHO "DEBUG (${scriptName}): END cat $headerFileSelected"
229
230while read v1 v2
231do
232 cycleArray[${#cycleArray[*]}]=$v1
233 filesArray[${#filesArray[*]}]=$v2
234done < $headerFileSelected
235
236if [ ${#cycleArray[*]} -eq 0 -o ${#filesArray[*]} -eq 0 ]; then
237 $ECHO "FATAL (${scriptName}): no header file selected (${#cycleArray[*]}, ${#filesArray[*]})"
238 exit 1
239else
240 $ECHO "DEBUG (${scriptName}): non zero elements found for cycleArray and filesArray"
241fi
242
243#
244$ECHO "DEBUG (${scriptName}): number of elements <${#cycleArray[*]}> <${#filesArray[*]}>"
245$ECHO "DEBUG (${scriptName}): END"
246#
247# (timeShift)
248#Add 3sec to start ON / OFF
249#Substract 4sec to start DAB ON / OFF
250#
251#Take care: Cycle numbering starts at 1 in SCAFiles while Arrays index start at 0
252#
253#for GAIN the reference cycle takes the middle of the run
254#
255#nwinmean donne le nombre de fenetre tspwin utilise pour faire calculer la moyenne des medianes de chaque fenetre
256#This is the nimber of paquets of the time window which change according to processing type
257$ECHO "DEBUG (${scriptName}): START switch on $typeofproc"
258#
259case "$typeofproc" in
260 GAIN)
261 $ECHO "process signal files for GAIN phase"
262 ingain=""
263 freqfilter="-freqfilter -"
264 nwinmean="1"
265 tspwin="5120"
266 dirName="Off"
267 cyclebasename="gaincycle"
268 indexStartHour="6"
269 timeShift="-4"
270 timeDuration="14"
271 firstCycleId=`expr ${#cycleArray[*]} / 2`
272 firstCycleId=`expr ${firstCycleId} - 1`
273 lastp1CycleId=`expr ${firstCycleId} + 1`
274 ;;
275 ON)
276 $ECHO "process signal files for ON phases"
277 ingain="-gain gain_${dateSelected}_${srclower}.fits"
[566]278 freqfilter=""
[535]279 nwinmean="5"
280 tspwin="5120"
281 dirName="On"
282 cyclebasename="datacycle"
283 indexStartHour="4"
284 timeShift="3"
285 timeDuration="30"
286 firstCycleId="0"
287 lastp1CycleId="${#cycleArray[@]}"
288 ;;
289 OFF)
290 $ECHO "process signal files for OFF phases"
291 ingain="-gain gain_${dateSelected}_${srclower}.fits"
[566]292 freqfilter=""
[535]293 nwinmean="5"
294 tspwin="5120"
295 dirName="Off"
296 cyclebasename="datacycle"
297 indexStartHour="8"
298 timeShift="3"
299 timeDuration="30"
300 firstCycleId="0"
301 lastp1CycleId="${#cycleArray[@]}"
302 ;;
[555]303 MEANOFF)
304 $ECHO "process signal files for OFF phases (MEAN)"
305 ingain="-gain gain_${dateSelected}_${srclower}.fits"
[556]306 nwinmean="25000"
307 tspwin="1"
[555]308 dirName="Off"
309 cyclebasename="meancycle"
310 indexStartHour="8"
311 timeShift="3"
312 timeDuration="30"
313 firstCycleId="0"
314 lastp1CycleId="${#cycleArray[@]}"
315 ;;
316 MEANON)
317 $ECHO "process signal files for OFF phases (MEAN)"
318 ingain="-gain gain_${dateSelected}_${srclower}.fits"
[556]319 nwinmean="25000"
320 tspwin="1"
[555]321 dirName="On"
322 cyclebasename="meancycle"
323 indexStartHour="8"
324 timeShift="3"
325 timeDuration="30"
326 firstCycleId="0"
327 lastp1CycleId="${#cycleArray[@]}"
328 ;;
[535]329 CALIBON)
330 $ECHO "process signal files for CALIBRATION ON phases"
331 ingain="-gain gain_${dateSelected}_${srclower}.fits"
[566]332 freqfilter=""
[535]333 nwinmean="1"
334 tspwin="1024"
335 dirName="On"
336 cyclebasename="calibcycle"
337 indexStartHour="2"
338 timeShift="-4"
339 timeDuration="14"
340 firstCycleId="0"
341 lastp1CycleId="${#cycleArray[@]}"
342 ;;
343 CALIBOFF)
344 $ECHO "process signal files for CALIBRATION OFF phases"
345 ingain="-gain gain_${dateSelected}_${srclower}.fits"
[566]346 freqfilter=""
[535]347 nwinmean="1"
348 tspwin="1024"
349 dirName="Off"
350 cyclebasename="calibcycle"
351 indexStartHour="6"
352 timeShift="-4"
353 timeDuration="14"
354 firstCycleId="0"
355 lastp1CycleId="${#cycleArray[@]}"
356 ;;
357 *)
358 $ECHO "FATAL (${scriptName}): type of processing"
359 usage
360 exit 1
361 ;;
362esac
363#
364$ECHO "DEBUG (${scriptName}): END"
365#
366#
367#Compute time windows (Warning usage of GMT date)
368#
369$ECHO "DEBUG (${scriptName}): START compute time windows"
370OUT=./baotiming.$$
371${AWK} -v datesys=${DATE} -v type=${indexStartHour} -v shift=${timeShift} '
372BEGIN {FS=","}
373{
374 phaseStart=$type
375 cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart);
376 (cmd | getline phstart);
377 close(cmd);
378 newstart = phstart+shift;
379 cmd=sprintf("%s +%%T -d \"1970-01-01 %s sec GMT\"",datesys,newstart);
380 (cmd | getline newStart);
381 close(cmd);
382 print $1,newStart,phaseStart;
383}
384' ${scaFileSummarized} > ${OUT}
385#
386$ECHO "DEBUG (${scriptName}): END"
387#
388$ECHO "DEBUG (${scriptName}): START cat ${OUT}"
389$CAT ${OUT}
390$ECHO "DEBUG (${scriptName}): END cat ${OUT}"
391#
392$ECHO "DEBUG (${scriptName}): START filling cylceArrayBis timeArray"
393#
394declare -a cycleArrayBis
395declare -a timeArray
396$ECHO "DEBUG (${scriptName}): IFS value between<>: <$IFS>"
397IFS=$DefaultIFS
398#select the selected cycles
399idtofind="0"
400while read v1 v2 v3
401do
402 if [ ${idtofind} -lt ${#cycleArray[*]} ]; then
403 if [ ${v1} = ${cycleArray[${idtofind}]} ]; then
404 cycleArrayBis[${#cycleArrayBis[*]}]=$v1
405 timeArray[${#timeArray[*]}]=$v2
406 idtofind=`expr ${idtofind} + 1`
407 fi
408 fi
409done < ${OUT}
410$ECHO "DEBUG (${scriptName}): number of elements ${#cycleArrayBis[*]} ${#timeArray[*]}"
411$ECHO "DEBUG (${scriptName}): END"
412
413
414#########################
415# specmfib exe
416#########################
417prg="/afs/in2p3.fr/throng/baoradio/Library/Progs/TAcq/Objs/specmfib"
418if [ ! -e $prg ]; then
419 $ECHO "FATAL (${scriptName}): $prg not found"
420 exit 1
421fi
422
423
424dirFiberfile=${iojobpath}/${localpath}
425
426curDir=`pwd`
427#
428$ECHO "DEBUG (${scriptName}): in principle $dirFiberfile == $curDir "
429#
430#force single channel
431forceSingle="-singlechan"
432#debug
433prtlevel="1"
434
435
436#Loop on cycles
437##
438$ECHO "DEBUG (${scriptName}): START loop on cycles Ids ${firstCycleId} to ${lastp1CycleId}"
439
440#write the script to be send to Batch
441#get gain file if necessary
442if [ ${typeofproc} != "GAIN" ]; then
443 OUT2=./igetStatus.$$
444 iget /baoradio/data/AmasNancay/${localpath}/gain_${dateSelected}_${srclower}.fits >${OUT2} 2>&1
445 igetStatus=`$GREP "^ERROR" ${OUT2}`
446 if [ "<${igetStatus}>" != "<>" ]; then
447 $ECHO "FATAL (${scriptName}): error while iget:"
448 $ECHO $igetStatus
449 exit 1
450 fi
451 $RM ${OUT2}
452fi
453
454
455for ((i=${firstCycleId};i<${lastp1CycleId};i++)); do
456#
[540]457
458####
459# Check daq status
460#JEC 1/10/11 Use generic baodaqstatus name
461####
462#get the daq current irod status
463#tag=`${DATE} +%F`
464#OUT1=${publicpath}/baodaqstatus-${tag}.txt
465OUT1=${publicpath}/baodaqstatus-current.txt
466
467if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
468 $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
469 exit 1
470# $ECHO "We should bring the DAQ status more up to date, this take 1 or 2min..."
471#JEC 29/9/11 avoid finished stuff
472# $RM -f ${tmppublicpath}/statusdaq.finished
473# ${scriptpath}/statusdaq.sh > ${OUT1}
474# while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
475# sleep 30
476# done
477# $RM ${tmppublicpath}/statusdaq.finished
478#protect against remove/rewriting
479# $CHMOD -v 444 ${OUT1}
480fi
481
[535]482#time window selection
483 tmproc="-tmproc ${timeArray[${i}]},${timeDuration}"
484#cycle <number>
485 cycle="${cycleArray[${i}]}"
486 if [ "<${firstCycle}>" != "<>" -a "<${lastCycle}>" != "<>" ]; then
487 if [ ${cycle} -lt ${firstCycle} -o ${cycle} -gt ${lastCycle} ]; then
488 continue
489 fi
490 fi
491 $ECHO "DEBUG (${scriptName}): process cycle $cycle"
492
493#cycle <name><number>
494 cycle="${cyclebasename}${cycleArray[${i}]}"
495#signal files selection
496 infiles="${filesArray[${i}]}"
497#
498#Prepare BQS parameters: MEMORY, CPU...#
499 infilesArray=( `$ECHO $infiles | $AWK 'BEGIN {FS=","} {for(i=1;i<NF;i++)print $i;}'` )
500 IFS='
501 '
502 infilesArray=( $( printf "%s\n" "${infilesArray[@]}" | awk 'x[$0]++ == 0' ) )
503 IFS=$DefaultIFS
504 firstFile=${infilesArray[0]}
505 lastFile=${infilesArray[1]}
506#
507#
508#
509#get signals files
510 OUT3=./getsignals.$$
[540]511#JEC 29/9/11 avoid finished stuff
512# $RM -f ${tmppublicpath}/getsignalfiles.finished
[535]513 ${scriptpath}/getsignalfiles.sh ${sourceRadio} ${dateSelected} ${firstFile} ${lastFile} > ${OUT3} 2>&1
[540]514# while [ ! -f "${tmppublicpath}/getsignalfiles.finished" ]; do
515# $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getsignalfiles.finished"
516# date +%T
517# sleep 30
518# done
519# $RM ${tmppublicpath}/getsignalfiles.finished
[535]520
521 getSignals=`$GREP "^FATAL" ${OUT3}`
522 if [ "<$getSignals>" != "<>" ]; then
523 $ECHO "FATAL (${scriptName}): error while get signals"
524 $ECHO $getSignals
525 exit 1
526 fi
527 $RM ${OUT3}
528
529#location of the signal file
530 fibfile="${curDir} 1,2"
531#
532 outDir=${curDir}/${dirName}/${cycle}
533 $MKDIR -p ${outDir}
534
535#
536# where ami...
537#
538 $ECHO "We are here `pwd`"
539 $LS -lrth
540 $FIND . -name "igetStatus.*" | $XARGS -i $CAT {}
541 $LS ./Fiber1 | $WC -l
542 $LS ./Fiber2 | $WC -l
543 $LS -lR ${outDir}
544
545#Note: here act=gain means only that specmfib will use median-like algorithms (not only for gains...)
[556]546 $prg -act ${action} $forceSingle $freqfilter -prt $prtlevel -out ${outDir} -nmean $nwinmean $ingain $tmproc -tspwin ${tspwin},0,0 -in $infiles ${fibfile}
[535]547
548 $ECHO ${outDir}
549 $LS -lrt ${outDir}
550
551#save results to Irods (use option -f ONLY to force override)
552 iput -v -K -r ${curDir}/${dirName} /baoradio/data/AmasNancay/${localpath}
553#
554#clean the signal files which can at the end of the day fill completly the scratch directory of the batch work/AmasNancayer
555 $RM -rf ${iojobpath}/${localpath}/Fiber1
556 $RM -rf ${iojobpath}/${localpath}/Fiber2
557 $RM -rf ${iojobpath}/${localpath}/${typeofproc}
558
559#
560#
561
562#end loop on cycles
563done
564#
565$ECHO "DEBUG (${scriptName}): END loop on cycles"
[579]566
[535]567exit 0
Note: See TracBrowser for help on using the repository browser.