Skip to content

Commit

Permalink
Bug Fixes And Refactoring in FITS Module (BoostGSoC19#147)
Browse files Browse the repository at this point in the history
* hdu.hpp ( Added Virtual Destructor )

* Removed todo in hdu.hpp

* extension_hdu.hpp ( Refactored duplicate code into a single helper function )

* card.hpp ( Minor bug-fixes )

* get_data() const returns by reference now instead of by value

* Refactored duplicate code

* Added virtual destructor in for making column a polymorphic base ( for column_data )

* Fixed major bugs in ascii_table and column_data

* Fixed a major bug in binary_table

* Refactored duplicate code in binary_table constructor

* Fixed minor bug and removed duplicate code in image_extension

* Fixed a minor level bug associated with spaces in boolean card

Co-authored-by: Pranam Lashkari <plashkari628@gmail.com>
  • Loading branch information
gopi487krishna and lpranam committed May 30, 2020
1 parent a70ff46 commit 6852cd5
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 143 deletions.
39 changes: 24 additions & 15 deletions include/boost/astronomy/io/ascii_table.hpp
Expand Up @@ -53,8 +53,7 @@ struct ascii_table : public table_extension
*/
ascii_table(std::fstream &file) : table_extension(file)
{
populate_column_data();
std::copy_n(std::istream_iterator<char>(file), naxis(1)*naxis(2), std::back_inserter(data));
set_ascii_table_info(file);
set_unit_end(file);
}

Expand All @@ -68,8 +67,7 @@ struct ascii_table : public table_extension
*/
ascii_table(std::fstream &file, hdu const& other) : table_extension(file, other)
{
populate_column_data();
std::copy_n(std::istream_iterator<char>(file), naxis(1)*naxis(2), std::back_inserter(data));
set_ascii_table_info(file);
set_unit_end(file);
}

Expand All @@ -83,8 +81,7 @@ struct ascii_table : public table_extension
*/
ascii_table(std::fstream &file, std::streampos pos) : table_extension(file, pos)
{
populate_column_data();
std::copy_n(std::istream_iterator<char>(file), naxis(1)*naxis(2), std::back_inserter(data));
set_ascii_table_info(file);
set_unit_end(file);
}

Expand Down Expand Up @@ -162,15 +159,15 @@ struct ascii_table : public table_extension
*/
std::unique_ptr<column> get_column(std::string name) const
{
for (auto col : col_metadata)
for (auto& col : col_metadata)
{
if (col.TTYPE() == name)
{
switch (get_type(col.TFORM()))
{
case 'A':
{
auto result = std::make_unique<column_data<char>>();
auto result = std::make_unique<column_data<char>>(col);
fill_column(result->get_data(), col.TBCOL(), column_size(col.TFORM()),
[](char const* element) -> char {
return *element;
Expand All @@ -180,7 +177,7 @@ struct ascii_table : public table_extension
}
case 'I':
{
auto result = std::make_unique<column_data<std::int32_t>>();
auto result = std::make_unique<column_data<std::int32_t>>(col);
fill_column(result->get_data(), col.TBCOL(), column_size(col.TFORM()),
[](char const* element) -> std::int32_t {
return boost::endian::big_to_native(*reinterpret_cast<const std::int32_t*>(element));
Expand All @@ -190,7 +187,7 @@ struct ascii_table : public table_extension
}
case 'F':
{
auto result = std::make_unique<column_data<float>>();
auto result = std::make_unique<column_data<float>>(col);
fill_column(result->get_data(), col.TBCOL(), column_size(col.TFORM()),
[](char const* element) -> float {
float result = (element[3] << 0) | (element[2] << 8) |
Expand All @@ -202,7 +199,7 @@ struct ascii_table : public table_extension
}
case 'E':
{
auto result = std::make_unique<column_data<float>>();
auto result = std::make_unique<column_data<float>>(col);
fill_column(result->get_data(), col.TBCOL(), column_size(col.TFORM()),
[](char const* element) -> float {
float result = (element[3] << 0) | (element[2] << 8) |
Expand All @@ -214,7 +211,7 @@ struct ascii_table : public table_extension
}
case 'D':
{
auto result = std::make_unique<column_data<double>>();
auto result = std::make_unique<column_data<double>>(col);
fill_column(result->get_data(), col.TBCOL(), column_size(col.TFORM()),
[](char const* element) -> double {
double result = (element[7] << 0) | (element[6] << 8) |
Expand All @@ -232,7 +229,7 @@ struct ascii_table : public table_extension
}
}

std::unique_ptr<column>(nullptr);
return std::unique_ptr<column>(nullptr);
}

/**
Expand Down Expand Up @@ -279,8 +276,8 @@ struct ascii_table : public table_extension
* @param[in,out] column_container Container that stores the field value for every row of specified field
* @param[in] start Position where column begins for the field
* @param[in] column_size Total size of the field
* @param[in] lambda Lambda function for fetching the field data from data buffer
* @todo Why is column size present there
* @param[in] lambda Lambda function for fetching the field data from data buffer
* @todo Why is column size present there
*/
template<typename VectorType, typename Lambda>
void fill_column
Expand All @@ -298,6 +295,18 @@ struct ascii_table : public table_extension
}
}

private:
/**
* @brief Initializes the current object with column metadata and table data
*/
void set_ascii_table_info(std::fstream& file)
{
populate_column_data();
std::copy_n(std::istream_iterator<char>(file), naxis(1) * naxis(2), std::back_inserter(data));

}


};

}}} //namespace boost::astronomy::io
Expand Down

0 comments on commit 6852cd5

Please sign in to comment.