source: BAORadio/AmasNancay/v3/sca.sh@ 612

Last change on this file since 612 was 547, checked in by campagne, 14 years ago

move to trunk the previous HEAD (jec)

File size: 4.5 KB
Line 
1#!/bin/sh
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.
15AWK=/bin/awk
16SED=/bin/sed
17GREP=/bin/grep
18WC=/usr/bin/wc
19RM=/bin/rm
20CAT=/bin/cat
21TOUCH=/bin/touch
22DATE=/bin/date
23ECHO=/bin/echo
24LS=/bin/ls
25MKDIR=/bin/mkdir
26DefaultIFS=$' \t\n'
27IFS=$DefaultIFS
28
29
30scriptName="`basename $0`"
31$ECHO "Processing script ${scriptName} at `date`"
32
33#temporary files to synchronize scripts
34tmppublicpath=${TMPPUBLICPATH}
35$LS -l ${tmppublicpath} > /dev/null
36
37#Path where the job will do temporary IO
38if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then
39 iojobpath="/sps/baoradio/AmasNancay/JEC"
40 $MKDIR -p $iojobpath
41elif [ ${ENVIRONMENT} = "BATCH" ] ; then
42 iojobpath=${TMPBATCH}
43else
44 $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
45#JEC 29/9/11 avoid finished stuff
46# touch ${tmppublicpath}/sca.finished
47 exit 1
48fi
49cd ${iojobpath}
50
51
52if [ ! $# = 1 ]
53 then
54 $ECHO "FATAL (${scriptName}): usage: ./sca.sh <file>"
55#JEC 29/9/11 avoid finished stuff
56# touch ${tmppublicpath}/sca.finished
57 exit 1
58fi
59
60
61fullfile=$1
62if [ ! -e $fullfile ]
63 then
64 $ECHO "FATAL (${scriptName}): $fullfile not found: FATAL"
65#JEC 29/9/11 avoid finished stuff
66# touch ${tmppublicpath}/sca.finished
67 exit 1
68fi
69
70#The output file would be in "fullprocfile"
71filename=$(basename $fullfile)
72#extension=${filename##*.}
73filename=${filename%.*}
74extension=".sum"
75fullprocfile=${filename}${extension}
76#create empty output file
77$RM -f $fullprocfile
78$TOUCH $fullprocfile
79
80
81#extract the PERI lines valid for DAB and DATA
82OUT1=./tmp1.$$
83$AWK '
84$1=="PERI" {
85 print "CYCLE",$6,$2,$3,$7,$8
86 }
87' $fullfile > $OUT1
88
89
90#Sequence of the cycle numbers (perform a unique filtering)
91tableau=( `cat $OUT1 | $AWK '{print $2}'` )
92IFS='
93'
94tableau=( $( printf "%s\n" "${tableau[@]}" | awk 'x[$0]++ == 0' ) )
95IFS=$DefaultIFS
96
97#scan each cycle
98OUT2=./tmp2.$$
99for i in ${tableau[@]}
100do
101#extract the DAB calibration phases. Hypothesis: 2 identical sequences
102 CALIB=./tmp_cycle_${i}_calib.$$
103 $AWK -v cycle=$i '$2==cycle && $5=="-1" {print $0} ' $OUT1 > $CALIB
104 nlines=`$WC $CALIB | $AWK '{print $1}'`
105 start1=1
106 let "end1=nlines/2"
107 let "start2=end1+1"
108 end2=$nlines
109
110#date Start/End of DAB1
111 $SED -e "${start1}!d" $CALIB | $AWK -v cycle=$i 'BEGIN {ORS=","} {
112 split($4,b,".");
113 print cycle "," $3,b[1]}' >> ${OUT2}
114 $SED -e "${end1}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
115 split($4,b,".");
116 print $3,b[1]}' >> ${OUT2}
117
118
119#date Start/End of DATA1: use date system function to add the duration to
120#compute the End,cf. End = Start + duration
121 $AWK -v datesys=$DATE -v cycle=$i '$2==cycle && ( $5=="1" ) {
122 split($3,a,"/");
123 split($4,b,".");
124 dateStart=a[2]"/"a[1]"/"a[3] " " b[1];
125 duree=$6 " sec";
126 cmd=sprintf("%s --date \"%s %s\" \"+%%d/%%m/%%y %%T\" ",datesys,dateStart,duree);
127 (cmd | getline dateEnd);
128 close(cmd);
129 ORS=","; print a[1]"/"a[2]"/"a[3] " " b[1];
130 ORS=","; print dateEnd;
131 } ' $OUT1 >> ${OUT2}
132
133#same as DAB1 for DAB2
134 $SED -e "${start2}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
135 split($4,b,".");
136 print $3,b[1]}' >> ${OUT2}
137 $SED -e "${end2}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
138 split($4,b,".");
139 print $3,b[1]}' >> ${OUT2}
140#same as DATA1 for DATA2
141 $AWK -v datesys=$DATE -v cycle=$i '$2==cycle && ( $5=="2" ) {
142 split($3,a,"/");
143 split($4,b,".")
144 dateStart=a[2]"/"a[1]"/"a[3] " " b[1];
145 duree=$6 " sec";
146 cmd=sprintf("%s --date \"%s %s\" \"+%%d/%%m/%%y %%T\" ",datesys,dateStart,duree);
147 (cmd | getline dateEnd);
148 close(cmd);
149 ORS=","; print a[1]"/"a[2]"/"a[3] " " b[1];
150 ORS="\n"; print dateEnd;
151 } ' $OUT1 >> ${OUT2}
152#clean
153 $RM $CALIB
154done
155
156#transform all the date/time into %Y-%m-%d %T
157$AWK -v datesys=$DATE '
158BEGIN { FS=","; OFS="," }
159{
160 for (i=2;i<=NF;i++) {
161 split($i,a,"/");
162 newdate=a[2]"/"a[1]"/"a[3];
163 cmd=sprintf("%s --date \"%s\" \"+%%Y-%%m-%%d %%T\" ",datesys,newdate);
164 (cmd | getline newdate);
165 close(cmd);
166 $i=newdate;
167 }
168 print $0;
169}' ${OUT2} > ${fullprocfile}
170
171
172#clean
173$RM $OUT1
174$RM $OUT2
175
176#JEC 29/9/11 avoid finished stuff
177#touch ${tmppublicpath}/sca.finished
178exit 0
179
180
181
Note: See TracBrowser for help on using the repository browser.