moc_fitsio.cc
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 "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);