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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
#include <stdlib.h>
#include <string.h>
#include "fitsio2.h"
/*--------------------------------------------------------------------------*/
int ffgiwcs(fitsfile *fptr, /* I - FITS file pointer */
char **header, /* O - pointer to the WCS related keywords */
int *status) /* IO - error status */
/*
int fits_get_image_wcs_keys
return a string containing all the image WCS header keywords.
This string is then used as input to the wcsinit WCSlib routine.
*/
{
int hdutype;
if (*status > 0)
return(*status);
fits_get_hdu_type(fptr, &hdutype, status);
if (hdutype != IMAGE_HDU)
{
ffpmsg(
"Error in ffgiwcs. This HDU is not an image. Can't read WCS keywords");
return(*status = NOT_IMAGE);
}
/* read header keywords into a long string of chars */
if (ffh2st(fptr, header, status) > 0)
{
ffpmsg("error creating string of image WCS keywords (ffgiwcs)");
return(*status);
}
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffgtwcs(fitsfile *fptr, /* I - FITS file pointer */
int xcol, /* I - column number for the X column */
int ycol, /* I - column number for the Y column */
char **header, /* O - string of all the WCS keywords */
int *status) /* IO - error status */
/*
int fits_get_table_wcs_keys
Return string containing all the WCS keywords appropriate for the
pair of X and Y columns containing the coordinate
of each event in an event list table. This string may then be passed
to Doug Mink's WCS library wcsinit routine, to create and initialize the
WCS structure. The calling routine must free the header character string
when it is no longer needed.
*/
{
int hdutype, ncols, tstatus, length;
int naxis1 = 1, naxis2 = 1;
long tlmin, tlmax;
char keyname[FLEN_KEYWORD];
char valstring[FLEN_VALUE];
char comm[2];
char *cptr;
/* construct a string of 80 blanks, for adding fill to the keywords */
/* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */
char blanks[] = " ";
if (*status > 0)
return(*status);
fits_get_hdu_type(fptr, &hdutype, status);
if (hdutype == IMAGE_HDU)
{
ffpmsg("Can't read table WSC keywords. This HDU is not a table");
return(*status = NOT_TABLE);
}
fits_get_num_cols(fptr, &ncols, status);
if (xcol < 1 || xcol > ncols)
{
ffpmsg("illegal X axis column number in fftwcs");
return(*status = BAD_COL_NUM);
}
if (ycol < 1 || ycol > ncols)
{
ffpmsg("illegal Y axis column number in fftwcs");
return(*status = BAD_COL_NUM);
}
/* allocate character string for all the WCS keywords */
*header = calloc(1, 2401); /* room for up to 30 keywords */
if (*header == 0)
{
ffpmsg("error allocating memory for WCS header keywords (fftwcs)");
return(*status = MEMORY_ALLOCATION);
}
cptr = *header;
comm[0] = '\0';
tstatus = 0;
ffkeyn("TLMIN",xcol,keyname,status);
ffgkyj(fptr,keyname, &tlmin,NULL,&tstatus);
if (!tstatus)
{
ffkeyn("TLMAX",xcol,keyname,status);
ffgkyj(fptr,keyname, &tlmax,NULL,&tstatus);
}
if (!tstatus)
{
naxis1 = tlmax - tlmin + 1;
}
tstatus = 0;
ffkeyn("TLMIN",ycol,keyname,status);
ffgkyj(fptr,keyname, &tlmin,NULL,&tstatus);
if (!tstatus)
{
ffkeyn("TLMAX",ycol,keyname,status);
ffgkyj(fptr,keyname, &tlmax,NULL,&tstatus);
}
if (!tstatus)
{
naxis2 = tlmax - tlmin + 1;
}
/* 123456789012345678901234567890 */
strcat(cptr, "NAXIS = 2");
strncat(cptr, blanks, 50);
cptr += 80;
ffi2c(naxis1, valstring, status); /* convert to formatted string */
ffmkky("NAXIS1", valstring, comm, cptr, status); /* construct the keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
strcpy(keyname, "NAXIS2");
ffi2c(naxis2, valstring, status); /* convert to formatted string */
ffmkky(keyname, valstring, comm, cptr, status); /* construct the keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
/* read the required header keywords (use defaults if not found) */
/* CTYPE1 keyword */
tstatus = 0;
ffkeyn("TCTYP",xcol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) )
valstring[0] = '\0';
ffmkky("CTYPE1", valstring, comm, cptr, status); /* construct the keyword*/
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
/* CTYPE2 keyword */
tstatus = 0;
ffkeyn("TCTYP",ycol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) )
valstring[0] = '\0';
ffmkky("CTYPE2", valstring, comm, cptr, status); /* construct the keyword*/
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
/* CRPIX1 keyword */
tstatus = 0;
ffkeyn("TCRPX",xcol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) )
strcpy(valstring, "1");
ffmkky("CRPIX1", valstring, comm, cptr, status); /* construct the keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
/* CRPIX2 keyword */
tstatus = 0;
ffkeyn("TCRPX",ycol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) )
strcpy(valstring, "1");
ffmkky("CRPIX2", valstring, comm, cptr, status); /* construct the keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
/* CRVAL1 keyword */
tstatus = 0;
ffkeyn("TCRVL",xcol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) )
strcpy(valstring, "1");
ffmkky("CRVAL1", valstring, comm, cptr, status); /* construct the keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
/* CRVAL2 keyword */
tstatus = 0;
ffkeyn("TCRVL",ycol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) )
strcpy(valstring, "1");
ffmkky("CRVAL2", valstring, comm, cptr, status); /* construct the keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
/* CDELT1 keyword */
tstatus = 0;
ffkeyn("TCDLT",xcol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) )
strcpy(valstring, "1");
ffmkky("CDELT1", valstring, comm, cptr, status); /* construct the keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
/* CDELT2 keyword */
tstatus = 0;
ffkeyn("TCDLT",ycol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) )
strcpy(valstring, "1");
ffmkky("CDELT2", valstring, comm, cptr, status); /* construct the keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
/* the following keywords may not exist */
/* CROTA2 keyword */
tstatus = 0;
ffkeyn("TCROT",ycol,keyname,status);
if (ffgkey(fptr, keyname, valstring, NULL, &tstatus) == 0 )
{
ffmkky("CROTA2", valstring, comm, cptr, status); /* construct keyword*/
strncat(cptr, blanks, 50); /* pad with blanks */
cptr += 80;
}
/* EPOCH keyword */
tstatus = 0;
if (ffgkey(fptr, "EPOCH", valstring, NULL, &tstatus) == 0 )
{
ffmkky("EPOCH", valstring, comm, cptr, status); /* construct keyword*/
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
/* EQUINOX keyword */
tstatus = 0;
if (ffgkey(fptr, "EQUINOX", valstring, NULL, &tstatus) == 0 )
{
ffmkky("EQUINOX", valstring, comm, cptr, status); /* construct keyword*/
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
/* RADECSYS keyword */
tstatus = 0;
if (ffgkey(fptr, "RADECSYS", valstring, NULL, &tstatus) == 0 )
{
ffmkky("RADECSYS", valstring, comm, cptr, status); /*construct keyword*/
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
/* TELESCOPE keyword */
tstatus = 0;
if (ffgkey(fptr, "TELESCOP", valstring, NULL, &tstatus) == 0 )
{
ffmkky("TELESCOP", valstring, comm, cptr, status);
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
/* INSTRUME keyword */
tstatus = 0;
if (ffgkey(fptr, "INSTRUME", valstring, NULL, &tstatus) == 0 )
{
ffmkky("INSTRUME", valstring, comm, cptr, status);
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
/* DETECTOR keyword */
tstatus = 0;
if (ffgkey(fptr, "DETECTOR", valstring, NULL, &tstatus) == 0 )
{
ffmkky("DETECTOR", valstring, comm, cptr, status);
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
/* MJD-OBS keyword */
tstatus = 0;
if (ffgkey(fptr, "MJD-OBS", valstring, NULL, &tstatus) == 0 )
{
ffmkky("MJD-OBS", valstring, comm, cptr, status);
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
/* DATE-OBS keyword */
tstatus = 0;
if (ffgkey(fptr, "DATE-OBS", valstring, NULL, &tstatus) == 0 )
{
ffmkky("DATE-OBS", valstring, comm, cptr, status);
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
/* DATE keyword */
tstatus = 0;
if (ffgkey(fptr, "DATE", valstring, NULL, &tstatus) == 0 )
{
ffmkky("DATE", valstring, comm, cptr, status);
length = strlen(cptr);
strncat(cptr, blanks, 80 - length); /* pad with blanks */
cptr += 80;
}
strcat(cptr, "END");
strncat(cptr, blanks, 77);
return(*status);
}
|