NASA - Jet Propulsion Laboratory
    + View the NASA Portal
Search JPL
Jet Propulsion Laboratory Home Earth Solar System Stars & Galaxies Technology
Introduction Background Software Links

healpix_map_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.jpl.nasa.gov
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, 2004 Max-Planck-Society
00029  *  Author: Martin Reinecke
00030  */
00031 
00032 #include "healpix_map_fitsio.h"
00033 #include "healpix_map.h"
00034 #include "fitshandle.h"
00035 
00036 using namespace std;
00037 
00038 template<typename T> void read_Healpix_map_from_fits
00039   (fitshandle &inp, Healpix_Map<T> &map, int colnum)
00040   {
00041   string ordering;
00042   inp.get_key ("ORDERING", ordering);
00043   arr<T> myarr;
00044   inp.read_entire_column (colnum, myarr);
00045   map.Set (myarr, ordering=="RING" ? RING : NEST);
00046   }
00047 
00048 template void read_Healpix_map_from_fits (fitshandle &inp,
00049   Healpix_Map<float> &map, int colnum);
00050 template void read_Healpix_map_from_fits (fitshandle &inp,
00051   Healpix_Map<double> &map, int colnum);
00052 template void read_Healpix_map_from_fits (fitshandle &inp,
00053   Healpix_Map<int> &map, int colnum);
00054 
00055 
00056 template<typename T> void read_Healpix_map_from_fits
00057   (const string &filename, Healpix_Map<T> &map, int colnum, int hdunum)
00058   {
00059   fitshandle inp;
00060   inp.open (filename);
00061   inp.goto_hdu (hdunum);
00062   read_Healpix_map_from_fits (inp,map,colnum);
00063   }
00064 
00065 template void read_Healpix_map_from_fits (const string &filename,
00066   Healpix_Map<float> &map, int colnum, int hdunum);
00067 template void read_Healpix_map_from_fits (const string &filename,
00068   Healpix_Map<double> &map, int colnum, int hdunum);
00069 template void read_Healpix_map_from_fits (const string &filename,
00070   Healpix_Map<int> &map, int colnum, int hdunum);
00071 
00072 
00073 void prepare_Healpix_fitsmap
00074   (fitshandle &out, const Healpix_Base &base, int datatype,
00075   const arr<string> &colname)
00076   {
00077   vector<fitscolumn> cols;
00078   int repcount = healpix_repcount (base.Npix());
00079   for (int m=0; m<colname.size(); ++m)
00080     cols.push_back (fitscolumn (colname[m],"unknown",repcount, datatype));
00081   out.insert_bintab(cols);
00082   out.add_key ("PIXTYPE",string("HEALPIX"),"HEALPIX pixelisation");
00083   string ordering = (base.Scheme()==RING) ? "RING" : "NESTED";
00084   out.add_key ("ORDERING",ordering,
00085                "Pixel ordering scheme, either RING or NESTED");
00086   out.add_key ("NSIDE",base.Nside(),"Resolution parameter for HEALPIX");
00087   out.add_key ("FIRSTPIX",0,"First pixel # (0 based)");
00088   out.add_key ("LASTPIX",base.Npix()-1,"Last pixel # (0 based)");
00089   out.add_key ("INDXSCHM",string("IMPLICIT"),"Indexing: IMPLICIT or EXPLICIT");
00090   }
00091 
00092 template<typename T> void write_Healpix_map_to_fits
00093   (fitshandle &out, const Healpix_Map<T> &map, int datatype)
00094   {
00095   arr<string> colname(1);
00096   colname[0] = "signal";
00097   prepare_Healpix_fitsmap (out, map, datatype, colname);
00098   out.write_column(1,map.Map());
00099   }
00100 
00101 template void write_Healpix_map_to_fits
00102   (fitshandle &out, const Healpix_Map<float> &map, int datatype);
00103 template void write_Healpix_map_to_fits
00104   (fitshandle &out, const Healpix_Map<double> &map, int datatype);
00105 template void write_Healpix_map_to_fits
00106   (fitshandle &out, const Healpix_Map<int> &map, int datatype);
00107 
00108 
00109 template<typename T> void write_Healpix_map_to_fits
00110   (fitshandle &out, const Healpix_Map<T> &mapT,
00111    const Healpix_Map<T> &mapQ, const Healpix_Map<T> &mapU, int datatype)
00112   {
00113   arr<string> colname(3);
00114   colname[0] = "signal";
00115   colname[1] = "Q-pol";
00116   colname[2] = "U-pol";
00117   prepare_Healpix_fitsmap (out, mapT, datatype, colname);
00118   out.write_column(1,mapT.Map());
00119   out.write_column(2,mapQ.Map());
00120   out.write_column(3,mapU.Map());
00121   }
00122 
00123 template void write_Healpix_map_to_fits
00124   (fitshandle &out, const Healpix_Map<float> &mapT,
00125    const Healpix_Map<float> &mapQ, const Healpix_Map<float> &mapU,
00126    int datatype);
00127 template void write_Healpix_map_to_fits
00128   (fitshandle &out, const Healpix_Map<double> &mapT,
00129    const Healpix_Map<double> &mapQ, const Healpix_Map<double> &mapU,
00130    int datatype);

Generated on Fri Jun 18 16:12:30 2010 for Healpix C++
Privacy / Copyright
FIRST GOV Contact: NASA Home Page Site Manager:
Webmaster:

CL 03-2650