Index: /trunk/AddOn/TAcq/branap.cc
===================================================================
--- /trunk/AddOn/TAcq/branap.cc	(revision 3775)
+++ /trunk/AddOn/TAcq/branap.cc	(revision 3776)
@@ -26,4 +26,5 @@
   npaqinzone_=npaqz;
   prtlevel_=0;
+  nbcalgrp_=1;
   nthreads_=1;
 }
@@ -75,4 +76,8 @@
       ka+=2;
     }
+    else if (strcmp(arg[ka],"-nvcal")==0) {
+      nbcalgrp_=atoi(arg[ka+1]);
+      ka+=2;
+    }
     else if (strcmp(arg[ka],"-in")==0) {
       if ((narg-ka)<4)  {
@@ -114,5 +119,5 @@
   cout << " Usage:  prgname [-act ACT] [-out OutPath] [-nmean NMean] [-zones NZones,nPaqinZone] \n" 
        << "                 [-nbloc NBloc] [-freq NumFreqMin,NumFreqMax,NBinFreq] \n" 
-       << "                 [-prtlev lev] [-nthr n] \n" 
+       << "                 [-prtlev lev] [-nvcal n] [-nthr n] \n" 
        << "         -in Imin,Imax,Istep InPath FiberList [InPath2 FiberList2 InPath3 FiberList3 ...] \n" << endl; 
   if (fgshort) {
@@ -130,5 +135,6 @@
        << " -freq NumFreqMin,NumFreqMax,NBinFreq : Frequency zone and number of bins \n" 
        << " -prtlev lev : Print level (0,1,2...) \n" 
-       << " -nthr n : number of threads for parallel execution (default=1) \n" 
+       << " -nvcal n : number of BRVisibilityCalculator objects running in parallel in BRVisCalcGroup  (default=1) \n" 
+       << " -nthr n : number of threads for parallel execution in BRVisibilityCalculator (default=1) \n" 
        << " -in : input files/directory definition : \n"
        << "       Imin,Imax,Istep: fits files signalII.fits Imin<=II<=Imax Istep=increment \n" 
@@ -159,4 +165,7 @@
   cout << " PaqSize=" << paqsize_ << "  -  NZones=" << nzones_ << " NPaqZone=" << npaqinzone_ 
        << " PrtLevel=" << prtlevel_ << endl;
+  cout << " NbVisibCalculator in Group: " <<  nbcalgrp_ << " with N//threads: " << nthreads_ << endl;
+
+
   return os;
 }
Index: /trunk/AddOn/TAcq/branap.h
===================================================================
--- /trunk/AddOn/TAcq/branap.h	(revision 3775)
+++ /trunk/AddOn/TAcq/branap.h	(revision 3776)
@@ -38,5 +38,6 @@
   uint_4 npaqinfile_;    // nombre de paquets dans un fichier p
   int prtlevel_;
-  uint_4 nthreads_;  // Nb de threads pour l'execution parallele 
+  uint_4 nbcalgrp_;    // Nb d'objets/threads dans BRVisCalcGroup 
+  uint_4 nthreads_;  // Nb de threads pour l'execution parallele ds BRVisibilityCalculator
 };
 
Index: /trunk/AddOn/TAcq/brproc.cc
===================================================================
--- /trunk/AddOn/TAcq/brproc.cc	(revision 3775)
+++ /trunk/AddOn/TAcq/brproc.cc	(revision 3776)
@@ -31,15 +31,13 @@
 
 /* --Methode-- */
-BRVisibilityCalculator::BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, 
-					       uint_4 freq1, uint_4 freq2, uint_4 nbfreq, size_t nthr)
-  : BRBaseProcessor(memgr), paralex_(*this, nthr), nparthr_(nthr), outpath_(outpath), nmean_(nmean), 
-    numfreq1_(freq1), numfreq2_(freq2), nbinfreq_(nbfreq), vpdata_(2*memgr.NbFibres())
+BRVisibilityCalculator::BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, size_t nthr)
+  : BRBaseProcessor(memgr), paralex_(*this, nthr), nparthr_(nthr), 
+    outpath_(outpath), nmean_(nmean), nbcalc_(1), calcid_(0), vpdata_(2*memgr.NbFibres())
     // , dtfos_(outpath+"visdt.fits", Fits_Create), visdt_(dtfos_, 1024, true);
-
 {  
-  BRPaquet paq(memgr_.PaqSize());
-
-  vismtx_.SetSize((2*memgr_.NbFibres()+1)*memgr_.NbFibres(), paq.DataSize()/4); 
-  chanum_.SetSize(vismtx_.NRows());
+  DefineRank(1,0);
+
+  uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
+  chanum_.SetSize(maxnpairs);
   sa_size_t k=0;
   for(size_t i=0; i<2*memgr_.NbFibres(); i++)  vpdata_[i]=NULL;
@@ -49,4 +47,6 @@
     }
   }
+  SelectPairs();
+
   //  visdt_.AddFloatColumn("mfc");
   visdt_.AddDoubleColumn("mfc");
@@ -60,50 +60,121 @@
   if (nmean_ < 1)  nmean_=1;
 
+  cout << " BRVisibilityCalculator::/Info  nmean=" << nmean_ << endl;
+
   totnbpaq_=0;
   numfile_=0;
   moyfc_=moytt_=0.;
 
-  jf1_=numfreq1_; jf2_=numfreq2_;
+  fgallfibok=NULL;
+  fgcktt_=false;
+}
+
+/* --Methode-- */
+BRVisibilityCalculator::~BRVisibilityCalculator()
+{
+  cout << " BRVisibilityCalculator - Visibility Datatable : " << endl;
+  cout << visdt_;
+  string filename;
+  filename = outpath_+"visdt.ppf";
+  if (nbcalc_>1) {
+    char sbuff[32];
+    sprintf(sbuff,"visdt_%d",(int)calcid_);
+    filename = outpath_+sbuff;
+  }
+  POutPersist po(filename);
+  po << visdt_;
+  if (calcid_ == 0) {
+    POutPersist poc(outpath_+"chanum.ppf");
+    poc << chanum_;
+  
+    if (fgcktt_) {
+      cout << " BRVisibilityCalculator -  Check TimeTag done: TotNPaqProc= " << totnbpaq_ << endl;
+      for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
+	cout << " BRTTCheck-Fiber[" << fib << "] NBadTT=" << vbadtt_[fib] << " NDiffTT>5="
+	     << vndiff5tt_[fib] << "  NotSameTT=" << vnsamett_[fib] << endl; 
+      }
+      POutPersist pott(outpath_+"ttfcmtx.ppf");
+      pott << PPFNameTag("FC") << fcmtx_; 
+      pott << PPFNameTag("TT") << ttmtx_;     
+    }
+  }
+}
+
+/* --Methode-- */
+void BRVisibilityCalculator::DefineRank(uint_4 nbc, uint_4 cid)
+{
+  if ((nbc>4)||(cid>=nbc)) 
+    throw ParmError("BRVisibilityCalculator::DefineRank() NbCalc > 4 !");
+  nbcalc_=nbc;
+  calcid_=cid;
+  if (nbcalc_>1) {
+    uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
+    uint_4 npairs=maxnpairs/nbcalc_;
+    if (calcid_==(nbcalc_-1)) 
+      SelectPairs(calcid_*npairs, maxnpairs-calcid_*npairs);
+    else 
+      SelectPairs(calcid_*npairs, npairs);
+    MemZaction mmzas[4]={MemZA_ProcA,MemZA_ProcB,MemZA_ProcC,MemZA_ProcD};
+    SetMemZAction(mmzas[calcid_]);
+  }
+  return ;
+}
+
+/* --Methode-- */
+uint_4 BRVisibilityCalculator::SelectPairs(uint_4 pair1, uint_4 nbpairs)
+{
+  BRPaquet paq(memgr_.PaqSize());
+  uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
+
+  if (pair1 >= maxnpairs)  pair1=maxnpairs-1;
+  if (nbpairs > maxnpairs-pair1)  nbpairs=maxnpairs-pair1;
+  pairst_=pair1;
+  nbpairs_=nbpairs;
+  vismtx_.SetSize(nbpairs_, paq.DataSize()/4); 
+  return nbpairs_;
+}
+
+/* --Methode-- */
+int BRVisibilityCalculator::SelectFreqBinning(uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
+{
+  jf1_=freq1; jf2_=freq2;
   if ((jf1_<1)||(jf1_>=vismtx_.NCols()))  jf1_=1;
   if ((jf2_<1)||(jf2_>=vismtx_.NCols())||(jf2_<jf1_))  jf2_=vismtx_.NCols()-1;
-  if (nbinfreq_<1) nbinfreq_=1;
-  djf_=(jf2_-jf1_)/nbinfreq_;
+  if (nbfreq<1) nbfreq=1;
+  djf_=(jf2_-jf1_)/nbfreq;
   if (djf_<1) djf_=0;
-  xnt_ = new double[vismtx_.NRows()+20];
-  for(int kk=0; kk<vismtx_.NRows(); kk++)  xnt_[kk]=0.;
-
-  cout << " BRVisibilityCalculator/Info NMean= " << nmean_ << " JF1=" << jf1_ 
+  cout << " BRVisibilityCalculator::SelectFreqBinning/Info  JF1=" << jf1_ 
        << " JF2=" << jf2_ << " DJF=" << djf_ << endl;
 
-  fgallfibok=NULL;
-  fgcktt_=false;
-}
-
-/* --Methode-- */
-BRVisibilityCalculator::~BRVisibilityCalculator()
-{
-  cout << " BRVisibilityCalculator - Visibility Datatable : " << endl;
-  cout << visdt_;
-  POutPersist po(outpath_+"visdt.ppf");
-  po << visdt_;
-  POutPersist poc(outpath_+"chanum.ppf");
-  poc << chanum_;
-
-  if (fgcktt_) {
-    cout << " BRVisibilityCalculator -  Check TimeTag done: TotNPaqProc= " << totnbpaq_ << endl;
-    for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
-      cout << " BRTTCheck-Fiber[" << fib << "] NBadTT=" << vbadtt_[fib] << " NDiffTT>5="
-	   << vndiff5tt_[fib] << "  NotSameTT=" << vnsamett_[fib] << endl; 
-    }
-    POutPersist pott(outpath_+"ttfcmtx.ppf");
-    pott << PPFNameTag("FC") << fcmtx_; 
-    pott << PPFNameTag("TT") << ttmtx_;     
-  }
-  delete[] xnt_;
-}
+}
+
+
+/* --Methode-- */
+int BRVisibilityCalculator::ActivateTimeTagCheck(uint_8 maxnpaq)
+{
+  mindeltatt_=memgr_.PaqSize()/2;
+  if (mindeltatt_<1) mindeltatt_=1;
+  fcmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
+  ttmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
+  vlasttt_.resize(memgr_.NbFibres(), 0);
+  vbadtt_.resize(memgr_.NbFibres(), 0);
+  vnsamett_.resize(memgr_.NbFibres(), 0);
+  vndiff5tt_.resize(memgr_.NbFibres(), 0);
+
+  fgcktt_=true;
+  cout << " BRVisibilityCalculator::ActivateTimeTagCheck() - TT/Fc matrix NCols=" << maxnpaq 
+       << " MinDeltaTT=" << mindeltatt_ << endl;
+
+  return 0;
+}
+
 
 /* --Methode-- */
 void BRVisibilityCalculator::run()
 {
+  cout << " BRVisibilityCalculator[" << calcid_ << "/" << nbcalc_ 
+       << "]::run() - Starting " << " NFibers=" << memgr_.NbFibres() 
+       << " NChan=" << 2*memgr_.NbFibres() << " NPairs=" << nbpairs_ << " First:" << pairst_ << endl;	
+  
   if (nparthr_ < 2)  return BRBaseProcessor::run();
   // Execution multithread parallele
@@ -111,6 +182,4 @@
   int rc=0;
   try {
-    cout << " BRVisibilityCalculator::run() - Starting " << " NFibers=" << memgr_.NbFibres() 
-	 << " NChan=" << 2*memgr_.NbFibres() << endl;	
     if ((nmean_%memgr_.NbPaquets())!=0) {
       uint_4 mnmean = (nmean_/memgr_.NbPaquets()+1)*memgr_.NbPaquets();
@@ -156,6 +225,9 @@
 	  
 	  // ATTENTION : Matrice visibilites non moyennee 
-	  char nfile[32];
-	  sprintf(nfile,"vismtx%d.ppf",numfile_);
+	  char nfile[48];
+	  if (nbcalc_==1) 
+	    sprintf(nfile,"vismtx%d.ppf",numfile_);
+	  else 
+	    sprintf(nfile,"vismtx_%d_%d.ppf",(int)calcid_,numfile_);
 	  string flnm=outpath_+nfile;
 	  POutPersist po(flnm);
@@ -187,5 +259,5 @@
 	  moyfc_ += curfc_[0];
 	  moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
-	  if (fgcktt_)  CheckTimeTag();
+	  if ((fgcktt_)&&(calcid_==0))  CheckTimeTag();
 	  totnbpaq_++;
 	}
@@ -220,23 +292,4 @@
 
 /* --Methode-- */
-int BRVisibilityCalculator::ActivateTimeTagCheck(uint_8 maxnpaq)
-{
-  mindeltatt_=memgr_.PaqSize()/2;
-  if (mindeltatt_<1) mindeltatt_=1;
-  fcmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
-  ttmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
-  vlasttt_.resize(memgr_.NbFibres(), 0);
-  vbadtt_.resize(memgr_.NbFibres(), 0);
-  vnsamett_.resize(memgr_.NbFibres(), 0);
-  vndiff5tt_.resize(memgr_.NbFibres(), 0);
-
-  fgcktt_=true;
-  cout << " BRVisibilityCalculator::ActivateTimeTagCheck() - TT/Fc matrix NCols=" << maxnpaq 
-       << " MinDeltaTT=" << mindeltatt_ << endl;
-
-  return 0;
-}
-
-/* --Methode-- */
 int BRVisibilityCalculator::Process()
 {
@@ -256,6 +309,9 @@
 
       // ATTENTION : Matrice visibilites non moyennee 
-      char nfile[32];
-      sprintf(nfile,"vismtx%d.ppf",numfile_);
+      char nfile[48];
+      if (nbcalc_==1) 
+	sprintf(nfile,"vismtx%d.ppf",numfile_);
+      else 
+	sprintf(nfile,"vismtx_%d_%d.ppf",(int)calcid_,numfile_);
       string flnm=outpath_+nfile;
       POutPersist po(flnm);
@@ -273,4 +329,7 @@
   for(size_t i=0; i<vpdata_.size(); i++) {
     for(size_t j=i; j<vpdata_.size(); j++) {
+      size_t kpair=i*vpdata_.size()+j;
+      if (kpair<pairst_)  continue;
+      if (kpair>=(pairst_+nbpairs_))  break;
       TVector< complex<r_4> > vis = vismtx_.Row(k);   k++;
       for(sa_size_t f=1; f<vis.Size(); f++) {
@@ -283,5 +342,5 @@
   moyfc_ += curfc_[0];
   moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
-  if (fgcktt_)  CheckTimeTag();
+  if ((fgcktt_)&&(calcid_==0))  CheckTimeTag();
   totnbpaq_++;
   return 0;
@@ -312,4 +371,7 @@
     for(size_t i=0; i<vpdata_.size(); i++) {
       for(size_t j=i; j<vpdata_.size(); j++) {
+	size_t kpair=i*vpdata_.size()+j;
+	if (kpair<pairst_)  continue;
+	if (kpair>=(pairst_+nbpairs_))  break;
 	TVector< complex<r_4> > vis = vismtx_.Row(k);   k++;
 	for(sa_size_t f=fdeb; f<ffin; f++) {
@@ -328,14 +390,15 @@
 int BRVisibilityCalculator::FillVisibTable(double fcm, double ttm)
 {
-  xnt_[0]=fcm;  xnt_[1]=ttm/1.25e8;
+  double xnt[10];
+  xnt[0]=fcm;  xnt[1]=ttm/1.25e8;
 
   if (djf_<2) {
     for(sa_size_t rv=0; rv<vismtx_.NRows(); rv++) {
       for(sa_size_t jf=jf1_; jf<jf2_; jf++) {
-	xnt_[2]=jf;
-	xnt_[3]=chanum_(rv);
-	xnt_[4]=vismtx_(rv,jf).real()/(r_4)(nmean_);
-	xnt_[5]=vismtx_(rv,jf).imag()/(r_4)(nmean_);
-	visdt_.AddRow(xnt_);
+	xnt[2]=jf;
+	xnt[3]=chanum_(rv+pairst_);
+	xnt[4]=vismtx_(rv,jf).real()/(r_4)(nmean_);
+	xnt[5]=vismtx_(rv,jf).imag()/(r_4)(nmean_);
+	visdt_.AddRow(xnt);
       }
     }
@@ -352,9 +415,9 @@
 	  moyimag+=vismtx_(rv,jjf).imag();
 	}
-	xnt_[2]=jf+djf_/2;
-	xnt_[3]=chanum_(rv);
-	xnt_[4]=moyreal/(r_4)(nmean_*djf_);
-	xnt_[5]=moyimag/(r_4)(nmean_*djf_);
-	visdt_.AddRow(xnt_);
+	xnt[2]=jf+djf_/2;
+	xnt[3]=chanum_(rv+pairst_);
+	xnt[4]=moyreal/(r_4)(nmean_*djf_);
+	xnt[5]=moyimag/(r_4)(nmean_*djf_);
+	visdt_.AddRow(xnt);
       }
     }
@@ -396,4 +459,46 @@
   }
   return 0;
+}
+
+//-------------------------------------------------------------------------------
+// Classe Groupe (ensemble) de Calculateur de Visibilites, tourant en parallele
+//-------------------------------------------------------------------------------
+
+/* --Methode-- */
+BRVisCalcGroup::BRVisCalcGroup(size_t nbcalc, RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, size_t nthr)
+{
+  if ((nbcalc<1)||(nbcalc>4)) 
+    throw ParmError("BRVisCalcGroup::BRVisCalcGroup NbCalc > 4 !");
+  for(size_t i=0; i<nbcalc; i++) {
+    BRVisibilityCalculator * viscp=new BRVisibilityCalculator(memgr, outpath, nmean, nthr);
+    viscp->DefineRank(nbcalc, i);
+    viscalcp_.push_back(viscp); 
+  }
+}
+/* --Methode-- */
+BRVisCalcGroup::~BRVisCalcGroup()
+{
+  for(size_t i=0; i<viscalcp_.size(); i++) 
+    delete viscalcp_[i];
+}
+/* --Methode-- */
+int BRVisCalcGroup::SelectFreqBinning(uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
+{
+  int rc=0;
+  for(size_t i=0; i<viscalcp_.size(); i++) 
+    rc=viscalcp_[i]->SelectFreqBinning(freq1, freq2, nbfreq);
+  return rc;
+}
+/* --Methode-- */
+void BRVisCalcGroup::start()
+{
+  for(size_t i=0; i<viscalcp_.size(); i++) 
+    viscalcp_[i]->start();
+}
+/* --Methode-- */
+void BRVisCalcGroup::join()
+{
+  for(size_t i=0; i<viscalcp_.size(); i++) 
+    viscalcp_[i]->join();
 }
 
Index: /trunk/AddOn/TAcq/brproc.h
===================================================================
--- /trunk/AddOn/TAcq/brproc.h	(revision 3775)
+++ /trunk/AddOn/TAcq/brproc.h	(revision 3776)
@@ -28,13 +28,21 @@
 class BRVisibilityCalculator : public BRBaseProcessor, ParallelTaskInterface {
 public:	
-  BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean=1000, 
-			 uint_4 freq1=0, uint_4 freq2=0, uint_4 nbfreq=1, size_t nthr=1);
+  BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean=1000, size_t nthr=1);
   virtual ~BRVisibilityCalculator(); // Fait le nettoyage final , sauvegarde des objets ...
 
-  virtual void run();
+  // Pour definir le rang de l'objet lors d'un traitement avec plusieurs BRVisibilityCalculator en //
+  void DefineRank(uint_4 nbc, uint_4 cid);
+
+  // Pour limiter le calcul des visibilites a certaines fibres 
+  uint_4 SelectPairs(uint_4 pair1=0, uint_4 nbpairs=99999999);
+  // pour definir le binning en frequence pour la VisibDataTable 
+  int SelectFreqBinning(uint_4 freq1=0, uint_4 freq2=0, uint_4 nbfreq=1);
+
   // Pour activer la verification des timetag
   // Creation / sauvegarde d'une matrice de TimeTag / FrameCounter avec NCols=maxnpaq (nb de paquets/trigger)  
   int ActivateTimeTagCheck(uint_8 maxnpaq);
-  
+
+  // Methode d'execution standard du thread (on redefinit la methode de BRBaseProcessor)
+  virtual void run();  
   // Methode de la classe ParallelTaskInterface 
   virtual int    execute(int tid);
@@ -50,6 +58,8 @@
   uint_4 nmean_;  // Nombre de spectres pour le calcul des moyennes 
   string outpath_;  // directory pour fichiers de sortie
-  uint_4 numfreq1_,numfreq2_,nbinfreq_;
-  uint_4 jf1_,jf2_,djf_;
+  uint_4 nbcalc_, calcid_;  // Nombre total de threads/objets BRVisibilityCalculator parallèles, l'identificateur de l'objet  
+
+  uint_4 pairst_, nbpairs_;   // Numero de la premiere paire, nombre de paires 
+  uint_4 jf1_,jf2_,djf_;  // binning en frequence pour la datatable
 
   vector<TwoByteComplex*> vpdata_;
@@ -64,5 +74,4 @@
   uint_4 numfile_;
   uint_8 totnbpaq_;
-  double* xnt_;
 
   // Variables/objets pour la verifications des timetag
@@ -79,4 +88,22 @@
 
 
+//-------------------------------------------------------------------------------
+// Classe Groupe (ensemble) de Calculateur de Visibilites, tourant en parallele
+//-------------------------------------------------------------------------------
+
+class BRVisCalcGroup {
+public:	
+  BRVisCalcGroup(size_t nbcalc, RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean=1000, size_t nthr=1);
+  ~BRVisCalcGroup();
+  int SelectFreqBinning(uint_4 freq1=0, uint_4 freq2=0, uint_4 nbfreq=1);
+  inline int ActivateTimeTagCheck(uint_8 maxnpaq)
+  { return viscalcp_[0]->ActivateTimeTagCheck(maxnpaq); }
+
+  void start();
+  void join();
+protected:
+  vector<BRVisibilityCalculator *> viscalcp_; 
+};
+ 
 //---------------------------------------------------------------------
 // Classe de traitement simple - calcul de spectres moyennes / voie
Index: /trunk/AddOn/TAcq/vismfib.cc
===================================================================
--- /trunk/AddOn/TAcq/vismfib.cc	(revision 3775)
+++ /trunk/AddOn/TAcq/vismfib.cc	(revision 3776)
@@ -57,13 +57,24 @@
     RAcqMemZoneMgr mmgr(par.nzones_, par.dirlist_.size(), par.npaqinzone_, par.paqsize_);
     if (par.action_ == "cube3d")  mmgr.SetFinalizedMask((uint_4)MemZS_Saved);
-    else  mmgr.SetFinalizedMask((uint_4)MemZS_ProcA);
-
+    else  {
+      if (par.nbcalgrp_==2) 
+	mmgr.SetFinalizedMask((uint_4)MemZS_ProcA|(uint_4)MemZS_ProcB);
+      else if (par.nbcalgrp_==3) 
+	mmgr.SetFinalizedMask((uint_4)MemZS_ProcA|(uint_4)MemZS_ProcB|(uint_4)MemZS_ProcC);
+      else if (par.nbcalgrp_==4) 
+	mmgr.SetFinalizedMask((uint_4)MemZS_ProcA|(uint_4)MemZS_ProcB|(uint_4)MemZS_ProcC|(uint_4)MemZS_ProcD);
+      else mmgr.SetFinalizedMask((uint_4)MemZS_ProcA);	
+    }
     BRMultiFitsReader reader(mmgr, par.dirlist_, true, par.imin_, par.imax_, par.istep_);
     reader.SetPrintLevel(par.prtlevel_);
 
-    BRVisibilityCalculator proc(mmgr, par.outpath_, par.nmean_, par.freqmin_, par.freqmax_, 
-				par.nbinfreq_, par.nthreads_);
-    if (par.action_ == "viscktt")  proc.ActivateTimeTagCheck(par.TotalNPaquets());
+    /*    BRVisibilityCalculator proc(mmgr, par.outpath_, par.nmean_, par.nthreads_);
+    proc.SelectFreqBinning(par.freqmin_, par.freqmax_, par.nbinfreq_);  */
+    BRVisCalcGroup procg(par.nbcalgrp_, mmgr, par.outpath_, par.nmean_, par.nthreads_);
+    procg.SelectFreqBinning(par.freqmin_, par.freqmax_, par.nbinfreq_);
+
+    if (par.action_ == "viscktt")  procg.ActivateTimeTagCheck(par.TotalNPaquets());
     BRMeanSpecCalculator procms(mmgr, par.outpath_, par.nmean_);
+
     FitsCubeWriter wrt(mmgr, par.outpath_, par.nbloc_);
     //    BRBaseProcessor proc(mmgr);
@@ -73,10 +84,10 @@
     if (par.action_ == "cube3d")   wrt.start();
     else if (par.action_ == "mspec")   procms.start();
-    else  proc.start();
+    else  procg.start();
     usleep(200000);
     reader.join();
     if (par.action_ == "cube3d")  wrt.join();
     else if (par.action_ == "mspec")  procms.join();
-    else proc.join();
+    else procg.join();
     mmgr.Print(cout);
     cout << resu ; 
