File: checkquads.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 (133 lines) | stat: -rw-r--r-- 3,584 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
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
/*
 # This file is part of the Astrometry.net suite.
 # Licensed under a 3-clause BSD style license - see LICENSE
 */

/*
 Checks the consistency of "quad" and "qidx" files.
 */

#include <string.h>

#include "starutil.h"
#include "quadfile.h"
#include "qidxfile.h"
#include "bl.h"
#include "fitsioutils.h"

#define OPTIONS "hf:"
const char HelpString[] =
    "quadidx -f fname\n";


int main(int argc, char *argv[]) {
    int argidx, argchar;
    char *qidxfname = NULL;
    char *quadfname = NULL;
    quadfile* quad;
    qidxfile* qidx;
    int q, s;
    int dimquads;
	
    while ((argchar = getopt (argc, argv, OPTIONS)) != -1)
        switch (argchar) {
        case 'f':
            qidxfname = mk_qidxfn(optarg);
            quadfname = mk_quadfn(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);
    }

    quad = quadfile_open(quadfname, 0);
    if (!quad) {
        fprintf(stderr, "Couldn't open quads file %s.\n", quadfname);
        exit(-1);
    }

    qidx = qidxfile_open(qidxfname, 0);
    if (!qidx) {
        fprintf(stderr, "Couldn't open qidx file %s.\n", qidxfname);
        exit(-1);
    }

    if (quad->numquads != qidx->numquads) {
        fprintf(stderr, "Number of quads does not agree: %i vs %i\n",
                quad->numquads, qidx->numquads);
        exit(-1);
    }

    dimquads = quadfile_dimquads(quad);

    printf("Checking stars...\n");
    for (s=0; s<qidx->numstars; s++) {
        uint32_t* quads;
        int nquads;
        int j;
        qidxfile_get_quads(qidx, s, &quads, &nquads);
        for (j=0; j<nquads; j++) {
            int star[dimquads];
            int k, n;
            quadfile_get_stars(quad, quads[j], star);
            n = 0;
            for (k=0; k<dimquads; k++) {
                if (star[k] == s)
                    n++;
            }
            if (n != 1) {
                fprintf(stderr, "Star %i, quad %i: found %i instances of the quad in the qidx (not 1)\n",
                        s, quads[j], n);
                fprintf(stderr, "  found: ");
                for (k=0; k<dimquads; k++) {
                    fprintf(stderr, "%i ", star[k]);
                }
                fprintf(stderr, "\n");
            }
        }
    }

    printf("Checking quads...\n");
    for (q=0; q<quad->numquads; q++) {
        int star[dimquads];
        uint32_t* quads;
        int nquads;
        int j;
        quadfile_get_stars(quad, q, star);
        for (j=0; j<dimquads; j++) {
            int k;
            int n;
            qidxfile_get_quads(qidx, star[j], &quads, &nquads);
            n = 0;
            for (k=0; k<nquads; k++) {
                if (quads[k] == q)
                    n++;
            }
            if (n != 1) {
                fprintf(stderr, "Quad %i, star %i: found %i instances of the quad in the qidx (not 1)\n",
                        q, star[j], n);
                fprintf(stderr, "  found: ");
                for (k=0; k<nquads; k++) {
                    fprintf(stderr, "%i ", quads[k]);
                }
                fprintf(stderr, "\n");
            }
        }
    }

    quadfile_close(quad);
    qidxfile_close(qidx);

    return 0;
}