Index: trunk/AddOn/TAcq/brviscalc.cc
===================================================================
--- trunk/AddOn/TAcq/brviscalc.cc	(revision 3993)
+++ trunk/AddOn/TAcq/brviscalc.cc	(revision 4012)
@@ -28,11 +28,16 @@
 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), 
+    outpath_(outpath), nbcalc_(1), calcid_(0), 
     vpdata_(2*memgr.NbFibres()), vpdatar_(2*memgr.NbFibres())
     // , dtfos_(outpath+"visdt.fits", Fits_Create), visdt_(dtfos_, 1024, true);
 {  
   SetFFTData();
+  SetNPaqIntervalMode(nmean);
   DefineRank(1,0);
   SetPPFOutput();
+
+  npaqcumul_=0;
+  moyfc_=moytt_=0.;
+  first_fc_=first_tt_=0;
 
   uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
@@ -57,10 +62,7 @@
   if (nmean_ < 1)  nmean_=1;
 
-  cout << " BRVisibilityCalculator::/Info  nmean=" << nmean_ << endl;
-
   totnbpaq_=0;
   numfile_=0;
   nb_flop_=0.;
-  moyfc_=moytt_=0.;
 
   fgallfibok=NULL;
@@ -272,5 +274,10 @@
        << "]::run() - Starting " << " NFibers=" << memgr_.NbFibres() 
        << " NChan=" << 2*memgr_.NbFibres() << " NPairs=" << nbpairs_ << " First:" << pairst_ << endl;	
-  
+
+  if (fgnpaq_time) 
+    cout << " BRVisibilityCalculator::run()/Info  NPaq=" << nmean_ << " Interval mode for visibility mtrix save" << endl;
+  else 
+    cout << " BRVisibilityCalculator::run()/Info  Time Tnterval (dt=" << dtimemean_ << ") for visibility mtrix save" << endl;
+
   if (nparthr_ < 2)  return BRBaseProcessor::run();
   // Execution multithread parallele
@@ -324,37 +331,10 @@
       }
 
-      if (totnbpaq_%nmean_ == 0) {
-	if (totnbpaq_ > 0) {
-	  moyfc_/=nmean_;
-	  moytt_/=nmean_;
-	  UpdateVisMtxInfo();    // add/update keywords in the Info DVList 
-	  // ATTENTION : Matrice visibilites non moyennee 
-	  char nfile[48];
-	  if (nbcalc_==1) 
-	    sprintf(nfile,"vismtx%d.%s",numfile_,OutFileExtension());
-	  else 
-	    sprintf(nfile,"vismtx_%d_%d.%s",(int)calcid_,numfile_,OutFileExtension());
-	  string flnm=outpath_+nfile;
-	  if (fgfitsout_) {  // Ecriture au format FITS
-	    FitsInOutFile fo(flnm, FitsInOutFile::Fits_Create);
-	    TArray<r_4> arvismtx = ArrCastC2R(vismtx_);
-	    arvismtx.Info()=vismtx_.Info();
-	    fo << arvismtx;
-	  }
-	  else {  // Format PPF 
-	    POutPersist po(flnm);
-	    po << vismtx_;
-	  }
-	  if ((prtlev_>0)&&(numfile_%prtmodulo_==0)) {
-	    cout << numfile_ << "-BRVisCalc[" << calcid_ << "/" << nbcalc_ << "]::run() NPaqProc="
-		 << totnbpaq_ << " TotMegaFLOP=" << (uint_8)TotNbMegaFLOP() << " -> VisibMtx in " << flnm << endl;
-	  }
-	  if (fgvisdt_) FillVisibTable(moyfc_, moytt_);
-	  numfile_++;
-	}
-	vismtx_ = complex<r_4>((r_4)0.,(r_4)0.);
-	moyfc_=moytt_=0.;
-	//	first_tmstamp_.SetNow();  // Current date and time 
-	first_tmstamp_=cts_;  // Current date and time 
+      if ( CheckInterval4VisMtxSave() ) {
+	if ((prtlev_>0)&&(numfile_%prtmodulo_==0)) {
+	  cout << numfile_ << "-BRVisCalc[" << calcid_ << "/" << nbcalc_ << "]::run() NPaqProc="
+	       << totnbpaq_ << " TotMegaFLOP=" << (uint_8)TotNbMegaFLOP() << " -> VisibMtx FileNum=" << numfile_ << endl;
+	}
+	SaveVisibilityMatrix();
       }
 
@@ -378,8 +358,9 @@
 	  moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
 	  if ((fgcktt_)&&(calcid_==0))  CheckTimeTag();
-	  if (totnbpaq_%nmean_ == 0) {
+	  if (npaqcumul_==0) {
 	    first_fc_=curfc_[0];
-	    first_tt_= (vpaq_[0].TimeTag()-ttfirst_[0]);
+	    first_tt_= vpaq_[0].TimeTag();
 	  }
+	  npaqcumul_++;
 	  totnbpaq_++;
 	}
@@ -431,39 +412,10 @@
   }
   
-  if (totnbpaq_%nmean_ == 0) {
-    if (totnbpaq_ > 0) {
-      moyfc_/=nmean_;
-      moytt_/=nmean_;
-      UpdateVisMtxInfo();    // add/update keywords in the Info DVList 
-      // ATTENTION : Matrice visibilites non moyennee 
-      char nfile[48];
-      if (nbcalc_==1) 
-	sprintf(nfile,"vismtx%d.%s",numfile_,OutFileExtension());
-      else 
-	sprintf(nfile,"vismtx_%d_%d.%s",(int)calcid_,numfile_,OutFileExtension());
-      string flnm=outpath_+nfile;
-      if (fgfitsout_) {  // Ecriture au format FITS
-	FitsInOutFile fo(flnm, FitsInOutFile::Fits_Create);
-	TArray<r_4> arvismtx = ArrCastC2R(vismtx_);
-	arvismtx.Info()=vismtx_.Info();
-	fo << arvismtx;
-      }
-      else {  // Format PPF 
-	POutPersist po(flnm);
-	po << vismtx_;
-      }
-      if ((prtlev_>0)&&(numfile_%prtmodulo_==0)) {
-	cout << numfile_ << "-BRVisCalc[" << calcid_ << "/" << nbcalc_ << "]::Process() NPaqProc="
-	     << totnbpaq_ << " TotMegaFLOP=" << (uint_8)TotNbMegaFLOP() << " -> VisibMtx in " << flnm << endl;
-      }
-      if (fgvisdt_) FillVisibTable(moyfc_, moytt_);
-      numfile_++;
-    }
-    vismtx_ = complex<r_4>((r_4)0.,(r_4)0.);
-    moyfc_=moytt_=0.;
-    first_fc_=curfc_[0];
-    first_tt_= (vpaq_[0].TimeTag()-ttfirst_[0]);
-    // first_tmstamp_.SetNow();  // Current date and time 
-    first_tmstamp_=cts_;  // Current date and time 
+  if ( CheckInterval4VisMtxSave() ) {
+    if ((prtlev_>0)&&(numfile_%prtmodulo_==0)) {
+      cout << numfile_ << "-BRVisCalc[" << calcid_ << "/" << nbcalc_ << "]::Process() NPaqProc="
+	   << totnbpaq_ << " TotMegaFLOP=" << (uint_8)TotNbMegaFLOP() << " -> VisibMtx FileNum= " << numfile_ << endl;
+    }
+    SaveVisibilityMatrix();
   }
 
@@ -494,4 +446,5 @@
   }
 
+  npaqcumul_++;
   moyfc_ += curfc_[0];
   moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
@@ -499,4 +452,41 @@
   totnbpaq_++;
   return 0;
+}
+/* --Methode-- */
+void BRVisibilityCalculator::SaveVisibilityMatrix()
+{
+  if (totnbpaq_ > 0) {
+    moyfc_/=npaqcumul_;
+    moytt_/=npaqcumul_;
+    UpdateVisMtxInfo();    // add/update keywords in the Info DVList 
+    // ATTENTION : Matrice visibilites non moyennee 
+    char nfile[48];
+    if (nbcalc_==1) 
+      sprintf(nfile,"vismtx%d.%s",numfile_,OutFileExtension());
+    else 
+      sprintf(nfile,"vismtx_%d_%d.%s",(int)calcid_,numfile_,OutFileExtension());
+    string flnm=outpath_+nfile;
+    if (fgfitsout_) {  // Ecriture au format FITS
+      FitsInOutFile fo(flnm, FitsInOutFile::Fits_Create);
+      TArray<r_4> arvismtx = ArrCastC2R(vismtx_);
+      arvismtx.Info()=vismtx_.Info();
+      fo << arvismtx;
+    }
+    else {  // Format PPF 
+      POutPersist po(flnm);
+      po << vismtx_;
+    }
+    if (fgvisdt_) FillVisibTable(moyfc_, moytt_);
+    numfile_++;
+  }
+  vismtx_ = complex<r_4>((r_4)0.,(r_4)0.);
+  npaqcumul_=0;
+  moyfc_=moytt_=0.;
+  first_fc_=curfc_[0];
+  first_tt_=vpaq_[0].TimeTag();
+  // first_tmstamp_.SetNow();  // Current date and time 
+  first_tmstamp_=cts_;  // Current date and time 
+  
+  return;
 }
 
@@ -512,5 +502,5 @@
   vismtx_.Info().SetComment(ikey,ikdesc);
   ikey="FirstTT";  ikdesc="First TimeTag";
-  vismtx_.Info().SetI(ikey,first_tt_);
+  vismtx_.Info().SetI(ikey,(first_tt_-ttfirst_[0]));
   vismtx_.Info().SetComment(ikey,ikdesc);
   ikey="LastFC";  ikdesc="Last FrameCounter";
@@ -527,5 +517,5 @@
   vismtx_.Info().SetComment(ikey,ikdesc);
   ikey="NPAQSUM";  ikdesc="Number of paquets summed";
-  vismtx_.Info().SetI(ikey,nmean_);
+  vismtx_.Info().SetI(ikey,npaqcumul_);
 }
 
@@ -752,4 +742,16 @@
 }  
 /* --Methode-- */
+void BRVisCalcGroup::SetNPaqIntervalMode(uint_4 nmean)
+{
+  for(size_t i=0; i<viscalcp_.size(); i++)
+    viscalcp_[i]->SetNPaqIntervalMode(nmean);
+}
+/* --Methode-- */
+void BRVisCalcGroup::SetTimeIntervalMode(double dtime)
+{
+  for(size_t i=0; i<viscalcp_.size(); i++)
+    viscalcp_[i]->SetTimeIntervalMode(dtime);
+}  
+/* --Methode-- */
 void BRVisCalcGroup::SetPrintLevel(int lev, uint_8 prtmodulo)
 {
