-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfitsread.c
63 lines (46 loc) · 1.27 KB
/
fitsread.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
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fitsio.h>
int main(int argc, char const *argv[])
{
if (argc != 2) {
fprintf(stderr, "%s: usage: %s FITS_FILENAME\n", argv[0], argv[0]);
return 1;
}
fitsfile *fptr;
int status = 0;
fits_open_image(&fptr, argv[1], READONLY, &status);
int bitpix, naxis;
long naxes[2];
fits_get_img_param(fptr, sizeof(naxes) / sizeof(long), &bitpix, &naxis, naxes, &status);
if (status)
goto fail;
if ((bitpix != FLOAT_IMG) || (naxis != 2) || (naxes[0] != 2)) {
fprintf(stderr, "%s: %s: unexpected image parameters\n", argv[0], argv[1]);
goto fail;
}
float buff[8192];
long frmpos = 0;
long frmlen = naxes[1];
const long frmbuflen = sizeof(buff) / (sizeof(float) * 2);
while (frmpos < frmlen) {
long fpixel[2] = {1, frmpos + 1};
long nframes = frmlen - frmpos;
if (nframes > frmbuflen)
nframes = frmbuflen;
fits_read_pix(fptr, TFLOAT, fpixel, nframes * 2, NULL, buff, NULL, &status);
if (status)
goto fail;
if (fwrite(buff, sizeof(float) * 2, nframes, stdout) != nframes) {
fprintf(stderr, "%s: fwrite: %s\n", argv[0], strerror(errno));
return errno;
}
frmpos += nframes;
}
fail:
fits_close_file(fptr, &status);
if (status)
fits_report_error(stderr, status);
return status;
}