Healpix C++  3.83
moc_fitsio.cc
1 /*
2  * This file is part of Healpix_cxx.
3  *
4  * Healpix_cxx is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Healpix_cxx is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Healpix_cxx; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * For more information about HEALPix, see http://healpix.sourceforge.net
19  */
20 
21 /*
22  * Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
23  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
24  * (DLR).
25  */
26 
27 /*
28  * Copyright (C) 2014-2017 Max-Planck-Society
29  * Author: Martin Reinecke
30  */
31 
32 #include "moc_fitsio.h"
33 #include "fitshandle.h"
34 
35 using namespace std;
36 
37 template<typename T> Moc<T> read_Moc_from_fits
38  (const std::string &filename, bool peano)
39  {
40  fitshandle inp;
41  inp.open (filename);
42  inp.goto_hdu (2);
43  vector<T> data;
44  inp.read_entire_column(1,data);
45  if (peano)
46  Moc<T>::uniq_nest2peano(data);
47  return Moc<T>::fromUniq(data);
48  }
49 
50 template Moc<int> read_Moc_from_fits
51  (const std::string &filename, bool peano);
52 template Moc<int64> read_Moc_from_fits
53  (const std::string &filename, bool peano);
54 
55 template<typename T> void write_Moc_to_fits
56  (const std::string &outfile, const Moc<T> &moc, bool peano)
57  {
58  PDT outtype=PLANCK_INT16;
59  vector<T> data=moc.toUniq();
60  if (peano)
61  Moc<T>::uniq_peano2nest(data);
62  if (data.size()>0)
63  {
64  if (data.back()>0x7fff) outtype=PLANCK_INT32;
65  if (data.back()>0x7fffffffLL) outtype=PLANCK_INT64;
66  }
67  fitshandle out;
68  out.create(outfile);
69  vector<fitscolumn> cols;
70  cols.push_back (fitscolumn ("PIXEL","",1,outtype));
71  out.insert_bintab(cols);
72  out.set_key("PIXTYPE", string("HEALPIX"), "HEALPix magic value");
73  out.set_key("ORDERING", string("NUNIQ"), "NUNIQ coding method");
74  out.set_key("COORDSYS", string("C"), "mandated by MOC standard");
75  out.set_key<int>("MOCORDER", moc.maxOrder(), "MOC resolution (best order)");
76  out.write_column(1,data);
77  }
78 
79 template void write_Moc_to_fits
80  (const std::string &outfile, const Moc<int> &moc, bool peano);
81 template void write_Moc_to_fits
82  (const std::string &outfile, const Moc<int64> &moc, bool peano);

Generated on Wed Nov 13 2024 12:18:30 for Healpix C++