1 /*
2  # This file is part of the Astrometry.net suite.
3  # Licensed under a 3-clause BSD style license - see LICENSE
4  */
5 
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <sys/types.h>
11 
12 #include "new-wcs.h"
13 #include "fitsioutils.h"
14 #include "errors.h"
15 #include "log.h"
16 
17 static const char* OPTIONS = "hi:w:o:de:v";
18 
printHelp(char * progname)19 static void printHelp(char* progname) {
20     printf("%s    -i <input-file>\n"
21            "      -w <WCS-file>\n"
22            "      -o <output-file>\n"
23            "      [-e <extension>]: (default: copy data from primary HDU)\n"
24            "      [-d]: also copy the data segment\n"
25            "      [-v]: +verbose\n"
26            "\n",
27            progname);
28 }
29 
30 
main(int argc,char * argv[])31 int main(int argc, char *argv[]) {
32     int argchar;
33     char* infn = NULL;
34     char* outfn = NULL;
35     char* wcsfn = NULL;
36     char* progname = argv[0];
37     anbool copydata = FALSE;
38     int loglvl = LOG_MSG;
39     int extension = 0;
40 
41     while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
42         switch (argchar) {
43         case 'v':
44             loglvl++;
45             break;
46         case 'e':
47             extension = atoi(optarg);
48             break;
49         case 'i':
50             infn = optarg;
51             break;
52         case 'o':
53             outfn = optarg;
54             break;
55         case 'w':
56             wcsfn = optarg;
57             break;
58         case 'd':
59             copydata = TRUE;
60             break;
61         case '?':
62         case 'h':
63             printHelp(progname);
64             return 0;
65         default:
66             return -1;
67         }
68 
69     if (!infn || !outfn || !wcsfn) {
70         printHelp(progname);
71         exit(-1);
72     }
73     log_init(loglvl);
74     fits_use_error_system();
75 
76     if (new_wcs(infn, extension, wcsfn, outfn, copydata)) {
77         ERROR("new_wcs() failed");
78         exit(-1);
79     }
80     return 0;
81 }
82