1 | #define utilitaires_de_block_archeops
|
---|
2 | #include "archeopsfile.h"
|
---|
3 | extern "C" {
|
---|
4 | #include "compress.h"
|
---|
5 | }
|
---|
6 | #include <iostream.h>
|
---|
7 |
|
---|
8 | // BlockSet is the current "state" of the file reader automate.
|
---|
9 | // It contains the last blocks of each kind, the current block and
|
---|
10 | // the look-ahead block.
|
---|
11 |
|
---|
12 | class BlockSet {
|
---|
13 | public:
|
---|
14 | BlockSet();
|
---|
15 | BlockSet(BlockSet const&);
|
---|
16 | ~BlockSet();
|
---|
17 | void setBloc(block_type_modele const& blk);
|
---|
18 | void setRawBloc(block_type_modele const& blk);
|
---|
19 |
|
---|
20 | block_type_param* lastParam;
|
---|
21 | block_type_journal* lastJournal;
|
---|
22 | block_type_reglage* lastReglage;
|
---|
23 | block_type_dilution* lastDilution;
|
---|
24 | block_type_gps* lastGPS;
|
---|
25 | block_type_une_periode* lastUnePeriode;
|
---|
26 | block_type_synchro_sol* lastSynchroSol;
|
---|
27 | block_type_pointage_sol* lastPointageSol;
|
---|
28 | block_type_bolo* lastBolo; // can be uncompressed bolo_comp
|
---|
29 | block_type_bolo* llastBolo;
|
---|
30 | block_type_gyro* lastGyro;
|
---|
31 | block_type_sst* lastSST;
|
---|
32 | block_type_bolo_comprime* lastBoloComp; // can be uncompressed bolo_comp
|
---|
33 | block_type_gyro_comprime* lastGyroComp;
|
---|
34 | block_type_sst_comprime* lastSSTComp;
|
---|
35 |
|
---|
36 | block_type_modele curBlock;
|
---|
37 | block_type_modele peekBlock;
|
---|
38 |
|
---|
39 | SSTHandler sstHandler;
|
---|
40 | GPSParser gpsParser;
|
---|
41 | };
|
---|
42 |
|
---|
43 | BlockSet::BlockSet() {
|
---|
44 | lastParam = NULL;
|
---|
45 | lastJournal = NULL;
|
---|
46 | lastReglage = NULL;
|
---|
47 | lastDilution = NULL;
|
---|
48 | lastGPS = NULL;
|
---|
49 | lastUnePeriode = NULL;
|
---|
50 | lastSynchroSol = NULL;
|
---|
51 | lastPointageSol= NULL;
|
---|
52 | lastBolo = NULL;
|
---|
53 | llastBolo = NULL;
|
---|
54 | lastGyro = NULL;
|
---|
55 | lastSST = NULL;
|
---|
56 | lastBoloComp = NULL;
|
---|
57 | lastGyroComp = NULL;
|
---|
58 | lastSSTComp = NULL;
|
---|
59 |
|
---|
60 | memset(&curBlock,0,sizeof(block_type_modele));
|
---|
61 | memset(&peekBlock,0,sizeof(block_type_modele));
|
---|
62 | }
|
---|
63 |
|
---|
64 | BlockSet::~BlockSet() {
|
---|
65 | delete lastParam;
|
---|
66 | delete lastJournal;
|
---|
67 | delete lastReglage;
|
---|
68 | delete lastDilution;
|
---|
69 | delete lastGPS;
|
---|
70 | delete lastUnePeriode;
|
---|
71 | delete lastSynchroSol;
|
---|
72 | delete lastPointageSol;
|
---|
73 | delete lastBolo;
|
---|
74 | delete llastBolo;
|
---|
75 | delete lastGyro;
|
---|
76 | delete lastSST;
|
---|
77 | delete lastBoloComp;
|
---|
78 | delete lastGyroComp;
|
---|
79 | delete lastSSTComp;
|
---|
80 | }
|
---|
81 |
|
---|
82 | BlockSet::BlockSet(BlockSet const& x)
|
---|
83 | : sstHandler(x.sstHandler)
|
---|
84 | {
|
---|
85 | lastParam = NULL;
|
---|
86 | lastJournal = NULL;
|
---|
87 | lastReglage = NULL;
|
---|
88 | lastDilution = NULL;
|
---|
89 | lastGPS = NULL;
|
---|
90 | lastUnePeriode = NULL;
|
---|
91 | lastSynchroSol = NULL;
|
---|
92 | lastPointageSol= NULL;
|
---|
93 | lastBolo = NULL;
|
---|
94 | llastBolo = NULL;
|
---|
95 | lastGyro = NULL;
|
---|
96 | lastSST = NULL;
|
---|
97 | lastBoloComp = NULL;
|
---|
98 | lastGyroComp = NULL;
|
---|
99 | lastSSTComp = NULL;
|
---|
100 |
|
---|
101 | if (x.lastParam) {
|
---|
102 | lastParam = new block_type_param;
|
---|
103 | *lastParam = *x.lastParam;
|
---|
104 | }
|
---|
105 | if (x.lastJournal) {
|
---|
106 | lastJournal = new block_type_journal;
|
---|
107 | *lastJournal = *x.lastJournal;
|
---|
108 | }
|
---|
109 | if (x.lastReglage) {
|
---|
110 | lastReglage = new block_type_reglage;
|
---|
111 | *lastReglage = *x.lastReglage;
|
---|
112 | }
|
---|
113 | if (x.lastDilution) {
|
---|
114 | lastDilution = new block_type_dilution;
|
---|
115 | *lastDilution = *x.lastDilution;
|
---|
116 | }
|
---|
117 | if (x.lastGPS) {
|
---|
118 | lastGPS = new block_type_gps;
|
---|
119 | *lastGPS = *x.lastGPS;
|
---|
120 | }
|
---|
121 | if (x.lastUnePeriode) {
|
---|
122 | lastUnePeriode = new block_type_une_periode;
|
---|
123 | *lastUnePeriode = *x.lastUnePeriode;
|
---|
124 | }
|
---|
125 | if (x.lastSynchroSol) {
|
---|
126 | lastSynchroSol = new block_type_synchro_sol;
|
---|
127 | *lastSynchroSol = *x.lastSynchroSol;
|
---|
128 | }
|
---|
129 | if (x.lastPointageSol) {
|
---|
130 | lastPointageSol = new block_type_pointage_sol;
|
---|
131 | *lastPointageSol = *x.lastPointageSol;
|
---|
132 | }
|
---|
133 | if (x.lastBolo) {
|
---|
134 | lastBolo = new block_type_bolo;
|
---|
135 | *lastBolo = *x.lastBolo;
|
---|
136 | }
|
---|
137 | if (x.llastBolo) {
|
---|
138 | llastBolo = new block_type_bolo;
|
---|
139 | *llastBolo = *x.llastBolo;
|
---|
140 | }
|
---|
141 | if (x.lastGyro) {
|
---|
142 | lastGyro = new block_type_gyro;
|
---|
143 | *lastGyro = *x.lastGyro;
|
---|
144 | }
|
---|
145 | if (x.lastSST) {
|
---|
146 | lastSST = new block_type_sst;
|
---|
147 | *lastSST = *x.lastSST;
|
---|
148 | }
|
---|
149 | if (x.lastBoloComp) {
|
---|
150 | lastBoloComp = new block_type_bolo_comprime;
|
---|
151 | *lastBoloComp = *x.lastBoloComp;
|
---|
152 | }
|
---|
153 | if (x.lastGyroComp) {
|
---|
154 | lastGyroComp = new block_type_gyro_comprime;
|
---|
155 | *lastGyroComp = *x.lastGyroComp;
|
---|
156 | }
|
---|
157 | if (x.lastSSTComp) {
|
---|
158 | lastSSTComp = new block_type_sst_comprime;
|
---|
159 | *lastSSTComp = *x.lastSSTComp;
|
---|
160 | }
|
---|
161 |
|
---|
162 | memcpy(&curBlock,&x.curBlock,sizeof(block_type_modele));
|
---|
163 | memcpy(&peekBlock,&x.peekBlock,sizeof(block_type_modele));
|
---|
164 |
|
---|
165 | }
|
---|
166 |
|
---|
167 | void BlockSet::setBloc(block_type_modele const& blk)
|
---|
168 | {
|
---|
169 | int kind = type_block(&blk);
|
---|
170 | switch (kind) {
|
---|
171 | case block_param:
|
---|
172 | if (!lastParam) lastParam = new block_type_param;
|
---|
173 | memcpy(lastParam, &blk, sizeof(block_type_param));
|
---|
174 | // Les fichiers fournis contiennent des valeurs debiles...
|
---|
175 | if (lastParam->param.n_max_bolo < 0)
|
---|
176 | lastParam->param.n_max_bolo = nb_max_bolo;
|
---|
177 | if (lastParam->param.n_per_block < 0)
|
---|
178 | lastParam->param.n_per_block = nb_per_block;
|
---|
179 | if (lastParam->param.n_max_mes_per < 0)
|
---|
180 | lastParam->param.n_max_mes_per = nb_max_mes_per;
|
---|
181 | break;
|
---|
182 | case block_journal:
|
---|
183 | if (!lastJournal) lastJournal = new block_type_journal;
|
---|
184 | memcpy(lastJournal, &blk, sizeof(block_type_journal));
|
---|
185 | break;
|
---|
186 | case block_reglage:
|
---|
187 | if (!lastReglage) lastReglage = new block_type_reglage;
|
---|
188 | memcpy(lastReglage, &blk, sizeof(block_type_reglage));
|
---|
189 | break;
|
---|
190 | case block_dilution:
|
---|
191 | if (!lastDilution) lastDilution = new block_type_dilution;
|
---|
192 | memcpy(lastDilution, &blk, sizeof(block_type_dilution));
|
---|
193 | break;
|
---|
194 | case block_gps:
|
---|
195 | if (!lastGPS) lastGPS = new block_type_gps;
|
---|
196 | memcpy(lastGPS, &blk, sizeof(block_type_gps));
|
---|
197 | break;
|
---|
198 | case block_une_periode:
|
---|
199 | if (!lastUnePeriode) lastUnePeriode = new block_type_une_periode;
|
---|
200 | memcpy(lastUnePeriode, &blk, sizeof(block_type_une_periode));
|
---|
201 | break;
|
---|
202 | case block_synchro_sol:
|
---|
203 | if (!lastSynchroSol) lastSynchroSol = new block_type_synchro_sol;
|
---|
204 | memcpy(lastSynchroSol, &blk, sizeof(block_type_synchro_sol));
|
---|
205 | break;
|
---|
206 | case block_pointage_sol:
|
---|
207 | if (!lastPointageSol) lastPointageSol = new block_type_pointage_sol;
|
---|
208 | memcpy(lastPointageSol, &blk, sizeof(block_type_pointage_sol));
|
---|
209 | break;
|
---|
210 | case block_bolo:
|
---|
211 | if (!lastBolo) lastBolo = new block_type_bolo;
|
---|
212 | else if (!llastBolo) {
|
---|
213 | llastBolo = new block_type_bolo;
|
---|
214 | }
|
---|
215 | if (llastBolo) {
|
---|
216 | memcpy(llastBolo, lastBolo, sizeof(block_type_bolo));
|
---|
217 | }
|
---|
218 | memcpy(lastBolo, &blk, sizeof(block_type_bolo));
|
---|
219 | break;
|
---|
220 | case block_gyro:
|
---|
221 | if (!lastGyro) lastGyro = new block_type_gyro;
|
---|
222 | memcpy(lastGyro, &blk, sizeof(block_type_gyro));
|
---|
223 | break;
|
---|
224 | case block_sst:
|
---|
225 | if (!lastSST) lastSST = new block_type_sst;
|
---|
226 | memcpy(lastSST, &blk, sizeof(block_type_sst));
|
---|
227 | break;
|
---|
228 | }
|
---|
229 | }
|
---|
230 |
|
---|
231 | void BlockSet::setRawBloc(block_type_modele const& blk)
|
---|
232 | {
|
---|
233 | int kind = type_block(&blk);
|
---|
234 | switch (kind) {
|
---|
235 | case block_bolo_comprime:
|
---|
236 | if (!lastBoloComp) lastBoloComp = new block_type_bolo_comprime;
|
---|
237 | memcpy(lastBoloComp, &blk, sizeof(block_type_bolo_comprime));
|
---|
238 | break;
|
---|
239 | case block_gyro_comprime:
|
---|
240 | if (!lastGyroComp) lastGyroComp = new block_type_gyro_comprime;
|
---|
241 | memcpy(lastGyroComp, &blk, sizeof(block_type_gyro_comprime));
|
---|
242 | break;
|
---|
243 | case block_sst_comprime:
|
---|
244 | if (!lastSSTComp) lastSSTComp = new block_type_sst_comprime;
|
---|
245 | memcpy(lastSSTComp, &blk, sizeof(block_type_sst_comprime));
|
---|
246 | break;
|
---|
247 | }
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 |
|
---|
252 | ArcheopsFile::ArcheopsFile(string const& fname) {
|
---|
253 | f = fopen(fname.c_str(), "rb");
|
---|
254 | fn = fname;
|
---|
255 | if (!f) throw ArchExc("file not found");
|
---|
256 | fseek(f,0,SEEK_END);
|
---|
257 | fLen = ftell(f);
|
---|
258 | curPos = -1;
|
---|
259 | peekPos = -1;
|
---|
260 | curKind = -1;
|
---|
261 | curRawKind = -1;
|
---|
262 | blockSet = new BlockSet;
|
---|
263 | utcOffset=2;
|
---|
264 | computeMJD(fname);
|
---|
265 | }
|
---|
266 |
|
---|
267 | ArcheopsFile::ArcheopsFile(ArcheopsFile const& x) {
|
---|
268 | blockSet = x.blockSet ? new BlockSet(*x.blockSet) : NULL;
|
---|
269 | fposStack = x.fposStack;
|
---|
270 |
|
---|
271 | stack<BlockSet*> tmp;
|
---|
272 | ArcheopsFile& y = (ArcheopsFile&) x;
|
---|
273 | while (!y.blockStack.empty()) {
|
---|
274 | tmp.push(y.blockStack.top());
|
---|
275 | y.blockStack.pop();
|
---|
276 | }
|
---|
277 | while (!tmp.empty()) {
|
---|
278 | y.blockStack.push(tmp.top());
|
---|
279 | blockStack.push(new BlockSet(*tmp.top()));
|
---|
280 | tmp.pop();
|
---|
281 | }
|
---|
282 |
|
---|
283 | //curBlock = x.curBlock;
|
---|
284 | curKind = x.curKind;
|
---|
285 | curRawKind = x.curRawKind;
|
---|
286 | curPos = x.curPos;
|
---|
287 | peekPos = x.peekPos;
|
---|
288 | fLen = x.fLen;
|
---|
289 | fn = x.fn;
|
---|
290 | f = fopen(fn.c_str(), "rb");
|
---|
291 |
|
---|
292 | rawMJD = x.rawMJD;
|
---|
293 | startMJD = x.startMJD;
|
---|
294 | utcOffset = x.utcOffset;
|
---|
295 | }
|
---|
296 |
|
---|
297 | ArcheopsFile::~ArcheopsFile() {
|
---|
298 | if (f) fclose(f);
|
---|
299 | delete blockSet;
|
---|
300 | while (!blockStack.empty())
|
---|
301 | { delete blockStack.top(); blockStack.pop();}
|
---|
302 | }
|
---|
303 |
|
---|
304 | void ArcheopsFile::grabLastBlocs(ArcheopsFile const& oldFile) {
|
---|
305 | delete blockSet;
|
---|
306 | blockSet = new BlockSet(*oldFile.blockSet);
|
---|
307 | //curBlock = oldFile.curBlock;
|
---|
308 | //peekBlock = oldFile.peekBlock;
|
---|
309 | if (peekPos>0) peekPos = 0;
|
---|
310 | setUTCOffset(oldFile.utcOffset);
|
---|
311 | }
|
---|
312 |
|
---|
313 |
|
---|
314 | def_nom_block
|
---|
315 |
|
---|
316 | def_long_block
|
---|
317 |
|
---|
318 | bool ArcheopsFile::nextBlock() {
|
---|
319 | // si pas de peek, alors en lire un pour commencer...
|
---|
320 | if (peekPos<0) {
|
---|
321 | peekPos=0; if (!nextBlock()) return false;
|
---|
322 | }
|
---|
323 | block_type_modele* curBlock=currentBlock();
|
---|
324 | block_type_modele* peekBlock=aheadBlock();
|
---|
325 |
|
---|
326 | memcpy(curBlock, peekBlock, sizeof(block_type_modele));
|
---|
327 | curPos = peekPos;
|
---|
328 |
|
---|
329 | while (true) {
|
---|
330 | if (peekPos+12 > fLen) return false; // fin de fichier
|
---|
331 | fseek(f,peekPos,SEEK_SET); // aller en peekPos
|
---|
332 | size_t read = fread(peekBlock,1,sizeof(block_type_modele),f);
|
---|
333 | swapEntete(peekBlock);
|
---|
334 | if (read < longueur_block(peekBlock) ||
|
---|
335 | type_block(peekBlock) < 0 || type_block(peekBlock) > 19 ||
|
---|
336 | longueur_block(peekBlock) != long_block[type_block(peekBlock)]) {
|
---|
337 | cout << "block de type/longueur invalide" << endl;
|
---|
338 | memset(peekBlock, 0, sizeof(block_type_modele)); // don't keep trash...
|
---|
339 | peekPos = searchNextBlock(peekPos);
|
---|
340 | if (peekPos<0) return false;
|
---|
341 | continue;
|
---|
342 | }
|
---|
343 | swapContent(peekBlock);
|
---|
344 | if (verifie_block(peekBlock) != block_correct) {
|
---|
345 | cout << "block invalide " << numero_block(peekBlock);
|
---|
346 | if (!fixBlock(peekBlock)) {
|
---|
347 | cout << " -- skipped" << endl;
|
---|
348 | peekPos += longueur_block(peekBlock); // la longueur doit etre ok...
|
---|
349 | continue;
|
---|
350 | } else {
|
---|
351 | cout << " -- fixed" << endl;
|
---|
352 | break;
|
---|
353 | }
|
---|
354 | }
|
---|
355 | break; // tout semble bon pour ce bloc...
|
---|
356 | }
|
---|
357 |
|
---|
358 | peekPos += longueur_block(peekBlock); // on suppose que longueur OK...
|
---|
359 | if (curPos < 0) {
|
---|
360 | curPos = 0; return true;
|
---|
361 | }
|
---|
362 | if (curBlock->debut != 0) {
|
---|
363 | curRawKind = curKind = type_block(curBlock);
|
---|
364 | postProcessBlock();
|
---|
365 | saveCurBlock();
|
---|
366 | } else {
|
---|
367 | curRawKind = curKind = -1;
|
---|
368 | }
|
---|
369 | return true;
|
---|
370 | }
|
---|
371 |
|
---|
372 | bool ArcheopsFile::nextBlock(long mask) {
|
---|
373 | if (!mask) return false;
|
---|
374 | while (1) {
|
---|
375 | if (!nextBlock()) return false;
|
---|
376 | if (( 1 << curRawKind) & mask) return true;
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | bool ArcheopsFile::fixBlock(block_type_modele* blk) {
|
---|
381 | return false;
|
---|
382 | }
|
---|
383 |
|
---|
384 |
|
---|
385 | int ArcheopsFile::blockKind() {
|
---|
386 | return curKind;
|
---|
387 | }
|
---|
388 |
|
---|
389 | int ArcheopsFile::blockRawKind() {
|
---|
390 | return curRawKind;
|
---|
391 | }
|
---|
392 |
|
---|
393 | int ArcheopsFile::blockNum() {
|
---|
394 | return numero_block(currentBlock());
|
---|
395 | }
|
---|
396 |
|
---|
397 | #define bitmot 24 // nb de bit horloge dans un mot ADC
|
---|
398 |
|
---|
399 | double ArcheopsFile::perEchant() { // periode d'echantillonage pour le dernier bloc reglage
|
---|
400 | double p,f1,f2,f3;
|
---|
401 | int pp;
|
---|
402 | if (!lastReglage()) return -1;
|
---|
403 | pp=lastReglage()->reglage.horloge.periode;
|
---|
404 | p=pp/5.;
|
---|
405 | f1=1000/p;f2=f1/bitmot;f3=f2*1000./(double)(lastReglage()->reglage.horloge.nb_mesures);
|
---|
406 | return 0.5/f3; // 2 fois la frequence de modulation
|
---|
407 | }
|
---|
408 |
|
---|
409 | double ArcheopsFile::perBlock() { // duree (en secondes) correspondant a un bloc bolo
|
---|
410 | return perEchant() * (double)lastParam()->param.n_per_block*2.;
|
---|
411 | }
|
---|
412 |
|
---|
413 | int ArcheopsFile::nEchBlock() { // Nb d'echantillons dans un bloc
|
---|
414 | return lastParam()->param.n_per_block*2;
|
---|
415 | }
|
---|
416 |
|
---|
417 | string ArcheopsFile::blockKdName() {
|
---|
418 | return nom_block[curKind];
|
---|
419 | }
|
---|
420 |
|
---|
421 | string ArcheopsFile::blockRawKdName() {
|
---|
422 | return nom_block[curRawKind];
|
---|
423 | }
|
---|
424 |
|
---|
425 |
|
---|
426 | block_type_modele* ArcheopsFile::currentBlock() {
|
---|
427 | //if (curPos<0) return NULL;
|
---|
428 | return &blockSet->curBlock;
|
---|
429 | }
|
---|
430 |
|
---|
431 | block_type_modele* ArcheopsFile::aheadBlock() {
|
---|
432 | //if (peekPos<0) return NULL;
|
---|
433 | return &blockSet->peekBlock;
|
---|
434 | }
|
---|
435 |
|
---|
436 | bool ArcheopsFile::sameBlockNumAhead() {
|
---|
437 | if (curPos<0) return false;
|
---|
438 | return (numero_block(&blockSet->curBlock) == numero_block(&blockSet->peekBlock));
|
---|
439 | }
|
---|
440 |
|
---|
441 |
|
---|
442 | block_type_param* ArcheopsFile::lastParam() {
|
---|
443 | return blockSet->lastParam;
|
---|
444 | }
|
---|
445 | block_type_journal* ArcheopsFile::lastJournal() {
|
---|
446 | return blockSet->lastJournal;
|
---|
447 | }
|
---|
448 | block_type_reglage* ArcheopsFile::lastReglage() {
|
---|
449 | return blockSet->lastReglage;
|
---|
450 | }
|
---|
451 | block_type_dilution* ArcheopsFile::lastDilution() {
|
---|
452 | return blockSet->lastDilution;
|
---|
453 | }
|
---|
454 | block_type_gps* ArcheopsFile::lastGPS() {
|
---|
455 | return blockSet->lastGPS;
|
---|
456 | }
|
---|
457 | block_type_une_periode* ArcheopsFile::lastUnePeriode() {
|
---|
458 | return blockSet->lastUnePeriode;
|
---|
459 | }
|
---|
460 | block_type_synchro_sol* ArcheopsFile::lastSynchroSol() {
|
---|
461 | return blockSet->lastSynchroSol;
|
---|
462 | }
|
---|
463 | block_type_pointage_sol* ArcheopsFile::lastPointageSol() {
|
---|
464 | return blockSet->lastPointageSol;
|
---|
465 | }
|
---|
466 | block_type_bolo* ArcheopsFile::lastBolo() {
|
---|
467 | return blockSet->lastBolo;
|
---|
468 | }
|
---|
469 | block_type_bolo* ArcheopsFile::llastBolo() {
|
---|
470 | return blockSet->llastBolo;
|
---|
471 | }
|
---|
472 | block_type_gyro* ArcheopsFile::lastGyro() {
|
---|
473 | return blockSet->lastGyro;
|
---|
474 | }
|
---|
475 | block_type_sst* ArcheopsFile::lastSST() {
|
---|
476 | return blockSet->lastSST;
|
---|
477 | }
|
---|
478 | block_type_bolo_comprime* ArcheopsFile::lastBoloComp() {
|
---|
479 | return blockSet->lastBoloComp;
|
---|
480 | }
|
---|
481 | block_type_gyro_comprime* ArcheopsFile::lastGyroComp() {
|
---|
482 | return blockSet->lastGyroComp;
|
---|
483 | }
|
---|
484 | block_type_sst_comprime* ArcheopsFile::lastSSTComp() {
|
---|
485 | return blockSet->lastSSTComp;
|
---|
486 | }
|
---|
487 |
|
---|
488 | void ArcheopsFile::forceBlock(block_type_modele* blk) {
|
---|
489 | blockSet->setBloc(*blk);
|
---|
490 | }
|
---|
491 |
|
---|
492 | #define place_paquet(i,j) ((i/8) * 24 + j*8 + (i%8) )
|
---|
493 |
|
---|
494 | void ArcheopsFile::postProcessBlock() {
|
---|
495 | switch (curKind) {
|
---|
496 | case block_bolo_comprime: {
|
---|
497 | blockSet->setRawBloc(blockSet->curBlock);
|
---|
498 | block_type_bolo blk2;
|
---|
499 | block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &blockSet->curBlock;
|
---|
500 | #if version_num <= 25
|
---|
501 | for(int j=0;j<nb_bolo_util;j++)
|
---|
502 | {
|
---|
503 | decompress_7_2((int4*)blk->data_bolo[j],blk2.data_bolo[j],nb_per_block*2);
|
---|
504 | }
|
---|
505 | #else
|
---|
506 | block_type_param* param = lastParam();
|
---|
507 | int jc=0;for(int j=0;j<nb_max_bolo;j++) // jc = bolo_comprime // j=bolo normal
|
---|
508 | {
|
---|
509 | if( (param->param.bolo[j].bolo_code_util==bolo_normal_transmis) && (jc<nb_bolo_util) )
|
---|
510 | {
|
---|
511 | decompress_7_2((int4 *)blk->data_bolo[jc],blk2.data_bolo[j],nb_per_block*2);
|
---|
512 | jc++;
|
---|
513 | }
|
---|
514 | else {
|
---|
515 | memset(blk2.data_bolo[j], 0, nb_per_block*2*sizeof(int4));
|
---|
516 | }
|
---|
517 | }
|
---|
518 |
|
---|
519 | #endif
|
---|
520 | valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk));
|
---|
521 | memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
|
---|
522 | curKind = block_bolo;
|
---|
523 | break;
|
---|
524 | }
|
---|
525 | case block_sst_comprime: { // $CHECK$ TBD
|
---|
526 | blockSet->setRawBloc(blockSet->curBlock);
|
---|
527 | block_type_sst blk2;
|
---|
528 | block_type_sst_comprime* blk = (block_type_sst_comprime*) &blockSet->curBlock;
|
---|
529 | for (int j=0; j<18; j++)
|
---|
530 | for (int i=0; i<nb_per_block*2; i++)
|
---|
531 | blk2.sst[i][j] = 0;
|
---|
532 |
|
---|
533 | int jc=0;
|
---|
534 | for( int j=0;j<48;j++) {
|
---|
535 | if ((j!=0) && (j!=4))
|
---|
536 | {
|
---|
537 | unsigned int4 sst_vrai[nb_per_block*2];
|
---|
538 | decompress_4_1((int4*)blk->sst[jc],(int4*)sst_vrai,nb_per_block*2);
|
---|
539 | for (int k=0;k<nb_per_block*2;k++) {
|
---|
540 | unsigned int4 a,b0,b1,b2;
|
---|
541 | b2 = sst_vrai[k] & 0xf;
|
---|
542 | b1 = (sst_vrai[k] >> 4) & 0xf;
|
---|
543 | b0 = (sst_vrai[k] >> 8) & 0xf;
|
---|
544 | a=place_paquet(j,0);
|
---|
545 | blk2.sst[k][a/8] |= (b0 << (a%8)*4);
|
---|
546 | a=place_paquet(j,1);
|
---|
547 | blk2.sst[k][a/8] |= (b1 << (a%8)*4);
|
---|
548 | a=place_paquet(j,2);
|
---|
549 | blk2.sst[k][a/8] |= (b2 << (a%8)*4);
|
---|
550 | }
|
---|
551 | jc++;
|
---|
552 | }
|
---|
553 | }
|
---|
554 | valide_block((block_type_modele*)&blk2,block_sst,numero_block(blk));
|
---|
555 | memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
|
---|
556 | curKind = block_sst;
|
---|
557 | blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
|
---|
558 | break;
|
---|
559 | }
|
---|
560 | case block_sst : {
|
---|
561 | blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
|
---|
562 | }
|
---|
563 | case block_gps : {
|
---|
564 | blockSet->gpsParser.ProcessBlock((block_type_gps*)&blockSet->curBlock);
|
---|
565 | }
|
---|
566 | }
|
---|
567 | }
|
---|
568 |
|
---|
569 | void ArcheopsFile::saveCurBlock() {
|
---|
570 | blockSet->setBloc(blockSet->curBlock);
|
---|
571 | }
|
---|
572 |
|
---|
573 | void ArcheopsFile::pushMark() { // push current file position, and "last" blocks`
|
---|
574 | fposStack.push(curPos);
|
---|
575 | fposStack.push(peekPos);
|
---|
576 | blockStack.push(new BlockSet(*blockSet));
|
---|
577 | }
|
---|
578 |
|
---|
579 | void ArcheopsFile::popMark() { // pops last file position and "last" blocks
|
---|
580 | if (! blockStack.empty()) {
|
---|
581 | delete blockSet;
|
---|
582 | blockSet = blockStack.top();
|
---|
583 | blockStack.pop();
|
---|
584 | peekPos = fposStack.top();
|
---|
585 | fposStack.pop();
|
---|
586 | curPos = fposStack.top();
|
---|
587 | fposStack.pop();
|
---|
588 | }
|
---|
589 | }
|
---|
590 |
|
---|
591 | typedef unsigned int4 uint_4;
|
---|
592 | typedef unsigned short uint_2;
|
---|
593 |
|
---|
594 | static inline void bswap4(void* p)
|
---|
595 | {
|
---|
596 | uint_4 tmp = *(uint_4*)p;
|
---|
597 | *(uint_4*)p = ((tmp >> 24) & 0x000000FF) |
|
---|
598 | ((tmp >> 8) & 0x0000FF00) |
|
---|
599 | ((tmp & 0x0000FF00) << 8) |
|
---|
600 | ((tmp & 0x000000FF) << 24);
|
---|
601 | }
|
---|
602 |
|
---|
603 | static inline void bswap2(void* p)
|
---|
604 | {
|
---|
605 | uint_2 tmp = *(uint_2*)p;
|
---|
606 | *(uint_2*)p = ((tmp >> 8) & 0x00FF) |
|
---|
607 | ((tmp & 0x00FF) << 8);
|
---|
608 | }
|
---|
609 |
|
---|
610 | #ifdef __DECCXX
|
---|
611 | #define SWAP
|
---|
612 | #endif
|
---|
613 | #if defined(Linux) || defined(linux)
|
---|
614 | #define SWAP
|
---|
615 | #endif
|
---|
616 |
|
---|
617 | #ifdef SWAP
|
---|
618 | void ArcheopsFile::swapEntete(block_type_modele* blk) {
|
---|
619 | bswap4(&(blk->debut));
|
---|
620 | bswap4(&(blk->code1));
|
---|
621 | bswap4(&(blk->code2));
|
---|
622 | long lg = longueur_block(blk);
|
---|
623 | if (lg < taille_maxi_block_archeops)
|
---|
624 | bswap4(((char*)blk) + lg - 4);
|
---|
625 | }
|
---|
626 | #else
|
---|
627 | void ArcheopsFile::swapEntete(block_type_modele* ) {
|
---|
628 | }
|
---|
629 | #endif
|
---|
630 |
|
---|
631 | #ifdef SWAP
|
---|
632 | void ArcheopsFile::swapContent(block_type_modele* blk) {
|
---|
633 | int typ = type_block(blk);
|
---|
634 |
|
---|
635 | if (typ == block_gps) return; // char only, no swap
|
---|
636 | if (typ == block_une_periode) { // une_periode, des shorts
|
---|
637 | block_type_une_periode* b = (block_type_une_periode*) blk;
|
---|
638 | for (int i=0; i<nb_max_bolo; i++)
|
---|
639 | for (int j=0; j<nb_max_mes_per; j++)
|
---|
640 | bswap2(&b->bol_per[i][j]);
|
---|
641 | return;
|
---|
642 | }
|
---|
643 |
|
---|
644 | for (int i=0; i<longueur_block(blk)/4-4; i++)
|
---|
645 | bswap4(blk->mot + i);
|
---|
646 | // On deswappe ce qui ne devait pas etre swappe...
|
---|
647 | switch (typ) {
|
---|
648 | case block_param: {
|
---|
649 | block_type_param* b = (block_type_param*) blk;
|
---|
650 | for (int i=0; i<nb_max_bolo; i++)
|
---|
651 | for (int j=0; j<8; j++)
|
---|
652 | #if version_num<=25
|
---|
653 | bswap4(&b->param.bolo[i].bolo_nom[4*j]);
|
---|
654 | #else
|
---|
655 | bswap4(&b->param.nom_coef[i].bolo_nom[4*j]);
|
---|
656 | #endif
|
---|
657 | }
|
---|
658 |
|
---|
659 | }
|
---|
660 | }
|
---|
661 | #else
|
---|
662 | void ArcheopsFile::swapContent(block_type_modele* ) {
|
---|
663 | }
|
---|
664 | #endif
|
---|
665 |
|
---|
666 | long ArcheopsFile::searchNextBlock(long pos) {
|
---|
667 | static char* buffer = 0;
|
---|
668 | static int4 debswp = debut_block_mesure;
|
---|
669 | static int4 longmax = taille_maxi_block_archeops*20;
|
---|
670 | if (!buffer) {
|
---|
671 | buffer = new char[longmax];
|
---|
672 | #ifdef SWAP
|
---|
673 | bswap4(&debswp);
|
---|
674 | #endif
|
---|
675 | }
|
---|
676 | fseek(f,pos,SEEK_SET);
|
---|
677 | size_t read = fread(buffer,1,taille_maxi_block_archeops*2,f);
|
---|
678 | //if (read<taille_maxi_block_archeops*2) return -1;
|
---|
679 | for (int i=4; i<read; i+=4) {
|
---|
680 | if (*(int4*)(buffer+i) == debswp) {
|
---|
681 | cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
|
---|
682 | return pos+i;
|
---|
683 | }
|
---|
684 | }
|
---|
685 | cout << "cannot find block start" << endl;
|
---|
686 | return -1;
|
---|
687 | }
|
---|
688 |
|
---|
689 |
|
---|
690 |
|
---|
691 |
|
---|
692 | static int mlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
|
---|
693 |
|
---|
694 | double ArcheopsFile::decodeMJD(string const& dateString) {
|
---|
695 | //99_04_29-15h36m22 ou 99_05_10
|
---|
696 | short y,m,d,hh,mm,ss;
|
---|
697 | char const* p = dateString.c_str();
|
---|
698 | char const* p2 = dateString.c_str() + dateString.length();
|
---|
699 | y = atoi(p); p+=3; if (p>p2) return -1;
|
---|
700 | m = atoi(p); p+=3; if (p>p2) return -1;
|
---|
701 | d = atoi(p); p+=3;
|
---|
702 | if (p<p2) {
|
---|
703 | hh = atoi(p); p+=3; if (p>p2) return -1;
|
---|
704 | mm = atoi(p); p+=3; if (p>p2) return -1;
|
---|
705 | ss = atoi(p);
|
---|
706 | } else {
|
---|
707 | hh=mm=ss=0;
|
---|
708 | }
|
---|
709 |
|
---|
710 | if (y<50) y += 100;
|
---|
711 | // 1. depuis 0/1/97 minuit
|
---|
712 | double mjd = (int) (365.25 * (y-97));
|
---|
713 | for (int i=0; i<m-1; i++)
|
---|
714 | mjd += mlen[i];
|
---|
715 | if (y%4 == 0 && m > 2) mjd++;
|
---|
716 | mjd += d;
|
---|
717 | mjd += hh/24. + mm/24./60. + ss/24./60./60;
|
---|
718 |
|
---|
719 | mjd += 448.5; // 0/1/97 minuit
|
---|
720 |
|
---|
721 | return mjd;
|
---|
722 | }
|
---|
723 |
|
---|
724 | void ArcheopsFile::computeMJD(string const& fname) {
|
---|
725 | //telemetrie : h99_04_29-15h36m22
|
---|
726 | //enregistreur : ARKxxxxxx.dat, et MJD = samedi 17 juillet, 21h -> 1377.4
|
---|
727 | char const* p = fname.c_str();
|
---|
728 | char const* p2 = p + fname.length()-1;
|
---|
729 | while (*p2 != ':' && *p2 != '/' && p2 != p) p2--;
|
---|
730 | if (*p2 == ':' || *p2 == '/') p2++;
|
---|
731 | if (*p2 == 'h') p2++;
|
---|
732 | if (!strncmp(p2, "ARK",3)) {
|
---|
733 | rawMJD = 1377.4;
|
---|
734 | } else {
|
---|
735 | rawMJD = decodeMJD(p2);
|
---|
736 | }
|
---|
737 | startMJD = rawMJD - utcOffset/24.;
|
---|
738 | }
|
---|
739 |
|
---|
740 | void ArcheopsFile::setUTCOffset(int UTCOffset) {
|
---|
741 | utcOffset = UTCOffset;
|
---|
742 | startMJD = rawMJD - utcOffset/24.;
|
---|
743 | }
|
---|
744 |
|
---|
745 | double ArcheopsFile::getStartMJD() {
|
---|
746 | return startMJD;
|
---|
747 | }
|
---|
748 |
|
---|
749 | int ArcheopsFile::getBoloBlockNum() {
|
---|
750 | if (!lastBolo()) return -1;
|
---|
751 | return numero_block(lastBolo());
|
---|
752 | }
|
---|
753 |
|
---|
754 | int ArcheopsFile::getSSTBlockNum() {
|
---|
755 | if (!lastSST()) return -1;
|
---|
756 | return numero_block(lastSST());
|
---|
757 | }
|
---|
758 |
|
---|
759 |
|
---|
760 | int ArcheopsFile::getGyroBlockNum() {
|
---|
761 | if (!lastGyro()) return -1;
|
---|
762 | return numero_block(lastGyro());
|
---|
763 | }
|
---|
764 |
|
---|
765 |
|
---|
766 | // GPS
|
---|
767 | // $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,
|
---|
768 |
|
---|
769 |
|
---|
770 | int ArcheopsFile::getGPSBlockNum() {
|
---|
771 | if (!lastGPS()) return -1;
|
---|
772 | return numero_block(lastGPS());
|
---|
773 | }
|
---|
774 |
|
---|
775 | double ArcheopsFile::getGPSUTC() { // en secondes depuis minuit UTC jour courant
|
---|
776 | if (!lastGPS()) return -9.e99;
|
---|
777 | return blockSet->gpsParser.getUTC();
|
---|
778 | }
|
---|
779 |
|
---|
780 | double ArcheopsFile::getGPSMJD() { // modified julian day du dernier bloc GPS, JD - 2450000
|
---|
781 | double t = getGPSUTC()/86400. - 0.5;
|
---|
782 | if (t<0) return t;
|
---|
783 | if (t > (startMJD - int(startMJD))) {
|
---|
784 | return int(startMJD) + t;
|
---|
785 | } else {
|
---|
786 | return int(startMJD) + 1. + t;
|
---|
787 | }
|
---|
788 | }
|
---|
789 |
|
---|
790 | double ArcheopsFile::getGPSLat() { // degres, + = NORD
|
---|
791 | if (!lastGPS()) return -9.e99;
|
---|
792 | return blockSet->gpsParser.getLatitude();
|
---|
793 | }
|
---|
794 |
|
---|
795 |
|
---|
796 | double ArcheopsFile::getGPSLong() { // degres, + = EST
|
---|
797 | if (!lastGPS()) return -9.e99;
|
---|
798 | return blockSet->gpsParser.getLongitude();
|
---|
799 | }
|
---|
800 |
|
---|
801 | double ArcheopsFile::getGPSAlt() { // meters from sea level
|
---|
802 | if (!lastGPS()) return -9.e99;
|
---|
803 | return blockSet->gpsParser.getAltitude();
|
---|
804 | }
|
---|
805 |
|
---|
806 | bool ArcheopsFile::hasGPSTime() {
|
---|
807 | if (!lastGPS()) return false;
|
---|
808 | return blockSet->gpsParser.hasGPSTime();
|
---|
809 | }
|
---|
810 |
|
---|
811 | bool ArcheopsFile::hasGPSPos() {
|
---|
812 | if (!lastGPS()) return false;
|
---|
813 | return blockSet->gpsParser.hasPosition();
|
---|
814 | }
|
---|
815 |
|
---|
816 | bool ArcheopsFile::hasGPSAlt() {
|
---|
817 | if (!lastGPS()) return false;
|
---|
818 | return blockSet->gpsParser.hasAltitude();
|
---|
819 | }
|
---|
820 |
|
---|
821 |
|
---|
822 | // Bolo
|
---|
823 | #define val_DS(j,i) (blk->data_bolo[j][i]&0x1fffff)
|
---|
824 |
|
---|
825 |
|
---|
826 | long ArcheopsFile::getRawBolo(int ibolo, int imesure) { // donnee brute, avec seulement soustraction offset
|
---|
827 | int nb_coups,aa;
|
---|
828 | block_type_bolo* blk = imesure >= 0 ? lastBolo() : llastBolo();
|
---|
829 | //cout << "raw " << imesure << " ";
|
---|
830 | if (imesure < 0) imesure += nEchBlock();
|
---|
831 | if (!blk) return 0;
|
---|
832 | block_type_reglage* reglage = lastReglage();
|
---|
833 | if (!reglage) return 0;
|
---|
834 |
|
---|
835 | nb_coups= reglage->reglage.horloge.nb_mesures/2 - reglage->reglage.horloge.temp_mort;
|
---|
836 | aa = (nb_coups<<14) + (nb_coups*190) ;
|
---|
837 |
|
---|
838 | int s = imesure % 2 ? 1 : -1;
|
---|
839 |
|
---|
840 | //cout << s*(((val_DS(ibolo,imesure)-aa)<<1)/nb_coups) << "\n";
|
---|
841 |
|
---|
842 | return s*(((val_DS(ibolo,imesure)-aa)<<1)/nb_coups);
|
---|
843 | }
|
---|
844 |
|
---|
845 | def_gains
|
---|
846 |
|
---|
847 | double ArcheopsFile::getMuVBolo(int ibolo, int imesure) { // microvolts, filtre avec filtre carre
|
---|
848 | double y = (getRawBolo(ibolo, imesure-1) + getRawBolo(ibolo, imesure))/2.;
|
---|
849 | //if (imesure%2) y=-y;
|
---|
850 | block_type_reglage* reglage = lastReglage();
|
---|
851 | block_type_param* param = lastParam();
|
---|
852 | if (!reglage) return 0;
|
---|
853 | if (!param) return 0;
|
---|
854 | //cout << "muv " << imesure << " " << y << "\n";
|
---|
855 | return bol_micro_volt(y,(double)param->param.bolo[ibolo].bolo_gain*gain_ampli(reglage->reglage.bolo[ibolo]));
|
---|
856 | //return ((1e5*y)/(65536.*gain_ampli(reglage->reglage.bolo[ibolo])));
|
---|
857 | }
|
---|
858 |
|
---|
859 |
|
---|
860 | // SST, gyros...
|
---|
861 |
|
---|
862 | void ArcheopsFile::needSSTProcessMask(int mask) {
|
---|
863 | blockSet->sstHandler.NeedProcess(mask);
|
---|
864 | }
|
---|
865 |
|
---|
866 | long ArcheopsFile::getSSTSignal(int idiode, int imesure) {
|
---|
867 | return blockSet->sstHandler.getSignal(imesure, idiode);
|
---|
868 | }
|
---|
869 |
|
---|
870 | long ArcheopsFile::getSSTRawSignal(int idiode, int imesure) {
|
---|
871 | return blockSet->sstHandler.getRawSignal(imesure, idiode);
|
---|
872 | }
|
---|
873 |
|
---|
874 | double ArcheopsFile::getSSTStarZ(int istar, int imesure) {
|
---|
875 | return blockSet->sstHandler.getStarZ(imesure, istar);
|
---|
876 | }
|
---|
877 |
|
---|
878 | double ArcheopsFile::getSSTStarF(int istar, int imesure) {
|
---|
879 | return blockSet->sstHandler.getStarF(imesure, istar);
|
---|
880 | }
|
---|
881 |
|
---|
882 | long ArcheopsFile::getGyro(int igyro, int imesure) {
|
---|
883 | if (igyro<0 || igyro>2) return 0;
|
---|
884 | if (imesure<0 || imesure>= nb_per_block*2) return 0;
|
---|
885 | block_type_gyro* blk = lastGyro() ;
|
---|
886 | if (!blk) return 0;
|
---|
887 | #if version_num<=25
|
---|
888 | return blk->gyros[igyro][imesure];
|
---|
889 | #else
|
---|
890 | return blk->gyro[igyro][imesure];
|
---|
891 | #endif
|
---|
892 | }
|
---|
893 |
|
---|
894 |
|
---|
895 |
|
---|
896 | // $CHECK$ TBD
|
---|
897 |
|
---|
898 |
|
---|
899 | double ArcheopsFile::getAzimut(int imesure) {return imesure*360/nEchBlock();}
|
---|
900 | double ArcheopsFile::getPendDirect(int /*imesure*/) {return 0;}
|
---|
901 | double ArcheopsFile::getPendOrth(int /*imesure*/) {return 0;}
|
---|
902 | double ArcheopsFile::getAlpha(int /*imesure*/) {return 0;}
|
---|
903 | double ArcheopsFile::getDelta(int /*imesure*/) {return 0;}
|
---|