1 | #include "starmatcher.h"
|
---|
2 | #include "sststarfinder.h"
|
---|
3 | #include "toimanager.h"
|
---|
4 | #include "archexc.h"
|
---|
5 |
|
---|
6 | extern "C" {
|
---|
7 | #include "aa_hadec.h"
|
---|
8 | }
|
---|
9 |
|
---|
10 | #include <stdio.h>
|
---|
11 |
|
---|
12 | StarMatcher::StarMatcher() {
|
---|
13 | possibleTOIs.insert(TOI("dummatcher", TOI::unspec, "", "blabla"));
|
---|
14 |
|
---|
15 | FILE* f;
|
---|
16 |
|
---|
17 | f = fopen("gsc7.dat","r");
|
---|
18 | if (!f) throw ArchExc("Error opening gsc7.dat");
|
---|
19 |
|
---|
20 | fread(&nstars, sizeof(long), 1 , f);
|
---|
21 | stars = new gscStar[nstars];
|
---|
22 | fread(stars, sizeof(gscStar), nstars, f);
|
---|
23 | fclose(f);
|
---|
24 |
|
---|
25 | TOIProducer* prod = TOIManager::findTOIProducer(TOI("sstStarCount"));
|
---|
26 | if (!prod) {
|
---|
27 | cerr << "StarMatcher : cannot find producer for sstStarCount" << endl;
|
---|
28 | exit(-1);
|
---|
29 | }
|
---|
30 |
|
---|
31 | SSTStarFinder* sprod = dynamic_cast<SSTStarFinder*>(prod);
|
---|
32 | if (!sprod) {
|
---|
33 | cerr << "StarMatcher : producer for sstStarCount is not a SSTStarFinder" << endl;
|
---|
34 | exit(-1);
|
---|
35 | }
|
---|
36 |
|
---|
37 | sprod->registerProcessor(this);
|
---|
38 |
|
---|
39 | }
|
---|
40 |
|
---|
41 | string StarMatcher::getName() {
|
---|
42 | return("StarMatcher 1.0");
|
---|
43 | }
|
---|
44 |
|
---|
45 | static ofstream starstream("stars.dat");
|
---|
46 |
|
---|
47 | void StarMatcher::dataFeed(SSTEtoile const& x) {
|
---|
48 | lastStars[(long)x.TEchan] = x;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | double StarMatcher::getValue(long sampleNum, TOI const& toi) {
|
---|
53 | if (lastStars.find(sampleNum) == lastStars.end()) return 0;
|
---|
54 |
|
---|
55 | SSTEtoile lastStar = lastStars[sampleNum];
|
---|
56 |
|
---|
57 |
|
---|
58 | map<TOI, TOIProducer*> m = neededTOIs[toi];
|
---|
59 | double lat, lon, ts, alpha, delta, az;
|
---|
60 |
|
---|
61 | for (map<TOI, TOIProducer*>::iterator i = m.begin(); i != m.end(); i++) {
|
---|
62 | TOI inToi = (*i).first;
|
---|
63 | TOIProducer* prod = (*i).second;
|
---|
64 | if (inToi.name == "latitude") lat = prod->getValue(sampleNum, inToi);
|
---|
65 | if (inToi.name == "longitude") lon = prod->getValue(sampleNum, inToi);
|
---|
66 | if (inToi.name == "tsid") ts = prod->getValue(sampleNum, inToi);
|
---|
67 | if (inToi.name == "alphaFPC") alpha = prod->getValue(sampleNum, inToi);
|
---|
68 | if (inToi.name == "deltaFPC") delta = prod->getValue(sampleNum, inToi);
|
---|
69 | if (inToi.name == "azimuthFPC") az = prod->getValue(sampleNum, inToi);
|
---|
70 | }
|
---|
71 |
|
---|
72 | // find all stars +- 2 deg boresight
|
---|
73 | double dist = 2;
|
---|
74 | double dmin = delta - dist; if (dmin<-90) dmin=-90;
|
---|
75 | double dmax = delta + dist; if (dmax> 90) dmax= 90;
|
---|
76 | double amin = alpha - dist / cos(delta * 3.1415926/180) / 15.;
|
---|
77 | if (amin<0) amin += 24;
|
---|
78 | double amax = alpha + dist / cos(delta * 3.1415926/180) / 15.;
|
---|
79 | if (amax>24) amax -= 24;
|
---|
80 |
|
---|
81 | int a,b,c;
|
---|
82 | a=0; c=nstars-1;
|
---|
83 | while (a+1<c) {
|
---|
84 | b = (a+c)/2;
|
---|
85 | if (stars[b].dec < dmin) a=b; else c=b;
|
---|
86 | }
|
---|
87 | int imin = a;
|
---|
88 | a=0; c=nstars;
|
---|
89 | while (a+1<c) {
|
---|
90 | b = (a+c)/2;
|
---|
91 | if (stars[b].dec < dmax) a=b; else c=b;
|
---|
92 | }
|
---|
93 | int imax = c;
|
---|
94 |
|
---|
95 | for (int i=imin; i<=imax; i++) {
|
---|
96 | if (stars[i].ra >= amin && stars[i].ra <= amax) {
|
---|
97 | double ha = (ts/3600. - stars[i].ra) * 15. * 3.1415926/180.;
|
---|
98 | double elv, azim;
|
---|
99 | hadec_aa(lat * 3.1415926/180., ha, stars[i].dec * 3.1415926/180.,
|
---|
100 | &elv, &azim);
|
---|
101 | elv *= 180/3.1415926;
|
---|
102 | azim *= 180/3.1415926;
|
---|
103 | if (azim<0) azim += 360;
|
---|
104 |
|
---|
105 | starstream << sampleNum << " " <<
|
---|
106 | /*lastStar.TEchan << " " <<*/ lastStar.NoDiode << " " <<
|
---|
107 | alpha << " " << delta << " " <<
|
---|
108 | az << " " <<
|
---|
109 | stars[i].ra << " " << stars[i].dec << " " <<
|
---|
110 | elv << " " << azim << "\n";
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | return 1;
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | set<TOI> StarMatcher::reqTOIFor(TOI const&) {
|
---|
119 | set<TOI> t;
|
---|
120 | t.insert(TOI("latitude", TOI::unspec, "interp"));
|
---|
121 | t.insert(TOI("longitude", TOI::unspec, "interp"));
|
---|
122 | t.insert(TOI("tsid", TOI::unspec));
|
---|
123 | t.insert(TOI("alphaFPC", TOI::unspec, "galcross0"));
|
---|
124 | t.insert(TOI("deltaFPC", TOI::unspec, "galcross0"));
|
---|
125 | t.insert(TOI("azimuthFPC", TOI::unspec, "galcross0"));
|
---|
126 | return t;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void StarMatcher::propagateLowBound(TOI const& toi, long sampleNum) {
|
---|
130 | for (map<long,SSTEtoile>::iterator i = lastStars.begin(); i != lastStars.end(); i++)
|
---|
131 | if ((*i).first < sampleNum) lastStars.erase(i);
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|