// archeopsfile.cc // Eric Aubourg CEA/DAPNIA/SPP juillet 1999 #define utilitaires_de_block_archeops #include "archeopsfile.h" #include "gyrohandler.h" extern "C" { #include "compress.h" #include "arcunit.h" } #include // BlockSet is the current "state" of the file reader automate. // It contains the last blocks of each kind, the current block and // the look-ahead block. class BlockSet { public: BlockSet(); BlockSet(BlockSet const&); ~BlockSet(); void setBloc(block_type_modele const& blk); void setRawBloc(block_type_modele const& blk); block_type_param* lastParam; block_type_journal* lastJournal; block_type_reglage* lastReglage; block_type_dilution* lastDilution; block_type_gps* lastGPS; block_type_une_periode* lastUnePeriode; block_type_synchro_sol* lastSynchroSol; block_type_pointage_sol* lastPointageSol; block_type_bolo* lastBolo; // can be uncompressed bolo_comp block_type_bolo* llastBolo; block_type_gyro* lastGyro; block_type_sst* lastSST; block_type_bolo_comprime* lastBoloComp; // can be uncompressed bolo_comp block_type_gyro_comprime* lastGyroComp; block_type_sst_comprime* lastSSTComp; block_type_modele curBlock; block_type_modele peekBlock; SSTHandler sstHandler; GyroHandler gyroHandler; GPSParser gpsParser; }; BlockSet::BlockSet() { lastParam = NULL; lastJournal = NULL; lastReglage = NULL; lastDilution = NULL; lastGPS = NULL; lastUnePeriode = NULL; lastSynchroSol = NULL; lastPointageSol= NULL; lastBolo = NULL; llastBolo = NULL; lastGyro = NULL; lastSST = NULL; lastBoloComp = NULL; lastGyroComp = NULL; lastSSTComp = NULL; memset(&curBlock,0,sizeof(block_type_modele)); memset(&peekBlock,0,sizeof(block_type_modele)); } BlockSet::~BlockSet() { delete lastParam; delete lastJournal; delete lastReglage; delete lastDilution; delete lastGPS; delete lastUnePeriode; delete lastSynchroSol; delete lastPointageSol; delete lastBolo; delete llastBolo; delete lastGyro; delete lastSST; delete lastBoloComp; delete lastGyroComp; delete lastSSTComp; } BlockSet::BlockSet(BlockSet const& x) : sstHandler(x.sstHandler), gyroHandler(x.gyroHandler) { lastParam = NULL; lastJournal = NULL; lastReglage = NULL; lastDilution = NULL; lastGPS = NULL; lastUnePeriode = NULL; lastSynchroSol = NULL; lastPointageSol= NULL; lastBolo = NULL; llastBolo = NULL; lastGyro = NULL; lastSST = NULL; lastBoloComp = NULL; lastGyroComp = NULL; lastSSTComp = NULL; if (x.lastParam) { lastParam = new block_type_param; *lastParam = *x.lastParam; } if (x.lastJournal) { lastJournal = new block_type_journal; *lastJournal = *x.lastJournal; } if (x.lastReglage) { lastReglage = new block_type_reglage; *lastReglage = *x.lastReglage; } if (x.lastDilution) { lastDilution = new block_type_dilution; *lastDilution = *x.lastDilution; } if (x.lastGPS) { lastGPS = new block_type_gps; *lastGPS = *x.lastGPS; } if (x.lastUnePeriode) { lastUnePeriode = new block_type_une_periode; *lastUnePeriode = *x.lastUnePeriode; } if (x.lastSynchroSol) { lastSynchroSol = new block_type_synchro_sol; *lastSynchroSol = *x.lastSynchroSol; } if (x.lastPointageSol) { lastPointageSol = new block_type_pointage_sol; *lastPointageSol = *x.lastPointageSol; } if (x.lastBolo) { lastBolo = new block_type_bolo; *lastBolo = *x.lastBolo; } if (x.llastBolo) { llastBolo = new block_type_bolo; *llastBolo = *x.llastBolo; } if (x.lastGyro) { lastGyro = new block_type_gyro; *lastGyro = *x.lastGyro; } if (x.lastSST) { lastSST = new block_type_sst; *lastSST = *x.lastSST; } if (x.lastBoloComp) { lastBoloComp = new block_type_bolo_comprime; *lastBoloComp = *x.lastBoloComp; } if (x.lastGyroComp) { lastGyroComp = new block_type_gyro_comprime; *lastGyroComp = *x.lastGyroComp; } if (x.lastSSTComp) { lastSSTComp = new block_type_sst_comprime; *lastSSTComp = *x.lastSSTComp; } memcpy(&curBlock,&x.curBlock,sizeof(block_type_modele)); memcpy(&peekBlock,&x.peekBlock,sizeof(block_type_modele)); } void BlockSet::setBloc(block_type_modele const& blk) { int kind = type_block(&blk); switch (kind) { case block_param: if (!lastParam) lastParam = new block_type_param; memcpy(lastParam, &blk, sizeof(block_type_param)); // Les fichiers fournis contiennent des valeurs debiles... if (lastParam->param.n_max_bolo < 0) lastParam->param.n_max_bolo = nb_max_bolo; if (lastParam->param.n_per_block < 0) lastParam->param.n_per_block = nb_per_block; if (lastParam->param.n_max_mes_per < 0) lastParam->param.n_max_mes_per = nb_max_mes_per; break; case block_journal: if (!lastJournal) lastJournal = new block_type_journal; memcpy(lastJournal, &blk, sizeof(block_type_journal)); break; case block_reglage: if (!lastReglage) lastReglage = new block_type_reglage; memcpy(lastReglage, &blk, sizeof(block_type_reglage)); break; case block_dilution: if (!lastDilution) lastDilution = new block_type_dilution; memcpy(lastDilution, &blk, sizeof(block_type_dilution)); break; case block_gps: if (!lastGPS) lastGPS = new block_type_gps; memcpy(lastGPS, &blk, sizeof(block_type_gps)); break; case block_une_periode: if (!lastUnePeriode) lastUnePeriode = new block_type_une_periode; memcpy(lastUnePeriode, &blk, sizeof(block_type_une_periode)); break; case block_synchro_sol: if (!lastSynchroSol) lastSynchroSol = new block_type_synchro_sol; memcpy(lastSynchroSol, &blk, sizeof(block_type_synchro_sol)); break; case block_pointage_sol: if (!lastPointageSol) lastPointageSol = new block_type_pointage_sol; memcpy(lastPointageSol, &blk, sizeof(block_type_pointage_sol)); break; case block_bolo: if (!lastBolo) lastBolo = new block_type_bolo; else if (!llastBolo) { llastBolo = new block_type_bolo; } if (llastBolo) { memcpy(llastBolo, lastBolo, sizeof(block_type_bolo)); } memcpy(lastBolo, &blk, sizeof(block_type_bolo)); break; case block_gyro: if (!lastGyro) lastGyro = new block_type_gyro; memcpy(lastGyro, &blk, sizeof(block_type_gyro)); break; case block_sst: if (!lastSST) lastSST = new block_type_sst; memcpy(lastSST, &blk, sizeof(block_type_sst)); break; } } void BlockSet::setRawBloc(block_type_modele const& blk) { int kind = type_block(&blk); switch (kind) { case block_bolo_comprime: if (!lastBoloComp) lastBoloComp = new block_type_bolo_comprime; memcpy(lastBoloComp, &blk, sizeof(block_type_bolo_comprime)); break; case block_gyro_comprime: if (!lastGyroComp) lastGyroComp = new block_type_gyro_comprime; memcpy(lastGyroComp, &blk, sizeof(block_type_gyro_comprime)); break; case block_sst_comprime: if (!lastSSTComp) lastSSTComp = new block_type_sst_comprime; memcpy(lastSSTComp, &blk, sizeof(block_type_sst_comprime)); break; } } ArcheopsFile::ArcheopsFile(string const& fname) { f = fopen(fname.c_str(), "rb"); setvbuf(f, NULL, _IOFBF, 1024L*1024L); fn = fname; if (!f) throw ArchExc("file not found"); fseek(f,0,SEEK_END); fLen = ftell(f); curPos = -1; peekPos = -1; curKind = -1; curRawKind = -1; blockSet = new BlockSet; utcOffset=2; computeMJD(fname); } ArcheopsFile::ArcheopsFile(ArcheopsFile const& x) { blockSet = x.blockSet ? new BlockSet(*x.blockSet) : NULL; fposStack = x.fposStack; stack tmp; ArcheopsFile& y = (ArcheopsFile&) x; while (!y.blockStack.empty()) { tmp.push(y.blockStack.top()); y.blockStack.pop(); } while (!tmp.empty()) { y.blockStack.push(tmp.top()); blockStack.push(new BlockSet(*tmp.top())); tmp.pop(); } //curBlock = x.curBlock; curKind = x.curKind; curRawKind = x.curRawKind; curPos = x.curPos; peekPos = x.peekPos; fLen = x.fLen; fn = x.fn; f = fopen(fn.c_str(), "rb"); setvbuf(f, NULL, _IOFBF, 1024L*1024L); rawMJD = x.rawMJD; startMJD = x.startMJD; utcOffset = x.utcOffset; } ArcheopsFile::~ArcheopsFile() { if (f) fclose(f); delete blockSet; while (!blockStack.empty()) { delete blockStack.top(); blockStack.pop();} } void ArcheopsFile::grabLastBlocs(ArcheopsFile const& oldFile) { delete blockSet; blockSet = new BlockSet(*oldFile.blockSet); //curBlock = oldFile.curBlock; //peekBlock = oldFile.peekBlock; if (peekPos>0) peekPos = 0; setUTCOffset(oldFile.utcOffset); } def_nom_block def_long_block bool ArcheopsFile::nextBlock() { // si pas de peek, alors en lire un pour commencer... if (peekPos<0) { peekPos=0; if (!nextBlock()) return false; } block_type_modele* curBlock=currentBlock(); block_type_modele* peekBlock=aheadBlock(); memcpy(curBlock, peekBlock, sizeof(block_type_modele)); curPos = peekPos; while (true) { if (peekPos+12 > fLen) return false; // fin de fichier fseek(f,peekPos,SEEK_SET); // aller en peekPos size_t read = fread(peekBlock,1,sizeof(block_type_modele),f); swapEntete(peekBlock); if (read < longueur_block(peekBlock) || type_block(peekBlock) < 0 || type_block(peekBlock) > 19 || longueur_block(peekBlock) != long_block[type_block(peekBlock)]) { cout << "invalid block, bad type or length" << endl; memset(peekBlock, 0, sizeof(block_type_modele)); // don't keep trash... peekPos = searchNextBlock(peekPos); if (peekPos<0) return false; continue; } swapContent(peekBlock); if (verifie_block(peekBlock) != block_correct) { cout << "invalid block " << numero_block(peekBlock); if (!fixBlock(peekBlock)) { cout << " -- skipped" << endl; peekPos += longueur_block(peekBlock); // la longueur doit etre ok... continue; } else { cout << " -- fixed" << endl; break; } } break; // tout semble bon pour ce bloc... } peekPos += longueur_block(peekBlock); // on suppose que longueur OK... if (curPos < 0) { curPos = 0; return true; } if (curBlock->debut != 0) { curRawKind = curKind = type_block(curBlock); postProcessBlock(); saveCurBlock(); } else { curRawKind = curKind = -1; } return true; } bool ArcheopsFile::nextBlock(long mask) { if (!mask) return false; while (1) { if (!nextBlock()) return false; if (( 1 << curRawKind) & mask) return true; } } bool ArcheopsFile::fixBlock(block_type_modele* ) { return false; } int ArcheopsFile::blockKind() { return curKind; } int ArcheopsFile::blockRawKind() { return curRawKind; } int ArcheopsFile::blockNum() { return numero_block(currentBlock()); } #define bitmot 24 // nb de bit horloge dans un mot ADC double ArcheopsFile::perEchant() { // periode d'echantillonage pour le dernier bloc reglage double p,f1,f2,f3; int pp; if (!lastReglage()) return -1; pp=lastReglage()->reglage.horloge.periode; p=pp/5.; f1=1000/p;f2=f1/bitmot;f3=f2*1000./(double)(lastReglage()->reglage.horloge.nb_mesures); return 0.5/f3; // 2 fois la frequence de modulation } double ArcheopsFile::perBlock() { // duree (en secondes) correspondant a un bloc bolo return perEchant() * (double)lastParam()->param.n_per_block*2.; } int ArcheopsFile::nEchBlock() { // Nb d'echantillons dans un bloc return lastParam()->param.n_per_block*2; } string ArcheopsFile::blockKdName() { return nom_block[curKind]; } string ArcheopsFile::blockRawKdName() { return nom_block[curRawKind]; } block_type_modele* ArcheopsFile::currentBlock() { //if (curPos<0) return NULL; return &blockSet->curBlock; } block_type_modele* ArcheopsFile::aheadBlock() { //if (peekPos<0) return NULL; return &blockSet->peekBlock; } bool ArcheopsFile::sameBlockNumAhead() { if (curPos<0) return false; return (numero_block(&blockSet->curBlock) == numero_block(&blockSet->peekBlock)); } block_type_param* ArcheopsFile::lastParam() { return blockSet->lastParam; } block_type_journal* ArcheopsFile::lastJournal() { return blockSet->lastJournal; } block_type_reglage* ArcheopsFile::lastReglage() { return blockSet->lastReglage; } block_type_dilution* ArcheopsFile::lastDilution() { return blockSet->lastDilution; } block_type_gps* ArcheopsFile::lastGPS() { return blockSet->lastGPS; } block_type_une_periode* ArcheopsFile::lastUnePeriode() { return blockSet->lastUnePeriode; } block_type_synchro_sol* ArcheopsFile::lastSynchroSol() { return blockSet->lastSynchroSol; } block_type_pointage_sol* ArcheopsFile::lastPointageSol() { return blockSet->lastPointageSol; } block_type_bolo* ArcheopsFile::lastBolo() { return blockSet->lastBolo; } block_type_bolo* ArcheopsFile::llastBolo() { return blockSet->llastBolo; } block_type_gyro* ArcheopsFile::lastGyro() { return blockSet->lastGyro; } block_type_sst* ArcheopsFile::lastSST() { return blockSet->lastSST; } block_type_bolo_comprime* ArcheopsFile::lastBoloComp() { return blockSet->lastBoloComp; } block_type_gyro_comprime* ArcheopsFile::lastGyroComp() { return blockSet->lastGyroComp; } block_type_sst_comprime* ArcheopsFile::lastSSTComp() { return blockSet->lastSSTComp; } void ArcheopsFile::forceBlock(block_type_modele* blk) { blockSet->setBloc(*blk); } #define place_paquet(i,j) ((i/8) * 24 + j*8 + (i%8) ) void ArcheopsFile::postProcessBlock() { switch (curKind) { case block_bolo_comprime: { blockSet->setRawBloc(blockSet->curBlock); block_type_bolo blk2; block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &blockSet->curBlock; #if version_num <= 25 for(int j=0;jdata_bolo[j],blk2.data_bolo[j],nb_per_block*2); } #else block_type_param* param = lastParam(); if (!param) return; int jc=0;for(int j=0;jparam.bolo[j].bolo_code_util==bolo_normal_transmis) && (jcdata_bolo[jc],blk2.data_bolo[j],nb_per_block*2); jc++; } else { memset(blk2.data_bolo[j], 0, nb_per_block*2*sizeof(int4)); } } #endif valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk)); memcpy(&blockSet->curBlock,&blk2,sizeof(blk2)); curKind = block_bolo; break; } case block_sst_comprime: { blockSet->setRawBloc(blockSet->curBlock); if (!blockSet->sstHandler.NeedBlocks()) break; // inutile de decompresser block_type_sst blk2; block_type_sst_comprime* blk = (block_type_sst_comprime*) &blockSet->curBlock; for (int j=0; j<18; j++) for (int i=0; isst[jc],(int4*)sst_vrai,nb_per_block*2); for (int k=0;k> 4) & 0xf; b0 = (sst_vrai[k] >> 8) & 0xf; a=place_paquet(j,0); blk2.sst[k][a/8] |= (b0 << (a%8)*4); a=place_paquet(j,1); blk2.sst[k][a/8] |= (b1 << (a%8)*4); a=place_paquet(j,2); blk2.sst[k][a/8] |= (b2 << (a%8)*4); } jc++; } } valide_block((block_type_modele*)&blk2,block_sst,numero_block(blk)); memcpy(&blockSet->curBlock,&blk2,sizeof(blk2)); curKind = block_sst; // cout << "process " << numero_block(&blockSet->curBlock) << "\n"; blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock); break; } case block_sst : { // cout << "process " << numero_block(&blockSet->curBlock) << "\n"; blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock); } case block_gyro : { blockSet->gyroHandler.ProcessBlock((block_type_gyro*)&blockSet->curBlock); } case block_gps : { blockSet->gpsParser.ProcessBlock((block_type_gps*)&blockSet->curBlock); } } } void ArcheopsFile::saveCurBlock() { blockSet->setBloc(blockSet->curBlock); } void ArcheopsFile::pushMark() { // push current file position, and "last" blocks fposStack.push(curPos); fposStack.push(peekPos); blockStack.push(new BlockSet(*blockSet)); } void ArcheopsFile::popMark() { // pops last file position and "last" blocks if (! blockStack.empty()) { delete blockSet; blockSet = blockStack.top(); blockStack.pop(); peekPos = fposStack.top(); fposStack.pop(); curPos = fposStack.top(); fposStack.pop(); } } typedef unsigned int4 uint_4; typedef unsigned short uint_2; static inline void bswap4(void* p) { uint_4 tmp = *(uint_4*)p; *(uint_4*)p = ((tmp >> 24) & 0x000000FF) | ((tmp >> 8) & 0x0000FF00) | ((tmp & 0x0000FF00) << 8) | ((tmp & 0x000000FF) << 24); } static inline void bswap2(void* p) { uint_2 tmp = *(uint_2*)p; *(uint_2*)p = ((tmp >> 8) & 0x00FF) | ((tmp & 0x00FF) << 8); } #ifdef __DECCXX #define SWAP #endif #if defined(Linux) || defined(linux) #define SWAP #endif #ifdef SWAP void ArcheopsFile::swapEntete(block_type_modele* blk) { bswap4(&(blk->debut)); bswap4(&(blk->code1)); bswap4(&(blk->code2)); long lg = longueur_block(blk); if (lg < taille_maxi_block_archeops) bswap4(((char*)blk) + lg - 4); } #else void ArcheopsFile::swapEntete(block_type_modele* ) { } #endif #ifdef SWAP void ArcheopsFile::swapContent(block_type_modele* blk) { int typ = type_block(blk); if (typ == block_gps) return; // char only, no swap if (typ == block_une_periode) { // une_periode, des shorts block_type_une_periode* b = (block_type_une_periode*) blk; for (int i=0; ibol_per[i][j]); return; } for (int i=0; imot + i); // On deswappe ce qui ne devait pas etre swappe... switch (typ) { case block_param: { block_type_param* b = (block_type_param*) blk; for (int i=0; iparam.bolo[i].bolo_nom[4*j]); #else bswap4(&b->param.nom_coef[i].bolo_nom[4*j]); #endif } } } #else void ArcheopsFile::swapContent(block_type_modele* ) { } #endif long ArcheopsFile::searchNextBlock(long pos) { static char* buffer = 0; static int4 debswp = debut_block_mesure; static int4 longmax = taille_maxi_block_archeops*20; if (!buffer) { buffer = new char[longmax]; #ifdef SWAP bswap4(&debswp); #endif } size_t read = longmax; while (read == longmax) { fseek(f,pos,SEEK_SET); read = fread(buffer,1,longmax,f); //if (read unaligned, but can lose bytes in flight recorder #ifndef __DECCXX #define __unaligned #endif for (size_t i=4; ip2) return -1; m = atoi(p); p+=3; if (p>p2) return -1; d = atoi(p); p+=3; if (pp2) return -1; mm = atoi(p); p+=3; if (p>p2) return -1; ss = atoi(p); } else { hh=mm=ss=0; } if (y<50) y += 100; // 1. depuis 0/1/97 minuit double mjd = (int) (365.25 * (y-97)); for (int i=0; i 2) mjd++; mjd += d; mjd += hh/24. + mm/24./60. + ss/24./60./60; mjd += 448.5; // 0/1/97 minuit return mjd; } void ArcheopsFile::computeMJD(string const& fname) { //telemetrie : h99_04_29-15h36m22 //enregistreur : ARKxxxxxx.dat, et MJD = samedi 17 juillet, 21h -> 1377.4 char const* p = fname.c_str(); char const* p2 = p + fname.length()-1; while (*p2 != ':' && *p2 != '/' && p2 != p) p2--; if (*p2 == ':' || *p2 == '/') p2++; if (*p2 == 'h') p2++; if (!strncmp(p2, "ARK",3) || !strncmp(p2,"ark",3)) { rawMJD = 1377.4; } else { rawMJD = decodeMJD(p2); } startMJD = rawMJD - utcOffset/24.; } void ArcheopsFile::setUTCOffset(int UTCOffset) { utcOffset = UTCOffset; startMJD = rawMJD - utcOffset/24.; } double ArcheopsFile::getStartMJD() { return startMJD; } int ArcheopsFile::getBoloBlockNum() { if (!lastBolo()) return -1; return numero_block(lastBolo()); } int ArcheopsFile::getBoloCompBlockNum() { if (!lastBolo()) return -1; return numero_block(lastBoloComp()); } int ArcheopsFile::getReglageBlockNum() { if (!lastReglage()) return -1; return numero_block(lastReglage()); } int ArcheopsFile::getDilutionBlockNum() { if (!lastDilution()) return -1; return numero_block(lastDilution()); } int ArcheopsFile::getSSTBlockNum() { if (!lastSST()) return -1; return numero_block(lastSST()); } int ArcheopsFile::getSSTCompBlockNum() { if (!lastSST()) return -1; return numero_block(lastSSTComp()); } int ArcheopsFile::getGyroBlockNum() { if (!lastGyro()) return -1; return numero_block(lastGyro()); } // GPS // $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z, int ArcheopsFile::getGPSBlockNum() { if (!lastGPS()) return -1; return numero_block(lastGPS()); } double ArcheopsFile::getGPSUTC() { // en secondes depuis minuit UTC jour courant if (!lastGPS()) return -9.e99; return blockSet->gpsParser.getUTC(); } double ArcheopsFile::getGPSMJD() { // modified julian day du dernier bloc GPS, JD - 2450000 double t = getGPSUTC()/86400. - 0.5; if (t<0) return t; if (t > (startMJD - int(startMJD))) { return int(startMJD) + t; } else { return int(startMJD) + 1. + t; } } double ArcheopsFile::getGPSLat() { // degres, + = NORD if (!lastGPS()) return -9.e99; return blockSet->gpsParser.getLatitude(); } double ArcheopsFile::getGPSLong() { // degres, + = EST if (!lastGPS()) return -9.e99; return blockSet->gpsParser.getLongitude(); } double ArcheopsFile::getGPSAlt() { // meters from sea level if (!lastGPS()) return -9.e99; return blockSet->gpsParser.getAltitude(); } bool ArcheopsFile::hasGPSTime() { if (!lastGPS()) return false; // return blockSet->gpsParser.hasGPSTime(); return blockSet->gpsParser.hasTime(); } bool ArcheopsFile::hasGPSPos() { if (!lastGPS()) return false; return blockSet->gpsParser.hasPosition(); } bool ArcheopsFile::hasGPSAlt() { if (!lastGPS()) return false; return blockSet->gpsParser.hasAltitude(); } // Bolo #define val_DS(j,i) (blk->data_bolo[j][i]&0x1fffff) double ArcheopsFile::getBoloRawMuV(int ibolo, int imesure) { // microvolts bruts block_type_bolo* blk = imesure >= 0 ? lastBolo() : llastBolo(); if (imesure < 0) imesure += nEchBlock(); block_type_reglage* reglage = lastReglage(); block_type_param* param = lastParam(); if (!blk) return 0; if (!reglage) return 0; if (!param) return 0; int s = imesure % 2 ? 1 : -1; return s*bolo_muV(¶m->param, ®lage->reglage, val_DS(ibolo,imesure), ibolo); } double ArcheopsFile::getBoloRawMuVCN(int ibolo, int imesure) { // Si pas bloc comprime -> 1 bit int lastbit = 1; if (!(lastBoloComp() == NULL) && (numero_block(lastBoloComp()) != numero_block(lastBolo()))) { unsigned int4* data = lastBoloComp()->data_bolo[ibolo]; // Les deux premieres valeurs sont codees directement... if (imesure>=2) { int iExp = (imesure-2)/4 + 1; int expo = data[iExp] & 0xf; lastbit = 1 << expo; } } block_type_reglage* reglage = lastReglage(); block_type_param* param = lastParam(); if (!reglage) return 0; if (!param) return 0; double noise = ( bolo_muV(¶m->param, ®lage->reglage, lastbit, ibolo) - bolo_muV(¶m->param, ®lage->reglage, 0, ibolo)) /2.; return noise; } def_gains double ArcheopsFile::getBoloMuV(int ibolo, int imesure) { // microvolts, filtre avec filtre carre double y = (getBoloRawMuV(ibolo, imesure-1) + getBoloRawMuV(ibolo, imesure))/2.; return y; } double ArcheopsFile::getBoloMuV2(int ibolo, int imesure) { // microvolts, filtre // On commence par trouver la valeur d'offset, en fittant une droite sur les soustractions if (!lastBolo() || !llastBolo()) return 0; //block_type_reglage* reglage = lastReglage(); //block_type_param* param = lastParam(); //if (!reglage) return 0; //if (!param) return 0; double sumx=0, sumy=0, sumxy=0, sumx2=0; int n=20; int s = imesure % 2 ? 1 : -1; for (int i=1; i<=n; i++) { double x = -i; double y = s*(getBoloRawMuV(ibolo, imesure-i+1) - getBoloRawMuV(ibolo, imesure-i))/2; s = -s; sumx += x; sumy += y; sumxy += x*y; sumx2 += x*x; } double a = (sumxy/n - (sumx/n)*(sumy/n)) / (sumx2/n - (sumx/n)*(sumx/n)); double b = (sumy/n) - a*(sumx/n); s = imesure % 2 ? 1 : -1; double y = getBoloRawMuV(ibolo, imesure); y = y-s*b; return y; } /* double ArcheopsFile::getBoloMuV2(int ibolo, int imesure) { // microvolts, filtre // On commence par trouver la valeur d'offset, en fittant une droite sur les soustractions if (!lastBolo() || !llastBolo()) return 0; double sumx=0, sumy=0, sumxy=0, sumx2=0; int n=20; int s = (imesure-n) % 2 ? 1 : -1; static double* data = NULL; if (!data) data = new double[n+1]; for (int i=0; i<=n; i++) { data[i] = getBoloRawMuV(ibolo, imesure-n+i); } for (int i=0; i<=n; i++) { } for (int i=1; i<=n; i++) { double x = -i; double y = s*(getBoloRawMuV(ibolo, imesure-i+1) - getBoloRawMuV(ibolo, imesure-i))/2; s = -s; sumx += x; sumy += y; sumxy += x*y; sumx2 += x*x; } double a = (sumxy/n - (sumx/n)*(sumy/n)) / (sumx2/n - (sumx/n)*(sumx/n)); double b = (sumy/n) - a*(sumx/n); s = imesure % 2 ? 1 : -1; double y = getBoloRawMuV(ibolo, imesure); y = y-s*b; return y; } */ double ArcheopsFile::getGainAmpli(int ibolo) { return gain_ampli(lastReglage()->reglage.bolo[ibolo]); } double ArcheopsFile::getDACV(int ibolo) { block_type_reglage* reglage = lastReglage(); block_type_param* param = lastParam(); if (!reglage) return 0; if (!param) return 0; return DAC_muV(¶m->param, ®lage->reglage, ibolo); } double ArcheopsFile::getDACI(int ibolo) { block_type_reglage* reglage = lastReglage(); block_type_param* param = lastParam(); if (!reglage) return 0; if (!param) return 0; return DAC_muA(¶m->param, ®lage->reglage, ibolo); } double ArcheopsFile::getBoloMuV2T(int ibolo, int imesure) { return getDACV(ibolo) - getBoloMuV2(ibolo, imesure) ; } double ArcheopsFile::getBoloRes(int ibolo, int imesure) { double i = getDACI(ibolo); // microAmps double v = getBoloMuV2T(ibolo, imesure); // microVolts double r = v/i; // Ohms return r; } double ArcheopsFile::getBoloTemp(int ibolo, int imesure) { double r = getBoloRes(ibolo, imesure); block_type_reglage* reglage = lastReglage(); block_type_param* param = lastParam(); if (!reglage) return 0; if (!param) return 0; return bolo_temp(¶m->param, ®lage->reglage, r, ibolo); } // Dilution int4 ArcheopsFile::getADCDil(int iADC) { block_type_dilution* blk = lastDilution(); if (!blk) return 0; if (iADC < 0 || iADC > 47) return 0; return blk->ADC_dil[iADC]; } int4 ArcheopsFile::getSwitchDil() { block_type_dilution* blk = lastDilution(); if (!blk) return 0; return blk->switch_dil; } // SST, gyros... void ArcheopsFile::needSSTProcessMask(int mask) { blockSet->sstHandler.NeedProcess(mask); } long ArcheopsFile::getSSTSignal(int idiode, int imesure) { return blockSet->sstHandler.getSignal(imesure, idiode); } long ArcheopsFile::getSSTRawSignal(int idiode, int imesure) { return blockSet->sstHandler.getRawSignal(imesure, idiode); } double ArcheopsFile::getSSTSignalCN(int idiode, int imesure) { return getSSTRawSignalCN(SSTHandler::getDiodPermut(idiode),imesure); } double ArcheopsFile::getSSTRawSignalCN(int ichannel, int imesure) { // Si pas bloc comprime -> 0.5 if (lastSSTComp() == NULL) return .5; if (numero_block(lastSSTComp()) != numero_block(lastSST())) return 0.5; // Attention, on ne transmet pas les canaux 0 et 4.... if (ichannel == 0 || ichannel == 4) return 0; int i = ichannel - 1; if (i >= 4) i--; unsigned int4* data = lastSSTComp()->sst[i]; // Les deux premieres valeurs sont codees directement... if (imesure<2) return 0.5; int iExp = (imesure-2)/7 + 1; int expo = data[iExp] & 0xf; int noise = 1 << expo; return noise/2.; } double ArcheopsFile::getSSTStarZ(int istar, int imesure) { return blockSet->sstHandler.getStarZ(imesure+getSSTBlockNum()*nb_per_block*2, istar); } double ArcheopsFile::getSSTStarF(int istar, int imesure) { return blockSet->sstHandler.getStarF(imesure+getSSTBlockNum()*nb_per_block*2, istar); } double ArcheopsFile::getSSTStarT(int istar, int imesure) { return blockSet->sstHandler.getStarTime(imesure+getSSTBlockNum()*nb_per_block*2, istar); } int ArcheopsFile::getNumbStar(int imesure) { return blockSet->sstHandler.getNumbStar(imesure+getSSTBlockNum()*nb_per_block*2); } long ArcheopsFile::getGyroRaw(int igyro, int imesure) { return blockSet->gyroHandler.getRawSignal(imesure, igyro); } double ArcheopsFile::getGyroTens(int igyro, int imesure) { return blockSet->gyroHandler.getSignal(imesure, igyro); } double ArcheopsFile::getGyroSpeed(int igyro, int imesure) { return blockSet->gyroHandler.getSpeed(imesure, igyro); } // $CHECK$ TBD double ArcheopsFile::getAzimut(int /*imesure*/) {return 0;} double ArcheopsFile::getPendDirect(int /*imesure*/) {return 0;} double ArcheopsFile::getPendOrth(int /*imesure*/) {return 0;} double ArcheopsFile::getAlphaAxis(int /*imesure*/) {return 0;} double ArcheopsFile::getDeltaAxis(int /*imesure*/) {return 0;}