NASA - Jet Propulsion Laboratory
    + View the NASA Portal
Search JPL
Jet Propulsion Laboratory Home Earth Solar System Stars & Galaxies Technology
Introduction Background Software Links

anafast_cxx.cc

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.jpl.nasa.gov
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Copyright (C) 2003, 2004, 2005 Max-Planck-Society
00029  *  Author: Martin Reinecke
00030  */
00031 
00032 #include "xcomplex.h"
00033 #include "cxxutils.h"
00034 #include "paramfile.h"
00035 #include "simparams.h"
00036 #include "healpix_data_io.h"
00037 #include "alm.h"
00038 #include "alm_fitsio.h"
00039 #include "healpix_map.h"
00040 #include "healpix_map_fitsio.h"
00041 #include "powspec.h"
00042 #include "powspec_fitsio.h"
00043 #include "alm_healpix_tools.h"
00044 #include "alm_powspec_tools.h"
00045 #include "fitshandle.h"
00046 
00047 using namespace std;
00048 
00049 template<typename T> void anafast_cxx (paramfile &params, simparams &par)
00050   {
00051   int nlmax = params.template find<int>("nlmax");
00052   int nmmax = params.template find<int>("nmmax",nlmax);
00053   string infile = params.template find<string>("infile");
00054   string outfile = params.template find<string>("outfile","");
00055   string outfile_alms = params.template find<string>("outfile_alms","");
00056   planck_assert ((outfile!="") || (outfile_alms!=""),
00057     "no output specified, nothing done");
00058   bool polarisation = params.template find<bool>("polarisation");
00059   int num_iter = params.template find<int>("iter_order",0);
00060 
00061   if (!polarisation)
00062     {
00063     Healpix_Map<T> map;
00064     read_Healpix_map_from_fits(infile,map,1,2);
00065     arr<double> weight;
00066     get_ring_weights (params,par,map.Nside(),weight);
00067 
00068     Alm<xcomplex<T> > alm(nlmax,nmmax);
00069     double avg=map.average();
00070     map.add(-avg);
00071     if (map.Scheme()==NEST) map.swap_scheme();
00072     map2alm_iter(map,alm,num_iter,weight);
00073 
00074     alm(0,0) += avg*sqrt(fourpi);
00075 
00076     if (outfile!="")
00077       {
00078       PowSpec powspec;
00079       extract_powspec (alm,powspec);
00080       fitshandle out;
00081       out.create (outfile);
00082       write_powspec_to_fits (out,powspec,1);
00083       }
00084     if (outfile_alms!="")
00085       {
00086       fitshandle out;
00087       out.create (outfile_alms);
00088       write_Alm_to_fits (out,alm,alm.Lmax(),alm.Mmax(),FITSUTIL<T>::DTYPE);
00089       }
00090     }
00091   else
00092     {
00093     Healpix_Map<T> mapT, mapQ, mapU;
00094     read_Healpix_map_from_fits(infile,mapT,1,2);
00095     read_Healpix_map_from_fits(infile,mapQ,2,2);
00096     read_Healpix_map_from_fits(infile,mapU,3,2);
00097     arr<double> weight;
00098     get_ring_weights (params,par,mapT.Nside(),weight);
00099 
00100     Alm<xcomplex<T> > almT(nlmax,nmmax), almG(nlmax,nmmax), almC(nlmax,nmmax);
00101     double avg=mapT.average();
00102     mapT.add(-avg);
00103     if (mapT.Scheme()==NEST) mapT.swap_scheme();
00104     if (mapQ.Scheme()==NEST) mapQ.swap_scheme();
00105     if (mapU.Scheme()==NEST) mapU.swap_scheme();
00106     map2alm_pol_iter
00107       (mapT,mapQ,mapU,almT,almG,almC,num_iter,weight);
00108 
00109     almT(0,0) += avg*sqrt(fourpi);
00110 
00111     if (outfile!="")
00112       {
00113       PowSpec powspec;
00114       extract_powspec (almT,almG,almC,powspec);
00115       fitshandle out;
00116       out.create (outfile);
00117       write_powspec_to_fits (out,powspec,4);
00118       }
00119     if (outfile_alms!="")
00120       {
00121       fitshandle out;
00122       out.create (outfile_alms);
00123       write_Alm_to_fits (out,almT,almT.Lmax(),almT.Mmax(),FITSUTIL<T>::DTYPE);
00124       write_Alm_to_fits (out,almG,almG.Lmax(),almG.Mmax(),FITSUTIL<T>::DTYPE);
00125       write_Alm_to_fits (out,almC,almC.Lmax(),almC.Mmax(),FITSUTIL<T>::DTYPE);
00126       }
00127     }
00128   }
00129 
00130 int main (int argc, const char **argv)
00131   {
00132 PLANCK_DIAGNOSIS_BEGIN
00133   module_startup ("anafast_cxx", argc, argv, 2, "<parameter file>");
00134   paramfile params (argv[1]);
00135   simparams par;
00136 
00137   bool dp = params.find<bool> ("double_precision",false);
00138   dp ? anafast_cxx<double>(params,par) : anafast_cxx<float>(params,par);
00139 PLANCK_DIAGNOSIS_END
00140   }

Generated on Fri Jun 18 16:12:30 2010 for Healpix C++
Privacy / Copyright
FIRST GOV Contact: NASA Home Page Site Manager:
Webmaster:

CL 03-2650