source: branches/trigger_burst_research/Processing/FillMoonInfo.sh@ 19923

Last change on this file since 19923 was 17907, checked in by Daniela Dorner, 10 years ago
included and/or improved check of variable certaindate
  • Property svn:executable set to *
File size: 3.2 KB
Line 
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
9if [ "$doupdate" = "" ]
10then
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)
13fi
14
15source `dirname $0`/../Sourcefile.sh
16printprocesslog "INFO starting $0 with option doupdate="$doupdate
17
18# get dates
19if [ "$certaindate" != "" ]
20then
21 checkstring=`echo $certaindate | grep -E -o '^20[0-9][0-9]\/[01][0-9]\/[0-3][0-9]$'`
22 if [ "$checkstring" = "" ]
23 then
24 echo "Please give the variable certaindate in the correct format (YYYY/MM/DD)"
25 finish
26 fi
27 getdates $certaindate
28else
29 # get all night
30 #getdates "all"
31 # get last 6 nights
32 getdates 6
33fi
34
35printprocesslog "INFO processing the following night(s): "${dates[@]}
36
37# do filling of aux data
38for date in ${dates[@]}
39do
40 runnumber=`echo $date | sed -e 's/\///g'`
41 if [ $runnumber -lt 20111115 ]
42 then
43 continue
44 fi
45 printprocesslog "INFO processing date "$date
46 #echo "INFO processing date "$date
47
48 # get file numbers from DB
49 # but only for not-corrupted files
50 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND NOT ISNULL(fRunStart) "
51 if [ "$doupdate" = "no" ]
52 then
53 query=$query" AND ISNULL(fMoonDisk) "
54 fi
55 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
56 # proceed only if there are files available
57 filenumbers=( `sendquery` )
58 if [ ${#filenumbers} -eq 0 ]
59 then
60 printprocesslog "INFO No files found in the DB for night "$date
61 continue
62 fi
63
64 # fill auxiliary information for files
65 for filenum in ${filenumbers[@]}
66 do
67 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
68
69 # get input info from DB
70 # query 999 in case value is empty to easily recognize this case
71 query="SELECT if (isnull(fRightAscension), 999, fRightAscension), "
72 query=$query" if (isnull(fDeclination), 999, fDeclination), "
73 query=$query" fRunStart from RunInfo "
74 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
75 info=( `sendquery` )
76 if [ "${info[0]}" == "999" ] && [ "${info[1]}" == "999" ]
77 then
78 lightinfo=( `$factpath/moon "${info[2]} ${info[3]}" 2>/dev/null` )
79 else
80 lightinfo=( `$factpath/moon "${info[2]} ${info[3]}" --ra=${info[0]} --dec=${info[1]} 2>/dev/null` )
81 fi
82 # return values of the programm
83 # timestamp sunzd moon-visible moondisk moonzd angletomoon angletosun
84
85 # build query to update runinfo in DB
86 query="UPDATE RunInfo SET fSunZenithDistance="${lightinfo[2]}", fMoonDisk="${lightinfo[4]}
87 query=$query", fMoonZenithDistance="${lightinfo[5]}
88 if [ "${info[0]}" != "999" ] && [ "${info[1]}" != "999" ]
89 then
90 query=$query", fAngleToMoon="${lightinfo[6]}
91 query=$query", fAngleToSun="${lightinfo[7]}
92 fi
93 # add where condition
94 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
95
96 #echo $query
97 # send query to DB
98 sendquery >/dev/null
99 done
100done
101
102finish
103
104
Note: See TracBrowser for help on using the repository browser.