3
* Justin Pryzby <justinpryzby@users.sf.net>
4
* Mon Dec 15 17:51:29 EST 2003
6
* Convert an image from an SBIG ST-4 astronomical CCD camera to pgm.
7
* See [http://www.sbig.com/]. Use sbigtopgm for all other SBIG
10
* Copyright (C) 2003 by Justin Pryzby <justinpryzby@users.sf.net>
12
* Permission to use, copy, modify, and distribute this software and its
13
* documentation for any purpose and without fee is hereby granted, provided
14
* that the above copyright notice appear in all copies and that both that
15
* copyright notice and this permission notice appear in supporting
16
* documentation. This software is provided "as is" without express or
23
/* 192x166, a 192*165 image plus a "line" of metadata. */
29
int main(int argc, char **argv);
30
void read_foot(FILE *fp);
31
void trim_comment0(char *comment);
32
void trim_comment1(char *comment);
34
int main(int argc, char **argv)
40
pgm_init(&argc, argv);
42
if (argc>2) pm_usage("[st4file]");
43
else if (argc==1) fp=pm_openr_seekable("-");
44
else fp=pm_openr_seekable(argv[1]);
46
fseek(fp, 0, SEEK_END);
47
if (ftell(fp)!=FSIZE) pm_error("Incorrect file size.");
49
pgm_writepgminit(stdout, COLS, ROWS, MAXVAL, 0);
50
grayrow = pgm_allocrow(COLS);
52
fseek(fp, 31680, SEEK_SET);
56
* Okay, the file is of the correct size, and read_foot has
57
* confirmed the constant-position, constant value byte. We
58
* accept the file as valid.
60
fseek(fp, 0, SEEK_SET);
63
for (row=0; row<ROWS; row++) {
64
for (col=0; col<COLS; col++) {
65
grayrow[col]=fgetc(fp);
68
pgm_writepgmrow(stdout, grayrow, COLS, MAXVAL, 0);
81
* Read the footer, which is stored in the following form.
83
* 2-79: Freeform comment.
84
* 80-89: Exposure time in 1/100s of a second.
85
* 90-99: Focal length in inches.
86
* 100-109: Aperture area in square inches.
87
* 110-119: Calibration factor.
90
void read_foot(FILE *fp)
94
fread(buf, 192, 1, fp);
97
* The only constant byte at a known constant offset, and thus
98
* serves as one of our two checks of the file type. (The other
99
* check being the file size).
101
if (buf[0]!='v') pm_error("Invalid file format.");
103
memmove(buf, buf+1, 78);
106
fprintf(stderr, "Comment: %80s\n", buf);
108
memcpy(buf, buf+79, 10);
111
fprintf(stderr, "Exposure time (1/100 s): %80s\n", buf);
113
memcpy(buf, buf+89, 10);
115
fprintf(stderr, "Focal length (in): %80s\n", buf);
117
memcpy(buf, buf+99, 10);
119
fprintf(stderr, "Aperture area (sq in): %80s\n", buf);
121
memcpy(buf, buf+109, 10);
123
fprintf(stderr, "Calibration factor: %80s\n", buf);
127
* Trim up to 79 trailing spaces from the given string.
129
void trim_comment0(char *comment)
131
for ( ; comment[strlen(comment)-1]==' '; comment[strlen(comment)-1]=0);
135
* Trim up to 79 leading spaces from the given string.
137
void trim_comment1(char *comment)
139
for ( ; 32==*comment; memmove(comment, comment+1, strlen(comment)));