Ignore:
Timestamp:
Aug 2, 1999, 3:45:52 PM (26 years ago)
Author:
ansari
Message:

archtoi 2 aout 99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Poubelle/archTOI.old/archeopsfile.cc

    r315 r342  
    3838 
    3939  SSTHandler sstHandler;
     40  GPSParser  gpsParser;
    4041};
    4142
     
    211212      else if (!llastBolo) {
    212213        llastBolo = new block_type_bolo;
     214      }
     215      if (llastBolo) {
    213216        memcpy(llastBolo, lastBolo, sizeof(block_type_bolo));
    214217      }
     
    286289  fn         = x.fn;
    287290  f = fopen(fn.c_str(), "rb");
     291
     292  rawMJD     = x.rawMJD;
     293  startMJD   = x.startMJD;
     294  utcOffset  = x.utcOffset;
    288295}
    289296
     
    300307  //curBlock = oldFile.curBlock;
    301308  //peekBlock = oldFile.peekBlock;
    302   peekPos = 0;
     309  if (peekPos>0) peekPos = 0;
    303310  setUTCOffset(oldFile.utcOffset);
    304311}
     
    306313
    307314def_nom_block
     315
     316def_long_block
    308317
    309318bool ArcheopsFile::nextBlock() {
     
    316325 
    317326  memcpy(curBlock, peekBlock, sizeof(block_type_modele));
    318  
    319   if (peekPos+12 > fLen) return false;
    320   fseek(f,peekPos,SEEK_SET);
    321   size_t read = fread(peekBlock,1,sizeof(block_type_modele),f);
    322   swapEntete(peekBlock);
    323   if (read < longueur_block(peekBlock)) return false;
    324   swapContent(peekBlock);
    325   if (verifie_block(peekBlock) != block_correct) {
    326   printf("block invalide\n"); throw ArchExc("invalid block");
    327   }
    328   peekPos += longueur_block(peekBlock);
     327  curPos = peekPos;
     328 
     329  while (true) {
     330    if (peekPos+12 > fLen) return false;  // fin de fichier
     331    fseek(f,peekPos,SEEK_SET);            // aller en peekPos
     332    size_t read = fread(peekBlock,1,sizeof(block_type_modele),f);
     333    swapEntete(peekBlock);
     334    if (read < longueur_block(peekBlock) ||
     335        type_block(peekBlock) < 0 || type_block(peekBlock) > 19 ||
     336        longueur_block(peekBlock) != long_block[type_block(peekBlock)]) {
     337      cout << "block de type/longueur invalide" << endl;
     338      memset(peekBlock, 0, sizeof(block_type_modele)); // don't keep trash...
     339      peekPos = searchNextBlock(peekPos);
     340      if (peekPos<0) return false;
     341      continue;
     342    }
     343    swapContent(peekBlock);
     344    if (verifie_block(peekBlock) != block_correct) {
     345      cout << "block invalide " << numero_block(peekBlock);
     346      if (!fixBlock(peekBlock)) {
     347        cout << " -- skipped" << endl;
     348        peekPos += longueur_block(peekBlock);  // la longueur doit etre ok...
     349        continue;
     350      } else {
     351        cout << " -- fixed" << endl;
     352        break;
     353      }
     354    }
     355    break; // tout semble bon pour ce bloc...
     356  }
     357 
     358  peekPos += longueur_block(peekBlock); // on suppose que longueur OK...
    329359  if (curPos < 0) {
    330360    curPos = 0; return true;
    331361  }
    332   curPos += longueur_block(curBlock);
    333   curRawKind = curKind = type_block(curBlock);
    334   //printf("block %d  :  %s \n",numero_block(&curBlock),nom_block[curKind]);
    335   postProcessBlock();
    336   saveCurBlock();
     362  if (curBlock->debut != 0) {
     363    curRawKind = curKind = type_block(curBlock);
     364    postProcessBlock();
     365    saveCurBlock();
     366  } else {
     367    curRawKind = curKind = -1;
     368  }
    337369  return true;
    338370}
     
    346378}
    347379
     380bool ArcheopsFile::fixBlock(block_type_modele* blk) {
     381  return false;
     382}
     383
     384
    348385int  ArcheopsFile::blockKind() {
    349386  return curKind;
     
    363400  double p,f1,f2,f3;
    364401  int pp;
     402  if (!lastReglage()) return -1;
    365403  pp=lastReglage()->reglage.horloge.periode;
    366404  p=pp/5.;
     
    374412
    375413int ArcheopsFile::nEchBlock() {  // Nb d'echantillons dans un bloc
    376   return lastParam()->param.n_per_block*2.;
     414  return lastParam()->param.n_per_block*2;
    377415}
    378416
     
    448486}
    449487
     488void ArcheopsFile::forceBlock(block_type_modele* blk) {
     489  blockSet->setBloc(*blk);
     490}
     491
     492#define place_paquet(i,j)        ((i/8) * 24  + j*8 + (i%8) )
     493
    450494void ArcheopsFile::postProcessBlock() {
    451495  switch (curKind) {
     
    454498       block_type_bolo blk2;
    455499       block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &blockSet->curBlock;
     500       #if version_num <= 25
    456501       for(int j=0;j<nb_bolo_util;j++) 
    457                 {
    458                    decompress_7_2(blk->data_bolo[j],blk2.data_bolo[j],nb_per_block*2);
     502           {
     503                   decompress_7_2((int4*)blk->data_bolo[j],blk2.data_bolo[j],nb_per_block*2);
     504           }
     505           #else
     506           block_type_param* param = lastParam();
     507           int jc=0;for(int j=0;j<nb_max_bolo;j++)       // jc = bolo_comprime  //   j=bolo normal
     508           {
     509                if( (param->param.bolo[j].bolo_code_util==bolo_normal_transmis) &&  (jc<nb_bolo_util)  )
     510                        {
     511                        decompress_7_2((int4 *)blk->data_bolo[jc],blk2.data_bolo[j],nb_per_block*2);
     512                        jc++;
     513                        }
     514                else {
     515                  memset(blk2.data_bolo[j], 0, nb_per_block*2*sizeof(int4));
    459516                }
     517                }
     518
     519           #endif
    460520       valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk));   
    461521       memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
     
    464524     }
    465525     case block_sst_comprime: {  // $CHECK$ TBD
     526       blockSet->setRawBloc(blockSet->curBlock);
     527       block_type_sst blk2;
     528       block_type_sst_comprime* blk = (block_type_sst_comprime*) &blockSet->curBlock;
     529       for (int j=0; j<18; j++)
     530         for (int i=0; i<nb_per_block*2; i++)
     531           blk2.sst[i][j] = 0;
     532
     533       int jc=0;
     534       for( int j=0;j<48;j++) {
     535         if ((j!=0) && (j!=4))
     536         {
     537           unsigned int4 sst_vrai[nb_per_block*2];
     538           decompress_4_1((int4*)blk->sst[jc],(int4*)sst_vrai,nb_per_block*2);
     539           for (int k=0;k<nb_per_block*2;k++) {
     540             unsigned int4 a,b0,b1,b2;
     541             b2 = sst_vrai[k] & 0xf;
     542             b1 = (sst_vrai[k] >> 4) & 0xf;
     543             b0 = (sst_vrai[k] >> 8) & 0xf;
     544                 a=place_paquet(j,0);
     545                 blk2.sst[k][a/8] |= (b0 << (a%8)*4);
     546                 a=place_paquet(j,1);
     547                 blk2.sst[k][a/8] |= (b1 << (a%8)*4);
     548                 a=place_paquet(j,2);
     549                 blk2.sst[k][a/8] |= (b2 << (a%8)*4);
     550           }
     551           jc++;
     552         }
     553       }       
     554       valide_block((block_type_modele*)&blk2,block_sst,numero_block(blk));     
     555       memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
     556       curKind = block_sst;
     557       blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
     558       break;
    466559     }
    467560     case block_sst : {
    468561       blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
     562     }
     563     case block_gps : {
     564       blockSet->gpsParser.ProcessBlock((block_type_gps*)&blockSet->curBlock);
    469565     }
    470566  }
     
    519615#endif
    520616
     617#ifdef SWAP
    521618void ArcheopsFile::swapEntete(block_type_modele* blk) {
    522 #ifdef SWAP
    523619  bswap4(&(blk->debut));
    524620  bswap4(&(blk->code1));
    525621  bswap4(&(blk->code2));
    526622  long lg = longueur_block(blk);
    527   bswap4(((char*)blk) + lg - 4);
     623  if (lg < taille_maxi_block_archeops)
     624    bswap4(((char*)blk) + lg - 4);
     625}
     626#else
     627void ArcheopsFile::swapEntete(block_type_modele* ) {
     628}
    528629#endif
    529 }
    530 
     630
     631#ifdef SWAP
    531632void ArcheopsFile::swapContent(block_type_modele* blk) {
    532 #ifdef SWAP
    533633  int typ = type_block(blk);
    534634
     
    550650    for (int i=0; i<nb_max_bolo; i++)
    551651      for (int j=0; j<8; j++)
    552         bswap4(&b->param.bolo[i].bolo_nom[4*j]);
    553   }
    554  
    555   }
     652#if version_num<=25
     653        bswap4(&b->param.bolo[i].bolo_nom[4*j]);
     654#else
     655        bswap4(&b->param.nom_coef[i].bolo_nom[4*j]);
    556656#endif
    557 }
    558  
     657  }
     658 
     659  }
     660}
     661#else
     662void ArcheopsFile::swapContent(block_type_modele* ) {
     663}
     664#endif
     665 
     666long ArcheopsFile::searchNextBlock(long pos) {
     667  static char* buffer = 0;
     668  static int4  debswp = debut_block_mesure;
     669  static int4  longmax = taille_maxi_block_archeops*20;
     670  if (!buffer) {
     671    buffer = new char[longmax];
     672#ifdef SWAP
     673    bswap4(&debswp);
     674#endif
     675  }
     676  fseek(f,pos,SEEK_SET);
     677  size_t read = fread(buffer,1,taille_maxi_block_archeops*2,f);
     678  //if (read<taille_maxi_block_archeops*2) return -1;
     679  for (int i=4; i<read; i+=4) {
     680    if (*(int4*)(buffer+i) == debswp) {
     681      cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
     682      return pos+i;
     683    }
     684  }
     685  cout << "cannot find block start" << endl;
     686  return -1;
     687}
     688
    559689 
    560690
     
    562692static int mlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    563693
     694double ArcheopsFile::decodeMJD(string const& dateString) {
     695  //99_04_29-15h36m22  ou  99_05_10
     696  short y,m,d,hh,mm,ss;
     697  char const* p = dateString.c_str();
     698  char const* p2 = dateString.c_str() + dateString.length();
     699  y  = atoi(p); p+=3; if (p>p2) return -1;
     700  m  = atoi(p); p+=3; if (p>p2) return -1;
     701  d  = atoi(p); p+=3;
     702  if (p<p2) {
     703  hh = atoi(p); p+=3; if (p>p2) return -1;
     704  mm = atoi(p); p+=3; if (p>p2) return -1;
     705  ss = atoi(p);
     706  } else {
     707    hh=mm=ss=0;
     708  }
     709
     710  if (y<50) y += 100;
     711  // 1. depuis 0/1/97 minuit
     712  double mjd = (int) (365.25 * (y-97));
     713  for (int i=0; i<m-1; i++)
     714    mjd += mlen[i];
     715  if (y%4 == 0 && m > 2) mjd++;
     716  mjd += d;
     717  mjd += hh/24. + mm/24./60. + ss/24./60./60;
     718 
     719  mjd += 448.5; // 0/1/97 minuit
     720
     721  return mjd;
     722}
     723
    564724void ArcheopsFile::computeMJD(string const& fname) {
    565   //h99_04_29-15h36m22
    566   short y,m,d,hh,mm,ss;
     725  //telemetrie : h99_04_29-15h36m22
     726  //enregistreur : ARKxxxxxx.dat, et MJD = samedi 17 juillet, 21h -> 1377.4
    567727  char const* p = fname.c_str();
    568728  char const* p2 = p  + fname.length()-1;
     
    570730  if (*p2 == ':' || *p2 == '/') p2++;
    571731  if (*p2 == 'h') p2++;
    572   y  = atoi(p2); p2+=3;
    573   m  = atoi(p2); p2+=3;
    574   d  = atoi(p2); p2+=3;
    575   hh = atoi(p2); p2+=3;
    576   mm = atoi(p2); p2+=3;
    577   ss = atoi(p2);
    578  
    579   if (y<50) y += 100;
    580   // 1. depuis 0/1/97 minuit
    581   rawMJD = (int) (365.25 * (y-97));
    582   for (int i=0; i<m-1; i++)
    583     rawMJD += mlen[i];
    584   if (y%4 == 0 && m > 2) rawMJD++;
    585   rawMJD += d;
    586   rawMJD += hh/24. + mm/24./60. + ss/24./60./60;
    587  
    588   rawMJD += 448.5; // 0/1/97 minuit
     732  if (!strncmp(p2, "ARK",3)) {
     733    rawMJD = 1377.4;
     734  } else {
     735    rawMJD = decodeMJD(p2);
     736  }
    589737  startMJD = rawMJD - utcOffset/24.;
    590738}
     
    610758
    611759
     760int ArcheopsFile::getGyroBlockNum() {
     761  if (!lastGyro()) return -1;
     762  return numero_block(lastGyro());
     763}
     764
     765
    612766// GPS
    613767// $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,
     
    621775double ArcheopsFile::getGPSUTC() {  // en secondes depuis minuit UTC jour courant
    622776  if (!lastGPS()) return -9.e99;
    623   char* p = lastGPS()->gps;
    624   if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
    625   p += 7;
     777  return blockSet->gpsParser.getUTC();
     778/*  char* p = lastGPS()->gps;
     779  //if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
     780  //p += 7;
     781  if (*p != '$') return -9.e99;
     782  p += 1;
    626783  double t;
    627784  sscanf(p, "%lg", &t);
    628785  int h = int(t/10000); t -= h*10000;
    629786  int m = int(t/100);   t -= m*100;
    630   return h*3600. + m*60. + t;
     787  return h*3600. + m*60. + t;*/
    631788}
    632789
    633790double ArcheopsFile::getGPSMJD() {  // modified julian day du dernier bloc GPS, JD - 2450000
    634   double t = getGPSUTC()/86400.;
     791  double t = getGPSUTC()/86400. - 0.5;
    635792  if (t<0) return t;
    636793  if (t > (startMJD - int(startMJD))) {
     
    643800double ArcheopsFile::getGPSLat() {  // degres, +  = NORD
    644801  if (!lastGPS()) return -9.e99;
    645   char* p = lastGPS()->gps;
    646   if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
     802  return blockSet->gpsParser.getLatitude();
     803  /*char* p = lastGPS()->gps;
     804  //if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
     805  if (*p!='$') return -9.e99;
    647806  char* fence = p+80;
    648   p += 7;
     807  p += 1;
    649808  while (*p != ',' && p<fence) p++;
    650809  if (*p != ',') return -9.e99;
     
    658817  p++;
    659818  if (*p == 'S') t = -t;
    660   return t;
    661 }
     819  return t;*/
     820}
     821
    662822
    663823double ArcheopsFile::getGPSLong() { // degres, +  = EST
    664824  if (!lastGPS()) return -9.e99;
    665   char* p = lastGPS()->gps;
    666   if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
     825  return blockSet->gpsParser.getLongitude();
     826  /*char* p = lastGPS()->gps;
     827  //if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
     828  if (*p!='$') return -9.e99;
    667829  char* fence = p+80;
    668   p += 7;
     830  p += 1;
    669831  for (int i=0; i<3; i++) {
    670832    while (*p != ',' && p<fence) p++;
     
    680842  p++;
    681843  if (*p == 'W') t = -t;
    682   return t;
    683 }
    684 
     844  return t;*/
     845}
     846
     847double ArcheopsFile::getGPSAlt() { // meters from sea level
     848  if (!lastGPS()) return -9.e99;
     849  return blockSet->gpsParser.getAltitude();
     850  /*char* p = lastGPS()->gps;
     851  //if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
     852  if (*p!='$') return -9.e99;
     853  char* fence = p+80;
     854  p += 1;
     855  for (int i=0; i<8; i++) {
     856    while (*p != ',' && p<fence) p++;
     857    if (*p != ',') return -9.e99;
     858    p++;
     859  }
     860  double t;
     861  sscanf(p, "%lg", &t);
     862  return t;*/
     863}
     864
     865bool ArcheopsFile::hasGPSTime() {
     866  if (!lastGPS()) return false;
     867  return blockSet->gpsParser.hasGPSTime();
     868}
     869
     870bool ArcheopsFile::hasGPSPos() {
     871  if (!lastGPS()) return false;
     872  return blockSet->gpsParser.hasPosition();
     873}
     874
     875bool ArcheopsFile::hasGPSAlt() {
     876  if (!lastGPS()) return false;
     877  return blockSet->gpsParser.hasAltitude();
     878}
    685879
    686880
    687881// Bolo
     882#define  val_DS(j,i)  (blk->data_bolo[j][i]&0x1fffff)
     883
    688884
    689885long ArcheopsFile::getRawBolo(int ibolo, int imesure) {    // donnee brute, avec seulement soustraction offset
    690886  int nb_coups,aa; 
    691887  block_type_bolo* blk = imesure >= 0 ? lastBolo() : llastBolo();
     888  //cout << "raw " << imesure << " ";
    692889  if (imesure < 0) imesure += nEchBlock();
    693890  if (!blk) return 0;
     
    699896 
    700897  int s = imesure % 2 ? 1 : -1;
    701 
    702   return s*(((blk->data_bolo[ibolo][imesure]-aa)<<1)/nb_coups);
     898 
     899  //cout << s*(((val_DS(ibolo,imesure)-aa)<<1)/nb_coups) << "\n";
     900
     901  return s*(((val_DS(ibolo,imesure)-aa)<<1)/nb_coups);
    703902}
    704903
     
    706905
    707906double ArcheopsFile::getMuVBolo(int ibolo, int imesure) { // microvolts, filtre avec filtre carre
    708   double y = (getRawBolo(ibolo, imesure-1) - getRawBolo(ibolo, imesure))/2.;
    709   if (imesure%2) y=-y;
     907  double y = (getRawBolo(ibolo, imesure-1) + getRawBolo(ibolo, imesure))/2.;
     908  //if (imesure%2) y=-y;
    710909  block_type_reglage* reglage = lastReglage();
    711   return ((1e5*y)/(65536.*gain_ampli(reglage->reglage.bolo[ibolo])));
     910  block_type_param*   param = lastParam();
     911  //cout << "muv " << imesure << " " << y << "\n";
     912  return bol_micro_volt(y,(double)param->param.bolo[ibolo].bolo_gain*gain_ampli(reglage->reglage.bolo[ibolo]));
     913  //return ((1e5*y)/(65536.*gain_ampli(reglage->reglage.bolo[ibolo])));
    712914}
    713915
     
    719921}
    720922
    721 
    722923long ArcheopsFile::getSSTSignal(int idiode, int imesure) {
    723924  return blockSet->sstHandler.getSignal(imesure, idiode);
    724925}
     926
     927long ArcheopsFile::getSSTRawSignal(int idiode, int imesure) {
     928  return blockSet->sstHandler.getRawSignal(imesure, idiode);
     929}
     930
     931double ArcheopsFile::getSSTStarZ(int istar, int imesure) {
     932  return blockSet->sstHandler.getStarZ(imesure, istar);
     933}
     934
     935double ArcheopsFile::getSSTStarF(int istar, int imesure) {
     936  return blockSet->sstHandler.getStarF(imesure, istar);
     937}
     938
     939long ArcheopsFile::getGyro(int igyro, int imesure) {   
     940  if (igyro<0 || igyro>2) return 0;
     941  if (imesure<0 || imesure>= nb_per_block*2) return 0;
     942  block_type_gyro* blk = lastGyro() ;
     943  if (!blk) return 0;
     944#if version_num<=25
     945  return blk->gyros[igyro][imesure];
     946#else
     947  return blk->gyro[igyro][imesure];
     948#endif
     949}
     950
     951
     952
    725953// $CHECK$ TBD
    726954
Note: See TracChangeset for help on using the changeset viewer.