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

/*-------------------------------------------------------------
 * This file is used to make a table with one column containing
 * whether the star was flagged as a diffraction spike by our
 * algorithm (ie. erroneous).
 * ------------------------------------------------------------
 */

#include <stdio.h>
#include "fitsioutils.h"

int create_table(FILE* inFid, FILE* outFid){
    int c, nEntries = 0;
    int x = 0;
    qfits_table* tbl;
    qfits_header* tbl_hdr;

    // create table header
    qfits_header* hdr = qfits_table_prim_header_default();
    qfits_header_dump(hdr, outFid);

    // create table
    tbl = qfits_table_new("spikes",QFITS_BINTABLE,1,1,0);
    // add column
    fits_add_column(tbl, 0,TFITS_BIN_TYPE_X, 1, " ", "diffraction spike"); 
	
    tbl_hdr = qfits_table_ext_header_default(tbl); 
    qfits_header_dump(tbl_hdr, outFid);

    // fill in content of table
    while((c = fgetc(inFid)) != EOF){
        // show progress
        if (x==100000){
            printf(".");
            x=0;
        }else{
            x++;
        }
        //printf("%c", c);
        fits_write_data_X(outFid,((unsigned char)c));
        nEntries++;
    }
    fits_pad_file(outFid);
    // fix the headers
    tbl->nr = nEntries;
    tbl_hdr = qfits_table_ext_header_default(tbl);
    fix_headers(outFid, hdr, tbl_hdr);
	
    qfits_header_destroy(hdr);
    qfits_header_destroy(tbl_hdr);
    qfits_table_close(tbl);
    return 0;
}

int fix_headers(FILE* fId, qfits_header* hdr, qfits_header* tbl_hdr){
    char val[32];
    off_t offset;
    offset = ftello(fId);
    fseeko(fId, 0, SEEK_SET);

    // write header
    qfits_header_dump(hdr, fId);

    // write table header again
    qfits_header_dump(tbl_hdr, fId);

    // point to the end of the file again
    fseek(fId, offset, SEEK_SET);
    return 0;
}

int main(int argc, char* argv[]){
    if (argc==3){
        FILE* inFid,outFid;
	   
        printf("processing %s ", argv[1]);

        // open files for reading/writing
        inFid = fopen(argv[1], "r");
        outFid = fopen(argv[2], "w");

        // create table and write to output file
        create_table(inFid, outFid);

        fclose(inFid);
        fclose(outFid);
        printf(" finished \n");
    } else {
        printf("Usage: spike_join inputFile outputFile\n");
    }
    return 1;
}