Logo ROOT   6.07/09
Reference Guide
FITS_tutorial5.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_FITS
3 /// Open a FITS file whose primary array represents
4 /// a spectrum (flux vs wavelength)
5 ///
6 /// \macro_code
7 ///
8 /// \author Claudi Martinez
9 
10 
11 void FITS_tutorial5()
12 {
13  TVectorD *v;
14 
15  printf("\n\n--------------------------------\n");
16  printf("WELCOME TO FITS tutorial #5 !!!!\n");
17  printf("--------------------------------\n");
18  printf("We're gonna open a FITS file that contains a\n");
19  printf("table with 9 rows and 8 columns. Column 4 has name\n");
20  printf("'mag' and contains a vector of 6 numeric components.\n");
21  printf("The values of vectors in rows 1 and 2 (column 4) are:\n");
22  printf("Row1: (99.0, 24.768, 23.215, 21.68, 21.076, 20.857)\n");
23  printf("Row2: (99.0, 21.689, 20.206, 18.86, 18.32 , 18.128 )\n");
24  printf("WARNING: when coding, row and column indices start from 0\n");
25 
26  if (!gROOT->IsBatch()) {
27  //printf("Press ENTER to start..."); getchar();
28  //printf("\n");
29  }
30 
31  TString dir = gSystem->DirName(__FILE__);
32 
33  //Open the table
34  TFITSHDU *hdu = new TFITSHDU(dir+"/sample4.fits[1]");
35  if (hdu == 0) {
36  printf("ERROR: could not access the HDU\n"); return;
37  }
38 
39 
40  //Read vectors at rows 1 and 2 (indices 0 and 1)
41  TVectorD *vecs[2];
42  vecs[0] = hdu->GetTabRealVectorCell(0, "mag");
43  vecs[1] = hdu->GetTabRealVectorCell(1, "mag");
44  for (int iVec=0; iVec < 2; iVec++) {
45  printf("Vector %d = (", iVec+1);
46  v = vecs[iVec];
47  for(int i=0; i < v->GetNoElements(); i++) {
48  if (i>0) printf(", ");
49  printf("%lg", (*v)[i]); //NOTE: the asterisk is for using the overloaded [] operator of the TVectorD object
50  }
51  printf(")\n");
52  }
53 
54  printf("\nBONUS EXAMPLE: we're gonna dump all rows using\n");
55  printf("the function GetTabRealVectorCells()\n");
56  //printf("Press ENTER to continue..."); getchar();
57 
58  TObjArray *vectorCollection = hdu->GetTabRealVectorCells("mag");
59 
60  for (int iVec=0; iVec < vectorCollection->GetEntriesFast(); iVec++) {
61  printf("Vector %d = (", iVec+1);
62  v = (TVectorD *) (*vectorCollection)[iVec]; //NOTE: the asterisk is for using the overloaded [] operator of the TObjArray object
63  for(int i=0; i < v->GetNoElements(); i++) {
64  if (i>0) printf(", ");
65  printf("%lg", (*v)[i]); //NOTE: the asterisk is for using the overloaded [] operator of the TVectorD object
66  }
67  printf(")\n");
68  }
69 
70 
71  //Clean up
72  delete vecs[0];
73  delete vecs[1];
74  delete vectorCollection;
75  delete hdu;
76 }
An array of TObjects.
Definition: TObjArray.h:39
TVectorT.
Definition: TMatrixTBase.h:89
#define gROOT
Definition: TROOT.h:364
Basic string class.
Definition: TString.h:137
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:997
Int_t GetEntriesFast() const
Definition: TObjArray.h:66
FITS file interface class.
Definition: TFITS.h:40
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
SVector< double, 2 > v
Definition: Dict.h:5
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
Int_t GetNoElements() const
Definition: TVectorT.h:82
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