File: quadsperstar.c

package info (click to toggle)
astrometry.net 0.93%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,372 kB
  • sloc: ansic: 163,192; python: 18,357; makefile: 1,522; sh: 138; cpp: 78; pascal: 67; awk: 56; perl: 9
file content (99 lines) | stat: -rw-r--r-- 2,400 bytes parent folder | download | duplicates (4)
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
/*
 # This file is part of the Astrometry.net suite.
 # Licensed under a 3-clause BSD style license - see LICENSE
 */

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <libgen.h>

#include "ioutils.h"
#include "qidxfile.h"

#define OPTIONS "h"


void print_help(char* progname)
{
    fprintf(stderr, "Usage: %s\n"
            "   [-h]: help\n"
            "   <base-name> [<base-name> ...]\n\n",
            progname);
}
static Inline void ensure_hist_size(unsigned int** hist, unsigned int* size, unsigned int newsize) {
    if (newsize <= *size)
        return;
    *hist = realloc(*hist, newsize*sizeof(unsigned int));
    memset((*hist) + (*size), 0, (newsize - *size) * sizeof(unsigned int));
    *size = newsize;
}

int main(int argc, char** args) {
    int argchar;
    char* basefn;
    qidxfile* qf;
    unsigned int* sumhist = NULL;
    unsigned int Nsumhist = 0;
    unsigned int i;

    while ((argchar = getopt (argc, args, OPTIONS)) != -1)
        switch (argchar) {
        case 'h':
            print_help(args[0]);
            exit(0);
        }

    if (optind == argc) {
        print_help(args[0]);
        exit(-1);
    }

    for (; optind<argc; optind++) {
        uint32_t* quads;
        int nquads;
        unsigned int* hist = NULL;
        unsigned int Nhist = 0;
        char* fn;

        basefn = args[optind];
        asprintf_safe(&fn, "%s.qidx.fits", basefn);
        fprintf(stderr, "Reading qidx from %s...\n", fn);
        fflush(stderr);
        qf = qidxfile_open(fn);
        if (!qf) {
            fprintf(stderr, "Couldn't read qidx from %s.\n", fn);
            exit(-1);
        }

        fprintf(stderr, "Reading %i stars from %s...\n", qf->numstars, fn);
        fflush(stderr);
        free(fn);

        for (i=0; i<qf->numstars; i++) {
            qidxfile_get_quads(qf, i, &quads, &nquads);
            ensure_hist_size(&hist, &Nhist, nquads+1);
            hist[nquads]++;
        }

        qidxfile_close(qf);

        printf("%s = [ ", basename(basefn));
        for (i=0; i<Nhist; i++)
            printf("%i, ", hist[i]);
        printf("];\n");

        ensure_hist_size(&sumhist, &Nsumhist, Nhist);
        for (i=0; i<Nhist; i++)
            sumhist[i] += hist[i];

        free(hist);
    }

    printf("sum = [ ");
    for (i=0; i<Nsumhist; i++)
        printf("%i, ", sumhist[i]);
    printf("];\n");

    return 0;
}