Changeset 315 in Sophya for trunk/Poubelle


Ignore:
Timestamp:
Jun 15, 1999, 3:53:04 PM (26 years ago)
Author:
ansari
Message:

Archeops 24, gestion byte-swap

Location:
trunk/Poubelle/archTOI.old
Files:
7 added
1 deleted
6 edited

Legend:

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

    r310 r315  
    11#define utilitaires_de_block_archeops
    22#include "archeopsfile.h"
     3extern "C" {
    34#include "compress.h"
     5}
    46#include <iostream.h>
     7
     8// BlockSet is the current "state" of the file reader automate.
     9// It contains the last blocks of each kind, the current block and
     10// the look-ahead block.
    511
    612class BlockSet {
     
    2733  block_type_gyro_comprime* lastGyroComp;
    2834  block_type_sst_comprime*  lastSSTComp;
     35   
     36  block_type_modele         curBlock;
     37  block_type_modele         peekBlock;
     38 
     39  SSTHandler sstHandler;
    2940};
    3041
     
    4556  lastGyroComp   = NULL;
    4657  lastSSTComp    = NULL;
     58 
     59  memset(&curBlock,0,sizeof(block_type_modele));
     60  memset(&peekBlock,0,sizeof(block_type_modele));
    4761}
    4862
     
    6579}
    6680
    67 BlockSet::BlockSet(BlockSet const& x) {
     81BlockSet::BlockSet(BlockSet const& x)
     82: sstHandler(x.sstHandler)
     83{
    6884  lastParam      = NULL;
    6985  lastJournal    = NULL;
     
    8197  lastGyroComp   = NULL;
    8298  lastSSTComp    = NULL;
     99 
    83100  if (x.lastParam) {
    84101    lastParam = new block_type_param;
     
    141158    *lastSSTComp = *x.lastSSTComp;
    142159  }
     160 
     161  memcpy(&curBlock,&x.curBlock,sizeof(block_type_modele));
     162  memcpy(&peekBlock,&x.peekBlock,sizeof(block_type_modele));
     163
    143164}
    144165
     
    232253  fseek(f,0,SEEK_END);
    233254  fLen = ftell(f);
    234   curPos = 0;
     255  curPos = -1;
     256  peekPos = -1;
    235257  curKind = -1;
    236258  curRawKind = -1;
     
    256278  }
    257279
    258   curBlock   = x.curBlock;
     280  //curBlock   = x.curBlock;
    259281  curKind    = x.curKind;
    260282  curRawKind = x.curRawKind;
    261283  curPos     = x.curPos;
     284  peekPos    = x.peekPos;
    262285  fLen       = x.fLen;
    263286  fn         = x.fn;
     
    275298  delete blockSet;
    276299  blockSet = new BlockSet(*oldFile.blockSet);
     300  //curBlock = oldFile.curBlock;
     301  //peekBlock = oldFile.peekBlock;
     302  peekPos = 0;
    277303  setUTCOffset(oldFile.utcOffset);
    278304}
     
    282308
    283309bool ArcheopsFile::nextBlock() {
    284   //if (curPos>0) saveCurBlock();
    285   //if (curPos<0) curPos = 0;
    286   if (curPos+12 > fLen) return false;
    287   fseek(f,curPos,SEEK_SET);
    288   size_t read = fread(&curBlock,1,sizeof(curBlock),f);
    289   if (read < longueur_block(&curBlock)) return false;
    290   if (verifie_block(&curBlock) != block_correct) {
     310  // si pas de peek, alors en lire un pour commencer...
     311  if (peekPos<0) {
     312    peekPos=0; if (!nextBlock()) return false;
     313  }
     314  block_type_modele* curBlock=currentBlock();
     315  block_type_modele* peekBlock=aheadBlock();
     316 
     317  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) {
    291326  printf("block invalide\n"); throw ArchExc("invalid block");
    292327  }
    293   curRawKind = curKind = type_block(&curBlock);
    294   curPos += longueur_block(&curBlock);
     328  peekPos += longueur_block(peekBlock);
     329  if (curPos < 0) {
     330    curPos = 0; return true;
     331  }
     332  curPos += longueur_block(curBlock);
     333  curRawKind = curKind = type_block(curBlock);
    295334  //printf("block %d  :  %s \n",numero_block(&curBlock),nom_block[curKind]);
    296335  postProcessBlock();
     
    316355
    317356int  ArcheopsFile::blockNum() {
    318   return numero_block(&curBlock);
     357  return numero_block(currentBlock());
    319358}
    320359
     
    348387
    349388block_type_modele*  ArcheopsFile::currentBlock() {
    350   if (curPos<0) return NULL;
    351   return &curBlock;
    352 }
     389  //if (curPos<0) return NULL;
     390  return &blockSet->curBlock;
     391}
     392
     393block_type_modele*  ArcheopsFile::aheadBlock() {
     394  //if (peekPos<0) return NULL;
     395  return &blockSet->peekBlock;
     396}
     397
     398bool ArcheopsFile::sameBlockNumAhead() {
     399  if (curPos<0) return false;
     400  return (numero_block(&blockSet->curBlock) == numero_block(&blockSet->peekBlock));
     401}
     402
    353403
    354404block_type_param* ArcheopsFile::lastParam() {
     
    401451  switch (curKind) {
    402452     case block_bolo_comprime: {
    403        blockSet->setRawBloc(curBlock);
     453       blockSet->setRawBloc(blockSet->curBlock);
    404454       block_type_bolo blk2;
    405        block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &curBlock;
     455       block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &blockSet->curBlock;
    406456       for(int j=0;j<nb_bolo_util;j++) 
    407457                {
     
    409459                }
    410460       valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk));   
    411        memcpy(&curBlock,&blk2,sizeof(blk2));
     461       memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
    412462       curKind = block_bolo;
    413463       break;
    414464     }
     465     case block_sst_comprime: {  // $CHECK$ TBD
     466     }
     467     case block_sst : {
     468       blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
     469     }
    415470  }
    416471}
    417472
    418473void ArcheopsFile::saveCurBlock() {
    419   blockSet->setBloc(curBlock);
     474  blockSet->setBloc(blockSet->curBlock);
    420475}
    421476
    422477void ArcheopsFile::pushMark() {    // push current file position, and "last" blocks`
    423478  fposStack.push(curPos);
     479  fposStack.push(peekPos);
    424480  blockStack.push(new BlockSet(*blockSet));
    425481}
     
    429485    delete blockSet;
    430486    blockSet = blockStack.top();
     487    blockStack.pop();
     488    peekPos = fposStack.top();
     489    fposStack.pop();
    431490    curPos = fposStack.top();
    432     blockStack.pop();
    433491    fposStack.pop();
    434492  }
    435493}
     494
     495typedef unsigned int4 uint_4;
     496typedef unsigned short uint_2;
     497
     498static inline void bswap4(void* p)
     499{
     500  uint_4 tmp = *(uint_4*)p;
     501  *(uint_4*)p = ((tmp >> 24) & 0x000000FF) |
     502                ((tmp >> 8)  & 0x0000FF00) |
     503                ((tmp & 0x0000FF00) << 8)  |
     504                ((tmp & 0x000000FF) << 24);
     505}
     506
     507static inline void bswap2(void* p)
     508{
     509  uint_2 tmp = *(uint_2*)p;
     510  *(uint_2*)p = ((tmp >> 8) & 0x00FF) |
     511                ((tmp & 0x00FF) << 8);
     512}
     513
     514#ifdef __DECCXX
     515#define SWAP
     516#endif
     517#if defined(Linux)  || defined(linux)
     518#define SWAP
     519#endif
     520
     521void ArcheopsFile::swapEntete(block_type_modele* blk) {
     522#ifdef SWAP
     523  bswap4(&(blk->debut));
     524  bswap4(&(blk->code1));
     525  bswap4(&(blk->code2));
     526  long lg = longueur_block(blk);
     527  bswap4(((char*)blk) + lg - 4);
     528#endif
     529}
     530
     531void ArcheopsFile::swapContent(block_type_modele* blk) {
     532#ifdef SWAP
     533  int typ = type_block(blk);
     534
     535  if (typ == block_gps) return; // char only, no swap
     536  if (typ == block_une_periode) { // une_periode, des shorts
     537    block_type_une_periode* b = (block_type_une_periode*) blk;
     538    for (int i=0; i<nb_max_bolo; i++)
     539      for (int j=0; j<nb_max_mes_per; j++)
     540        bswap2(&b->bol_per[i][j]);
     541    return;
     542  }
     543
     544  for (int i=0; i<longueur_block(blk)/4-4; i++)
     545    bswap4(blk->mot + i);
     546  // On deswappe ce qui ne devait pas etre swappe...
     547  switch (typ) {
     548  case block_param: {
     549    block_type_param* b = (block_type_param*) blk;
     550    for (int i=0; i<nb_max_bolo; i++)
     551      for (int j=0; j<8; j++)
     552        bswap4(&b->param.bolo[i].bolo_nom[4*j]);
     553  }
     554 
     555  }
     556#endif
     557}
     558 
     559 
     560
    436561
    437562static int mlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
     
    474599}
    475600
     601int ArcheopsFile::getBoloBlockNum() {
     602  if (!lastBolo()) return -1;
     603  return numero_block(lastBolo());
     604}
     605
     606int ArcheopsFile::getSSTBlockNum() {
     607  if (!lastSST()) return -1;
     608  return numero_block(lastSST());
     609}
     610
     611
    476612// GPS
    477613// $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,
     
    484620
    485621double ArcheopsFile::getGPSUTC() {  // en secondes depuis minuit UTC jour courant
    486   if (!lastGPS()) return -1;
     622  if (!lastGPS()) return -9.e99;
    487623  char* p = lastGPS()->gps;
    488   if (strncmp(p, "$GPGGA,", 7)) return -1;
     624  if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
    489625  p += 7;
    490626  double t;
     
    506642
    507643double ArcheopsFile::getGPSLat() {  // degres, +  = NORD
    508   if (!lastGPS()) return 99999;
     644  if (!lastGPS()) return -9.e99;
    509645  char* p = lastGPS()->gps;
    510   if (strncmp(p, "$GPGGA,", 7)) return 99999;
     646  if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
    511647  char* fence = p+80;
    512648  p += 7;
    513649  while (*p != ',' && p<fence) p++;
    514   if (*p != ',') return 99999;
     650  if (*p != ',') return -9.e99;
    515651  p++;
    516652  double t;
     
    519655  t = d + t/60;
    520656  while (*p != ',' && p<fence) p++;
    521   if (*p != ',') return 99999;
     657  if (*p != ',') return -9.e99;
    522658  p++;
    523659  if (*p == 'S') t = -t;
     
    526662
    527663double ArcheopsFile::getGPSLong() { // degres, +  = EST
    528   if (!lastGPS()) return -1;
     664  if (!lastGPS()) return -9.e99;
    529665  char* p = lastGPS()->gps;
    530   if (strncmp(p, "$GPGGA,", 7)) return 99999;
     666  if (strncmp(p, "$GPGGA,", 7)) return -9.e99;
    531667  char* fence = p+80;
    532668  p += 7;
    533669  for (int i=0; i<3; i++) {
    534670    while (*p != ',' && p<fence) p++;
    535     if (*p != ',') return 99999;
     671    if (*p != ',') return -9.e99;
    536672    p++;
    537673  }
     
    541677  t = d + t/60;
    542678  while (*p != ',' && p<fence) p++;
    543   if (*p != ',') return 99999;
     679  if (*p != ',') return -9.e99;
    544680  p++;
    545681  if (*p == 'W') t = -t;
     
    570706
    571707double ArcheopsFile::getMuVBolo(int ibolo, int imesure) { // microvolts, filtre avec filtre carre
    572   double y = (getRawBolo(ibolo, imesure-1) + getRawBolo(ibolo, imesure))/2.;
     708  double y = (getRawBolo(ibolo, imesure-1) - getRawBolo(ibolo, imesure))/2.;
     709  if (imesure%2) y=-y;
    573710  block_type_reglage* reglage = lastReglage();
    574   return ((1e5*y)/(65536.*gain(reglage->reglage.bolo[ibolo])));
     711  return ((1e5*y)/(65536.*gain_ampli(reglage->reglage.bolo[ibolo])));
    575712}
    576713
    577714
    578715// SST, gyros...
     716
     717void ArcheopsFile::needSSTProcessMask(int mask) {
     718  blockSet->sstHandler.NeedProcess(mask);
     719}
     720
     721
     722long ArcheopsFile::getSSTSignal(int idiode, int imesure) {
     723  return blockSet->sstHandler.getSignal(imesure, idiode);
     724}
    579725// $CHECK$ TBD
    580726
  • trunk/Poubelle/archTOI.old/archeopsfile.h

    r310 r315  
    66#include <stack>
    77
     8
     9#ifndef nb_max_bolo
    810#define _archeops               //  Acquisition Archeops (avec transputer)
    911#define programme
    10 
    1112extern "C" {
    1213#include "archeops.h"
    1314}
     15#endif
     16
     17#include "ssthandler.h"
    1418
    1519enum {
     
    4246class BlockSet;
    4347
    44 class ArchExc : public exception {
     48class ArchExc {
    4549public:
    4650  ArchExc(string s) : msg(s) {}
     
    7579  void pushMark();    // push current file position, and "last" blocks
    7680  void popMark();     // pops last file position and "last" blocks
    77  
     81   
    7882  void grabLastBlocs(ArcheopsFile const& oldFile);
    7983 
     84  block_type_modele*  aheadBlock();   // internal buffer
    8085  block_type_modele*  currentBlock(); // internal buffer
     86  bool sameBlockNumAhead();
    8187 
    8288  block_type_param*         lastParam();  // saved blocks, including current
     
    101107  // On travaille en MJD = JD - 2450000.0, = 9 octobre 1995 midi UTC
    102108  // 1er juillet 1999 minuit UTC = JD 2451360.5,   MJD 1360.5
     109  // Ces fonctions travaillent sur le dernier bloc GPS
    103110  int getGPSBlockNum();
    104111  double getGPSUTC();  // en secondes depuis minuit UTC
     
    106113  double getGPSLat();  // degres, +  = NORD
    107114  double getGPSLong(); // degres, +  = EST
    108  
     115   
    109116  // Bolo
     117  int getBoloBlockNum();
    110118  long getRawBolo(int ibolo, int imesure);   // donnee brute, avec seulement soustraction offset
    111119  double getMuVBolo(int ibolo, int imesure); // microvolts, filtre avec filtre carre
    112120 
    113121  // SST, gyros, etc
     122  int getSSTBlockNum();
     123  void needSSTProcessMask(int mask);
     124  long getSSTSignal(int iDiode, int imesure);
    114125 
    115126  double getAzimut(int imesure);
     
    119130  double getAlpha(int imesure);
    120131  double getDelta(int imesure);
    121  
    122  
     132   
    123133protected:
    124134  BlockSet*                 blockSet;
     
    128138  void saveCurBlock();
    129139  void postProcessBlock();
     140
     141  void swapEntete(block_type_modele* blk);
     142  void swapContent(block_type_modele* blk);
    130143 
    131144  void computeMJD(string const& fname);
    132  
    133   block_type_modele         curBlock;
     145   
    134146  int                       curKind;
    135147  int                       curRawKind;
    136   size_t                    curPos;
     148  long                      curPos;
     149  long                      peekPos;
    137150  size_t                    fLen;
    138151  FILE* f;
  • trunk/Poubelle/archTOI.old/compress.h

    r310 r315  
    66/************************************************************************/
    77
     8#ifndef int4
     9#ifdef __alpha
     10#define int4 int
     11#else
     12#define int4 long
     13#endif
     14#endif
    815
    916
     
    1724/*      pour    n = 72    en sortie     19 mots = 76 octets             */
    1825
    19 void compress_7_1(long* in,long*out,int n,int pasin);
    20 void decompress_7_1(long* in,long*out,int n);
     26void compress_7_1(int4* in,int4*out,int n,int pasin);
     27void decompress_7_1(int4* in,int4*out,int n);
    2128
    2229
     
    2936/*      pour    n = 72    en sortie     11 mots = 44 octets             */
    3037
    31 void compress_4_1(long* in,long*out,int n,int pasin);
    32 void decompress_4_1(long* in,long*out,int n);
     38void compress_4_1(int4* in,int4*out,int n,int pasin);
     39void decompress_4_1(int4* in,int4*out,int n);
    3340
    3441
     
    4249
    4350
    44 void compress_3_1(long* in,long*out,int n,int pasin);
    45 void decompress_3_1(long* in,long*out,int n);
     51void compress_3_1(int4* in,int4*out,int n,int pasin);
     52void decompress_3_1(int4* in,int4*out,int n);
    4653
    4754/************************************************************************/
     
    6370
    6471
    65 void compress_7_2(long* in,long*out,int n,int pasin);
    66 void decompress_7_2(long* in,long*out,int n);
     72void compress_7_2(int4* in,int4*out,int n,int pasin);
     73void decompress_7_2(int4* in,int4*out,int n);
    6774
    6875
     
    7885
    7986
    80 void compress_4_2(long* in,long*out,int n,int pasin);
    81 void decompress_4_2(long* in,long*out,int n);
     87void compress_4_2(int4* in,int4*out,int n,int pasin);
     88void decompress_4_2(int4* in,int4*out,int n);
    8289
    8390
  • trunk/Poubelle/archTOI.old/decompress.c

    r310 r315  
    88//*******************************************************************************************
    99
    10 void  decom_3(long val,long* in,long*out,int n);
     10void  decom_3(int4 val,int4* in,int4*out,int n);
    1111
    1212#define kmax_   15              /*  valeur maximum de l'exposant        */
     
    2424
    2525
    26 void decompress_3_1(long* in,long*out,int n)
    27 {
    28 long val;
     26void decompress_3_1(int4* in,int4*out,int n)
     27{
     28int4 val;
    2929val=    *in;
    3030decom_3(val,in+1,out,n/9);
     
    3333
    3434
    35 void  decom_3(long val,long* in,long*out,int n)
    36 {
    37 register long R;
    38 long ec1,ec2,ec3,ec4,ec5,ec6,ec7,ec8,ec9;
     35void  decom_3(int4 val,int4* in,int4*out,int n)
     36{
     37register int4 R;
     38int4 ec1,ec2,ec3,ec4,ec5,ec6,ec7,ec8,ec9;
    3939int i,k;
    4040
     
    7373//*******************************************************************************************
    7474
    75 void  decom_4(long val,long* in,long*out,int n);
    76 void  decom_4_paire(long val1,long val2,long* in,long*out,int n);
     75void  decom_4(int4 val,int4* in,int4*out,int n);
     76void  decom_4_paire(int4 val1,int4 val2,int4* in,int4*out,int n);
    7777
    7878#undef kmax_
     
    9696
    9797
    98 void decompress_4_1(long* in,long*out,int n)
    99 {
    100 long val1,val2;
     98void decompress_4_1(int4* in,int4*out,int n)
     99{
     100int4 val1,val2;
    101101val1=   ( (*in & 0xffff0000)>>16 ) & 0x0000ffff;
    102102val2=   ( (*in & 0x0000ffff)     )  & 0x0000ffff;
     
    108108
    109109
    110 void  decom_4(long val,long* in,long*out,int n)
    111 {
    112 register long R;
    113 long ec1,ec2,ec3,ec4,ec5,ec6,ec7;
     110void  decom_4(int4 val,int4* in,int4*out,int n)
     111{
     112register int4 R;
     113int4 ec1,ec2,ec3,ec4,ec5,ec6,ec7;
    114114int i,k;
    115115
     
    146146
    147147
    148 void decompress_4_2(long* in,long*out,int n)
    149 {
    150 long val1,val2;
     148void decompress_4_2(int4* in,int4*out,int n)
     149{
     150int4 val1,val2;
    151151val1=in[0];             val2=in[1];
    152152out[0]=val1;    out[1]=val2;
     
    155155
    156156
    157 void  decom_4_paire(long val1,long val2,long* in,long*out,int n)
    158 {
    159 register long R;
    160 long ec1,ec2,ec3,ec4,ec5,ec6,ec7;
     157void  decom_4_paire(int4 val1,int4 val2,int4* in,int4*out,int n)
     158{
     159register int4 R;
     160int4 ec1,ec2,ec3,ec4,ec5,ec6,ec7;
    161161int i,k;
    162162
     
    213213/*      4*n     ==>     n+1     */
    214214
    215 void  decom_7(long val,long* in,long*out,int n);
    216 
    217 void decompress_7_1(long* in,long*out,int n)
    218 {
    219 long val;
     215void  decom_7(int4 val,int4* in,int4*out,int n);
     216
     217void decompress_7_1(int4* in,int4*out,int n)
     218{
     219int4 val;
    220220val=*in;
    221221*out=val;
     
    229229/*  la valeur val est la valeur de reference du point origine   */
    230230
    231 void  decom_7(long val,long* in,long*out,int n)
    232 {
    233 register long R;
    234 long ec1,ec2,ec3,ec4;
     231void  decom_7(int4 val,int4* in,int4*out,int n)
     232{
     233register int4 R;
     234int4 ec1,ec2,ec3,ec4;
    235235int i,k;
    236236
     
    260260/********************************************************************************/
    261261
    262 void  decom_7_paire(long val1,long val2,long* in,long*out,int n);
    263 
    264 void decompress_7_2(long* in,long*out,int n)
    265 {
    266 long val1,val2;
     262void  decom_7_paire(int4 val1,int4 val2,int4* in,int4*out,int n);
     263
     264void decompress_7_2(int4* in,int4*out,int n)
     265{
     266int4 val1,val2;
    267267val1=   ( (*in & 0xffff0000)>>11 ) & 0x001fffe0;
    268268val2=   ( (*in & 0x0000ffff)<<5 )  & 0x001fffe0;
     
    272272
    273273
    274 void  decom_7_paire(long val1,long val2,long* in,long*out,int n)
    275 {
    276 register long R;
    277 long ec1,ec2,ec3,ec4;
     274void  decom_7_paire(int4 val1,int4 val2,int4* in,int4*out,int n)
     275{
     276register int4 R;
     277int4 ec1,ec2,ec3,ec4;
    278278int i,k;
    279279
  • trunk/Poubelle/archTOI.old/toiiter.cc

    r310 r315  
    11#include "toiiter.h"
     2#include "toiinterpolator.h"
    23#include <dirent.h>
    34
     
    1718 
    1819 tBlock0 = -1;
     20 
     21 rawIter = NULL;
     22 interp  = NULL;
     23 lastSample = -1;
     24 maxLookAhead = 1000;
    1925
    2026}
     
    3238  infos = x.infos;   
    3339
    34   file = new ArcheopsFile(*x.file);
     40  if (x.file)
     41    file = new ArcheopsFile(*x.file);
     42  else
     43    file = NULL;
     44   
     45  if (x.rawIter) {
     46    rawIter = new TOIIter(*x.rawIter);
     47    interp = new TOIInterpolator[infos.size()];
     48    for (int i=0; i<infos.size(); i++)
     49      interp[i] = x.interp[i];
     50  } else {
     51    rawIter = NULL;
     52    interp  = NULL;
     53  }
     54 
     55  lastSample = x.lastSample;
     56  maxLookAhead = x.maxLookAhead;
    3557}
    3658
    3759TOIIter::~TOIIter() {
    3860  delete file;
     61  delete rawIter;
     62  delete[] interp;
    3963}
    4064
    4165void TOIIter::Init() {
     66
     67  // $CHECK$ a deplacer, pour gerer repertoires...
    4268  if (directory == "") {
    4369    file = new ArcheopsFile(fileName);
     
    6086  // mieux en prenant le min de tous les delta_T.
    6187 
    62     tBlock0 = file->getStartMJD();
    63 #if 0
     88  tBlock0 = file->getStartMJD();
     89
    6490  file->pushMark();
    6591  if (file->lastGPS() || file->nextBlock(block_gps_mask)) {
     
    7197  }
    7298  file->popMark();
    73 #endif 
     99
     100  bool hasInterp = false;
    74101 
    75102  trigMask = 0;
    76103  for (vector<info>::iterator i = infos.begin(); i != infos.end(); i++) {
     104    if ((*i).interpolated) hasInterp = true;
    77105    if ((*i).triggering) {
    78106      switch ((*i).kind) {
     
    86114          break;
    87115        case azimut:
     116          file->needSSTProcessMask(SSTHandler::findPeriod);
    88117          trigMask |= block_sst_mask;
    89118          break;
    90         case alpha:
    91         case delta:
     119        case sstStarZ:
     120        case sstStarF:
     121          file->needSSTProcessMask(SSTHandler::findStars);
     122          trigMask |= block_sst_mask;
     123          break;
     124        case sstSignal:
     125          file->needSSTProcessMask(SSTHandler::rmveOffset);
     126          trigMask |= block_sst_mask;
     127          break;
     128        case alphaAxis:
     129        case deltaAxis:
     130        case alphaBolo:
     131        case deltaBolo:
     132          file->needSSTProcessMask(SSTHandler::findAxis);
    92133          trigMask |= block_sst_mask;
    93134          break;
     
    101142    imes = 0;
    102143  }
     144 
     145  if (hasInterp) {
     146    rawIter = new TOIIter(*this);
     147    interp = new TOIInterpolator[infos.size()];
     148    for (int i=0; i<infos.size(); i++) {
     149      rawIter->infos[i].interpolated = false;
     150    }
     151    delete file; file = NULL; // on ne travaille plus sur le fichier directement...
     152  }
    103153}
    104154
    105155bool TOIIter::NextFile() {
     156  if (rawIter)
     157    return rawIter->NextFile();
     158   
    106159  if (directory == "") {
    107160    return false;
     
    119172
    120173bool TOIIter::Next() {
    121 
     174  if (rawIter) {  // Delegation pour interpolation
     175    // Trouve prochain sample disponible
     176    for (int k=0; k<2; k++) {
     177      long smp = 2147483647L;
     178      for (int i=0; i<infos.size(); i++) {
     179        long ss = interp[i].nextSample(lastSample+1);
     180        if (ss > 0 && ss < smp) smp=ss;
     181      }
     182      if (smp != 2147483647L) {
     183        lastSample = smp;
     184        break;
     185      }
     186      if (!fetchAhead())  // tout le monde etait en bout de course,
     187        return false;     // on lit un echantillon, ca suffit, d'ou le k<2
     188    }
     189    // Verifie que tous les interpolateurs ont assez de donnees pour
     190    // trouver la valeur correspondante
     191    for (int i=0; i<infos.size(); i++) {
     192      //rif (infos[i].interpolated)
     193        while (interp[i].needMoreDataFor(lastSample) &&
     194               rawIter->getSampleIndex() - lastSample < maxLookAhead)
     195          if (!fetchAhead()) return false;
     196    }
     197   
     198    // On est pret...
     199    return true;
     200  }
    122201
    123202  // trigger sur info indexee dans bloc bolo ou bloc sst ?
     
    129208 
    130209  // soit pas d'info indexee, soit fin bloc courant...
    131  
    132   if (file->nextBlock(trigMask)) {
    133     return true;
    134   }
    135   if (!NextFile()) return false;
    136   return file->nextBlock(trigMask);
    137 }
    138 
    139  double TOIIter::getTime() {                // MJD
     210  while (1) {
     211    if (file->nextBlock(trigMask)) {
     212      while (file->sameBlockNumAhead()) {  // tant que meme numero de bloc, on lit
     213        if (!file->nextBlock()) {          // fin de fichier ?
     214          if (NextFile()) file->nextBlock();
     215          else break;
     216        }
     217      }
     218      return true;
     219    }
     220    if (!NextFile()) return false;
     221  }
     222}
     223
     224/* double TOIIter::getTime() {                // MJD
    140225   // le temps du bloc courant, en secondes
    141226   double dt = file->blockNum() * file->perBlock();
    142227   return tBlock0 + dt/86400. + imes*file->perEchant()/86400.;
    143228 }
    144  
    145  double TOIIter::getValue(int column) {
    146    if (column < 0 || column >= infos.size()) return -1;
     229 */
     230 
     231bool TOIIter::canGetValue(int column) {
     232   if (column < 0 || column >= infos.size()) return false;
     233   if (rawIter) {
     234       return interp[column].canGet(lastSample);
     235   }
    147236   TOIKind kind = infos[column].kind;
    148237   int index = infos[column].index;
    149238   switch (kind) {
     239     case sampleNum:
     240     case internalTime:
     241     case utc:
     242       return true;
     243     case boloTens:
     244     case boloRaw:
     245       return file->lastBolo() != NULL;
     246     case sstSignal:
     247       return file->lastSST() != NULL;
     248     case longitude:
     249     case latitude:
     250       return file->lastGPS() != NULL;
     251     case azimut:
     252     case alphaAxis:
     253     case deltaAxis:
     254       return (file->lastGPS() != NULL && file->lastSST() != NULL);
     255   }
     256   return false;
     257}
     258 
     259double TOIIter::getValue(int column) {
     260   if (column < 0 || column >= infos.size()) return -1;
     261   if (rawIter) {
     262     if (infos[column].interpolated)
     263       return interp[column].getIValue(lastSample);
     264     else
     265       return interp[column].getEValue(lastSample);
     266   }
     267   TOIKind kind = infos[column].kind;
     268   int index = infos[column].index;
     269   switch (kind) {
     270     case sampleNum:
     271       return file->blockNum() * file->nEchBlock() + imes;
     272     case internalTime:
     273       return (file->blockNum() * file->nEchBlock() + imes) * file->perEchant();
     274     case utc:
     275      /* printf("utc: %d %d %g %g %g\n",file->blockNum(),
     276         (file->blockNum() * file->nEchBlock() + imes),
     277         file->perEchant(),
     278         (file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.,
     279         tBlock0+(file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.); */
     280       return tBlock0+(file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.;
    150281     case boloTens:
    151282       return file->getMuVBolo(index, imes);
    152283     case boloRaw:
    153284       return file->getRawBolo(index, imes);
     285     case sstSignal:
     286       return file->getSSTSignal(index, imes);
    154287     case longitude:
    155288       return file->getGPSLong(); // $CHECK$ TBD gerer interpolation (dans file)
    156289     case latitude:
    157290       return file->getGPSLat();  // $CHECK$ TBD gerer interpolation (dans file)
    158       case azimut:
     291     case azimut:
    159292       return file->getAzimut(imes);
    160       case alpha:
     293     case alphaAxis:
    161294       return file->getAlpha(imes);
    162       case delta:
     295     case deltaAxis:
    163296       return file->getDelta(imes);
    164297   }
    165298   return -1;
    166  }
    167  
    168  bool   TOIIter::newValue(int column) {
     299}
     300 
     301bool   TOIIter::newValue(int column) {
    169302   if (column < 0 || column >= infos.size()) return false;
    170303   TOIKind kind = infos[column].kind;
    171304   switch (kind) {
     305     case sampleNum:
     306     case internalTime:
     307     case utc:
     308       return true;
    172309     case boloTens:
    173        return file->blockKind() == block_bolo;
     310       return file->blockNum() == file->getBoloBlockNum();
    174311     case boloRaw:
    175        return file->blockKind() == block_bolo;
     312       return file->blockNum() == file->getBoloBlockNum();
     313     case sstSignal:
     314       return file->blockNum() == file->getSSTBlockNum();
    176315     case longitude:
    177        return file->blockKind() == block_gps;
     316       return file->blockNum() == file->getGPSBlockNum() && imes==0;
    178317     case latitude:
    179        return file->blockKind() == block_gps;
    180       case azimut:
    181        return file->blockKind() == block_sst || file->blockKind() == block_bolo;
    182       case alpha:
    183        return file->blockKind() == block_sst || file->blockKind() == block_bolo;
    184       case delta:
    185        return file->blockKind() == block_sst || file->blockKind() == block_bolo;
     318       return file->blockNum() == file->getGPSBlockNum() && imes==0;
     319     case azimut:
     320       return true; // $CHECK$ with SSTHandler
     321     case alphaAxis:
     322       return true; // $CHECK$ with SSTHandler
     323     case deltaAxis:
     324       return true; // $CHECK$ with SSTHandler
    186325   }
    187326   return false;
    188  }
    189  
    190  bool   TOIIter::extendValue(int column) {
    191    return !newValue(column);
    192  }
    193  
    194  bool   TOIIter::interpValue(int /*column*/) {
    195    return false; // $CHECK$ TBD gerer interpolation
    196  }
    197  
    198  TOIKind TOIIter::getKind(int column) {
     327}
     328 
     329bool   TOIIter::extendValue(int column) {
     330   return (!infos[column].interpolated && !newValue(column));
     331}
     332 
     333bool   TOIIter::interpValue(int column) {
     334   return (infos[column].interpolated && !newValue(column));
     335}
     336 
     337TOIKind TOIIter::getKind(int column) {
    199338   if (column < 0 || column >= infos.size()) return (TOIKind)-1;
    200339   return infos[column].kind;
    201  }
    202  
    203  int TOIIter::getIndex(int column) {
     340}
     341 
     342int TOIIter::getIndex(int column) {
    204343   if (column < 0 || column >= infos.size()) return (TOIKind)-1;
    205344   return infos[column].index;
    206  }
     345}
     346
     347int TOIIter::getColTOI(TOIKind kind, int index) {
     348   for (int i=0; i<infos.size(); i++)
     349     if (infos[i].kind == kind && infos[i].index == index)
     350       return i;
     351   return -1;
     352}
     353
     354bool TOIIter::canGetTOI(TOIKind kind, int index) {
     355   int col = getColTOI(kind, index);
     356   if (col<0) return false;
     357   return canGetValue(col);
     358}
     359
     360double TOIIter::getTOI(TOIKind kind, int index) {
     361   int col = getColTOI(kind, index);
     362   if (col<0) return -9.e99;
     363   return getValue(col);
     364}
     365
    207366   
    208  int TOIIter::getSampleIndex() {
     367int TOIIter::getBlockSampleIndex() {
    209368   return imes;
    210  }
     369}
     370 
     371int TOIIter::getSampleIndex() {
     372   return file->blockNum() * file->nEchBlock() + imes;
     373}
     374 
     375bool TOIIter::fetchAhead() { // Seulement si delegation
     376  if (!rawIter) return false;
     377  if (!rawIter->Next()) return false;
     378  long sample = rawIter->getSampleIndex();
     379  for (int i=0; i<infos.size(); i++) {
     380    if (rawIter->canGetValue(i) && rawIter->newValue(i))
     381      interp[i].enterValue(rawIter->getValue(i), sample);
     382  }
     383  return true;
     384}
     385
  • trunk/Poubelle/archTOI.old/toiiter.h

    r310 r315  
    99
    1010enum TOIKind {
     11  sampleNum,  // Numero d'echantillon (timer interne transputer)
     12  internalTime, // temps transputer depuis debut manip, en secondes.
     13  utc,        // UTC (en jours, MJD = JD - 2450000). index=0 : premier bloc GPS. 1: + sioux.
    1114  boloTens,   // tension en microVolts, filtree avec filtre carre indexe par bolometre
    1215  boloRaw,    // tension brute, non filtree indexe par bolometre
    13   longitude,  // ballon
    14   latitude,   // ballon
     16  sstSignal,  // signal brut SST, indice = diode
     17  sstStarZ,   // numero de diode d'une eventuelle etoile,   i=etoile 0..n
     18  sstStarF,   // flux d'une eventuelle etoile,             -1 si moins de i+1 etoiles
     19  longitude,  // position ballon
     20  latitude,   // position ballon
     21  tsid,       // temps sideral en secondes
    1522  azimut,     // a preciser, reconstruit SST, magneto, autres...
    16  
    17   alpha,      // sur le ciel, indexe par bolometre
    18   delta       // sur le ciel, indexe par bolometre
    19  
     23  alphaAxis,  //
     24  deltaAxis,  //
     25  alphaBolo,  // sur le ciel, indexe par bolometre
     26  deltaBolo   // sur le ciel, indexe par bolometre
     27
    2028};
    2129
    22 
     30class TOIInterpolator;
    2331
    2432class TOIIter {
    2533public:
    26    TOIIter(TOIIter const&);
     34   TOIIter(TOIIter const&);   // $CHECK$ prevoir operator = ?
    2735   ~TOIIter();
    2836   bool Next();
    2937   
    30    double getTime();                // MJD
    31    double getValue(int column);
    32    bool   newValue(int column);     // a juste change ?
    33    bool   extendValue(int column);  // une valeur plus ancienne, etendue ?
    34    bool   interpValue(int column);  // une valeur interpolee avec valeur future ?
     38   bool    canGetValue(int column);  // data is available for that...
     39   double  getValue(int column);
     40   bool    newValue(int column);     // a juste change ?
     41   bool    extendValue(int column);  // une valeur plus ancienne, etendue ?
     42   bool    interpValue(int column);  // une valeur interpolee avec valeur future ?
    3543   TOIKind getKind(int column);
    36    int     getIndex(int column);    // si plusieurs, exemple, tension bolo 2
     44   int     getIndex(int column);     // si plusieurs, exemple, tension bolo 2
    3745   
    38    int    getSampleIndex();         // numero d'echantillon dans dernier bloc bolo
     46   bool    canGetTOI(TOIKind kind, int index=0);
     47   double  getTOI(TOIKind kind, int index=0);
     48   
     49   
     50   int    getBlockSampleIndex();        // numero d'echantillon dans dernier bloc bolo
     51   int    getSampleIndex();             // numero d'echantillon
    3952
    4053   block_type_param*         lastParam(); 
     
    7891   };
    7992   
     93   int getColTOI(TOIKind kind, int index=0);
     94   
    8095   long trigMask;
    8196   
     
    8499   friend class TOISvr;
    85100   
     101   // Gestion de l'interpolation, par delegation a un autre iterateur
     102   TOIIter* rawIter; // iterateur sans interpolation, qui avance avec retard
     103                     // en bufferisant les valeurs. S'il existe, on lui delegue
     104                     // toutes les operations agissant sur le fichier.
     105   TOIInterpolator* interp; // interpolateurs pour stocker les valeurs
     106   long lastSample;  // last interpolated sample
     107   long maxLookAhead;
     108   bool fetchAhead(); // avance d'une TOI en nourrissant les interpolateurs
     109   
    86110   private:
    87111};
Note: See TracChangeset for help on using the changeset viewer.