1 #include <stdio.h>
2 #include "fitsio.h"
3 
main(int argc,char * argv[])4 int main(int argc, char *argv[])
5 {
6     fitsfile *infptr, *outfptr;   /* FITS file pointers defined in fitsio.h */
7     int status = 0;       /* status must always be initialized = 0  */
8 
9     if (argc != 3)
10     {
11  printf("Usage:  fitscopy inputfile outputfile\n");
12  printf("\n");
13  printf("Copy an input file to an output file, optionally filtering\n");
14  printf("the file in the process.  This seemingly simple program can\n");
15  printf("apply powerful filters which transform the input file as\n");
16  printf("it is being copied.  Filters may be used to extract a\n");
17  printf("subimage from a larger image, select rows from a table,\n");
18  printf("filter a table with a GTI time extension or a SAO region file,\n");
19  printf("create or delete columns in a table, create an image by\n");
20  printf("binning (histogramming) 2 table columns, and convert IRAF\n");
21  printf("format *.imh or raw binary data files into FITS images.\n");
22  printf("See the CFITSIO User's Guide for a complete description of\n");
23  printf("the Extended File Name filtering syntax.\n");
24  printf("\n");
25  printf("Examples:\n");
26  printf("\n");
27  printf("fitscopy in.fit out.fit                   (simple file copy)\n");
28  printf("fitscopy - -                              (stdin to stdout)\n");
29  printf("fitscopy in.fit[11:50,21:60] out.fit      (copy a subimage)\n");
30  printf("fitscopy iniraf.imh out.fit               (IRAF image to FITS)\n");
31  printf("fitscopy in.dat[i512,512] out.fit         (raw array to FITS)\n");
32  printf("fitscopy in.fit[events][pi>35] out.fit    (copy rows with pi>35)\n");
33  printf("fitscopy in.fit[events][bin X,Y] out.fit  (bin an image) \n");
34  printf("fitscopy in.fit[events][col x=.9*y] out.fit        (new x column)\n");
35  printf("fitscopy in.fit[events][gtifilter()] out.fit       (time filter)\n");
36  printf("fitscopy in.fit[2][regfilter(\"pow.reg\")] out.fit (spatial filter)\n");
37  printf("\n");
38  printf("Note that it may be necessary to enclose the input file name\n");
39  printf("in single quote characters on the Unix command line.\n");
40       return(0);
41     }
42     /* Open the input file */
43     if ( !fits_open_file(&infptr, argv[1], READONLY, &status) )
44     {
45       /* Create the output file */
46       if ( !fits_create_file(&outfptr, argv[2], &status) )
47       {
48 
49         /* copy the previous, current, and following HDUs */
50         fits_copy_file(infptr, outfptr, 1, 1, 1, &status);
51 
52         fits_close_file(outfptr,  &status);
53       }
54       fits_close_file(infptr, &status);
55     }
56 
57     /* if error occured, print out error message */
58     if (status) fits_report_error(stderr, status);
59     return(status);
60 }
61