Changeset 534 in Sophya for trunk/Poubelle/archTOI.old/archeopsfile.cc
- Timestamp:
- Nov 1, 1999, 10:59:29 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Poubelle/archTOI.old/archeopsfile.cc
r442 r534 5 5 #define utilitaires_de_block_archeops 6 6 #include "archeopsfile.h" 7 #include "gyrohandler.h"8 7 9 8 extern "C" { … … 43 42 block_type_modele curBlock; 44 43 block_type_modele peekBlock; 45 46 SSTHandler sstHandler;47 GyroHandler gyroHandler;48 GPSParser gpsParser;49 44 }; 50 45 … … 89 84 90 85 BlockSet::BlockSet(BlockSet const& x) 91 : sstHandler(x.sstHandler), gyroHandler(x.gyroHandler)92 86 { 93 87 lastParam = NULL; … … 255 249 } 256 250 } 251 252 #ifdef __MWERKS__ 253 #pragma mark - 254 #endif 255 #ifdef __MWERKS__ 256 #pragma mark - 257 #endif 258 257 259 258 260 ArcheopsFile::ArcheopsFile(string const& fname) { … … 404 406 } 405 407 406 #define bitmot 24 // nb de bit horloge dans un mot ADC407 408 double ArcheopsFile::perEchant() { // periode d'echantillonage pour le dernier bloc reglage409 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 modulation416 }417 418 double ArcheopsFile::perBlock() { // duree (en secondes) correspondant a un bloc bolo419 return perEchant() * (double)lastParam()->param.n_per_block*2.;420 }421 422 int ArcheopsFile::nEchBlock() { // Nb d'echantillons dans un bloc423 return lastParam()->param.n_per_block*2;424 }425 408 426 409 string ArcheopsFile::blockKdName() { … … 448 431 } 449 432 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 433 void ArcheopsFile::forceBlock(block_type_modele* blk) { 498 434 blockSet->setBloc(*blk); 435 } 436 437 long ArcheopsFile::searchNextBlock(long pos) { 438 static char* buffer = 0; 439 static int4 debswp = debut_block_mesure; 440 static int4 longmax = taille_maxi_block_archeops*20; 441 if (!buffer) { 442 buffer = new char[longmax]; 443 #ifdef SWAP 444 bswap4(&debswp); 445 #endif 446 } 447 long read = longmax; 448 while (read == longmax) { 449 fseek(f,pos,SEEK_SET); 450 read = fread(buffer,1,longmax,f); 451 //if (read<taille_maxi_block_archeops*2) return -1; 452 // EA 150999 changed i+=4 to i++ -> unaligned, but can lose bytes in flight recorder 453 #ifndef __DECCXX 454 #define __unaligned 455 #endif 456 for (long i=4; i<read; i++) { 457 if (*(__unaligned int4*)(buffer+i) == debswp) { 458 cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl; 459 return pos+i; 460 } 461 } 462 pos += read; 463 } 464 cout << "cannot find block start" << endl; 465 return -1; 499 466 } 500 467 … … 531 498 memcpy(&blockSet->curBlock,&blk2,sizeof(blk2)); 532 499 curKind = block_bolo; 500 postProcessBlock(); 533 501 break; 534 502 } 535 503 case block_sst_comprime: { 536 504 blockSet->setRawBloc(blockSet->curBlock); 537 if (!blockSet->sstHandler.NeedBlocks()) break; // inutile de decompresser538 505 block_type_sst blk2; 539 506 block_type_sst_comprime* blk = (block_type_sst_comprime*) &blockSet->curBlock; … … 566 533 memcpy(&blockSet->curBlock,&blk2,sizeof(blk2)); 567 534 curKind = block_sst; 568 // cout << "process " << numero_block(&blockSet->curBlock) << "\n"; 569 blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock); 535 postProcessBlock(); 570 536 break; 571 537 } 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 } 538 // Delegation a tous les producers qui traitent des blocs bruts 539 } 540 } 541 542 543 544 #ifdef __MWERKS__ 545 #pragma mark - 546 #endif 547 548 block_type_param* ArcheopsFile::lastParam() { 549 return blockSet->lastParam; 550 } 551 block_type_journal* ArcheopsFile::lastJournal() { 552 return blockSet->lastJournal; 553 } 554 block_type_reglage* ArcheopsFile::lastReglage() { 555 return blockSet->lastReglage; 556 } 557 block_type_dilution* ArcheopsFile::lastDilution() { 558 return blockSet->lastDilution; 559 } 560 block_type_gps* ArcheopsFile::lastGPS() { 561 return blockSet->lastGPS; 562 } 563 block_type_une_periode* ArcheopsFile::lastUnePeriode() { 564 return blockSet->lastUnePeriode; 565 } 566 block_type_synchro_sol* ArcheopsFile::lastSynchroSol() { 567 return blockSet->lastSynchroSol; 568 } 569 block_type_pointage_sol* ArcheopsFile::lastPointageSol() { 570 return blockSet->lastPointageSol; 571 } 572 block_type_bolo* ArcheopsFile::lastBolo() { 573 return blockSet->lastBolo; 574 } 575 block_type_bolo* ArcheopsFile::llastBolo() { 576 return blockSet->llastBolo; 577 } 578 block_type_gyro* ArcheopsFile::lastGyro() { 579 return blockSet->lastGyro; 580 } 581 block_type_sst* ArcheopsFile::lastSST() { 582 return blockSet->lastSST; 583 } 584 block_type_bolo_comprime* ArcheopsFile::lastBoloComp() { 585 return blockSet->lastBoloComp; 586 } 587 block_type_gyro_comprime* ArcheopsFile::lastGyroComp() { 588 return blockSet->lastGyroComp; 589 } 590 block_type_sst_comprime* ArcheopsFile::lastSSTComp() { 591 return blockSet->lastSSTComp; 592 } 593 594 #ifdef __MWERKS__ 595 #pragma mark - 596 #endif 597 598 584 599 585 600 void ArcheopsFile::saveCurBlock() { … … 680 695 #endif 681 696 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 697 #ifdef __MWERKS__ 698 #pragma mark - 699 #endif 714 700 715 701 … … 762 748 } 763 749 764 void ArcheopsFile::setUTCOffset( intUTCOffset) {750 void ArcheopsFile::setUTCOffset(double UTCOffset) { 765 751 utcOffset = UTCOffset; 766 752 startMJD = rawMJD - utcOffset/24.; … … 771 757 } 772 758 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 // GPS813 // $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 courant822 if (!lastGPS()) return -9.e99;823 return blockSet->gpsParser.getUTC();824 }825 826 double ArcheopsFile::getGPSMJD() { // modified julian day du dernier bloc GPS, JD - 2450000827 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, + = NORD837 if (!lastGPS()) return -9.e99;838 return blockSet->gpsParser.getLatitude();839 }840 841 842 double ArcheopsFile::getGPSLong() { // degres, + = EST843 if (!lastGPS()) return -9.e99;844 return blockSet->gpsParser.getLongitude();845 }846 847 double ArcheopsFile::getGPSAlt() { // meters from sea level848 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 // Bolo870 #define val_DS(j,i) (blk->data_bolo[j][i]&0x1fffff)871 872 873 double ArcheopsFile::getBoloRawMuV(int ibolo, int imesure) { // microvolts bruts874 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 bit889 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_gains914 915 double ArcheopsFile::getBoloMuV(int ibolo, int imesure) { // microvolts, filtre avec filtre carre916 double y = (getBoloRawMuV(ibolo, imesure-1) + getBoloRawMuV(ibolo, imesure))/2.;917 return y;918 }919 920 double ArcheopsFile::getBoloMuV2(int ibolo, int imesure) { // microvolts, filtre921 // On commence par trouver la valeur d'offset, en fittant une droite sur les soustractions922 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, filtre949 // On commence par trouver la valeur d'offset, en fittant une droite sur les soustractions950 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); // microAmps1008 double v = getBoloMuV2T(ibolo, imesure); // microVolts1009 double r = v/i; // Ohms1010 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 // Dilution1024 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.51059 if (lastSSTComp() == NULL) return .5;1060 if (numero_block(lastSSTComp()) != numero_block(lastSST())) return 0.5;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.5;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$ TBD1110 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;}
Note:
See TracChangeset
for help on using the changeset viewer.