Index: /trunk/AddOn/TAcq/README
===================================================================
--- /trunk/AddOn/TAcq/README	(revision 3634)
+++ /trunk/AddOn/TAcq/README	(revision 3635)
@@ -49,2 +49,11 @@
    serverName : Name or IP adress of the machine where tsok S is running 
    NLoop,SizeX,SizeY: Number of transfers, 2D array size for OPEMsg=PPFSOCKET 
+
+
+6/ --- Avril 2009 
+   Amelioration programme mfits2spec
+   --- Mai 2009
+   o Amelioration du programme tmtacq.cc (+/- copie programme d'acquisition)
+   o Introduction du programme de lecture / traitement multi-thread des fichiers 
+     minifits acquisition 
+     Ajout fichiers : mcrd.cc , brfitsrd.h .cc , brproc.h .cc  
Index: /trunk/AddOn/TAcq/brfitsrd.cc
===================================================================
--- /trunk/AddOn/TAcq/brfitsrd.cc	(revision 3635)
+++ /trunk/AddOn/TAcq/brfitsrd.cc	(revision 3635)
@@ -0,0 +1,142 @@
+//----------------------------------------------------------------
+// ---- classes de threads pour lecture fichiers minifits
+// LAL -      R. Ansari - Mai 2009 
+//----------------------------------------------------------------
+
+
+#include "brfitsrd.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fstream>
+#include <signal.h>
+#include "pexceptions.h"
+#include "timestamp.h"
+#include "ctimer.h"
+
+#include "brpaqu.h"
+#include "minifits.h"
+
+#include "resusage.h" // Pour mesure temps elapsed/CPU ...
+#include "datatable.h" // Pour sauver les entetes de paquet 
+#include <sys/time.h>  // pour gettimeofday
+
+//-------------------------------------------------------
+// Classe thread de sauvegarde sur fichiers
+//-------------------------------------------------------
+
+BRFitsReader::BRFitsReader(RAcqMemZoneMgr& mem, vector<string>& infiles, bool fgnotrl)
+  :  memgr(mem), infiles_(infiles), fgnotrl_(fgnotrl)
+{
+}
+void BRFitsReader::Stop()
+{
+  // cout<< " BRFitsReader:Stop ........ " << endl;
+  stop_=true;
+}
+void BRFitsReader::run()
+{
+  setRC(1);	
+  BRPaqChecker pcheck;  // Verification/comptage des paquets 
+
+  try {
+    TimeStamp ts; 
+    Timer tm("BRFitsReader");
+    size_t totnbytesrd = 0;
+    cout << " BRFitsReader::run() - Starting " << ts << " NbFiles=" << infiles_.size() 
+         << "  memgr.PaqSize() = " << memgr.PaqSize() << endl;
+
+    uint_4  nfileok = 0; 
+    uint_8 nbytesrd = 0;  
+    for(int ifile=0; ifile<infiles_.size(); ifile++) {
+      string ffname = infiles_[ifile];
+// -------------- Lecture de bytes      
+      cout << "BRFitsReader::run() [" << ifile <<"]Ouverture/lecture fichier " << ffname << endl;
+      MiniFITSFile mff(ffname, MF_Read);
+      cout << "... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() 
+  	   << " NAxis2=" << mff.NAxis2() << endl;
+      if (mff.DataType() != MF_Byte) {
+        cout << "BRFitsReader::run() PB : DataType!=MF_Byte --> skipping " << endl;
+        continue;
+      }
+// Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) si fgnotrl=true
+      int incpaqsz=0;
+      int paqsz = 0;
+      if (fgnotrl_) {
+        incpaqsz=16;
+        cout << " Warning : FITS files without frame trailers ..." << endl;
+      }
+      if (paqsz == 0)  {  // premier passage, on fixe la taille de paquet et on alloue le buffer
+        paqsz = mff.NAxis1()+incpaqsz;
+        if (paqsz != memgr.PaqSize()) {
+         cout << "BRFitsReader::run() mff.NAxis1() incompatible with memgr.PaqSize() -> exception " << endl;
+         throw SzMismatchError(" fits file size incompatible with memgr.PaqSize()"); 
+        }
+       if (mff.NAxis2() != memgr.NbPaquets())  {
+         cout << "BRFitsReader::run() mff.NAxis2() <> memgr.NbPaquets() -> exception " << endl;
+         throw SzMismatchError(" fits file NAxies2() <> memgr.NbPaquets()"); 
+        }
+      }
+      else {
+        if (paqsz != mff.NAxis1()+incpaqsz) {
+        cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+" << incpaqsz << " --> skipping " << endl;
+        continue;
+        }
+        if (memgr.NbPaquets() != mff.NAxis2()) {
+        cout << " PB memgr.NbPaquets() != mff.NAxis2()  --> skipping " << endl;
+        continue;
+        }
+      }
+      int mid = memgr.FindMemZoneId(MemZA_Fill);  
+      Byte* buff = memgr.GetMemZone(mid);
+      if (buff == NULL) {
+	cout << " BRFitsReader::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
+	setRC(2);	
+	return;	
+      }
+      size_t sx = mff.NAxis1(); 
+      size_t sy = mff.NAxis2();
+      
+      for(int j=0; j<mff.NAxis2(); j++) {
+        mff.ReadB(buff+j*paqsz, sx, j*sx);
+	BRPaquet paq(NULL, buff+j*paqsz, paqsz);
+	pcheck.Check(paq);   // Verification du paquet / FrameCounter 
+
+      }
+      nfileok++;   
+      size_t nbytesrd = sx*sy;
+      totnbytesrd += nbytesrd;
+      memgr.FreeMemZone(mid, MemZS_Filled);
+    }   // Fin de la boucle sur les fichiers
+
+
+//    sprintf(fname,"%s/.log",path_.c_str());
+//    ofstream filog(fname);
+//    filog << " DataProc::run() - starting log file " << ts << endl;		       
+//    filog << " NbFiles=" << nfiles_ << " NBloc/File="  << nblocperfile_ << " NMaxMemZones=" << nmax_ << endl;
+    	
+
+
+    cout << " ------------------  BRFitsReader::run() END ----------------- " << endl;
+    ts.SetNow();
+    tm.Split();
+    cout << "  END reading " << ts << " NFileOK=" << nfileok << endl; 
+    cout << "  TotalDiskRead= " << totnbytesrd/(1024*1024) << " MBytes Disk-Read rate= " 
+         << (double)(totnbytesrd)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;    
+    pcheck.Print(cout);
+    cout << " ---------------------------------------------------------- " << endl;
+
+  }  // Fin du bloc try 
+  catch (MiniFITSException& exc) {
+    cout << " BRFitsReader::run()/catched MiniFITSException " << exc.Msg() << endl;
+    setRC(3);	
+    return; 
+  }
+  catch(...) {
+    cout << " BRFitsReader::run()/catched unknown ... exception " << endl;
+    setRC(4);	
+    return; 
+  }
+  setRC(0);
+  return;
+}   
Index: /trunk/AddOn/TAcq/brfitsrd.h
===================================================================
--- /trunk/AddOn/TAcq/brfitsrd.h	(revision 3635)
+++ /trunk/AddOn/TAcq/brfitsrd.h	(revision 3635)
@@ -0,0 +1,42 @@
+#ifndef  RARDFITS_H_SEEN
+#define  RARDFITS_H_SEEN
+
+//----------------------------------------------------------------
+// classes de threads pour lecture de fichier fits produit 
+//    par le programme d'acquisition TAcq/ de BAORadio
+// LAL -      R. Ansari - Mai 2009
+//----------------------------------------------------------------
+
+#include "racqumem.h"
+#include <string>
+#include <vector>
+#include <iostream>
+#include "sopnamsp.h"
+#include "zthread.h"
+
+#include "brtypes.h"
+#include "brpaqu.h"
+
+using namespace std;
+
+
+//-------------------------------------------------------
+// Classe thread de lecture des fichiers (mini)fits
+//-------------------------------------------------------
+
+class BRFitsReader : public ZThread {
+public:	
+  BRFitsReader(RAcqMemZoneMgr& mem, vector<string>& infiles, bool fgnotrl=false); 
+
+  virtual void run(); 
+  void Stop(); 
+  inline void STOP() { stop_ = true; }	
+
+protected:
+  RAcqMemZoneMgr& memgr;
+  vector<string> infiles_;
+  bool fgnotrl_;
+  bool stop_;  
+};
+
+#endif
Index: /trunk/AddOn/TAcq/brpaqu.h
===================================================================
--- /trunk/AddOn/TAcq/brpaqu.h	(revision 3634)
+++ /trunk/AddOn/TAcq/brpaqu.h	(revision 3635)
@@ -141,5 +141,5 @@
   inline UInt32 TimeTag1()   {return *((UInt32*)(dst_+(BRTMTAGOFF+OFFSET)));}
   inline UInt32 TimeTag2() {return (*((UInt32*)(dst_+(BRFRCPTOFF+OFFSET))) &0xFFFF);}
-  inline UInt64 TimeTag() {return (*((UInt64*)(dst_+(BRTMTAGOFF+OFFSET))) &0x0000FFFFFFFFFFFFLL);}
+  inline UInt64 TimeTag() {return (*((UInt64*)(dst_+(BRTMTAGOFF+OFFSET))) &0x0000FFFFFFFFFFFFULL);}
 
   inline UInt32 PaqId()     {return *((UInt32*)(dst_+(BRPKTIDOFF+OFFSET)));}
Index: /trunk/AddOn/TAcq/brproc.cc
===================================================================
--- /trunk/AddOn/TAcq/brproc.cc	(revision 3635)
+++ /trunk/AddOn/TAcq/brproc.cc	(revision 3635)
@@ -0,0 +1,172 @@
+#include "racquproc.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fstream>
+#include <signal.h>
+
+#include "pexceptions.h"
+#include "tvector.h"
+#include "fioarr.h"
+#include "timestamp.h"
+#include "ctimer.h"
+#include "fftpserver.h"
+#include "fftwserver.h"
+
+#include "FFTW/fftw3.h"
+
+
+#include "pciewrap.h"
+#include "brpaqu.h"
+#include "brproc.h"
+
+
+//---------------------------------------------------------------
+// Classe thread de traitement donnees ADC avec 2 voies par frame
+//---------------------------------------------------------------
+
+BRProcARaw2C::BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
+  :  memgr(mem) 
+{
+  nmax_ = nmax;	
+  nmean_ = nmean;
+  step_ = step;
+  stop_ = false;	
+  path_ = path;	
+}
+
+void BRProcARaw2C::Stop()
+{
+ stop_=true;
+ // cout <<" BRProcARaw2C::Stop ... > STOP " << endl;
+}
+
+
+static inline r_4 Zmod2(complex<r_4> z) 
+{ return (z.real()*z.real()+z.imag()*z.imag()); }
+
+void BRProcARaw2C::run()
+{
+  setRC(1);	
+  try {
+    Timer tm("BRProcARaw2C");
+    TimeStamp ts; 
+    cout << " BRProcARaw2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 
+	 << " NMean=" << nmean_ << " Step=" << step_ << endl;	
+    cout << " BRProcARaw2C::run()... - Output Data Path: " << path_ << endl;
+    char fname[512];
+//    sprintf(fname,"%s/proc.log",path_.c_str());
+//    ofstream filog(fname);
+//    filog << " BRProcARaw2C::run() - starting log file " << ts << endl;		       
+//    filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;	
+
+// Initialisation pour calcul FFT 
+    TVector< complex<r_4> > cfour;  // composant TF
+    uint_4 paqsz = memgr.PaqSize();
+    uint_4 procpaqsz = memgr.ProcPaqSize();
+    BRPaquet pq(NULL, NULL, paqsz); 
+    TVector<r_4> vx(pq.DataSize()/2);
+    vx = (r_4)(0.);
+    FFTPackServer ffts;
+    ffts.FFTForward(vx, cfour);
+    TVector<r_4> spectreV1, spectreV2;
+  
+    spectreV1.ReSize(cfour.Size());
+    spectreV2.ReSize(cfour.Size());
+    
+    TVector< complex<r_4> > visiV12( cfour.Size() );
+
+
+    uint_4 ifile = 0;  			        
+    uint_4 nzm = 0;
+    for (uint_4 kmz=0; kmz<nmax_; kmz++) {
+      if (stop_) break;
+      int mid = memgr.FindMemZoneId(MemZA_ProcA);
+      Byte* buff = memgr.GetMemZone(mid);
+      if (buff == NULL) {
+  	cout << " BRProcARaw2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
+  	break;		
+      }
+      Byte* procbuff = memgr.GetProcMemZone(mid);
+      if (procbuff == NULL) {
+  	cout << " BRProcARaw2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
+  	break;	
+      }
+      BRPaquet paq0(NULL, buff, paqsz); 
+      for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
+  	BRPaquet paq(NULL, buff+i*paqsz, paqsz); 
+  	Byte min = 255;
+  	Byte max = 0;
+ 
+// Traitement voie 1  	    
+  	for(sa_size_t j=0; j<vx.Size(); j++) 
+  	  vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
+        fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
+        fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(), coeff1, FFTW_ESTIMATE); 
+  	fftwf_execute(plan); 
+        //   ffts_.FFTForward(vx, cfour_);
+        complex<r_4>* zp1 = (complex<r_4>*)(coeff1);
+        for(sa_size_t j=0; j<spectreV1.Size(); j++) 
+          spectreV1(j) += Zmod2(zp1[j]);
+ 
+// Traitement voie 2  	    
+   	for(sa_size_t j=0; j<vx.Size(); j++) 
+ 	  vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
+        fftwf_complex* coeff2 = (fftwf_complex*)(procbuff+i*procpaqsz+procpaqsz/2);
+        plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(), coeff2, FFTW_ESTIMATE); 
+  	fftwf_execute(plan); 
+        //    ffts_.FFTForward(vx, cfour_);
+        complex<r_4>* zp2 = (complex<r_4>*)(coeff2);
+        for(sa_size_t j=0; j<spectreV2.Size(); j++) 
+          spectreV2(j) += Zmod2(zp2[j]); 
+
+// Calcul correlation (visibilite V1 * V2)
+        for(sa_size_t j=0; j<visiV12.Size(); j++) visiV12(j)+=zp1[j]*zp2[j];
+
+        nzm++;
+      }
+      if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
+        spectreV1 /= (r_4)(nzm);
+        spectreV2 /= (r_4)(nzm);
+
+        visiV12 /= complex<r_4>((r_4)nzm, 0.);
+
+        spectreV1.Info()["NPaqMoy"] = nzm;
+        spectreV2.Info()["NPaqMoy"] = nzm;
+        visiV12.Info()["NPaqMoy"] = nzm;
+	{
+    	sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
+        POutPersist po(fname);
+        po << PPFNameTag("specV1") << spectreV1; 
+        po << PPFNameTag("specV2") << spectreV2; 
+        po << PPFNameTag("visiV12") << visiV12; 
+	}
+        spectreV1 = (r_4)(0.);
+        spectreV2 = (r_4)(0.);
+        visiV12 = complex<r_4>(0., 0.);
+        nzm = 0;  ifile++; 
+//        ts.SetNow();
+//        filog << ts << " :  proc file  " << fname << endl;		       
+        cout << " BRProcARaw2C::run() created file  " << fname << endl;
+      }
+      
+      memgr.FreeMemZone(mid, MemZS_ProcA);
+    }
+  }
+  catch (PException& exc) {
+    cout << " BRProcARaw2C::run()/catched PException " << exc.Msg() << endl;
+    setRC(3);	
+    return; 
+  }
+  catch(...) {
+    cout << " BRProcARaw2C::run()/catched unknown ... exception " << endl;
+    setRC(4);	
+    return; 
+  }
+  setRC(0);
+  return;
+}   
+
+
+
+
Index: /trunk/AddOn/TAcq/brproc.h
===================================================================
--- /trunk/AddOn/TAcq/brproc.h	(revision 3635)
+++ /trunk/AddOn/TAcq/brproc.h	(revision 3635)
@@ -0,0 +1,41 @@
+#ifndef  BRPROCA_H_SEEN
+#define  BRPROCA_H_SEEN
+
+//----------------------------------------------------------------
+// ---- classe de thread de traitememt  acquisition BAORadio -----
+// LAL -      R. Ansari - Juin/Juillet 2008 
+//----------------------------------------------------------------
+
+
+#include "racqumem.h"
+#include <string>
+#include <vector>
+#include <iostream>
+#include "sopnamsp.h"
+#include "zthread.h"
+
+#include "brtypes.h"
+
+using namespace std;
+
+
+//---------------------------------------------------------------------
+// Classe thread de traitement avec 2 voies par frame (donnees brutes)
+//---------------------------------------------------------------------
+class BRProcARaw2C : public ZThread {
+public:	
+  BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean=1, uint_4 step=1, uint_4 nmax=100);
+  virtual void run(); 
+  void Stop();
+  inline void STOP() { stop_ = true; }	
+protected:
+  RAcqMemZoneMgr& memgr;
+  bool stop_;  
+  uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
+  uint_4 step_;  // 1/step_ frame traite ds chaque bloc
+  uint_4 nmean_;  // Nombre de blocs pour le calcul des moyennes 
+  string path_;  
+};
+
+
+#endif
Index: /trunk/AddOn/TAcq/makefile
===================================================================
--- /trunk/AddOn/TAcq/makefile	(revision 3634)
+++ /trunk/AddOn/TAcq/makefile	(revision 3635)
@@ -2,8 +2,8 @@
 
 # all : traidio  tmtfft tstminifits tbrpaq tpciew tmtacq tstrdfits mfits2spec tsok 
-all : traidio  tmtfft tstminifits tmtacq tstrdfits mfits2spec tsok 
+all : traidio  tmtfft tstminifits tmtacq tstrdfits mfits2spec tsok mcrd
 
 clean :
-	rm *.o traidio tmtfft tstminifits tpciew tbrpaq tmtacq tstrdfits mfits2spec 
+	rm *.o traidio tmtfft tstminifits tpciew tbrpaq tmtacq tstrdfits mfits2spec mcrd
 	rm mfits2spec tsok *.ppf *.fits 
 
@@ -25,4 +25,19 @@
 racquproc.o : racquproc.cc racquproc.h racqurw.h racqumem.h
 	$(CXXCOMPILE) -c -o racquproc.o racquproc.cc 
+
+## Lecture / traitement minifits multi-thread
+##   --------------
+mcrd : mcrd.o  racqumem.o brfitsrd.o brproc.o racquproc.o brpaqu.o pciewrap.o minifits.o
+	$(CXXLINK) -o mcrd mcrd.o  racqumem.o brfitsrd.o brproc.o racquproc.o brpaqu.o minifits.o $(SOPHYAALLSLBLIST)
+
+mcrd.o : mcrd.cc brfitsrd.h racqumem.h brproc.h 
+	$(CXXCOMPILE) -c  -o mcrd.o mcrd.cc 
+
+brfitsrd.o : brfitsrd.cc brfitsrd.h racqumem.h
+	$(CXXCOMPILE) -c -o brfitsrd.o brfitsrd.cc 
+
+brproc.o : brproc.cc brproc.h racqumem.h
+	$(CXXCOMPILE) -c  -o brproc.o brproc.cc 
+
 
 ##   --------------
Index: /trunk/AddOn/TAcq/mcrd.cc
===================================================================
--- /trunk/AddOn/TAcq/mcrd.cc	(revision 3635)
+++ /trunk/AddOn/TAcq/mcrd.cc	(revision 3635)
@@ -0,0 +1,133 @@
+// Utilisation de SOPHYA pour faciliter les tests ...
+#include "sopnamsp.h"
+#include "machdefs.h"
+
+/* ---------------------------------------------------------- 
+   Programme de lecture multi canaux pour BAORadio  
+   R. Ansari, C. Magneville
+   V : Mai 2009
+   ---------------------------------------------------------- */
+
+// include standard c/c++
+#include <math.h>
+#include <stdio.h>
+
+#include <iostream>
+#include <string>
+
+#include "pexceptions.h"
+#include "tvector.h"
+#include "fioarr.h"
+#include "tarrinit.h" 
+#include "timestamp.h"
+#include "fftpserver.h"
+#include "fftwserver.h"
+
+#include "FFTW/fftw3.h"
+
+// include sophya mesure ressource CPU/memoire ...
+#include "resusage.h"
+#include "ctimer.h"
+#include "timing.h"
+
+
+// include mini-fits lib , et structure paquet BAORadio
+#include "minifits.h"
+#include "brpaqu.h"
+#include "brfitsrd.h"
+#include "brproc.h"
+
+
+//--- Fonctions de ce fichier 
+int DecodeMiniFitsHeader(string& filename, uint_4& paqsz, uint_4& npaq, bool fgnotrl=false) 
+{
+  MiniFITSFile mff(filename, MF_Read);
+  cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() 
+       << " NAxis2=" << mff.NAxis2() << endl;
+  paqsz = mff.NAxis1();
+  npaq = mff.NAxis2();
+  if (fgnotrl)  paqsz += 16;
+  return 0;
+}
+
+//----------------------------------------------------
+//----------------------------------------------------
+int main(int narg, char* arg[])
+{
+  if (narg < 4) {
+    cout << " --- Reading/Processing BAORadio FITS files" << endl;
+    cout << " Usage:  mcrd ACT OutPPF -infits DirName Imin Imax " << endl;
+    cout << " ACT= notrl FITS files without frame trailer \n" 
+         << " OutPPF : Output PPF file name (without .ppf)" << endl;
+    cout << " -infiles DirName Imin Imax : Input fits directory and sequence numbers \n" 
+         << "    FileNames=DirName/signalII.fits Imin<=II<=Imax " << endl;  
+    return 1;
+  }
+
+  TArrayInitiator  _inia;
+
+  int rc = 0;
+  try {
+    string act = arg[1];
+    string outname = arg[2];
+    vector<string> infiles;
+    if ((strcmp(arg[3],"-infits")!=0) || (narg<7)) {
+        cout << " mcrd/Error arguments - type mcrd for help" << endl;
+        return 2;
+    }
+    char nbuff[1024];
+    char* dirname = arg[4]; 
+    int imin = atoi(arg[5]);
+    int imax = atoi(arg[6]);
+    for(int ii=imin; ii<=imax; ii++) {
+      sprintf(nbuff,"%s/signal%d.fits",dirname,ii);
+      infiles.push_back(nbuff);
+    }
+
+    cout << " ---------- mcrd.cc Start - ACT= " << act << " ------------- " << endl;
+    ResourceUsage resu;
+    bool fgnotrl=false;   // fichier fits avec Trailer de frame (> mai 2009)
+    if (act=="notrl") fgnotrl=true;  // fichier fits SANS trailer 
+
+    uint_4 paqsz, npaq;
+    DecodeMiniFitsHeader(infiles[0],paqsz, npaq, fgnotrl); 
+
+    int nzones = 3;
+    RAcqMemZoneMgr mmgr(nzones, npaq, paqsz, sizeof(complex<r_4>)*paqsz);
+    mmgr.SetFinalizedMask((uint_4)MemZS_ProcA);
+
+    BRFitsReader reader(mmgr, infiles, fgnotrl);
+    BRProcARaw2C proc(mmgr, outname, npaq, 1, npaq*infiles.size());
+
+    cout << " mcrd.cc : Starting threads (reader, proc) ... " << endl;
+    reader.start();
+    proc.start();
+    sleep(1);
+    cout << " mcrd.cc : Waiting for reader thread to finish ... " << endl;
+    reader.join();
+    cout << " mcrd.cc : Reader finished, waiting for process thread to finish ... " << endl;
+    sleep(2);
+    mmgr.Stop();
+    proc.join();
+    mmgr.Print(cout);
+    cout << resu ; 
+  }
+  catch (MiniFITSException& exc) {
+    cerr << " mcrd.cc catched MiniFITSException " << exc.Msg() << endl;
+    rc = 77;
+  }  
+  catch (std::exception& sex) {
+    cerr << "\n mcrd.cc std::exception :" 
+         << (string)typeid(sex).name() << "\n msg= " 
+         << sex.what() << endl;
+    rc = 78;
+  }
+  catch (...) {
+    cerr << " mcrd.cc catched unknown (...) exception  " << endl; 
+    rc = 79; 
+  } 
+
+  cout << ">>>> mcrd.cc ------- FIN ----------- RC=" << rc << endl;
+  return rc;
+
+}
Index: /trunk/AddOn/TAcq/mfits2spec.cc
===================================================================
--- /trunk/AddOn/TAcq/mfits2spec.cc	(revision 3634)
+++ /trunk/AddOn/TAcq/mfits2spec.cc	(revision 3635)
@@ -45,9 +45,9 @@
 int ana_data_0(vector<string>& infiles, string& outfile);
 // Fonction d'analyse 2eme version , 1 voie / paquet
-int ana_data_1(vector<string>& infiles, string& oufile);
+int ana_data_1(vector<string>& infiles, string& oufile, bool fgnotrl=false);
 // Fonction d'analyse 2eme version , 2 voies / paquet
-int ana_data_2(vector<string>& infiles, string& oufile);
+int ana_data_2(vector<string>& infiles, string& oufile, bool fgnotrl=false);
 // Fonction d'analyse 2eme version , 2 voies / paquet
-int ana_data_fft_2(vector<string>& infiles, string& oufile);
+int ana_data_fft_2(vector<string>& infiles, string& oufile, bool fgnotrl=false);
 
 //----------------------------------------------------
@@ -59,8 +59,9 @@
     cout << " Usage: mfits2spec ACT OutPPF file1 [file2 file3 ...] " << endl;
     cout << "  Or :  mfits2spec ACT OutPPF -infits DirName Imin Imax " << endl;
-    cout << " ACT=-0,-1,-2,-fft2 \n" 
+    cout << " ACT=-0,-1,-2,-fft2 , -1nt -2nt -fft2nt \n" 
          << "   -0: Nancay-July2008 \n" 
          << "   -1,-2 :  Raw data  1 ou 2 channels / packet(or frame) \n" 
-         << "   -fft2 :  FFT data 2 channels / packet " << endl;
+         << "   -fft2 :  FFT data 2 channels / packet \n"
+         << "   nt : (-1nt -2nt -fft2nt) fits files without frame trailer " << endl;
     cout << " OutPPF : Output PPF file name " << endl;  
     cout << " file1,file2 ... : Input FITS files " << endl;  
@@ -96,8 +97,11 @@
     cout << " ---------- mfits2spec.cc Start - ACT= " << act << " ------------- " << endl;
     ResourceUsage resu;
+    bool fgnotrl=false;   // fichier fits avec Trailer de frame (> mai 2009)
+    if ((act=="-1nt")||(act=="-2nt")||(act=="-fft2nt")) fgnotrl=true;  // fichier fits SANS trailer 
+
     if (act == "-0") ana_data_0(infiles, outppf);
-    else if (act == "-1") ana_data_1(infiles, outppf);
-    else if (act == "-2") ana_data_2(infiles, outppf);
-    else if (act == "-fft2") ana_data_fft_2(infiles, outppf);
+    else if ((act == "-1")||(act=="-1nt")) ana_data_1(infiles, outppf, fgnotrl);
+    else if ((act == "-2")||(act=="-2nt")) ana_data_2(infiles, outppf, fgnotrl);
+    else if ((act == "-fft2")||(act=="-fft2nt")) ana_data_fft_2(infiles, outppf, fgnotrl);
     else cout << " mfits2spec.cc / Bad argument ACT=" << act << " -> exit" << endl;
     cout << resu ; 
@@ -177,5 +181,5 @@
 
 /*--Nouvelle-Fonction--*/
-int ana_data_1(vector<string>& infiles, string& outfile)
+int ana_data_1(vector<string>& infiles, string& outfile, bool fgnotrl)
 // Calcul spectre moyen 1 voie, donnees brutes  
 {
@@ -202,13 +206,18 @@
       continue;
     }
-// Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) ...
+// Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) si fgnotrl=true
+    int incpaqsz=0;
+    if (fgnotrl) {
+      incpaqsz=16;
+      cout << " Warning : FITS files without frame trailers ..." << endl;
+    }
     if (paqsz == 0)  {  // premier passage, on fixe la taille de paquet et on alloue le buffer
-      paqsz = mff.NAxis1()+16;
+      paqsz = mff.NAxis1()+incpaqsz;
       data = new Byte[paqsz];
       for(int ib=0; ib<paqsz; ib++) data[ib]=0;
     }
     else {
-      if (paqsz != mff.NAxis1()+16) {
-      cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+16 --> skipping " << endl;
+      if (paqsz != mff.NAxis1()+incpaqsz) {
+      cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+" << incpaqsz << " --> skipping " << endl;
       continue;
       }
@@ -257,5 +266,5 @@
 
 /*--Nouvelle-Fonction--*/
-int ana_data_2(vector<string>& infiles, string& outfile)
+int ana_data_2(vector<string>& infiles, string& outfile, bool fgnotrl)
 // Calcul spectres moyens 2 voies, donnees brutes  
 {
@@ -284,7 +293,12 @@
       continue;
     }
-// Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) ...
+// Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) si fgnotrl=true
+    int incpaqsz=0;
+    if (fgnotrl) {
+      incpaqsz=16;
+      cout << " Warning : FITS files without frame trailers ..." << endl;
+    }
     if (paqsz == 0)  {  // premier passage, on fixe la taille de paquet et on alloue le buffer
-      paqsz = mff.NAxis1()+16;
+      paqsz = mff.NAxis1()+incpaqsz;
       cout << " ana_data_2/ Allocating data , PaqSz=" << paqsz << endl;
       data = new Byte[paqsz];
@@ -292,6 +306,6 @@
     }
     else {
-      if (paqsz != mff.NAxis1()+16) {
-      cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+16 --> skipping " << endl;
+      if (paqsz != mff.NAxis1()+incpaqsz) {
+      cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+" << incpaqsz << " --> skipping " << endl;
       continue;
       }
@@ -359,5 +373,5 @@
 
 /*--Nouvelle-Fonction--*/
-int ana_data_fft_2(vector<string>& infiles, string& outfile)
+int ana_data_fft_2(vector<string>& infiles, string& outfile, bool fgnotrl)
 // Calcul spectres moyens 2 voies, donnees brutes  
 {
@@ -385,7 +399,12 @@
       continue;
     }
-// Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) ...
+// Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) si fgnotrl=true
+    int incpaqsz=0;
+    if (fgnotrl) {
+      incpaqsz=16;
+      cout << " Warning : FITS files without frame trailers ..." << endl;
+    }
     if (paqsz == 0)  {  // premier passage, on fixe la taille de paquet et on alloue le buffer
-      paqsz = mff.NAxis1()+16;
+      paqsz = mff.NAxis1()+incpaqsz;
       cout << " ana_data_fft_2/ Allocating data , PaqSz=" << paqsz << endl;
       data = new Byte[paqsz];
@@ -393,6 +412,6 @@
     }
     else {
-      if (paqsz != mff.NAxis1()+16) {
-      cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+16 --> skipping " << endl;
+      if (paqsz != mff.NAxis1()+incpaqsz) {
+      cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+" << incpaqsz << " --> skipping " << endl;
       continue;
       }
Index: /trunk/AddOn/TAcq/racqumem.cc
===================================================================
--- /trunk/AddOn/TAcq/racqumem.cc	(revision 3634)
+++ /trunk/AddOn/TAcq/racqumem.cc	(revision 3635)
@@ -7,6 +7,6 @@
 
 /* --Methode-- */
-RAcqMemZoneMgr::RAcqMemZoneMgr(uint_4 nz, uint_4 np, uint_4 psz)
-  : mex(true), nzones(nz), npaq(np), paqsz(psz), stop_(false)
+RAcqMemZoneMgr::RAcqMemZoneMgr(uint_4 nz, uint_4 np, uint_4 psz, uint_4 procpsz)
+  : mex(true), nzones(nz), npaq(np), paqsz(psz), procpaqsz(procpsz),stop_(false)
 {
   St_MemZ st;
@@ -17,8 +17,10 @@
   for(int k=0; k<6; k++) st.nbact[k] = 0;
   uint_8 mzsz = npaq*paqsz;
+  uint_8 procmzsz = npaq*procpaqsz;
 
    for(int k=0; k<NbZones(); k++) {
      memzones.push_back(new Byte[mzsz] );
      states.push_back(st);
+     if (procmzsz > 0)  procmemzones.push_back(new Byte[procmzsz] );
    }
   serial_ = 0;
@@ -43,5 +45,6 @@
   int rid = -1;
   if (stop_) return rid;
-  if ((act != MemZA_Fill) && (act != MemZA_Save) && (act != MemZA_Proc)) return rid;
+  if ((act != MemZA_Fill) && (act != MemZA_Save) && (act != MemZA_Proc) &&
+      (act != MemZA_ProcA) && (act != MemZA_ProcB) && (act != MemZA_ProcC)) return rid;
   mex.lock();
   uint_8 bestserial = serial_ + 5;
@@ -184,4 +187,8 @@
   os << "RAcqMemZoneMgr::Print() NbZones=" << NbZones() << " PaqSize()=" << PaqSize()
      << " NbPaquets()=" << NbPaquets() << " ZoneSize()=" << ZoneSize() << endl;
+  if (ProcPaqSize() > 0)  
+    cout << " ... With Processed Data Zones ProcPaqSize()=" << ProcPaqSize() 
+         << " ProcZoneSize()=" << ProcZoneSize() << endl;
+  else cout << " ... NO Processed Data Zones" << endl;
   for(uint_4 k=0; k<states.size(); k++) 
     os << " [" << k << "] Act=" << states[k].act << " Stat=" << states[k].stat 
Index: /trunk/AddOn/TAcq/racqumem.h
===================================================================
--- /trunk/AddOn/TAcq/racqumem.h	(revision 3634)
+++ /trunk/AddOn/TAcq/racqumem.h	(revision 3635)
@@ -47,5 +47,7 @@
 public:
 // Constructeur, nz=Nb de zones, np=Nb de paquets/zone , psz=taille de paquet
-  RAcqMemZoneMgr(uint_4 nz, uint_4 np=256, uint_4 psz=4096);
+//     Si procpsz>0 , on alloue aussi des zones memoire pour donnees traitees
+//      dans ce cas, procpsz à la taille memoire des donnees traites pour chaque paquet 
+  RAcqMemZoneMgr(uint_4 nz, uint_4 np=256, uint_4 psz=4096, uint_4 procpsz=0);
   ~RAcqMemZoneMgr();
   
@@ -58,4 +60,9 @@
   // Retourne la taille totale d'une zone 
   inline uint_4 ZoneSize() { return npaq*paqsz; }
+
+  // Retourne la taille de la zone memoire correspondant aux donnees traitees d'un paquet
+  inline uint_4 ProcPaqSize() { return procpaqsz; }
+  // Retourne la taille totale d'une zone de donnees traitees
+  inline uint_4 ProcZoneSize() { return npaq*procpaqsz; }
   
   // Definit l'etat des operations obligatoires avant qu'une zone 
@@ -74,4 +81,8 @@
     return memzones[id];  
     }
+  inline Byte* GetProcMemZone(int id)  {
+    if ((id < 0) || (id >=(int) procmemzones.size()))  return NULL;
+    return procmemzones[id];  
+    }
   
   ostream& Print(ostream& os);
@@ -81,8 +92,9 @@
   // ... variables membres
   ZMutex mex;   
-  uint_4 nzones, npaq, paqsz;
+  uint_4 nzones, npaq, paqsz, procpaqsz;
 //  DMAMgrInterface &dma_;
   vector< Byte* > memzones;
   vector< St_MemZ > states; 
+  vector< Byte* > procmemzones;
   bool stop_;
   uint_4 mask_finalized_;
Index: /trunk/AddOn/TAcq/racquproc.cc
===================================================================
--- /trunk/AddOn/TAcq/racquproc.cc	(revision 3634)
+++ /trunk/AddOn/TAcq/racquproc.cc	(revision 3635)
@@ -42,5 +42,5 @@
 }
 
-inline r_4 Zmod2(complex<r_4> z) 
+static inline r_4 Zmod2(complex<r_4> z) 
 { return (z.real()*z.real()+z.imag()*z.imag()); }
 
Index: /trunk/AddOn/TAcq/racqurw.cc
===================================================================
--- /trunk/AddOn/TAcq/racqurw.cc	(revision 3634)
+++ /trunk/AddOn/TAcq/racqurw.cc	(revision 3635)
@@ -274,4 +274,5 @@
 
 	  if (savesig_) // Reza - Ecriture conditionnel fichier fits signal 
+	    mff.WriteB(paq.Header(),paq.PaquetSize()); // ecriture tout le paquet (modif Mai 2009
 	  //  mff.WriteB(paq.Data1(), paq.DataSize());
 	    mff.WriteB(paq.Header(),paq.DataSize()+paq.HeaderSize()); // ecriture datas + header
