source: BAORadio/AmasNancay/trunk/scaextractor.sh @ 627

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

correct case esac structure (jec)

File size: 3.8 KB
Line 
1#!/bin/sh -xvf
2#download SCA file, proceed to introspection, and upload results
3DATE=/bin/date
4GREP=/bin/grep
5AWK=/bin/awk
6ECHO=/bin/echo
7WC=/usr/bin/wc
8CAT=/bin/cat
9PRINTF=/usr/bin/printf
10MKDIR=/bin/mkdir
11RM=/bin/rm
12LS=/bin/ls
13TR=/usr/bin/tr
14DefaultIFS=$' \t\n'
15IFS=$DefaultIFS
16
17
18#set Irods environment   
19. /usr/local/shared/bin/irods_env.sh -noverbose
20
21scriptName="`basename $0`"
22$ECHO "Processing script ${scriptName} at `date`"
23
24#Process cmd line args: the -src option is mandatory (source name as Abell85)
25sourceRadio=
26dateSelected=
27#force recomputation force=Yes
28force="No"
29#use Drift Scan script=Yes
30is4DriftScan="No"
31while [ $# -gt 0 ]
32  do
33  case "$1" in
34      -src)  sourceRadio=$2; shift;;
35      -date) dateSelected=$2;     shift;;
36      -force) force="Yes";;
37      -drift) is4DriftScan="Yes";;
38      -h)
39      echo >&2 \
40          "usage: $0 -src souce -date YYYYMMDD [-force] [-drift]"
41          exit 1;;
42      *)  break;;       # terminate while loop
43  esac
44  shift
45done
46
47
48#which source to analyse
49srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
50
51
52#Path to public backupable path
53publicpath="/afs/in2p3.fr/home/c/campagne/public"
54
55#temporary files to synchronize scripts
56tmppublicpath=${TMPPUBLICPATH}
57$LS -l ${tmppublicpath} > /dev/null
58
59
60#Path where the job will do temporary IO
61. ${SCRIPTPATH}/set_iojobpath.sh
62iojobpath=$(set_iojobpath)
63cd ${iojobpath}
64
65
66localpath="${sourceRadio}"
67$MKDIR -p ./${localpath}
68cd ./${localpath}
69
70
71#Path of the utility scripts
72scriptpath=${SCRIPTPATH}
73
74
75#JEC 1/10/11 Use generic baodaqstatus name
76OUT1=${publicpath}/baodaqstatus-current.txt
77
78
79if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
80    $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
81    exit 1
82fi
83
84if [ ! "<${sourceRadio}>" = "<>" ]; then
85    $ECHO "You have selected sourceRadio = $sourceRadio[date = ${dateSelected}]"
86#JEC 14/12/11 One should take care of DR extension for Drift Scan
87#tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
88    tableau=( `$GREP -i "${sourceRadio}/${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
89else
90    tableau=( `$CAT ${OUT1} | $AWK'( NF==4 ) { print $2 }'`  )
91fi
92IFS='
93'
94tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
95IFS=$DefaultIFS
96
97for i in ${tableau[@]}
98do
99OUT2=./baodir.$$
100#scrutinize irods directory
101#Nb: we do not care here if ILS returns non unique instance of a file
102  ils -l $i 2>&1 | $GREP -i "sca" > ${OUT2}
103  $CAT ${OUT2}
104#test if the SCA file has been already processed
105  scatrans=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $NF}'`
106#test if the file is empty due to previous processing dysfunction
107  emptyfile=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $4}'`
108#  echo "scrutinize directory <$i>: [$nblines] [$scatrans]"
109  if [ "<${scatrans}>" = "<>" -o "<${emptyfile}>" = "<0>" -o "<${force}>" = "<Yes>" ]; then
110      $ECHO "$i may be non prepared for analysis..."
111      scafile=`$GREP -i "sca[0-9][0-9]*\.[0-9][0-9]*" ${OUT2} | $AWK '{print $NF}'`
112      if [ "<${scafile}>" = "<>" ]; then
113          $ECHO "WARNING (${scriptName}): Cannot download a SCA file for $i"
114      else
115#get sca file
116        iget -r -f -v -K ${i}/${scafile} ${iojobpath}
117#extract summary (sum extension)
118#JEC 7/12/11 START
119        if [ "<${is4DriftScan}>" != "<Yes>" ]; then
120            ${scriptpath}/sca.sh ${scafile}
121            $ECHO "INFO (${scriptName}): sca.sh has finished"
122        else
123            ${scriptpath}/sca_ds.sh ${scafile}
124            $ECHO "INFO (${scriptName}): sca_ds.sh has finished"
125        fi
126#
127#TODO see if there is errors...
128        scaFileName=$(basename $scafile)
129        scaFileName=${scaFileName%.*}
130#transform the date (sum.trans extension)
131        ${scriptpath}/transdate.sh ${scaFileName}.sum
132        $ECHO "INFO (${scriptName}): transdate.sh  has finished"
133        iput -f -v -K ${iojobpath}/${scaFileName}.sum $i
134        iput -f -v -K ${iojobpath}/${scaFileName}.sum.trans $i
135      fi
136  fi
137$RM ${OUT2}
138done
139
140exit 0
Note: See TracBrowser for help on using the repository browser.