1 | #include "toiiter.h"
|
---|
2 | #include <dirent.h>
|
---|
3 |
|
---|
4 | // Format bloc GPS
|
---|
5 | // $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,
|
---|
6 |
|
---|
7 | TOIIter::TOIIter() {
|
---|
8 | // Toutes les valeurs initialisees par defaut. Le TOISvr les positionnera,
|
---|
9 | // puis lancera l'initialisation
|
---|
10 |
|
---|
11 | file = NULL;
|
---|
12 | directory = "";
|
---|
13 | fileName = "";
|
---|
14 |
|
---|
15 | tStart = -9.e99;
|
---|
16 | tEnd = -9.e99;
|
---|
17 |
|
---|
18 | tBlock0 = -1;
|
---|
19 |
|
---|
20 | }
|
---|
21 |
|
---|
22 | TOIIter::TOIIter(TOIIter const& x) {
|
---|
23 | directory = x.directory;
|
---|
24 | fileName = x.fileName;
|
---|
25 | files = x.files;
|
---|
26 | curFile = x.curFile;
|
---|
27 | imes = x.imes;
|
---|
28 | tStart = x.tStart;
|
---|
29 | tEnd = x.tEnd;
|
---|
30 | tBlock0 = x.tBlock0;
|
---|
31 | trigMask = x.trigMask;
|
---|
32 | infos = x.infos;
|
---|
33 |
|
---|
34 | file = new ArcheopsFile(*x.file);
|
---|
35 | }
|
---|
36 |
|
---|
37 | TOIIter::~TOIIter() {
|
---|
38 | delete file;
|
---|
39 | }
|
---|
40 |
|
---|
41 | void TOIIter::Init() {
|
---|
42 | if (directory == "") {
|
---|
43 | file = new ArcheopsFile(fileName);
|
---|
44 | } else {
|
---|
45 | DIR* dir = opendir(directory.c_str());
|
---|
46 | struct dirent* ent;
|
---|
47 | while ((ent = readdir(dir)) != NULL) {
|
---|
48 | files.insert(ent->d_name);
|
---|
49 | }
|
---|
50 | closedir(dir);
|
---|
51 | curFile = files.begin();
|
---|
52 | file = new ArcheopsFile((*curFile).c_str());
|
---|
53 | }
|
---|
54 |
|
---|
55 | if (!file->lastParam()) file->nextBlock(block_param_mask);
|
---|
56 | if (!file->lastReglage()) file->nextBlock(block_reglage_mask);
|
---|
57 |
|
---|
58 | // On cherche un bloc GPS pour avoir la correspondance timestamp/UTC.
|
---|
59 | // Pour le moment, on se fonde sur le premier bloc GPS. On pourra faire
|
---|
60 | // mieux en prenant le min de tous les delta_T.
|
---|
61 |
|
---|
62 | tBlock0 = file->getStartMJD();
|
---|
63 | #if 0
|
---|
64 | file->pushMark();
|
---|
65 | if (file->lastGPS() || file->nextBlock(block_gps_mask)) {
|
---|
66 | // le temps du bloc courant, en secondes
|
---|
67 | double dt = file->blockNum() * file->perBlock();
|
---|
68 | tBlock0 = file->getGPSMJD() - dt/86400.;
|
---|
69 | } else { // pas de bloc GPS...
|
---|
70 | tBlock0 = file->getStartMJD();
|
---|
71 | }
|
---|
72 | file->popMark();
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | trigMask = 0;
|
---|
76 | for (vector<info>::iterator i = infos.begin(); i != infos.end(); i++) {
|
---|
77 | if ((*i).triggering) {
|
---|
78 | switch ((*i).kind) {
|
---|
79 | case boloTens:
|
---|
80 | case boloRaw:
|
---|
81 | trigMask |= block_bolo_mask;
|
---|
82 | break;
|
---|
83 | case longitude:
|
---|
84 | case latitude:
|
---|
85 | trigMask |= block_gps_mask;
|
---|
86 | break;
|
---|
87 | case azimut:
|
---|
88 | trigMask |= block_sst_mask;
|
---|
89 | break;
|
---|
90 | case alpha:
|
---|
91 | case delta:
|
---|
92 | trigMask |= block_sst_mask;
|
---|
93 | break;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | if (trigMask & (block_bolo_mask | block_sst_mask)) {
|
---|
99 | imes = 9999;
|
---|
100 | } else {
|
---|
101 | imes = 0;
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | bool TOIIter::NextFile() {
|
---|
106 | if (directory == "") {
|
---|
107 | return false;
|
---|
108 | } else {
|
---|
109 | if (curFile == files.end()) return false;
|
---|
110 | curFile++;
|
---|
111 | if (curFile == files.end()) return false;
|
---|
112 | ArcheopsFile* newfile = new ArcheopsFile((*curFile).c_str());
|
---|
113 | newfile->grabLastBlocs(*file);
|
---|
114 | delete file;
|
---|
115 | file = newfile;
|
---|
116 | return true;
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | bool TOIIter::Next() {
|
---|
121 |
|
---|
122 |
|
---|
123 | // trigger sur info indexee dans bloc bolo ou bloc sst ?
|
---|
124 | if (trigMask & (block_bolo_mask | block_sst_mask)) {
|
---|
125 | imes++;
|
---|
126 | if (imes < file->nEchBlock()) return true;
|
---|
127 | imes = 0;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // soit pas d'info indexee, soit fin bloc courant...
|
---|
131 |
|
---|
132 | if (file->nextBlock(trigMask)) {
|
---|
133 | return true;
|
---|
134 | }
|
---|
135 | if (!NextFile()) return false;
|
---|
136 | return file->nextBlock(trigMask);
|
---|
137 | }
|
---|
138 |
|
---|
139 | double TOIIter::getTime() { // MJD
|
---|
140 | // le temps du bloc courant, en secondes
|
---|
141 | double dt = file->blockNum() * file->perBlock();
|
---|
142 | return tBlock0 + dt/86400. + imes*file->perEchant()/86400.;
|
---|
143 | }
|
---|
144 |
|
---|
145 | double TOIIter::getValue(int column) {
|
---|
146 | if (column < 0 || column >= infos.size()) return -1;
|
---|
147 | TOIKind kind = infos[column].kind;
|
---|
148 | int index = infos[column].index;
|
---|
149 | switch (kind) {
|
---|
150 | case boloTens:
|
---|
151 | return file->getMuVBolo(index, imes);
|
---|
152 | case boloRaw:
|
---|
153 | return file->getRawBolo(index, imes);
|
---|
154 | case longitude:
|
---|
155 | return file->getGPSLong(); // $CHECK$ TBD gerer interpolation (dans file)
|
---|
156 | case latitude:
|
---|
157 | return file->getGPSLat(); // $CHECK$ TBD gerer interpolation (dans file)
|
---|
158 | case azimut:
|
---|
159 | return file->getAzimut(imes);
|
---|
160 | case alpha:
|
---|
161 | return file->getAlpha(imes);
|
---|
162 | case delta:
|
---|
163 | return file->getDelta(imes);
|
---|
164 | }
|
---|
165 | return -1;
|
---|
166 | }
|
---|
167 |
|
---|
168 | bool TOIIter::newValue(int column) {
|
---|
169 | if (column < 0 || column >= infos.size()) return false;
|
---|
170 | TOIKind kind = infos[column].kind;
|
---|
171 | switch (kind) {
|
---|
172 | case boloTens:
|
---|
173 | return file->blockKind() == block_bolo;
|
---|
174 | case boloRaw:
|
---|
175 | return file->blockKind() == block_bolo;
|
---|
176 | case longitude:
|
---|
177 | return file->blockKind() == block_gps;
|
---|
178 | case latitude:
|
---|
179 | return file->blockKind() == block_gps;
|
---|
180 | case azimut:
|
---|
181 | return file->blockKind() == block_sst || file->blockKind() == block_bolo;
|
---|
182 | case alpha:
|
---|
183 | return file->blockKind() == block_sst || file->blockKind() == block_bolo;
|
---|
184 | case delta:
|
---|
185 | return file->blockKind() == block_sst || file->blockKind() == block_bolo;
|
---|
186 | }
|
---|
187 | return false;
|
---|
188 | }
|
---|
189 |
|
---|
190 | bool TOIIter::extendValue(int column) {
|
---|
191 | return !newValue(column);
|
---|
192 | }
|
---|
193 |
|
---|
194 | bool TOIIter::interpValue(int /*column*/) {
|
---|
195 | return false; // $CHECK$ TBD gerer interpolation
|
---|
196 | }
|
---|
197 |
|
---|
198 | TOIKind TOIIter::getKind(int column) {
|
---|
199 | if (column < 0 || column >= infos.size()) return (TOIKind)-1;
|
---|
200 | return infos[column].kind;
|
---|
201 | }
|
---|
202 |
|
---|
203 | int TOIIter::getIndex(int column) {
|
---|
204 | if (column < 0 || column >= infos.size()) return (TOIKind)-1;
|
---|
205 | return infos[column].index;
|
---|
206 | }
|
---|
207 |
|
---|
208 | int TOIIter::getSampleIndex() {
|
---|
209 | return imes;
|
---|
210 | } |
---|