00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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 ¶ms, 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 }