Logo ROOT   6.08/07
Reference Guide
FITS_tutorial2.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_tutorial2()
12 {
13  printf("\n\n--------------------------------\n");
14  printf("WELCOME TO FITS tutorial #2 !!!!\n");
15  printf("--------------------------------\n");
16  printf("We're gonna open a FITS file that contains the\n");
17  printf("primary HDU and a little data table.\n");
18  printf("The primary HDU is an array of 2 rows by 2040 columns, and\n");
19  printf("they represent a radiation spectrum. The first row contains\n");
20  printf("the flux data, whereas the second row the wavelengths.\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 primary HDU from file
29  TFITSHDU *hdu = new TFITSHDU(dir+"/sample2.fits");
30  if (hdu == 0) {
31  printf("ERROR: could not access the HDU\n"); return;
32  }
33  printf("File successfully open!\n");
34 
35 
36  // Dump the HDUs within the FITS file
37  // and also their metadata
38  //printf("Press ENTER to see summary of all data stored in the file:"); getchar();
39  hdu->Print("F+");
40 
41  printf("....................................\n");
42  printf("We are going to generate a TGraph from vectors\n");
43  //printf("within the primary array. Press ENTER to continue.."); getchar();
44 
45  TVectorD *Y = hdu->GetArrayRow(0);
46  TVectorD *X = hdu->GetArrayRow(1);
47  TGraph *gr = new TGraph(*X,*Y);
48 
49  // Show the graphic
50  TCanvas *c = new TCanvas("c1", "FITS tutorial #2", 800, 800);
51  gr->Draw("BA");
52 
53 
54  // Clean up
55  delete X;
56  delete Y;
57  delete hdu;
58 }
return c
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
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:747
void Print(const Option_t *opt="") const
Print metadata.
Definition: TFITS.cxx:722
FITS file interface class.
Definition: TFITS.h:40
TVectorD * GetArrayRow(UInt_t row)
Get a row from the image HDU when it's a 2D array.
Definition: TFITS.cxx:1037
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
TGraphErrors * gr
Definition: legend1.C:25
The Canvas class.
Definition: TCanvas.h:41
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53