| 1 | // archeopsfile.cc
|
|---|
| 2 | // Eric Aubourg CEA/DAPNIA/SPP juillet 1999
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 | #define utilitaires_de_block_archeops
|
|---|
| 6 | #include "archeopsfile.h"
|
|---|
| 7 | #include "gyrohandler.h"
|
|---|
| 8 |
|
|---|
| 9 | extern "C" {
|
|---|
| 10 | #include "compress.h"
|
|---|
| 11 | #include "arcunit.h"
|
|---|
| 12 | }
|
|---|
| 13 | #include <iostream.h>
|
|---|
| 14 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 42 |
|
|---|
| 43 | block_type_modele curBlock;
|
|---|
| 44 | block_type_modele peekBlock;
|
|---|
| 45 |
|
|---|
| 46 | SSTHandler sstHandler;
|
|---|
| 47 | GyroHandler gyroHandler;
|
|---|
| 48 | GPSParser gpsParser;
|
|---|
| 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;
|
|---|
| 67 |
|
|---|
| 68 | memset(&curBlock,0,sizeof(block_type_modele));
|
|---|
| 69 | memset(&peekBlock,0,sizeof(block_type_modele));
|
|---|
| 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 |
|
|---|
| 90 | BlockSet::BlockSet(BlockSet const& x)
|
|---|
| 91 | : sstHandler(x.sstHandler), gyroHandler(x.gyroHandler)
|
|---|
| 92 | {
|
|---|
| 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;
|
|---|
| 108 |
|
|---|
| 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 | }
|
|---|
| 169 |
|
|---|
| 170 | memcpy(&curBlock,&x.curBlock,sizeof(block_type_modele));
|
|---|
| 171 | memcpy(&peekBlock,&x.peekBlock,sizeof(block_type_modele));
|
|---|
| 172 |
|
|---|
| 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;
|
|---|
| 222 | }
|
|---|
| 223 | if (llastBolo) {
|
|---|
| 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");
|
|---|
| 260 | setvbuf(f, NULL, _IOFBF, 1024L*1024L);
|
|---|
| 261 |
|
|---|
| 262 | fn = fname;
|
|---|
| 263 | if (!f) throw ArchExc("file not found");
|
|---|
| 264 | fseek(f,0,SEEK_END);
|
|---|
| 265 | fLen = ftell(f);
|
|---|
| 266 | curPos = -1;
|
|---|
| 267 | peekPos = -1;
|
|---|
| 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 |
|
|---|
| 291 | //curBlock = x.curBlock;
|
|---|
| 292 | curKind = x.curKind;
|
|---|
| 293 | curRawKind = x.curRawKind;
|
|---|
| 294 | curPos = x.curPos;
|
|---|
| 295 | peekPos = x.peekPos;
|
|---|
| 296 | fLen = x.fLen;
|
|---|
| 297 | fn = x.fn;
|
|---|
| 298 | f = fopen(fn.c_str(), "rb");
|
|---|
| 299 | setvbuf(f, NULL, _IOFBF, 1024L*1024L);
|
|---|
| 300 |
|
|---|
| 301 | rawMJD = x.rawMJD;
|
|---|
| 302 | startMJD = x.startMJD;
|
|---|
| 303 | utcOffset = x.utcOffset;
|
|---|
| 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);
|
|---|
| 316 | //curBlock = oldFile.curBlock;
|
|---|
| 317 | //peekBlock = oldFile.peekBlock;
|
|---|
| 318 | if (peekPos>0) peekPos = 0;
|
|---|
| 319 | setUTCOffset(oldFile.utcOffset);
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 | def_nom_block
|
|---|
| 324 |
|
|---|
| 325 | def_long_block
|
|---|
| 326 |
|
|---|
| 327 | bool ArcheopsFile::nextBlock() {
|
|---|
| 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));
|
|---|
| 336 | curPos = peekPos;
|
|---|
| 337 |
|
|---|
| 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)]) {
|
|---|
| 346 | cout << "invalid block, bad type or length" << endl;
|
|---|
| 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) {
|
|---|
| 354 | cout << "invalid block " << numero_block(peekBlock);
|
|---|
| 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...
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | peekPos += longueur_block(peekBlock); // on suppose que longueur OK...
|
|---|
| 368 | if (curPos < 0) {
|
|---|
| 369 | curPos = 0; return true;
|
|---|
| 370 | }
|
|---|
| 371 | if (curBlock->debut != 0) {
|
|---|
| 372 | curRawKind = curKind = type_block(curBlock);
|
|---|
| 373 | postProcessBlock();
|
|---|
| 374 | saveCurBlock();
|
|---|
| 375 | } else {
|
|---|
| 376 | curRawKind = curKind = -1;
|
|---|
| 377 | }
|
|---|
| 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 |
|
|---|
| 389 | bool ArcheopsFile::fixBlock(block_type_modele* ) {
|
|---|
| 390 | return false;
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 | int ArcheopsFile::blockKind() {
|
|---|
| 395 | return curKind;
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | int ArcheopsFile::blockRawKind() {
|
|---|
| 399 | return curRawKind;
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | int ArcheopsFile::blockNum() {
|
|---|
| 403 | return numero_block(currentBlock());
|
|---|
| 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;
|
|---|
| 411 | if (!lastReglage()) return -1;
|
|---|
| 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
|
|---|
| 423 | return lastParam()->param.n_per_block*2;
|
|---|
| 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() {
|
|---|
| 436 | //if (curPos<0) return NULL;
|
|---|
| 437 | return &blockSet->curBlock;
|
|---|
| 438 | }
|
|---|
| 439 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 503 | void ArcheopsFile::postProcessBlock() {
|
|---|
| 504 | switch (curKind) {
|
|---|
| 505 | case block_bolo_comprime: {
|
|---|
| 506 | blockSet->setRawBloc(blockSet->curBlock);
|
|---|
| 507 | block_type_bolo blk2;
|
|---|
| 508 | block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &blockSet->curBlock;
|
|---|
| 509 | #if version_num <= 25
|
|---|
| 510 | for(int j=0;j<nb_bolo_util;j++)
|
|---|
| 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();
|
|---|
| 516 | if (!param) return;
|
|---|
| 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));
|
|---|
| 526 | }
|
|---|
| 527 | }
|
|---|
| 528 |
|
|---|
| 529 | #endif
|
|---|
| 530 | valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk));
|
|---|
| 531 | memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
|
|---|
| 532 | curKind = block_bolo;
|
|---|
| 533 | break;
|
|---|
| 534 | }
|
|---|
| 535 | case block_sst_comprime: {
|
|---|
| 536 | blockSet->setRawBloc(blockSet->curBlock);
|
|---|
| 537 | if (!blockSet->sstHandler.NeedBlocks()) break; // inutile de decompresser
|
|---|
| 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;
|
|---|
| 568 | // cout << "process " << numero_block(&blockSet->curBlock) << "\n";
|
|---|
| 569 | blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
|
|---|
| 570 | break;
|
|---|
| 571 | }
|
|---|
| 572 | case block_sst : {
|
|---|
| 573 | // cout << "process " << numero_block(&blockSet->curBlock) << "\n";
|
|---|
| 574 | blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
|
|---|
| 575 | }
|
|---|
| 576 | case block_gyro : {
|
|---|
| 577 | blockSet->gyroHandler.ProcessBlock((block_type_gyro*)&blockSet->curBlock);
|
|---|
| 578 | }
|
|---|
| 579 | case block_gps : {
|
|---|
| 580 | blockSet->gpsParser.ProcessBlock((block_type_gps*)&blockSet->curBlock);
|
|---|
| 581 | }
|
|---|
| 582 | }
|
|---|
| 583 | }
|
|---|
| 584 |
|
|---|
| 585 | void ArcheopsFile::saveCurBlock() {
|
|---|
| 586 | blockSet->setBloc(blockSet->curBlock);
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | void ArcheopsFile::pushMark() { // push current file position, and "last" blocks
|
|---|
| 590 | fposStack.push(curPos);
|
|---|
| 591 | fposStack.push(peekPos);
|
|---|
| 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();
|
|---|
| 600 | peekPos = fposStack.top();
|
|---|
| 601 | fposStack.pop();
|
|---|
| 602 | curPos = fposStack.top();
|
|---|
| 603 | fposStack.pop();
|
|---|
| 604 | }
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 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 |
|
|---|
| 633 | #ifdef SWAP
|
|---|
| 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);
|
|---|
| 639 | if (lg < taille_maxi_block_archeops)
|
|---|
| 640 | bswap4(((char*)blk) + lg - 4);
|
|---|
| 641 | }
|
|---|
| 642 | #else
|
|---|
| 643 | void ArcheopsFile::swapEntete(block_type_modele* ) {
|
|---|
| 644 | }
|
|---|
| 645 | #endif
|
|---|
| 646 |
|
|---|
| 647 | #ifdef SWAP
|
|---|
| 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++)
|
|---|
| 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
|
|---|
| 673 | }
|
|---|
| 674 |
|
|---|
| 675 | }
|
|---|
| 676 | }
|
|---|
| 677 | #else
|
|---|
| 678 | void ArcheopsFile::swapContent(block_type_modele* ) {
|
|---|
| 679 | }
|
|---|
| 680 | #endif
|
|---|
| 681 |
|
|---|
| 682 | long ArcheopsFile::searchNextBlock(long pos) {
|
|---|
| 683 | static char* buffer = 0;
|
|---|
| 684 | static int4 debswp = debut_block_mesure;
|
|---|
| 685 | static int4 longmax = taille_maxi_block_archeops*20;
|
|---|
| 686 | if (!buffer) {
|
|---|
| 687 | buffer = new char[longmax];
|
|---|
| 688 | #ifdef SWAP
|
|---|
| 689 | bswap4(&debswp);
|
|---|
| 690 | #endif
|
|---|
| 691 | }
|
|---|
| 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
|
|---|
| 698 | #ifndef __DECCXX
|
|---|
| 699 | #define __unaligned
|
|---|
| 700 | #endif
|
|---|
| 701 | for (size_t i=4; i<read; i++) {
|
|---|
| 702 | if (*(__unaligned int4*)(buffer+i) == debswp) {
|
|---|
| 703 | cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
|
|---|
| 704 | return pos+i;
|
|---|
| 705 | }
|
|---|
| 706 | }
|
|---|
| 707 | pos += read;
|
|---|
| 708 | }
|
|---|
| 709 | cout << "cannot find block start" << endl;
|
|---|
| 710 | return -1;
|
|---|
| 711 | }
|
|---|
| 712 |
|
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 | static int mlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
|
|---|
| 717 |
|
|---|
| 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 |
|
|---|
| 748 | void ArcheopsFile::computeMJD(string const& fname) {
|
|---|
| 749 | //telemetrie : h99_04_29-15h36m22
|
|---|
| 750 | //enregistreur : ARKxxxxxx.dat, et MJD = samedi 17 juillet, 21h -> 1377.4
|
|---|
| 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++;
|
|---|
| 756 | if (!strncmp(p2, "ARK",3) || !strncmp(p2,"ark",3)) {
|
|---|
| 757 | rawMJD = 1377.4;
|
|---|
| 758 | } else {
|
|---|
| 759 | rawMJD = decodeMJD(p2);
|
|---|
| 760 | }
|
|---|
| 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 |
|
|---|
| 773 | int ArcheopsFile::getBoloBlockNum() {
|
|---|
| 774 | if (!lastBolo()) return -1;
|
|---|
| 775 | return numero_block(lastBolo());
|
|---|
| 776 | }
|
|---|
| 777 |
|
|---|
| 778 | int ArcheopsFile::getBoloCompBlockNum() {
|
|---|
| 779 | if (!lastBolo()) return -1;
|
|---|
| 780 | return numero_block(lastBoloComp());
|
|---|
| 781 | }
|
|---|
| 782 |
|
|---|
| 783 | int ArcheopsFile::getReglageBlockNum() {
|
|---|
| 784 | if (!lastReglage()) return -1;
|
|---|
| 785 | return numero_block(lastReglage());
|
|---|
| 786 | }
|
|---|
| 787 |
|
|---|
| 788 | int ArcheopsFile::getDilutionBlockNum() {
|
|---|
| 789 | if (!lastDilution()) return -1;
|
|---|
| 790 | return numero_block(lastDilution());
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 |
|
|---|
| 794 | int ArcheopsFile::getSSTBlockNum() {
|
|---|
| 795 | if (!lastSST()) return -1;
|
|---|
| 796 | return numero_block(lastSST());
|
|---|
| 797 | }
|
|---|
| 798 |
|
|---|
| 799 | int ArcheopsFile::getSSTCompBlockNum() {
|
|---|
| 800 | if (!lastSST()) return -1;
|
|---|
| 801 | return numero_block(lastSSTComp());
|
|---|
| 802 | }
|
|---|
| 803 |
|
|---|
| 804 |
|
|---|
| 805 |
|
|---|
| 806 | int ArcheopsFile::getGyroBlockNum() {
|
|---|
| 807 | if (!lastGyro()) return -1;
|
|---|
| 808 | return numero_block(lastGyro());
|
|---|
| 809 | }
|
|---|
| 810 |
|
|---|
| 811 |
|
|---|
| 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
|
|---|
| 822 | if (!lastGPS()) return -9.e99;
|
|---|
| 823 | return blockSet->gpsParser.getUTC();
|
|---|
| 824 | }
|
|---|
| 825 |
|
|---|
| 826 | double ArcheopsFile::getGPSMJD() { // modified julian day du dernier bloc GPS, JD - 2450000
|
|---|
| 827 | double t = getGPSUTC()/86400. - 0.5;
|
|---|
| 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
|
|---|
| 837 | if (!lastGPS()) return -9.e99;
|
|---|
| 838 | return blockSet->gpsParser.getLatitude();
|
|---|
| 839 | }
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 | double ArcheopsFile::getGPSLong() { // degres, + = EST
|
|---|
| 843 | if (!lastGPS()) return -9.e99;
|
|---|
| 844 | return blockSet->gpsParser.getLongitude();
|
|---|
| 845 | }
|
|---|
| 846 |
|
|---|
| 847 | double ArcheopsFile::getGPSAlt() { // meters from sea level
|
|---|
| 848 | if (!lastGPS()) return -9.e99;
|
|---|
| 849 | return blockSet->gpsParser.getAltitude();
|
|---|
| 850 | }
|
|---|
| 851 |
|
|---|
| 852 | bool ArcheopsFile::hasGPSTime() {
|
|---|
| 853 | if (!lastGPS()) return false;
|
|---|
| 854 | // return blockSet->gpsParser.hasGPSTime();
|
|---|
| 855 | return blockSet->gpsParser.hasTime();
|
|---|
| 856 | }
|
|---|
| 857 |
|
|---|
| 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 |
|
|---|
| 869 | // Bolo
|
|---|
| 870 | #define val_DS(j,i) (blk->data_bolo[j][i]&0x1fffff)
|
|---|
| 871 |
|
|---|
| 872 |
|
|---|
| 873 | double ArcheopsFile::getBoloRawMuV(int ibolo, int imesure) { // microvolts bruts
|
|---|
| 874 | block_type_bolo* blk = imesure >= 0 ? lastBolo() : llastBolo();
|
|---|
| 875 | if (imesure < 0) imesure += nEchBlock();
|
|---|
| 876 | block_type_reglage* reglage = lastReglage();
|
|---|
| 877 | block_type_param* param = lastParam();
|
|---|
| 878 | if (!blk) return 0;
|
|---|
| 879 | if (!reglage) return 0;
|
|---|
| 880 | if (!param) return 0;
|
|---|
| 881 |
|
|---|
| 882 | int s = imesure % 2 ? 1 : -1;
|
|---|
| 883 |
|
|---|
| 884 | return s*bolo_muV(¶m->param, ®lage->reglage, val_DS(ibolo,imesure), ibolo);
|
|---|
| 885 | }
|
|---|
| 886 |
|
|---|
| 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 | }
|
|---|
| 900 | block_type_reglage* reglage = lastReglage();
|
|---|
| 901 | block_type_param* param = lastParam();
|
|---|
| 902 | if (!reglage) return 0;
|
|---|
| 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.;
|
|---|
| 907 |
|
|---|
| 908 | return noise;
|
|---|
| 909 | }
|
|---|
| 910 |
|
|---|
| 911 |
|
|---|
| 912 |
|
|---|
| 913 | def_gains
|
|---|
| 914 |
|
|---|
| 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;
|
|---|
| 918 | }
|
|---|
| 919 |
|
|---|
| 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;
|
|---|
| 945 | }
|
|---|
| 946 |
|
|---|
| 947 | /*
|
|---|
| 948 | double ArcheopsFile::getBoloMuV2(int ibolo, int imesure) { // microvolts, filtre
|
|---|
| 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;
|
|---|
| 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 | }
|
|---|
| 962 | for (int i=1; i<=n; i++) {
|
|---|
| 963 | double x = -i;
|
|---|
| 964 | double y = s*(getBoloRawMuV(ibolo, imesure-i+1) - getBoloRawMuV(ibolo, imesure-i))/2;
|
|---|
| 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;
|
|---|
| 974 | double y = getBoloRawMuV(ibolo, imesure);
|
|---|
| 975 | y = y-s*b;
|
|---|
| 976 | return y;
|
|---|
| 977 | }
|
|---|
| 978 | */
|
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 | double ArcheopsFile::getGainAmpli(int ibolo) {
|
|---|
| 982 | return gain_ampli(lastReglage()->reglage.bolo[ibolo]);
|
|---|
| 983 | }
|
|---|
| 984 |
|
|---|
| 985 |
|
|---|
| 986 | double ArcheopsFile::getDACV(int ibolo) {
|
|---|
| 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);
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | double ArcheopsFile::getDACI(int ibolo) {
|
|---|
| 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);
|
|---|
| 1000 | }
|
|---|
| 1001 |
|
|---|
| 1002 | double ArcheopsFile::getBoloMuV2T(int ibolo, int imesure) {
|
|---|
| 1003 | return getDACV(ibolo) - getBoloMuV2(ibolo, imesure) ;
|
|---|
| 1004 | }
|
|---|
| 1005 |
|
|---|
| 1006 | double ArcheopsFile::getBoloRes(int ibolo, int imesure) {
|
|---|
| 1007 | double i = getDACI(ibolo); // microAmps
|
|---|
| 1008 | double v = getBoloMuV2T(ibolo, imesure); // microVolts
|
|---|
| 1009 | double r = v/i; // Ohms
|
|---|
| 1010 | return r;
|
|---|
| 1011 | }
|
|---|
| 1012 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 1039 | // SST, gyros...
|
|---|
| 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 | }
|
|---|
| 1048 |
|
|---|
| 1049 | long ArcheopsFile::getSSTRawSignal(int idiode, int imesure) {
|
|---|
| 1050 | return blockSet->sstHandler.getRawSignal(imesure, idiode);
|
|---|
| 1051 | }
|
|---|
| 1052 |
|
|---|
| 1053 | double ArcheopsFile::getSSTSignalCN(int idiode, int imesure) {
|
|---|
| 1054 | return getSSTRawSignalCN(SSTHandler::getDiodPermut(idiode),imesure);
|
|---|
| 1055 | }
|
|---|
| 1056 |
|
|---|
| 1057 | double ArcheopsFile::getSSTRawSignalCN(int ichannel, int imesure) {
|
|---|
| 1058 | // Si pas bloc comprime -> 0
|
|---|
| 1059 | if (lastSSTComp() == NULL) return 0;
|
|---|
| 1060 | if (numero_block(lastSSTComp()) != numero_block(lastSST())) return 0;
|
|---|
| 1061 |
|
|---|
| 1062 | // Attention, on ne transmet pas les canaux 0 et 4....
|
|---|
| 1063 | if (ichannel == 0 || ichannel == 4) return 0;
|
|---|
| 1064 | int i = ichannel - 1;
|
|---|
| 1065 | if (i >= 4) i--;
|
|---|
| 1066 | unsigned int4* data = lastSSTComp()->sst[i];
|
|---|
| 1067 | // Les deux premieres valeurs sont codees directement...
|
|---|
| 1068 | if (imesure<2) return 0;
|
|---|
| 1069 | int iExp = (imesure-2)/7 + 1;
|
|---|
| 1070 | int expo = data[iExp] & 0xf;
|
|---|
| 1071 | int noise = 1 << expo;
|
|---|
| 1072 | return noise/2.;
|
|---|
| 1073 | }
|
|---|
| 1074 |
|
|---|
| 1075 |
|
|---|
| 1076 |
|
|---|
| 1077 | double ArcheopsFile::getSSTStarZ(int istar, int imesure) {
|
|---|
| 1078 | return blockSet->sstHandler.getStarZ(imesure+getSSTBlockNum()*nb_per_block*2, istar);
|
|---|
| 1079 | }
|
|---|
| 1080 |
|
|---|
| 1081 | double ArcheopsFile::getSSTStarF(int istar, int imesure) {
|
|---|
| 1082 | return blockSet->sstHandler.getStarF(imesure+getSSTBlockNum()*nb_per_block*2, istar);
|
|---|
| 1083 | }
|
|---|
| 1084 |
|
|---|
| 1085 | double ArcheopsFile::getSSTStarT(int istar, int imesure) {
|
|---|
| 1086 | return blockSet->sstHandler.getStarTime(imesure+getSSTBlockNum()*nb_per_block*2, istar);
|
|---|
| 1087 | }
|
|---|
| 1088 |
|
|---|
| 1089 | int ArcheopsFile::getNumbStar(int imesure) {
|
|---|
| 1090 | return blockSet->sstHandler.getNumbStar(imesure+getSSTBlockNum()*nb_per_block*2);
|
|---|
| 1091 | }
|
|---|
| 1092 |
|
|---|
| 1093 | long ArcheopsFile::getGyroRaw(int igyro, int imesure) {
|
|---|
| 1094 | return blockSet->gyroHandler.getRawSignal(imesure, igyro);
|
|---|
| 1095 | }
|
|---|
| 1096 |
|
|---|
| 1097 | double ArcheopsFile::getGyroTens(int igyro, int imesure) {
|
|---|
| 1098 | return blockSet->gyroHandler.getSignal(imesure, igyro);
|
|---|
| 1099 | }
|
|---|
| 1100 |
|
|---|
| 1101 | double ArcheopsFile::getGyroSpeed(int igyro, int imesure) {
|
|---|
| 1102 | return blockSet->gyroHandler.getSpeed(imesure, igyro);
|
|---|
| 1103 | }
|
|---|
| 1104 |
|
|---|
| 1105 |
|
|---|
| 1106 |
|
|---|
| 1107 |
|
|---|
| 1108 |
|
|---|
| 1109 | // $CHECK$ TBD
|
|---|
| 1110 |
|
|---|
| 1111 |
|
|---|
| 1112 | double ArcheopsFile::getAzimut(int /*imesure*/) {return 0;}
|
|---|
| 1113 | double ArcheopsFile::getPendDirect(int /*imesure*/) {return 0;}
|
|---|
| 1114 | double ArcheopsFile::getPendOrth(int /*imesure*/) {return 0;}
|
|---|
| 1115 | double ArcheopsFile::getAlphaAxis(int /*imesure*/) {return 0;}
|
|---|
| 1116 | double ArcheopsFile::getDeltaAxis(int /*imesure*/) {return 0;}
|
|---|