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