27 | | An example of reading and writing is available in !RootHealPix/tutorials/[ReadAndWrite.C]. |
| 27 | The following example onreading and writing is adapted from !RootHealPix/tutorials/ReadAndWrite.C. |
| 28 | |
| 29 | {{{!#Spoiler |
| 30 | {{{!#c++ |
| 31 | void ReadAndWrite() |
| 32 | { |
| 33 | THealPixD hpd1("hpd1", "data1", 5); |
| 34 | THealPixD hpd2("hpd2", "data2", 4); |
| 35 | hpd1.SetUnit("MeV"); // Set the unit of entries |
| 36 | hpd2.SetUnit("GeV"); |
| 37 | hpd1.SetDegree(); // change the unit of Fill(theta, phi) |
| 38 | hpd2.SetDegree(); |
| 39 | |
| 40 | for(Int_t i = 0; i<1800; i++) |
| 41 | { |
| 42 | for(Int_t j = 0; j<3600; j++) |
| 43 | { |
| 44 | hpd1.Fill(i/10., j/10., 1); |
| 45 | hpd2.Fill(i/10., j/10., 5); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | std::vector<THealPix*> vec; |
| 50 | vec.push_back(&hpd1); |
| 51 | vec.push_back(&hpd2); |
| 52 | |
| 53 | THealUtil::SaveToFits("!test.fits", vec); // hpd1/2 are saved in one file |
| 54 | |
| 55 | // Read only "data2" from FITS file |
| 56 | THealPixD* hpd = THealPixD::ReadFits("test.fits", "data2"); |
| 57 | |
| 58 | std::cout << "Order: " << hpd->GetOrder() << std::endl; |
| 59 | std::cout << "Nside: " << hpd->GetNside() << std::endl; |
| 60 | std::cout << "Npix : " << hpd->GetNpix() << std::endl; |
| 61 | std::cout << "Unit : " << hpd->GetUnit() << std::endl; |
| 62 | std::cout << "Title: " << hpd->GetTitle() << std::endl; |
| 63 | } |
| 64 | }}} |
| 65 | }}} |