source: BAORadio/AmasNancay/v2/getsignalfiles.sh@ 605

Last change on this file since 605 was 516, checked in by campagne, 14 years ago

change the tmppubicpath (jec)

File size: 4.0 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 touch ${tmppublicpath}/getsignalfiles.finished
27 exit 0
28fi
29
30# Irods environment settings
31#export PATH=$PATH:/home/bao/irods2.5_LinuxSL5
32. /usr/local/shared/bin/irods_env.sh -noverbose
33
34sourceRadio=$1
35srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
36dateDAQ=$2
37
38#Path to public backupable path
39publicpath="/afs/in2p3.fr/home/c/campagne/public"
40
41#temporary files to synchronize scripts
42tmppublicpath=${TMPPUBLICPATH}
43$LS -l ${tmppublicpath} > /dev/null
44
45
46#Path where the job will do temporary IO
47if [ ${ENVIRONMENT} == "INTERACTIVE" ]; then
48 iojobpath="/sps/baoradio/AmasNancay/JEC"
49 $MKDIR -p $iojobpath
50elif [ ${ENVIRONMENT} == "BATCH" ] ; then
51 iojobpath=${TMPBATCH}
52else
53 $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
54 touch ${tmppublicpath}/getsignalfiles.finished
55 exit 1
56fi
57cd ${iojobpath}
58
59localpath="${sourceRadio}/${dateDAQ}${srclower}"
60$MKDIR -p ./${localpath}
61cd ./${localpath}
62
63#Path of the utility scripts
64scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
65
66
67#determine the sequence of signal files to download
68#get the daq current irod status
69tag=`${DATE} +%F`
70OUT1=${publicpath}/baodaqstatus-${tag}.txt
71
72if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
73# $ECHO "We should bring the DAQ status more up to date, this take few
74# sec..."
75# $RM -f ${tmppublicpath}/statusdaq.finished
76# ${scriptpath}/statusdaq.sh > ${OUT1}
77# while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
78# $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished"
79# date +%T
80# sleep 30
81# done
82# $RM ${tmppublicpath}/statusdaq.finished
83 $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..."
84 touch ${tmppublicpath}/getsignalfiles.finished
85 exit 1
86fi
87
88nfiles=`${GREP} "${sourceRadio}.*${dateDAQ}" ${OUT1} | ${AWK} '(NF==4){print $4}'`
89if [ "<${nfiles}>" == "<>" ]; then
90 $ECHO "FATAL (${scriptName}): No run found for <${sourceRadio}> and date <${dateDAQ}>"
91 $CAT $OUT1
92 touch ${tmppublicpath}/getsignalfiles.finished
93 exit 1
94fi
95
96
97firstFile=$3
98if [ ${firstFile} -gt ${nfiles} ]; then
99 $ECHO "FATAL (${scriptName}): ${firstFile} > ${nfiles}"
100 touch ${tmppublicpath}/getsignalfiles.finished
101 exit 1
102fi
103
104
105lastFile=$4
106if [ ${lastFile} -gt ${nfiles} ]; then
107 $ECHO "FATAL (${scriptName}): ${lastFile} > ${nfiles}"
108 touch ${tmppublicpath}/getsignalfiles.finished
109 exit 1
110fi
111
112if [ ${firstFile} -gt ${lastFile} ]; then
113 $ECHO "FATAL (${scriptName}): ${firstFile} > ${lastFile}"
114 touch ${tmppublicpath}/getsignalfiles.finished
115 exit 1
116fi
117
118
119dirIrod="/baoradio/data/AmasNancay/${sourceRadio}/${dateDAQ}${srclower}"
120dirLocal="."
121
122##$ECHO "Ready to download [${firstFile},${lastFile}] in $dirLocal from $dirIrod"
123#Nb we are in the localpath
124$MKDIR -p Fiber1
125$MKDIR -p Fiber2
126
127OUT2=./igetStatus.$$
128
129n=$firstFile
130while [[ $n -le $lastFile ]]; do
131 iget -r -f -v -K ${dirIrod}/Fiber1/signal$n.fits ${dirLocal}/Fiber1 >${OUT2} 2>&1
132 igetStatus=`$GREP "^ERROR" ${OUT2}`
133 if [ "<$igetStatus>" != "<>" ]; then
134 $ECHO "FATAL (${scriptName}): error while iget:"
135 $ECHO $igetStatus
136 touch ${tmppublicpath}/getsignalfiles.finished
137 exit 1
138 fi
139 iget -r -f -v -K ${dirIrod}/Fiber2/signal$n.fits ${dirLocal}/Fiber2 >${OUT2} 2>&1
140 igetStatus=`$GREP "^ERROR" ${OUT2}`
141 if [ "<$igetStatus>" != "<>" ]; then
142 $ECHO "FATAL (${scriptName}): error while iget:"
143 $ECHO $igetStatus
144 touch ${tmppublicpath}/getsignalfiles.finished
145 exit 1
146 fi
147 n=$(($n+1))
148done
149
150touch ${tmppublicpath}/getsignalfiles.finished
151exit 0
Note: See TracBrowser for help on using the repository browser.