[565] | 1 | #!/bin/sh |
---|
| 2 | #make an archive of the processing |
---|
| 3 | DATE=/bin/date |
---|
| 4 | GREP=/bin/grep |
---|
| 5 | AWK=/bin/awk |
---|
| 6 | ECHO=/bin/echo |
---|
| 7 | WC=/usr/bin/wc |
---|
| 8 | CAT=/bin/cat |
---|
| 9 | PRINTF=/usr/bin/printf |
---|
| 10 | FIND=/usr/bin/find |
---|
| 11 | MKDIR=/bin/mkdir |
---|
| 12 | XARGS=/usr/bin/xargs |
---|
| 13 | SORT=/bin/sort |
---|
| 14 | RM=/bin/rm |
---|
| 15 | TR=/usr/bin/tr |
---|
| 16 | CP=/bin/cp |
---|
| 17 | LS=/bin/ls |
---|
| 18 | CHMOD=/bin/chmod |
---|
| 19 | |
---|
| 20 | DefaultIFS=$' \t\n' |
---|
| 21 | IFS=$DefaultIFS |
---|
| 22 | |
---|
| 23 | #set Irods environment |
---|
| 24 | . /usr/local/shared/bin/irods_env.sh -noverbose |
---|
| 25 | |
---|
| 26 | scriptName="`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) |
---|
| 31 | sourceRadio= |
---|
| 32 | dateSelected= |
---|
| 33 | prependTag="" |
---|
| 34 | appendTag="" |
---|
| 35 | simulationMode=Off |
---|
[581] | 36 | mvgain=No |
---|
[565] | 37 | while [ $# -gt 0 ] |
---|
| 38 | do |
---|
| 39 | case "$1" in |
---|
| 40 | -src) sourceRadio=$2; shift;; |
---|
| 41 | -date) dateSelected=$2; shift;; |
---|
| 42 | -ppTag) prependTag=$2; shift;; |
---|
| 43 | -apTag) appendTag=$2; shift;; |
---|
| 44 | -sim) simulationMode=On;; |
---|
[581] | 45 | -all) mvgain=Yes;; |
---|
[565] | 46 | -h) |
---|
| 47 | echo >&2 \ |
---|
| 48 | "usage: $0 -src souce -date YYYYMMDD -ppTag <tag> -apTag <tag> [-sim to trig simulation mode]" |
---|
| 49 | exit 1;; |
---|
| 50 | *) break;; # terminate while loop |
---|
| 51 | esac |
---|
| 52 | shift |
---|
| 53 | done |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | if [ ${simulationMode} = "On" ]; then |
---|
| 57 | $ECHO "INFO ${scriptName} running in SIMUL mode" |
---|
| 58 | fi |
---|
| 59 | |
---|
| 60 | if [ "<${sourceRadio}>" = "<>" ]; then |
---|
| 61 | $ECHO "FATAL: You have forgotten to select the source option (-src)" |
---|
| 62 | exit 1 |
---|
| 63 | fi |
---|
| 64 | |
---|
| 65 | if [ "<${prependTag}>" = "<>" -a "<${appendTag}>" = "<>" ]; then |
---|
| 66 | $ECHO "FATAL: choose either a prepend Tag or a append Tag" |
---|
| 67 | exit |
---|
| 68 | fi |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | case ${sourceRadio} in |
---|
| 72 | Abell85) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 73 | Abell2440) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 74 | Abell1205) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
[601] | 75 | NGC4383) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
[565] | 76 | *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen" |
---|
| 77 | exit 1;; |
---|
| 78 | esac |
---|
| 79 | |
---|
| 80 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
| 81 | |
---|
| 82 | #Path to public backupable path |
---|
| 83 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | #temporary files to synchronize scripts |
---|
| 87 | tmppublicpath=${TMPPUBLICPATH} |
---|
| 88 | #wakeup the NFS disk |
---|
| 89 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 90 | |
---|
| 91 | #Path where the job will do temporary IO |
---|
[579] | 92 | . ${SCRIPTPATH}/set_iojobpath.sh |
---|
| 93 | iojobpath=$(set_iojobpath) |
---|
[565] | 94 | cd ${iojobpath} |
---|
| 95 | |
---|
| 96 | localpath="${sourceRadio}" |
---|
| 97 | $MKDIR -p ./${localpath} |
---|
| 98 | cd ./${localpath} |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | #Path of the utility scripts |
---|
[575] | 102 | scriptpath=${SCRIPTPATH} |
---|
[565] | 103 | |
---|
| 104 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
| 105 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
| 106 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
| 107 | exit 1 |
---|
| 108 | fi |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | $ECHO "You have selected sourceRadio = ${sourceRadio} [date = ${dateSelected}]" |
---|
| 113 | tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
| 114 | IFS=' |
---|
| 115 | ' |
---|
| 116 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 117 | IFS=$DefaultIFS |
---|
| 118 | |
---|
| 119 | $ECHO "We are in directory `pwd`" |
---|
| 120 | |
---|
| 121 | for i in ${tableau[@]} |
---|
| 122 | do |
---|
| 123 | # |
---|
| 124 | |
---|
| 125 | $ECHO "DEBUG: (${scriptName}) irods root dir $i" |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | #make a new archive directory |
---|
| 130 | archiveDir=${prependTag}Arch${appendTag} |
---|
| 131 | |
---|
| 132 | archExist=`ils ${i} 2>&1 | $GREP -i ".*C-.*${archiveDir}"| $WC -l` |
---|
| 133 | if [ ${archExist} -gt 0 ]; then |
---|
| 134 | $ECHO "FATAL: ${archiveDir} already exit in ${i}" |
---|
| 135 | exit 1 |
---|
| 136 | fi |
---|
| 137 | |
---|
| 138 | imkdir -v ${i}/${archiveDir} |
---|
| 139 | |
---|
| 140 | #Move the Off and On directory |
---|
| 141 | imv -v ${i}/Off ${i}/${archiveDir}/Off |
---|
| 142 | imv -v ${i}/On ${i}/${archiveDir}/On |
---|
| 143 | |
---|
| 144 | #recreate On and Off directories |
---|
| 145 | imkdir -v ${i}/Off |
---|
| 146 | imkdir -v ${i}/On |
---|
| 147 | |
---|
| 148 | #mv the fichiers de calibrations BAO |
---|
| 149 | calibfiles=( `ils ${i} 2>&1 | $GREP -i "calib_.*\.txt" ` ) |
---|
| 150 | IFS=' |
---|
| 151 | ' |
---|
| 152 | calibfiles=( $( $PRINTF "%s\n" "${calibfiles[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 153 | IFS=$DefaultIFS |
---|
| 154 | |
---|
| 155 | for j in ${calibfiles[@]} |
---|
| 156 | do |
---|
| 157 | file=`$ECHO $j` |
---|
| 158 | imv -v ${i}/${file} ${i}/${archiveDir}/${file} |
---|
| 159 | done |
---|
| 160 | |
---|
| 161 | #mv the ppf files |
---|
| 162 | ppffiles=( `ils ${i} 2>&1 | $GREP -i ".*\.ppf" ` ) |
---|
| 163 | IFS=' |
---|
| 164 | ' |
---|
| 165 | ppffiles=( $( $PRINTF "%s\n" "${ppffiles[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 166 | IFS=$DefaultIFS |
---|
| 167 | |
---|
| 168 | for j in ${ppffiles[@]} |
---|
| 169 | do |
---|
| 170 | file=`$ECHO $j` |
---|
| 171 | imv -v ${i}/${file} ${i}/${archiveDir}/${file} |
---|
| 172 | done |
---|
| 173 | |
---|
| 174 | #save the gain file |
---|
| 175 | gainfile=`ils ${i} 2>&1 | $GREP -i "gain.*\.fits"` |
---|
| 176 | file=`$ECHO ${gainfile}` |
---|
[581] | 177 | if [ "<${mvgain}>" = "<No>" ]; then |
---|
| 178 | icp -v ${i}/${file} ${i}/${archiveDir}/${file} |
---|
| 179 | else |
---|
| 180 | imv -v ${i}/${file} ${i}/${archiveDir}/${file} |
---|
| 181 | fi |
---|
[565] | 182 | |
---|
| 183 | done |
---|
| 184 | |
---|
| 185 | exit 0 |
---|