source: BAORadio/AmasNancay/trunk/getsignalfiles.sh @ 547

Last change on this file since 547 was 547, checked in by campagne, 13 years ago

move to trunk the previous HEAD (jec)

File size: 4.4 KB
Line 
1#!/bin/sh
2#
3#Script sh d'extraction de fichiers d'irod
4# Auteur: JE Campagne (LAL Orsay)
5# Creation: 2 mai 2011
6# adaptation pour le CC 17 juin 2011
7DATE=/bin/date
8GREP=/bin/grep
9AWK=/bin/awk
10ECHO=/bin/echo
11TR=/usr/bin/tr
12MKDIR=/bin/mkdir
13CAT=/bin/cat
14RM=/bin/rm
15LS=/bin/ls
16DefaultIFS=$' \t\n'
17IFS=$DefaultIFS
18
19scriptName="`basename $0`"
20$ECHO "Processing script ${scriptName} at `date`"
21
22
23
24if [ ! $# = 4 ]; then
25  $ECHO "usage: ${scriptName} <source:ex. Abell85> <date:YYYYMMDD> first last"
26#JEC 29/9/11 avoid finished stuff
27#  touch ${tmppublicpath}/getsignalfiles.finished
28  exit 0
29fi
30
31# Irods environment settings
32#export PATH=$PATH:/home/bao/irods2.5_LinuxSL5
33. /usr/local/shared/bin/irods_env.sh -noverbose
34
35sourceRadio=$1
36srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
37dateDAQ=$2
38
39#Path to public backupable path
40publicpath="/afs/in2p3.fr/home/c/campagne/public"
41
42#temporary files to synchronize scripts
43tmppublicpath=${TMPPUBLICPATH}
44$LS -l ${tmppublicpath} > /dev/null
45
46
47#Path where the job will do temporary IO
48if [ ${ENVIRONMENT} == "INTERACTIVE" ]; then
49    iojobpath="/sps/baoradio/AmasNancay/JEC"
50    $MKDIR -p $iojobpath
51elif [ ${ENVIRONMENT} == "BATCH" ] ; then
52    iojobpath=${TMPBATCH}
53else
54   $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
55#JEC 29/9/11 avoid finished stuff
56#   touch ${tmppublicpath}/getsignalfiles.finished
57   exit 1
58fi
59cd ${iojobpath}
60
61localpath="${sourceRadio}/${dateDAQ}${srclower}"
62$MKDIR -p ./${localpath}
63cd ./${localpath}
64
65#Path of the utility scripts
66scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
67
68
69#determine the sequence of signal files to download
70#JEC 1/10/11 Use generic baodaqstatus name
71#get the daq current irod status
72#tag=`${DATE} +%F`
73#OUT1=${publicpath}/baodaqstatus-${tag}.txt
74OUT1=${publicpath}/baodaqstatus-current.txt
75
76if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
77#     $ECHO "We should bring the DAQ status more up to date, this take few
78# sec..."
79#     $RM -f ${tmppublicpath}/statusdaq.finished
80#     ${scriptpath}/statusdaq.sh > ${OUT1}
81#     while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
82#       $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished"
83#       date +%T
84#       sleep 30
85#     done
86#     $RM ${tmppublicpath}/statusdaq.finished
87    $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..."
88#JEC 29/9/11 avoid finished stuff
89#    touch ${tmppublicpath}/getsignalfiles.finished
90    exit 1
91fi
92
93nfiles=`${GREP} "${sourceRadio}.*${dateDAQ}" ${OUT1} | ${AWK} '(NF==4){print $4}'` 
94if [ "<${nfiles}>" == "<>" ]; then
95    $ECHO "FATAL (${scriptName}): No run found for <${sourceRadio}> and date <${dateDAQ}>"
96    $CAT $OUT1
97#JEC 29/9/11 avoid finished stuff
98#    touch ${tmppublicpath}/getsignalfiles.finished
99    exit 1
100fi
101
102
103firstFile=$3
104if [ ${firstFile} -gt  ${nfiles} ]; then
105    $ECHO "FATAL (${scriptName}): ${firstFile} >  ${nfiles}"
106#JEC 29/9/11 avoid finished stuff
107#    touch ${tmppublicpath}/getsignalfiles.finished
108    exit 1
109fi
110
111
112lastFile=$4
113if [ ${lastFile} -gt  ${nfiles} ]; then
114    $ECHO "FATAL (${scriptName}): ${lastFile} >  ${nfiles}"
115#JEC 29/9/11 avoid finished stuff
116#    touch ${tmppublicpath}/getsignalfiles.finished
117    exit 1
118fi
119
120if [ ${firstFile} -gt  ${lastFile} ]; then
121    $ECHO "FATAL (${scriptName}): ${firstFile} >  ${lastFile}"
122#JEC 29/9/11 avoid finished stuff
123#    touch ${tmppublicpath}/getsignalfiles.finished
124    exit 1
125fi
126
127
128dirIrod="/baoradio/data/AmasNancay/${sourceRadio}/${dateDAQ}${srclower}"
129dirLocal="."
130
131##$ECHO "Ready to download [${firstFile},${lastFile}] in $dirLocal from $dirIrod"
132#Nb we are in the localpath
133$MKDIR -p Fiber1
134$MKDIR -p Fiber2
135
136OUT2=./igetStatus.$$
137
138n=$firstFile
139while [[ $n -le $lastFile ]]; do
140   iget -r -f -v -K ${dirIrod}/Fiber1/signal$n.fits ${dirLocal}/Fiber1 >${OUT2} 2>&1
141   igetStatus=`$GREP "^ERROR" ${OUT2}`
142   if [ "<$igetStatus>" != "<>" ]; then
143       $ECHO "FATAL (${scriptName}): error while iget:"
144       $ECHO $igetStatus
145#JEC 29/9/11 avoid finished stuff
146#       touch ${tmppublicpath}/getsignalfiles.finished
147       exit 1
148   fi
149   iget -r -f -v -K ${dirIrod}/Fiber2/signal$n.fits ${dirLocal}/Fiber2 >${OUT2} 2>&1
150   igetStatus=`$GREP "^ERROR" ${OUT2}`
151   if [ "<$igetStatus>" != "<>" ]; then
152       $ECHO "FATAL (${scriptName}): error while iget:"
153       $ECHO $igetStatus
154#JEC 29/9/11 avoid finished stuff
155#       touch ${tmppublicpath}/getsignalfiles.finished
156       exit 1
157   fi
158   n=$(($n+1))
159done
160
161#JEC 29/9/11 avoid finished stuff
162#touch ${tmppublicpath}/getsignalfiles.finished
163exit 0
Note: See TracBrowser for help on using the repository browser.