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 <assert.h>
11 
12 #include "an-bool.h"
13 #include "resort-xylist.h"
14 #include "fitsioutils.h"
15 #include "errors.h"
16 #include "log.h"
17 
18 const char* OPTIONS = "hdf:b:v";
19 
printHelp(char * progname)20 static void printHelp(char* progname) {
21     printf("Usage:   %s  <input> <output>\n"
22            "      -f <flux-column-name>  (default: FLUX) \n"
23            "      -b <background-column-name>  (default: BACKGROUND)\n"
24            "      [-d]: sort in descending order (default is ascending)\n"
25            "      [-v]: add verboseness.\n"
26            "\n", progname);
27 }
28 
29 
main(int argc,char ** args)30 int main(int argc, char** args) {
31     int argchar;
32     char* infn = NULL;
33     char* outfn = NULL;
34     char* progname = args[0];
35     char* fluxcol = NULL;
36     char* backcol = NULL;
37     anbool ascending = TRUE;
38     int loglvl = LOG_MSG;
39 
40     while ((argchar = getopt (argc, args, OPTIONS)) != -1)
41         switch (argchar) {
42         case 'f':
43             fluxcol = optarg;
44             break;
45         case 'b':
46             backcol = optarg;
47             break;
48         case 'd':
49             ascending = FALSE;
50             break;
51         case 'v':
52             loglvl++;
53             break;
54         case '?':
55         case 'h':
56             printHelp(progname);
57             return 0;
58         default:
59             return -1;
60         }
61     log_init(loglvl);
62 
63     if (optind != argc-2) {
64         printHelp(progname);
65         exit(-1);
66     }
67 
68     infn = args[optind];
69     outfn = args[optind+1];
70 
71     fits_use_error_system();
72 
73     if (resort_xylist(infn, outfn, fluxcol, backcol, ascending)) {
74         ERROR("Failed to re-sorting xylist by FLUX and BACKGROUND");
75         exit(-1);
76     }
77 
78     return 0;
79 }
80