source: trunk/DataCheck/Archive/fixAuxKeyWords.sh@ 19813

Last change on this file since 19813 was 12750, checked in by lyard, 13 years ago
added ingest stuff
  • Property svn:executable set to *
File size: 4.0 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="temp.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/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`
36
37else
38 echo "Could not list keywords in $file" >> $processErrors
39 exit
40fi
41
42rm $tempFile
43
44#retrieve the start and stop time from the data itself
45result=`/home/isdc/lyard/FACT++/fitsdump $file -c Time --minmax --nozero -o $tempFile 2>/dev/null`
46
47if [ -a $tempFile ]
48then
49
50 tstart=`grep 'min' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
51 tstop=`grep 'max' $tempFile | grep -E -o '[-]*[0-9]*[.]*[0-9]+'`
52 tstarti2=`echo $tstart | grep -E -o '[-]*[0-9]*[.]' | grep -E -o '[-]*[0-9]*'`
53 tstartf2=`echo $tstart | grep -E -o '[.][0-9]+'`
54 if [ "$tstarti2" == "" ] #no decimal part
55 then
56 tstarti2=$tstart
57 fi
58 tstartf2="0"$tstartf2
59 tstopi2=`echo $tstop | grep -E -o '[-]*[0-9]*[.]' | grep -E -o '[-]*[0-9]*'`
60 tstopf2=`echo $tstop | grep -E -o '[.][0-9]+'`
61 if [ "$tstopi2" == "" ] #no decimal part
62 then
63 tstopi2=$tstop
64 fi
65 tstopf2="0"$tstopf2
66
67else
68# echo "Could not minmax $file" >> $processErrors
69 exit
70fi
71
72rm $tempFile
73#output the values to be added/updated to temp text files
74modified="false"
75if [ "$telescope" == "" ]
76then
77 echo "TELESCOP FACT / Telescope that acquired this data" >> $tempFile
78 modified="true"
79 echo "TELESCOP in $file" >> $2
80fi
81if [ "$package" == "" ]
82then
83 echo "PACKAGE FACT++ / Package name" >> $tempFile
84 modified="true"
85 echo "PACKAGE in $file" >> $2
86fi
87if [ "$origin" == "" ]
88then
89 echo "ORIGIN FACT / Institution that wrote the file" >> $tempFile
90 modified="true"
91 echo "ORIGIN in $file" >> $2
92fi
93if [ "$timeunit" == "" ]
94then
95 echo "TIMEUNIT d / Time given in days w.r.t. to MJDREF" >> $tempFile
96 modified="true"
97 echo "TIMEUNIT in $file" >> $2
98fi
99if [ "$mjdref" != "40587" ]
100then
101 mjdref="40587"
102 echo "MJDREF "$mjdref" / Store times in UNIX time (sec from 1970ish)" >> $tempFile
103 modified="true"
104 echo "MJDREF in $file" >> $2
105fi
106if [ "$timesys" != "UTC" ]
107then
108 timesys="UTC"
109 echo "TIMESYS "$timesys" / Time system" >> $tempFile
110 modified="true"
111 echo "TIMESYS in $file" >> $2
112fi
113if [ "$tstarti2" != "$tstarti" ] || [ "$tstartf2" != "$tstartf" ]
114then
115 echo "TSTARTI "$tstarti2" / Time when first event received (integral part)" >> $tempFile
116 echo "TSTARTF "$tstartf2" / Time when first event received (fractional part)" >> $tempFile
117 date_obs2=`echo "$tstarti2 + $tstartf2 + $mjdref" | bc -l`
118 date_obs2=`/home/isdc/lyard/FACT++/MjDtoISO $date_obs2`
119 echo "DATE-OBS "$date_obs2" / Time when first event was received" >> $tempFile
120 modified="true"
121 echo "TSTART in $file" >> $2
122fi
123
124if [ "$tstopi2" != "$tstopi" ] || [ "$tstopf2" != "$tstopf" ]
125then
126 echo "TSTOPI "$tstopi2" / Time when last event received (integral part)" >> $tempFile
127 echo "TSTOPF "$tstopf2" / Time when last event received (fractional part)" >> $tempFile
128 date_end2=`echo "$tstopi2 + $tstopf2 + $mjdref" | bc -l`
129 date_end2=`/home/isdc/lyard/FACT++/MjDtoISO $date_end2`
130 echo "DATE-END "$date_end2" / Time when last event was received" >> $tempFile
131 modified="true"
132 echo "TSTOP in $file" >> $2
133fi
134
135if [ "$modified" == "true" ]
136then
137 echo "INGEST v0.1 Version of Etienne ingest script" >> $tempFile
138fi
139
140if [ -a $tempFile ]
141then
142 fmodhead $file $tempFile 2>&1 1>/dev/null
143fi
144
145fchecksum $file update+ 2>&1 1>/dev/null
146
147rm $tempFile 2>/dev/null
Note: See TracBrowser for help on using the repository browser.