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