moc_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) 2014-2015 Max-Planck-Society
00029  *  Author: Martin Reinecke
00030  */
00031 
00032 #include "moc_fitsio.h"
00033 #include "fitshandle.h"
00034 
00035 using namespace std;
00036 
00037 template<typename T> void read_Moc_from_fits
00038   (const std::string &filename, Moc<T> &moc, bool peano)
00039   {
00040   fitshandle inp;
00041   inp.open (filename);
00042   inp.goto_hdu (2);
00043   vector<T> data;
00044   inp.read_entire_column(1,data);
00045   if (peano)
00046     Moc<T>::uniq_nest2peano(data);
00047   moc=Moc<T>::fromUniq(data);
00048   }
00049 
00050 template void read_Moc_from_fits
00051   (const std::string &filename, Moc<int> &moc, bool peano);
00052 template void read_Moc_from_fits
00053   (const std::string &filename, Moc<int64> &moc, bool peano);
00054 
00055 template<typename T> void write_Moc_to_fits
00056   (const std::string &outfile, const Moc<T> &moc, bool peano)
00057   {
00058   PDT outtype=PLANCK_INT16;
00059   vector<T> data=moc.toUniq();
00060   if (peano)
00061     Moc<T>::uniq_peano2nest(data);
00062   if (data.size()>0)
00063     {
00064     if (data.back()>0x7fff) outtype=PLANCK_INT32;
00065     if (data.back()>0x7fffffffLL) outtype=PLANCK_INT64;
00066     }
00067   fitshandle out;
00068   out.create(outfile);
00069   vector<fitscolumn> cols;
00070   cols.push_back (fitscolumn ("PIXEL","",1,outtype));
00071   out.insert_bintab(cols);
00072   out.set_key("PIXTYPE", string("HEALPIX"), "HEALPix magic value");
00073   out.set_key("ORDERING", string("NUNIQ"), "NUNIQ coding method");
00074   out.set_key("COORDSYS", string("C"), "mandated by MOC standard");
00075   out.set_key<int>("MOCORDER", moc.maxOrder(), "MOC resolution (best order)");
00076   out.write_column(1,data);
00077   }
00078   
00079 template void write_Moc_to_fits
00080   (const std::string &outfile, const Moc<int> &moc, bool peano);
00081 template void write_Moc_to_fits
00082   (const std::string &outfile, const Moc<int64> &moc, bool peano);

Generated on Thu Oct 8 14:48:52 2015 for Healpix C++