source: Sophya/trunk/Poubelle/archTOI.old/archeopsfile.cc@ 426

Last change on this file since 426 was 426, checked in by ansari, 26 years ago

alpha delta a partir croisement galax

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