| 1 | #!/bin/bash
|
|---|
| 2 |
|
|---|
| 3 | # option
|
|---|
| 4 | doupdate="yes" # update all entries (needed when new fields have been added)
|
|---|
| 5 | #doupdate="no" # fill only entries which are not yet existing (default)
|
|---|
| 6 |
|
|---|
| 7 | source `dirname $0`/../Sourcefile.sh
|
|---|
| 8 | printprocesslog "INFO starting $0 with option doupdate="$doupdate
|
|---|
| 9 |
|
|---|
| 10 | logfile=$runlogpath"/FillMoonInfo-"$datetime".log"
|
|---|
| 11 | date >> $logfile
|
|---|
| 12 |
|
|---|
| 13 | # get last 3, 6 or 9 nights
|
|---|
| 14 | dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
|
|---|
| 15 | # `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
|
|---|
| 16 | # `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
|
|---|
| 17 | )
|
|---|
| 18 | dates=( `find $auxdata -mindepth 3 -type d | sort -r | sed "s/\${auxdata_for_sed}//g" | sed -e 's/^\///'` )
|
|---|
| 19 | echo ${dates[@]}
|
|---|
| 20 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
|---|
| 21 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
|---|
| 22 |
|
|---|
| 23 | # do filling of aux data
|
|---|
| 24 | for date in ${dates[@]}
|
|---|
| 25 | do
|
|---|
| 26 | runnumber=`echo $date | sed -e 's/\///g'`
|
|---|
| 27 | if [ $runnumber -lt 20111115 ]
|
|---|
| 28 | then
|
|---|
| 29 | continue
|
|---|
| 30 | fi
|
|---|
| 31 | echo "processing date "$date
|
|---|
| 32 |
|
|---|
| 33 | # get file numbers from DB
|
|---|
| 34 | # but only for not-corrupted files
|
|---|
| 35 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND NOT ISNULL(fRightAscension) AND NOT ISNULL(fDeclination) "
|
|---|
| 36 | #query=$query" AND fRunTypeKEY=6 "
|
|---|
| 37 | if [ "$doupdate" = "no" ]
|
|---|
| 38 | then
|
|---|
| 39 | query=$query" AND ISNULL(fMoonDisk) "
|
|---|
| 40 | fi
|
|---|
| 41 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
|---|
| 42 | filenumbers=( `sendquery` )
|
|---|
| 43 | if [ ${#filenumbers} -eq 0 ]
|
|---|
| 44 | then
|
|---|
| 45 | printprocesslog "INFO No files found in the DB for night "$date
|
|---|
| 46 | continue
|
|---|
| 47 | fi
|
|---|
| 48 |
|
|---|
| 49 | # fill auxiliary information for files
|
|---|
| 50 | for filenum in ${filenumbers[@]}
|
|---|
| 51 | do
|
|---|
| 52 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
|---|
| 53 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
|---|
| 54 |
|
|---|
| 55 | # get input info from DB
|
|---|
| 56 | query="SELECT fRightAscension, fDeclination, fRunStart from RunInfo "
|
|---|
| 57 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
|---|
| 58 | info=( `sendquery` )
|
|---|
| 59 | echo ${info[@]}
|
|---|
| 60 | #echo "/home/fact/FACT++.db/moon "${info[2]} ${info[3]}" --ra=${info[0]} --dec=${info[1]} 2>/dev/null"
|
|---|
| 61 | lightinfo=( `/home/fact/FACT++.db/moon "${info[2]} ${info[3]}" --ra=${info[0]} --dec=${info[1]} 2>/dev/null` )
|
|---|
| 62 | echo ${lightinfo[@]}
|
|---|
| 63 |
|
|---|
| 64 | # build query to update runinfo in DB
|
|---|
| 65 | query="UPDATE RunInfo SET fSunZenithDistance="${lightinfo[2]}", fMoonDisk="${lightinfo[4]}", fMoonZenithDistance="${lightinfo[5]}", fAngleToMoon="${lightinfo[6]}
|
|---|
| 66 | # add where condition
|
|---|
| 67 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
|---|
| 68 | echo $query
|
|---|
| 69 |
|
|---|
| 70 | # send query to DB
|
|---|
| 71 | sendquery >/dev/null
|
|---|
| 72 | done
|
|---|
| 73 | done
|
|---|
| 74 |
|
|---|
| 75 | finish
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|