Logo ROOT   6.07/09
Reference Guide
FITS_tutorial4.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 void FITS_tutorial4()
11 {
12  printf("\n\n--------------------------------\n");
13  printf("WELCOME TO FITS tutorial #4 !!!!\n");
14  printf("--------------------------------\n");
15  printf("We're gonna open a FITS file that contains the\n");
16  printf("primary HDU and a little data table.\n");
17  printf("The data table is extension #1 and it has 2 rows.\n");
18  printf("We want to read only the rows that have the column\n");
19  printf("named DATAMAX greater than 2e-15 (there's only 1\n");
20  printf("matching row)\n");
21  printf("Data copyright: NASA\n\n");
22 
23  if (!gROOT->IsBatch()) {
24  //printf("Press ENTER to start..."); getchar();
25  }
26  TString dir = gSystem->DirName(__FILE__);
27 
28  //Open the table extension number 1)
29  TFITSHDU *hdu = new TFITSHDU(dir+"/sample2.fits[1][DATAMAX > 2e-15]");
30  if (hdu == 0) {
31  printf("ERROR: could not access the HDU\n"); return;
32  }
33  //printf("Press ENTER to see information about the table's columns..."); getchar();
34  hdu->Print("T");
35 
36  printf("\n\n........................................\n");
37  printf("Press ENTER to see full table contents (maybe you should resize\n");
38  //printf("this window as large as possible before)..."); getchar();
39  hdu->Print("T+");
40 
41  printf("\n\n........................................\n");
42  //printf("Press ENTER to get only the DATAMAX value of the matched row..."); getchar();
43  TVectorD *v = hdu->GetTabRealVectorColumn("DATAMAX");
44  printf("%lg\n", (*v)[0]);
45 
46 
47  printf("Does the matched row have DATAMAX > 2e-15? :-)\n");
48 
49  //Clean up
50  delete v;
51  delete hdu;
52 }
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
FITS file interface class.
Definition: TFITS.h:40
void Print(const Option_t *opt="") const
Print metadata.
Definition: TFITS.cxx:722
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
SVector< double, 2 > v
Definition: Dict.h:5
TVectorD * GetTabRealVectorColumn(Int_t colnum)
Get a real number-typed column from a table HDU given its column index (>=0).
Definition: TFITS.cxx:1194