ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FITS_tutorial2.C
Go to the documentation of this file.
1 // Open a FITS file whose primary array represents
2 // a spectrum (flux vs wavelength)
4 {
5  printf("\n\n--------------------------------\n");
6  printf("WELCOME TO FITS tutorial #2 !!!!\n");
7  printf("--------------------------------\n");
8  printf("We're gonna open a FITS file that contains the\n");
9  printf("primary HDU and a little data table.\n");
10  printf("The primary HDU is an array of 2 rows by 2040 columns, and\n");
11  printf("they represent a radiation spectrum. The first row contains\n");
12  printf("the flux data, whereas the second row the wavelengths.\n");
13  printf("Data copyright: NASA\n\n");
14 
15  if (!gROOT->IsBatch()) {
16  //printf("Press ENTER to start..."); getchar();
17  }
18  TString dir = gSystem->DirName(__FILE__);
19 
20  // Open primary HDU from file
21  TFITSHDU *hdu = new TFITSHDU(dir+"/sample2.fits");
22  if (hdu == 0) {
23  printf("ERROR: could not access the HDU\n"); return;
24  }
25  printf("File successfully open!\n");
26 
27 
28  // Dump the HDUs within the FITS file
29  // and also their metadata
30  //printf("Press ENTER to see summary of all data stored in the file:"); getchar();
31  hdu->Print("F+");
32 
33  printf("....................................\n");
34  printf("We are going to generate a TGraph from vectors\n");
35  //printf("within the primary array. Press ENTER to continue.."); getchar();
36 
37  TVectorD *Y = hdu->GetArrayRow(0);
38  TVectorD *X = hdu->GetArrayRow(1);
39  TGraph *gr = new TGraph(*X,*Y);
40 
41  // Show the graphic
42  TCanvas *c = new TCanvas("c1", "FITS tutorial #2", 800, 800);
43  gr->Draw("BA");
44 
45 
46  // Clean up
47  delete X;
48  delete Y;
49  delete hdu;
50 }
51 
52 
void FITS_tutorial2()
Definition: FITS_tutorial2.C:3
return c
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:980
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
FITS file interface class.
Definition: TFITS.h:40
void Print(const Option_t *opt="") const
Print metadata.
Definition: TFITS.cxx:722
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:545
TGraphErrors * gr
Definition: legend1.C:25
The Canvas class.
Definition: TCanvas.h:48
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
void dir(char *path=0)
Definition: rootalias.C:30
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53