30#if defined(HAVE_LIBCFITSIO)
33#pragma GCC diagnostic ignored "-Wstrict-prototypes"
35#pragma GCC diagnostic pop
37#error CFITSIO library is not available
40int main(
int argc,
char *argv[] )
45 int single = 0, hdupos = 0, nkeys = 0, ii = 0;
47 int printhelp = ( argc == 2 && ( strcmp( argv[1],
"-h" ) == 0 || strcmp( argv[1],
"--help" ) == 0 ) );
49 if ( printhelp || argc != 2 ) {
50 fprintf( stderr,
"Usage: %s filename[ext] \n", argv[0] );
52 fprintf( stderr,
"List the FITS header keywords in a single extension, or, if \n" );
53 fprintf( stderr,
"ext is not given, list the keywords in all the extensions. \n" );
55 fprintf( stderr,
"Examples: \n" );
56 fprintf( stderr,
" %s file.fits - list every header in the file \n", argv[0] );
57 fprintf( stderr,
" %s file.fits[0] - list primary array header \n", argv[0] );
58 fprintf( stderr,
" %s file.fits[2] - list header of 2nd extension \n", argv[0] );
59 fprintf( stderr,
" %s file.fits+2 - same as above \n", argv[0] );
60 fprintf( stderr,
" %s file.fits[GTI] - list header of GTI extension\n", argv[0] );
62 fprintf( stderr,
"Note that it may be necessary to enclose the input file\n" );
63 fprintf( stderr,
"name in single quote characters on the Unix command line.\n" );
67#if defined(PAGER) && defined(HAVE_POPEN) && defined(HAVE_PCLOSE)
68 FILE *fout = popen( PAGER,
"w" );
70 fprintf( stderr,
"Could not execute '%s'\n", PAGER );
77 if ( !fits_open_file( &fptr, argv[1], READONLY, &
status ) ) {
78 fits_get_hdu_num( fptr, &hdupos );
81 if ( hdupos != 1 || strchr( argv[1],
'[' ) ) {
85 for ( ; !
status; hdupos++ ) {
86 fits_get_hdrspace( fptr, &nkeys, NULL, &
status );
88 fprintf( fout,
"Header listing for HDU #%d:\n", hdupos );
90 for ( ii = 1; ii <= nkeys; ii++ ) {
92 if ( fits_read_record( fptr, ii, card, &
status ) ) {
103 fits_movrel_hdu( fptr, 1, NULL, &
status );
106 if (
status == END_OF_FILE ) {
110 fits_close_file( fptr, &
status );
113#if defined(PAGER) && defined(HAVE_POPEN) && defined(HAVE_PCLOSE)
118 fits_report_error( stderr,
status );