| 1 | #!/bin/sh -xvf
 | 
|---|
| 2 | #Basic tuning of system fuction used.
 | 
|---|
| 3 | AWK=/bin/awk
 | 
|---|
| 4 | SED=/bin/sed
 | 
|---|
| 5 | GREP=/bin/grep
 | 
|---|
| 6 | WC=/usr/bin/wc
 | 
|---|
| 7 | RM=/bin/rm
 | 
|---|
| 8 | CAT=/bin/cat
 | 
|---|
| 9 | TOUCH=/bin/touch
 | 
|---|
| 10 | DATE=/bin/date
 | 
|---|
| 11 | ECHO=/bin/echo
 | 
|---|
| 12 | LS=/bin/ls
 | 
|---|
| 13 | MKDIR=/bin/mkdir
 | 
|---|
| 14 | TR=/usr/bin/tr
 | 
|---|
| 15 | FIND=/usr/bin/find
 | 
|---|
| 16 | PRINTF=/usr/bin/printf
 | 
|---|
| 17 | XARGS=/usr/bin/xargs
 | 
|---|
| 18 | SORT=/bin/sort
 | 
|---|
| 19 | QSUB=qsub
 | 
|---|
| 20 | 
 | 
|---|
| 21 | DefaultIFS=$' \t\n'
 | 
|---|
| 22 | IFS=$DefaultIFS
 | 
|---|
| 23 | 
 | 
|---|
| 24 | 
 | 
|---|
| 25 | scriptName="`basename $0`"
 | 
|---|
| 26 | $ECHO "Processing script ${scriptName} at `date`"
 | 
|---|
| 27 | ######
 | 
|---|
| 28 | # Local functions
 | 
|---|
| 29 | ######
 | 
|---|
| 30 | usage() {
 | 
|---|
| 31 |   echo "usage: $scriptName <source> <YYYYMMDD-directory> <type of process>"
 | 
|---|
| 32 |   echo "      -<source> as Abell85"
 | 
|---|
| 33 |   echo "      -<YYYYMMDD-directory> as 20110428"
 | 
|---|
| 34 |   echo "      -<type of process> as GAIN|CALIBON|CALIBOFF|ON|OFF"
 | 
|---|
| 35 | }
 | 
|---|
| 36 | ######
 | 
|---|
| 37 | # argument test
 | 
|---|
| 38 | ######
 | 
|---|
| 39 | 
 | 
|---|
| 40 | #Process cmd line args: the -src option is mandatory (source name as Abell85)
 | 
|---|
| 41 | #action: gain|mspec (gain: gain-like doucble median filtering
 | 
|---|
| 42 | #                   mspec: mean+sigma wo filetring)
 | 
|---|
| 43 | action="gain"
 | 
|---|
| 44 | sourceRadio=
 | 
|---|
| 45 | dateSelected=
 | 
|---|
| 46 | typeofproc=
 | 
|---|
| 47 | #use -sim option to simulate processing (debug the script as if...)
 | 
|---|
| 48 | simulationMode=Off
 | 
|---|
| 49 | #
 | 
|---|
| 50 | #first and last cycle to process
 | 
|---|
| 51 | #
 | 
|---|
| 52 | firstCycle=
 | 
|---|
| 53 | lastCycle=
 | 
|---|
| 54 | while [ $# -gt 0 ]
 | 
|---|
| 55 | do
 | 
|---|
| 56 |   case "$1" in
 | 
|---|
| 57 |       -act)  action=$2;         shift;;
 | 
|---|
| 58 |       -src)  sourceRadio=$2;    shift;;
 | 
|---|
| 59 |       -date) dateSelected=$2;   shift;;
 | 
|---|
| 60 |       -type) typeofproc=$2;     shift;;
 | 
|---|
| 61 |       -fcycle) firstCycle=$2;   shift;;
 | 
|---|
| 62 |       -lcycle) lastCycle=$2;    shift;;
 | 
|---|
| 63 |       -sim)  simulationMode=On;;
 | 
|---|
| 64 |         -h)
 | 
|---|
| 65 |             echo >&2 \
 | 
|---|
| 66 |             "usage: $0 [-act <action> ] -src souce -date YYYYMMDD -type type [-fcycle firstCycle] [-lcycle lastCycle] [-sim to trig simulation mode]"
 | 
|---|
| 67 |             exit 1;;
 | 
|---|
| 68 |         *)  break;;     # terminate while loop
 | 
|---|
| 69 |     esac
 | 
|---|
| 70 |     shift
 | 
|---|
| 71 | done
 | 
|---|
| 72 | 
 | 
|---|
| 73 | #Check input
 | 
|---|
| 74 | 
 | 
|---|
| 75 | if [ "<${sourceRadio}>" = "<>" ]; then
 | 
|---|
| 76 |     $ECHO "FATAL: You have forgotten to select the source option (-src)"
 | 
|---|
| 77 |     exit 1
 | 
|---|
| 78 | fi
 | 
|---|
| 79 | 
 | 
|---|
| 80 | if [ "<${dateSelected}>" = "<>" ]; then
 | 
|---|
| 81 |     $ECHO "FATAL: You have forgotten to select the date option (-date)"
 | 
|---|
| 82 |     exit 1
 | 
|---|
| 83 | fi
 | 
|---|
| 84 | 
 | 
|---|
| 85 | if [ "<${typeofproc}>" = "<>" ]; then
 | 
|---|
| 86 |     $ECHO "FATAL: You have forgotten to select the type option (-type)"
 | 
|---|
| 87 |     exit 1
 | 
|---|
| 88 | 
 | 
|---|
| 89 | fi
 | 
|---|
| 90 | #else
 | 
|---|
| 91 | #    offtype=`$ECHO ${typeofproc} | $GREP -i OFF | $WC -l`
 | 
|---|
| 92 | #    ontype=`$ECHO ${typeofproc} | $GREP -i ON | $WC -l`
 | 
|---|
| 93 | #    if [ "<${offtype}>" = "<1>" -a  "<${ontype}>" = "<0>" ]; then
 | 
|---|
| 94 | #       datatype="OFF"
 | 
|---|
| 95 | #    elif [ "<${offtype}>" = "<0>" -a  "<${ontype}>" = "<1>" ]; then
 | 
|---|
| 96 | #       datatype="ON"
 | 
|---|
| 97 | #    else
 | 
|---|
| 98 | #       $ECHO "FATAL: not supported: -type ${typeofproc}"
 | 
|---|
| 99 | #       exit 1
 | 
|---|
| 100 | #    fi
 | 
|---|
| 101 | #fi
 | 
|---|
| 102 | 
 | 
|---|
| 103 | 
 | 
|---|
| 104 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
 | 
|---|
| 105 | 
 | 
|---|
| 106 | 
 | 
|---|
| 107 | #Path to public backupable path
 | 
|---|
| 108 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
 | 
|---|
| 109 | 
 | 
|---|
| 110 | #temporary files to synchronize scripts
 | 
|---|
| 111 | tmppublicpath=${TMPPUBLICPATH}
 | 
|---|
| 112 | $LS -l ${tmppublicpath} > /dev/null
 | 
|---|
| 113 | 
 | 
|---|
| 114 | 
 | 
|---|
| 115 | #Path where the job will do temporary IO
 | 
|---|
| 116 | . ${SCRIPTPATH}/set_iojobpath.sh
 | 
|---|
| 117 | iojobpath=$(set_iojobpath)
 | 
|---|
| 118 | cd ${iojobpath}
 | 
|---|
| 119 | 
 | 
|---|
| 120 | localpath="${sourceRadio}/${dateSelected}${srclower}"
 | 
|---|
| 121 | $MKDIR -p ./${localpath}
 | 
|---|
| 122 | cd ./${localpath}
 | 
|---|
| 123 | mainDirectory=`pwd`
 | 
|---|
| 124 | 
 | 
|---|
| 125 | 
 | 
|---|
| 126 | #Path of the utility scripts
 | 
|---|
| 127 | scriptpath=${SCRIPTPATH}
 | 
|---|
| 128 | 
 | 
|---|
| 129 | 
 | 
|---|
| 130 | #select file per cycle
 | 
|---|
| 131 | #$ECHO "Select files process..."
 | 
|---|
| 132 | #keep only lines with structure: cycle_number first,last,step
 | 
|---|
| 133 | #Get sca files
 | 
|---|
| 134 | $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateSelected}"
 | 
|---|
| 135 | OUT1=./getScaStatus.$$
 | 
|---|
| 136 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 137 | #$RM -f ${tmppublicpath}/getscafiles.finished
 | 
|---|
| 138 | ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateSelected} > ${OUT1} 2>&1
 | 
|---|
| 139 | #while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
 | 
|---|
| 140 | #    $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
 | 
|---|
| 141 | #    date +%T
 | 
|---|
| 142 | #    sleep 30
 | 
|---|
| 143 | #done
 | 
|---|
| 144 | #$RM -f ${tmppublicpath}/getscafiles.finished
 | 
|---|
| 145 | $ECHO "DEBUG (${scriptName}): END"
 | 
|---|
| 146 | 
 | 
|---|
| 147 | 
 | 
|---|
| 148 | getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
 | 
|---|
| 149 | 
 | 
|---|
| 150 | if [ "<${getScaStatus}>" != "<>" ]; then
 | 
|---|
| 151 |   $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateSelected"
 | 
|---|
| 152 |   $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
 | 
|---|
| 153 |   $CAT ${OUT1}
 | 
|---|
| 154 |   $ECHO "DEBUG (${scriptName}): END"
 | 
|---|
| 155 |   exit 1
 | 
|---|
| 156 | fi
 | 
|---|
| 157 | 
 | 
|---|
| 158 | 
 | 
|---|
| 159 | scaFileSummarized=`$FIND . -name "sca*.sum" -print`
 | 
|---|
| 160 | if [ "<${scaFileSummarized}>" = "<>" ]; then
 | 
|---|
| 161 |   $ECHO "FATAL (${scriptName}): strange sca file summarized not available: $sourceRadio $dateSelected"
 | 
|---|
| 162 |   $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
 | 
|---|
| 163 |   $CAT ${OUT1}
 | 
|---|
| 164 |   $ECHO "DEBUG (${scriptName}): END"
 | 
|---|
| 165 |   exit 1
 | 
|---|
| 166 | fi
 | 
|---|
| 167 | $RM ${OUT1}
 | 
|---|
| 168 | 
 | 
|---|
| 169 | scaFileSummarized=`basename $scaFileSummarized`
 | 
|---|
| 170 | 
 | 
|---|
| 171 | #set Irods environment
 | 
|---|
| 172 | . /usr/local/shared/bin/irods_env.sh -noverbose
 | 
|---|
| 173 | #download header files to be used for signal files selction
 | 
|---|
| 174 | $MKDIR -p ./Fiber1
 | 
|---|
| 175 | dirFiberfile=`pwd`/Fiber1
 | 
|---|
| 176 | 
 | 
|---|
| 177 | dirIrods="/baoradio/data/AmasNancay/${sourceRadio}/${dateSelected}${srclower}/Fiber1"
 | 
|---|
| 178 | 
 | 
|---|
| 179 | listOfFiles=( `ils ${dirIrods} | $GREP -i "header" | $XARGS -i basename {} | $SORT -k1.7n` )
 | 
|---|
| 180 | IFS='
 | 
|---|
| 181 | '
 | 
|---|
| 182 | listOfFiles=( $( $PRINTF "%s\n" "${listOfFiles[@]}" | $AWK 'x[$0]++ == 0' ) )
 | 
|---|
| 183 | IFS=$DefaultIFS
 | 
|---|
| 184 | 
 | 
|---|
| 185 | #
 | 
|---|
| 186 | $ECHO "DEBUG (${scriptName}): Download if necessary the headers"
 | 
|---|
| 187 | #
 | 
|---|
| 188 | for ifile in ${listOfFiles[@]}
 | 
|---|
| 189 | do
 | 
|---|
| 190 | #test if the headers have not yet been downloaded
 | 
|---|
| 191 |   if [ ! -e ${dirFiberfile}/${ifile} ]; then
 | 
|---|
| 192 |       OUT2=./getheaders.$$
 | 
|---|
| 193 |       iget -f -K ${dirIrods}/${ifile} ${dirFiberfile} >${OUT2} 2>&1
 | 
|---|
| 194 |       igetStatus=`$GREP "^ERROR" ${OUT2}`
 | 
|---|
| 195 |       if [ "<$igetStatus>" != "<>" ]; then
 | 
|---|
| 196 |           $ECHO "FATAL (${scriptName}): error while iget:"
 | 
|---|
| 197 |           $ECHO $igetStatus
 | 
|---|
| 198 |           exit 1
 | 
|---|
| 199 |       fi
 | 
|---|
| 200 |       $RM -f $OUT2
 | 
|---|
| 201 |   fi
 | 
|---|
| 202 | done
 | 
|---|
| 203 | #
 | 
|---|
| 204 | $ECHO "DEBUG (${scriptName}): START call select.sh ${scaFileSummarized} ${dirFiberfile} ${typeofproc}"
 | 
|---|
| 205 | #
 | 
|---|
| 206 | #Get list of file to process
 | 
|---|
| 207 | headerFileSelected=./selectSignal.$$
 | 
|---|
| 208 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 209 | #$RM -f ${tmppublicpath}/select.finished
 | 
|---|
| 210 | ${scriptpath}/select.sh ${scaFileSummarized} ${dirFiberfile} ${typeofproc} | $GREP "^#[0-9]" | $SED "s/^#//" > $headerFileSelected
 | 
|---|
| 211 | #while [ ! -f "${tmppublicpath}/select.finished" ]; do
 | 
|---|
| 212 | #    $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/select.finished"
 | 
|---|
| 213 | #    date +%T
 | 
|---|
| 214 | #    sleep 30
 | 
|---|
| 215 | #done
 | 
|---|
| 216 | #$RM ${tmppublicpath}/select.finished
 | 
|---|
| 217 | #
 | 
|---|
| 218 | $ECHO "DEBUG (${scriptName}): END"
 | 
|---|
| 219 | #
 | 
|---|
| 220 | $ECHO "DEBUG (${scriptName}): START filling cycleArray, filesArray"
 | 
|---|
| 221 | #
 | 
|---|
| 222 | declare -a cycleArray
 | 
|---|
| 223 | declare -a filesArray
 | 
|---|
| 224 | $ECHO "DEBUG (${scriptName}): IFS value between<>: <$IFS>"
 | 
|---|
| 225 | IFS=$DefaultIFS
 | 
|---|
| 226 | $ECHO "DEBUG (${scriptName}): START cat $headerFileSelected"
 | 
|---|
| 227 | $CAT $headerFileSelected
 | 
|---|
| 228 | $ECHO "DEBUG (${scriptName}): END cat $headerFileSelected"
 | 
|---|
| 229 | 
 | 
|---|
| 230 | while read v1 v2
 | 
|---|
| 231 | do
 | 
|---|
| 232 |  cycleArray[${#cycleArray[*]}]=$v1
 | 
|---|
| 233 |  filesArray[${#filesArray[*]}]=$v2
 | 
|---|
| 234 | done < $headerFileSelected
 | 
|---|
| 235 | 
 | 
|---|
| 236 | if [ ${#cycleArray[*]} -eq 0 -o ${#filesArray[*]} -eq 0 ]; then
 | 
|---|
| 237 |    $ECHO "FATAL (${scriptName}): no header file selected (${#cycleArray[*]}, ${#filesArray[*]})"
 | 
|---|
| 238 |    exit 1
 | 
|---|
| 239 | else
 | 
|---|
| 240 |    $ECHO "DEBUG (${scriptName}): non zero elements found for cycleArray and filesArray" 
 | 
|---|
| 241 | fi
 | 
|---|
| 242 | 
 | 
|---|
| 243 | #
 | 
|---|
| 244 | $ECHO "DEBUG (${scriptName}): number of elements <${#cycleArray[*]}> <${#filesArray[*]}>"
 | 
|---|
| 245 | $ECHO "DEBUG (${scriptName}): END"
 | 
|---|
| 246 | #
 | 
|---|
| 247 | # (timeShift)
 | 
|---|
| 248 | #Add 3sec to start ON / OFF
 | 
|---|
| 249 | #Substract 4sec to start DAB ON / OFF
 | 
|---|
| 250 | #
 | 
|---|
| 251 | #Take care: Cycle numbering starts at 1 in SCAFiles while Arrays index start at 0
 | 
|---|
| 252 | #
 | 
|---|
| 253 | #for GAIN the reference cycle takes the middle of the run
 | 
|---|
| 254 | #
 | 
|---|
| 255 | #nwinmean donne le nombre de fenetre tspwin utilise pour faire calculer la moyenne des medianes de chaque fenetre
 | 
|---|
| 256 | #This is the nimber of paquets of the time window which change according to processing type
 | 
|---|
| 257 | $ECHO "DEBUG (${scriptName}): START switch on $typeofproc"
 | 
|---|
| 258 | #
 | 
|---|
| 259 | case "$typeofproc" in
 | 
|---|
| 260 |     GAIN)
 | 
|---|
| 261 |       $ECHO "process signal files for GAIN phase"
 | 
|---|
| 262 |       ingain=""
 | 
|---|
| 263 |       freqfilter="-freqfilter -"
 | 
|---|
| 264 |       nwinmean="1"
 | 
|---|
| 265 |       tspwin="5120"
 | 
|---|
| 266 |       dirName="Off"
 | 
|---|
| 267 |       cyclebasename="gaincycle"
 | 
|---|
| 268 |       indexStartHour="6"
 | 
|---|
| 269 |       timeShift="-4"
 | 
|---|
| 270 |       timeDuration="14"
 | 
|---|
| 271 |       firstCycleId=`expr  ${#cycleArray[*]} / 2`
 | 
|---|
| 272 |       firstCycleId=`expr ${firstCycleId} - 1`
 | 
|---|
| 273 |       lastp1CycleId=`expr ${firstCycleId} + 1`
 | 
|---|
| 274 |       ;;
 | 
|---|
| 275 |     GAINNF)
 | 
|---|
| 276 |       $ECHO "process signal files for GAIN phase wo Freq FILTERING"
 | 
|---|
| 277 |       ingain=""
 | 
|---|
| 278 |       freqfilter="-freqfilter 4"
 | 
|---|
| 279 |       nwinmean="1"
 | 
|---|
| 280 |       tspwin="5120"
 | 
|---|
| 281 |       dirName="Off"
 | 
|---|
| 282 |       cyclebasename="gainf4cycle"
 | 
|---|
| 283 |       indexStartHour="6"
 | 
|---|
| 284 |       timeShift="-4"
 | 
|---|
| 285 |       timeDuration="14"
 | 
|---|
| 286 |       firstCycleId=`expr  ${#cycleArray[*]} / 2`
 | 
|---|
| 287 |       firstCycleId=`expr ${firstCycleId} - 1`
 | 
|---|
| 288 |       lastp1CycleId=`expr ${firstCycleId} + 1`
 | 
|---|
| 289 |       ;;
 | 
|---|
| 290 |     ON)
 | 
|---|
| 291 |       $ECHO "process signal files for ON phases"
 | 
|---|
| 292 |       ingain="-gain gain_${dateSelected}_${srclower}.fits"
 | 
|---|
| 293 |       freqfilter=""
 | 
|---|
| 294 |       nwinmean="5"
 | 
|---|
| 295 |       tspwin="5120"
 | 
|---|
| 296 |       dirName="On"
 | 
|---|
| 297 |       cyclebasename="datacycle"
 | 
|---|
| 298 |       indexStartHour="4"
 | 
|---|
| 299 |       timeShift="3"
 | 
|---|
| 300 |       timeDuration="30"
 | 
|---|
| 301 |       firstCycleId="0"
 | 
|---|
| 302 |       lastp1CycleId="${#cycleArray[@]}"
 | 
|---|
| 303 |       ;;
 | 
|---|
| 304 |     OFF)
 | 
|---|
| 305 |       $ECHO "process signal files for OFF phases"
 | 
|---|
| 306 |       ingain="-gain gain_${dateSelected}_${srclower}.fits"
 | 
|---|
| 307 |       freqfilter=""
 | 
|---|
| 308 |       nwinmean="5"
 | 
|---|
| 309 |       tspwin="5120"
 | 
|---|
| 310 |       dirName="Off"
 | 
|---|
| 311 |       cyclebasename="datacycle"
 | 
|---|
| 312 |       indexStartHour="8"
 | 
|---|
| 313 |       timeShift="3"
 | 
|---|
| 314 |       timeDuration="30"
 | 
|---|
| 315 |       firstCycleId="0"
 | 
|---|
| 316 |       lastp1CycleId="${#cycleArray[@]}"
 | 
|---|
| 317 |       ;;
 | 
|---|
| 318 |     MEANOFF)
 | 
|---|
| 319 |       $ECHO "process signal files for OFF phases (MEAN)"
 | 
|---|
| 320 |       ingain="-gain gain_${dateSelected}_${srclower}.fits"
 | 
|---|
| 321 |       freqfilter=""
 | 
|---|
| 322 |       nwinmean="25000"
 | 
|---|
| 323 |       tspwin="0"
 | 
|---|
| 324 |       dirName="Off"
 | 
|---|
| 325 |       cyclebasename="meancycle"
 | 
|---|
| 326 |       indexStartHour="8"
 | 
|---|
| 327 |       timeShift="3"
 | 
|---|
| 328 |       timeDuration="30"
 | 
|---|
| 329 |       firstCycleId="0"
 | 
|---|
| 330 |       lastp1CycleId="${#cycleArray[@]}"
 | 
|---|
| 331 |       ;;
 | 
|---|
| 332 |     MEANON)
 | 
|---|
| 333 |       $ECHO "process signal files for ON phases (MEAN)"
 | 
|---|
| 334 |       ingain="-gain gain_${dateSelected}_${srclower}.fits"
 | 
|---|
| 335 |       freqfilter=""
 | 
|---|
| 336 |       nwinmean="25000"
 | 
|---|
| 337 |       tspwin="0"
 | 
|---|
| 338 |       dirName="On"
 | 
|---|
| 339 |       cyclebasename="meancycle"
 | 
|---|
| 340 |       indexStartHour="4"
 | 
|---|
| 341 |       timeShift="3"
 | 
|---|
| 342 |       timeDuration="30"
 | 
|---|
| 343 |       firstCycleId="0"
 | 
|---|
| 344 |       lastp1CycleId="${#cycleArray[@]}"
 | 
|---|
| 345 |       ;;
 | 
|---|
| 346 |     CALIBON)
 | 
|---|
| 347 |       $ECHO "process signal files for CALIBRATION ON phases"
 | 
|---|
| 348 |       ingain="-gain gain_${dateSelected}_${srclower}.fits"
 | 
|---|
| 349 |       freqfilter="-freqfilter -"
 | 
|---|
| 350 |       nwinmean="1"
 | 
|---|
| 351 |       tspwin="1024"
 | 
|---|
| 352 |       dirName="On"
 | 
|---|
| 353 |       cyclebasename="calibcycle"
 | 
|---|
| 354 |       indexStartHour="2"
 | 
|---|
| 355 |       timeShift="-4"
 | 
|---|
| 356 |       timeDuration="14"
 | 
|---|
| 357 |       firstCycleId="0"
 | 
|---|
| 358 |       lastp1CycleId="${#cycleArray[@]}"
 | 
|---|
| 359 |       ;;
 | 
|---|
| 360 |     CALIBOFF)
 | 
|---|
| 361 |       $ECHO "process signal files for CALIBRATION OFF phases"
 | 
|---|
| 362 |       ingain="-gain gain_${dateSelected}_${srclower}.fits"
 | 
|---|
| 363 |       freqfilter="-freqfilter -"
 | 
|---|
| 364 |       nwinmean="1"
 | 
|---|
| 365 |       tspwin="1024"
 | 
|---|
| 366 |       dirName="Off"
 | 
|---|
| 367 |       cyclebasename="calibcycle"
 | 
|---|
| 368 |       indexStartHour="6"
 | 
|---|
| 369 |       timeShift="-4"
 | 
|---|
| 370 |       timeDuration="14"
 | 
|---|
| 371 |       firstCycleId="0"
 | 
|---|
| 372 |       lastp1CycleId="${#cycleArray[@]}"
 | 
|---|
| 373 |       ;;
 | 
|---|
| 374 |     *)
 | 
|---|
| 375 |     $ECHO "FATAL (${scriptName}): type of processing"
 | 
|---|
| 376 |     usage
 | 
|---|
| 377 |     exit 1
 | 
|---|
| 378 |     ;;
 | 
|---|
| 379 | esac
 | 
|---|
| 380 | #
 | 
|---|
| 381 | $ECHO "DEBUG (${scriptName}): END"
 | 
|---|
| 382 | #
 | 
|---|
| 383 | #
 | 
|---|
| 384 | #Compute time windows (Warning usage of GMT date)
 | 
|---|
| 385 | #
 | 
|---|
| 386 | $ECHO "DEBUG (${scriptName}): START compute time windows"
 | 
|---|
| 387 | OUT=./baotiming.$$
 | 
|---|
| 388 | ${AWK} -v datesys=${DATE} -v type=${indexStartHour} -v shift=${timeShift} '
 | 
|---|
| 389 | BEGIN {FS=","}
 | 
|---|
| 390 | {
 | 
|---|
| 391 |   phaseStart=$type
 | 
|---|
| 392 |   cmd=sprintf("%s +%%s -d  \"%s\" ",datesys,phaseStart);
 | 
|---|
| 393 |   (cmd | getline phstart);
 | 
|---|
| 394 |   close(cmd);
 | 
|---|
| 395 |   newstart = phstart+shift;
 | 
|---|
| 396 |   cmd=sprintf("%s +%%T -d \"1970-01-01 %s sec GMT\"",datesys,newstart);
 | 
|---|
| 397 |   (cmd | getline newStart);
 | 
|---|
| 398 |   close(cmd);
 | 
|---|
| 399 |   print $1,newStart,phaseStart;
 | 
|---|
| 400 | }
 | 
|---|
| 401 | '  ${scaFileSummarized} > ${OUT}
 | 
|---|
| 402 | #
 | 
|---|
| 403 | $ECHO "DEBUG (${scriptName}): END"
 | 
|---|
| 404 | #
 | 
|---|
| 405 | $ECHO "DEBUG (${scriptName}): START cat ${OUT}"
 | 
|---|
| 406 | $CAT ${OUT}
 | 
|---|
| 407 | $ECHO "DEBUG (${scriptName}): END cat ${OUT}"
 | 
|---|
| 408 | #
 | 
|---|
| 409 | $ECHO "DEBUG (${scriptName}): START filling cylceArrayBis timeArray"
 | 
|---|
| 410 | #
 | 
|---|
| 411 | declare -a cycleArrayBis
 | 
|---|
| 412 | declare -a timeArray
 | 
|---|
| 413 | $ECHO "DEBUG (${scriptName}): IFS value between<>: <$IFS>"
 | 
|---|
| 414 | IFS=$DefaultIFS
 | 
|---|
| 415 | #select the selected cycles
 | 
|---|
| 416 | idtofind="0"
 | 
|---|
| 417 | while read v1 v2 v3
 | 
|---|
| 418 | do
 | 
|---|
| 419 |  if [ ${idtofind} -lt ${#cycleArray[*]} ]; then
 | 
|---|
| 420 |     if [ ${v1} = ${cycleArray[${idtofind}]} ]; then
 | 
|---|
| 421 |         cycleArrayBis[${#cycleArrayBis[*]}]=$v1
 | 
|---|
| 422 |         timeArray[${#timeArray[*]}]=$v2
 | 
|---|
| 423 |         idtofind=`expr ${idtofind} + 1`
 | 
|---|
| 424 |     fi
 | 
|---|
| 425 |  fi
 | 
|---|
| 426 | done < ${OUT}
 | 
|---|
| 427 | $ECHO "DEBUG (${scriptName}): number of elements ${#cycleArrayBis[*]} ${#timeArray[*]}"
 | 
|---|
| 428 | $ECHO "DEBUG (${scriptName}): END"
 | 
|---|
| 429 | 
 | 
|---|
| 430 | 
 | 
|---|
| 431 | #########################
 | 
|---|
| 432 | # specmfib exe
 | 
|---|
| 433 | #########################
 | 
|---|
| 434 | prg="/afs/in2p3.fr/throng/baoradio/Library/Progs/TAcq/Objs/specmfib"
 | 
|---|
| 435 | if [ ! -e $prg ]; then
 | 
|---|
| 436 |     $ECHO "FATAL (${scriptName}): $prg not found"
 | 
|---|
| 437 |     exit 1
 | 
|---|
| 438 | fi
 | 
|---|
| 439 | 
 | 
|---|
| 440 | 
 | 
|---|
| 441 | dirFiberfile=${iojobpath}/${localpath}
 | 
|---|
| 442 | 
 | 
|---|
| 443 | curDir=`pwd`
 | 
|---|
| 444 | #
 | 
|---|
| 445 | $ECHO "DEBUG (${scriptName}): in principle $dirFiberfile == $curDir "
 | 
|---|
| 446 | #
 | 
|---|
| 447 | #force single channel
 | 
|---|
| 448 | forceSingle="-singlechan"
 | 
|---|
| 449 | #debug
 | 
|---|
| 450 | prtlevel="1"
 | 
|---|
| 451 | 
 | 
|---|
| 452 | 
 | 
|---|
| 453 | #Loop on cycles
 | 
|---|
| 454 | ##
 | 
|---|
| 455 | $ECHO "DEBUG (${scriptName}): START loop on cycles Ids ${firstCycleId} to ${lastp1CycleId}"
 | 
|---|
| 456 | 
 | 
|---|
| 457 | #write the script to be send to Batch
 | 
|---|
| 458 | #get gain file if necessary
 | 
|---|
| 459 | if [ ${typeofproc} != "GAIN" ]; then
 | 
|---|
| 460 |     OUT2=./igetStatus.$$
 | 
|---|
| 461 |     iget /baoradio/data/AmasNancay/${localpath}/gain_${dateSelected}_${srclower}.fits >${OUT2} 2>&1
 | 
|---|
| 462 |     igetStatus=`$GREP "^ERROR" ${OUT2}`
 | 
|---|
| 463 |     if [ "<${igetStatus}>" != "<>" ]; then
 | 
|---|
| 464 |         $ECHO "FATAL (${scriptName}): error while iget:"
 | 
|---|
| 465 |         $ECHO $igetStatus
 | 
|---|
| 466 |         exit 1
 | 
|---|
| 467 |     fi
 | 
|---|
| 468 |     $RM ${OUT2}
 | 
|---|
| 469 | fi    
 | 
|---|
| 470 | 
 | 
|---|
| 471 | 
 | 
|---|
| 472 | for ((i=${firstCycleId};i<${lastp1CycleId};i++)); do
 | 
|---|
| 473 | #
 | 
|---|
| 474 | 
 | 
|---|
| 475 | ####
 | 
|---|
| 476 | # Check daq status
 | 
|---|
| 477 | #JEC 1/10/11 Use generic baodaqstatus name 
 | 
|---|
| 478 | ####
 | 
|---|
| 479 | #get the daq current irod status
 | 
|---|
| 480 | #tag=`${DATE} +%F`
 | 
|---|
| 481 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt
 | 
|---|
| 482 | OUT1=${publicpath}/baodaqstatus-current.txt
 | 
|---|
| 483 | 
 | 
|---|
| 484 | if [ ! -e ${OUT1}  -o ! -r ${OUT1} ]; then
 | 
|---|
| 485 |     $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
 | 
|---|
| 486 |     exit 1
 | 
|---|
| 487 | #    $ECHO "We should bring the DAQ status more up to date, this take 1 or 2min..."
 | 
|---|
| 488 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 489 | #    $RM -f ${tmppublicpath}/statusdaq.finished
 | 
|---|
| 490 | #    ${scriptpath}/statusdaq.sh > ${OUT1}
 | 
|---|
| 491 | #    while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
 | 
|---|
| 492 | #       sleep 30
 | 
|---|
| 493 | #    done
 | 
|---|
| 494 | #    $RM ${tmppublicpath}/statusdaq.finished
 | 
|---|
| 495 | #protect against remove/rewriting    
 | 
|---|
| 496 | #    $CHMOD -v 444 ${OUT1} 
 | 
|---|
| 497 | fi
 | 
|---|
| 498 | 
 | 
|---|
| 499 | #time window selection
 | 
|---|
| 500 |     tmproc="-tmproc ${timeArray[${i}]},${timeDuration}"
 | 
|---|
| 501 | #cycle <number>
 | 
|---|
| 502 |     cycle="${cycleArray[${i}]}"
 | 
|---|
| 503 |     if [ "<${firstCycle}>" != "<>" -a "<${lastCycle}>" != "<>" ]; then
 | 
|---|
| 504 |         if [ ${cycle} -lt ${firstCycle} -o ${cycle} -gt ${lastCycle} ]; then
 | 
|---|
| 505 |             continue
 | 
|---|
| 506 |         fi
 | 
|---|
| 507 |     fi
 | 
|---|
| 508 |     $ECHO "DEBUG (${scriptName}): process cycle $cycle"
 | 
|---|
| 509 | 
 | 
|---|
| 510 | #cycle <name><number>
 | 
|---|
| 511 |     cycle="${cyclebasename}${cycleArray[${i}]}"
 | 
|---|
| 512 | #signal files selection
 | 
|---|
| 513 |     infiles="${filesArray[${i}]}"
 | 
|---|
| 514 | #
 | 
|---|
| 515 | #Prepare BQS parameters: MEMORY, CPU...#
 | 
|---|
| 516 |     infilesArray=( `$ECHO $infiles | $AWK 'BEGIN {FS=","} {for(i=1;i<NF;i++)print $i;}'` )
 | 
|---|
| 517 |     IFS='
 | 
|---|
| 518 |     '
 | 
|---|
| 519 |     infilesArray=( $( printf "%s\n" "${infilesArray[@]}" | awk 'x[$0]++ == 0' ) )
 | 
|---|
| 520 |     IFS=$DefaultIFS
 | 
|---|
| 521 |     firstFile=${infilesArray[0]}
 | 
|---|
| 522 |     lastFile=${infilesArray[1]}
 | 
|---|
| 523 | #
 | 
|---|
| 524 | #
 | 
|---|
| 525 | #
 | 
|---|
| 526 | #get signals files
 | 
|---|
| 527 |     OUT3=./getsignals.$$
 | 
|---|
| 528 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 529 | #    $RM -f ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 530 |     ${scriptpath}/getsignalfiles.sh ${sourceRadio} ${dateSelected} ${firstFile}  ${lastFile} > ${OUT3} 2>&1
 | 
|---|
| 531 | #    while [ ! -f "${tmppublicpath}/getsignalfiles.finished" ]; do
 | 
|---|
| 532 | #       $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getsignalfiles.finished"
 | 
|---|
| 533 | #       date +%T
 | 
|---|
| 534 | #       sleep 30
 | 
|---|
| 535 | #    done
 | 
|---|
| 536 | #    $RM ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 537 | 
 | 
|---|
| 538 |     getSignals=`$GREP "^FATAL" ${OUT3}`
 | 
|---|
| 539 |     if [ "<$getSignals>" != "<>" ]; then
 | 
|---|
| 540 |         $ECHO "FATAL (${scriptName}): error while get signals"
 | 
|---|
| 541 |         $ECHO $getSignals
 | 
|---|
| 542 |         exit 1
 | 
|---|
| 543 |     fi
 | 
|---|
| 544 |     $RM ${OUT3}
 | 
|---|
| 545 | 
 | 
|---|
| 546 | #location of the signal file
 | 
|---|
| 547 |     fibfile="${curDir} 1,2"
 | 
|---|
| 548 | #
 | 
|---|
| 549 |     outDir=${curDir}/${dirName}/${cycle}
 | 
|---|
| 550 |     $MKDIR -p ${outDir}
 | 
|---|
| 551 | 
 | 
|---|
| 552 | #
 | 
|---|
| 553 | # where ami...
 | 
|---|
| 554 | #
 | 
|---|
| 555 |     $ECHO "We are here `pwd`"
 | 
|---|
| 556 |     $LS -lrth
 | 
|---|
| 557 |     $FIND . -name "igetStatus.*" | $XARGS -i  $CAT {}
 | 
|---|
| 558 |     $LS ./Fiber1 | $WC -l
 | 
|---|
| 559 |     $LS ./Fiber2 | $WC -l
 | 
|---|
| 560 |     $LS -lR ${outDir}
 | 
|---|
| 561 | 
 | 
|---|
| 562 | #Note: here act=gain means only that specmfib will use median-like algorithms (not only for gains...)
 | 
|---|
| 563 |     $prg -act ${action} $forceSingle $freqfilter  -prt $prtlevel -out ${outDir} -nmean $nwinmean $ingain $tmproc -tspwin ${tspwin},0,0 -in $infiles ${fibfile}
 | 
|---|
| 564 | 
 | 
|---|
| 565 |     $ECHO    ${outDir}
 | 
|---|
| 566 |     $LS -lrt ${outDir}
 | 
|---|
| 567 | 
 | 
|---|
| 568 | #save results to Irods (use option -f ONLY to force override)
 | 
|---|
| 569 |     iput -v -K -r -f ${curDir}/${dirName} /baoradio/data/AmasNancay/${localpath}
 | 
|---|
| 570 | #
 | 
|---|
| 571 | #clean the signal files which can at the end of the day fill completly the scratch directory of the batch work/AmasNancayer
 | 
|---|
| 572 |     $RM -rf ${iojobpath}/${localpath}/Fiber1
 | 
|---|
| 573 |     $RM -rf ${iojobpath}/${localpath}/Fiber2
 | 
|---|
| 574 | #    $RM -rf ${iojobpath}/${localpath}/${typeofproc} JEC 25/10/11
 | 
|---|
| 575 |     $RM -rf ${curDir}/${dirName}
 | 
|---|
| 576 | #
 | 
|---|
| 577 | #
 | 
|---|
| 578 | 
 | 
|---|
| 579 | #end loop on cycles
 | 
|---|
| 580 | done
 | 
|---|
| 581 | #
 | 
|---|
| 582 | $ECHO "DEBUG (${scriptName}): END loop on cycles"
 | 
|---|
| 583 | 
 | 
|---|
| 584 | exit 0
 | 
|---|