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