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 "powspec_fitsio.h"
00033 #include "powspec.h"
00034 #include "fitshandle.h"
00035
00036 using namespace std;
00037
00038 void read_powspec_from_fits (fitshandle &inp, PowSpec &powspec, int nspecs,
00039 int lmax)
00040 {
00041 planck_assert ((nspecs==1)||(nspecs==4)||(nspecs==6),
00042 "wrong number of spectra");
00043
00044 arr<double> tt(lmax+1,0),gg(lmax+1,0),cc(lmax+1,0),tg(lmax+1,0),
00045 tc(lmax+1,0),gc(lmax+1,0);
00046
00047 int lmax_file = safe_cast<int>(inp.nelems(1)-1);
00048 if (lmax_file<lmax)
00049 cerr << "warning: lmax in file smaller than expected; padding with 0."
00050 << endl;
00051 int lmax_read = min (lmax,lmax_file);
00052 inp.read_column_raw (1,&tt[0],lmax_read+1);
00053 if (nspecs>=4)
00054 {
00055 inp.read_column_raw (2,&gg[0],lmax_read+1);
00056 inp.read_column_raw (3,&cc[0],lmax_read+1);
00057 inp.read_column_raw (4,&tg[0],lmax_read+1);
00058 }
00059 if (nspecs==6)
00060 {
00061 inp.read_column_raw (5,&tc[0],lmax_read+1);
00062 inp.read_column_raw (6,&gc[0],lmax_read+1);
00063 }
00064
00065 if (nspecs==1) powspec.Set(tt);
00066 if (nspecs==4) powspec.Set(tt,gg,cc,tg);
00067 if (nspecs==6) powspec.Set(tt,gg,cc,tg,tc,gc);
00068 }
00069
00070 void read_powspec_from_fits (const string &infile, PowSpec &powspec,
00071 int nspecs, int lmax, int hdunum)
00072 {
00073 fitshandle inp;
00074 inp.open(infile);
00075 inp.goto_hdu(hdunum);
00076
00077 read_powspec_from_fits (inp,powspec,nspecs,lmax);
00078 }
00079
00080 void write_powspec_to_fits (fitshandle &out,
00081 const PowSpec &powspec, int nspecs)
00082 {
00083 planck_assert ((nspecs==1)||(nspecs==4)||(nspecs==6),
00084 "incorrect number of spectra");
00085 vector<fitscolumn> cols;
00086 cols.push_back(fitscolumn("Temperature C_l","unknown",1,PLANCK_FLOAT64));
00087 if (nspecs>1)
00088 {
00089 cols.push_back(fitscolumn("E-mode C_l","unknown",1,PLANCK_FLOAT64));
00090 cols.push_back(fitscolumn("B-mode C_l","unknown",1,PLANCK_FLOAT64));
00091 cols.push_back(fitscolumn("T-E cross-corr.","unknown",1,
00092 PLANCK_FLOAT64));
00093 }
00094 if (nspecs>4)
00095 {
00096 cols.push_back(fitscolumn("T-B cross-corr.","unknown",1,PLANCK_FLOAT64));
00097 cols.push_back(fitscolumn("E-B cross-corr.","unknown",1,PLANCK_FLOAT64));
00098 }
00099 out.insert_bintab(cols);
00100 out.write_column(1,powspec.tt());
00101 if (nspecs>1)
00102 {
00103 out.write_column(2,powspec.gg());
00104 out.write_column(3,powspec.cc());
00105 out.write_column(4,powspec.tg());
00106 }
00107 if (nspecs>4)
00108 {
00109 out.write_column(5,powspec.tc());
00110 out.write_column(6,powspec.gc());
00111 }
00112 }
00113
00114 void write_powspec_to_fits (const string &outfile,
00115 const PowSpec &powspec, int nspecs)
00116 {
00117 fitshandle out;
00118 out.create(outfile);
00119 write_powspec_to_fits(out,powspec,nspecs);
00120 }