source: BAORadio/AmasNancay/trunk/getsignalfiles.sh

Last change on this file was 579, checked in by torrento, 13 years ago

version adaptee a grid engin (ana)

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