ROOT
6.07/01
Reference Guide
ROOT Home Page
Main Page
Tutorials
User's Classes
Namespaces
All Classes
Files
Release Notes
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
tutorials
fitsio
FITS_tutorial5.C
Go to the documentation of this file.
1
// Open a FITS file whose primary array represents
2
// a spectrum (flux vs wavelength)
3
void
FITS_tutorial5
()
4
{
5
TVectorD
*
v
;
6
7
printf
(
"\n\n--------------------------------\n"
);
8
printf
(
"WELCOME TO FITS tutorial #5 !!!!\n"
);
9
printf
(
"--------------------------------\n"
);
10
printf
(
"We're gonna open a FITS file that contains a\n"
);
11
printf
(
"table with 9 rows and 8 columns. Column 4 has name\n"
);
12
printf
(
"'mag' and contains a vector of 6 numeric components.\n"
);
13
printf
(
"The values of vectors in rows 1 and 2 (column 4) are:\n"
);
14
printf
(
"Row1: (99.0, 24.768, 23.215, 21.68, 21.076, 20.857)\n"
);
15
printf
(
"Row2: (99.0, 21.689, 20.206, 18.86, 18.32 , 18.128 )\n"
);
16
printf
(
"WARNING: when coding, row and column indices start from 0\n"
);
17
18
if
(!
gROOT
->IsBatch()) {
19
//printf("Press ENTER to start..."); getchar();
20
//printf("\n");
21
}
22
23
TString
dir
=
gSystem
->
DirName
(__FILE__);
24
25
//Open the table
26
TFITSHDU
*hdu =
new
TFITSHDU
(dir+
"/sample4.fits[1]"
);
27
if
(hdu == 0) {
28
printf
(
"ERROR: could not access the HDU\n"
);
return
;
29
}
30
31
32
//Read vectors at rows 1 and 2 (indices 0 and 1)
33
TVectorD
*vecs[2];
34
vecs[0] = hdu->
GetTabRealVectorCell
(0,
"mag"
);
35
vecs[1] = hdu->
GetTabRealVectorCell
(1,
"mag"
);
36
for
(
int
iVec=0; iVec < 2; iVec++) {
37
printf
(
"Vector %d = ("
, iVec+1);
38
v = vecs[iVec];
39
for
(
int
i=0; i < v->
GetNoElements
(); i++) {
40
if
(i>0)
printf
(
", "
);
41
printf
(
"%lg"
, (*v)[i]);
//NOTE: the asterisk is for using the overloaded [] operator of the TVectorD object
42
}
43
printf
(
")\n"
);
44
}
45
46
printf
(
"\nBONUS EXAMPLE: we're gonna dump all rows using\n"
);
47
printf
(
"the function GetTabRealVectorCells()\n"
);
48
//printf("Press ENTER to continue..."); getchar();
49
50
TObjArray
*vectorCollection = hdu->
GetTabRealVectorCells
(
"mag"
);
51
52
for
(
int
iVec=0; iVec < vectorCollection->
GetEntriesFast
(); iVec++) {
53
printf
(
"Vector %d = ("
, iVec+1);
54
v = (
TVectorD
*) (*vectorCollection)[iVec];
//NOTE: the asterisk is for using the overloaded [] operator of the TObjArray object
55
for
(
int
i=0; i < v->
GetNoElements
(); i++) {
56
if
(i>0)
printf
(
", "
);
57
printf
(
"%lg"
, (*v)[i]);
//NOTE: the asterisk is for using the overloaded [] operator of the TVectorD object
58
}
59
printf
(
")\n"
);
60
}
61
62
63
//Clean up
64
delete
vecs[0];
65
delete
vecs[1];
66
delete
vectorCollection;
67
delete
hdu;
68
}
69
70
TObjArray
An array of TObjects.
Definition:
TObjArray.h:39
TVectorT< Double_t >
gROOT
#define gROOT
Definition:
TROOT.h:344
TString
Basic string class.
Definition:
TString.h:137
TSystem::DirName
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition:
TSystem.cxx:980
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
Definition:
TObjArray.h:66
TFITSHDU
FITS file interface class.
Definition:
TFITS.h:40
FITS_tutorial5
void FITS_tutorial5()
Definition:
FITS_tutorial5.C:3
gSystem
R__EXTERN TSystem * gSystem
Definition:
TSystem.h:545
v
SVector< double, 2 > v
Definition:
Dict.h:5
printf
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
dir
void dir(char *path=0)
Definition:
rootalias.C:30
TFITSHDU::GetTabRealVectorCell
TVectorD * GetTabRealVectorCell(Int_t rownum, Int_t colnum)
Get a real vector embedded in a cell given by (row>=0, column>=0)
Definition:
TFITS.cxx:1373
TVectorT::GetNoElements
Int_t GetNoElements() const
Definition:
TVectorT.h:82
TFITSHDU::GetTabRealVectorCells
TObjArray * GetTabRealVectorCells(Int_t colnum)
Get a collection of real vectors embedded in cells along a given column from a table HDU...
Definition:
TFITS.cxx:1315