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 "planck_rng.h"
00037 #include "alm.h"
00038 #include "alm_fitsio.h"
00039 #include "fitshandle.h"
00040 #include "powspec.h"
00041 #include "powspec_fitsio.h"
00042 #include "alm_powspec_tools.h"
00043
00044 using namespace std;
00045
00046 template<typename T> void syn_alm_cxx (paramfile ¶ms, simparams &par)
00047 {
00048 par.add_comment("-----------------------");
00049 par.add_comment(" ** syn_alm_cxx 1.0 **");
00050 par.add_comment("-----------------------");
00051
00052 int nlmax = params.template find<int>("nlmax");
00053 par.add("nlmax","NLMAX",nlmax,"maximum l of the alms");
00054 int nmmax = params.template find<int>("nmmax",nlmax);
00055 par.add("nmmax","NMMAX",nmmax,"maximum m of the alms");
00056 planck_assert(nmmax<=nlmax,"nmmax must not be larger than nlmax");
00057 string infile = params.template find<string>("infile");
00058 par.add_source_file (infile, 2);
00059 string outfile = params.template find<string>("outfile");
00060 int rand_seed = params.template find<int>("rand_seed");
00061 par.add("rand_seed","RANDSEED",rand_seed,"random number seed");
00062 double fwhm = params.template find<double>("fwhm_arcmin",0.);
00063 par.add("fwhm","FWHM",fwhm,"[arcmin] Gaussian smoothing FWHM");
00064 fwhm *= degr2rad/60;
00065 bool polarisation = params.template find<bool>("polarisation");
00066
00067 PowSpec powspec;
00068 int nspecs = polarisation ? 4 : 1;
00069 read_powspec_from_fits (infile, powspec, nspecs, nlmax);
00070 powspec.Smooth_with_Gauss(fwhm);
00071
00072 planck_rng rng(rand_seed);
00073
00074 if (polarisation)
00075 {
00076 Alm<xcomplex<T> >
00077 almT(nlmax,nmmax), almG(nlmax,nmmax), almC(nlmax,nmmax);
00078 create_alm_pol (powspec, almT, almG, almC, rng);
00079
00080 fitshandle out;
00081 out.create(outfile);
00082 write_Alm_to_fits(out,almT,nlmax,nmmax,FITSUTIL<T>::DTYPE);
00083 out.add_key("PDMTYPE",string("MAPALM"),"Planck data model type");
00084 par.add_keys(out);
00085 write_Alm_to_fits(out,almG,nlmax,nmmax,FITSUTIL<T>::DTYPE);
00086 out.add_key("PDMTYPE",string("MAPALM"),"Planck data model type");
00087 par.add_keys(out);
00088 write_Alm_to_fits(out,almC,nlmax,nmmax,FITSUTIL<T>::DTYPE);
00089 out.add_key("PDMTYPE",string("MAPALM"),"Planck data model type");
00090 par.add_keys(out);
00091 }
00092 else
00093 {
00094 Alm<xcomplex<T> > almT(nlmax,nmmax);
00095 create_alm (powspec, almT, rng);
00096
00097 fitshandle out;
00098 out.create(outfile);
00099 write_Alm_to_fits(out,almT,nlmax,nmmax,FITSUTIL<T>::DTYPE);
00100 out.add_key("PDMTYPE",string("MAPALM"),"Planck data model type");
00101 par.add_keys(out);
00102 }
00103 }
00104
00105 int main (int argc, const char **argv)
00106 {
00107 PLANCK_DIAGNOSIS_BEGIN
00108 module_startup ("syn_alm_cxx", argc, argv, 2, "<parameter file>");
00109 paramfile params (argv[1]);
00110 simparams par;
00111
00112 bool dp = params.find<bool> ("double_precision",false);
00113 dp ? syn_alm_cxx<double>(params,par) : syn_alm_cxx<float>(params,par);
00114 PLANCK_DIAGNOSIS_END
00115 }