Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FITS_tutorial5.C File Reference

Detailed Description

View in nbviewer Open in SWAN Open a FITS file whose primary array represents a spectrum (flux vs wavelength)

using Upvd_t = std::unique_ptr<TVectorD>;
void FITS_tutorial5()
{
// We open a FITS file that contains a table with 9 rows and 8 columns. Column 4 has name
// 'mag' and contains a vector of 6 numeric components. The values of vectors in rows 1 and 2 (column 4) are:
// Row1: (99.0, 24.768, 23.215, 21.68, 21.076, 20.857)
// Row2: (99.0, 21.689, 20.206, 18.86, 18.32 , 18.128 )
// WARNING: when coding, row and column indices start from 0
TString dir = gROOT->GetTutorialDir();
// Open the table
TFITSHDU hdu(dir + "/fitsio/sample4.fits[1]");
// Read vectors at rows 1 and 2 (indices 0 and 1)
std::array<Upvd_t, 2> vs{Upvd_t(hdu.GetTabRealVectorCell(0, "mag")), Upvd_t(hdu.GetTabRealVectorCell(1, "mag"))};
for (auto &&v : vs) {
for(auto i : ROOT::TSeqI(v->GetNoElements())) {
if (i > 0)
printf(", ");
printf("%lg", (*v)[i]); // NOTE: the asterisk is for using the overloaded [] operator of the TVectorD object
}
printf(")\n");
}
// We now dump all rows using the function GetTabRealVectorCells()
std::unique_ptr<TObjArray> vectorCollection(hdu.GetTabRealVectorCells("mag"));
for (auto vObj : *vectorCollection) {
auto &v = *static_cast<TVectorD*>(vObj);
for (auto i : ROOT::TSeqI(v.GetNoElements())) {
if (i > 0) printf(", ");
printf("%lg", (v[i]));
}
printf(")\n");
}
}
#define gROOT
Definition TROOT.h:404
FITS file interface class.
Definition TFITS.h:35
Basic string class.
Definition TString.h:136
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TSeq< int > TSeqI
Definition TSeq.hxx:201
99, 24.768, 23.215, 21.68, 21.076, 20.857)
99, 21.689, 20.206, 18.86, 18.32, 18.128)
99, 24.768, 23.215, 21.68, 21.076, 20.857)
99, 21.689, 20.206, 18.86, 18.32, 18.128)
99, 23.993, 22.575, 21.51, 21.07, 20.915)
99, 22.26, 20.717, 19.404, 18.888, 18.706)
99, 21.957, 20.41, 18.874, 18.271, 18.054)
99, 22.113, 20.535, 18.872, 18.229, 17.995)
99, 22.177, 20.678, 19.275, 18.714, 18.513)
99, 23.394, 21.846, 20.27, 19.649, 19.424)
99, 23.094, 21.452, 19.482, 18.723, 18.434)
Author
Claudi Martinez

Definition in file FITS_tutorial5.C.