source: BAORadio/AmasNancay/trunk/sca.sh@ 624

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

sca decryptor for Drift Scan data (jec)

File size: 4.1 KB
RevLine 
[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.
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
[516]34tmppublicpath=${TMPPUBLICPATH}
[507]35$LS -l ${tmppublicpath} > /dev/null
36
37#Path where the job will do temporary IO
[579]38. ${SCRIPTPATH}/set_iojobpath.sh
39iojobpath=$(set_iojobpath)
[507]40cd ${iojobpath}
41
42
43if [ ! $# = 1 ]
44 then
45 $ECHO "FATAL (${scriptName}): usage: ./sca.sh <file>"
46 exit 1
47fi
48
49
50fullfile=$1
51if [ ! -e $fullfile ]
52 then
[624]53 $ECHO "FATAL (${scriptName}): <${fullfile}> not found: FATAL"
[507]54 exit 1
55fi
56
57#The output file would be in "fullprocfile"
58filename=$(basename $fullfile)
59#extension=${filename##*.}
60filename=${filename%.*}
61extension=".sum"
62fullprocfile=${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
69OUT1=./tmp1.$$
70$AWK '
71$1=="PERI" {
72 print "CYCLE",$6,$2,$3,$7,$8
73 }
74' $fullfile > $OUT1
75
[624]76echo "DEBUG START"
77cat $OUT1
78echo "DEBUG STOP"
[507]79
[624]80
[507]81#Sequence of the cycle numbers (perform a unique filtering)
82tableau=( `cat $OUT1 | $AWK '{print $2}'` )
83IFS='
84'
85tableau=( $( printf "%s\n" "${tableau[@]}" | awk 'x[$0]++ == 0' ) )
86IFS=$DefaultIFS
87
88#scan each cycle
89OUT2=./tmp2.$$
90for i in ${tableau[@]}
91do
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
145done
146
147#transform all the date/time into %Y-%m-%d %T
148$AWK -v datesys=$DATE '
149BEGIN { 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
167exit 0
168
169
170
Note: See TracBrowser for help on using the repository browser.