Index: trunk/SophyaProg/PrgMap/map2cl.cc
===================================================================
--- trunk/SophyaProg/PrgMap/map2cl.cc	(revision 1841)
+++ trunk/SophyaProg/PrgMap/map2cl.cc	(revision 2051)
@@ -34,8 +34,9 @@
    -iter_order lval : 1,2,3,4... order of an iterative analysis,
               3rd order is usually optimal (default=0 -> standard analysis)
-   -fitsout: Select the FITS format for the output map (default PPF format)
-   -fitsin : Select the FITS format for the input vector (default PPF format)
+   -keepalm : Save Alm's as a 2-D array (Matrix) 
+   -fitsout: Select the FITS format for the output vector/alm's (default PPF format)
+   -fitsin : Select the FITS format for the input map (default PPF format)
    InFileName : Input file name (HEALPix map)
-   OutFileName : Output file name (the C_l vector)
+   OutFileName : Output file name (the C_l vector / and Alm's)
 
   \endverbatim
@@ -53,12 +54,14 @@
     cout << " map2cl : Spherical harmonics analysis - HEALPix map -> Power spectrum C_l \n" 
 	 << " Usage: map2cl [-float/-r4] [-lmax lval] [-thetacut dtdeg] [-iter_order lval]\n" 
-	 << "        [-fitsin] [-fitsout] InFileName OutFileName \n" 
+	 << "        [-keepalm AlmFileName] [-fitsin] [-fitsout] InFileName OutFileName \n" 
 	 << "   -float (-r4): single precision C_l and map (default = double) \n"
 	 << "   -lmax lval: Maximum value for l index (default=255)\n" 
 	 << "   -thetacut dtdeg : Symmetric delta-theta cut (in degree) along equator \n" 
 	 << "                    (default=0 -> no cut)\n"
-         << "   -iter_order lval : 1,2,3,4... order of an iterative analysis , 3rd order is usually optimal (default=0 -> standard analysis)\n"
-	 << "   -fitsout: Select the FITS format for the output map (default PPF format) \n"
-	 << "   -fitsin : Select the FITS format for the input vector (default PPF format) \n"
+         << "   -iter_order lval : 1,2,3,4... order of an iterative analysis\n" 
+	 << "       3rd order is usually optimal (default=0 -> standard analysis)\n"
+	 << "   -keepalm : Save Alm's as a 2-D complex array (Matrix<complex>) - only with PPF format  \n"
+	 << "   -fitsout: Select the FITS format for the output files (Map/Alm) (default PPF format) \n"
+	 << "   -fitsin : Select the FITS format for the input map (default PPF format) \n"
 	 << "   InFileName : Input file name (HEALPix map) \n" 
 	 << "   OutFileName : Output file name (the C_l vector) \n" << endl; 
@@ -72,5 +75,5 @@
 public :
 static void ComputeCl(string & infile, string & outfile, int lmax, double tcut, 
-		      int iterationOrder, bool fgfitsin, bool fgfitsout)
+		      int iterationOrder, bool fgfitsin, bool fgfitsout, bool keepalm)
 {
   double deg2rad =  M_PI/180.;
@@ -98,6 +101,18 @@
   // Decomposition de la carte en C_l
   SphericalTransformServer<T> sphtr;
-  TVector<T> clvec = sphtr.DecomposeToCl(sph, lmax, ctcut, iterationOrder);
- 
+  TVector<T> clvec;
+  TMatrix< complex<T> > almmtx;
+  if (keepalm) {
+    Alm<T> alm(lmax);
+    sphtr.DecomposeToAlm(sph, alm, lmax, ctcut, iterationOrder);
+    almmtx.SetSize(alm.Lmax()+1, alm.Lmax()+1);
+    for(int il=0; il<alm.Lmax()+1; il++)
+      for(int im=0; im<il; im++)
+	almmtx(il, im) = alm(il, im);
+    clvec = alm.powerSpectrum();
+  }
+  else {
+    clvec = sphtr.DecomposeToCl(sph, lmax, ctcut, iterationOrder);
+  }
   T min, max;
   double mean, sigma;
@@ -109,12 +124,20 @@
   
   if (fgfitsout) {
+    FitsOutFile fio(outfile, FitsFile::clear);
     cout << "--- Writing C_l vector to Output FITS file " << outfile << endl; 
-    FitsOutFile fio(outfile, FitsFile::clear);
     fio << clvec;
   }
   else {
-    cout << "--- Writing C_l vector to Output PPF file " << outfile << endl; 
     POutPersist ppo(outfile);
-    ppo << clvec;
+    if (keepalm) {
+      cout << "--- Writing C_l vector to Output PPF file " << outfile << endl; 
+      ppo.PutObject(clvec, "Cl");
+      cout << "--- Writing Alm Matrix to Output PPF file " << outfile << endl; 
+      ppo.PutObject(almmtx, "Alm");      
+    }
+    else {
+      cout << "--- Writing C_l vector to Output PPF file " << outfile << endl; 
+      ppo << clvec;
+    }
   }
 }
@@ -135,4 +158,5 @@
   bool fgfitsout = false;
   bool fgr4 = false;
+  bool fgkeepalm = false;
   cout << " map2cl : Decoding command line options ... " << endl;
 
@@ -156,4 +180,7 @@
     else if (strcmp(arg[k], "-fitsout") == 0) {
       fgfitsout = true;  
+    }
+    else if (strcmp(arg[k], "-keepalm") == 0) {
+      fgkeepalm = true;  
     }
     else if ((strcmp(arg[k], "-float") == 0) || (strcmp(arg[k], "-r4") == 0) ) {
@@ -174,9 +201,11 @@
     if (fgr4) {
       cout << " SphereHEALPix<r_4>  --> Power spectrum C_l<r_4> (float)" << endl;
-      _Map2Cl<r_4>::ComputeCl(infile, outfile, lmax, tcut, iterationOrder, fgfitsin, fgfitsout);
+      _Map2Cl<r_4>::ComputeCl(infile, outfile, lmax, tcut, iterationOrder, 
+			      fgfitsin, fgfitsout, fgkeepalm);
     }
     else {
       cout << " SphereHEALPix<r_8>  --> Power spectrum C_l<r_8> (double)" << endl;
-      _Map2Cl<r_8>::ComputeCl(infile, outfile, lmax, tcut, iterationOrder,fgfitsin, fgfitsout);
+      _Map2Cl<r_8>::ComputeCl(infile, outfile, lmax, tcut, iterationOrder,
+			      fgfitsin, fgfitsout, fgkeepalm);
     }
   }
