1 | #!/bin/bash
|
---|
2 |
|
---|
3 | if [ "$#" != 3 ]
|
---|
4 | then
|
---|
5 | echo "Error: fixAuxKeyWords.sh should be called with 2 arguments. Aborting."
|
---|
6 | exit
|
---|
7 | fi
|
---|
8 |
|
---|
9 | file=$1
|
---|
10 | tempFile="/scratch/tempRaw.txt"
|
---|
11 | reportFile=$2
|
---|
12 | processErrors=$3
|
---|
13 |
|
---|
14 | if [ -a $tempFile ]
|
---|
15 | then
|
---|
16 | rm $tempFile 2>/dev/null
|
---|
17 | fi
|
---|
18 |
|
---|
19 | #get current keywords value
|
---|
20 | result=`/home_nfs/isdc/lyard/FACT++/fitsdump $file -h -o $tempFile 2>/dev/null`
|
---|
21 |
|
---|
22 | if [ -a $tempFile ]
|
---|
23 | then
|
---|
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`
|
---|
36 | else
|
---|
37 | echo "Could not list keywords in $file" >> $processErrors
|
---|
38 | exit
|
---|
39 | fi
|
---|
40 |
|
---|
41 | rm $tempFile
|
---|
42 |
|
---|
43 | #retrieve the start and stop time from the data itself
|
---|
44 | result=`/home_nfs/isdc/lyard/FACT++/fitsdump $file -c UnixTimeUTC --minmax --nozero -o $tempFile 2>/dev/null`
|
---|
45 |
|
---|
46 | if [ -a $tempFile ]
|
---|
47 | then
|
---|
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
|
---|
56 | else
|
---|
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
|
---|
81 | fi
|
---|
82 |
|
---|
83 | rm $tempFile
|
---|
84 | #output the values to be added/updated to temp text files
|
---|
85 | modified="false"
|
---|
86 | if [ "$telescope" == "" ]
|
---|
87 | then
|
---|
88 | echo "TELESCOP FACT / Telescope that acquired this data" >> $tempFile
|
---|
89 | modified="true"
|
---|
90 | echo "TELESCOP in $file" >> $2
|
---|
91 | fi
|
---|
92 | if [ "$package" == "" ]
|
---|
93 | then
|
---|
94 | echo "PACKAGE FACT++ / Package name" >> $tempFile
|
---|
95 | modified="true"
|
---|
96 | echo "PACKAGE in $file" >> $2
|
---|
97 | fi
|
---|
98 | if [ "$origin" == "" ]
|
---|
99 | then
|
---|
100 | echo "ORIGIN FACT / Institution that wrote the file" >> $tempFile
|
---|
101 | modified="true"
|
---|
102 | echo "ORIGIN in $file" >> $2
|
---|
103 | fi
|
---|
104 | if [ "$timeunit" == "" ]
|
---|
105 | then
|
---|
106 | echo "TIMEUNIT d / Time given in days w.r.t. to MJDREF" >> $tempFile
|
---|
107 | modified="true"
|
---|
108 | echo "TIMEUNIT in $file" >> $2
|
---|
109 | fi
|
---|
110 | if [ "$mjdref" == "" ]
|
---|
111 | then
|
---|
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
|
---|
117 | fi
|
---|
118 | if [ "$timesys" != "UTC" ]
|
---|
119 | then
|
---|
120 | timesys="UTC"
|
---|
121 | echo "TIMESYS "$timesys" / Time system" >> $tempFile
|
---|
122 | modified="true"
|
---|
123 | echo "TIMESYS in $file" >> $2
|
---|
124 | fi
|
---|
125 | #adapt the start and stop to the mjdref (it is raw unix time in the data)
|
---|
126 | if [ "$tstarti2" != "0" ] && [ "$tstarti2" != "" ]
|
---|
127 | then
|
---|
128 | tstarti2=`echo "$tstarti2 - $mjdref" | bc -l`
|
---|
129 | tstopi2=`echo "$tstopi2 - $mjdref" | bc -l`
|
---|
130 | else
|
---|
131 | tstarti2=0
|
---|
132 | tstopi2=0
|
---|
133 | fi
|
---|
134 |
|
---|
135 | #give latitude for 10-6 precision in tstart and tstop
|
---|
136 | tfcompare=`echo $tstartf | grep -E -o '0\.[0-9]{6}'`
|
---|
137 | tfcompare2=`echo $tstartf2 | grep -E -o '0\.[0-9]{6}'`
|
---|
138 |
|
---|
139 | if [ "$tstarti2" != "$tstarti" ] || [ "$tfcompare" != "$tfcompare2" ]
|
---|
140 | then
|
---|
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
|
---|
148 | fi
|
---|
149 |
|
---|
150 | tfcompare=`echo $tstopf | grep -E -o '0\.[0-9]{6}'`
|
---|
151 | tfcompare2=`echo $tstopf2 | grep -E -o '0\.[0-9]{6}'`
|
---|
152 |
|
---|
153 | if [ "$tstopi2" != "$tstopi" ] || [ "$tfcompare" != "$tfcompare2" ]
|
---|
154 | then
|
---|
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
|
---|
164 | fi
|
---|
165 |
|
---|
166 | if [ "$modified" == "true" ]
|
---|
167 | then
|
---|
168 | echo "INGEST v0.2 Version of Etienne ingest script" >> $tempFile
|
---|
169 | echo $file" header has been modified" >> $reportFile
|
---|
170 | else
|
---|
171 | echo $file" header has NOT been modified" >> $reportFile
|
---|
172 | fi
|
---|
173 |
|
---|
174 | if [ -a $tempFile ]
|
---|
175 | then
|
---|
176 | fmodhead $file $tempFile 2>&1 1>/dev/null
|
---|
177 | fi
|
---|
178 |
|
---|
179 | fchecksum $file update+ 2>&1 1>/dev/null
|
---|
180 |
|
---|
181 | rm $tempFile 2>/dev/null
|
---|