1 /*
2  # This file is part of the Astrometry.net suite.
3  # Licensed under a 3-clause BSD style license - see LICENSE
4  */
5 
6 /*
7  Reads raw NOMAD data files and prints them out in text format to allow
8  verification of our FITS versions.
9  */
10 
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <sys/types.h>
16 #include <sys/mman.h>
17 #include <endian.h>
18 #include <netinet/in.h>
19 #include <byteswap.h>
20 
21 #include "nomad.h"
22 
main(int argc,char ** args)23 int main(int argc, char** args) {
24     int j;
25 
26     printf("ra dec sigma_racosdec sigma_dec mu_racosdec mu_dec "
27            "sigma_mu_racosdec sigma_mu_dec epoch_ra epoch_dec "
28            "mag_B mag_V mag_R mag_J mag_H mag_K usnob_id twomass_id "
29            "yb6_id ucac2_id tycho2_id astrometry_src blue_src visual_src "
30            "red_src usnob_fail twomass_fail tycho_astrometry "
31            "alt_radec alt_2mass alt_ucac alt_tycho blue_o red_e "
32            "twomass_only hipp_astrometry diffraction confusion "
33            "bright_confusion bright_artifact standard external\n");
34 
35     for (j=1; j<argc; j++) {
36         char* infn;
37         FILE* fid;
38         unsigned char* map;
39         size_t map_size;
40         int i;
41 
42         infn = args[j];
43         fprintf(stderr, "Reading file %s...\n", infn);
44         fid = fopen(infn, "rb");
45         if (!fid) {
46             fprintf(stderr, "Couldn't open input file %s: %s\n", infn, strerror(errno));
47             exit(-1);
48         }
49         if (fseeko(fid, 0, SEEK_END)) {
50             fprintf(stderr, "Couldn't seek to end of input file %s: %s\n", infn, strerror(errno));
51             exit(-1);
52         }
53         map_size = ftello(fid);
54         fseeko(fid, 0, SEEK_SET);
55         map = mmap(NULL, map_size, PROT_READ, MAP_SHARED, fileno(fid), 0);
56         if (map == MAP_FAILED) {
57             fprintf(stderr, "Couldn't mmap input file %s: %s\n", infn, strerror(errno));
58             exit(-1);
59         }
60         fclose(fid);
61         if (map_size % NOMAD_RECORD_SIZE) {
62             fprintf(stderr, "Warning, input file %s has size %u which is not divisible into %i-byte records.\n",
63                     infn, (unsigned int)map_size, NOMAD_RECORD_SIZE);
64         }
65 
66         for (i=0; i<map_size; i+=NOMAD_RECORD_SIZE) {
67             nomad_entry e;
68             if (nomad_parse_entry(&e, map + i)) {
69                 fprintf(stderr, "Failed to parse NOMAD entry: offset %i in file %s.\n",
70                         i, infn);
71                 exit(-1);
72             }
73 
74             printf("%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ",
75                    e.ra, e.dec, e.sigma_racosdec, e.sigma_dec,
76                    e.mu_racosdec, e.mu_dec, e.sigma_mu_racosdec,
77                    e.sigma_mu_dec, e.epoch_ra, e.epoch_dec, e.mag_B,
78                    e.mag_V, e.mag_R, e.mag_J, e.mag_H, e.mag_K);
79             printf("%u %u %u %u %u %i %i %i %i ",
80                    e.usnob_id, e.twomass_id, e.yb6_id, e.ucac2_id,
81                    e.tycho2_id, (int)e.astrometry_src, (int)e.blue_src,
82                    (int)e.visual_src, (int)e.red_src);
83             printf("%i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i\n",
84                    (int)e.usnob_fail, (int)e.twomass_fail,
85                    (int)e.tycho_astrometry, (int)e.alt_radec,
86                    (int)e.alt_2mass, (int)e.alt_ucac, (int)e.alt_tycho,
87                    (int)e.blue_o, (int)e.red_e, (int)e.twomass_only,
88                    (int)e.hipp_astrometry, (int)e.diffraction,
89                    (int)e.confusion, (int)e.bright_confusion,
90                    (int)e.bright_artifact, (int)e.standard,
91                    (int)e.external);
92         }
93 
94         munmap(map, map_size);
95     }
96 
97     return 0;
98 }
99