aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/cfitsio/listhead.c
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /pkg/tbtables/cfitsio/listhead.c
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/tbtables/cfitsio/listhead.c')
-rw-r--r--pkg/tbtables/cfitsio/listhead.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/pkg/tbtables/cfitsio/listhead.c b/pkg/tbtables/cfitsio/listhead.c
new file mode 100644
index 00000000..a9a62384
--- /dev/null
+++ b/pkg/tbtables/cfitsio/listhead.c
@@ -0,0 +1,62 @@
+#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, 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);
+}
+