powspec_fitsio.cc

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.sourceforge.net
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Copyright (C) 2003-2010 Max-Planck-Society
00029  *  Author: Martin Reinecke
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   }

Generated on Wed Apr 24 11:31:18 2013 for Healpix C++