source: BAORadio/AmasNancay/v2/sca.sh@ 605

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

change the tmppubicpath (jec)

File size: 4.4 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 touch ${tmppublicpath}/sca.finished
46 exit 1
47fi
48cd ${iojobpath}
49
50
51if [ ! $# = 1 ]
52 then
53 $ECHO "FATAL (${scriptName}): usage: ./sca.sh <file>"
54 touch ${tmppublicpath}/sca.finished
55 exit 1
56fi
57
58
59fullfile=$1
60if [ ! -e $fullfile ]
61 then
62 $ECHO "FATAL (${scriptName}): $fullfile not found: FATAL"
63 touch ${tmppublicpath}/sca.finished
64 exit 1
65fi
66
67#The output file would be in "fullprocfile"
68filename=$(basename $fullfile)
69#extension=${filename##*.}
70filename=${filename%.*}
71extension=".sum"
72fullprocfile=${filename}${extension}
73#create empty output file
74$RM -f $fullprocfile
75$TOUCH $fullprocfile
76
77
78#extract the PERI lines valid for DAB and DATA
79OUT1=./tmp1.$$
80$AWK '
81$1=="PERI" {
82 print "CYCLE",$6,$2,$3,$7,$8
83 }
84' $fullfile > $OUT1
85
86
87#Sequence of the cycle numbers (perform a unique filtering)
88tableau=( `cat $OUT1 | $AWK '{print $2}'` )
89IFS='
90'
91tableau=( $( printf "%s\n" "${tableau[@]}" | awk 'x[$0]++ == 0' ) )
92IFS=$DefaultIFS
93
94#scan each cycle
95OUT2=./tmp2.$$
96for i in ${tableau[@]}
97do
98#extract the DAB calibration phases. Hypothesis: 2 identical sequences
99 CALIB=./tmp_cycle_${i}_calib.$$
100 $AWK -v cycle=$i '$2==cycle && $5=="-1" {print $0} ' $OUT1 > $CALIB
101 nlines=`$WC $CALIB | $AWK '{print $1}'`
102 start1=1
103 let "end1=nlines/2"
104 let "start2=end1+1"
105 end2=$nlines
106
107#date Start/End of DAB1
108 $SED -e "${start1}!d" $CALIB | $AWK -v cycle=$i 'BEGIN {ORS=","} {
109 split($4,b,".");
110 print cycle "," $3,b[1]}' >> ${OUT2}
111 $SED -e "${end1}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
112 split($4,b,".");
113 print $3,b[1]}' >> ${OUT2}
114
115
116#date Start/End of DATA1: use date system function to add the duration to
117#compute the End,cf. End = Start + duration
118 $AWK -v datesys=$DATE -v cycle=$i '$2==cycle && ( $5=="1" ) {
119 split($3,a,"/");
120 split($4,b,".");
121 dateStart=a[2]"/"a[1]"/"a[3] " " b[1];
122 duree=$6 " sec";
123 cmd=sprintf("%s --date \"%s %s\" \"+%%d/%%m/%%y %%T\" ",datesys,dateStart,duree);
124 (cmd | getline dateEnd);
125 close(cmd);
126 ORS=","; print a[1]"/"a[2]"/"a[3] " " b[1];
127 ORS=","; print dateEnd;
128 } ' $OUT1 >> ${OUT2}
129
130#same as DAB1 for DAB2
131 $SED -e "${start2}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
132 split($4,b,".");
133 print $3,b[1]}' >> ${OUT2}
134 $SED -e "${end2}!d" $CALIB | $AWK 'BEGIN {ORS=","} {
135 split($4,b,".");
136 print $3,b[1]}' >> ${OUT2}
137#same as DATA1 for DATA2
138 $AWK -v datesys=$DATE -v cycle=$i '$2==cycle && ( $5=="2" ) {
139 split($3,a,"/");
140 split($4,b,".")
141 dateStart=a[2]"/"a[1]"/"a[3] " " b[1];
142 duree=$6 " sec";
143 cmd=sprintf("%s --date \"%s %s\" \"+%%d/%%m/%%y %%T\" ",datesys,dateStart,duree);
144 (cmd | getline dateEnd);
145 close(cmd);
146 ORS=","; print a[1]"/"a[2]"/"a[3] " " b[1];
147 ORS="\n"; print dateEnd;
148 } ' $OUT1 >> ${OUT2}
149#clean
150 $RM $CALIB
151done
152
153#transform all the date/time into %Y-%m-%d %T
154$AWK -v datesys=$DATE '
155BEGIN { FS=","; OFS="," }
156{
157 for (i=2;i<=NF;i++) {
158 split($i,a,"/");
159 newdate=a[2]"/"a[1]"/"a[3];
160 cmd=sprintf("%s --date \"%s\" \"+%%Y-%%m-%%d %%T\" ",datesys,newdate);
161 (cmd | getline newdate);
162 close(cmd);
163 $i=newdate;
164 }
165 print $0;
166}' ${OUT2} > ${fullprocfile}
167
168
169#clean
170$RM $OUT1
171$RM $OUT2
172
173touch ${tmppublicpath}/sca.finished
174exit 0
175
176
177
Note: See TracBrowser for help on using the repository browser.