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 "alm_powspec_tools.h"
00040 #include "fitshandle.h"
00041
00042 using namespace std;
00043
00044 template<typename T> void mult_alm (paramfile ¶ms, simparams &par)
00045 {
00046 par.add_comment("----------------");
00047 par.add_comment(" ** mult_alm **");
00048 par.add_comment("----------------");
00049
00050 string infile = params.template find<string>("infile");
00051 par.add_source_file (infile, 2);
00052 string outfile = params.template find<string>("outfile");
00053 int nside_pixwin_in = params.template find<int>("nside_pixwin_in",0);
00054 planck_assert (nside_pixwin_in>=0,"nside_pixwin_in must be >= 0");
00055 int nside_pixwin_out = params.template find<int>("nside_pixwin_out",0);
00056 planck_assert (nside_pixwin_out>=0,"nside_pixwin_out must be >= 0");
00057 double fwhm_arcmin_in = params.template find<double>("fwhm_arcmin_in",0);
00058 planck_assert (fwhm_arcmin_in>=0,"fwhm_arcmin_in must be >= 0");
00059 double fwhm_arcmin_out = params.template find<double>("fwhm_arcmin_out",0);
00060 planck_assert (fwhm_arcmin_out>=0,"fwhm_arcmin_out must be >= 0");
00061
00062 string datadir;
00063 if ((nside_pixwin_in>0) || (nside_pixwin_out>0))
00064 datadir = params.template find<string>("healpix_data");
00065
00066 bool polarisation = params.template find<bool>("polarisation");
00067 if (!polarisation)
00068 {
00069 int nlmax, nmmax;
00070 get_almsize(infile, nlmax, nmmax, 2);
00071 Alm<xcomplex<T> > alm;
00072 read_Alm_from_fits(infile,alm,nlmax,nmmax,2);
00073 if (fwhm_arcmin_in>0) smooth_with_Gauss (alm, -fwhm_arcmin_in);
00074 arr<double> temp(nlmax+1);
00075 if (nside_pixwin_in>0)
00076 {
00077 read_pixwin(datadir,nside_pixwin_in,temp);
00078 for (int l=0; l<=nlmax; ++l)
00079 temp[l] = 1/temp[l];
00080 alm.ScaleL (temp);
00081 }
00082 if (nside_pixwin_out>0)
00083 {
00084 read_pixwin(datadir,nside_pixwin_out,temp);
00085 alm.ScaleL (temp);
00086 }
00087 if (fwhm_arcmin_out>0) smooth_with_Gauss (alm, fwhm_arcmin_out);
00088 fitshandle out;
00089 out.create (outfile);
00090 write_Alm_to_fits (out,alm,nlmax,nmmax,FITSUTIL<T>::DTYPE);
00091 par.add_keys(out);
00092 }
00093 else
00094 {
00095 int nlmax, nmmax;
00096 get_almsize_pol(infile, nlmax, nmmax);
00097 Alm<xcomplex<T> > almT, almG, almC;
00098 read_Alm_from_fits(infile,almT,nlmax,nmmax,2);
00099 read_Alm_from_fits(infile,almG,nlmax,nmmax,3);
00100 read_Alm_from_fits(infile,almC,nlmax,nmmax,4);
00101 if (fwhm_arcmin_in>0)
00102 smooth_with_Gauss (almT, almG, almC, -fwhm_arcmin_in);
00103 arr<double> temp(nlmax+1), pol(nlmax+1);
00104 if (nside_pixwin_in>0)
00105 {
00106 read_pixwin(datadir,nside_pixwin_in,temp,pol);
00107 for (int l=0; l<=nlmax; ++l)
00108 { temp[l] = 1/temp[l]; pol[l] = 1/pol[l]; }
00109 almT.ScaleL(temp); almG.ScaleL(pol); almC.ScaleL(pol);
00110 }
00111 if (nside_pixwin_out>0)
00112 {
00113 read_pixwin(datadir,nside_pixwin_out,temp,pol);
00114 almT.ScaleL(temp); almG.ScaleL(pol); almC.ScaleL(pol);
00115 }
00116 if (fwhm_arcmin_out>0)
00117 smooth_with_Gauss (almT, almG, almC, fwhm_arcmin_out);
00118 fitshandle out;
00119 out.create (outfile);
00120 write_Alm_to_fits (out,almT,nlmax,nmmax,FITSUTIL<T>::DTYPE);
00121 par.add_keys(out);
00122 write_Alm_to_fits (out,almG,nlmax,nmmax,FITSUTIL<T>::DTYPE);
00123 par.add_keys(out);
00124 write_Alm_to_fits (out,almC,nlmax,nmmax,FITSUTIL<T>::DTYPE);
00125 par.add_keys(out);
00126 }
00127 }
00128
00129 int main (int argc, const char **argv)
00130 {
00131 PLANCK_DIAGNOSIS_BEGIN
00132 module_startup ("mult_alm", argc, argv, 2, "<parameter file>");
00133 paramfile params (argv[1]);
00134 simparams par;
00135
00136 bool dp = params.find<bool> ("double_precision",false);
00137 dp ? mult_alm<double>(params,par) : mult_alm<float>(params,par);
00138 PLANCK_DIAGNOSIS_END
00139 }