| 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="temp.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/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 |
|
|---|
| 37 | else
|
|---|
| 38 | echo "Could not list keywords in $file" >> $processErrors
|
|---|
| 39 | exit
|
|---|
| 40 | fi
|
|---|
| 41 |
|
|---|
| 42 | rm $tempFile
|
|---|
| 43 |
|
|---|
| 44 | #retrieve the start and stop time from the data itself
|
|---|
| 45 | result=`/home/isdc/lyard/FACT++/fitsdump $file -c Time --minmax --nozero -o $tempFile 2>/dev/null`
|
|---|
| 46 |
|
|---|
| 47 | if [ -a $tempFile ]
|
|---|
| 48 | then
|
|---|
| 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 |
|
|---|
| 67 | else
|
|---|
| 68 | # echo "Could not minmax $file" >> $processErrors
|
|---|
| 69 | exit
|
|---|
| 70 | fi
|
|---|
| 71 |
|
|---|
| 72 | rm $tempFile
|
|---|
| 73 | #output the values to be added/updated to temp text files
|
|---|
| 74 | modified="false"
|
|---|
| 75 | if [ "$telescope" == "" ]
|
|---|
| 76 | then
|
|---|
| 77 | echo "TELESCOP FACT / Telescope that acquired this data" >> $tempFile
|
|---|
| 78 | modified="true"
|
|---|
| 79 | echo "TELESCOP in $file" >> $2
|
|---|
| 80 | fi
|
|---|
| 81 | if [ "$package" == "" ]
|
|---|
| 82 | then
|
|---|
| 83 | echo "PACKAGE FACT++ / Package name" >> $tempFile
|
|---|
| 84 | modified="true"
|
|---|
| 85 | echo "PACKAGE in $file" >> $2
|
|---|
| 86 | fi
|
|---|
| 87 | if [ "$origin" == "" ]
|
|---|
| 88 | then
|
|---|
| 89 | echo "ORIGIN FACT / Institution that wrote the file" >> $tempFile
|
|---|
| 90 | modified="true"
|
|---|
| 91 | echo "ORIGIN in $file" >> $2
|
|---|
| 92 | fi
|
|---|
| 93 | if [ "$timeunit" == "" ]
|
|---|
| 94 | then
|
|---|
| 95 | echo "TIMEUNIT d / Time given in days w.r.t. to MJDREF" >> $tempFile
|
|---|
| 96 | modified="true"
|
|---|
| 97 | echo "TIMEUNIT in $file" >> $2
|
|---|
| 98 | fi
|
|---|
| 99 | if [ "$mjdref" != "40587" ]
|
|---|
| 100 | then
|
|---|
| 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
|
|---|
| 105 | fi
|
|---|
| 106 | if [ "$timesys" != "UTC" ]
|
|---|
| 107 | then
|
|---|
| 108 | timesys="UTC"
|
|---|
| 109 | echo "TIMESYS "$timesys" / Time system" >> $tempFile
|
|---|
| 110 | modified="true"
|
|---|
| 111 | echo "TIMESYS in $file" >> $2
|
|---|
| 112 | fi
|
|---|
| 113 | if [ "$tstarti2" != "$tstarti" ] || [ "$tstartf2" != "$tstartf" ]
|
|---|
| 114 | then
|
|---|
| 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
|
|---|
| 122 | fi
|
|---|
| 123 |
|
|---|
| 124 | if [ "$tstopi2" != "$tstopi" ] || [ "$tstopf2" != "$tstopf" ]
|
|---|
| 125 | then
|
|---|
| 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
|
|---|
| 133 | fi
|
|---|
| 134 |
|
|---|
| 135 | if [ "$modified" == "true" ]
|
|---|
| 136 | then
|
|---|
| 137 | echo "INGEST v0.1 Version of Etienne ingest script" >> $tempFile
|
|---|
| 138 | fi
|
|---|
| 139 |
|
|---|
| 140 | if [ -a $tempFile ]
|
|---|
| 141 | then
|
|---|
| 142 | fmodhead $file $tempFile 2>&1 1>/dev/null
|
|---|
| 143 | fi
|
|---|
| 144 |
|
|---|
| 145 | fchecksum $file update+ 2>&1 1>/dev/null
|
|---|
| 146 |
|
|---|
| 147 | rm $tempFile 2>/dev/null
|
|---|