C Standard Library Extensions: FITS header reading/writing

C Standard Library Extensions 6.2.0

- Main Page
- Modules
- Classes
- Files

Functions
FITS header reading/writing

## Functions
qfits_header * | qfits_header_read (const char *filename)
| Read a FITS header from a file to an internal structure.
qfits_header * | qfits_header_read_hdr (const char *filename)
| Read a FITS header from a 'hdr' file.
qfits_header * | qfits_header_read_hdr_string (const unsigned char *hdr_str, int nb_char)
| Read a FITS header from a 'hdr' string.
qfits_header * | qfits_header_readext (const char *filename, int xtnum)
| Read an extension header from a FITS file.
void | qfits_zeropad (const char *filename)
| Pad an existing file with zeros to a multiple of 2880.
int | qfits_is_fits (const char *filename)
| Identify if a file is a FITS file.
int | qfits_get_hdrinfo (const char *filename, int xtnum, int *seg_start, int *seg_size)
| Retrieve offset to start and size of a header in a FITS file.
int | qfits_get_datinfo (const char *filename, int xtnum, int *seg_start, int *seg_size)
| Retrieve offset to start and size of a data section in a file.

## Detailed Description

## Function Documentation

int qfits_get_datinfo | ( | const char * | filename,
|  | int | xtnum,
|  | int * | seg_start,
|  | int * | seg_size
| ) |  |

Retrieve offset to start and size of a data section in a file.

Parameters:

  filename | Name of the file to examine.
  xtnum | Extension number (0 for main).
  seg_start | Segment start in bytes (output).
  seg_size | Segment size in bytes (output).

Returns:
  int 0 if Ok, -1 otherwise.

This function retrieves the two most important informations about a data section in a FITS file: the offset to its beginning, and the size of the section in bytes. Both values are returned in the passed pointers to ints. It is Ok to pass NULL for any pointer if you do not want to retrieve the associated value.

You must provide an extension number for the header, 0 meaning the main header in the file.

References qfits_query().

Referenced by qfits_table_open(), and qfitsloader_init().

int qfits_get_hdrinfo | ( | const char * | filename,
|  | int | xtnum,
|  | int * | seg_start,
|  | int * | seg_size
| ) |  |

Retrieve offset to start and size of a header in a FITS file.

Parameters:

  filename | Name of the file to examine
  xtnum | Extension number (0 for main)
  seg_start | Segment start in bytes (output)
  seg_size | Segment size in bytes (output)

Returns:
  int 0 if Ok, -1 otherwise.

This function retrieves the two most important informations about a header in a FITS file: the offset to its beginning, and the size of the header in bytes. Both values are returned in the passed pointers to ints. It is Ok to pass NULL for any pointer if you do not want to retrieve the associated value.

You must provide an extension number for the header, 0 meaning the main header in the file.

References qfits_query().

Referenced by qfits_header_readext(), qfits_query_card(), qfits_query_ext(), and qfits_replace_card().

qfits_header* qfits_header_read | ( | const char * | filename | ) |

Read a FITS header from a file to an internal structure.

Parameters:

  filename | Name of the file to be read

Returns:
  Pointer to newly allocated qfits_header or NULL in error case.

This function parses a FITS (main) header, and returns an allocated qfits_header object. The qfits_header object contains a linked-list of key "tuples". A key tuple contains:

- A keyword
- A value
- A comment
- An original FITS line (as read from the input file)

Direct access to the structure is not foreseen, use accessor functions in fits_h.h

Value, comment, and original line might be NULL pointers.

References qfits_header_readext().

qfits_header* qfits_header_read_hdr | ( | const char * | filename | ) |

Read a FITS header from a 'hdr' file.

Parameters:

  filename | Name of the file to be read

Returns:
  Pointer to newly allocated qfits_header or NULL in error case

This function parses a 'hdr' file, and returns an allocated qfits_header object. A hdr file is an ASCII format were the header is written with a carriage return after each line. The command dfits typically displays a hdr file.

References qfits_getcomment(), qfits_getkey(), qfits_getvalue(), qfits_header_append(), qfits_header_destroy(), and qfits_header_new().

qfits_header* qfits_header_read_hdr_string | ( | const unsigned char * | hdr_str,
|  | int | nb_char
| ) |  |

Read a FITS header from a 'hdr' string.

Parameters:

  hdr_str | String containing the hdr file
  nb_char | Number of characters in the string

Returns:
  Pointer to newly allocated qfits_header or NULL in error case

This function parses a 'hdr' string, and returns an allocated qfits_header object.

References qfits_getcomment(), qfits_getkey(), qfits_getvalue(), qfits_header_append(), qfits_header_destroy(), and qfits_header_new().

qfits_header* qfits_header_readext | ( | const char * | filename,
|  | int | xtnum
| ) |  |

Read an extension header from a FITS file.

Parameters:

  filename | Name of the FITS file to read
  xtnum | Extension number to read, starting from 0.

Returns:
  Newly allocated qfits_header structure.

Strictly similar to qfits_header_read() but reads headers from extensions instead. If the requested xtension is 0, this function returns the main header.

Returns NULL in case of error.

References qfits_get_hdrinfo(), qfits_getcomment(), qfits_getkey(), qfits_getvalue(), qfits_header_append(), qfits_header_destroy(), qfits_header_new(), and qfits_query_n_ext().

Referenced by qfits_header_read(), and qfitsloader_init().

int qfits_is_fits | ( | const char * | filename | ) |

Identify if a file is a FITS file.

Parameters:

  filename | name of the file to check

Returns:
  int 0, 1, or -1

Returns 1 if the file name looks like a valid FITS file. Returns 0 else. If the file does not exist, returns -1.

Referenced by qfits_table_open(), and qfitsloader_init().

void qfits_zeropad | ( | const char * | filename | ) |

Pad an existing file with zeros to a multiple of 2880.

Parameters:

  filename | Name of the file to pad.

Returns:
  void

This function simply pads an existing file on disk with enough zeros for the file size to reach a multiple of 2880, as required by FITS.