File: listhead.c

package info (click to toggle)
astrometry.net 0.93%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,372 kB
  • sloc: ansic: 163,192; python: 18,357; makefile: 1,522; sh: 138; cpp: 78; pascal: 67; awk: 56; perl: 9
file content (77 lines) | stat: -rw-r--r-- 3,022 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 This file was downloaded from the CFITSIO utilities web page:
 http://heasarc.gsfc.nasa.gov/docs/software/fitsio/cexamples.html

 That page contains this text:
 You may freely modify, reuse, and redistribute these programs as you wish.

 We assume it was originally written by the CFITSIO authors (primarily William
 D. Pence).

 We (the Astrometry.net team) have modified it slightly.
 # Licensed under a 3-clause BSD style license - see LICENSE
 */

#include <string.h>
#include <stdio.h>
#include "fitsio.h"

int main(int argc, char *argv[])
{
    fitsfile *fptr;         /* FITS file pointer, defined in fitsio.h */
    char card[FLEN_CARD];   /* Standard string lengths defined in fitsio.h */
    int status = 0;   /* CFITSIO status value MUST be initialized to zero! */
    int single = 0, hdupos, nkeys, ii;

    if (argc != 2) {
        printf("Usage:  listhead filename[ext] \n");
        printf("\n");
        printf("List the FITS header keywords in a single extension, or, if \n");
        printf("ext is not given, list the keywords in all the extensions. \n");
        printf("\n");
        printf("Examples: \n");
        printf("   listhead file.fits      - list every header in the file \n");
        printf("   listhead file.fits[0]   - list primary array header \n");
        printf("   listhead file.fits[2]   - list header of 2nd extension \n");
        printf("   listhead file.fits+2    - same as above \n");
        printf("   listhead file.fits[GTI] - list header of GTI extension\n");
        printf("\n");
        printf("Note that it may be necessary to enclose the input file\n");
        printf("name in single quote characters on the Unix command line.\n");
        return(0);
    }

    if (!fits_open_file(&fptr, argv[1], READONLY, &status))
        {
            fits_get_hdu_num(fptr, &hdupos);  /* Get the current HDU position */

            /* List only a single header if a specific extension was given */ 
            if (hdupos != 1 || strchr(argv[1], '[')) single = 1;

            for (; !status; hdupos++)  /* Main loop through each extension */
                {
                    fits_get_hdrspace(fptr, &nkeys, NULL, &status); /* get # of keywords */

                    printf("Header listing for HDU #%d:\n", hdupos);

                    for (ii = 1; ii <= nkeys; ii++) { /* Read and print each keywords */

                        if (fits_read_record(fptr, ii, card, &status))break;
                        printf("%s\n", card);
                    }
                    printf("END\n\n");  /* terminate listing with END */

                    if (single) break;  /* quit if only listing a single header */

                    fits_movrel_hdu(fptr, 1, NULL, &status);  /* try to move to next HDU */
                }

            if (status == END_OF_FILE)  status = 0; /* Reset after normal error */

            fits_close_file(fptr, &status);
        }

    if (status) fits_report_error(stderr, status); /* print any error message */
    return(status);
}