[507] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | #hypothesis: ON = data1 phase, OFF data2 phase |
---|
| 4 | |
---|
| 5 | #Basic tuning of system fuction used. |
---|
| 6 | AWK=/bin/awk |
---|
| 7 | SED=/bin/sed |
---|
| 8 | GREP=/bin/grep |
---|
| 9 | WC=/usr/bin/wc |
---|
| 10 | RM=/bin/rm |
---|
| 11 | CAT=/bin/cat |
---|
| 12 | TOUCH=/bin/touch |
---|
| 13 | DATE=/bin/date |
---|
| 14 | ECHO=/bin/echo |
---|
| 15 | FIND=/usr/bin/find |
---|
| 16 | XARGS=/usr/bin/xargs |
---|
| 17 | SORT=/bin/sort |
---|
| 18 | MKDIR=/bin/mkdir |
---|
| 19 | LS=/bin/ls |
---|
| 20 | DefaultIFS=$' \t\n' |
---|
| 21 | IFS=$DefaultIFS |
---|
| 22 | |
---|
| 23 | scriptName="`basename $0`" |
---|
| 24 | $ECHO "Processing script ${scriptName} at `date`" |
---|
| 25 | |
---|
| 26 | if [ ! $# = 3 ]; then |
---|
| 27 | $ECHO "usage: ${scriptName} <scaXYZ.sum> <signalXYZDirectory> <type of phase:ON|OFF|CALIBON|CALIBOFF>" |
---|
[540] | 28 | #JEC 29/9/11 avoid finished stuff |
---|
| 29 | # touch ${tmppublicpath}/select.finished |
---|
[507] | 30 | exit 0 |
---|
| 31 | fi |
---|
| 32 | |
---|
| 33 | #Path to public backupable path |
---|
| 34 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 35 | |
---|
| 36 | #temporary files to synchronize scripts |
---|
[516] | 37 | tmppublicpath=${TMPPUBLICPATH} |
---|
[507] | 38 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | #Path of the utility scripts |
---|
[510] | 42 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay" |
---|
[507] | 43 | |
---|
| 44 | |
---|
| 45 | OUT1=./selectFits.$$ |
---|
| 46 | |
---|
| 47 | #inputs x-chexk sca file |
---|
| 48 | inScaFile=$1 |
---|
| 49 | if [ ! -e $inScaFile ]; then |
---|
| 50 | $ECHO "FATAL (${scriptName}): $inScaFile not found" |
---|
[540] | 51 | #JEC 29/9/11 avoid finished stuff |
---|
| 52 | # touch ${tmppublicpath}/select.finished |
---|
[507] | 53 | exit 1 |
---|
| 54 | fi |
---|
| 55 | |
---|
| 56 | #Where to look at |
---|
| 57 | inFiberDir=$2 |
---|
| 58 | |
---|
| 59 | inTypeOfPhase=$3 |
---|
| 60 | case "$inTypeOfPhase" in |
---|
| 61 | ON) |
---|
| 62 | $ECHO "INFO (${scriptName}): filter signal files for ON phases";; |
---|
| 63 | OFF) |
---|
| 64 | $ECHO "INFO (${scriptName}): filter signal files for OFF phases";; |
---|
| 65 | CALIBON) |
---|
| 66 | $ECHO "INFO (${scriptName}): filter signal files for CALIBRATION ON phases";; |
---|
| 67 | CALIBOFF) |
---|
| 68 | $ECHO "INFO (${scriptName}): filter signal files for CALIBRATION OFF phases";; |
---|
| 69 | GAIN) |
---|
| 70 | $ECHO "INFO (${scriptName}): filter signal files for GAIN = CALIB OFF phases";; |
---|
| 71 | *) |
---|
| 72 | $ECHO "FATAL (${scriptName}): use ON|OFF|CALIBON|CALIBOFF phase tags." |
---|
[540] | 73 | #JEC 29/9/11 avoid finished stuff |
---|
| 74 | # touch ${tmppublicpath}/select.finished |
---|
[507] | 75 | exit 1 |
---|
| 76 | ;; |
---|
| 77 | esac |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | ################# |
---|
| 81 | #fill the arrays association header file with start/end date&time |
---|
| 82 | # arrays |
---|
| 83 | declare -a sigStart |
---|
| 84 | declare -a sigEnd |
---|
| 85 | declare -a sigFile |
---|
| 86 | |
---|
| 87 | for fullfile in $( $FIND $inFiberDir -name "header*" | $XARGS -i basename {} | $SORT -k1.7n) |
---|
| 88 | do |
---|
| 89 | filename=$(basename $fullfile) |
---|
| 90 | extension=${filename##*.} |
---|
| 91 | filename=${filename%.*} |
---|
| 92 | ffn=${inFiberDir}/${filename}.${extension} |
---|
| 93 | # echo "process $ffn" |
---|
| 94 | while read -n80 L |
---|
| 95 | do |
---|
| 96 | [ "${L::3}" = "END" ] && break |
---|
| 97 | echo $L |
---|
| 98 | done < $ffn > $OUT1 |
---|
| 99 | |
---|
| 100 | strStart=`$GREP TMSTART $OUT1 | $AWK '{split($0,a,"/"); split(a[1],b,"="); print b[2];}' | $SED 's/^[ \t]*//;s/[ \t]*$//' | $SED "s/^\([\"']\)\(.*\)\1\$/\2/g" | $AWK '{split($0,a,"T"); print a[1]" "a[2];}' ` |
---|
| 101 | |
---|
| 102 | strEnd=`$GREP TMEND $OUT1 | $AWK '{split($0,a,"/"); split(a[1],b,"="); print b[2];}' | $SED 's/^[ \t]*//;s/[ \t]*$//' | $SED "s/^\([\"']\)\(.*\)\1\$/\2/g" | $AWK '{split($0,a,"T"); print a[1]" "a[2];}' ` |
---|
| 103 | |
---|
| 104 | if [[ -n "$strStart" && -n "$strEnd" ]]; then |
---|
| 105 | timeStart=`${DATE} +%s -d "${strStart}"` |
---|
| 106 | timeEnd=`${DATE} +%s -d "${strEnd}"` |
---|
| 107 | # echo "$fullfile start $strStart <$timeStart>, end $strEnd <$timeEnd>" |
---|
| 108 | sigStart[${#sigStart[*]}]=$timeStart |
---|
| 109 | sigEnd[${#sigEnd[*]}]=$timeEnd |
---|
| 110 | sigFile[${#sigFile[*]}]=$filename |
---|
| 111 | else |
---|
| 112 | $ECHO "WARNING (${scriptName}): $ffn PATHOLOGIQUE" |
---|
| 113 | fi |
---|
| 114 | done |
---|
| 115 | |
---|
| 116 | ############ |
---|
| 117 | #scan all the cycles |
---|
| 118 | # calib1start=$2; calib1end=$3; |
---|
| 119 | # data1start=$4; data1end=$5; |
---|
| 120 | # calib2start=$6; calib2end=$7; |
---|
| 121 | # data2start=$8; data2end=$9; |
---|
| 122 | #to pass to awk: use a "," as field separator |
---|
| 123 | awk_sigStart=$( printf "%s," "${sigStart[@]}" ) |
---|
| 124 | awk_sigEnd=$( printf "%s," "${sigEnd[@]}" ) |
---|
| 125 | awk_sigFile=$( printf "%s," "${sigFile[@]}" ) |
---|
| 126 | |
---|
| 127 | #attention a la derniere "," pour le calcul de nfile |
---|
| 128 | OUT1=./tmpselect1.$$ |
---|
| 129 | #selection d'une seul cycle pour debug |
---|
| 130 | $AWK -v datesys=$DATE -v type=$inTypeOfPhase -v str_sigStart="$awk_sigStart" -v str_sigEnd="$awk_sigEnd" -v str_sigFile="$awk_sigFile" ' |
---|
| 131 | BEGIN { |
---|
| 132 | FS=","; |
---|
| 133 | split(str_sigStart,a_sigStart,","); |
---|
| 134 | split(str_sigEnd,a_sigEnd,","); |
---|
| 135 | nfile=split(str_sigFile,a_sigFile,","); |
---|
| 136 | delete a_sigFile[nfile]; |
---|
| 137 | delete a_sigStart[nfile]; |
---|
| 138 | delete a_sigEnd[nfile]; |
---|
| 139 | nfile--; |
---|
| 140 | |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | { |
---|
| 144 | cycle=$1; |
---|
| 145 | |
---|
| 146 | if ( type == "ON" ) { |
---|
| 147 | phaseStart=$4; phaseEnd=$5; |
---|
| 148 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart); |
---|
| 149 | (cmd | getline phstart); |
---|
| 150 | close(cmd); |
---|
| 151 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd); |
---|
| 152 | (cmd | getline phend); |
---|
| 153 | close(cmd); |
---|
| 154 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">"; |
---|
| 155 | deltaStartSafety=4; |
---|
| 156 | deltaEndSafety=-4; |
---|
| 157 | } |
---|
| 158 | else if ( type == "OFF" ) { |
---|
| 159 | phaseStart=$8; phaseEnd=$9; |
---|
| 160 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart); |
---|
| 161 | (cmd | getline phstart); |
---|
| 162 | close(cmd); |
---|
| 163 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd); |
---|
| 164 | (cmd | getline phend); |
---|
| 165 | close(cmd); |
---|
| 166 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">"; |
---|
| 167 | deltaStartSafety=4; |
---|
| 168 | deltaEndSafety=-4; |
---|
| 169 | } |
---|
| 170 | else if ( type == "CALIBON" ) { |
---|
| 171 | phaseStart=$2; phaseEnd=$3; |
---|
| 172 | print "Phase: ",type," cycle: ",cycle,": <",phaseStart,">:<",phaseEnd,">"; |
---|
| 173 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart); |
---|
| 174 | (cmd | getline phstart); |
---|
| 175 | close(cmd); |
---|
| 176 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd); |
---|
| 177 | (cmd | getline phend); |
---|
| 178 | close(cmd); |
---|
| 179 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">"; |
---|
| 180 | deltaStartSafety=-6; |
---|
| 181 | deltaEndSafety=6; |
---|
| 182 | } |
---|
| 183 | else if ( (type == "CALIBOFF") || (type == "GAIN") ) { |
---|
| 184 | phaseStart=$6; phaseEnd=$7; |
---|
| 185 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseStart); |
---|
| 186 | (cmd | getline phstart); |
---|
| 187 | close(cmd); |
---|
| 188 | cmd=sprintf("%s +%%s -d \"%s\" ",datesys,phaseEnd); |
---|
| 189 | (cmd | getline phend); |
---|
| 190 | close(cmd); |
---|
| 191 | # print "Phase: ",type," cycle: ",cycle,": <",phstart,">:<",phend,">"; |
---|
| 192 | deltaStartSafety=-6; |
---|
| 193 | deltaEndSafety=6; |
---|
| 194 | } |
---|
| 195 | else { |
---|
| 196 | print "FATAL: ",type," NOT YET SUPPORTED"; exit 1; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | for (i=1; i<=nfile; i++) { |
---|
| 200 | diffstart = a_sigStart[i] - phstart; |
---|
| 201 | diffend = a_sigEnd[i] - phend; |
---|
| 202 | # print "file ",i," start ",a_sigStart[i],": diff <" diffstart ">:<" diffend ">"; |
---|
| 203 | if ( diffstart >= deltaStartSafety && diffend <= deltaEndSafety ) |
---|
| 204 | print "cycle ",cycle," file ",i-1," accepted ",a_sigFile[i]; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | }' $inScaFile > ${OUT1} |
---|
| 209 | |
---|
| 210 | OUT2=./tmpselect2.$$ |
---|
| 211 | $AWK ' |
---|
| 212 | BEGIN { max=0; min=999999; }; |
---|
| 213 | |
---|
| 214 | ($1=="cycle") { table[$2] = table[$2]","$4; if($2>max){max=$2}; if($2<min){min=$2} }; |
---|
| 215 | |
---|
| 216 | END { for (j=min;j<=max;j++) {print j,table[j];} } |
---|
| 217 | ' ${OUT1} > ${OUT2} |
---|
| 218 | |
---|
| 219 | $AWK ' |
---|
| 220 | BEGIN { FS=","} |
---|
| 221 | { |
---|
| 222 | print "#"$1,$2","$NF",1"; |
---|
| 223 | } |
---|
| 224 | ' ${OUT2} |
---|
| 225 | |
---|
| 226 | $RM $OUT1 |
---|
| 227 | $RM $OUT2 |
---|
| 228 | |
---|
[540] | 229 | #JEC 29/9/11 avoid finished stuff |
---|
| 230 | #touch ${tmppublicpath}/select.finished |
---|
[507] | 231 | exit 0 |
---|