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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
# This file is part of the Astrometry.net suite.
# Licensed under a 3-clause BSD style license - see LICENSE
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "os-features.h"
#include "uniformize-catalog.h"
#include "fitstable.h"
#include "boilerplate.h"
#include "errors.h"
#include "log.h"
#include "fitsioutils.h"
#include "mathutil.h"
const char* OPTIONS = "hvH:s:n:N:d:R:D:S:fm:";
void printHelp(char* progname) {
BOILERPLATE_HELP_HEADER(stdout);
printf("\nUsage: %s [options] <input-FITS-catalog> <output-FITS-catalog>\n"
" [-R <ra-column-name>]: name of RA in FITS table (default RA)\n"
" [-D <dec-column-name>]: name of DEC in FITS table (default DEC)\n"
" [-S <sort-column-name>]: column on which to sort\n"
" [-f]: sort in descending order (eg, for FLUX); default ascending (eg, for MAG)\n"
" [-H <big healpix>]; default is all-sky\n"
" [-s <big healpix Nside>]; default is 1\n"
" [-m <margin>]: add a margin of <margin> healpixels; default 0\n"
" [-n <sweeps>] (ie, number of stars per fine healpix grid cell); default 10\n"
" [-N <nside>]: fine healpixelization grid; default 100.\n"
" [-d <dedup-radius>]: deduplication radius in arcseconds; default no deduplication\n"
" [-v]: +verbose\n"
"\n", progname);
}
int main(int argc, char *argv[]) {
int argchar;
char* progname = argv[0];
char* infn = NULL;
char* outfn = NULL;
char* racol = NULL;
char* deccol = NULL;
char* sortcol = NULL;
anbool sortasc = TRUE;
int loglvl = LOG_MSG;
int bighp = -1;
int bignside = 1;
int sweeps = 10;
int Nside = 100;
double dedup = 0.0;
int margin = 0;
double mincut = -LARGE_VAL;
fitstable_t* intable;
fitstable_t* outtable;
char** myargs;
int nmyargs;
while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
switch (argchar) {
case 'R':
racol = optarg;
break;
case 'D':
deccol = optarg;
break;
case 'S':
sortcol = optarg;
break;
case 'f':
sortasc = FALSE;
break;
case 'H':
bighp = atoi(optarg);
break;
case 's':
bignside = atoi(optarg);
break;
case 'n':
sweeps = atoi(optarg);
break;
case 'N':
Nside = atoi(optarg);
break;
case 'd':
dedup = atof(optarg);
break;
case 'm':
margin = atoi(optarg);
break;
case 'v':
loglvl++;
break;
case '?':
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
case 'h':
printHelp(progname);
return 0;
default:
return -1;
}
nmyargs = argc - optind;
myargs = argv + optind;
if (nmyargs != 2) {
printHelp(progname);
exit(-1);
}
log_init(loglvl);
fits_use_error_system();
infn = myargs[0];
outfn = myargs[1];
logmsg("Reading catalog from %s, writing to %s\n", infn, outfn);
logmsg("Reading %s...\n", infn);
intable = fitstable_open(infn);
if (!intable) {
ERROR("Couldn't read catalog %s", infn);
exit(-1);
}
logmsg("Got %i stars\n", fitstable_nrows(intable));
outtable = fitstable_open_for_writing(outfn);
if (!outtable) {
ERROR("Failed to open output table %s", outfn);
exit(-1);
}
/*
if (fitstable_write_primary_header(outtable)) {
ERROR("Failed to write primary header");
exit(-1);
}
*/
if (uniformize_catalog(intable, outtable, racol, deccol,
sortcol, sortasc, mincut,
bighp, bignside, margin,
Nside, dedup, sweeps,
argv, argc)) {
exit(-1);
}
if (fitstable_fix_primary_header(outtable) ||
fitstable_close(outtable)) {
ERROR("Failed to close output table");
exit(-1);
}
fitstable_close(intable);
return 0;
}
|