Logo ROOT   6.14/05
Reference Guide
FITS_tutorial7.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_FITS
3 /// Open a FITS file that contains a catalog of astronomical objects
4 /// and dump some of its columns
5 ///
6 /// \macro_code
7 ///
8 /// \author Elizabeth Buckley-Geer
9 
10 void FITS_tutorial7()
11 {
12 
13  printf("\n\n--------------------------------\n");
14  printf("WELCOME TO FITS tutorial #7 !!!!\n");
15  printf("--------------------------------\n");
16  printf("We are going to open a table from a FITS file\n");
17  printf("and print out three columns for some of the objects.\n");
18  printf("This table contains a logical data type so this tutorial tests\n");
19  printf("that we can read it correctly\n\n");
20 
21  TString dir = gSystem->DirName(__FILE__);
22 
23  // Open the table
24  TFITSHDU *hdu = new TFITSHDU(dir + "/sample5.fits[1]");
25  if (hdu == 0) {
26  printf("ERROR: could not access the HDU\n");
27  return;
28  }
29 
30  TVectorD *vec1;
31  TVectorD *vec2;
32  TVectorD *vec3;
33  TVectorD *vec4;
34 
35  // Read the ra, dec, flux_g and brick_primary columns
36 
37  vec1 = hdu->GetTabRealVectorColumn("ra");
38  vec2 = hdu->GetTabRealVectorColumn("dec");
39  vec3 = hdu->GetTabRealVectorColumn("flux_g");
40  vec4 = hdu->GetTabRealVectorColumn("brick_primary");
41 
42  Double_t gflux, ra, dec, bp;
43 
44  for (Int_t i = vec1->GetLwb(); i <= vec1->GetUpb(); i++) {
45 
46  bp = (*vec4)[i];
47  gflux = (*vec3)[i];
48  ra = (*vec1)[i];
49  dec = (*vec2)[i];
50 
51  if (bp) {
52  printf("RA %f DEC %f G-FLUX %f\n", ra, dec, gflux);
53  }
54  }
55 
56  // Clean up
57 
58  delete vec1;
59  delete vec2;
60  delete vec3;
61  delete vec4;
62  delete hdu;
63 }
Int_t GetLwb() const
Definition: TVectorT.h:73
Int_t GetUpb() const
Definition: TVectorT.h:74
TVectorT.
Definition: TMatrixTBase.h:77
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1004
FITS file interface class.
Definition: TFITS.h:34
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
double Double_t
Definition: RtypesCore.h:55
TVectorD * GetTabRealVectorColumn(Int_t colnum)
Get a real number-typed column from a table HDU given its column index (>=0).
Definition: TFITS.cxx:1225