forked from dstndstn/astrometry.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintsolved.c
139 lines (121 loc) · 3.44 KB
/
printsolved.c
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
/*
# This file is part of the Astrometry.net suite.
# Licensed under a 3-clause BSD style license - see LICENSE
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "starutil.h"
#include "mathutil.h"
#include "boilerplate.h"
#include "bl.h"
#include "solvedfile.h"
const char* OPTIONS = "hum:SM:jwps";
void printHelp(char* progname) {
BOILERPLATE_HELP_HEADER(stderr);
fprintf(stderr, "\nUsage: %s <solved-file> ...\n"
" [-s]: just summary info, no field numbers\n"
" [-p]: print percent solved\n"
" [-u]: print UNsolved fields\n"
" [-j]: just the field numbers, no headers, etc.\n"
" [-m <max-field>]: for unsolved mode, max field number.\n"
" [-w]: format for the wiki.\n"
" [-M <variable-name>]: format for Matlab.\n"
"\n", progname);
}
int main(int argc, char** args) {
int argchar;
char* progname = args[0];
char** inputfiles = NULL;
int ninputfiles = 0;
int i;
anbool unsolved = FALSE;
int maxfield = 0;
anbool wiki = FALSE;
char* matlab = NULL;
anbool justnums = FALSE;
anbool percent = FALSE;
anbool printinfo = FALSE;
anbool printnums = FALSE;
anbool summary = FALSE;
int ncounted = 0;
int ntotal = 0;
while ((argchar = getopt (argc, args, OPTIONS)) != -1) {
switch (argchar) {
case 's':
summary = TRUE;
break;
case 'p':
percent = TRUE;
break;
case 'j':
justnums = TRUE;
break;
case 'M':
matlab = optarg;
break;
case 'w':
wiki = TRUE;
break;
case 'u':
unsolved = TRUE;
break;
case 'm':
maxfield = atoi(optarg);
break;
case 'h':
default:
printHelp(progname);
exit(-1);
}
}
if (optind < argc) {
ninputfiles = argc - optind;
inputfiles = args + optind;
} else {
printHelp(progname);
exit(-1);
}
printinfo = (!matlab && !justnums);
printnums = !summary;
if (matlab)
printf("%s=[", matlab);
for (i=0; i<ninputfiles; i++) {
int j;
il* list;
if (printinfo)
printf("File %s\n", inputfiles[i]);
if (wiki)
printf("|| %i || ", i+1);
if (unsolved)
list = solvedfile_getall(inputfiles[i], 1, maxfield, 0);
else
list = solvedfile_getall_solved(inputfiles[i], 1, maxfield, 0);
if (percent) {
int nt = solvedfile_getsize(inputfiles[i]);
int nc = il_size(list);
printf("%s: %i/%i (%f %%) %ssolved\n", inputfiles[i], nc, nt, (100.0 * nc / (double)nt), unsolved ? "un":"");
ncounted += nc;
ntotal += nt;
}
if (!list) {
fprintf(stderr, "Failed to get list of fields.\n");
exit(-1);
}
if (printnums) {
for (j=0; j<il_size(list); j++)
printf("%i ", il_get(list, j));
}
il_free(list);
if (wiki)
printf(" ||");
printf("\n");
}
if (matlab)
printf("];\n");
if (percent) {
printf("Total: %i/%i (%f %%) %ssolved\n", ncounted, ntotal, (100.0 * ncounted / (double)ntotal), unsolved ? "un":"");
}
return 0;
}