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

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

V2

File size: 19.8 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
[315]8extern "C" {
[310]9#include "compress.h"
[436]10#include "arcunit.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;
[310]44};
45
46BlockSet::BlockSet() {
47 lastParam = NULL;
48 lastJournal = NULL;
49 lastReglage = NULL;
50 lastDilution = NULL;
51 lastGPS = NULL;
52 lastUnePeriode = NULL;
53 lastSynchroSol = NULL;
54 lastPointageSol= NULL;
55 lastBolo = NULL;
56 llastBolo = NULL;
57 lastGyro = NULL;
58 lastSST = NULL;
59 lastBoloComp = NULL;
60 lastGyroComp = NULL;
61 lastSSTComp = NULL;
[315]62
63 memset(&curBlock,0,sizeof(block_type_modele));
64 memset(&peekBlock,0,sizeof(block_type_modele));
[310]65}
66
67BlockSet::~BlockSet() {
68 delete lastParam;
69 delete lastJournal;
70 delete lastReglage;
71 delete lastDilution;
72 delete lastGPS;
73 delete lastUnePeriode;
74 delete lastSynchroSol;
75 delete lastPointageSol;
76 delete lastBolo;
77 delete llastBolo;
78 delete lastGyro;
79 delete lastSST;
80 delete lastBoloComp;
81 delete lastGyroComp;
82 delete lastSSTComp;
83}
84
[315]85BlockSet::BlockSet(BlockSet const& x)
86{
[310]87 lastParam = NULL;
88 lastJournal = NULL;
89 lastReglage = NULL;
90 lastDilution = NULL;
91 lastGPS = NULL;
92 lastUnePeriode = NULL;
93 lastSynchroSol = NULL;
94 lastPointageSol= NULL;
95 lastBolo = NULL;
96 llastBolo = NULL;
97 lastGyro = NULL;
98 lastSST = NULL;
99 lastBoloComp = NULL;
100 lastGyroComp = NULL;
101 lastSSTComp = NULL;
[315]102
[310]103 if (x.lastParam) {
104 lastParam = new block_type_param;
105 *lastParam = *x.lastParam;
106 }
107 if (x.lastJournal) {
108 lastJournal = new block_type_journal;
109 *lastJournal = *x.lastJournal;
110 }
111 if (x.lastReglage) {
112 lastReglage = new block_type_reglage;
113 *lastReglage = *x.lastReglage;
114 }
115 if (x.lastDilution) {
116 lastDilution = new block_type_dilution;
117 *lastDilution = *x.lastDilution;
118 }
119 if (x.lastGPS) {
120 lastGPS = new block_type_gps;
121 *lastGPS = *x.lastGPS;
122 }
123 if (x.lastUnePeriode) {
124 lastUnePeriode = new block_type_une_periode;
125 *lastUnePeriode = *x.lastUnePeriode;
126 }
127 if (x.lastSynchroSol) {
128 lastSynchroSol = new block_type_synchro_sol;
129 *lastSynchroSol = *x.lastSynchroSol;
130 }
131 if (x.lastPointageSol) {
132 lastPointageSol = new block_type_pointage_sol;
133 *lastPointageSol = *x.lastPointageSol;
134 }
135 if (x.lastBolo) {
136 lastBolo = new block_type_bolo;
137 *lastBolo = *x.lastBolo;
138 }
139 if (x.llastBolo) {
140 llastBolo = new block_type_bolo;
141 *llastBolo = *x.llastBolo;
142 }
143 if (x.lastGyro) {
144 lastGyro = new block_type_gyro;
145 *lastGyro = *x.lastGyro;
146 }
147 if (x.lastSST) {
148 lastSST = new block_type_sst;
149 *lastSST = *x.lastSST;
150 }
151 if (x.lastBoloComp) {
152 lastBoloComp = new block_type_bolo_comprime;
153 *lastBoloComp = *x.lastBoloComp;
154 }
155 if (x.lastGyroComp) {
156 lastGyroComp = new block_type_gyro_comprime;
157 *lastGyroComp = *x.lastGyroComp;
158 }
159 if (x.lastSSTComp) {
160 lastSSTComp = new block_type_sst_comprime;
161 *lastSSTComp = *x.lastSSTComp;
162 }
[315]163
164 memcpy(&curBlock,&x.curBlock,sizeof(block_type_modele));
165 memcpy(&peekBlock,&x.peekBlock,sizeof(block_type_modele));
166
[310]167}
168
169void BlockSet::setBloc(block_type_modele const& blk)
170{
171 int kind = type_block(&blk);
172 switch (kind) {
173 case block_param:
174 if (!lastParam) lastParam = new block_type_param;
175 memcpy(lastParam, &blk, sizeof(block_type_param));
176 // Les fichiers fournis contiennent des valeurs debiles...
177 if (lastParam->param.n_max_bolo < 0)
178 lastParam->param.n_max_bolo = nb_max_bolo;
179 if (lastParam->param.n_per_block < 0)
180 lastParam->param.n_per_block = nb_per_block;
181 if (lastParam->param.n_max_mes_per < 0)
182 lastParam->param.n_max_mes_per = nb_max_mes_per;
183 break;
184 case block_journal:
185 if (!lastJournal) lastJournal = new block_type_journal;
186 memcpy(lastJournal, &blk, sizeof(block_type_journal));
187 break;
188 case block_reglage:
189 if (!lastReglage) lastReglage = new block_type_reglage;
190 memcpy(lastReglage, &blk, sizeof(block_type_reglage));
191 break;
192 case block_dilution:
193 if (!lastDilution) lastDilution = new block_type_dilution;
194 memcpy(lastDilution, &blk, sizeof(block_type_dilution));
195 break;
196 case block_gps:
197 if (!lastGPS) lastGPS = new block_type_gps;
198 memcpy(lastGPS, &blk, sizeof(block_type_gps));
199 break;
200 case block_une_periode:
201 if (!lastUnePeriode) lastUnePeriode = new block_type_une_periode;
202 memcpy(lastUnePeriode, &blk, sizeof(block_type_une_periode));
203 break;
204 case block_synchro_sol:
205 if (!lastSynchroSol) lastSynchroSol = new block_type_synchro_sol;
206 memcpy(lastSynchroSol, &blk, sizeof(block_type_synchro_sol));
207 break;
208 case block_pointage_sol:
209 if (!lastPointageSol) lastPointageSol = new block_type_pointage_sol;
210 memcpy(lastPointageSol, &blk, sizeof(block_type_pointage_sol));
211 break;
212 case block_bolo:
213 if (!lastBolo) lastBolo = new block_type_bolo;
214 else if (!llastBolo) {
215 llastBolo = new block_type_bolo;
[342]216 }
217 if (llastBolo) {
[310]218 memcpy(llastBolo, lastBolo, sizeof(block_type_bolo));
219 }
220 memcpy(lastBolo, &blk, sizeof(block_type_bolo));
221 break;
222 case block_gyro:
223 if (!lastGyro) lastGyro = new block_type_gyro;
224 memcpy(lastGyro, &blk, sizeof(block_type_gyro));
225 break;
226 case block_sst:
227 if (!lastSST) lastSST = new block_type_sst;
228 memcpy(lastSST, &blk, sizeof(block_type_sst));
229 break;
230 }
231}
232
233void BlockSet::setRawBloc(block_type_modele const& blk)
234{
235 int kind = type_block(&blk);
236 switch (kind) {
237 case block_bolo_comprime:
238 if (!lastBoloComp) lastBoloComp = new block_type_bolo_comprime;
239 memcpy(lastBoloComp, &blk, sizeof(block_type_bolo_comprime));
240 break;
241 case block_gyro_comprime:
242 if (!lastGyroComp) lastGyroComp = new block_type_gyro_comprime;
243 memcpy(lastGyroComp, &blk, sizeof(block_type_gyro_comprime));
244 break;
245 case block_sst_comprime:
246 if (!lastSSTComp) lastSSTComp = new block_type_sst_comprime;
247 memcpy(lastSSTComp, &blk, sizeof(block_type_sst_comprime));
248 break;
249 }
250}
251
[534]252#ifdef __MWERKS__
253#pragma mark -
254#endif
255#ifdef __MWERKS__
256#pragma mark -
257#endif
258
259
[310]260ArcheopsFile::ArcheopsFile(string const& fname) {
261 f = fopen(fname.c_str(), "rb");
[436]262 setvbuf(f, NULL, _IOFBF, 1024L*1024L);
263
[310]264 fn = fname;
265 if (!f) throw ArchExc("file not found");
266 fseek(f,0,SEEK_END);
267 fLen = ftell(f);
[315]268 curPos = -1;
269 peekPos = -1;
[310]270 curKind = -1;
271 curRawKind = -1;
272 blockSet = new BlockSet;
273 utcOffset=2;
274 computeMJD(fname);
275}
276
277ArcheopsFile::ArcheopsFile(ArcheopsFile const& x) {
278 blockSet = x.blockSet ? new BlockSet(*x.blockSet) : NULL;
279 fposStack = x.fposStack;
280
281 stack<BlockSet*> tmp;
282 ArcheopsFile& y = (ArcheopsFile&) x;
283 while (!y.blockStack.empty()) {
284 tmp.push(y.blockStack.top());
285 y.blockStack.pop();
286 }
287 while (!tmp.empty()) {
288 y.blockStack.push(tmp.top());
289 blockStack.push(new BlockSet(*tmp.top()));
290 tmp.pop();
291 }
292
[315]293 //curBlock = x.curBlock;
[310]294 curKind = x.curKind;
295 curRawKind = x.curRawKind;
296 curPos = x.curPos;
[315]297 peekPos = x.peekPos;
[310]298 fLen = x.fLen;
299 fn = x.fn;
300 f = fopen(fn.c_str(), "rb");
[436]301 setvbuf(f, NULL, _IOFBF, 1024L*1024L);
[342]302
303 rawMJD = x.rawMJD;
304 startMJD = x.startMJD;
305 utcOffset = x.utcOffset;
[310]306}
307
308ArcheopsFile::~ArcheopsFile() {
309 if (f) fclose(f);
310 delete blockSet;
311 while (!blockStack.empty())
312 { delete blockStack.top(); blockStack.pop();}
313}
314
315void ArcheopsFile::grabLastBlocs(ArcheopsFile const& oldFile) {
316 delete blockSet;
317 blockSet = new BlockSet(*oldFile.blockSet);
[315]318 //curBlock = oldFile.curBlock;
319 //peekBlock = oldFile.peekBlock;
[342]320 if (peekPos>0) peekPos = 0;
[310]321 setUTCOffset(oldFile.utcOffset);
322}
323
324
325def_nom_block
326
[342]327def_long_block
328
[310]329bool ArcheopsFile::nextBlock() {
[315]330 // si pas de peek, alors en lire un pour commencer...
331 if (peekPos<0) {
332 peekPos=0; if (!nextBlock()) return false;
333 }
334 block_type_modele* curBlock=currentBlock();
335 block_type_modele* peekBlock=aheadBlock();
336
337 memcpy(curBlock, peekBlock, sizeof(block_type_modele));
[342]338 curPos = peekPos;
[315]339
[342]340 while (true) {
341 if (peekPos+12 > fLen) return false; // fin de fichier
342 fseek(f,peekPos,SEEK_SET); // aller en peekPos
343 size_t read = fread(peekBlock,1,sizeof(block_type_modele),f);
344 swapEntete(peekBlock);
345 if (read < longueur_block(peekBlock) ||
346 type_block(peekBlock) < 0 || type_block(peekBlock) > 19 ||
347 longueur_block(peekBlock) != long_block[type_block(peekBlock)]) {
[350]348 cout << "invalid block, bad type or length" << endl;
[342]349 memset(peekBlock, 0, sizeof(block_type_modele)); // don't keep trash...
350 peekPos = searchNextBlock(peekPos);
351 if (peekPos<0) return false;
352 continue;
353 }
354 swapContent(peekBlock);
355 if (verifie_block(peekBlock) != block_correct) {
[350]356 cout << "invalid block " << numero_block(peekBlock);
[342]357 if (!fixBlock(peekBlock)) {
358 cout << " -- skipped" << endl;
359 peekPos += longueur_block(peekBlock); // la longueur doit etre ok...
360 continue;
361 } else {
362 cout << " -- fixed" << endl;
363 break;
364 }
365 }
366 break; // tout semble bon pour ce bloc...
[310]367 }
[342]368
369 peekPos += longueur_block(peekBlock); // on suppose que longueur OK...
[315]370 if (curPos < 0) {
371 curPos = 0; return true;
372 }
[342]373 if (curBlock->debut != 0) {
374 curRawKind = curKind = type_block(curBlock);
375 postProcessBlock();
376 saveCurBlock();
377 } else {
378 curRawKind = curKind = -1;
379 }
[310]380 return true;
381}
382
383bool ArcheopsFile::nextBlock(long mask) {
384 if (!mask) return false;
385 while (1) {
386 if (!nextBlock()) return false;
387 if (( 1 << curRawKind) & mask) return true;
388 }
389}
390
[350]391bool ArcheopsFile::fixBlock(block_type_modele* ) {
[342]392 return false;
393}
394
395
[310]396int ArcheopsFile::blockKind() {
397 return curKind;
398}
399
400int ArcheopsFile::blockRawKind() {
401 return curRawKind;
402}
403
404int ArcheopsFile::blockNum() {
[315]405 return numero_block(currentBlock());
[310]406}
407
408
409string ArcheopsFile::blockKdName() {
410 return nom_block[curKind];
411}
412
413string ArcheopsFile::blockRawKdName() {
414 return nom_block[curRawKind];
415}
416
417
418block_type_modele* ArcheopsFile::currentBlock() {
[315]419 //if (curPos<0) return NULL;
420 return &blockSet->curBlock;
[310]421}
422
[315]423block_type_modele* ArcheopsFile::aheadBlock() {
424 //if (peekPos<0) return NULL;
425 return &blockSet->peekBlock;
426}
427
428bool ArcheopsFile::sameBlockNumAhead() {
429 if (curPos<0) return false;
430 return (numero_block(&blockSet->curBlock) == numero_block(&blockSet->peekBlock));
431}
432
[342]433void ArcheopsFile::forceBlock(block_type_modele* blk) {
434 blockSet->setBloc(*blk);
435}
436
[534]437long ArcheopsFile::searchNextBlock(long pos) {
438 static char* buffer = 0;
439 static int4 debswp = debut_block_mesure;
440 static int4 longmax = taille_maxi_block_archeops*20;
441 if (!buffer) {
442 buffer = new char[longmax];
443#ifdef SWAP
444 bswap4(&debswp);
445#endif
446 }
447 long read = longmax;
448 while (read == longmax) {
449 fseek(f,pos,SEEK_SET);
450 read = fread(buffer,1,longmax,f);
451 //if (read<taille_maxi_block_archeops*2) return -1;
452 // EA 150999 changed i+=4 to i++ -> unaligned, but can lose bytes in flight recorder
453#ifndef __DECCXX
454#define __unaligned
455#endif
456 for (long i=4; i<read; i++) {
457 if (*(__unaligned int4*)(buffer+i) == debswp) {
458 cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
459 return pos+i;
460 }
461 }
462 pos += read;
463 }
464 cout << "cannot find block start" << endl;
465 return -1;
466}
467
[342]468#define place_paquet(i,j) ((i/8) * 24 + j*8 + (i%8) )
469
[310]470void ArcheopsFile::postProcessBlock() {
471 switch (curKind) {
472 case block_bolo_comprime: {
[315]473 blockSet->setRawBloc(blockSet->curBlock);
[310]474 block_type_bolo blk2;
[315]475 block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &blockSet->curBlock;
[342]476 #if version_num <= 25
[310]477 for(int j=0;j<nb_bolo_util;j++)
[342]478 {
479 decompress_7_2((int4*)blk->data_bolo[j],blk2.data_bolo[j],nb_per_block*2);
480 }
481 #else
482 block_type_param* param = lastParam();
[350]483 if (!param) return;
[342]484 int jc=0;for(int j=0;j<nb_max_bolo;j++) // jc = bolo_comprime // j=bolo normal
485 {
486 if( (param->param.bolo[j].bolo_code_util==bolo_normal_transmis) && (jc<nb_bolo_util) )
487 {
488 decompress_7_2((int4 *)blk->data_bolo[jc],blk2.data_bolo[j],nb_per_block*2);
489 jc++;
490 }
491 else {
492 memset(blk2.data_bolo[j], 0, nb_per_block*2*sizeof(int4));
[310]493 }
[342]494 }
495
496 #endif
[310]497 valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk));
[315]498 memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
[310]499 curKind = block_bolo;
[534]500 postProcessBlock();
[310]501 break;
502 }
[405]503 case block_sst_comprime: {
[342]504 blockSet->setRawBloc(blockSet->curBlock);
505 block_type_sst blk2;
506 block_type_sst_comprime* blk = (block_type_sst_comprime*) &blockSet->curBlock;
507 for (int j=0; j<18; j++)
508 for (int i=0; i<nb_per_block*2; i++)
509 blk2.sst[i][j] = 0;
510
511 int jc=0;
512 for( int j=0;j<48;j++) {
513 if ((j!=0) && (j!=4))
514 {
515 unsigned int4 sst_vrai[nb_per_block*2];
516 decompress_4_1((int4*)blk->sst[jc],(int4*)sst_vrai,nb_per_block*2);
517 for (int k=0;k<nb_per_block*2;k++) {
518 unsigned int4 a,b0,b1,b2;
519 b2 = sst_vrai[k] & 0xf;
520 b1 = (sst_vrai[k] >> 4) & 0xf;
521 b0 = (sst_vrai[k] >> 8) & 0xf;
522 a=place_paquet(j,0);
523 blk2.sst[k][a/8] |= (b0 << (a%8)*4);
524 a=place_paquet(j,1);
525 blk2.sst[k][a/8] |= (b1 << (a%8)*4);
526 a=place_paquet(j,2);
527 blk2.sst[k][a/8] |= (b2 << (a%8)*4);
528 }
529 jc++;
530 }
531 }
532 valide_block((block_type_modele*)&blk2,block_sst,numero_block(blk));
533 memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
534 curKind = block_sst;
[534]535 postProcessBlock();
[342]536 break;
[315]537 }
[534]538// Delegation a tous les producers qui traitent des blocs bruts
[310]539 }
540}
541
[534]542
543
544#ifdef __MWERKS__
545#pragma mark -
546#endif
547
548block_type_param* ArcheopsFile::lastParam() {
549 return blockSet->lastParam;
550}
551block_type_journal* ArcheopsFile::lastJournal() {
552 return blockSet->lastJournal;
553}
554block_type_reglage* ArcheopsFile::lastReglage() {
555 return blockSet->lastReglage;
556}
557block_type_dilution* ArcheopsFile::lastDilution() {
558 return blockSet->lastDilution;
559}
560block_type_gps* ArcheopsFile::lastGPS() {
561 return blockSet->lastGPS;
562}
563block_type_une_periode* ArcheopsFile::lastUnePeriode() {
564 return blockSet->lastUnePeriode;
565}
566block_type_synchro_sol* ArcheopsFile::lastSynchroSol() {
567 return blockSet->lastSynchroSol;
568}
569block_type_pointage_sol* ArcheopsFile::lastPointageSol() {
570 return blockSet->lastPointageSol;
571}
572block_type_bolo* ArcheopsFile::lastBolo() {
573 return blockSet->lastBolo;
574}
575block_type_bolo* ArcheopsFile::llastBolo() {
576 return blockSet->llastBolo;
577}
578block_type_gyro* ArcheopsFile::lastGyro() {
579 return blockSet->lastGyro;
580}
581block_type_sst* ArcheopsFile::lastSST() {
582 return blockSet->lastSST;
583}
584block_type_bolo_comprime* ArcheopsFile::lastBoloComp() {
585 return blockSet->lastBoloComp;
586}
587block_type_gyro_comprime* ArcheopsFile::lastGyroComp() {
588 return blockSet->lastGyroComp;
589}
590block_type_sst_comprime* ArcheopsFile::lastSSTComp() {
591 return blockSet->lastSSTComp;
592}
593
594#ifdef __MWERKS__
595#pragma mark -
596#endif
597
598
599
[310]600void ArcheopsFile::saveCurBlock() {
[315]601 blockSet->setBloc(blockSet->curBlock);
[310]602}
603
[398]604void ArcheopsFile::pushMark() { // push current file position, and "last" blocks
[310]605 fposStack.push(curPos);
[315]606 fposStack.push(peekPos);
[310]607 blockStack.push(new BlockSet(*blockSet));
608}
609
610void ArcheopsFile::popMark() { // pops last file position and "last" blocks
611 if (! blockStack.empty()) {
612 delete blockSet;
613 blockSet = blockStack.top();
614 blockStack.pop();
[315]615 peekPos = fposStack.top();
[310]616 fposStack.pop();
[315]617 curPos = fposStack.top();
618 fposStack.pop();
[310]619 }
620}
621
[315]622typedef unsigned int4 uint_4;
623typedef unsigned short uint_2;
624
625static inline void bswap4(void* p)
626{
627 uint_4 tmp = *(uint_4*)p;
628 *(uint_4*)p = ((tmp >> 24) & 0x000000FF) |
629 ((tmp >> 8) & 0x0000FF00) |
630 ((tmp & 0x0000FF00) << 8) |
631 ((tmp & 0x000000FF) << 24);
632}
633
634static inline void bswap2(void* p)
635{
636 uint_2 tmp = *(uint_2*)p;
637 *(uint_2*)p = ((tmp >> 8) & 0x00FF) |
638 ((tmp & 0x00FF) << 8);
639}
640
641#ifdef __DECCXX
642#define SWAP
643#endif
644#if defined(Linux) || defined(linux)
645#define SWAP
646#endif
647
[342]648#ifdef SWAP
[315]649void ArcheopsFile::swapEntete(block_type_modele* blk) {
650 bswap4(&(blk->debut));
651 bswap4(&(blk->code1));
652 bswap4(&(blk->code2));
653 long lg = longueur_block(blk);
[342]654 if (lg < taille_maxi_block_archeops)
655 bswap4(((char*)blk) + lg - 4);
656}
657#else
658void ArcheopsFile::swapEntete(block_type_modele* ) {
659}
[315]660#endif
661
[342]662#ifdef SWAP
[315]663void ArcheopsFile::swapContent(block_type_modele* blk) {
664 int typ = type_block(blk);
665
666 if (typ == block_gps) return; // char only, no swap
667 if (typ == block_une_periode) { // une_periode, des shorts
668 block_type_une_periode* b = (block_type_une_periode*) blk;
669 for (int i=0; i<nb_max_bolo; i++)
670 for (int j=0; j<nb_max_mes_per; j++)
671 bswap2(&b->bol_per[i][j]);
672 return;
673 }
674
675 for (int i=0; i<longueur_block(blk)/4-4; i++)
676 bswap4(blk->mot + i);
677 // On deswappe ce qui ne devait pas etre swappe...
678 switch (typ) {
679 case block_param: {
680 block_type_param* b = (block_type_param*) blk;
681 for (int i=0; i<nb_max_bolo; i++)
682 for (int j=0; j<8; j++)
[342]683#if version_num<=25
684 bswap4(&b->param.bolo[i].bolo_nom[4*j]);
685#else
686 bswap4(&b->param.nom_coef[i].bolo_nom[4*j]);
687#endif
[315]688 }
689
690 }
[342]691}
692#else
693void ArcheopsFile::swapContent(block_type_modele* ) {
694}
[315]695#endif
[409]696
[534]697#ifdef __MWERKS__
698#pragma mark -
[342]699#endif
700
[315]701
[310]702static int mlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
703
[342]704double ArcheopsFile::decodeMJD(string const& dateString) {
705 //99_04_29-15h36m22 ou 99_05_10
706 short y,m,d,hh,mm,ss;
707 char const* p = dateString.c_str();
708 char const* p2 = dateString.c_str() + dateString.length();
709 y = atoi(p); p+=3; if (p>p2) return -1;
710 m = atoi(p); p+=3; if (p>p2) return -1;
711 d = atoi(p); p+=3;
712 if (p<p2) {
713 hh = atoi(p); p+=3; if (p>p2) return -1;
714 mm = atoi(p); p+=3; if (p>p2) return -1;
715 ss = atoi(p);
716 } else {
717 hh=mm=ss=0;
718 }
719
720 if (y<50) y += 100;
721 // 1. depuis 0/1/97 minuit
722 double mjd = (int) (365.25 * (y-97));
723 for (int i=0; i<m-1; i++)
724 mjd += mlen[i];
725 if (y%4 == 0 && m > 2) mjd++;
726 mjd += d;
727 mjd += hh/24. + mm/24./60. + ss/24./60./60;
728
729 mjd += 448.5; // 0/1/97 minuit
730
731 return mjd;
732}
733
[310]734void ArcheopsFile::computeMJD(string const& fname) {
[342]735 //telemetrie : h99_04_29-15h36m22
736 //enregistreur : ARKxxxxxx.dat, et MJD = samedi 17 juillet, 21h -> 1377.4
[310]737 char const* p = fname.c_str();
738 char const* p2 = p + fname.length()-1;
739 while (*p2 != ':' && *p2 != '/' && p2 != p) p2--;
740 if (*p2 == ':' || *p2 == '/') p2++;
741 if (*p2 == 'h') p2++;
[350]742 if (!strncmp(p2, "ARK",3) || !strncmp(p2,"ark",3)) {
[342]743 rawMJD = 1377.4;
744 } else {
745 rawMJD = decodeMJD(p2);
746 }
[310]747 startMJD = rawMJD - utcOffset/24.;
748}
749
[534]750void ArcheopsFile::setUTCOffset(double UTCOffset) {
[310]751 utcOffset = UTCOffset;
752 startMJD = rawMJD - utcOffset/24.;
753}
754
755double ArcheopsFile::getStartMJD() {
756 return startMJD;
757}
758
Note: See TracBrowser for help on using the repository browser.