Index: trunk/SophyaPI/ProgPI/sopiamodule.cc
===================================================================
--- trunk/SophyaPI/ProgPI/sopiamodule.cc	(revision 2904)
+++ trunk/SophyaPI/ProgPI/sopiamodule.cc	(revision 2920)
@@ -31,5 +31,8 @@
 }
 
-void SophyaFFT(string& nom, string& nomout, string dopt);
+void SophyaFFT_forw(string& nom, string& nomout, string dopt);
+void SophyaFFT_back(string& nom, string& nomout, string dopt);
+void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt);
+void SophyaFFT_filter(string& nom, string& nomfilter, string dopt);
 
 class sopiamoduleExecutor : public CmdExecutor {
@@ -194,16 +197,44 @@
 
 string hgrp = "SophyaCmd";
-string kw = "powerspec";
-string usage = "FFT on a vector -> Plots power spectrum ";
-usage += "\n Usage: fftp vecName vecFFT [graphic_att] ";
-mpiac->RegisterCommand(kw, usage, this, hgrp);
+string kw,usage;
+
+kw = "powerspec";
+usage = "FFT on a vector -> Plots power spectrum ";
+usage += "\n Usage: powerspec vecName vecFFT [graphic_att] ";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+
+kw = "fftforw";
+usage = "FFT on a vector -> Plots power spectrum (same as powerspec)";
+usage += "\n Usage: fftforw vecName vecFFT [graphic_att] ";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+
+kw = "fftback";
+usage = "FFT on a vector -> Plots power spectrum";
+usage += "\n Usage: fftback vecFFT vecName [graphic_att] ";
+usage += "\n  vecFFT is complex<r_8>";
+usage += "\n  If vecName already exist, it gives the type(r_8 or complex<r_8>)";
+usage += "\n  If vecName does not exist, return type is complex<r_8>";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+
+kw = "crefilter";
+usage = "Create a filter for vecFFT (vector complex<r_8>)";
+usage += "\n Usage: crefilter vecFFT filter f(x) [graphic_att] ";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+
+kw = "fftfilter";
+usage = "Filter (multiply) vecFFT (vector complex<r_8>) by filter (vector<r_8>)";
+usage += "\n Usage: fftfilter vecFFT filter [graphic_att] ";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+
 kw = "mollgridsph";
 usage = "Creates a spherical coordinate grid in Molleweide projection ";
 usage += "\n Usage: mollgridsph NameSphericalMap [Nb_Parallel Nb_Meridien graphic_att] ";
 mpiac->RegisterCommand(kw, usage, this, hgrp);
+
 kw = "mollgrid";
 usage = "Creates a spherical coordinate grid in Molleweide projection ";
 usage += "\n Usage: mollgrid [Nb_Parallel Nb_Meridien graphic_att] ";
 mpiac->RegisterCommand(kw, usage, this, hgrp);
+
 kw = "setprjmoldefval";
 usage = "Set default value for Molleweide projection of spherical maps (outside maps)";
@@ -222,12 +253,37 @@
 {
 
-if (kw == "powerspec") {
+if (kw == "powerspec" || kw == "fftforw") {
   if (tokens.size() < 2) {
     cout << "Usage: powerspec nameVec vecFFT [graphic_att]" << endl;
     return(0);
     }
-  if (tokens.size() < 3)  tokens.push_back((string)"n");
-  SophyaFFT(tokens[0], tokens[1], tokens[2]);
-  }
+  if (tokens.size() < 3)  tokens.push_back((string)"");
+  SophyaFFT_forw(tokens[0], tokens[1], tokens[2]);
+  }
+else if (kw == "fftback") {
+  if (tokens.size() < 2) {
+    cout << "Usage: fftback vecFFT nameVec [graphic_att]" << endl;
+    return(0);
+    }
+  if (tokens.size() < 3)  tokens.push_back((string)"");
+  SophyaFFT_back(tokens[0], tokens[1], tokens[2]);
+  }
+else if (kw == "crefilter") {
+  if (tokens.size() < 3) {
+    cout << "Usage: crefilter vecFFT filter f(x) [graphic_att]" << endl;
+    return(0);
+    }
+  if (tokens.size() < 4)  tokens.push_back((string)"");
+  SophyaFFT_crefilter(tokens[0], tokens[1], tokens[2], tokens[3]);
+  }
+else if (kw == "fftfilter") {
+  if (tokens.size() < 2) {
+    cout << "Usage: fftfilter vecFFT filter [graphic_att]" << endl;
+    return(0);
+    }
+  if (tokens.size() < 3)  tokens.push_back((string)"");
+  SophyaFFT_filter(tokens[0], tokens[1], tokens[2]);
+  }
+
 else if (kw == "prjmoldefval") {
   if (tokens.size() < 1) {
@@ -315,30 +371,144 @@
 
 
-/* --Methode-- */
-void SophyaFFT(string& nom, string& nomout, string dopt)
-{
-Timer tm("powerspec");
+/*  Nouvelle-Fonction */
+void SophyaFFT_forw(string& nom, string& nomout, string dopt)
+{
+//Timer tm("powerspec");
 NamedObjMgr omg;
 AnyDataObj* obj=omg.GetObj(nom);
 if (obj == NULL) {
-  cout << "SophyaFFT() Error , Pas d'objet de nom " << nom << endl;
-  return;
-}
-
-Vector* vin = dynamic_cast<Vector *>(obj);
-if (vin == NULL) {
-  cout << "SophyaFFT() Error , Objet n'est pas un vecteur " <<  endl;
-  return;
-  }
-TVector< complex<double> > * vout = new TVector< complex<double> >  ;
+  cout<<"SophyaFFT_forw() Error , Pas d'objet de nom "<<nom<<endl;
+  return;
+}
+
+TVector<r_8>* vin = dynamic_cast<TVector<r_8> *>(obj);
+TVector< complex<r_8> >* vinc = dynamic_cast<TVector< complex<r_8> >*>(obj);
+if (vin == NULL && vinc == NULL) {
+  cout<<"SophyaFFT_forw() Error , Objet n'est pas un vecteur r_8 ou complex<r_8>"<<endl;
+  return;
+}
+TVector< complex<r_8> > * vout = new TVector< complex<r_8> >  ;
 FFTPackServer ffts;
-cout << "SophyaFFT() - Computing FFT of vector size " << vin->NElts() << endl;
-ffts.FFTForward(*vin, *vout);
+if(vin!=NULL) {
+  cout<<"SophyaFFT_forw() - Computing FFT of TVector<r_8> of size "<<vin->NElts()<< endl;
+  ffts.FFTForward(*vin, *vout);
+  cout<<"...Output TVector<complex<r_8>> of size: "<<vout->NElts()<<endl;
+} else {
+  cout<<"SophyaFFT_forw() - Computing FFT of vector TVector<complex<r_8>> of size "<<vinc->NElts()<< endl;
+  ffts.FFTForward(*vinc, *vout);
+  cout<<"...Output TVector<complex<r_8>> of size: "<<vout->NElts()<<endl;
+}
 // cout << " SophyaFFT - FFT done " << endl;
  // tm.Split(" FFT done ");
 
 omg.AddObj(vout, nomout);
-omg.DisplayObj(nomout, dopt);
+if(dopt.size()>0) omg.DisplayObj(nomout, dopt);
 return;
 
 }
+
+
+/*  Nouvelle-Fonction */
+void SophyaFFT_back(string& nom, string& nomout, string dopt)
+{
+  //Timer tm("powerspec");
+NamedObjMgr omg;
+AnyDataObj* obj=omg.GetObj(nom);
+if (obj == NULL) {
+  cout << "SophyaFFT_back() Error , Pas d'objet de nom " << nom << endl;
+  return;
+}
+
+TVector< complex<r_8> >* vinc = dynamic_cast<TVector< complex<r_8> >*>(obj);
+if (vinc == NULL) {
+  cout << "SophyaFFT_back() Error , Objet n'est pas un vecteur complex<r_8>" <<  endl;
+  return;
+  }
+
+TVector< r_8 > * vout = NULL;
+TVector< complex<r_8> > * voutc = NULL;
+obj=omg.GetObj(nomout);
+if(obj == NULL) {
+  voutc = new TVector< complex<r_8> >;
+} else {
+  vout = dynamic_cast<TVector<r_8>*>(obj);
+  if(vout==NULL) voutc = dynamic_cast<TVector< complex<r_8> >*>(obj);
+}
+if(vout==NULL && voutc==NULL) {
+ cout << "SophyaFFT_back() Error , Output objet n'est pas un vecteur r_8 ou complex<r_8>" <<  endl;
+ return;
+}
+
+FFTPackServer ffts;
+cout << "SophyaFFT_back() - Computing Backward FFT of vector size " << vinc->NElts() << endl;
+if(vout!=NULL) {
+  ffts.FFTBackward(*vinc, *vout);
+  cout<<"...Output TVector<r_8> of size: "<<vout->NElts()<<endl;
+  omg.AddObj(vout, nomout);
+} else {
+  ffts.FFTBackward(*vinc, *voutc);
+  cout<<"...Output TVector<complex<r_8>> of size: "<<voutc->NElts()<<endl;
+  omg.AddObj(voutc, nomout);
+}
+
+if(dopt.size()>0) omg.DisplayObj(nomout, dopt);
+return;
+}
+
+/*  Nouvelle-Fonction */
+void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt)
+{
+NamedObjMgr omg;
+AnyDataObj* obj=omg.GetObj(nomvec);
+if(obj == NULL) {
+  cout<<"SophyaFFT_crefilter() Error , Pas d'objet de nom "<<nomvec<<endl;
+  return;
+}
+
+TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj);
+if(vfft == NULL) {
+  cout<<"SophyaFFT_crefilter() Error , Objet "<<nomvec<<" n'est pas un Tvector<complex<r_8>>"<< endl;
+  return;
+}
+int n = vfft->Size();
+if(n<=0) return;
+
+cout<<"Creating filter "<<nomfilter<<"("<<n<<") from vec "<<nomvec<<" with fun "<<func<<endl;
+omg.GetServiceObj()->PlotFunc(func,nomfilter,0.,(double)n,n,dopt); 
+}
+
+/*  Nouvelle-Fonction */
+void SophyaFFT_filter(string& nom, string& nomfilter, string dopt)
+{
+NamedObjMgr omg;
+AnyDataObj* obj=omg.GetObj(nom);
+if(obj == NULL) {
+  cout<<"SophyaFFT_filter() Error , Pas d'objet de nom "<<nom<<endl;
+  return;
+}
+
+AnyDataObj* objfilter=omg.GetObj(nomfilter);
+if(objfilter == NULL) {
+  cout<<"SophyaFFT_filter() Error , Pas d'objet de nom "<<nomfilter<<endl;
+  return;
+}
+
+TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj);
+if(vfft == NULL) {
+  cout<<"SophyaFFT_filter() Error , Objet "<<nom<<" n'est pas un Tvector<complex<r_8>>"<< endl;
+  return;
+}
+
+TVector<r_8>* vfilter = dynamic_cast<TVector<r_8>*>(objfilter);
+if(vfft == NULL) {
+  cout<<"SophyaFFT_filter() Error , Objet "<<nomfilter<<" n'est pas un Tvector<r_8>"<<endl;
+  return;
+}
+
+int n = (vfilter->Size()<vfft->Size()) ? vfilter->Size(): vfft->Size();
+cout<<"...filtering from 0 to "<<n<<endl;
+for(int i=0;i<n;i++) (*vfft)(i) *= (*vfilter)(i);
+
+if(dopt.size()>0) omg.DisplayObj(nom,dopt);
+return;
+}
