-
Notifications
You must be signed in to change notification settings - Fork 0
/
SchedBlock.cpp
125 lines (99 loc) · 2.6 KB
/
SchedBlock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "classes.hpp"
using namespace std;
SchedBlock::SchedBlock(
Project* project,
unsigned int schedBlockIndex,
int seqBlockIndex,
unsigned int execTime,
double obsFrequency,
double RA,
double Dec,
double LSTr,
double LSTs
):
project(project),
schedBlockIndex(schedBlockIndex),
seqBlockIndex(seqBlockIndex),
execTime(execTime),
obsFrequency(obsFrequency),
status(false),
RA(RA),
Dec(Dec),
LSTr(LSTr),
LSTs(LSTs)
{
}
SchedBlock::~SchedBlock(){
}
unsigned int SchedBlock::getIndex(){
return schedBlockIndex;
}
Project* SchedBlock::getProject(){
return project;
}
time_t SchedBlock::getExecTime(){
return execTime;
}
double SchedBlock::getObservationFrequency(){
return obsFrequency;
}
bool SchedBlock::isAvailable(){
if(seqBlockIndex == -1) return true;
SchedBlock * sq_blk = this->project->getSchedBlock(seqBlockIndex);
if(sq_blk == NULL) return true;
if(sq_blk->isExecuted()) return true;
return false;
}
bool SchedBlock::isExecuted(){
return status;
}
void SchedBlock::setExecuted(){
if (!status) {
this->status = true;
this->notifyObservers();
}
}
double SchedBlock::getRA() {
return RA;
}
double SchedBlock::getDec() {
return Dec;
}
bool RA_Dec_to_valid(time_t unixTime, double RA, double Dec, double LAT, double LONG, double UT)
{
/* This function can be optimized */
const double GtoR = 0.0174532925;
double JD = (unixTime / 86400.0) + 2440587.5;
double LST = 100.46 + 0.985647 * JD + LONG + 15*UT;
double HR_ANG = (LST - RA) < 0 ? LST - RA + 360: LST - RA;
double ALT = asin(
sin( LAT * GtoR) * sin( Dec * GtoR) +
cos( LAT * GtoR) * cos( Dec * GtoR) * cos( HR_ANG * GtoR));
if(ALT/GtoR > 10)
return true;
return false;
}
bool LST_to_valid(time_t unixTime, double LSTr, double LSTs, double LAT, double LONG, double UT)
{
/* This function can be optimized */
double JD = (unixTime / 86400.0) + 2440587.5;
double LST = 100.46 + 0.985647 * JD + LONG + 15*UT;
LST = LST - floor(LST);
if(LSTr < LST && LST < LSTs )
return true;
return false;
}
bool SchedBlock::isVisible(time_t start, time_t end){
ProjectHandler *ph = this->project->getProjectHandler();
double latitude = ph->getLatitude();
double longitude = ph->getLongitude();
double UT = ph->getUT();
/*
return (LST_to_valid(start,LSTr,LSTs,latitude,longitude,UT) &&
// LST_to_valid((start+end)/2,LSTr,LSTs,latitude,longitude,UT) &&
LST_to_valid(end,LSTr,LSTs,latitude,longitude,UT));
*/
return (RA_Dec_to_valid(start,RA,Dec,latitude,longitude,UT) &&
// RA_Dec_to_valid((start+end)/2,RA,Dec,latitude,longitude,UT) &&
RA_Dec_to_valid(end,RA,Dec,latitude,longitude,UT));
}