GNU Astronomy Utilities



12.3.11.1 FITS Macros, errors and filenames

Some general constructs provided by Gnuastro’s FITS handling functions are discussed here. In particular there are several useful functions about FITS file names.

Macro: GAL_FITS_MAX_NDIM

The maximum number of dimensions a dataset can have in FITS format, according to the FITS standard this is 999.

Function:
void
gal_fits_io_error (int status, char *message)

If status is non-zero, this function will print the CFITSIO error message corresponding to status, print message (optional) in the next line and abort the program. If message==NULL, it will print a default string after the CFITSIO error.

Function:
int
gal_fits_name_is_fits (char *name)

If the name is an acceptable CFITSIO FITS filename return 1 (one), otherwise return 0 (zero). The currently acceptable FITS suffixes are .fits, .fit, .fits.gz, .fits.Z, .imh, .fits.fz. IMH is the IRAF format which is acceptable to CFITSIO.

Function:
int
gal_fits_suffix_is_fits (char *suffix)

Similar to gal_fits_name_is_fits, but only for the suffix. The suffix does not have to start with ‘.’: this function will return 1 (one) for both fits and .fits.

Function:
int
gal_fits_file_recognized (char *name)

Return 1 if the given file name (possibly including its contents) is a FITS file. This is necessary when the contents of a FITS file do follow the FITS standard, but the file does not have a Gnuastro-recognized FITS suffix. Therefore, it will first call gal_fits_name_is_fits, if the result is negative, then this function will attempt to open the file with CFITSIO and if it works, it will close it again and return 1. In the process of opening the file, CFITSIO will just open the file, and no reading will take place, so it should have a minimal CPU footprint.

Function:
char *
gal_fits_name_save_as_string (char *filename, char *hdu)

If the name is a FITS name, then put a (hdu: ...) after it and return the string. If it is not a FITS file, just print the name, if filename==NULL, then return the string stdin. Note that the output string’s space is allocated.

This function is useful when you want to report a random file to the user which may be FITS or not (for a FITS file, simply the filename is not enough, the HDU is also necessary).