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

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

fix alpha swap

File size: 20.1 KB
Line 
1// archeopsfile.cc
2// Eric Aubourg CEA/DAPNIA/SPP juillet 1999
3
4
5#define utilitaires_de_block_archeops
6#include "archeopsfile.h"
7
8extern "C" {
9#include "compress.h"
10#include "arcunit.h"
11}
12#include <iostream.h>
13
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
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;
41
42 block_type_modele curBlock;
43 block_type_modele peekBlock;
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;
62
63 memset(&curBlock,0,sizeof(block_type_modele));
64 memset(&peekBlock,0,sizeof(block_type_modele));
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
85BlockSet::BlockSet(BlockSet const& x)
86{
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;
102
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 }
163
164 memcpy(&curBlock,&x.curBlock,sizeof(block_type_modele));
165 memcpy(&peekBlock,&x.peekBlock,sizeof(block_type_modele));
166
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;
216 }
217 if (llastBolo) {
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
252#ifdef __MWERKS__
253#pragma mark -
254#endif
255#ifdef __MWERKS__
256#pragma mark -
257#endif
258
259
260ArcheopsFile::ArcheopsFile(string const& fname) {
261 f = fopen(fname.c_str(), "rb");
262 setvbuf(f, NULL, _IOFBF, 1024L*1024L);
263
264 fn = fname;
265 if (!f) throw ArchExc("file not found");
266 fseek(f,0,SEEK_END);
267 fLen = ftell(f);
268 curPos = -1;
269 peekPos = -1;
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
293 //curBlock = x.curBlock;
294 curKind = x.curKind;
295 curRawKind = x.curRawKind;
296 curPos = x.curPos;
297 peekPos = x.peekPos;
298 fLen = x.fLen;
299 fn = x.fn;
300 f = fopen(fn.c_str(), "rb");
301 setvbuf(f, NULL, _IOFBF, 1024L*1024L);
302
303 rawMJD = x.rawMJD;
304 startMJD = x.startMJD;
305 utcOffset = x.utcOffset;
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);
318 //curBlock = oldFile.curBlock;
319 //peekBlock = oldFile.peekBlock;
320 if (peekPos>0) peekPos = 0;
321 setUTCOffset(oldFile.utcOffset);
322}
323
324
325def_nom_block
326
327def_long_block
328
329bool ArcheopsFile::nextBlock() {
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));
338 curPos = peekPos;
339
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)]) {
348 cout << "invalid block, bad type or length" << endl;
349 //cout << "addr = " << peekPos << endl;
350 memset(peekBlock, 0, sizeof(block_type_modele)); // don't keep trash...
351 peekPos = searchNextBlock(peekPos);
352 if (peekPos<0) return false;
353 continue;
354 }
355 swapContent(peekBlock);
356 if (verifie_block(peekBlock) != block_correct) {
357 cout << "invalid block " << numero_block(peekBlock);
358 if (!fixBlock(peekBlock)) {
359 cout << " -- skipped" << endl;
360 peekPos += longueur_block(peekBlock); // la longueur doit etre ok...
361 continue;
362 } else {
363 cout << " -- fixed" << endl;
364 break;
365 }
366 }
367 break; // tout semble bon pour ce bloc...
368 }
369
370 peekPos += longueur_block(peekBlock); // on suppose que longueur OK...
371 if (curPos < 0) {
372 curPos = 0; return true;
373 }
374 if (curBlock->debut != 0) {
375 curRawKind = curKind = type_block(curBlock);
376 postProcessBlock();
377 saveCurBlock();
378 } else {
379 curRawKind = curKind = -1;
380 }
381 return true;
382}
383
384bool ArcheopsFile::nextBlock(long mask) {
385 if (!mask) return false;
386 while (1) {
387 if (!nextBlock()) return false;
388 if (( 1 << curRawKind) & mask) return true;
389 }
390}
391
392bool ArcheopsFile::fixBlock(block_type_modele* ) {
393 return false;
394}
395
396
397int ArcheopsFile::blockKind() {
398 return curKind;
399}
400
401int ArcheopsFile::blockRawKind() {
402 return curRawKind;
403}
404
405int ArcheopsFile::blockNum() {
406 return numero_block(currentBlock());
407}
408
409
410string ArcheopsFile::blockKdName() {
411 return nom_block[curKind];
412}
413
414string ArcheopsFile::blockRawKdName() {
415 return nom_block[curRawKind];
416}
417
418
419block_type_modele* ArcheopsFile::currentBlock() {
420 //if (curPos<0) return NULL;
421 return &blockSet->curBlock;
422}
423
424block_type_modele* ArcheopsFile::aheadBlock() {
425 //if (peekPos<0) return NULL;
426 return &blockSet->peekBlock;
427}
428
429bool ArcheopsFile::sameBlockNumAhead() {
430 if (curPos<0) return false;
431 return (numero_block(&blockSet->curBlock) == numero_block(&blockSet->peekBlock));
432}
433
434void ArcheopsFile::forceBlock(block_type_modele* blk) {
435 blockSet->setBloc(*blk);
436}
437
438
439#ifdef __DECCXX
440#define SWAP
441#endif
442#if ((defined(Linux) || defined(linux)) && !defined(powerpc))
443#define SWAP
444#endif
445
446
447typedef unsigned int4 uint_4;
448typedef unsigned short uint_2;
449
450static inline void bswap4(void* p)
451{
452 uint_4 tmp = *(uint_4*)p;
453 *(uint_4*)p = ((tmp >> 24) & 0x000000FF) |
454 ((tmp >> 8) & 0x0000FF00) |
455 ((tmp & 0x0000FF00) << 8) |
456 ((tmp & 0x000000FF) << 24);
457}
458
459static inline void bswap2(void* p)
460{
461 uint_2 tmp = *(uint_2*)p;
462 *(uint_2*)p = ((tmp >> 8) & 0x00FF) |
463 ((tmp & 0x00FF) << 8);
464}
465
466
467long ArcheopsFile::searchNextBlock(long pos) {
468 static char* buffer = 0;
469 static int4 debswp = debut_block_mesure;
470 static long longmax = taille_maxi_block_archeops*20;
471 if (!buffer) {
472 buffer = new char[longmax];
473#ifdef SWAP
474 bswap4(&debswp);
475#endif
476 }
477 //printf("searchNext %o len = %d value = %x \n", pos, longmax, debswp);
478 long read = longmax;
479 while (read == longmax) {
480 fseek(f,pos,SEEK_SET);
481 read = fread(buffer,1,longmax,f);
482 //if (read<taille_maxi_block_archeops*2) return -1;
483 // EA 150999 changed i+=4 to i++ -> unaligned, but can lose bytes in flight recorder
484#ifndef __DECCXX
485#define __unaligned
486#endif
487 for (long i=4; i<read; i++) {
488 // printf("%o %x\n", pos+i, *(__unaligned int4*)(buffer+i));
489 if (*(__unaligned int4*)(buffer+i) == debswp) {
490 cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
491 return pos+i;
492 }
493 }
494 pos += read;
495 }
496 cout << "cannot find block start" << endl;
497 return -1;
498}
499
500#define place_paquet(i,j) ((i/8) * 24 + j*8 + (i%8) )
501
502void ArcheopsFile::postProcessBlock() {
503 switch (curKind) {
504 case block_bolo_comprime: {
505 blockSet->setRawBloc(blockSet->curBlock);
506 block_type_bolo blk2;
507 block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &blockSet->curBlock;
508 #if version_num <= 25
509 for(int j=0;j<nb_bolo_util;j++)
510 {
511 decompress_7_2((int4*)blk->data_bolo[j],blk2.data_bolo[j],nb_per_block*2);
512 }
513 #else
514 block_type_param* param = lastParam();
515 if (!param) return;
516 int jc=0;for(int j=0;j<nb_max_bolo;j++) // jc = bolo_comprime // j=bolo normal
517 {
518 if( (param->param.bolo[j].bolo_code_util==bolo_normal_transmis) && (jc<nb_bolo_util) )
519 {
520 decompress_7_2((int4 *)blk->data_bolo[jc],blk2.data_bolo[j],nb_per_block*2);
521 jc++;
522 }
523 else {
524 memset(blk2.data_bolo[j], 0, nb_per_block*2*sizeof(int4));
525 }
526 }
527
528 #endif
529 valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk));
530 memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
531 curKind = block_bolo;
532 postProcessBlock();
533 break;
534 }
535 case block_sst_comprime: {
536 blockSet->setRawBloc(blockSet->curBlock);
537 block_type_sst blk2;
538 block_type_sst_comprime* blk = (block_type_sst_comprime*) &blockSet->curBlock;
539 for (int j=0; j<18; j++)
540 for (int i=0; i<nb_per_block*2; i++)
541 blk2.sst[i][j] = 0;
542
543 int jc=0;
544 for( int j=0;j<48;j++) {
545 if ((j!=0) && (j!=4))
546 {
547 unsigned int4 sst_vrai[nb_per_block*2];
548 decompress_4_1((int4*)blk->sst[jc],(int4*)sst_vrai,nb_per_block*2);
549 for (int k=0;k<nb_per_block*2;k++) {
550 unsigned int4 a,b0,b1,b2;
551 b2 = sst_vrai[k] & 0xf;
552 b1 = (sst_vrai[k] >> 4) & 0xf;
553 b0 = (sst_vrai[k] >> 8) & 0xf;
554 a=place_paquet(j,0);
555 blk2.sst[k][a/8] |= (b0 << (a%8)*4);
556 a=place_paquet(j,1);
557 blk2.sst[k][a/8] |= (b1 << (a%8)*4);
558 a=place_paquet(j,2);
559 blk2.sst[k][a/8] |= (b2 << (a%8)*4);
560 }
561 jc++;
562 }
563 }
564 valide_block((block_type_modele*)&blk2,block_sst,numero_block(blk));
565 memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
566 curKind = block_sst;
567 postProcessBlock();
568 break;
569 }
570// Delegation a tous les producers qui traitent des blocs bruts
571 }
572}
573
574
575
576#ifdef __MWERKS__
577#pragma mark -
578#endif
579
580block_type_param* ArcheopsFile::lastParam() {
581 return blockSet->lastParam;
582}
583block_type_journal* ArcheopsFile::lastJournal() {
584 return blockSet->lastJournal;
585}
586block_type_reglage* ArcheopsFile::lastReglage() {
587 return blockSet->lastReglage;
588}
589block_type_dilution* ArcheopsFile::lastDilution() {
590 return blockSet->lastDilution;
591}
592block_type_gps* ArcheopsFile::lastGPS() {
593 return blockSet->lastGPS;
594}
595block_type_une_periode* ArcheopsFile::lastUnePeriode() {
596 return blockSet->lastUnePeriode;
597}
598block_type_synchro_sol* ArcheopsFile::lastSynchroSol() {
599 return blockSet->lastSynchroSol;
600}
601block_type_pointage_sol* ArcheopsFile::lastPointageSol() {
602 return blockSet->lastPointageSol;
603}
604block_type_bolo* ArcheopsFile::lastBolo() {
605 return blockSet->lastBolo;
606}
607block_type_bolo* ArcheopsFile::llastBolo() {
608 return blockSet->llastBolo;
609}
610block_type_gyro* ArcheopsFile::lastGyro() {
611 return blockSet->lastGyro;
612}
613block_type_sst* ArcheopsFile::lastSST() {
614 return blockSet->lastSST;
615}
616block_type_bolo_comprime* ArcheopsFile::lastBoloComp() {
617 return blockSet->lastBoloComp;
618}
619block_type_gyro_comprime* ArcheopsFile::lastGyroComp() {
620 return blockSet->lastGyroComp;
621}
622block_type_sst_comprime* ArcheopsFile::lastSSTComp() {
623 return blockSet->lastSSTComp;
624}
625
626#ifdef __MWERKS__
627#pragma mark -
628#endif
629
630
631
632void ArcheopsFile::saveCurBlock() {
633 blockSet->setBloc(blockSet->curBlock);
634}
635
636void ArcheopsFile::pushMark() { // push current file position, and "last" blocks
637 fposStack.push(curPos);
638 fposStack.push(peekPos);
639 blockStack.push(new BlockSet(*blockSet));
640}
641
642void ArcheopsFile::popMark() { // pops last file position and "last" blocks
643 if (! blockStack.empty()) {
644 delete blockSet;
645 blockSet = blockStack.top();
646 blockStack.pop();
647 peekPos = fposStack.top();
648 fposStack.pop();
649 curPos = fposStack.top();
650 fposStack.pop();
651 }
652}
653
654#ifdef SWAP
655void ArcheopsFile::swapEntete(block_type_modele* blk) {
656 bswap4(&(blk->debut));
657 bswap4(&(blk->code1));
658 bswap4(&(blk->code2));
659 long lg = longueur_block(blk);
660 if (lg < taille_maxi_block_archeops)
661 bswap4(((char*)blk) + lg - 4);
662}
663#else
664void ArcheopsFile::swapEntete(block_type_modele* ) {
665}
666#endif
667
668#ifdef SWAP
669void ArcheopsFile::swapContent(block_type_modele* blk) {
670 int typ = type_block(blk);
671
672 if (typ == block_gps) return; // char only, no swap
673 if (typ == block_une_periode) { // une_periode, des shorts
674 block_type_une_periode* b = (block_type_une_periode*) blk;
675 for (int i=0; i<nb_max_bolo; i++)
676 for (int j=0; j<nb_max_mes_per; j++)
677 bswap2(&b->bol_per[i][j]);
678 return;
679 }
680
681 for (int i=0; i<longueur_block(blk)/4-4; i++)
682 bswap4(blk->mot + i);
683 // On deswappe ce qui ne devait pas etre swappe...
684 switch (typ) {
685 case block_param: {
686 block_type_param* b = (block_type_param*) blk;
687 for (int i=0; i<nb_max_bolo; i++)
688 for (int j=0; j<8; j++)
689#if version_num<=25
690 bswap4(&b->param.bolo[i].bolo_nom[4*j]);
691#else
692 bswap4(&b->param.nom_coef[i].bolo_nom[4*j]);
693#endif
694 }
695
696 }
697}
698#else
699void ArcheopsFile::swapContent(block_type_modele* ) {
700}
701#endif
702
703#ifdef __MWERKS__
704#pragma mark -
705#endif
706
707
708static int mlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
709
710double ArcheopsFile::decodeMJD(string const& dateString) {
711 //99_04_29-15h36m22 ou 99_05_10
712 short y,m,d,hh,mm,ss;
713 char const* p = dateString.c_str();
714 char const* p2 = dateString.c_str() + dateString.length();
715 y = atoi(p); p+=3; if (p>p2) return -1;
716 m = atoi(p); p+=3; if (p>p2) return -1;
717 d = atoi(p); p+=3;
718 if (p<p2) {
719 hh = atoi(p); p+=3; if (p>p2) return -1;
720 mm = atoi(p); p+=3; if (p>p2) return -1;
721 ss = atoi(p);
722 } else {
723 hh=mm=ss=0;
724 }
725
726 if (y<50) y += 100;
727 // 1. depuis 0/1/97 minuit
728 double mjd = (int) (365.25 * (y-97));
729 for (int i=0; i<m-1; i++)
730 mjd += mlen[i];
731 if (y%4 == 0 && m > 2) mjd++;
732 mjd += d;
733 mjd += hh/24. + mm/24./60. + ss/24./60./60;
734
735 mjd += 448.5; // 0/1/97 minuit
736
737 return mjd;
738}
739
740void ArcheopsFile::computeMJD(string const& fname) {
741 //telemetrie : h99_04_29-15h36m22
742 //enregistreur : ARKxxxxxx.dat, et MJD = samedi 17 juillet, 21h -> 1377.4
743 char const* p = fname.c_str();
744 char const* p2 = p + fname.length()-1;
745 while (*p2 != ':' && *p2 != '/' && p2 != p) p2--;
746 if (*p2 == ':' || *p2 == '/') p2++;
747 if (*p2 == 'h') p2++;
748 if (!strncmp(p2, "ARK",3) || !strncmp(p2,"ark",3)) {
749 rawMJD = 1377.4;
750 } else {
751 rawMJD = decodeMJD(p2);
752 }
753 startMJD = rawMJD - utcOffset/24.;
754}
755
756void ArcheopsFile::setUTCOffset(double UTCOffset) {
757 utcOffset = UTCOffset;
758 startMJD = rawMJD - utcOffset/24.;
759}
760
761double ArcheopsFile::getStartMJD() {
762 return startMJD;
763}
764
Note: See TracBrowser for help on using the repository browser.