Index: trunk/Poubelle/archTOI.old/archeopsfile.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archeopsfile.cc	(revision 442)
+++ trunk/Poubelle/archTOI.old/archeopsfile.cc	(revision 534)
@@ -5,5 +5,4 @@
 #define utilitaires_de_block_archeops
 #include "archeopsfile.h"
-#include "gyrohandler.h"
 
 extern "C" {
@@ -43,8 +42,4 @@
   block_type_modele         curBlock;
   block_type_modele         peekBlock;
-  
-  SSTHandler   sstHandler;
-  GyroHandler  gyroHandler;
-  GPSParser    gpsParser;
 };
 
@@ -89,5 +84,4 @@
 
 BlockSet::BlockSet(BlockSet const& x) 
-: sstHandler(x.sstHandler), gyroHandler(x.gyroHandler)
 {
   lastParam      = NULL;
@@ -255,4 +249,12 @@
   }
 }
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
 
 ArcheopsFile::ArcheopsFile(string const& fname) {
@@ -404,23 +406,4 @@
 }
 
-#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() {
@@ -448,53 +431,37 @@
 }
 
-
-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);
+}
+
+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
+  }
+  long read = longmax;
+  while (read == longmax) {
+    fseek(f,pos,SEEK_SET);
+    read = fread(buffer,1,longmax,f);
+    //if (read<taille_maxi_block_archeops*2) return -1; 
+    // EA 150999 changed i+=4 to i++ -> unaligned, but can lose bytes in flight recorder
+#ifndef __DECCXX
+#define __unaligned 
+#endif
+     for (long i=4; i<read; i++) {
+      if (*(__unaligned int4*)(buffer+i) == debswp) {
+        cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
+	    return pos+i;
+      }
+    }
+    pos += read;
+  }
+  cout << "cannot find block start" << endl;
+  return -1;
 }
 
@@ -531,9 +498,9 @@
        memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
        curKind = block_bolo;
+       postProcessBlock();
        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;
@@ -566,20 +533,68 @@
        memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
        curKind = block_sst;
-       //       cout << "process " << numero_block(&blockSet->curBlock) << "\n";
-       blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
+       postProcessBlock();
        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);
-     }
-  }
-}
+// Delegation a tous les producers qui traitent des blocs bruts
+  }
+}
+
+
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
+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;
+}
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
+
 
 void ArcheopsFile::saveCurBlock() {
@@ -680,36 +695,7 @@
 #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<taille_maxi_block_archeops*2) return -1; 
-    // EA 150999 changed i+=4 to i++ -> unaligned, but can lose bytes in flight recorder
-#ifndef __DECCXX
-#define __unaligned 
-#endif
-     for (size_t i=4; i<read; i++) {
-      if (*(__unaligned int4*)(buffer+i) == debswp) {
-	cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
-	return pos+i;
-      }
-    }
-    pos += read;
-  }
-  cout << "cannot find block start" << endl;
-  return -1;
-}
-
-
+#ifdef __MWERKS__
+#pragma mark -
+#endif
 
 
@@ -762,5 +748,5 @@
 }
 
-void ArcheopsFile::setUTCOffset(int UTCOffset) {
+void ArcheopsFile::setUTCOffset(double UTCOffset) {
   utcOffset = UTCOffset;
   startMJD = rawMJD - utcOffset/24.;
@@ -771,346 +757,2 @@
 }
 
-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(&param->param, &reglage->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(&param->param, &reglage->reglage, lastbit, ibolo) -
-    bolo_muV(&param->param, &reglage->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(&param->param, &reglage->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(&param->param, &reglage->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(&param->param, &reglage->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;}
