Index: /trunk/AddOn/TAcq/branap.cc
===================================================================
--- /trunk/AddOn/TAcq/branap.cc	(revision 3937)
+++ /trunk/AddOn/TAcq/branap.cc	(revision 3938)
@@ -158,4 +158,5 @@
        << "    viscktt: compute visibilities and check TimeTag/FrameCounter\n "
        << "    mspec: compute and save mean spectra for each channel \n "
+       << "    bproc: run BRBaseProcessor for debug/printing (use -prt)  \n "
        << " -out OutPath: Output directory name \n"
        << " -nmean NMean: Number of packet used for spectra/visibility computation \n"
Index: /trunk/AddOn/TAcq/brbaseproc.cc
===================================================================
--- /trunk/AddOn/TAcq/brbaseproc.cc	(revision 3937)
+++ /trunk/AddOn/TAcq/brbaseproc.cc	(revision 3938)
@@ -39,4 +39,5 @@
   totprocnpaq_=0;
   setNameId("baseproc",0); 
+  SetPrintLevel();
 }
 
@@ -117,5 +118,5 @@
 	for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
 	  vpaq_[fib].Set(fbuff_[fib]+jp*paqsz);
-	  vfgok_[fib] = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
+	  vfgok_[fib]=vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
 	  if (!vfgok_[fib])  fgokallfibers_=false;
 	  if (procpaqsz>0)    vprocpaq_[fib] = fprocbuff_[fib]+jp*procpaqsz;
@@ -167,13 +168,21 @@
   //  return 0;
   /*    Exemple de code test  */
-  if ( totprocnpaq_ % 1000 == 0 ) {
-    cout << " BRBaseProcessor::Process() " << totprocnpaq_ << " FrameCnt=" ;
+  if ((prtlev_>0)&&(totprocnpaq_ %prtmodulo_==0))  {
+    cout << " BRBaseProcessor::Process(totnpaq=" << totprocnpaq_ << ")  ObsTime=" << getObsTime() 
+	 << " TimeTag=" << getCurTimeTagSeconds() << " s. FrameCounter="  << getCurFrameCounter() << endl;
+    if (prtlev_<2) return 0;
+    cout << " ... FrameCnt[0..." << memgr_.NbFibres()-1 << "]=" ;
     for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)   
-      cout << curfc_[fib] << "," ;
+      cout << getCurFrameCounter(fib) << "," ;
     cout << endl;
-    cout << " TimeTag : " ;
+    cout << " ... TimeTag[0..." << memgr_.NbFibres()-1 << "]=" ;
     for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)   
-      cout << vpaq_[fib].TimeTag()/125000000 << "," ;
-      cout << "   seconds" << endl;
+      cout << getCurTimeTag(fib) << "," ;
+    cout << endl;
+    if (prtlev_<3) return 0;
+    cout << " ... TimeTagSeconds[0..." << memgr_.NbFibres()-1 << "]=" ;
+    for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)   
+      cout << getCurTimeTagSeconds(fib) << "," ;
+    cout << endl;
   }
   return 0;
Index: /trunk/AddOn/TAcq/brbaseproc.h
===================================================================
--- /trunk/AddOn/TAcq/brbaseproc.h	(revision 3937)
+++ /trunk/AddOn/TAcq/brbaseproc.h	(revision 3938)
@@ -30,5 +30,6 @@
 
   virtual void run();
-  inline void Stop();
+
+  inline void Stop() { stop_ = true; }	
   inline void STOP() { stop_ = true; }	
 
@@ -37,4 +38,22 @@
   inline void setNameId(string nom, int id) 
   { bpnom_=nom;   bpid_=id;  }
+
+  // get Observation Time ( obtained from MemZoneMgr )
+  inline SOPHYA::TimeStamp& getObsTime()  { return cts_; }
+  // Renvoie le numero de frame-counter courant - si fgz=true, soustrait le FC du premier paquet 
+  inline uint_8 getCurFrameCounter(size_t fib=0, bool fgz=true) 
+  { if (fgz) return (curfc_[fib]-fcfirst_[fib]) ;  else return curfc_[fib]; }
+  // Renvoie le TimeTag courant (unite coups d'horloge) - si fgz=true, soustrait le TT du premier paquet 
+  inline uint_8 getCurTimeTag(size_t fib=0, bool fgz=true) 
+  { if (fgz) return (vpaq_[fib].TimeTag()-ttfirst_[fib]) ;  else return vpaq_[fib].TimeTag(); }
+  // Renvoie le TimeTag courant converti en secondes  - si fgz=true, soustrait le TT du premier paquet 
+  inline double getCurTimeTagSeconds(size_t fib=0, bool fgz=true) 
+  { 
+    if (fgz) return ((double)(vpaq_[fib].TimeTag()-ttfirst_[fib])/1.25e8) ;  
+    else return ((double)vpaq_[fib].TimeTag()/1.25e8); 
+  }
+  //---- niveau d'impression 
+  inline void SetPrintLevel(int lev=0, uint_8 prtmodulo=10) 
+    { prtlev_=lev;   prtmodulo_=prtmodulo;}
 
 protected:
@@ -53,8 +72,8 @@
   vector<uint_8> vfgok_;    // Vecteur de flag si paquet OK pour chaque fibre
   vector<uint_8> curfc_;    // Vecteur de numero de FrameCounter pour chaque fibre
-  vector<uint_8> fcfirst_;  // 
-  vector<uint_8> ttfirst_;
+  vector<uint_8> fcfirst_;  // numero du FrameCounter pour le premier paquet 
+  vector<uint_8> ttfirst_;  // TimeTag pour le premier paquet 
   bool fgokallfibers_;      // true -> paquets for all fibers OK
-
+  
   uint_8 totprocnpaq_; 
   SOPHYA::TimeStamp cts_;   // current time stamp, get from MemZoneMgr
@@ -62,4 +81,7 @@
   string bpnom_;    // nom du processeur
   int bpid_;        // numero d'identificateur 
+
+  int prtlev_;    // print level 
+  uint_8 prtmodulo_;   // print periodicity (modulo) 
 };
 
Index: /trunk/AddOn/TAcq/brfitsrd.cc
===================================================================
--- /trunk/AddOn/TAcq/brfitsrd.cc	(revision 3937)
+++ /trunk/AddOn/TAcq/brfitsrd.cc	(revision 3938)
@@ -57,12 +57,20 @@
     // Extraction de qques parametres utiles depuis les fichiers FITS 
     string fkvs;
+    cpaqdeltatime_=0.;
     if (fib==0) {
       fkvs=mff_[fib].GetKeyValue("DATEOBS");
-      if (fkvs.length()>0) { 
-	cdateobs_.Set(fkvs);
-	cout << " BRMultiFitsReader/First file (for fiber 0) DATEOBS=" << fkvs << endl;
-      }
-    }
-    fkvs=mff_[fib].GetKeyValue("DATEOBS");
+      if (fkvs.length()>0)  cdateobs_.Set(fkvs);
+      fkvs=mff_[fib].GetKeyValue("TMSTART");
+      if (fkvs.length()>0) {
+	ctmstart_.Set(fkvs);
+	cout << " BRMultiFitsReader/First file (for fiber 0) TMSTART=" << fkvs << endl;
+	fkvs=mff_[fib].GetKeyValue("TMEND");
+	SOPHYA::TimeStamp tmend_=ctmstart_;
+	if (fkvs.length()>0) tmend_.Set(fkvs);
+	cpaqdeltatime_=((double)(tmend_.DaysPart()-cdateobs_.DaysPart())*86400.+
+			(tmend_.SecondsPart()-cdateobs_.SecondsPart()))/(double)mff_[fib].NAxis2();
+      }
+    }
+    fkvs=mff_[fib].GetKeyValue("FIBERNUM");
     memgr_.FiberId(fib) = atoi( fkvs.c_str() );
 
@@ -222,4 +230,14 @@
 	string fkvs=mff_[fib].GetKeyValue("DATEOBS");
 	if (fkvs.length()>0)  cdateobs_.Set(fkvs);
+	fkvs=mff_[fib].GetKeyValue("TMSTART");
+	if (fkvs.length()>0) {
+	  ctmstart_.Set(fkvs);
+	  cout << " BRMultiFitsReader/First file (for fiber 0) TMSTART=" << fkvs << endl;
+	  fkvs=mff_[fib].GetKeyValue("TMEND");
+	  SOPHYA::TimeStamp tmend_=ctmstart_;
+	  if (fkvs.length()>0) tmend_.Set(fkvs);
+	  cpaqdeltatime_=((double)(tmend_.DaysPart()-cdateobs_.DaysPart())*86400.+
+			  (tmend_.SecondsPart()-cdateobs_.SecondsPart()))/(double)mff_[fib].NAxis2();
+	}
       } 
       vfpos_[fib]=0;
@@ -254,4 +272,6 @@
   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)
     mmbufib_[fib]=memgr_.GetMemZone(mid_,fib);
+  // Definition temps pour la zone a remplir 
+  memgr_.GetAuxData(mid_)->FillTime().Set(ctmstart_.ToDays()+cpaqdeltatime_*(double)vfpos_[0]/86400.);
   return false;
 }
Index: /trunk/AddOn/TAcq/brfitsrd.h
===================================================================
--- /trunk/AddOn/TAcq/brfitsrd.h	(revision 3937)
+++ /trunk/AddOn/TAcq/brfitsrd.h	(revision 3938)
@@ -80,5 +80,7 @@
   Byte* mmbufib_[MAXANAFIB];  // Pointeurs zone memoire de chaque fibre rendu par RAcqMemZoneMgr 
 
-  SOPHYA::TimeStamp cdateobs_;    // current time/date read from file 
+  SOPHYA::TimeStamp cdateobs_;    // current file time/date  (from DATEOBS keyword in fits file)
+  SOPHYA::TimeStamp ctmstart_;    // current time/date read from file (from TMSTART keyword in fits file)
+  double cpaqdeltatime_;          // current time laps between two paquets in file = (TMEND-TMSTART)/NAXIS2
  
   int prtlev_;         // print level 
Index: /trunk/AddOn/TAcq/brproc.cc
===================================================================
--- /trunk/AddOn/TAcq/brproc.cc	(revision 3937)
+++ /trunk/AddOn/TAcq/brproc.cc	(revision 3938)
@@ -76,20 +76,5 @@
   ofsdtp_=NULL;
   dtp_=NULL;
-  string dtfile="!"+outpath_+"/dtspec.fits";
-  ofsdtp_ = new FitsInOutFile(dtfile,FitsInOutFile::Fits_Create);
-  dtp_ = new SwFitsDataTable(*ofsdtp_,1024,true);
-  char cnom[32];
-  for(int i=0; i<nchan; i++) {
-    sprintf(cnom,"variance%d",i);
-    dtp_->AddFloatColumn(cnom);    
-  }
-  /*
-  for(int i=0; i<nchan; i++) {
-    sprintf(cnom,"sigma%d",i);
-    dtp_->AddFloatColumn(cnom);    
-  }
-  */
-  xnt_=new double[nchan*2];
-
+  xnt_=new double[nchan*2];  // CHECK : ATTENTION la taille depend de nombre de colonne du NTuple !
 }
 
@@ -108,6 +93,6 @@
     delete dtp_;
     delete ofsdtp_;
-    delete xnt_;
-  }
+  }
+  if (xnt_)   delete xnt_;
   cout << " ------------------------------------------------------------------------ " << endl;
 }
@@ -138,4 +123,25 @@
 
 /* --Methode-- */
+void BRMeanSpecCalculator::DefineDataTable()
+{
+  string dtfile="!"+outpath_+"/dtspec.fits";
+  ofsdtp_ = new FitsInOutFile(dtfile,FitsInOutFile::Fits_Create);
+  dtp_ = new SwFitsDataTable(*ofsdtp_,1024,true);
+  char cnom[32];
+  size_t nchan=(fgsinglechannel_?memgr_.NbFibres():2*memgr_.NbFibres());
+  for(int i=0; i<nchan; i++) {
+    sprintf(cnom,"variance%d",i);
+    dtp_->AddFloatColumn(cnom);    
+  }
+  /*
+  for(int i=0; i<nchan; i++) {
+    sprintf(cnom,"sigma%d",i);
+    dtp_->AddFloatColumn(cnom);    
+  }
+  */
+  //  xnt_=new double[nchan*2];  CHECK : faut-il reallouer ?
+}
+
+/* --Methode-- */
 void BRMeanSpecCalculator::ReadGainFitsFile(string filename, bool fgapp)
 {
@@ -212,7 +218,17 @@
 void BRMeanSpecCalculator::ProcSpecWin(uint_8 numpaqstart, uint_8 numpaqend)
 {
-  //DBG  cout << "BRMeanSpecCalculator::ProcSpecWin()/Debug: numpaqstart=" << numpaqstart 
-  //DBG     << " numpaqend=" << numpaqend << endl;
-
+
+  if (prtlev_>0)  {
+    uint_8 modulo =  prtmodulo_/GetSpectraWindowSize();
+    if (modulo<1) modulo=1;
+    if (nbtot_specwin_%modulo==0) {
+      cout << " BRMeanSpecCalculator::ProcSpecWin() num_win=" << nbtot_specwin_ << " numpaqstart=" << numpaqstart 
+	   << " numpaqend=" << numpaqend << endl;
+      cout << " ... ObsTime=" << getObsTime() << " TimeTag=" << getCurTimeTagSeconds() << " s. FrameCounter=" 
+	   << getCurFrameCounter() << endl;
+    }
+  }
+  nbtot_specwin_++;
+  return;
   // On appelle la routine de nettoyage qui doit flagger les mauvais paquets 
   FlagBadPackets(numpaqstart, numpaqend);
@@ -255,10 +271,10 @@
       double variance=0.;
       variance=spec_window_(Range(1,Range::lastIndex()), Range(i), Range(kz)).Sum();
-      xnt_[i]=variance;
+      //      xnt_[i]=variance;
       clnflg_(i,kz)=0;
       if (variance<varmin_) { clnflg_(i,kz)=1;  nbadpaq_[i]++; }
       else if (variance>varmax_) { clnflg_(i,kz)=2;  nbadpaq_[i]++; }
     }
-  dtp_->AddRow(xnt_);
+    if (dtp_)  dtp_->AddRow(xnt_);
   }
   return;
Index: /trunk/AddOn/TAcq/brproc.h
===================================================================
--- /trunk/AddOn/TAcq/brproc.h	(revision 3937)
+++ /trunk/AddOn/TAcq/brproc.h	(revision 3938)
@@ -26,4 +26,5 @@
 
 using namespace std;
+
 
  
@@ -51,6 +52,9 @@
   inline sa_size_t PaqNumToArrayIndex(uint_8 numpaq)  { return numpaq%spec_window_.SizeZ() ; }
 
-// Pour definir le nombre maximum de fichiers de fenetres de spectres 
+// Pour definir le nombre maximum de fichiers de fenetres de spectres a sauver sur fichiers
   inline void SetMaxNbSepcWinFiles(uint_4 nmax=0)  {  nmaxfiles_specw_=nmax; }
+
+// Pour definir le datatable a remplir - pas de DataTable rempli si pas appele 
+  virtual void DefineDataTable();
 
   inline void SetVarianceLimits(double vmin=0., double vmax=9.e99)
Index: /trunk/AddOn/TAcq/specmfib.cc
===================================================================
--- /trunk/AddOn/TAcq/specmfib.cc	(revision 3937)
+++ /trunk/AddOn/TAcq/specmfib.cc	(revision 3938)
@@ -50,6 +50,6 @@
     if (rc) return rc;
     par.Print(cout);
-    if ((par.action_!="cube3d")&&(par.action_!="mspec")) {
-      cout << " !!! specmfib.cc  BAD action = " << par.action_ << " possible values: mspec,cube3d" << endl;
+    if ((par.action_!="cube3d")&&(par.action_!="mspec")&&(par.action_!="bproc")) {
+      cout << " !!! specmfib.cc  BAD action = " << par.action_ << " possible values: mspec,cube3d,bproc" << endl;
       return 5;
     }   
@@ -74,4 +74,6 @@
     procms.SetVarianceLimits(par.vmin_, par.vmax_);
     if (par.gainfile_.length()>0) procms.ReadGainFitsFile(par.gainfile_);
+    procms.SetPrintLevel(par.prtlevel_,par.prtmodulo_);
+    // Il faut appeler procms.DefineDataTable() si on veut remplir le DataTable
 
     BRFFTCalculator procfft(mmgr, par.fgsinglechannel_);
@@ -83,4 +85,11 @@
     FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_);
 
+    BRBaseProcessor* bproc_p=NULL; 
+    if (par.action_=="bproc") { 
+       bproc_p = new BRBaseProcessor(mmgr);
+       bproc_p->SetPrintLevel(par.prtlevel_,par.prtmodulo_);
+       if (!par.fgdatafft_)  bproc_p->SetMemZAction(MemZA_ProcB);
+    }
+
     cout << " specmfib: Starting threads (reader meanSpecCalculator ...) ... " << endl;
     reader.start();
@@ -88,5 +97,6 @@
     else {  // Calcul spectre moyenne 
       if (!par.fgdatafft_)  procfft.start(); 
-      procms.start();
+      if (par.action_=="bproc")  bproc_p->start();
+      else procms.start();
     }
     usleep(200000);
@@ -95,7 +105,9 @@
     else {
       if (!par.fgdatafft_)  procfft.join(); 
-      procms.join();
+      if (par.action_=="bproc")  bproc_p->join();
+      else procms.join();
     }
     mmgr.Print(cout);
+    if (bproc_p) delete bproc_p;
     cout << resu ; 
   }
Index: /trunk/AddOn/TAcq/svv2mtx.cc
===================================================================
--- /trunk/AddOn/TAcq/svv2mtx.cc	(revision 3937)
+++ /trunk/AddOn/TAcq/svv2mtx.cc	(revision 3938)
@@ -173,17 +173,30 @@
 
   cout << " ---- ProcSVFiles()-Begin - Reading chanum vector" << endl;
-  TVector< uint_4 > chanum;
+  /*
+  TVector< uint_4 > chanum(8*17);
+  int ku=0; 
+  for(int iu=1; iu<=16; iu++) 
+    for(int ju=iu; ju<=16; ju++)  {
+      chanum(ku)=iu*1000+ju;  ku++;
+    }
+  */
+  TVector< uint_4 > chanum;      
   {
-  sprintf(fname, "%s/chanum.ppf",inoutpath.c_str());
+  sprintf(fname, "%s/chanum_0.ppf",inoutpath.c_str());
   PInPersist pic(fname);
-  pic >> chanum;
-  }
-
+  pic >> PPFNameTag("chanpairnum") >> chanum;
+  }
+  
   cout << " ---- ProcSVFiles()-Read chanum done " << endl;
   sa_size_t nrows = (imax-imin+1)/istep;
   sa_size_t kr=0;
 
+  sa_size_t mtf_binfreq=25;
+  sa_size_t mtf_bintime=5;
+
+  sa_size_t ncols=1;
+
   for(int ifile=imin; ifile<=imax; ifile+=istep) {
-    sprintf(fname, "%s/vismtx%d.ppf",inoutpath.c_str(),ifile);
+    sprintf(fname, "%s/vismtx_0_%d.ppf",inoutpath.c_str(),ifile);
     cout << " ProcSVFiles[" << ifile << "] opening file " << fname << endl;
     PInPersist pin(fname);
@@ -192,13 +205,22 @@
 
     if (ifile==imin) {
-      sa_size_t ncols = vismtx.NCols();
+      ncols = vismtx.NCols();
       cout << " ProcSVFilesVJun09/Info: Output Time-Frequency matrices NRows=NFiles" 
            << nrows << " NCols=NFreq=" << ncols << endl;
       for(size_t j=0; j<rowlist.size(); j++)   
-	vmtf.push_back(TMatrix< complex<r_4> >(nrows, ncols) );
-    }
+	vmtf.push_back(TMatrix< complex<r_4> >(ncols/mtf_binfreq+1, nrows/mtf_bintime+1));
+    }
+    /*
     for(size_t j=0; j<rowlist.size(); j++) 
       vmtf[j].Row(kr) = vismtx.Row(rowlist[j]);
+    */
+    for(size_t j=0; j<rowlist.size(); j++) 
+      for(sa_size_t icf=0; icf<ncols; icf++)  {
+	vmtf[j](icf/mtf_binfreq,kr/mtf_bintime)+=vismtx(rowlist[j],icf);
+    }
+    //    cout << " DBG* kr=" << kr << " kr/mtf_bintime=" << kr/mtf_bintime 
+    //	   << " ncols/2/mtf_binfreq=" << ncols/2/mtf_binfreq << endl;
     kr++;
+
      
 // Calcul moyenne dans des bandes en frequence 
