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