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
|
/*
# This file is part of the Astrometry.net suite.
# Licensed under a 3-clause BSD style license - see LICENSE
*/
#include "starutil.h"
#include "catalog.h"
#define OPTIONS "hn:f:r:R:d:D:S:"
const char HelpString[] =
"randcat -f fname -n numstars [-r/R RAmin/max] [-d/D DECmin/max]\n"
" -r -R -d -D set ra and dec limits in radians\n";
int RANDSEED = 999;
int main(int argc, char *argv[])
{
int argidx, argchar;
int numstars = 10;
char *fname = NULL;
double ramin = DEFAULT_RAMIN, ramax = DEFAULT_RAMAX;
double decmin = DEFAULT_DECMIN, decmax = DEFAULT_DECMAX;
int i;
catalog* cat;
if (argc <= 4) {
fprintf(stderr, HelpString);
return (OPT_ERR);
}
while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
switch (argchar) {
case 'S':
RANDSEED = atoi(optarg);
break;
case 'n':
numstars = strtoul(optarg, NULL, 0);
break;
case 'r':
ramin = strtod(optarg, NULL);
break;
case 'R':
ramax = strtod(optarg, NULL);
break;
case 'd':
decmin = strtod(optarg, NULL);
break;
case 'D':
decmax = strtod(optarg, NULL);
break;
case 'f':
fname = mk_catfn(optarg);
break;
case '?':
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
case 'h':
fprintf(stderr, HelpString);
return (HELP_ERR);
default:
return (OPT_ERR);
}
if (optind < argc) {
for (argidx = optind; argidx < argc; argidx++)
fprintf (stderr, "Non-option argument %s\n", argv[argidx]);
fprintf(stderr, HelpString);
return (OPT_ERR);
}
srand(RANDSEED);
fprintf(stderr, "randcat: Making %u random stars\n", numstars);
fprintf(stderr, "[RANDSEED=%d]\n", RANDSEED);
if (ramin > DEFAULT_RAMIN || ramax < DEFAULT_RAMAX ||
decmin > DEFAULT_DECMIN || decmax < DEFAULT_DECMAX)
fprintf(stderr, " using limits %f<=RA<=%f ; %f<=DEC<=%f deg.\n",
rad2deg(ramin), rad2deg(ramax), rad2deg(decmin), rad2deg(decmax));
cat = catalog_open_for_writing(fname);
for (i=0; i <numstars; i++) {
double star[DIM_STARS];
make_rand_star(star, ramin, ramax, decmin, decmax);
if (catalog_write_star(cat, star)) {
fprintf(stderr, "Failed to write star %i.\n", i);
exit(-1);
}
}
//catalog_compute_radecminmax(&cat);
if (catalog_close(cat)) {
fprintf(stderr, "Failed to write catalog.\n");
exit(-1);
}
return 0;
}
|