1 /*
2  # This file is part of the Astrometry.net suite.
3  # Licensed under a 3-clause BSD style license - see LICENSE
4  */
5 #include <stdio.h>
6 #include <sys/types.h>
7 #include <sys/mman.h>
8 
9 #include "usnob-fits.h"
10 #include "usnob.h"
11 #include "starutil.h"
12 #include "healpix.h"
13 #include "boilerplate.h"
14 #include "assert.h"
15 #include "an-endian.h"
16 
17 #define OPTIONS "h"
18 
print_help(char * progname)19 void print_help(char* progname) {
20     BOILERPLATE_HELP_HEADER(stdout);
21     printf("\nUsage:\n"
22            "  %s\n"
23            , progname);
24     //-H <healpix> -N <nside>
25 }
26 
27 
28 
main(int argc,char ** args)29 int main(int argc, char** args) {
30     int c;
31     int i;
32     int fnum = 0, fnum1 = 0, d = 10;
33 
34 
35     while ((c = getopt(argc, args, OPTIONS)) != -1) {
36         switch (c) {
37         case '?':
38         case 'h':
39             print_help(args[0]);
40             exit(0);
41         }
42     }
43 
44 
45     assert(d<180);
46     // checks the first d degrees of the sky (must be less than 180)
47     while (fnum1<d){
48         FILE *fid;
49         unsigned char* map;
50         size_t map_size;
51         char fname[40];
52         char *fn = "/w/284/stars284/USNOB10/%03d/b%03d%d.cat";
53         sprintf(fname, fn, fnum1, fnum1,fnum);
54         printf("%s\n", fname);
55 
56         // try to open the file.
57         fid = fopen(fname, "r");
58         if (fid == NULL){
59             printf("crap\n");
60             return 1;
61         }
62 
63 
64         //move to end of file
65         if (fseeko(fid, 0, SEEK_END)) {
66             printf("Couldn't seek to end of input file: \n");
67             exit(-1);
68         }
69         //get file size
70         map_size = ftello(fid);
71         //move back to beginning of file
72         fseeko(fid, 0, SEEK_SET);
73         //read map into memory
74         map = mmap(NULL, map_size, PROT_READ, MAP_SHARED, fileno(fid), 0);
75 
76 
77         printf("mapsize: %d", map_size/USNOB_RECORD_SIZE);
78 
79         //for each entry, prase entry, alert when diffraction_spike flag is set
80         for (i=0; i<map_size; i+=USNOB_RECORD_SIZE) {
81             usnob_entry entry;
82             if (i && (i % 10000000 * USNOB_RECORD_SIZE == 0)) {
83                 printf("o");
84                 fflush(stdout);
85             }
86             if (usnob_parse_entry(map + i, &entry)) {
87                 printf("Failed to parse USNOB entry: offset %i.\n", i);
88                 exit(-1);
89             }else{
90                 //printf(".");
91             }
92             if (entry.diffraction_spike){
93                 uint ival;
94                 printf("\ndiffraction spike, entry %d\n", i/USNOB_RECORD_SIZE);
95                 // print bytes 12-15 in base 10 of USNOB entry prior to spike
96                 ival = u32_letoh(*((uint*)(map+i+ 12 - USNOB_RECORD_SIZE)));
97                 printf("entry prior spike: %010d\n", ival);
98                 // print bytes 12-15 in base 10 of USNOB entry with spike
99                 ival = u32_letoh(*((uint*)(map+i+ 12)));
100                 printf("diffraction spike: %010d\n", ival);
101                 // print bytes 12-15 in base 10 of USNOB entry after spike
102                 ival = u32_letoh(*((uint*)(map+i+ 12 + USNOB_RECORD_SIZE)));
103                 printf("entry after spike: %010d\n", ival);
104             }
105 
106 
107         }
108         printf("\n");
109         fclose(fid);
110 
111         // increment filenumber (degree counter)
112         if (fnum%10 == 9){
113             fnum1++;
114             fnum = 0;
115         } else {
116             fnum++;
117         }
118     }
119     return 0;
120 }
121 
122 
123