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

Last change on this file since 637 was 625, checked in by torrento, 13 years ago

Recover working copy

File size: 4.0 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
38. ${SCRIPTPATH}/set_iojobpath.sh
39iojobpath=$(set_iojobpath)
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
53    $ECHO "FATAL (${scriptName}): $fullfile not found: FATAL"
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
76
77#Sequence of the cycle numbers (perform a unique filtering)
78tableau=( `cat $OUT1 | $AWK '{print $2}'` )
79IFS='
80'
81tableau=( $( printf "%s\n" "${tableau[@]}" | awk 'x[$0]++ == 0' ) )
82IFS=$DefaultIFS
83
84#scan each cycle
85OUT2=./tmp2.$$
86for i in ${tableau[@]}
87do
88#extract the DAB calibration phases. Hypothesis: 2 identical sequences
89  CALIB=./tmp_cycle_${i}_calib.$$
90  $AWK -v cycle=$i '$2==cycle && $5=="-1" {print $0} ' $OUT1 > $CALIB
91  nlines=`$WC $CALIB | $AWK '{print $1}'`
92  start1=1
93  let "end1=nlines/2"
94  let "start2=end1+1"
95  end2=$nlines
96
97#date Start/End of DAB1
98  $SED -e "${start1}!d" $CALIB | $AWK -v cycle=$i 'BEGIN {ORS=","} {
99    split($4,b,".");   
100    print cycle "," $3,b[1]}' >> ${OUT2}
101  $SED -e "${end1}!d"   $CALIB | $AWK 'BEGIN {ORS=","} {
102    split($4,b,".");   
103    print $3,b[1]}' >> ${OUT2}
104
105
106#date Start/End of DATA1: use date system function to add the duration to
107#compute the End,cf. End = Start + duration
108  $AWK -v datesys=$DATE -v cycle=$i '$2==cycle && ( $5=="1" ) {
109    split($3,a,"/");
110    split($4,b,".");   
111    dateStart=a[2]"/"a[1]"/"a[3] " " b[1];
112    duree=$6 " sec";
113    cmd=sprintf("%s --date \"%s %s\"  \"+%%d/%%m/%%y %%T\" ",datesys,dateStart,duree);
114   (cmd | getline dateEnd);
115    close(cmd); 
116    ORS=","; print a[1]"/"a[2]"/"a[3] " " b[1];
117    ORS=","; print dateEnd;
118  } ' $OUT1 >> ${OUT2}
119 
120#same as DAB1 for DAB2
121  $SED -e "${start2}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
122    split($4,b,".");   
123    print $3,b[1]}' >> ${OUT2}
124  $SED -e "${end2}!d"   $CALIB | $AWK 'BEGIN {ORS=","} {
125     split($4,b,".");   
126     print $3,b[1]}' >> ${OUT2}
127#same as DATA1 for DATA2
128  $AWK -v datesys=$DATE -v cycle=$i '$2==cycle && ( $5=="2" ) {
129    split($3,a,"/");
130    split($4,b,".")   
131    dateStart=a[2]"/"a[1]"/"a[3] " " b[1];
132    duree=$6 " sec";
133    cmd=sprintf("%s --date \"%s %s\"  \"+%%d/%%m/%%y %%T\" ",datesys,dateStart,duree);
134   (cmd | getline dateEnd);
135    close(cmd); 
136    ORS=","; print a[1]"/"a[2]"/"a[3] " " b[1];
137    ORS="\n"; print  dateEnd;
138  } ' $OUT1 >> ${OUT2}
139#clean
140  $RM $CALIB
141done
142
143#transform all the date/time into %Y-%m-%d %T
144$AWK -v datesys=$DATE '
145BEGIN { FS=","; OFS="," }
146{
147  for (i=2;i<=NF;i++) {
148    split($i,a,"/");
149    newdate=a[2]"/"a[1]"/"a[3];
150    cmd=sprintf("%s --date \"%s\" \"+%%Y-%%m-%%d %%T\" ",datesys,newdate);
151    (cmd | getline newdate);
152    close(cmd);
153    $i=newdate;
154  }
155  print $0;
156}' ${OUT2} > ${fullprocfile}
157
158
159#clean
160$RM $OUT1
161$RM $OUT2
162
163exit 0
164
165
166
Note: See TracBrowser for help on using the repository browser.