[624] | 1 | #!/bin/sh -xvf
|
---|
[507] | 2 | #
|
---|
| 3 | #Script sh d'extraction de fichier SCA des sequances Diodes a Bruit (DAB)
|
---|
| 4 | #et Data des cycles ON/OFF
|
---|
| 5 | #Bash script that extract from SCA files the DAB/DATA phases in ON/OFF cycles
|
---|
| 6 | #It is supposed that the sequence is: DAB1 DATA1 DAB2 DATA2
|
---|
| 7 | #and that the DAB1 and DAB2 have equal number of subsequences
|
---|
| 8 | # Auteur: JE Campagne (LAL Orsay)
|
---|
| 9 | # Creation: 11 Avril 2011
|
---|
| 10 | # Revision: 12 Avril 2011
|
---|
| 11 | # o 12/04/11: mv date format to %Y-%m-%d %T for further treatment by 'date'
|
---|
| 12 | # system function
|
---|
| 13 |
|
---|
| 14 | #Basic tuning of system fuction used.
|
---|
| 15 | AWK=/bin/awk
|
---|
| 16 | SED=/bin/sed
|
---|
| 17 | GREP=/bin/grep
|
---|
| 18 | WC=/usr/bin/wc
|
---|
| 19 | RM=/bin/rm
|
---|
| 20 | CAT=/bin/cat
|
---|
| 21 | TOUCH=/bin/touch
|
---|
| 22 | DATE=/bin/date
|
---|
| 23 | ECHO=/bin/echo
|
---|
| 24 | LS=/bin/ls
|
---|
| 25 | MKDIR=/bin/mkdir
|
---|
| 26 | DefaultIFS=$' \t\n'
|
---|
| 27 | IFS=$DefaultIFS
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | scriptName="`basename $0`"
|
---|
| 31 | $ECHO "Processing script ${scriptName} at `date`"
|
---|
| 32 |
|
---|
| 33 | #temporary files to synchronize scripts
|
---|
[516] | 34 | tmppublicpath=${TMPPUBLICPATH}
|
---|
[507] | 35 | $LS -l ${tmppublicpath} > /dev/null
|
---|
| 36 |
|
---|
| 37 | #Path where the job will do temporary IO
|
---|
[579] | 38 | . ${SCRIPTPATH}/set_iojobpath.sh
|
---|
| 39 | iojobpath=$(set_iojobpath)
|
---|
[507] | 40 | cd ${iojobpath}
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | if [ ! $# = 1 ]
|
---|
| 44 | then
|
---|
| 45 | $ECHO "FATAL (${scriptName}): usage: ./sca.sh <file>"
|
---|
| 46 | exit 1
|
---|
| 47 | fi
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | fullfile=$1
|
---|
| 51 | if [ ! -e $fullfile ]
|
---|
| 52 | then
|
---|
[624] | 53 | $ECHO "FATAL (${scriptName}): <${fullfile}> not found: FATAL"
|
---|
[507] | 54 | exit 1
|
---|
| 55 | fi
|
---|
| 56 |
|
---|
| 57 | #The output file would be in "fullprocfile"
|
---|
| 58 | filename=$(basename $fullfile)
|
---|
| 59 | #extension=${filename##*.}
|
---|
| 60 | filename=${filename%.*}
|
---|
| 61 | extension=".sum"
|
---|
| 62 | fullprocfile=${filename}${extension}
|
---|
| 63 | #create empty output file
|
---|
| 64 | $RM -f $fullprocfile
|
---|
| 65 | $TOUCH $fullprocfile
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | #extract the PERI lines valid for DAB and DATA
|
---|
| 69 | OUT1=./tmp1.$$
|
---|
| 70 | $AWK '
|
---|
| 71 | $1=="PERI" {
|
---|
| 72 | print "CYCLE",$6,$2,$3,$7,$8
|
---|
| 73 | }
|
---|
| 74 | ' $fullfile > $OUT1
|
---|
| 75 |
|
---|
[624] | 76 | echo "DEBUG START"
|
---|
| 77 | cat $OUT1
|
---|
| 78 | echo "DEBUG STOP"
|
---|
[507] | 79 |
|
---|
[624] | 80 |
|
---|
[507] | 81 | #Sequence of the cycle numbers (perform a unique filtering)
|
---|
| 82 | tableau=( `cat $OUT1 | $AWK '{print $2}'` )
|
---|
| 83 | IFS='
|
---|
| 84 | '
|
---|
| 85 | tableau=( $( printf "%s\n" "${tableau[@]}" | awk 'x[$0]++ == 0' ) )
|
---|
| 86 | IFS=$DefaultIFS
|
---|
| 87 |
|
---|
| 88 | #scan each cycle
|
---|
| 89 | OUT2=./tmp2.$$
|
---|
| 90 | for i in ${tableau[@]}
|
---|
| 91 | do
|
---|
| 92 | #extract the DAB calibration phases. Hypothesis: 2 identical sequences
|
---|
| 93 | CALIB=./tmp_cycle_${i}_calib.$$
|
---|
| 94 | $AWK -v cycle=$i '$2==cycle && $5=="-1" {print $0} ' $OUT1 > $CALIB
|
---|
| 95 | nlines=`$WC $CALIB | $AWK '{print $1}'`
|
---|
| 96 | start1=1
|
---|
| 97 | let "end1=nlines/2"
|
---|
| 98 | let "start2=end1+1"
|
---|
| 99 | end2=$nlines
|
---|
| 100 |
|
---|
| 101 | #date Start/End of DAB1
|
---|
| 102 | $SED -e "${start1}!d" $CALIB | $AWK -v cycle=$i 'BEGIN {ORS=","} {
|
---|
| 103 | split($4,b,".");
|
---|
| 104 | print cycle "," $3,b[1]}' >> ${OUT2}
|
---|
| 105 | $SED -e "${end1}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
|
---|
| 106 | split($4,b,".");
|
---|
| 107 | print $3,b[1]}' >> ${OUT2}
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | #date Start/End of DATA1: use date system function to add the duration to
|
---|
| 111 | #compute the End,cf. End = Start + duration
|
---|
| 112 | $AWK -v datesys=$DATE -v cycle=$i '$2==cycle && ( $5=="1" ) {
|
---|
| 113 | split($3,a,"/");
|
---|
| 114 | split($4,b,".");
|
---|
| 115 | dateStart=a[2]"/"a[1]"/"a[3] " " b[1];
|
---|
| 116 | duree=$6 " sec";
|
---|
| 117 | cmd=sprintf("%s --date \"%s %s\" \"+%%d/%%m/%%y %%T\" ",datesys,dateStart,duree);
|
---|
| 118 | (cmd | getline dateEnd);
|
---|
| 119 | close(cmd);
|
---|
| 120 | ORS=","; print a[1]"/"a[2]"/"a[3] " " b[1];
|
---|
| 121 | ORS=","; print dateEnd;
|
---|
| 122 | } ' $OUT1 >> ${OUT2}
|
---|
| 123 |
|
---|
| 124 | #same as DAB1 for DAB2
|
---|
| 125 | $SED -e "${start2}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
|
---|
| 126 | split($4,b,".");
|
---|
| 127 | print $3,b[1]}' >> ${OUT2}
|
---|
| 128 | $SED -e "${end2}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
|
---|
| 129 | split($4,b,".");
|
---|
| 130 | print $3,b[1]}' >> ${OUT2}
|
---|
| 131 | #same as DATA1 for DATA2
|
---|
| 132 | $AWK -v datesys=$DATE -v cycle=$i '$2==cycle && ( $5=="2" ) {
|
---|
| 133 | split($3,a,"/");
|
---|
| 134 | split($4,b,".")
|
---|
| 135 | dateStart=a[2]"/"a[1]"/"a[3] " " b[1];
|
---|
| 136 | duree=$6 " sec";
|
---|
| 137 | cmd=sprintf("%s --date \"%s %s\" \"+%%d/%%m/%%y %%T\" ",datesys,dateStart,duree);
|
---|
| 138 | (cmd | getline dateEnd);
|
---|
| 139 | close(cmd);
|
---|
| 140 | ORS=","; print a[1]"/"a[2]"/"a[3] " " b[1];
|
---|
| 141 | ORS="\n"; print dateEnd;
|
---|
| 142 | } ' $OUT1 >> ${OUT2}
|
---|
| 143 | #clean
|
---|
| 144 | $RM $CALIB
|
---|
| 145 | done
|
---|
| 146 |
|
---|
| 147 | #transform all the date/time into %Y-%m-%d %T
|
---|
| 148 | $AWK -v datesys=$DATE '
|
---|
| 149 | BEGIN { FS=","; OFS="," }
|
---|
| 150 | {
|
---|
| 151 | for (i=2;i<=NF;i++) {
|
---|
| 152 | split($i,a,"/");
|
---|
| 153 | newdate=a[2]"/"a[1]"/"a[3];
|
---|
| 154 | cmd=sprintf("%s --date \"%s\" \"+%%Y-%%m-%%d %%T\" ",datesys,newdate);
|
---|
| 155 | (cmd | getline newdate);
|
---|
| 156 | close(cmd);
|
---|
| 157 | $i=newdate;
|
---|
| 158 | }
|
---|
| 159 | print $0;
|
---|
| 160 | }' ${OUT2} > ${fullprocfile}
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | #clean
|
---|
| 164 | $RM $OUT1
|
---|
| 165 | $RM $OUT2
|
---|
| 166 |
|
---|
| 167 | exit 0
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 |
|
---|