Index: /trunk/Poubelle/archTOI.old/archeopsfile.cc
===================================================================
--- /trunk/Poubelle/archTOI.old/archeopsfile.cc	(revision 310)
+++ /trunk/Poubelle/archTOI.old/archeopsfile.cc	(revision 310)
@@ -0,0 +1,586 @@
+#define utilitaires_de_block_archeops
+#include "archeopsfile.h"
+#include "compress.h"
+#include <iostream.h>
+
+class BlockSet {
+public:
+  BlockSet();
+  BlockSet(BlockSet const&);
+  ~BlockSet();
+  void setBloc(block_type_modele const& blk);
+  void setRawBloc(block_type_modele const& blk);
+
+  block_type_param*         lastParam;
+  block_type_journal*       lastJournal;
+  block_type_reglage*       lastReglage;
+  block_type_dilution*      lastDilution;
+  block_type_gps*           lastGPS;
+  block_type_une_periode*   lastUnePeriode;
+  block_type_synchro_sol*   lastSynchroSol;
+  block_type_pointage_sol*  lastPointageSol;
+  block_type_bolo*          lastBolo;   // can be uncompressed bolo_comp
+  block_type_bolo*          llastBolo;   
+  block_type_gyro*          lastGyro;
+  block_type_sst*           lastSST;
+  block_type_bolo_comprime* lastBoloComp;   // can be uncompressed bolo_comp
+  block_type_gyro_comprime* lastGyroComp;
+  block_type_sst_comprime*  lastSSTComp;
+};
+
+BlockSet::BlockSet() {
+  lastParam      = NULL;
+  lastJournal    = NULL;
+  lastReglage    = NULL;
+  lastDilution   = NULL;
+  lastGPS        = NULL;
+  lastUnePeriode = NULL;
+  lastSynchroSol = NULL;
+  lastPointageSol= NULL;
+  lastBolo       = NULL;   
+  llastBolo      = NULL;   
+  lastGyro       = NULL;
+  lastSST        = NULL;
+  lastBoloComp   = NULL;   
+  lastGyroComp   = NULL;
+  lastSSTComp    = NULL;
+}
+
+BlockSet::~BlockSet() {
+  delete lastParam;
+  delete lastJournal;
+  delete lastReglage;
+  delete lastDilution;
+  delete lastGPS;
+  delete lastUnePeriode;
+  delete lastSynchroSol;
+  delete lastPointageSol;
+  delete lastBolo;   
+  delete llastBolo;   
+  delete lastGyro;
+  delete lastSST;
+  delete lastBoloComp;   
+  delete lastGyroComp;
+  delete lastSSTComp;
+}
+
+BlockSet::BlockSet(BlockSet const& x) {
+  lastParam      = NULL;
+  lastJournal    = NULL;
+  lastReglage    = NULL;
+  lastDilution   = NULL;
+  lastGPS        = NULL;
+  lastUnePeriode = NULL;
+  lastSynchroSol = NULL;
+  lastPointageSol= NULL;
+  lastBolo       = NULL;   
+  llastBolo      = NULL;   
+  lastGyro       = NULL;
+  lastSST        = NULL;
+  lastBoloComp   = NULL;   
+  lastGyroComp   = NULL;
+  lastSSTComp    = NULL;
+  if (x.lastParam) {
+    lastParam = new block_type_param;
+    *lastParam = *x.lastParam;
+  }
+  if (x.lastJournal) {
+    lastJournal = new block_type_journal;
+    *lastJournal = *x.lastJournal;
+  }
+  if (x.lastReglage) {
+    lastReglage = new block_type_reglage;
+    *lastReglage = *x.lastReglage;
+  }
+  if (x.lastDilution) {
+    lastDilution = new block_type_dilution;
+    *lastDilution = *x.lastDilution;
+  }
+  if (x.lastGPS) {
+    lastGPS = new block_type_gps;
+    *lastGPS = *x.lastGPS;
+  }
+  if (x.lastUnePeriode) {
+    lastUnePeriode = new block_type_une_periode;
+    *lastUnePeriode = *x.lastUnePeriode;
+  }
+  if (x.lastSynchroSol) {
+    lastSynchroSol = new block_type_synchro_sol;
+    *lastSynchroSol = *x.lastSynchroSol;
+  }
+  if (x.lastPointageSol) {
+    lastPointageSol = new block_type_pointage_sol;
+    *lastPointageSol = *x.lastPointageSol;
+  }
+  if (x.lastBolo) {
+    lastBolo = new block_type_bolo;
+    *lastBolo = *x.lastBolo;
+  }
+  if (x.llastBolo) {
+    llastBolo = new block_type_bolo;
+    *llastBolo = *x.llastBolo;
+  }
+  if (x.lastGyro) {
+    lastGyro = new block_type_gyro;
+    *lastGyro = *x.lastGyro;
+  }
+  if (x.lastSST) {
+    lastSST = new block_type_sst;
+    *lastSST = *x.lastSST;
+  }
+  if (x.lastBoloComp) {
+    lastBoloComp = new block_type_bolo_comprime;
+    *lastBoloComp = *x.lastBoloComp;
+  }
+  if (x.lastGyroComp) {
+    lastGyroComp = new block_type_gyro_comprime;
+    *lastGyroComp = *x.lastGyroComp;
+  }
+  if (x.lastSSTComp) {
+    lastSSTComp = new block_type_sst_comprime;
+    *lastSSTComp = *x.lastSSTComp;
+  }
+}
+
+void BlockSet::setBloc(block_type_modele const& blk)
+{
+  int kind = type_block(&blk);
+  switch (kind) {
+    case block_param:
+      if (!lastParam) lastParam = new block_type_param;
+      memcpy(lastParam, &blk, sizeof(block_type_param));
+      // Les fichiers fournis contiennent des valeurs debiles...
+      if (lastParam->param.n_max_bolo < 0)
+        lastParam->param.n_max_bolo = nb_max_bolo;
+      if (lastParam->param.n_per_block < 0)
+        lastParam->param.n_per_block = nb_per_block;
+      if (lastParam->param.n_max_mes_per < 0)
+        lastParam->param.n_max_mes_per = nb_max_mes_per;
+      break;
+    case block_journal:
+      if (!lastJournal) lastJournal = new block_type_journal;
+      memcpy(lastJournal, &blk, sizeof(block_type_journal));
+      break;
+    case block_reglage:
+      if (!lastReglage) lastReglage = new block_type_reglage;
+      memcpy(lastReglage, &blk, sizeof(block_type_reglage));
+      break;
+    case block_dilution:
+      if (!lastDilution) lastDilution = new block_type_dilution;
+      memcpy(lastDilution, &blk, sizeof(block_type_dilution));
+      break;
+    case block_gps:
+      if (!lastGPS) lastGPS = new block_type_gps;
+      memcpy(lastGPS, &blk, sizeof(block_type_gps));
+      break;
+    case block_une_periode:
+      if (!lastUnePeriode) lastUnePeriode = new block_type_une_periode;
+      memcpy(lastUnePeriode, &blk, sizeof(block_type_une_periode));
+      break;
+    case block_synchro_sol:
+      if (!lastSynchroSol) lastSynchroSol = new block_type_synchro_sol;
+      memcpy(lastSynchroSol, &blk, sizeof(block_type_synchro_sol));
+      break;
+    case block_pointage_sol:
+      if (!lastPointageSol) lastPointageSol = new block_type_pointage_sol;
+      memcpy(lastPointageSol, &blk, sizeof(block_type_pointage_sol));
+      break;
+    case block_bolo:
+      if (!lastBolo) lastBolo = new block_type_bolo;
+      else if (!llastBolo) {
+        llastBolo = new block_type_bolo;
+        memcpy(llastBolo, lastBolo, sizeof(block_type_bolo));
+      }
+      memcpy(lastBolo, &blk, sizeof(block_type_bolo));
+      break;
+    case block_gyro:
+      if (!lastGyro) lastGyro = new block_type_gyro;
+      memcpy(lastGyro, &blk, sizeof(block_type_gyro));
+      break;
+    case block_sst:
+      if (!lastSST) lastSST = new block_type_sst;
+      memcpy(lastSST, &blk, sizeof(block_type_sst));
+      break;
+  }
+}
+
+void BlockSet::setRawBloc(block_type_modele const& blk)
+{
+  int kind = type_block(&blk);
+  switch (kind) {
+    case block_bolo_comprime:
+      if (!lastBoloComp) lastBoloComp = new block_type_bolo_comprime;
+      memcpy(lastBoloComp, &blk, sizeof(block_type_bolo_comprime));
+      break;
+    case block_gyro_comprime:
+      if (!lastGyroComp) lastGyroComp = new block_type_gyro_comprime;
+      memcpy(lastGyroComp, &blk, sizeof(block_type_gyro_comprime));
+      break;
+    case block_sst_comprime:
+      if (!lastSSTComp) lastSSTComp = new block_type_sst_comprime;
+      memcpy(lastSSTComp, &blk, sizeof(block_type_sst_comprime));
+      break;
+  }
+}
+
+
+
+ArcheopsFile::ArcheopsFile(string const& fname) {
+  f = fopen(fname.c_str(), "rb");
+  fn = fname;
+  if (!f) throw ArchExc("file not found");
+  fseek(f,0,SEEK_END);
+  fLen = ftell(f);
+  curPos = 0;
+  curKind = -1;
+  curRawKind = -1;
+  blockSet = new BlockSet;
+  utcOffset=2;
+  computeMJD(fname);
+}
+
+ArcheopsFile::ArcheopsFile(ArcheopsFile const& x) {
+  blockSet = x.blockSet ? new BlockSet(*x.blockSet) : NULL;
+  fposStack = x.fposStack;
+  
+  stack<BlockSet*> tmp;
+  ArcheopsFile& y = (ArcheopsFile&) x;
+  while (!y.blockStack.empty()) {
+    tmp.push(y.blockStack.top());
+    y.blockStack.pop();
+  }
+  while (!tmp.empty()) {
+    y.blockStack.push(tmp.top());
+    blockStack.push(new BlockSet(*tmp.top()));
+    tmp.pop();
+  }
+
+  curBlock   = x.curBlock;
+  curKind    = x.curKind;
+  curRawKind = x.curRawKind;
+  curPos     = x.curPos;
+  fLen       = x.fLen;
+  fn         = x.fn;
+  f = fopen(fn.c_str(), "rb");
+}
+
+ArcheopsFile::~ArcheopsFile() {
+  if (f) fclose(f);
+  delete blockSet;
+  while (!blockStack.empty())
+    { delete blockStack.top(); blockStack.pop();}
+}
+
+void ArcheopsFile::grabLastBlocs(ArcheopsFile const& oldFile) {
+  delete blockSet;
+  blockSet = new BlockSet(*oldFile.blockSet);
+  setUTCOffset(oldFile.utcOffset);
+}
+
+
+def_nom_block
+
+bool ArcheopsFile::nextBlock() {
+  //if (curPos>0) saveCurBlock();
+  //if (curPos<0) curPos = 0;
+  if (curPos+12 > fLen) return false;
+  fseek(f,curPos,SEEK_SET);
+  size_t read = fread(&curBlock,1,sizeof(curBlock),f);
+  if (read < longueur_block(&curBlock)) return false;
+  if (verifie_block(&curBlock) != block_correct) {
+  printf("block invalide\n"); throw ArchExc("invalid block");
+  }
+  curRawKind = curKind = type_block(&curBlock);
+  curPos += longueur_block(&curBlock);
+  //printf("block %d  :  %s \n",numero_block(&curBlock),nom_block[curKind]);
+  postProcessBlock();
+  saveCurBlock();
+  return true;
+}
+
+bool ArcheopsFile::nextBlock(long mask) {
+  if (!mask) return false;
+  while (1) {
+    if (!nextBlock()) return false;
+    if (( 1 << curRawKind) & mask) return true;
+  }
+}
+
+int  ArcheopsFile::blockKind() {
+  return curKind;
+}
+
+int  ArcheopsFile::blockRawKind() {
+  return curRawKind;
+}
+
+int  ArcheopsFile::blockNum() {
+  return numero_block(&curBlock);
+}
+
+#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;
+  pp=lastReglage()->reglage.horloge.periode;
+  p=pp/5.;
+  f1=1000/p;f2=f1/bitmot;f3=f2*1000./(double)(lastReglage()->reglage.horloge.nb_mesures);
+  return 0.5/f3;					//  2 fois la frequence de modulation
+}
+
+double ArcheopsFile::perBlock() {  // duree (en secondes) correspondant a un bloc bolo
+  return perEchant() * (double)lastParam()->param.n_per_block*2.;
+}
+
+int ArcheopsFile::nEchBlock() {  // Nb d'echantillons dans un bloc
+  return lastParam()->param.n_per_block*2.;
+}
+
+string  ArcheopsFile::blockKdName() {
+  return nom_block[curKind];
+}
+
+string  ArcheopsFile::blockRawKdName() {
+  return nom_block[curRawKind];
+}
+
+
+block_type_modele*  ArcheopsFile::currentBlock() {
+  if (curPos<0) return NULL;
+  return &curBlock;
+}
+
+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::postProcessBlock() {
+  switch (curKind) {
+     case block_bolo_comprime: {
+       blockSet->setRawBloc(curBlock);
+       block_type_bolo blk2;
+       block_type_bolo_comprime* blk = (block_type_bolo_comprime*) &curBlock;
+       for(int j=0;j<nb_bolo_util;j++)	
+		{
+		   decompress_7_2(blk->data_bolo[j],blk2.data_bolo[j],nb_per_block*2);
+		}
+       valide_block((block_type_modele*)&blk2,block_bolo,numero_block(blk));	
+       memcpy(&curBlock,&blk2,sizeof(blk2));
+       curKind = block_bolo;
+       break;
+     }
+  }
+}
+
+void ArcheopsFile::saveCurBlock() {
+  blockSet->setBloc(curBlock);
+}
+
+void ArcheopsFile::pushMark() {    // push current file position, and "last" blocks`
+  fposStack.push(curPos);
+  blockStack.push(new BlockSet(*blockSet));
+}
+
+void ArcheopsFile::popMark() {    // pops last file position and "last" blocks
+  if (! blockStack.empty()) {
+    delete blockSet;
+    blockSet = blockStack.top();
+    curPos = fposStack.top();
+    blockStack.pop();
+    fposStack.pop();
+  }
+}
+
+static int mlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
+
+void ArcheopsFile::computeMJD(string const& fname) {
+  //h99_04_29-15h36m22
+  short y,m,d,hh,mm,ss;
+  char const* p = fname.c_str();
+  char const* p2 = p  + fname.length()-1;
+  while (*p2 != ':' && *p2 != '/' && p2 != p) p2--;
+  if (*p2 == ':' || *p2 == '/') p2++;
+  if (*p2 == 'h') p2++;
+  y  = atoi(p2); p2+=3;
+  m  = atoi(p2); p2+=3;
+  d  = atoi(p2); p2+=3;
+  hh = atoi(p2); p2+=3;
+  mm = atoi(p2); p2+=3;
+  ss = atoi(p2);
+  
+  if (y<50) y += 100;
+  // 1. depuis 0/1/97 minuit
+  rawMJD = (int) (365.25 * (y-97));
+  for (int i=0; i<m-1; i++)
+    rawMJD += mlen[i];
+  if (y%4 == 0 && m > 2) rawMJD++;
+  rawMJD += d;
+  rawMJD += hh/24. + mm/24./60. + ss/24./60./60;
+  
+  rawMJD += 448.5; // 0/1/97 minuit
+  startMJD = rawMJD - utcOffset/24.;
+}
+
+void ArcheopsFile::setUTCOffset(int UTCOffset) {
+  utcOffset = UTCOffset;
+  startMJD = rawMJD - utcOffset/24.;
+}
+
+double ArcheopsFile::getStartMJD() {
+  return startMJD;
+}
+
+// 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 -1;
+  char* p = lastGPS()->gps;
+  if (strncmp(p, "$GPGGA,", 7)) return -1;
+  p += 7;
+  double t;
+  sscanf(p, "%lg", &t);
+  int h = int(t/10000); t -= h*10000;
+  int m = int(t/100);   t -= m*100;
+  return h*3600. + m*60. + t;
+}
+
+double ArcheopsFile::getGPSMJD() {  // modified julian day du dernier bloc GPS, JD - 2450000
+  double t = getGPSUTC()/86400.;
+  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 99999;
+  char* p = lastGPS()->gps;
+  if (strncmp(p, "$GPGGA,", 7)) return 99999;
+  char* fence = p+80;
+  p += 7;
+  while (*p != ',' && p<fence) p++;
+  if (*p != ',') return 99999; 
+  p++;
+  double t;
+  sscanf(p, "%lg", &t);
+  int d = int(t/100); t -= d*100;
+  t = d + t/60;
+  while (*p != ',' && p<fence) p++;
+  if (*p != ',') return 99999; 
+  p++;
+  if (*p == 'S') t = -t;
+  return t;
+}
+
+double ArcheopsFile::getGPSLong() { // degres, +  = EST
+  if (!lastGPS()) return -1;
+  char* p = lastGPS()->gps;
+  if (strncmp(p, "$GPGGA,", 7)) return 99999;
+  char* fence = p+80;
+  p += 7;
+  for (int i=0; i<3; i++) {
+    while (*p != ',' && p<fence) p++;
+    if (*p != ',') return 99999; 
+    p++;
+  }
+  double t;
+  sscanf(p, "%lg", &t);
+  int d = int(t/100); t -= d*100;
+  t = d + t/60;
+  while (*p != ',' && p<fence) p++;
+  if (*p != ',') return 99999; 
+  p++;
+  if (*p == 'W') t = -t;
+  return t;
+}
+
+
+
+// Bolo
+
+long ArcheopsFile::getRawBolo(int ibolo, int imesure) {    // donnee brute, avec seulement soustraction offset
+  int nb_coups,aa;  
+  block_type_bolo* blk = imesure >= 0 ? lastBolo() : llastBolo();
+  if (imesure < 0) imesure += nEchBlock();
+  if (!blk) return 0;
+  block_type_reglage* reglage = lastReglage();
+  block_type_param* param = lastParam();
+  
+  nb_coups= reglage->reglage.horloge.nb_mesures/2 - reglage->reglage.horloge.temp_mort;
+  aa = (nb_coups<<14) + (nb_coups*190) ;
+  
+  int s = imesure % 2 ? 1 : -1;
+
+  return s*(((blk->data_bolo[ibolo][imesure]-aa)<<1)/nb_coups);
+}
+
+def_gains 
+
+double ArcheopsFile::getMuVBolo(int ibolo, int imesure) { // microvolts, filtre avec filtre carre
+  double y = (getRawBolo(ibolo, imesure-1) + getRawBolo(ibolo, imesure))/2.;
+  block_type_reglage* reglage = lastReglage();
+  return ((1e5*y)/(65536.*gain(reglage->reglage.bolo[ibolo])));
+}
+
+
+// SST, gyros...
+// $CHECK$ TBD
+
+
+double ArcheopsFile::getAzimut(int imesure) {return imesure*360/nEchBlock();}
+double ArcheopsFile::getPendDirect(int /*imesure*/) {return 0;}
+double ArcheopsFile::getPendOrth(int /*imesure*/) {return 0;}
+double ArcheopsFile::getAlpha(int /*imesure*/) {return 0;}
+double ArcheopsFile::getDelta(int /*imesure*/) {return 0;}
Index: /trunk/Poubelle/archTOI.old/archeopsfile.h
===================================================================
--- /trunk/Poubelle/archTOI.old/archeopsfile.h	(revision 310)
+++ /trunk/Poubelle/archTOI.old/archeopsfile.h	(revision 310)
@@ -0,0 +1,147 @@
+#ifndef ARCHEOPSFILE_H
+#define ARCHEOPSFILE_H
+
+#include <stdio.h>
+#include <string>
+#include <stack>
+
+#define _archeops		//  Acquisition Archeops (avec transputer) 
+#define programme
+
+extern "C" {
+#include "archeops.h"
+}
+
+enum {
+  block_param_mask = 1 << block_param,
+  block_journal_mask = 1 << block_journal,
+  block_reglage_mask = 1 << block_reglage,
+  block_dilution_mask = 1 << block_dilution,
+  block_gps_mask = 1 << block_gps,
+  block_une_periode_mask = 1 << block_une_periode,
+  block_synchro_sol_mask = 1 << block_synchro_sol,
+  block_pointage_sol_mask = 1 << block_pointage_sol,
+  block_bolo_nc_mask = 1 << block_bolo,
+  block_gyro_nc_mask = 1 << block_gyro,
+  block_sst_nc_mask = 1 << block_sst,
+  block_11_mask = 1 << block_11,
+  block_bolo_comprime_mask = 1 << block_bolo_comprime,
+  block_gyro_comprime_mask = 1 << block_gyro_comprime,
+  block_sst_comprime_mask = 1 << block_sst_comprime,
+  block_catalog_flash_mask = 1 << block_catalog_flash,
+  block_cmd_flash_mask = 1 << block_cmd_flash,
+  block_data_brute_mask = 1 << block_data_brute,
+  block_18_mask = 1 << block_18,
+  block_19_mask = 1 << block_19,
+
+  block_bolo_mask = block_bolo_nc_mask | block_bolo_comprime_mask,
+  block_gyro_mask = block_gyro_nc_mask | block_gyro_comprime_mask,
+  block_sst_mask = block_sst_nc_mask | block_sst_comprime_mask
+};
+
+class BlockSet;
+
+class ArchExc : public exception {
+public:
+  ArchExc(string s) : msg(s) {}
+  string Msg() {return msg;}
+protected:
+  string msg;
+};
+
+class ArcheopsFile {
+public:
+  ArcheopsFile(string const& fname);  // starting before first block
+  ArcheopsFile(ArcheopsFile const&);
+  virtual ~ArcheopsFile();
+  
+  void setUTCOffset(int UTCOffset=2); // StartMJD : decodage a partir du nom du bloc...
+  double getStartMJD();
+  
+  bool nextBlock();   // go to next block, true if block exists
+  bool nextBlock(long mask); // go to next block matching mask
+  int  blockKind();   // kind of the current bloc, enum in archeops.h
+  int  blockRawKind();   // kind of the current raw bloc, enum in archeops.h
+  int  blockNum();   // number (timestamp) of the current bloc
+  string blockKdName();
+  string blockRawKdName();
+  
+  double perEchant(); // periode d'echantillonage pour le dernier bloc reglage
+  double perBlock();  // duree (en secondes) correspondant a un bloc bolo
+                      // utilise infos dernier bloc param et dernier bloc reglage.
+  int nEchBlock(); // Nb d'echantillons dans un bloc bolo
+  
+  
+  void pushMark();    // push current file position, and "last" blocks
+  void popMark();     // pops last file position and "last" blocks
+  
+  void grabLastBlocs(ArcheopsFile const& oldFile);
+  
+  block_type_modele*  currentBlock(); // internal buffer
+  
+  block_type_param*         lastParam();  // saved blocks, including current
+  block_type_journal*       lastJournal();
+  block_type_reglage*       lastReglage();
+  block_type_dilution*      lastDilution();
+  block_type_gps*           lastGPS();
+  block_type_une_periode*   lastUnePeriode();
+  block_type_synchro_sol*   lastSynchroSol();
+  block_type_pointage_sol*  lastPointageSol();
+  block_type_bolo*          lastBolo();   // can be uncompressed bolo_comp
+  block_type_bolo*          llastBolo();   
+  block_type_gyro*          lastGyro();
+  block_type_sst*           lastSST();
+  block_type_bolo_comprime* lastBoloComp();   
+  block_type_gyro_comprime* lastGyroComp();
+  block_type_sst_comprime*  lastSSTComp();
+  
+  // Decodage des derniers blocs..
+  
+  // GPS
+  // On travaille en MJD = JD - 2450000.0, = 9 octobre 1995 midi UTC
+  // 1er juillet 1999 minuit UTC = JD 2451360.5,   MJD 1360.5 
+  int getGPSBlockNum();
+  double getGPSUTC();  // en secondes depuis minuit UTC
+  double getGPSMJD();  // modified julian day du dernier bloc GPS, JD - 2450000
+  double getGPSLat();  // degres, +  = NORD
+  double getGPSLong(); // degres, +  = EST
+  
+  // Bolo
+  long getRawBolo(int ibolo, int imesure);   // donnee brute, avec seulement soustraction offset
+  double getMuVBolo(int ibolo, int imesure); // microvolts, filtre avec filtre carre
+  
+  // SST, gyros, etc
+  
+  double getAzimut(int imesure);
+  double getPendDirect(int imesure);
+  double getPendOrth(int imesure);
+  
+  double getAlpha(int imesure);
+  double getDelta(int imesure);
+  
+  
+protected:
+  BlockSet*                 blockSet;
+  stack<BlockSet*>          blockStack;
+  stack<size_t>             fposStack;
+  
+  void saveCurBlock();
+  void postProcessBlock();
+  
+  void computeMJD(string const& fname);
+  
+  block_type_modele         curBlock;
+  int                       curKind;
+  int                       curRawKind;
+  size_t                    curPos;
+  size_t                    fLen;
+  FILE* f;
+  string fn;
+  
+  double rawMJD;   // decodage a partir du nom de fichier, sans application d'offset heure locale
+  double startMJD; // MJD du debut du fichier.
+  double utcOffset;
+private:
+};
+
+#endif
Index: /trunk/Poubelle/archTOI.old/compress.h
===================================================================
--- /trunk/Poubelle/archTOI.old/compress.h	(revision 310)
+++ /trunk/Poubelle/archTOI.old/compress.h	(revision 310)
@@ -0,0 +1,97 @@
+
+/************************************************************************/
+/*******   							*********/
+/*******   	compresseur de données rangées en ligne		*********/
+/*******  			 				*********/
+/************************************************************************/
+
+
+
+
+/*  	comprime une suite de n valeures  (dans des mots de 32 bit)	*/
+/*  		valeures  codées sur 22 bit maximum			*/
+/*	resultat de la compression codé sur 7 bit + exposant		*/
+/*	n doit etre multiple de  4					*/
+/*	le fichier resultat a pour longueur   n/4 + 1 mot de 32 bit	*/
+/*		4 * n  octets   ==>	n + 4 octets			*/
+/*	pour 	n = 72	  en sortie	19 mots = 76 octets		*/
+
+void compress_7_1(long* in,long*out,int n,int pasin);
+void decompress_7_1(long* in,long*out,int n);
+
+
+/*  	comprime une suite de n valeures  (dans des mots de 32 bit)	*/
+/*  		valeures  codées sur 16 bit maximum			*/
+/*	resultat de la compression codé sur 4 bit + exposant		*/
+/*	n doit etre  ( multiple de  7 )  + 2				*/
+/*	le fichier resultat a pour longueur   (n-2)/7 + 1 mot de 32 bit	*/
+/*		4 * n  octets   ==>	4 * (n-2) / 7 + 4  octets	*/
+/*	pour 	n = 72	  en sortie	11 mots = 44 octets		*/
+
+void compress_4_1(long* in,long*out,int n,int pasin);
+void decompress_4_1(long* in,long*out,int n);
+
+
+/*  	comprime une suite de n valeures  (dans des mots de 32 bit)	*/
+/*  		valeures  codées sur 16 bit maximum			*/
+/*	resultat de la compression codé sur 3 bit + exposant		*/
+/*	n doit etre  ( multiple de  9 )					*/
+/*	le fichier resultat a pour longueur   n/9 + 1 mot de 32 bit	*/
+/*		4 * n  octets   ==>	4 * n / 9 + 4  octets		*/
+/*	pour 	n = 72	  en sortie	9 mots = 36 octets		*/
+
+
+void compress_3_1(long* in,long*out,int n,int pasin);
+void decompress_3_1(long* in,long*out,int n);
+
+/************************************************************************/
+/***********   							*********/
+/***********   compresseur de données rangées par paires	*********/
+/***********		(data bolo par exemple)			*********/
+/***********   			 				*********/
+/************************************************************************/
+
+
+
+/*  	comprime une suite de n valeures  (dans des mots de 32 bit)	*/
+/*  		valeures  codées sur 21 bit maximum			*/
+/*	resultat de la compression codé sur 7 bit + exposant		*/
+/*	n doit etre multiple de  4					*/
+/*	le fichier resultat a pour longueur   n/4 + 1 mot de 32 bit	*/
+/*		4 * n  octets   ==>	n + 4 octets			*/
+/*	pour 	n = 72	  en sortie	19 mots = 76 octets		*/
+
+
+void compress_7_2(long* in,long*out,int n,int pasin);
+void decompress_7_2(long* in,long*out,int n);
+
+
+
+/*  	comprime une suite de n valeures  (dans des mots de 32 bit)	*/
+/*  		valeures  codées sur 32 bit maximum			*/
+/*	resultat de la compression codé sur 4 bit + exposant		*/
+/*	n doit etre  ( multiple de  7 )  + 2				*/
+/*	le fichier resultat a pour longueur   (n-2)/7 + 2 mot de 32 bit	*/
+/*		4 * n  octets   ==>	4 * (n-2) / 7 + 8  octets	*/
+/*	pour 	n = 72	  en sortie	12 mots = 48 octets		*/
+
+
+
+void compress_4_2(long* in,long*out,int n,int pasin);
+void decompress_4_2(long* in,long*out,int n);
+
+
+																						
+/************************************************************************/
+/***********   							*********/
+/***********   	definitions communes pour les compresseurs	*********/
+/***********   			 				*********/
+/************************************************************************/
+
+/*Les valeures de la table d'entree sont consideres comme toujopurs positives	*/
+/* les ecarts sont calculés signés sur 32 bit avant d'etre tronconnés		*/
+
+#define	shif(ec,k,q)	{while(ec>q)if(k<kmax_){k++;q<<=1;}else ec=q;while(ec<-q)if(k<kmax_){k++;q<<=1;}else ec=-q;}
+#define	recup(ec,sss,k) {ec=((R>>sss)&emak_);if(ec & sgbi_ ) ec|= sign_ ; ec<<=k;}
+#define	arrondi(ec,k)	((ec &  filtre[k]) +( (ec & test[k]) <<1 ) )	
+
Index: /trunk/Poubelle/archTOI.old/decompress.c
===================================================================
--- /trunk/Poubelle/archTOI.old/decompress.c	(revision 310)
+++ /trunk/Poubelle/archTOI.old/decompress.c	(revision 310)
@@ -0,0 +1,299 @@
+#include "compress.h"
+
+
+//*******************************************************************************************
+//****************   			 											*****************
+//****************   			 		decompress_3							*****************
+//****************   			 											*****************
+//*******************************************************************************************
+
+void  decom_3(long val,long* in,long*out,int n);
+
+#define kmax_	15		/*  valeur maximum de l'exposant	*/
+#define	kmak_	0xf		/*	masque pour l'exposant		*/
+#define	emak_	0x7		/*	masque pour l'ecart		*/		
+#define	sgbi_	0x4		/*	bit de signe de l'ecart		*/
+#define	sign_	0xfffffff8	/*	masque de signe de l'ecart	*/
+
+//  compress un tableau in de n*9 points disposé avec un pas pasin
+//  les data compressées sont ecrites dans le tableau out de n points
+//  la valeur val est la valeur de reference du point origine
+
+/*  comprime	9*n points  : 1er point dans 1er mot, tous les ecarts dans les n mots suivants		*/ 
+/*	9*n	==>	n+1	    pour  72 points :   9 mots			*/
+
+
+void decompress_3_1(long* in,long*out,int n)
+{
+long val;
+val=	*in;
+decom_3(val,in+1,out,n/9);
+}
+
+
+
+void  decom_3(long val,long* in,long*out,int n)
+{
+register long R;
+long ec1,ec2,ec3,ec4,ec5,ec6,ec7,ec8,ec9;
+int i,k;
+
+for(i=0;i<n;i++)
+	{
+	R=in[i];
+	k=R&kmak_;
+	recup(ec1,29,k); 
+	recup(ec2,26,k); 
+	recup(ec3,23,k); 
+	recup(ec4,20,k); 
+	recup(ec5,17,k); 
+	recup(ec6,14,k); 
+	recup(ec7,11,k);
+	recup(ec8,8,k);
+	recup(ec9,5,k);
+	
+	val+=ec1; 	out[i*9]=val;	 
+	val+=ec2;	out[i*9+1]=val;	 
+	val+=ec3;	out[i*9+2]=val;	 
+	val+=ec4;	out[i*9+3]=val;	 
+	val+=ec5;	out[i*9+4]=val;	 
+	val+=ec6;	out[i*9+5]=val;	 
+	val+=ec7;	out[i*9+6]=val;	 
+	val+=ec8;	out[i*9+7]=val;	 
+	val+=ec9;	out[i*9+8]=val;	 
+	}
+}
+
+
+
+//*******************************************************************************************
+//****************   			 											*****************
+//****************   			 		decompress_4							*****************
+//****************   			 											*****************
+//*******************************************************************************************
+
+void  decom_4(long val,long* in,long*out,int n);
+void  decom_4_paire(long val1,long val2,long* in,long*out,int n);
+
+#undef kmax_
+#undef	kmak_
+#undef	emak_		
+#undef	sgbi_
+#undef	sign_
+
+
+
+#define kmax_	15		/*  valeur maximum de l'exposant	*/
+#define	kmak_	0xf		/*	masque pour l'exposant		*/
+#define	emak_	0xf		/*	masque pour l'ecart		*/		
+#define	sgbi_	0x8		/*	bit de signe de l'ecart		*/
+#define	sign_	0xfffffff0	/*	masque de signe de l'ecart	*/
+
+
+/*  comprime	7*n + 2  points  (de 16 bit chacun)  				*/
+/*	1er et 2 eme point dans 1er mot, les ecarts dans les n mots suivants	*/ 
+/*	7*n + 2	==>	n+1	     ==>   pour  72 points :   11 mots  	*/
+
+
+void decompress_4_1(long* in,long*out,int n)
+{
+long val1,val2;
+val1=	( (*in & 0xffff0000)>>16 ) & 0x0000ffff;
+val2=	( (*in & 0x0000ffff)     )  & 0x0000ffff;
+out[0]=val1;
+out[1]=val2;
+decom_4(val2,in+1,out+2,n/7);
+}
+
+
+
+void  decom_4(long val,long* in,long*out,int n)
+{
+register long R;
+long ec1,ec2,ec3,ec4,ec5,ec6,ec7;
+int i,k;
+
+for(i=0;i<n;i++)
+	{
+	R=in[i];
+	k=R&kmak_;
+	recup(ec1,28,k); 
+	recup(ec2,24,k); 
+	recup(ec3,20,k); 
+	recup(ec4,16,k); 
+	recup(ec5,12,k); 
+	recup(ec6,8,k); 
+	recup(ec7,4,k);
+	
+	val+=ec1; 	out[7*i]=val;	 
+	val+=ec2;	out[7*i+1]=val;	 
+	val+=ec3;	out[7*i+2]=val;	 
+	val+=ec4;	out[7*i+3]=val;	 
+	val+=ec5;	out[7*i+4]=val;	 
+	val+=ec6;	out[7*i+5]=val;	 
+	val+=ec7;	out[7*i+6]=val;	 
+	}
+}
+
+/********************************************************************************************/
+
+/*  compresse en 4 bit mais par paire (pour data provenant de la detection synchrone)		*/
+
+/*     21 bit maleur maximum									*/
+/*  comprime	7*n+2 points  : 1er et 2eme point dans 1er et 2eme mot, suite dans n mots	*/
+/*		différences entre valeures paires  et entre valeures impaires uniquement	*/ 
+/*	7*n+2	==>	n+2		==>  pour 72 points :	12 mots				*/
+
+
+void decompress_4_2(long* in,long*out,int n)
+{
+long val1,val2;
+val1=in[0];		val2=in[1];
+out[0]=val1;	out[1]=val2;
+decom_4_paire(val1,val2,in+2,out+2,n/7);
+}
+
+
+void  decom_4_paire(long val1,long val2,long* in,long*out,int n)
+{
+register long R;
+long ec1,ec2,ec3,ec4,ec5,ec6,ec7;
+int i,k;
+
+for(i=0;i<n;i++)
+	{
+	R=in[i];
+	k=R&kmak_;
+	recup(ec1,28,k); 
+	recup(ec2,24,k); 
+	recup(ec3,20,k); 
+	recup(ec4,16,k); 
+	recup(ec5,12,k); 
+	recup(ec6,8,k); 
+	recup(ec7,4,k);
+	
+//	printf("i=%d  k=%d  ec= %d %d %d    \n",i,k,ec1,ec2,ec3);
+
+
+	val1+=ec1; 	out[7*i]=val1;	 
+	val2+=ec2;	out[7*i+1]=val2;	 
+	val1+=ec3;	out[7*i+2]=val1;	 
+	val2+=ec4;	out[7*i+3]=val2;	 
+	val1+=ec5;	out[7*i+4]=val1;	 
+	val2+=ec6;	out[7*i+5]=val2;	 
+	val1+=ec7;	out[7*i+6]=val1;
+	R=val1;val1=val2;val2=R;	 
+	}
+}
+
+
+//*******************************************************************************************
+//****************   			 											*****************
+//****************   			 		compress_7							*****************
+//****************   			 											*****************
+//*******************************************************************************************
+
+
+#undef kmax_
+#undef	kmak_
+#undef	emak_		
+#undef	sgbi_
+#undef	sign_
+
+
+
+#define kmax_	15		/*  valeur maximum de l'exposant	*/
+#define	kmak_	0xf		/*	masque pour l'exposant		*/
+#define	emak_	0x7f		/*	masque pour l'ecart		*/		
+#define	sgbi_	0x40		/*	bit de signe de l'ecart		*/
+#define	sign_	0xffffff80	/*	masque de signe de l'ecart	*/
+
+
+/*  comprime	4*n points  : 1er point dans 1er mot, tous les ecarts dans les n mots suivants		*/ 
+/*	4*n	==>	n+1	*/
+
+void  decom_7(long val,long* in,long*out,int n);
+
+void decompress_7_1(long* in,long*out,int n)
+{
+long val;
+val=*in;
+*out=val;
+decom_7(val,in+1,out,n/4);
+}
+
+
+
+/*  compress un tableau in de n*4 points disposé avec un pas pasin	*/
+/*  les data compressées sont ecrites dans le tableau out de n points	*/
+/*  la valeur val est la valeur de reference du point origine	*/
+
+void  decom_7(long val,long* in,long*out,int n)
+{
+register long R;
+long ec1,ec2,ec3,ec4;
+int i,k;
+
+for(i=0;i<n;i++)
+	{
+	R=in[i];
+	k=R&kmak_;
+	recup(ec1,25,k); 
+	recup(ec2,18,k); 
+	recup(ec3,11,k); 
+	recup(ec4,4,k); 
+	
+	val+=ec1; 	out[4*i]=val;	 
+	val+=ec2;	out[4*i+1]=val;	 
+	val+=ec3;	out[4*i+2]=val;	 
+	val+=ec4;	out[4*i+3]=val;	 
+	}
+}
+
+/********************************************************************************/
+/*  compresse en 7 bit mais par paire (pour data de la detection synchrone	*/
+/* 21 bit maleur maximum							*/
+/*  comprime	4*n points  : 1er et 2eme point dans 1er mot (16 bit chacun),	*/
+/*				 suite dans n mots				*/
+/*	différences entre valeures paires  et entre valeures impaires uniquement*/ 
+/*			4*n	==>	n+1					*/
+/********************************************************************************/
+
+void  decom_7_paire(long val1,long val2,long* in,long*out,int n);
+
+void decompress_7_2(long* in,long*out,int n)
+{
+long val1,val2;
+val1=	( (*in & 0xffff0000)>>11 ) & 0x001fffe0;
+val2=	( (*in & 0x0000ffff)<<5 )  & 0x001fffe0;
+/*printf("val1=%x  val2=%x  \n",val1,val2);*/
+decom_7_paire(val1,val2,in+1,out,n/4);
+}
+
+
+void  decom_7_paire(long val1,long val2,long* in,long*out,int n)
+{
+register long R;
+long ec1,ec2,ec3,ec4;
+int i,k;
+
+for(i=0;i<n;i++)
+	{
+	R=in[i];
+	k=R&kmak_;
+	recup(ec1,25,k); 
+	recup(ec2,18,k); 
+	recup(ec3,11,k); 
+	recup(ec4,4,k); 
+	
+	val1+=ec1; 	out[4*i]=val1;	 
+	val2+=ec2;	out[4*i+1]=val2;	 
+	val1+=ec3;	out[4*i+2]=val1;	 
+	val2+=ec4;	out[4*i+3]=val2;	 
+
+/*if(i<5)  printf("in=%x  i=%d  k=%d  ec= %x %x %x %x  \n",R,i,k,ec1,ec2,ec3,ec4);	*/
+
+	}
+}
+
+
Index: /trunk/Poubelle/archTOI.old/dirent.h
===================================================================
--- /trunk/Poubelle/archTOI.old/dirent.h	(revision 310)
+++ /trunk/Poubelle/archTOI.old/dirent.h	(revision 310)
@@ -0,0 +1,38 @@
+/* $Id: dirent.h,v 1.1.1.1 1999-05-25 08:25:53 ansari Exp $ */
+
+#ifndef _DIRENT_H
+#define _DIRENT_H
+
+#include <stat.h>
+
+typedef unsigned short			ushort_t;
+
+typedef struct {
+	short volrefnum;
+	long dirid;
+	int nextfile;
+} DIR;
+
+struct dirent {
+    ino_t    d_ino;               /* file number of entry */
+    ushort_t d_reclen;            /* length of this record */
+    ushort_t d_namlen;            /* length of string in d_name */
+	char d_name[FILENAME_MAX];
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+DIR *opendir(char const *);
+struct dirent *readdir(DIR *);
+int closedir(DIR *);
+void rewinddir(DIR*);
+//long telldir(DIR *);
+//void seekdir(DIR *, long);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: /trunk/Poubelle/archTOI.old/opendir.c
===================================================================
--- /trunk/Poubelle/archTOI.old/opendir.c	(revision 310)
+++ /trunk/Poubelle/archTOI.old/opendir.c	(revision 310)
@@ -0,0 +1,107 @@
+/* $Id: opendir.c,v 1.1.1.1 1999-05-25 08:25:53 ansari Exp $ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "dirent.h"
+
+#include <Files.h>
+#include <TextUtils.h>
+
+#include "errno.h"
+
+#define FALSE 0
+#define ENOENT          2               /* No such file or directory */
+#define EIO             5               /* I/O error */
+
+
+DIR *opendir(char const * path)
+{
+	CInfoPBRec cipbr;
+	HFileInfo *fpb = (HFileInfo*)&cipbr;
+	DirInfo *dpb = (DirInfo*)&cipbr;
+	DIR *dp;
+	char name[FILENAME_MAX];
+	short err;
+	FSSpec tempspec;
+	
+	strncpy(name, path, sizeof(name)-1);
+	c2pstr(name);
+	
+	err = FSMakeFSSpec(0,0,(unsigned char*)name,&tempspec);
+	
+	fpb->ioNamePtr= (unsigned char*)name;
+	fpb->ioVRefNum= 0;
+	fpb->ioFDirIndex= 0;
+	fpb->ioFVersNum= 0;
+	dpb->ioDrDirID= 0;
+	err= PBGetCatInfo(&cipbr, FALSE);
+	if (err != noErr) {
+		errno = ENOENT;
+		return NULL;
+	}
+	dp = (DIR*)calloc(1, sizeof(DIR));
+	if (dp != NULL) {
+		dp->volrefnum = tempspec.vRefNum;
+		dp->dirid = fpb->ioDirID;
+		dp->nextfile = 1;
+	}
+	return dp;
+}
+
+/*
+ * Close a directory.
+ */
+
+int closedir(DIR *dp)
+{
+	free(dp);
+	return 0;
+}
+
+/*
+ * Read the next directory entry.
+ */
+
+struct dirent *readdir(DIR *dp)
+{
+	CInfoPBRec cipbr;
+	HFileInfo *fpb = (HFileInfo*)&cipbr;
+	DirInfo *dpb = (DirInfo*)&cipbr;
+	short err;
+	static struct dirent dir;
+
+	fpb->ioDirID= dp->dirid;
+	fpb->ioNamePtr= (unsigned char*)dir.d_name;
+	fpb->ioVRefNum= dp->volrefnum;
+	fpb->ioFDirIndex= dp->nextfile++;
+	fpb->ioFVersNum= 0;
+	err= PBGetCatInfo(&cipbr, FALSE);
+	if (err != noErr) {
+		errno = EIO;
+		return NULL;
+	}
+	p2cstr((StringPtr)dir.d_name);
+	dir.d_namlen = strlen(dir.d_name);
+	dir.d_reclen = sizeof(dir);
+	dir.d_ino = 0;
+	return &dir;
+}
+
+void rewinddir(DIR *dp)
+{
+		dp->nextfile = 1;
+}
+
+/*
+long telldir(DIR *dp)
+{
+   return dp->nextfile;
+}
+
+void seekdir(DIR *dp, long location)
+{
+  dp->nextfile = location;
+}
+*/
Index: /trunk/Poubelle/archTOI.old/test.cp
===================================================================
--- /trunk/Poubelle/archTOI.old/test.cp	(revision 310)
+++ /trunk/Poubelle/archTOI.old/test.cp	(revision 310)
@@ -0,0 +1,42 @@
+
+#include <iostream.h>
+#include <iomanip.h>
+
+#include "archeopsfile.h"
+#include "toisvr.h"
+
+using namespace std;  //introduces namespace std
+
+int main()
+{	
+	TOISvr svr;
+	svr.SetFile("h99_04_29-15h36m22");
+	svr.AddInfo(boloTens,0);
+	svr.AddInfo(boloTens,1);
+	svr.AddInfo(boloTens,2);
+	svr.AddInfo(boloTens,3);
+	
+	TOIIter iter = svr.DoQuery();
+	while (iter.Next()) {
+	  cout << setprecision(15) << iter.getTime() << " " << 
+	    setprecision(4) << iter.getValue(0) << " " << iter.getValue(1) << " " <<
+	                       iter.getValue(2) << " " << iter.getValue(3) << "\n";
+	}
+	
+	/*
+    int nblk[20];
+    for (int i=0; i<20; i++) nblk[i] = 0;
+	cout << "opening" << endl;
+	//ArcheopsFile file("Stock:ARCHEOPS:h99_04_29-15h36m22");
+	ArcheopsFile file("h99_04_29-15h36m22");
+	cout << file.getStartMJD() << endl;
+	cout << "reading" << endl;
+	while (file.nextBlock()) {
+	  //cout << file.blockKdName() << " " << file.blockNum() << "\n";
+	  nblk[file.blockKind()]++;
+	}
+	cout << "done" << endl;
+    for (int i=0; i<20; i++) cout << i <<" " << nblk[i] << endl;
+    */
+}
+
Index: /trunk/Poubelle/archTOI.old/toiiter.cc
===================================================================
--- /trunk/Poubelle/archTOI.old/toiiter.cc	(revision 310)
+++ /trunk/Poubelle/archTOI.old/toiiter.cc	(revision 310)
@@ -0,0 +1,210 @@
+#include "toiiter.h"
+#include <dirent.h>
+
+// Format bloc GPS
+// $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,
+
+TOIIter::TOIIter() {
+ // Toutes les valeurs initialisees par defaut. Le TOISvr les positionnera,
+ // puis lancera l'initialisation
+ 
+ file = NULL;
+ directory = "";
+ fileName = "";
+ 
+ tStart = -9.e99;
+ tEnd   = -9.e99;
+ 
+ tBlock0 = -1;
+
+}
+
+TOIIter::TOIIter(TOIIter const& x) {
+  directory = x.directory;
+  fileName = x.fileName;
+  files = x.files;
+  curFile = x.curFile;
+  imes = x.imes;
+  tStart = x.tStart;
+  tEnd = x.tEnd;
+  tBlock0 = x.tBlock0;
+  trigMask = x.trigMask;
+  infos = x.infos;   
+
+  file = new ArcheopsFile(*x.file);
+}
+
+TOIIter::~TOIIter() {
+  delete file;
+}
+
+void TOIIter::Init() {
+  if (directory == "") {
+    file = new ArcheopsFile(fileName);
+  } else {
+    DIR* dir = opendir(directory.c_str());
+    struct dirent* ent;
+    while ((ent = readdir(dir)) != NULL) {
+      files.insert(ent->d_name);
+    }
+    closedir(dir);
+    curFile = files.begin();
+    file = new ArcheopsFile((*curFile).c_str());
+  }
+
+  if (!file->lastParam()) file->nextBlock(block_param_mask);
+  if (!file->lastReglage()) file->nextBlock(block_reglage_mask);
+  
+  // On cherche un bloc GPS pour avoir la correspondance timestamp/UTC.
+  // Pour le moment, on se fonde sur le premier bloc GPS. On pourra faire
+  // mieux en prenant le min de tous les delta_T.
+  
+    tBlock0 = file->getStartMJD();
+#if 0
+  file->pushMark();
+  if (file->lastGPS() || file->nextBlock(block_gps_mask)) {
+    // le temps du bloc courant, en secondes
+    double dt = file->blockNum() * file->perBlock();
+    tBlock0 = file->getGPSMJD() - dt/86400.;
+  } else { // pas de bloc GPS...
+    tBlock0 = file->getStartMJD();
+  }
+  file->popMark();
+#endif  
+  
+  trigMask = 0;
+  for (vector<info>::iterator i = infos.begin(); i != infos.end(); i++) {
+    if ((*i).triggering) {
+      switch ((*i).kind) {
+        case boloTens:
+        case boloRaw:
+          trigMask |= block_bolo_mask;
+          break;
+        case longitude:
+        case latitude:
+          trigMask |= block_gps_mask;
+          break;
+        case azimut:
+          trigMask |= block_sst_mask;
+          break;
+        case alpha:
+        case delta:
+          trigMask |= block_sst_mask;
+          break;
+      }
+    }
+  }
+  
+  if (trigMask & (block_bolo_mask | block_sst_mask)) {
+    imes = 9999;
+  } else {
+    imes = 0;
+  }
+}
+
+bool TOIIter::NextFile() {
+  if (directory == "") {
+    return false;
+  } else {
+    if (curFile == files.end()) return false;
+    curFile++;
+    if (curFile == files.end()) return false;
+    ArcheopsFile* newfile = new ArcheopsFile((*curFile).c_str());
+    newfile->grabLastBlocs(*file);
+    delete file;
+    file = newfile;
+    return true;
+  }
+}
+
+bool TOIIter::Next() {
+
+
+  // trigger sur info indexee dans bloc bolo ou bloc sst ?
+  if (trigMask & (block_bolo_mask | block_sst_mask)) {
+    imes++;
+    if (imes < file->nEchBlock()) return true;
+    imes = 0;
+  }
+  
+  // soit pas d'info indexee, soit fin bloc courant...
+  
+  if (file->nextBlock(trigMask)) {
+    return true;
+  }
+  if (!NextFile()) return false;
+  return file->nextBlock(trigMask);
+}
+
+ double TOIIter::getTime() {                // MJD 
+   // le temps du bloc courant, en secondes
+   double dt = file->blockNum() * file->perBlock();
+   return tBlock0 + dt/86400. + imes*file->perEchant()/86400.;
+ }
+ 
+ double TOIIter::getValue(int column) {
+   if (column < 0 || column >= infos.size()) return -1;
+   TOIKind kind = infos[column].kind;
+   int index = infos[column].index;
+   switch (kind) {
+     case boloTens:
+       return file->getMuVBolo(index, imes);
+     case boloRaw:
+       return file->getRawBolo(index, imes);
+     case longitude:
+       return file->getGPSLong(); // $CHECK$ TBD gerer interpolation (dans file)
+     case latitude:
+       return file->getGPSLat();  // $CHECK$ TBD gerer interpolation (dans file)
+      case azimut:
+       return file->getAzimut(imes);
+      case alpha:
+       return file->getAlpha(imes);
+      case delta:
+       return file->getDelta(imes);
+   }
+   return -1;
+ }
+ 
+ bool   TOIIter::newValue(int column) {
+   if (column < 0 || column >= infos.size()) return false;
+   TOIKind kind = infos[column].kind;
+   switch (kind) {
+     case boloTens:
+       return file->blockKind() == block_bolo;
+     case boloRaw:
+       return file->blockKind() == block_bolo;
+     case longitude:
+       return file->blockKind() == block_gps;
+     case latitude:
+       return file->blockKind() == block_gps;
+      case azimut:
+       return file->blockKind() == block_sst || file->blockKind() == block_bolo;
+      case alpha:
+       return file->blockKind() == block_sst || file->blockKind() == block_bolo;
+      case delta:
+       return file->blockKind() == block_sst || file->blockKind() == block_bolo;
+   }
+   return false;
+ }
+ 
+ bool   TOIIter::extendValue(int column) {
+   return !newValue(column);
+ }
+ 
+ bool   TOIIter::interpValue(int /*column*/) {
+   return false; // $CHECK$ TBD gerer interpolation
+ }
+ 
+ TOIKind TOIIter::getKind(int column) {
+   if (column < 0 || column >= infos.size()) return (TOIKind)-1;
+   return infos[column].kind;
+ }
+ 
+ int TOIIter::getIndex(int column) {
+   if (column < 0 || column >= infos.size()) return (TOIKind)-1;
+   return infos[column].index;
+ }
+   
+ int TOIIter::getSampleIndex() {
+   return imes;
+ }
Index: /trunk/Poubelle/archTOI.old/toiiter.h
===================================================================
--- /trunk/Poubelle/archTOI.old/toiiter.h	(revision 310)
+++ /trunk/Poubelle/archTOI.old/toiiter.h	(revision 310)
@@ -0,0 +1,89 @@
+#ifndef TOIITER_H
+#define TOIITER_H
+
+
+#include <vector>
+#include <set>
+#include <string>
+#include "archeopsfile.h"
+
+enum TOIKind {
+  boloTens,   // tension en microVolts, filtree avec filtre carre indexe par bolometre
+  boloRaw,    // tension brute, non filtree indexe par bolometre
+  longitude,  // ballon
+  latitude,   // ballon
+  azimut,     // a preciser, reconstruit SST, magneto, autres...
+  
+  alpha,      // sur le ciel, indexe par bolometre
+  delta       // sur le ciel, indexe par bolometre
+  
+};
+
+
+
+class TOIIter {
+public:
+   TOIIter(TOIIter const&);
+   ~TOIIter();
+   bool Next();
+   
+   double getTime();                // MJD 
+   double getValue(int column);
+   bool   newValue(int column);     // a juste change ?
+   bool   extendValue(int column);  // une valeur plus ancienne, etendue ?
+   bool   interpValue(int column);  // une valeur interpolee avec valeur future ?
+   TOIKind getKind(int column);
+   int     getIndex(int column);    // si plusieurs, exemple, tension bolo 2
+   
+   int    getSampleIndex();         // numero d'echantillon dans dernier bloc bolo
+
+   block_type_param*         lastParam();  
+   block_type_journal*       lastJournal();
+   block_type_reglage*       lastReglage();
+   block_type_dilution*      lastDilution();
+   block_type_gps*           lastGPS();
+   block_type_une_periode*   lastUnePeriode();
+   block_type_synchro_sol*   lastSynchroSol();
+   block_type_pointage_sol*  lastPointageSol();
+   block_type_bolo*          lastBolo();   
+   block_type_gyro*          lastGyro();
+   block_type_sst*           lastSST();
+   block_type_bolo_comprime* lastBoloComp();   
+   block_type_gyro_comprime* lastGyroComp();
+   block_type_sst_comprime*  lastSSTComp();
+
+protected:
+   TOIIter();
+   void Init(); // After setting the options, opens the first file.
+   
+   bool NextFile();
+   
+   ArcheopsFile* file;
+   string directory;   // If several files to be read
+   string fileName;    // If only one file to be read
+   set<string> files;  // list of files in the directory...
+   set<string>::iterator curFile;
+   
+   int imes;
+   
+   double tStart, tEnd;
+   
+   double tBlock0;  // MJD du bloc numero zero...
+   
+   struct info {
+     TOIKind kind;
+     int index;
+     bool triggering;
+     bool interpolated;
+   };
+   
+   long trigMask;
+   
+   vector<info>   infos;
+   
+   friend class TOISvr;
+   
+   private:
+};
+
+#endif
Index: /trunk/Poubelle/archTOI.old/toisvr.cc
===================================================================
--- /trunk/Poubelle/archTOI.old/toisvr.cc	(revision 310)
+++ /trunk/Poubelle/archTOI.old/toisvr.cc	(revision 310)
@@ -0,0 +1,37 @@
+#include "toisvr.h"
+
+TOISvr::TOISvr()
+{}
+
+void TOISvr::SetDirectory(string d) {
+  iter.directory = d;
+  iter.fileName = "";
+}
+
+void TOISvr::SetFile(string f) {
+  iter.directory = "";
+  iter.fileName = f;
+}
+  
+void TOISvr::SetTimeInterval(double tStart, double tEnd) {
+  iter.tStart = tStart;
+  iter.tEnd = tEnd;
+}
+  
+void TOISvr::AddInfo(TOIKind kind, int index, bool triggering, bool interp) {
+  TOIIter::info i;
+  i.kind = kind; 
+  i.index = index;
+  i.triggering = triggering;
+  i.interpolated= interp;
+  iter.infos.push_back(i);
+}
+
+void TOISvr::AddInfo(TOIKind kind, bool triggering, bool interp) {
+  AddInfo(kind,0,triggering,interp);
+}
+  
+TOIIter TOISvr::DoQuery() {
+  iter.Init();
+  return iter;
+}
Index: /trunk/Poubelle/archTOI.old/toisvr.h
===================================================================
--- /trunk/Poubelle/archTOI.old/toisvr.h	(revision 310)
+++ /trunk/Poubelle/archTOI.old/toisvr.h	(revision 310)
@@ -0,0 +1,26 @@
+#ifndef TOISVR_H
+#define TOISVR_H
+
+#include "toiiter.h"
+
+class TOISvr {
+public:
+  TOISvr();
+  
+  void SetDirectory(string);
+  void SetFile(string);
+  
+  void SetTimeInterval(double tStart, double tEnd);
+  
+  void AddInfo(TOIKind kind, int index, bool triggering=true, bool interp=false);
+  void AddInfo(TOIKind kind, bool triggering=true, bool interp=false);
+  
+  TOIIter DoQuery();
+  
+  
+protected:
+  TOIIter iter;
+};
+
+
+#endif
