source: BAORadio/AmasNancay/trunk/anadriftmaker.sh@ 673

Last change on this file since 673 was 637, checked in by campagne, 14 years ago

first introduction of DRIFT data (jec)

  • Property svn:executable set to *
File size: 7.9 KB
Line 
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=
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;;
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})] [-bwd bandwidth in MHz (default ${bwBAOCalib})]"
44 exit 1;;
45 *) break;; # terminate while loop
46 esac
47 shift
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
59#TODO in principe the naming convention is <SOURCE>DR but NGC4383 is an exception
60case ${sourceRadio} in
61 NGC4383DR) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
62 3C273DR) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
63 3C161DR) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
64 3C161BDR) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
65 *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen"
66 exit 1;;
67esac
68
69srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
70
71#Path to public backupable path
72publicpath="/afs/in2p3.fr/home/c/campagne/public"
73
74
75#temporary files to synchronize scripts
76tmppublicpath=${TMPPUBLICPATH}
77#wakeup the NFS disk
78$LS -l ${tmppublicpath} > /dev/null
79#clean previous spurious files
80$RM -f ${tmppublicpath}/*.finished
81
82#Path where the job will do temporary IO
83. ${SCRIPTPATH}/isInteractive.sh
84isInteractive=$(isInteractive)
85if [ ${isInteractive} == "1" ]; then
86 $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!"
87 exit 0;
88fi
89
90. ${SCRIPTPATH}/set_iojobpath.sh
91iojobpath=$(set_iojobpath)
92cd ${iojobpath}
93
94localpath="${sourceRadio}"
95$MKDIR -p ./${localpath}
96cd ./${localpath}
97
98#save the top directory
99topDir=`pwd`
100
101#Path of the utility scripts
102scriptpath=${SCRIPTPATH}
103
104#Use generic baodaqstatus name
105OUT1=${publicpath}/baodaqstatus-current.txt
106if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
107 $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
108 exit 1
109fi
110
111
112#Nb: if we want to implement a loop on sources we have to take care of srclower...
113
114$ECHO "You have selected sourceRadio = $sourceRadio[date = ${dateSelected}]"
115#JEC 14/12/11 One should take care of DR extension for Drift Scan
116#tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
117tableau=( `$GREP -i "${sourceRadio}/${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
118IFS='
119'
120tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
121IFS=$DefaultIFS
122
123
124for i in ${tableau[@]}
125 do
126#
127# start a "fresh" session
128 cd ${topDir}
129 $LS | $XARGS -i $RM -rf {}
130
131
132 $ECHO "DEBUG: (${scriptName}) irods root dir $i"
133 dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
134
135 $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}"
136 $LS -lrt
137
138
139######
140 $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}"
141#go to the .../source/date-sourcelowercase directory
142#download Off/calibcycle<> and On/calibcycle<> directories
143 $MKDIR -p ${topDir}/${dateDAQ}${srclower}
144 cd ${topDir}/${dateDAQ}${srclower}
145 aboveOnOffDir=`pwd`
146 $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>"
147#
148 mode="On"
149 $ECHO "DEBUG (${scriptName}): START download the ${mode} fits files"
150 inFileDirectory="./${mode}"
151 $MKDIR -p ${inFileDirectory}
152
153 listOfDataCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "datacycle" |$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` )
154 IFS='
155 '
156 listOfDataCycle=( $( $PRINTF "%s\n" "${listOfDataCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
157 IFS=$DefaultIFS
158
159 firstCycle=`$ECHO ${listOfDataCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
160 nCycles=`expr ${#listOfDataCycle[*]} - 1`
161
162 lastCycle=`$ECHO ${listOfDataCycle[${nCycles}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
163
164 listOfDataCycle=( "${listOfDataCycle[@]/#/${i}/${mode}/}" )
165
166 $ECHO "INFO (${scriptName}): use cycles [${firstCycle}, ${lastCycle}]"
167
168
169 for j in ${listOfDataCycle[@]}
170 do
171 irodsDownDir="${j}"
172 OUT=./getInFits.$$
173 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
174 igetStatus=`$GREP "^ERROR" ${OUT}`
175 if [ "<$igetStatus>" != "<>" ]; then
176 $ECHO "FATAL (${scriptName}): error while iget fits files:"
177 $ECHO $igetStatus
178 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
179 continue
180 fi
181 $RM -f ${OUT}
182 done
183 $ECHO "DEBUG (${scriptName}): END download the ${mode} fits files"
184#Get sca file
185 $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}"
186 OUT1=./getScaStatus.$$
187# $RM -f ${tmppublicpath}/getscafiles.finished
188 ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
189# $RM ${tmppublicpath}/getscafiles.finished
190 $ECHO "DEBUG (${scriptName}): END"
191#
192 getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
193#
194 if [ "<${getScaStatus}>" != "<>" ]; then
195 $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ"
196 $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
197 $CAT ${OUT1}
198 $ECHO "DEBUG (${scriptName}): END"
199 continue
200 fi
201 $RM -f ${OUT1}
202
203 scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}`
204
205#prepare job submission
206 cd ${aboveOnOffDir}
207#the default spectra name is medfiltmtx, otherwise use -specname <a_string>
208
209 logFile="analyse_DRIFT_${sourceRadio}_${dateDAQ}.log"
210 $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`"
211 if [ ${simulationMode} = "On" ]; then
212 $ECHO "SIMUL: ${scriptpath}/Objs/analyse -act driftScanImg -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir datacycle -numcycle ${firstCycle},${lastCycle} -debug 1 >& ${logFile}"
213 cat > ${logFile} <<EOF
214 Ok calibration finished
215EOF
216#WARNING: the EOF must start at 1st column overwise the rest of the script is part of the file cat...
217 else
218 ${scriptpath}/Objs/analyse -act driftScanImg -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir datacycle -numcycle ${firstCycle},${lastCycle} -debug 1 >& ${logFile}
219 fi
220#
221 $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods"
222 rcstatus=`$GREP -i "Ok drift finished" ${logFile} | $WC -l`
223 if [ ${rcstatus} -eq 0 ]; then
224 $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}"
225 $ECHO " START logfile"
226 $CAT ${logFile}
227 $ECHO " END logFile"
228#clean and leave
229 cd ${aboveOnOffDir}
230 $LS | $XARGS -i $RM -rf {}
231 continue
232 fi
233#Save into Irods
234 $ECHO "DEBUG (${scriptName}): START save output files"
235 $LS ${aboveOnOffDir}
236#use -f option for iput ONLY to force override
237 if [ ${simulationMode} = "On" ]; then
238 $ECHO "SIMUL: here we look for calib file and put them in Irods"
239 else
240 $LS -lrth
241 $FIND . -name "img_*" -print | $XARGS -i iput -f -v -K {} ${i}
242 fi
243#save analysis logfile
244 $LS -l ${tmppublicpath} > /dev/null
245 $CP ${logFile} ${tmppublicpath}
246 $ECHO "DEBUG (${scriptName}): END save output files"
247#clean up to avoid scratch SIZE EXCEED LIMIT
248 cd ${aboveOnOffDir}
249 $LS | $XARGS -i $RM -rf {}
250
251done
252
253exit 0
Note: See TracBrowser for help on using the repository browser.