From 1eb6a5c9a65c0d140ebd5529ce5c8feac3ec840e Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Fri, 14 Mar 2008 01:26:35 +0000 Subject: [PATCH] start load method implementation --- include/GHealpix.hpp | 20 ++++++++++++++++---- src/GHealpix.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+), 4 deletions(-) diff --git a/include/GHealpix.hpp b/include/GHealpix.hpp index aa0991f..3660739 100644 --- a/include/GHealpix.hpp +++ b/include/GHealpix.hpp @@ -20,6 +20,7 @@ #define GHEALPIX_HPP /* __ Includes ___________________________________________________________ */ +#include "GFitsHDU.hpp" /* __ Namespaces _________________________________________________________ */ @@ -41,16 +42,27 @@ public: GHealpix& operator= (const GHealpix& pixels); // Methods + void load(const GFitsHDU* hdu); + int nside(void) const; + int num_pixels(void) const; + double omega(void) const; -protected: - // Protected methods +private: + // Private methods void init_members(void); void copy_members(const GHealpix& pixels); void free_members(void); GHealpix* clone(void) const; - // Protected data area -private: + // Private data area + int m_nside; //!< Number of divisions of each base pixel (1,2,..) + int m_order; //!< Ordering (0=ring, 1=nested) + int m_coordsys; //!< Coordinate system (0=equatorial, 1=galactic) + int m_num_pixels; //!< Number of pixels + int m_size_pixels; //!< Vector size of each pixel + double* m_pixels; //!< Pixel array + double* m_lon; //!< RA or GLON values for each pixel + double* m_lat; //!< DEC or GLAT values for each pixel }; #endif /* GHEALPIX_HPP */ diff --git a/src/GHealpix.cpp b/src/GHealpix.cpp index e7f70ba..19161c3 100644 --- a/src/GHealpix.cpp +++ b/src/GHealpix.cpp @@ -19,6 +19,7 @@ /* __ Includes ___________________________________________________________ */ #include "GException.hpp" +#include "GTools.hpp" #include "GHealpix.hpp" /* __ Namespaces _________________________________________________________ */ @@ -121,6 +122,124 @@ GHealpix& GHealpix::operator= (const GHealpix& pixels) = = ==========================================================================*/ +/***********************************************************************//** + * @brief Load Healpix data from table. + * + * @param hdu FITS HDU containing the Healpix data + ***************************************************************************/ +void GHealpix::load(const GFitsHDU* hdu) +{ + // Free memory and initialise members + free_members(); + init_members(); + + // Get HDU header + GFitsHeader* hdr = hdu->header(); + if (hdr == NULL) + throw; + + // Check if we have a healpix representation + if (hdr->card("PIXTYPE")->string() != "HEALPIX") + throw; + + // Get Healpix resolution and determine number of pixels + m_nside = hdr->card("NSIDE")->integer(); + m_num_pixels = 12*m_nside*m_nside; + + // Get ordering + try { + std::string ordering = hdr->card("ORDERING")->string(); + if (ordering == "RING") + m_order = 0; + else if (ordering == "NESTED") + m_order = 1; + else + throw; + } + catch (exception &e) { + m_order = 1; // Default is NESTED + } + + // Get coordinate system + try { + std::string coordsys = hdr->card("COORDSYS")->string(); + if (coordsys == "EQUATORIAL") + m_coordsys = 0; + else if (coordsys == "GALACTIC") + m_coordsys = 1; + else + throw; + } + catch (exception &e) { + m_coordsys = 0; // Default is EQUATORIAL + } + + // Continue only of we have pixels + if (m_num_pixels > 0) { + + // Get first column + GFitsTableCol* col = hdu->column(1); + + // Check column consistency + if (col->length() != m_num_pixels) + throw; + + // Extract vector size of each pixel + m_size_pixels = col->number(); + + // If there are pixels then load them + int size = m_num_pixels * m_size_pixels; + if (size > 0) { + m_pixels = new double[size]; + double* ptr = m_pixels; + for (int row = 0; row < m_num_pixels; ++row) { + for (int inx = 0; inx < m_size_pixels; ++inx, ++ptr) + *ptr = col->real(row,inx); + } + } // endif: there were pixels to load + + // Calculate longitude and latitude for each pixel + + } // endif: we had pixels + + // Return + return; +} + + + +/***********************************************************************//** + * @brief Returns number of divisions of the side of each base pixel. + ***************************************************************************/ +int GHealpix::nside(void) const +{ + // Return nside + return m_nside; +} + + +/***********************************************************************//** + * @brief Returns number of pixels. + ***************************************************************************/ +int GHealpix::num_pixels(void) const +{ + // Return nside + return m_num_pixels; +} + + +/***********************************************************************//** + * @brief Returns solid angle of pixel + ***************************************************************************/ +double GHealpix::omega(void) const +{ + // Set solid angle + double omega = fourpi / m_num_pixels; + + // Return solid angle + return omega; +} + /*========================================================================== = = @@ -134,6 +253,14 @@ GHealpix& GHealpix::operator= (const GHealpix& pixels) void GHealpix::init_members(void) { // Initialise members + m_nside = 0; + m_order = 0; + m_coordsys = 0; + m_num_pixels = 0; + m_size_pixels = 0; + m_pixels = NULL; + m_lon = NULL; + m_lat = NULL; // Return return; @@ -148,6 +275,28 @@ void GHealpix::init_members(void) void GHealpix::copy_members(const GHealpix& pixels) { // Copy attributes + m_nside = pixels.m_nside; + m_order = pixels.m_order; + m_coordsys = pixels.m_coordsys; + m_num_pixels = pixels.m_num_pixels; + m_size_pixels = pixels.m_size_pixels; + + // Copy arrays + if (m_num_pixels > 0) { + if (m_size_pixels > 0 && pixels.m_pixels != NULL) { + int size = m_num_pixels*m_size_pixels; + m_pixels = new double[size]; + memcpy(m_pixels, pixels.m_pixels, size*sizeof(double)); + } + if (pixels.m_lon != NULL) { + m_lon = new double[m_num_pixels]; + memcpy(m_lon, pixels.m_lon, m_num_pixels*sizeof(double)); + } + if (pixels.m_lat != NULL) { + m_lat = new double[m_num_pixels]; + memcpy(m_lat, pixels.m_lat, m_num_pixels*sizeof(double)); + } + } // Return return; @@ -160,8 +309,14 @@ void GHealpix::copy_members(const GHealpix& pixels) void GHealpix::free_members(void) { // Free memory + if (m_pixels != NULL) delete [] m_pixels; + if (m_lon != NULL) delete [] m_lon; + if (m_lat != NULL) delete [] m_lat; // Mark memory as free + m_pixels = NULL; + m_lon = NULL; + m_lat = NULL; // Return return; -- libgit2 0.21.4