Index: /trunk/AddOn/TAcq/branap.cc
===================================================================
--- /trunk/AddOn/TAcq/branap.cc	(revision 3773)
+++ /trunk/AddOn/TAcq/branap.cc	(revision 3774)
@@ -120,7 +120,8 @@
     return 5;
   }
-  cout << " -act Action: cube3d or vis or viscktt  \n"
+  cout << " -act Action: cube3d or vis or viscktt or mspec \n"
        << "    cube3d: create 3D fits cubes, vis: compute visibilites,  \n" 
        << "    viscktt: compute visibilities and check TimeTag/FrameCounter\n "
+       << "    mspec: compute and save mean spectra for each channel \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 3773)
+++ /trunk/AddOn/TAcq/brbaseproc.cc	(revision 3774)
@@ -17,8 +17,9 @@
 
 /* --Methode-- */
-BRBaseProcessor::BRBaseProcessor(RAcqMemZoneMgr& memgr)
+BRBaseProcessor::BRBaseProcessor(RAcqMemZoneMgr& memgr, MemZaction mmact)
   : memgr_(memgr), vpaq_(memgr.NbFibres()), vpchk_(memgr.NbFibres()), vfgok_(memgr.NbFibres()), 
     curfc_(memgr.NbFibres()), fcfirst_(memgr.NbFibres()), ttfirst_(memgr.NbFibres())
 {
+  SetMemZAction(mmact);
   stop_ = false;
   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
@@ -33,4 +34,36 @@
   fgokallfibers_=true;
   totprocnpaq_=0;
+}
+
+/* --Methode-- */
+MemZStatus BRBaseProcessor::SetMemZAction(MemZaction mmact)
+{
+  mmact_=mmact;
+  mmsta_=MemZS_ProcA;
+  switch (mmact) {
+  case MemZA_ProcA:
+    mmsta_=MemZS_ProcA;    
+    break;
+  case MemZA_ProcB:
+    mmsta_=MemZS_ProcB;    
+    break;
+  case MemZA_ProcC:
+    mmsta_=MemZS_ProcC;    
+    break;
+  case MemZA_ProcD:
+    mmsta_=MemZS_ProcD;    
+    break;
+  case MemZA_ProcE:
+    mmsta_=MemZS_ProcE;    
+    break;
+  case MemZA_ProcF:
+    mmsta_=MemZS_ProcF;    
+    break;
+  default:
+    mmact_=MemZA_ProcA;
+    mmsta_=MemZS_ProcA;
+    break;
+  }
+  return mmsta_;
 }
 
@@ -49,5 +82,5 @@
       if (stop_) break;
       if (memgr_.GetRunState() == MemZR_Stopped) break;
-      int mid = memgr_.FindMemZoneId(MemZA_ProcA);
+      int mid = memgr_.FindMemZoneId(mmact_);  // (MemZA_ProcA);
       Byte* buffg = memgr_.GetMemZone(mid);
       if (buffg == NULL) {
@@ -85,5 +118,5 @@
 	//	if (rcp != 0)   { fgrun=false; break; }
       }  // Fin de boucle sur les paquets 
-      memgr_.FreeMemZone(mid, MemZS_ProcA);
+      memgr_.FreeMemZone(mid, mmsta_);   // (MemZS_ProcA);
     } // Fin de boucle sur les zones a traiter 
     //------------------------------------
Index: /trunk/AddOn/TAcq/brbaseproc.h
===================================================================
--- /trunk/AddOn/TAcq/brbaseproc.h	(revision 3773)
+++ /trunk/AddOn/TAcq/brbaseproc.h	(revision 3774)
@@ -24,5 +24,7 @@
 class BRBaseProcessor : public SOPHYA::ZThread {
 public:	
-  BRBaseProcessor(RAcqMemZoneMgr& memgr);
+  BRBaseProcessor(RAcqMemZoneMgr& memgr, MemZaction mmact=MemZA_ProcA);
+  
+  MemZStatus SetMemZAction(MemZaction mmact=MemZA_ProcA);
 
   virtual void run();
@@ -35,4 +37,6 @@
 
   RAcqMemZoneMgr& memgr_;
+  MemZaction mmact_;    // Definition de l'action sur les paquets (defaut=MemZA_ProcA)
+  MemZStatus mmsta_;    // Statut associe a mmact_ (defaut=MemZS_ProcA)
   bool stop_;
   vector<Byte*> fbuff_;      // Vecteur de pointeur de zone memoire pour chaque fibre 
Index: /trunk/AddOn/TAcq/brpaqu.h
===================================================================
--- /trunk/AddOn/TAcq/brpaqu.h	(revision 3773)
+++ /trunk/AddOn/TAcq/brpaqu.h	(revision 3774)
@@ -58,4 +58,7 @@
   inline double realD() { return  (double)(val_)[0]; }
   inline double imagD() { return  (double)(val_)[1]; }
+
+  inline float  module2F() { return ((float)(val_)[0]*(float)(val_)[0]+(float)(val_)[1]*(float)(val_)[1]); }
+  inline double module2D() { return ((double)(val_)[0]*(double)(val_)[0]+(double)(val_)[1]*(double)(val_)[1]); }
 
   SByte val_[2];
Index: /trunk/AddOn/TAcq/brproc.cc
===================================================================
--- /trunk/AddOn/TAcq/brproc.cc	(revision 3773)
+++ /trunk/AddOn/TAcq/brproc.cc	(revision 3774)
@@ -131,5 +131,5 @@
       if (stop_) break;
       if (memgr_.GetRunState() == MemZR_Stopped) break;
-      int mid = memgr_.FindMemZoneId(MemZA_ProcA);
+      int mid = memgr_.FindMemZoneId(mmact_);  // (MemZA_ProcA);
       Byte* buffg = memgr_.GetMemZone(mid);
       if (buffg == NULL) {
@@ -141,5 +141,5 @@
 	fbuff_[fib] = memgr_.GetMemZone(mid,fib);
 	if (fbuff_[fib] == NULL) { // cela ne devrait pas arriver 
-	  cout << "BRBaseProcessor::run()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
+	  cout << "BRVisibilityCalculator::run()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
 	  setRC(9);	  fgrun=false;		
 	  break;
@@ -196,5 +196,5 @@
       if (rcpex!=0)  cout << " BRVisibilityCalculator::run() / Error Rc[paralex_.execute()]=" << rcpex << endl;
 
-      memgr_.FreeMemZone(mid, MemZS_ProcA);
+      memgr_.FreeMemZone(mid, mmsta_);  // (MemZS_ProcA);
     } // Fin de boucle sur les zones a traiter 
     //------------------------------------
@@ -207,10 +207,10 @@
   }
   catch (std::exception& exc) {
-    cout << " BRBaseProcessor::run()/catched std::exception " << exc.what() << endl;
+    cout << " BRVisibilityCalculator::run()/catched std::exception " << exc.what() << endl;
     setRC(98);	
     return; 
   }
   catch(...) {
-    cout << " BRBaseProcessor::run()/catched unknown ... exception " << endl;
+    cout << " BRVisibilityCalculator::run()/catched unknown ... exception " << endl;
     setRC(99);	
     return; 
@@ -397,4 +397,59 @@
   return 0;
 }
+
+
+//---------------------------------------------------------------------
+// Classe de traitement simple - calcul de spectres moyennes / voie
+//---------------------------------------------------------------------
+/* --Methode-- */
+BRMeanSpecCalculator::BRMeanSpecCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean)
+  : BRBaseProcessor(memgr), outpath_(outpath), nmean_(nmean)
+{
+  BRPaquet paq(memgr_.PaqSize());
+  mspecmtx_.SetSize(2*memgr_.NbFibres(), paq.DataSize()/4); 
+  numfile_=0;
+  totnbpaq_=0;
+}
+
+/* --Methode-- */
+BRMeanSpecCalculator::~BRMeanSpecCalculator()
+{
+}
+
+
+/* --Methode-- */
+int BRMeanSpecCalculator::Process()
+{
+      
+  if (totnbpaq_%nmean_ == 0) {
+    if (totnbpaq_ > 0) {
+      mspecmtx_.Info()["NPAQSUM"] = nmean_;
+      mspecmtx_ /= (double)nmean_;
+      char nfile[32];
+      sprintf(nfile,"mspecmtx%d.ppf",numfile_);
+      string flnm=outpath_+nfile;
+      POutPersist po(flnm);
+      po << mspecmtx_;
+      cout << numfile_ << "-BRMeanSpecCalculator::Process() NPaqProc="
+	   << totnbpaq_ << "  -> Mean spectra Matrix in " << flnm << endl;
+      numfile_++;
+    }
+    mspecmtx_ = (r_8)(0.);
+  }
+
+  sa_size_t k=0;
+  for(size_t i=0; i<(size_t)2*memgr_.NbFibres(); i++) {
+    TwoByteComplex* zp=vpaq_[i/2].Data1C();
+    if (i%2==1)  zp=vpaq_[i/2].Data2C();
+    TVector< r_4 > spec = mspecmtx_.Row(k);   k++;
+    for(sa_size_t f=1; f<spec.Size(); f++) {
+      spec(f) += zp[f].module2F();
+      }
+    }
+
+  totnbpaq_++;
+  return 0;
+}
+
 
 //---------------------------------------------------------------
Index: /trunk/AddOn/TAcq/brproc.h
===================================================================
--- /trunk/AddOn/TAcq/brproc.h	(revision 3773)
+++ /trunk/AddOn/TAcq/brproc.h	(revision 3774)
@@ -79,4 +79,24 @@
 
 
+//---------------------------------------------------------------------
+// Classe de traitement simple - calcul de spectres moyennes / voie
+//---------------------------------------------------------------------
+class BRMeanSpecCalculator : public BRBaseProcessor
+{
+public:
+  BRMeanSpecCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean=1000);
+  virtual ~BRMeanSpecCalculator(); // Fait le nettoyage final , sauvegarde des objets ...
+
+protected:
+  virtual int Process(); 
+
+  uint_4 nmean_;  // Nombre de spectres pour le calcul des moyennes 
+  string outpath_;  // directory pour fichiers de sortie
+  uint_4 numfile_;
+
+  uint_8 totnbpaq_;
+  TMatrix< r_4 > mspecmtx_;    // Matrice des spectres moyennees 
+}; 
+
 //-------------------------------------------------------------------------
 //    **** OBSOLETE : BRProcA2C et BRProcB4C
Index: /trunk/AddOn/TAcq/vismfib.cc
===================================================================
--- /trunk/AddOn/TAcq/vismfib.cc	(revision 3773)
+++ /trunk/AddOn/TAcq/vismfib.cc	(revision 3774)
@@ -65,4 +65,5 @@
 				par.nbinfreq_, par.nthreads_);
     if (par.action_ == "viscktt")  proc.ActivateTimeTagCheck(par.TotalNPaquets());
+    BRMeanSpecCalculator procms(mmgr, par.outpath_, par.nmean_);
     FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_);
     //    BRBaseProcessor proc(mmgr);
@@ -71,8 +72,10 @@
     reader.start();
     if (par.action_ == "cube3d")   wrt.start();
+    else if (par.action_ == "mspec")   procms.start();
     else  proc.start();
     usleep(200000);
     reader.join();
     if (par.action_ == "cube3d")  wrt.join();
+    else if (par.action_ == "mspec")  procms.join();
     else proc.join();
     mmgr.Print(cout);
