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