Index: trunk/SophyaLib/NTools/fftpserver.cc
===================================================================
--- trunk/SophyaLib/NTools/fftpserver.cc	(revision 2988)
+++ trunk/SophyaLib/NTools/fftpserver.cc	(revision 3002)
@@ -40,7 +40,9 @@
 
 
-FFTPackServer::FFTPackServer()
+//! Constructor - If preserve_input==true, input arrays will not be overwritten.
+FFTPackServer::FFTPackServer(bool preserve_input)
    : FFTServerInterface("FFTPackServer using extended FFTPack (C-version) package")
-  , ckR4("FFTPackServer: ", true, true) , ckR8("FFTPackServer: ", true, true)
+  , ckR4("FFTPackServer: ", true, true) , ckR8("FFTPackServer: ", true, true),
+  _preserve_input(preserve_input)
 {
 //the working array and its size for the different
@@ -66,9 +68,9 @@
 FFTServerInterface * FFTPackServer::Clone()
 {
-  return (new FFTPackServer);
-}
-
-
-void FFTPackServer::FFTForward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out)
+  return (new FFTPackServer(_preserve_input) );
+}
+
+
+void FFTPackServer::FFTForward(TArray< complex<r_8> > & in, TArray< complex<r_8> > & out)
 {
   ckR8.CheckResize(in, out);
@@ -78,5 +80,5 @@
 }
 
-void FFTPackServer::FFTBackward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out)
+void FFTPackServer::FFTBackward(TArray< complex<r_8> > & in, TArray< complex<r_8> > & out)
 {
   ckR8.CheckResize(in, out);
@@ -86,5 +88,5 @@
 
 
-void FFTPackServer::FFTForward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out)
+void FFTPackServer::FFTForward(TArray< complex<r_4> > & in, TArray< complex<r_4> > & out)
 {
   ckR4.CheckResize(in, out);  
@@ -94,5 +96,5 @@
 }
 
-void FFTPackServer::FFTBackward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out)
+void FFTPackServer::FFTBackward(TArray< complex<r_4> > & in, TArray< complex<r_4> > & out)
 {
   ckR4.CheckResize(in, out);  
@@ -101,8 +103,9 @@
 }
 
-void FFTPackServer::FFTForward(TArray< r_4 > const & in, TArray< complex<r_4> > & out)
-{
-  ckR4.CheckResize(in, out);  
-  TArray< r_4 > inout(in, false);
+void FFTPackServer::FFTForward(TArray< r_4 > & in, TArray< complex<r_4> > & out)
+{
+  ckR4.CheckResize(in, out);
+  bool share = (_preserve_input) ? false : true;
+  TArray< r_4 > inout(in, share);
   fftf(inout.Size(), inout.Data());
   ReShapetoCompl(inout, out);
@@ -110,5 +113,5 @@
 }
 
-void FFTPackServer::FFTBackward(TArray< complex<r_4> > const & in, TArray< r_4 > & out,
+void FFTPackServer::FFTBackward(TArray< complex<r_4> > & in, TArray< r_4 > & out,
 				bool usoutsz)
 {
@@ -119,8 +122,9 @@
 
 
-void FFTPackServer::FFTForward(TArray< r_8 > const & in, TArray< complex<r_8> > & out)
+void FFTPackServer::FFTForward(TArray< r_8 > & in, TArray< complex<r_8> > & out)
 {
   ckR8.CheckResize(in, out);  
-  TArray< r_8 > inout(in, false);
+  bool share = (_preserve_input) ? false : true;
+  TArray< r_8 > inout(in, share);
   fftf(inout.Size(), inout.Data());
   ReShapetoCompl(inout, out);
@@ -128,5 +132,5 @@
 }
 
-void FFTPackServer::FFTBackward(TArray< complex<r_8> > const & in, TArray< r_8 > & out,
+void FFTPackServer::FFTBackward(TArray< complex<r_8> > & in, TArray< r_8 > & out,
 				bool usoutsz)
 {
Index: trunk/SophyaLib/NTools/fftpserver.h
===================================================================
--- trunk/SophyaLib/NTools/fftpserver.h	(revision 2988)
+++ trunk/SophyaLib/NTools/fftpserver.h	(revision 3002)
@@ -15,5 +15,5 @@
 class FFTPackServer : public FFTServerInterface {
  public:
-  FFTPackServer();
+  FFTPackServer(bool preserve_input=true);
   virtual ~FFTPackServer();
 
@@ -23,15 +23,15 @@
 
   // Transforme unidimensionnel sur des double
-  virtual void FFTForward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out);
-  virtual void FFTBackward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out);
-  virtual void FFTForward(TArray< r_8 > const & in, TArray< complex<r_8> > & out);
-  virtual void FFTBackward(TArray< complex<r_8> > const & in, TArray< r_8 > & out, 
+  virtual void FFTForward(TArray< complex<r_8> > & in, TArray< complex<r_8> > & out);
+  virtual void FFTBackward(TArray< complex<r_8> > & in, TArray< complex<r_8> > & out);
+  virtual void FFTForward(TArray< r_8 > & in, TArray< complex<r_8> > & out);
+  virtual void FFTBackward(TArray< complex<r_8> > & in, TArray< r_8 > & out, 
 			   bool usoutsz=false);
 
   // Transforme unidimensionnel sur des float
-  virtual void FFTForward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out);
-  virtual void FFTBackward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out);
-  virtual void FFTForward(TArray< r_4 > const & in, TArray< complex<r_4> > & out);
-  virtual void FFTBackward(TArray< complex<r_4> > const & in, TArray< r_4 > & out,
+  virtual void FFTForward(TArray< complex<r_4> > & in, TArray< complex<r_4> > & out);
+  virtual void FFTBackward(TArray< complex<r_4> > & in, TArray< complex<r_4> > & out);
+  virtual void FFTForward(TArray< r_4 > & in, TArray< complex<r_4> > & out);
+  virtual void FFTBackward(TArray< complex<r_4> > & in, TArray< r_4 > & out,
 			   bool usoutsz=false);
 
@@ -72,4 +72,6 @@
   FFTArrayChecker<r_4> ckR4;
   FFTArrayChecker<r_8> ckR8;
+  bool _preserve_input; // if true, input arrays not overwritten
+
 };
 
Index: trunk/SophyaLib/NTools/fftservintf.cc
===================================================================
--- trunk/SophyaLib/NTools/fftservintf.cc	(revision 2988)
+++ trunk/SophyaLib/NTools/fftservintf.cc	(revision 3002)
@@ -71,5 +71,5 @@
   \param out : Output complex array
  */
-void FFTServerInterface::FFTForward(TArray< complex<r_8> > const &, TArray< complex<r_8> > &)
+void FFTServerInterface::FFTForward(TArray< complex<r_8> > &, TArray< complex<r_8> > &)
 {
   throw NotAvailableOperation("FFTServer::FFTForward(TArray...) Unsupported operation !");
@@ -82,5 +82,5 @@
   \param out : Output complex array
  */
-void FFTServerInterface::FFTBackward(TArray< complex<r_8> > const &, TArray< complex<r_8> > &)
+void FFTServerInterface::FFTBackward(TArray< complex<r_8> > &, TArray< complex<r_8> > &)
 {
   throw NotAvailableOperation("FFTServer::FFTBackward(TArray...) Unsupported operation !");
@@ -93,5 +93,5 @@
   \param out : Output complex array
  */
-void FFTServerInterface::FFTForward(TArray< r_8 > const &, TArray< complex<r_8> > &)
+void FFTServerInterface::FFTForward(TArray< r_8 > &, TArray< complex<r_8> > &)
 {
   throw NotAvailableOperation("FFTServer::FFTForward(TArray...) Unsupported operation !");
@@ -110,5 +110,5 @@
   size_out_real = 2*size_in_complex - ( 1 or 2)   
  */
-void FFTServerInterface::FFTBackward(TArray< complex<r_8> > const &, TArray< r_8 > &, bool)
+void FFTServerInterface::FFTBackward(TArray< complex<r_8> > &, TArray< r_8 > &, bool)
 {
   throw NotAvailableOperation("FFTServer::FFTBackward(TArray...) Unsupported operation !");
@@ -124,5 +124,5 @@
   \param out : Output complex array
  */
-void FFTServerInterface::FFTForward(TArray< complex<r_4> > const &, TArray< complex<r_4> > &)
+void FFTServerInterface::FFTForward(TArray< complex<r_4> > &, TArray< complex<r_4> > &)
 {
   throw NotAvailableOperation("FFTServer::FFTForward(TArray r_4 ... ) Unsupported operation !");
@@ -135,5 +135,5 @@
   \param out : Output complex array
  */
-void FFTServerInterface::FFTBackward(TArray< complex<r_4> > const &, TArray< complex<r_4> > &)
+void FFTServerInterface::FFTBackward(TArray< complex<r_4> > &, TArray< complex<r_4> > &)
 {
   throw NotAvailableOperation("FFTServer::FFTBackward(TArray r_4 ... ) Unsupported operation !");
@@ -146,5 +146,5 @@
   \param out : Output complex array
  */
-void FFTServerInterface::FFTForward(TArray< r_4 > const &, TArray< complex<r_4> > &)
+void FFTServerInterface::FFTForward(TArray< r_4 > &, TArray< complex<r_4> > &)
 {
   throw NotAvailableOperation("FFTServer::FFTForward(TArray r_4 ... ) Unsupported operation !");
@@ -163,5 +163,5 @@
   size_out_real = 2*size_in_complex - ( 1 or 2)   
 */
-void FFTServerInterface::FFTBackward(TArray< complex<r_4> > const &, TArray< r_4 > &, bool)
+void FFTServerInterface::FFTBackward(TArray< complex<r_4> > &, TArray< r_4 > &, bool)
 {
   throw NotAvailableOperation("FFTServer::FFTBackward(TArray r_4 ... ) Unsupported operation !");
Index: trunk/SophyaLib/NTools/fftservintf.h
===================================================================
--- trunk/SophyaLib/NTools/fftservintf.h	(revision 2988)
+++ trunk/SophyaLib/NTools/fftservintf.h	(revision 3002)
@@ -36,13 +36,13 @@
   //---------------------------------------------------
   // Transforme N-dim sur des doubles
-  virtual void FFTForward(TArray<r_4> const & in, TArray< complex<r_4> > & out);
-  virtual void FFTForward(TArray<r_8> const & in, TArray< complex<r_8> > & out); 
-  virtual void FFTForward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out);
-  virtual void FFTForward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out);
+  virtual void FFTForward(TArray<r_4> & in, TArray< complex<r_4> > & out);
+  virtual void FFTForward(TArray<r_8> & in, TArray< complex<r_8> > & out); 
+  virtual void FFTForward(TArray< complex<r_4> > & in, TArray< complex<r_4> > & out);
+  virtual void FFTForward(TArray< complex<r_8> > & in, TArray< complex<r_8> > & out);
 
-  virtual void FFTBackward(TArray< complex<r_4> > const & in, TArray<r_4> & out,bool usoutsz=false);
-  virtual void FFTBackward(TArray< complex<r_8> > const & in, TArray<r_8> & out,bool usoutsz=false);
-  virtual void FFTBackward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out);
-  virtual void FFTBackward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out);
+  virtual void FFTBackward(TArray< complex<r_4> > & in, TArray<r_4> & out,bool usoutsz=false);
+  virtual void FFTBackward(TArray< complex<r_8> > & in, TArray<r_8> & out,bool usoutsz=false);
+  virtual void FFTBackward(TArray< complex<r_4> > & in, TArray< complex<r_4> > & out);
+  virtual void FFTBackward(TArray< complex<r_8> > & in, TArray< complex<r_8> > & out);
 
  protected:
Index: trunk/SophyaLib/NTools/toeplitzMatrix.cc
===================================================================
--- trunk/SophyaLib/NTools/toeplitzMatrix.cc	(revision 2988)
+++ trunk/SophyaLib/NTools/toeplitzMatrix.cc	(revision 3002)
@@ -28,5 +28,5 @@
 Toeplitz::Toeplitz() : hermitian_(false)
   {
-    fftIntfPtr_=new FFTPackServer;
+    fftIntfPtr_=new FFTPackServer(true);  // true -> on ne surecrit pas les input
     fftIntfPtr_->setNormalize(false);
   }
@@ -36,5 +36,5 @@
 Toeplitz::Toeplitz(const TVector<complex<double> >& firstCol) : hermitian_(false)
   {
-    fftIntfPtr_=new FFTPackServer;
+    fftIntfPtr_=new FFTPackServer(true); // true -> on ne surecrit pas les input
     fftIntfPtr_->setNormalize(false);
     setMatrix(firstCol); 
Index: trunk/SophyaLib/NTools/toeplitzMatrix.h
===================================================================
--- trunk/SophyaLib/NTools/toeplitzMatrix.h	(revision 2988)
+++ trunk/SophyaLib/NTools/toeplitzMatrix.h	(revision 3002)
@@ -79,11 +79,13 @@
 
 
+// Reza+CMV du 3/7/2006 : on a instancie le FFTPackServer avec le flag preserveinput=true
+// On peut donc faire en principe les const_cast sans danger 
 inline void transformeeFourier(const TVector<complex<double> >& v, TVector< complex<double> >& tv) const
 {
-  fftIntfPtr_-> FFTForward(v, tv);
+  fftIntfPtr_-> FFTForward(const_cast<TVector<complex<double> > & >(v), tv);
 } 
 inline void transformeeFourier(const TVector<double>& v, TVector< complex<double> >& tv) const
 {
-  fftIntfPtr_-> FFTForward(v, tv);
+  fftIntfPtr_-> FFTForward(const_cast<TVector<double> & >(v), tv);
 } 
 
@@ -92,5 +94,5 @@
 {
   int n= tv.Size();
-  fftIntfPtr_-> FFTBackward(tv, v);
+  fftIntfPtr_-> FFTBackward(const_cast<TVector<complex<double> > & >(tv), v);
   v/=n;
 } 
@@ -98,5 +100,5 @@
 {
   int n= tv.Size();
-  fftIntfPtr_-> FFTBackward(tv, v);
+  fftIntfPtr_-> FFTBackward(const_cast< TVector<complex<double> > & >(tv), v);
   double fac = 1./(2*(n-1));
   v *= fac;
