/* $Id: cpl_fits.c,v 1.2 2007/11/22 11:04:40 yjung Exp $ * * This file is part of the ESO Common Pipeline Library * Copyright (C) 2001-2004 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Author: yjung $ * $Date: 2007/11/22 11:04:40 $ * $Revision: 1.2 $ * $Name: $ */ #ifdef HAVE_CONFIG_H #include #endif /*----------------------------------------------------------------------------- Includes -----------------------------------------------------------------------------*/ #include #include "cpl_fits.h" #include "cpl_error.h" #include "cpl_memory.h" /*----------------------------------------------------------------------------*/ /** * @defgroup cpl_fits FITS related basic routines * * This module provides functions to get basic information on FITS files * * @par Synopsis: * @code * #include "cpl_fits.h" * @endcode */ /*----------------------------------------------------------------------------*/ /**@{*/ /*----------------------------------------------------------------------------- Function codes -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /** @brief Get the number of extensions contained in a FITS file @param filename The file name @return the number of extensions or -1 in error case Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if the input pointer is NULL - CPL_ERROR_ILLEGAL_INPUT if the input file is not FITS */ /*----------------------------------------------------------------------------*/ int cpl_fits_get_nb_extensions(const char * filename) { fitsfile * fptr ; int fio_status=0 ; char * extname ; int cur_ext ; /* Check entries */ cpl_ensure(filename, CPL_ERROR_NULL_INPUT, -1); /* Check the PDU */ extname = cpl_sprintf(filename) ; fits_open_file(&fptr, extname, READONLY, &fio_status) ; cpl_free(extname) ; cpl_ensure(fio_status==0, CPL_ERROR_ILLEGAL_INPUT, -1) ; fits_close_file(fptr, &fio_status) ; /* Check the extensions */ cur_ext = 0 ; while (fio_status==0) { cur_ext ++ ; extname = cpl_sprintf("%s[%d]", filename, cur_ext) ; fits_open_file(&fptr, extname, READONLY, &fio_status) ; cpl_free(extname) ; /* Last extension reached ? */ if (fio_status != 0) break ; else fits_close_file(fptr, &fio_status) ; } return cur_ext-1 ; ; } /*----------------------------------------------------------------------------*/ /** @brief Get the place of a given extensions in a FITS file @param filename The file name @param extname The extension name @return the extension place or 0 if it is not there or -1 in error case Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if one of the input pointers is NULL */ /*----------------------------------------------------------------------------*/ int cpl_fits_get_extension_nb( const char * filename, const char * extname) { fitsfile * fptr ; int fio_status=0 ; char * fileextname ; int ext_num ; /* Check entries */ cpl_ensure(filename, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(extname, CPL_ERROR_NULL_INPUT, -1); /* Open the searched extension */ fileextname = cpl_sprintf("%s[%s]", filename, extname) ; fits_open_file(&fptr, fileextname, READONLY, &fio_status) ; cpl_free(fileextname) ; if (fio_status != 0) return 0 ; fits_get_hdu_num(fptr, &ext_num) ; fits_close_file(fptr, &fio_status) ; return ext_num - 1 ; } /**@}*/