1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # script to fill moon information to DB
|
---|
4 | # doesn't need raw files
|
---|
5 | # probably doesn't run at ISDC (FACT++/moon missing)
|
---|
6 |
|
---|
7 | # option whether to fill all row or only those where information is missing
|
---|
8 | # $doupdate might be given as environment variable
|
---|
9 | if [ "$doupdate" = "" ]
|
---|
10 | then
|
---|
11 | doupdate="yes" # update all entries (needed when new fields have been added)
|
---|
12 | doupdate="no" # fill only entries which are not yet existing (default)
|
---|
13 | fi
|
---|
14 |
|
---|
15 | source `dirname $0`/../Sourcefile.sh
|
---|
16 | printprocesslog "INFO starting $0 with option doupdate="$doupdate
|
---|
17 |
|
---|
18 | # get dates
|
---|
19 | if [ "$certaindate" != "" ]
|
---|
20 | then
|
---|
21 | getdates $certaindate
|
---|
22 | else
|
---|
23 | # get all night
|
---|
24 | #getdates "all"
|
---|
25 | # get last 6 nights
|
---|
26 | getdates 6
|
---|
27 | fi
|
---|
28 |
|
---|
29 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
---|
30 |
|
---|
31 | # do filling of aux data
|
---|
32 | for date in ${dates[@]}
|
---|
33 | do
|
---|
34 | runnumber=`echo $date | sed -e 's/\///g'`
|
---|
35 | if [ $runnumber -lt 20111115 ]
|
---|
36 | then
|
---|
37 | continue
|
---|
38 | fi
|
---|
39 | printprocesslog "INFO processing date "$date
|
---|
40 | #echo "INFO processing date "$date
|
---|
41 |
|
---|
42 | # get file numbers from DB
|
---|
43 | # but only for not-corrupted files
|
---|
44 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND NOT ISNULL(fRunStart) "
|
---|
45 | if [ "$doupdate" = "no" ]
|
---|
46 | then
|
---|
47 | query=$query" AND ISNULL(fMoonDisk) "
|
---|
48 | fi
|
---|
49 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
---|
50 | filenumbers=( `sendquery` )
|
---|
51 | if [ ${#filenumbers} -eq 0 ]
|
---|
52 | then
|
---|
53 | printprocesslog "INFO No files found in the DB for night "$date
|
---|
54 | continue
|
---|
55 | fi
|
---|
56 |
|
---|
57 | # fill auxiliary information for files
|
---|
58 | for filenum in ${filenumbers[@]}
|
---|
59 | do
|
---|
60 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
61 |
|
---|
62 | # get input info from DB
|
---|
63 | # query 999 in case value is empty to easily recognize this case
|
---|
64 | query="SELECT if (isnull(fRightAscension), 999, fRightAscension), "
|
---|
65 | query=$query" if (isnull(fDeclination), 999, fDeclination), "
|
---|
66 | query=$query" fRunStart from RunInfo "
|
---|
67 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
68 | info=( `sendquery` )
|
---|
69 | if [ "${info[0]}" == "999" ] && [ "${info[1]}" == "999" ]
|
---|
70 | then
|
---|
71 | lightinfo=( `$factpath/moon "${info[2]} ${info[3]}" 2>/dev/null` )
|
---|
72 | else
|
---|
73 | lightinfo=( `$factpath/moon "${info[2]} ${info[3]}" --ra=${info[0]} --dec=${info[1]} 2>/dev/null` )
|
---|
74 | fi
|
---|
75 | # return values of the programm
|
---|
76 | # timestamp sunzd moon-visible moondisk moonzd angletomoon angletosun
|
---|
77 |
|
---|
78 | # build query to update runinfo in DB
|
---|
79 | query="UPDATE RunInfo SET fSunZenithDistance="${lightinfo[2]}", fMoonDisk="${lightinfo[4]}
|
---|
80 | query=$query", fMoonZenithDistance="${lightinfo[5]}
|
---|
81 | if [ "${info[0]}" != "999" ] && [ "${info[1]}" != "999" ]
|
---|
82 | then
|
---|
83 | query=$query", fAngleToMoon="${lightinfo[6]}
|
---|
84 | query=$query", fAngleToSun="${lightinfo[7]}
|
---|
85 | fi
|
---|
86 | # add where condition
|
---|
87 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
88 |
|
---|
89 | #echo $query
|
---|
90 | # send query to DB
|
---|
91 | sendquery >/dev/null
|
---|
92 | done
|
---|
93 | done
|
---|
94 |
|
---|
95 | finish
|
---|
96 |
|
---|
97 |
|
---|