source: trunk/DataCheck/Archive/fixRawKeyWords.sh@ 17117

Last change on this file since 17117 was 12871, checked in by lyard, 13 years ago
added more scripts
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/bin/bash
2
3if [ "$#" != 3 ]
4then
5 echo "Error: fixAuxKeyWords.sh should be called with 2 arguments. Aborting."
6 exit
7fi
8
9file=$1
10tempFile="/scratch/tempRaw.txt"
11reportFile=$2
12processErrors=$3
13
14if [ -a $tempFile ]
15then
16 rm $tempFile 2>/dev/null
17fi
18
19#get current keywords value
20result=`/home_nfs/isdc/lyard/FACT++/fitsdump $file -h -o $tempFile 2>/dev/null`
21
22if [ -a $tempFile ]
23then
24 timesys=`grep 'TIMESYS' $tempFile | grep -E -o 'UTC'`
25 mjdref=`grep 'MJDREF' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
26 tstarti=`grep 'TSTARTI' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
27 tstartf=`grep 'TSTARTF' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
28 tstopi=`grep 'TSTOPI' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
29 tstopf=`grep 'TSTOPF' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
30 date_obs=`grep 'DATE-OBS' $tempFile`
31 date_end=`grep 'DATE-END' $tempFile`
32 telescope=`grep 'TELESCOP' $tempFile`
33 package=`grep 'PACKAGE' $tempFile`
34 origin=`grep 'ORIGIN' $tempFile`
35 timeunit=`grep 'TIMEUNIT' $tempFile`
36else
37 echo "Could not list keywords in $file" >> $processErrors
38 exit
39fi
40
41rm $tempFile
42
43#retrieve the start and stop time from the data itself
44result=`/home_nfs/isdc/lyard/FACT++/fitsdump $file -c UnixTimeUTC --minmax --nozero -o $tempFile 2>/dev/null`
45
46if [ -a $tempFile ]
47then
48 tstart=`grep 'min' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
49 tstop=`grep 'max' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
50 tstarti2=`echo $tstart | grep -E -o '[-]*[0-9]*[.]' | grep -E -o '[-]*[0-9]*'`
51 tstartf2=`echo $tstart | grep -E -o '[.][0-9]+'`
52 tstartf2="0"$tstartf2
53 tstopi2=`echo $tstop | grep -E -o '[-]*[0-9]*[.]' | grep -E -o '[-]*[0-9]*'`
54 tstopf2=`echo $tstop | grep -E -o '[.][0-9]+'`
55 tstopf2="0"$tstopf2
56else
57 #let's give it a shot with PCTime
58 result=`/home_nfs/isdc/lyard/FACT++/fitsdump $file -c PCTime --minmax --nozero -o $tempFile 2>/dev/null`
59 if [ -a $tempFile ]
60 then
61 tstart=`grep 'min' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
62 tstop=`grep 'max' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
63 tstarti2=`echo $tstart | grep -E -o '[-]*[0-9]*[.]' | grep -E -o '[-]*[0-9]*'`
64 tstartf2=`echo $tstart | grep -E -o '[.][0-9]+'`
65 if [ "$tstarti2" == "" ] #no decimal part
66 then
67 tstarti2=$tstart
68 fi
69 tstartf2="0"$tstartf2
70 tstopi2=`echo $tstop | grep -E -o '[-]*[0-9]*[.]' | grep -E -o '[-]*[0-9]*'`
71 tstopf2=`echo $tstop | grep -E -o '[.][0-9]+'`
72 if [ "$tstopi2" == "" ] #no decimal part
73 then
74 tstopi2=$tstop
75 fi
76 tstopf2="0"$tstopf2
77 else
78# echo "Could not minmax $file" >> $processErrors
79 exit
80 fi
81fi
82
83rm $tempFile
84#output the values to be added/updated to temp text files
85modified="false"
86if [ "$telescope" == "" ]
87then
88 echo "TELESCOP FACT / Telescope that acquired this data" >> $tempFile
89 modified="true"
90 echo "TELESCOP in $file" >> $2
91fi
92if [ "$package" == "" ]
93then
94 echo "PACKAGE FACT++ / Package name" >> $tempFile
95 modified="true"
96 echo "PACKAGE in $file" >> $2
97fi
98if [ "$origin" == "" ]
99then
100 echo "ORIGIN FACT / Institution that wrote the file" >> $tempFile
101 modified="true"
102 echo "ORIGIN in $file" >> $2
103fi
104if [ "$timeunit" == "" ]
105then
106 echo "TIMEUNIT d / Time given in days w.r.t. to MJDREF" >> $tempFile
107 modified="true"
108 echo "TIMEUNIT in $file" >> $2
109fi
110if [ "$mjdref" == "" ]
111then
112# mjdref="0"
113 mjdref="40587"
114 echo "MJDREF "$mjdref" / Store times in UNIX time (sec from 1970ish)" >> $tempFile
115 modified="true"
116 echo "MJDREF in $file" >> $2
117fi
118if [ "$timesys" != "UTC" ]
119then
120 timesys="UTC"
121 echo "TIMESYS "$timesys" / Time system" >> $tempFile
122 modified="true"
123 echo "TIMESYS in $file" >> $2
124fi
125#adapt the start and stop to the mjdref (it is raw unix time in the data)
126if [ "$tstarti2" != "0" ] && [ "$tstarti2" != "" ]
127then
128 tstarti2=`echo "$tstarti2 - $mjdref" | bc -l`
129 tstopi2=`echo "$tstopi2 - $mjdref" | bc -l`
130else
131 tstarti2=0
132 tstopi2=0
133fi
134
135#give latitude for 10-6 precision in tstart and tstop
136tfcompare=`echo $tstartf | grep -E -o '0\.[0-9]{6}'`
137tfcompare2=`echo $tstartf2 | grep -E -o '0\.[0-9]{6}'`
138
139if [ "$tstarti2" != "$tstarti" ] || [ "$tfcompare" != "$tfcompare2" ]
140then
141 echo "TSTARTI "$tstarti2" / Time when first event received (integral part)" >> $tempFile
142 echo "TSTARTF "$tstartf2" / Time when first event received (fractional part)" >> $tempFile
143 date_obs2=`echo "$tstarti2 + $tstartf2 + $mjdref" | bc -l`
144 date_obs2=`/home_nfs/isdc/lyard/FACT++/MjDtoISO $date_obs2`
145 echo "DATE-OBS "$date_obs2" / Time when first event was received" >> $tempFile
146 modified="true"
147 echo "TSTART in $file" >> $2
148fi
149
150tfcompare=`echo $tstopf | grep -E -o '0\.[0-9]{6}'`
151tfcompare2=`echo $tstopf2 | grep -E -o '0\.[0-9]{6}'`
152
153if [ "$tstopi2" != "$tstopi" ] || [ "$tfcompare" != "$tfcompare2" ]
154then
155
156 echo "first: $tfcompare ||| second: $tfcompare2||"
157 echo "TSTOPI "$tstopi2" / Time when last event received (integral part)" >> $tempFile
158 echo "TSTOPF "$tstopf2" / Time when last event received (fractional part)" >> $tempFile
159 date_end2=`echo "$tstopi2 + $tstopf2 + $mjdref" | bc -l`
160 date_end2=`/home_nfs/isdc/lyard/FACT++/MjDtoISO $date_end2`
161 echo "DATE-END "$date_end2" / Time when last event was received" >> $tempFile
162 modified="true"
163 echo "TSTOP in $file" >> $2
164fi
165
166if [ "$modified" == "true" ]
167then
168 echo "INGEST v0.2 Version of Etienne ingest script" >> $tempFile
169 echo $file" header has been modified" >> $reportFile
170else
171 echo $file" header has NOT been modified" >> $reportFile
172fi
173
174if [ -a $tempFile ]
175then
176 fmodhead $file $tempFile 2>&1 1>/dev/null
177fi
178
179fchecksum $file update+ 2>&1 1>/dev/null
180
181rm $tempFile 2>/dev/null
Note: See TracBrowser for help on using the repository browser.