source: BAORadio/AmasNancay/trunk/sca_ds.sh @ 675

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

sca decryptor for Drift Scan data (jec)

  • Property svn:executable set to *
File size: 3.2 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 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.
13AWK=/bin/awk
14SED=/bin/sed
15GREP=/bin/grep
16WC=/usr/bin/wc
17RM=/bin/rm
18CAT=/bin/cat
19TOUCH=/bin/touch
20DATE=/bin/date
21ECHO=/bin/echo
22LS=/bin/ls
23MKDIR=/bin/mkdir
24DefaultIFS=$' \t\n'
25IFS=$DefaultIFS
26
27
28scriptName="`basename $0`"
29$ECHO "Processing script ${scriptName} at `date`"
30
31#temporary files to synchronize scripts
32tmppublicpath=${TMPPUBLICPATH}
33$LS -l ${tmppublicpath} > /dev/null
34
35#Path where the job will do temporary IO
36. ${SCRIPTPATH}/set_iojobpath.sh
37iojobpath=$(set_iojobpath)
38cd ${iojobpath}
39
40
41if [ ! $# = 1 ]
42    then
43    $ECHO "FATAL  (${scriptName}): usage: ./sca.sh <file>"
44    exit 1
45fi
46
47
48fullfile=$1
49if [ ! -e $fullfile ] 
50    then
51    $ECHO "FATAL (${scriptName}): <${fullfile}> not found: FATAL"
52    exit 1
53fi
54
55#The output file would be in "fullprocfile"
56filename=$(basename $fullfile)
57#extension=${filename##*.}
58filename=${filename%.*}
59extension=".sum"
60fullprocfile=${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
67OUT1=./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)
75tableau=( `cat $OUT1 | $AWK '{print $2}'` )
76IFS='
77'
78tableau=( $( printf "%s\n" "${tableau[@]}" | awk 'x[$0]++ == 0' ) )
79IFS=$DefaultIFS
80
81#scan each cycle
82OUT2=./tmp2.$$
83for i in ${tableau[@]}
84do
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
117done
118
119#transform all the date/time into %Y-%m-%d %T
120$AWK -v datesys=$DATE '
121BEGIN { 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
139exit 0
140
141
142
Note: See TracBrowser for help on using the repository browser.