Commit 3049f851bc469e14933fa65ae1ed4ec70ef2ef64

Authored by knodlseder
1 parent bb8039af

add unit and TDIM information to print() method

Showing 1 changed file with 63 additions and 11 deletions
src/fits/GFitsTableCol.cpp
... ... @@ -28,7 +28,6 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include <iostream>
32 31 #include "GException.hpp"
33 32 #include "GFitsCfitsio.hpp"
34 33 #include "GFitsTableCol.hpp"
... ... @@ -170,7 +169,7 @@ GFitsTableCol&amp; GFitsTableCol::operator= (const GFitsTableCol&amp; column)
170 169 /***********************************************************************//**
171 170 * @brief Set column name
172 171 *
173   - * @param[in] name Name of the column.
  172 + * @param[in] name Column name.
174 173 ***************************************************************************/
175 174 void GFitsTableCol::name(const std::string& name)
176 175 {
... ... @@ -185,11 +184,11 @@ void GFitsTableCol::name(const std::string&amp; name)
185 184 /***********************************************************************//**
186 185 * @brief Set column unit
187 186 *
188   - * @param[in] unit Unit of the column.
  187 + * @param[in] unit Column unit.
189 188 ***************************************************************************/
190 189 void GFitsTableCol::unit(const std::string& unit)
191 190 {
192   - // Set name
  191 + // Set unit
193 192 m_unit = unit;
194 193  
195 194 // Return
... ... @@ -198,11 +197,30 @@ void GFitsTableCol::unit(const std::string&amp; unit)
198 197  
199 198  
200 199 /***********************************************************************//**
  200 + * @brief Set column dimension
  201 + *
  202 + * @param[in] dim Column dimension.
  203 + *
  204 + * The column dimension is a integer vector.
  205 + *
  206 + * @todo Implement dimension check.
  207 + ***************************************************************************/
  208 +void GFitsTableCol::dim(const std::vector<int>& dim)
  209 +{
  210 + // Set dimension
  211 + m_dim = dim;
  212 +
  213 + // Return
  214 + return;
  215 +}
  216 +
  217 +
  218 +/***********************************************************************//**
201 219 * @brief Returns column name
202 220 ***************************************************************************/
203 221 std::string GFitsTableCol::name(void) const
204 222 {
205   - // Return Name
  223 + // Return name
206 224 return m_name;
207 225 }
208 226  
... ... @@ -212,12 +230,22 @@ std::string GFitsTableCol::name(void) const
212 230 ***************************************************************************/
213 231 std::string GFitsTableCol::unit(void) const
214 232 {
215   - // Return column length
  233 + // Return column unit
216 234 return m_unit;
217 235 }
218 236  
219 237  
220 238 /***********************************************************************//**
  239 + * @brief Returns column dimension
  240 + ***************************************************************************/
  241 +std::vector<int> GFitsTableCol::dim(void) const
  242 +{
  243 + // Return column dimension
  244 + return m_dim;
  245 +}
  246 +
  247 +
  248 +/***********************************************************************//**
221 249 * @brief Returns number of column in FITS file (starting from 1)
222 250 ***************************************************************************/
223 251 int GFitsTableCol::colnum(void) const
... ... @@ -317,10 +345,16 @@ std::string GFitsTableCol::print(void) const
317 345 // Initialise result string
318 346 std::string result;
319 347  
320   - // Append formatted column name
321   - result.append(parformat(m_name));
  348 + // Append formatted column name. Optionally add units
  349 + if (m_unit.length() > 0) {
  350 + result.append(parformat(m_name+" ("+m_unit+")"));
  351 + }
  352 + else {
  353 + result.append(parformat(m_name));
  354 + }
322 355  
323   - // Append column number
  356 + // Append column number. This will be "-" if the column does not exist
  357 + // in the FITS file.
324 358 if (m_colnum > 0)
325 359 result.append(right(str(m_colnum),4)+" ");
326 360 else
... ... @@ -335,6 +369,20 @@ std::string GFitsTableCol::print(void) const
335 369 // Append format information
336 370 result.append("["+binary_format()+","+ascii_format()+"]");
337 371  
  372 + // Append dimensions (if available)
  373 + if (m_dim.size() > 0) {
  374 +
  375 + // Build TDIM string
  376 + std::string value = "("+str(m_dim[0]);
  377 + for (int k = 1; k < m_dim.size(); ++k) {
  378 + value += ","+str(m_dim[k]);
  379 + }
  380 + value += ")";
  381 +
  382 + // Append
  383 + result.append(" "+value);
  384 + }
  385 +
338 386 // Append cfitsio information
339 387 result.append(" repeat="+str(m_repeat));
340 388 result.append(" width="+str(m_width));
... ... @@ -495,16 +543,18 @@ void GFitsTableCol::save_column(void)
495 543 status = __ffmahd(FPTR(m_fitsfile),
496 544 (FPTR(m_fitsfile)->HDUposition)+1, NULL,
497 545 &status);
498   - if (status != 0)
  546 + if (status != 0) {
499 547 throw GException::fits_hdu_not_found(G_SAVE_COLUMN,
500 548 (FPTR(m_fitsfile)->HDUposition)+1,
501 549 status);
  550 + }
502 551  
503 552 // Save the column data
504 553 status = __ffpcn(FPTR(m_fitsfile), m_type, m_colnum, 1, 1,
505 554 m_size, ptr_data(), ptr_nulval(), &status);
506   - if (status != 0)
  555 + if (status != 0) {
507 556 throw GException::fits_error(G_SAVE_COLUMN, status);
  557 + }
508 558  
509 559 } // endif: FITS file was connected
510 560  
... ... @@ -596,6 +646,7 @@ void GFitsTableCol::init_members(void)
596 646 // Initialise members
597 647 m_name.clear();
598 648 m_unit.clear();
  649 + m_dim.clear();
599 650 m_colnum = 0;
600 651 m_type = 0;
601 652 m_repeat = 0;
... ... @@ -620,6 +671,7 @@ void GFitsTableCol::copy_members(const GFitsTableCol&amp; column)
620 671 // Copy attributes
621 672 m_name = column.m_name;
622 673 m_unit = column.m_unit;
  674 + m_dim = column.m_dim;
623 675 m_colnum = column.m_colnum;
624 676 m_type = column.m_type;
625 677 m_repeat = column.m_repeat;
... ...