Commit 4c183d28d47d28107f5978307989a4deb02aea32

Authored by Jürgen Knödlseder
1 parent 9c085b7c

Add FITS file creation example.

examples/cpp/createfits/Makefile 0 → 100644
  1 +CXX=g++
  2 +CFLAGS=-I/usr/local/gamma/include/gammalib
  3 +LDFLAGS=-L/usr/local/gamma/lib -lgamma
  4 +DEPS=
  5 +OBJ=createfits.cpp
  6 +
  7 +createfits: $(OBJ)
  8 + $(CXX) -o $@ $^ $(CFLAGS) $(LDFLAGS)
... ...
examples/cpp/createfits/createfits.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * createfits.cpp - Create FITS file *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2013 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file createfits.cpp
  23 + * @brief Create FITS file
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#include "GammaLib.hpp"
  29 +
  30 +
  31 +/***********************************************************************//**
  32 + * @brief Create FITS file
  33 + *
  34 + * This code illustrates the creation of a FITS file.
  35 + ***************************************************************************/
  36 +int main(void) {
  37 +
  38 + // Allocate FITS object
  39 + GFits fits;
  40 +
  41 + // Create FITS image
  42 + GFitsImageDouble image(20,10);
  43 + for (int x = 0; x < 20; ++x) {
  44 + for (int y = 0; y < 10; ++y) {
  45 + image(x,y) = x+100.0*y;
  46 + }
  47 + }
  48 +
  49 + // Append image to FITS object
  50 + fits.append(image);
  51 +
  52 + // Create binary table
  53 + GFitsBinTable table;
  54 + GFitsTableDoubleCol column("ENERGY", 10, 3);
  55 + for (int row = 0; row < 10; ++row) {
  56 + for (int index = 0; index < 3; ++index) {
  57 + column(row, index) = row*100.0+index;
  58 + }
  59 + }
  60 + table.append_column(column);
  61 +
  62 + // Append table to FITS object
  63 + fits.append(table);
  64 +
  65 + // Save file to disk
  66 + fits.saveto("my_fits_file.fits", true);
  67 +
  68 + // Close FITS object
  69 + fits.close();
  70 +
  71 + // Exit
  72 + return 0;
  73 +}
  74 +
... ...