1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # script to read observation information from the database
|
---|
4 | # format: as given by David
|
---|
5 | # MJD DATE START STOP FLUX COMMENT
|
---|
6 | # for times before midnight: eg 22:33 -> -01:27
|
---|
7 |
|
---|
8 |
|
---|
9 | source `dirname $0`/../Sourcefile.sh
|
---|
10 | printprocesslog "INFO starting $0 $1"
|
---|
11 |
|
---|
12 | # getting db info for query
|
---|
13 | getdbsetup
|
---|
14 |
|
---|
15 | function get_table()
|
---|
16 | {
|
---|
17 | printprocesslog "INFO writing "$file
|
---|
18 | query="SELECT Datediff(Max(fRunStop), '1858-11-17') as MJD, "
|
---|
19 | query=$query" Date_format(Max(fRunStop), '%Y/%m/%d') as DATE, "
|
---|
20 | #query=$query" Date_format(Min(fRunStart), '%H:%i') as STARTOLD, "
|
---|
21 | query=$query" if(Hour(Min(fRunStart))>10, Concat('-', Time_format(Addtime(Timediff(Concat(STR_TO_DATE(fNight, '%Y%m%d'), ' 23:59:59'), Min(fRunStart)), '0 0:1:0.0'), '%H:%i')), Date_format(Min(fRunStart), '%H:%i')) as START, "
|
---|
22 | #query=$query" Date_format(Max(fRunStop), '%H:%i') as STOPOLD, "
|
---|
23 | query=$query" if(Hour(Max(fRunStop))>10, Concat('-', Time_format(Addtime(Timediff(Concat(STR_TO_DATE(fNight, '%Y%m%d'), ' 23:59:59'), Max(fRunStop)), '0 0:1:0.0'), '%H:%i')), Date_format(Max(fRunStop), '%H:%i')) as STOP, "
|
---|
24 | query=$query" CONCAT('---') as FLUX, "
|
---|
25 | #query=$query" CONCAT('#') as Comments"
|
---|
26 | #query=$query" CONCAT('# ', Timediff(Max(fRunStop), Min(fRunStart)), ' ontime: ', Convert(Sum(Time_to_sec(Timediff(fRunStop, fRunStart)))/60./60., decimal(2,1))) AS Comments"
|
---|
27 | query=$query" IF (ISNULL(Sum(fOnTime)), CONCAT('#'), CONCAT('# ontime: ', Convert(Sum(fOntime)/3600, decimal(2,1)), 'h')) AS Comments"
|
---|
28 | query=$query" FROM RunInfo "
|
---|
29 | query=$query" WHERE fSourceKEY="$sourcekey
|
---|
30 | query=$query" AND fRunTypeKEY=1 "
|
---|
31 | query=$query" AND fNight BETWEEN "$start" AND "$stop
|
---|
32 | query=$query" GROUP BY fNight "
|
---|
33 | query=$query" ORDER BY fNight "
|
---|
34 | #echo $query
|
---|
35 | #echo ""
|
---|
36 | printprocesslog "DEBUG sendquery QUERY: "$query
|
---|
37 | # sendquery can't be used as it writes everything into a variable
|
---|
38 | mysql -s -u $us --password=$pw --host=$ho $db -e " $query " > $file
|
---|
39 | }
|
---|
40 |
|
---|
41 | ##mrk501
|
---|
42 | #sourcekey=2
|
---|
43 | #file="Mrk501_FACT_observations_2014.txt"
|
---|
44 | #start=20140101
|
---|
45 | #stop=20141030
|
---|
46 | #get_table
|
---|
47 | #exit
|
---|
48 |
|
---|
49 | #mrk421
|
---|
50 | sourcekey=1
|
---|
51 |
|
---|
52 | file="Mrk421_FACT_observations_all.txt"
|
---|
53 | start=20111115
|
---|
54 | stop=20200101
|
---|
55 | get_table
|
---|
56 |
|
---|
57 | file="Mrk421_FACT_observations_2011_2012.txt"
|
---|
58 | start=20120101
|
---|
59 | stop=20120701
|
---|
60 | get_table
|
---|
61 |
|
---|
62 | file="Mrk421_FACT_observations_2012_2013.txt"
|
---|
63 | start=20121001
|
---|
64 | stop=20130930
|
---|
65 | get_table
|
---|
66 |
|
---|
67 | file="Mrk421_FACT_observations_2013_2014.txt"
|
---|
68 | start=20131001
|
---|
69 | stop=20140930
|
---|
70 | get_table
|
---|
71 |
|
---|
72 | file="Mrk421_FACT_observations_2014_2015.txt"
|
---|
73 | start=20141001
|
---|
74 | stop=20150930
|
---|
75 | get_table
|
---|
76 |
|
---|
77 |
|
---|
78 | #mrk501
|
---|
79 | sourcekey=2
|
---|
80 |
|
---|
81 | file="Mrk501_FACT_observations_all.txt"
|
---|
82 | start=20120501 #really started at 19.5.2012
|
---|
83 | stop=20200101
|
---|
84 | get_table
|
---|
85 |
|
---|
86 | file="Mrk501_FACT_observations_2012.txt"
|
---|
87 | start=20120501
|
---|
88 | stop=20121030
|
---|
89 | get_table
|
---|
90 |
|
---|
91 | file="Mrk501_FACT_observations_2013.txt"
|
---|
92 | start=20130101
|
---|
93 | stop=20131030
|
---|
94 | get_table
|
---|
95 |
|
---|
96 | file="Mrk501_FACT_observations_2014.txt"
|
---|
97 | start=20140101
|
---|
98 | stop=20141030
|
---|
99 | get_table
|
---|
100 |
|
---|
101 | file="Mrk501_FACT_observations_2015.txt"
|
---|
102 | start=20150101
|
---|
103 | stop=20151030
|
---|
104 | get_table
|
---|
105 |
|
---|