Index: trunk/Poubelle/archTOI.old/archeopsfile.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archeopsfile.cc	(revision 432)
+++ trunk/Poubelle/archTOI.old/archeopsfile.cc	(revision 436)
@@ -9,4 +9,5 @@
 extern "C" {
 #include "compress.h"
+#include "arcunit.h"
 }
 #include <iostream.h>
@@ -257,4 +258,6 @@
 ArcheopsFile::ArcheopsFile(string const& fname) {
   f = fopen(fname.c_str(), "rb");
+  setvbuf(f, NULL, _IOFBF, 1024L*1024L);
+
   fn = fname;
   if (!f) throw ArchExc("file not found");
@@ -294,4 +297,5 @@
   fn         = x.fn;
   f = fopen(fn.c_str(), "rb");
+  setvbuf(f, NULL, _IOFBF, 1024L*1024L);
 
   rawMJD     = x.rawMJD;
@@ -867,73 +871,58 @@
 
 
-double ArcheopsFile::getRawBolo(int ibolo, int imesure) {    // donnee brute, avec seulement soustraction offset
-  int nb_coups,aa;  
+double ArcheopsFile::getBoloRawMuV(int ibolo, int imesure) {    // microvolts bruts
   block_type_bolo* blk = imesure >= 0 ? lastBolo() : llastBolo();
-  //cout << "raw " << imesure << " ";
   if (imesure < 0) imesure += nEchBlock();
+  block_type_reglage* reglage = lastReglage();
+  block_type_param*   param = lastParam();
   if (!blk) return 0;
-  block_type_reglage* reglage = lastReglage();
   if (!reglage) return 0;
-
-  nb_coups= reglage->reglage.horloge.nb_mesures/2 - reglage->reglage.horloge.temp_mort;
-  aa = (nb_coups<<14) + (nb_coups*190) ;
-  
+  if (!param) return 0;
+
   int s = imesure % 2 ? 1 : -1;
-  
-  //cout << s*(((val_DS(ibolo,imesure)-aa)<<1)/nb_coups) << "\n";
-
-  return s*(((val_DS(ibolo,imesure)-aa)<<1)/double(nb_coups));
-}
-
-double ArcheopsFile::getRawBoloCN(int ibolo, int imesure) {    
-  // Si pas bloc comprime -> 0
-  if (lastBoloComp() == NULL) return 0;
-  if (numero_block(lastBoloComp()) != numero_block(lastBolo())) return 0;
-  block_type_reglage* reglage = lastReglage();
-  if (!reglage) return 0;
-
-  int nb_coups= reglage->reglage.horloge.nb_mesures/2 - reglage->reglage.horloge.temp_mort;
-  unsigned int4* data = lastBoloComp()->data_bolo[ibolo];
-  // Les deux premieres valeurs sont codees directement...
-  if (imesure<2) return 0;
-  int iExp = (imesure-2)/4 + 1;
-  int expo = data[iExp] & 0xf;
-  int noise = 1 << expo;
-  return (noise << 1)/double(nb_coups)/2.;
-}
-
-
-
-def_gains 
-
-double ArcheopsFile::getMuVBolo(int ibolo, int imesure) { // microvolts, filtre avec filtre carre
-  double y = (getRawBolo(ibolo, imesure-1) + getRawBolo(ibolo, imesure))/2.;
-  //if (imesure%2) y=-y;
+    
+  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;
-  //cout << "muv " << imesure << " " << y << "\n";
-  return bol_micro_volt(y,(double)param->param.bolo[ibolo].bolo_gain*gain_ampli(reglage->reglage.bolo[ibolo]));
-  //return ((1e5*y)/(65536.*gain_ampli(reglage->reglage.bolo[ibolo])));
-}
-
-double ArcheopsFile::getMuVBoloCN(int ibolo, int imesure) { // microvolts, sur valeur unique 
-  double y = getRawBoloCN(ibolo, imesure);
-  block_type_reglage* reglage = lastReglage();
-  block_type_param*   param = lastParam();
-  if (!reglage) return 0;
-  if (!param) return 0;
-  return bol_micro_volt(y,(double)param->param.bolo[ibolo].bolo_gain*gain_ampli(reglage->reglage.bolo[ibolo]));
-}
-
-
-double ArcheopsFile::getMuVBolo2(int ibolo, int imesure) { // microvolts, filtre 
+  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;
+  //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;
@@ -941,5 +930,5 @@
   for (int i=1; i<=n; i++) {
     double x = -i;
-    double y = s*(getRawBolo(ibolo, imesure-i+1) - getRawBolo(ibolo, imesure-i))/2;
+    double y = s*(getBoloRawMuV(ibolo, imesure-i+1) - getBoloRawMuV(ibolo, imesure-i))/2;
     s = -s;
     sumx += x;
@@ -951,8 +940,42 @@
   double b = (sumy/n) - a*(sumx/n);
   s = imesure % 2 ? 1 : -1;
-  double y = getRawBolo(ibolo, imesure);
+  double y = getBoloRawMuV(ibolo, imesure);
   y = y-s*b;
-  return bol_micro_volt(y,(double)param->param.bolo[ibolo].bolo_gain*gain_ampli(reglage->reglage.bolo[ibolo]));
-}
+  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) {
@@ -960,33 +983,41 @@
 }
 
-#define capa(uu)	((parametr.bolo[uu].bolo_bebo==10)?0.000868 * (double)parametr.bolo[uu].bolo_capa:0.001 * (double)parametr.bolo[uu].bolo_capa)		// capa en pF
-#define pt_micA(uu)	((4096. * 22. * 20.) / capa(uu) )			//  pts / micro Amperes
-
-
-#define pt_micV(uu)	(((double)parametr.bolo[uu].bolo_diviseur) / 2441.)	// pts / microvolt
-
 
 double ArcheopsFile::getDACV(int ibolo) {
-  double dacV = dac_V(lastReglage()->reglage.bolo[ibolo]);
-  param_bolo& parametr = lastParam()->param;
-  return dacV / pt_micV(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) {
-  double dacI = dac_I(lastReglage()->reglage.bolo[ibolo]);
-  param_bolo& parametr = lastParam()->param;
-  return dacI / pt_micA(ibolo);
-}
-
-double ArcheopsFile::getMuVBolo2T(int ibolo, int imesure) {
-  return getMuVBolo2(ibolo, imesure) - getDACV(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 = getMuVBolo2T(ibolo, imesure); // microVolts
+  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
