From $ROOTSYS/tutorials/fitsio/FITS_tutorial3.C

// Open a FITS file and retrieve the first plane of the image array
// as a TImage object
void FITS_tutorial3()
{
   printf("\n\n--------------------------------\n");
   printf("WELCOME TO FITS tutorial #3 !!!!\n");
   printf("--------------------------------\n");
   printf("We're gonna open a FITS file that contains several image\n");
   printf("extensions. The primary HDU contains no data.\n");
   printf("Data copyright: NASA\n\n");

   if (!gROOT->IsBatch()) {
      //printf("Press ENTER to start..."); getchar();
   }

   // Open extensions 1 to 5 from file
   //printf("Press ENTER to see a canvas with all images within the file:"); getchar();
   TString dir = gSystem->DirName(__FILE__);

   TCanvas *c = new TCanvas("c1", "FITS tutorial #1", 800, 700);
   c->Divide(2,3);
   for (int i=1; i <= 5; i++) {
      TFITSHDU *hdu = new TFITSHDU(dir+"/sample3.fits", i);
      if (hdu == 0) {
         printf("ERROR: could not access the HDU\n"); return;
      }

      TImage *im = hdu->ReadAsImage(0);
      c->cd(i);
      im->Draw();
      delete hdu;
   }
}


 FITS_tutorial3.C:1
 FITS_tutorial3.C:2
 FITS_tutorial3.C:3
 FITS_tutorial3.C:4
 FITS_tutorial3.C:5
 FITS_tutorial3.C:6
 FITS_tutorial3.C:7
 FITS_tutorial3.C:8
 FITS_tutorial3.C:9
 FITS_tutorial3.C:10
 FITS_tutorial3.C:11
 FITS_tutorial3.C:12
 FITS_tutorial3.C:13
 FITS_tutorial3.C:14
 FITS_tutorial3.C:15
 FITS_tutorial3.C:16
 FITS_tutorial3.C:17
 FITS_tutorial3.C:18
 FITS_tutorial3.C:19
 FITS_tutorial3.C:20
 FITS_tutorial3.C:21
 FITS_tutorial3.C:22
 FITS_tutorial3.C:23
 FITS_tutorial3.C:24
 FITS_tutorial3.C:25
 FITS_tutorial3.C:26
 FITS_tutorial3.C:27
 FITS_tutorial3.C:28
 FITS_tutorial3.C:29
 FITS_tutorial3.C:30
 FITS_tutorial3.C:31
 FITS_tutorial3.C:32
 FITS_tutorial3.C:33
 FITS_tutorial3.C:34
 FITS_tutorial3.C:35
 FITS_tutorial3.C:36