1
2 /* This file, getcol.c, contains routines that read data elements from */
3 /* a FITS image or table. There are generic datatype routines. */
4
5 /* The FITSIO software was written by William Pence at the High Energy */
6 /* Astrophysic Science Archive Research Center (HEASARC) at the NASA */
7 /* Goddard Space Flight Center. */
8
9 #include <stdlib.h>
10 #include "fitsio2.h"
11
12 /*--------------------------------------------------------------------------*/
ffgpxv(fitsfile * fptr,int datatype,long * firstpix,LONGLONG nelem,void * nulval,void * array,int * anynul,int * status)13 int ffgpxv( fitsfile *fptr, /* I - FITS file pointer */
14 int datatype, /* I - datatype of the value */
15 long *firstpix, /* I - coord of first pixel to read (1s based) */
16 LONGLONG nelem, /* I - number of values to read */
17 void *nulval, /* I - value for undefined pixels */
18 void *array, /* O - array of values that are returned */
19 int *anynul, /* O - set to 1 if any values are null; else 0 */
20 int *status) /* IO - error status */
21 /*
22 Read an array of values from the primary array. The datatype of the
23 input array is defined by the 2nd argument. Data conversion
24 and scaling will be performed if necessary (e.g, if the datatype of
25 the FITS array is not the same as the array being read).
26 Undefined elements will be set equal to NULVAL, unless NULVAL=0
27 in which case no checking for undefined values will be performed.
28 ANYNUL is returned with a value of .true. if any pixels are undefined.
29 */
30 {
31 LONGLONG tfirstpix[99];
32 int naxis, ii;
33
34 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
35 return(*status);
36
37 /* get the size of the image */
38 ffgidm(fptr, &naxis, status);
39
40 for (ii=0; ii < naxis; ii++)
41 tfirstpix[ii] = firstpix[ii];
42
43 ffgpxvll(fptr, datatype, tfirstpix, nelem, nulval, array, anynul, status);
44
45 return(*status);
46 }
47 /*--------------------------------------------------------------------------*/
ffgpxvll(fitsfile * fptr,int datatype,LONGLONG * firstpix,LONGLONG nelem,void * nulval,void * array,int * anynul,int * status)48 int ffgpxvll( fitsfile *fptr, /* I - FITS file pointer */
49 int datatype, /* I - datatype of the value */
50 LONGLONG *firstpix, /* I - coord of first pixel to read (1s based) */
51 LONGLONG nelem, /* I - number of values to read */
52 void *nulval, /* I - value for undefined pixels */
53 void *array, /* O - array of values that are returned */
54 int *anynul, /* O - set to 1 if any values are null; else 0 */
55 int *status) /* IO - error status */
56 /*
57 Read an array of values from the primary array. The datatype of the
58 input array is defined by the 2nd argument. Data conversion
59 and scaling will be performed if necessary (e.g, if the datatype of
60 the FITS array is not the same as the array being read).
61 Undefined elements will be set equal to NULVAL, unless NULVAL=0
62 in which case no checking for undefined values will be performed.
63 ANYNUL is returned with a value of .true. if any pixels are undefined.
64 */
65 {
66 int naxis, ii;
67 char cdummy;
68 int nullcheck = 1;
69 LONGLONG naxes[9], trc[9]= {1,1,1,1,1,1,1,1,1};
70 long inc[9]= {1,1,1,1,1,1,1,1,1};
71 LONGLONG dimsize = 1, firstelem;
72
73 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
74 return(*status);
75
76 /* get the size of the image */
77 ffgidm(fptr, &naxis, status);
78
79 ffgiszll(fptr, 9, naxes, status);
80
81 if (naxis == 0 || naxes[0] == 0) {
82 *status = BAD_DIMEN;
83 return(*status);
84 }
85
86 /* calculate the position of the first element in the array */
87 firstelem = 0;
88 for (ii=0; ii < naxis; ii++)
89 {
90 firstelem += ((firstpix[ii] - 1) * dimsize);
91 dimsize *= naxes[ii];
92 trc[ii] = firstpix[ii];
93 }
94 firstelem++;
95
96 if (fits_is_compressed_image(fptr, status))
97 {
98 /* this is a compressed image in a binary table */
99
100 /* test for special case of reading an integral number of */
101 /* rows in a 2D or 3D image (which includes reading the whole image */
102
103 if (naxis > 1 && naxis < 4 && firstpix[0] == 1 &&
104 (nelem / naxes[0]) * naxes[0] == nelem) {
105
106 /* calculate coordinate of last pixel */
107 trc[0] = naxes[0]; /* reading whole rows */
108 trc[1] = firstpix[1] + (nelem / naxes[0] - 1);
109 while (trc[1] > naxes[1]) {
110 trc[1] = trc[1] - naxes[1];
111 trc[2] = trc[2] + 1; /* increment to next plane of cube */
112 }
113
114 fits_read_compressed_img(fptr, datatype, firstpix, trc, inc,
115 1, nulval, array, NULL, anynul, status);
116
117 } else {
118
119 fits_read_compressed_pixels(fptr, datatype, firstelem,
120 nelem, nullcheck, nulval, array, NULL, anynul, status);
121 }
122
123 return(*status);
124 }
125
126 /*
127 the primary array is represented as a binary table:
128 each group of the primary array is a row in the table,
129 where the first column contains the group parameters
130 and the second column contains the image itself.
131 */
132
133 if (datatype == TBYTE)
134 {
135 if (nulval == 0)
136 ffgclb(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
137 (unsigned char *) array, &cdummy, anynul, status);
138 else
139 ffgclb(fptr, 2, 1, firstelem, nelem, 1, 1, *(unsigned char *) nulval,
140 (unsigned char *) array, &cdummy, anynul, status);
141 }
142 else if (datatype == TSBYTE)
143 {
144 if (nulval == 0)
145 ffgclsb(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
146 (signed char *) array, &cdummy, anynul, status);
147 else
148 ffgclsb(fptr, 2, 1, firstelem, nelem, 1, 1, *(signed char *) nulval,
149 (signed char *) array, &cdummy, anynul, status);
150 }
151 else if (datatype == TUSHORT)
152 {
153 if (nulval == 0)
154 ffgclui(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
155 (unsigned short *) array, &cdummy, anynul, status);
156 else
157 ffgclui(fptr, 2, 1, firstelem, nelem, 1, 1, *(unsigned short *) nulval,
158 (unsigned short *) array, &cdummy, anynul, status);
159 }
160 else if (datatype == TSHORT)
161 {
162 if (nulval == 0)
163 ffgcli(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
164 (short *) array, &cdummy, anynul, status);
165 else
166 ffgcli(fptr, 2, 1, firstelem, nelem, 1, 1, *(short *) nulval,
167 (short *) array, &cdummy, anynul, status);
168 }
169 else if (datatype == TUINT)
170 {
171 if (nulval == 0)
172 ffgcluk(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
173 (unsigned int *) array, &cdummy, anynul, status);
174 else
175 ffgcluk(fptr, 2, 1, firstelem, nelem, 1, 1, *(unsigned int *) nulval,
176 (unsigned int *) array, &cdummy, anynul, status);
177 }
178 else if (datatype == TINT)
179 {
180 if (nulval == 0)
181 ffgclk(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
182 (int *) array, &cdummy, anynul, status);
183 else
184 ffgclk(fptr, 2, 1, firstelem, nelem, 1, 1, *(int *) nulval,
185 (int *) array, &cdummy, anynul, status);
186 }
187 else if (datatype == TULONG)
188 {
189 if (nulval == 0)
190 ffgcluj(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
191 (unsigned long *) array, &cdummy, anynul, status);
192 else
193 ffgcluj(fptr, 2, 1, firstelem, nelem, 1, 1, *(unsigned long *) nulval,
194 (unsigned long *) array, &cdummy, anynul, status);
195 }
196 else if (datatype == TLONG)
197 {
198 if (nulval == 0)
199 ffgclj(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
200 (long *) array, &cdummy, anynul, status);
201 else
202 ffgclj(fptr, 2, 1, firstelem, nelem, 1, 1, *(long *) nulval,
203 (long *) array, &cdummy, anynul, status);
204 }
205 else if (datatype == TULONGLONG)
206 {
207 if (nulval == 0)
208 ffgclujj(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
209 (ULONGLONG *) array, &cdummy, anynul, status);
210 else
211 ffgclujj(fptr, 2, 1, firstelem, nelem, 1, 1, *(ULONGLONG *) nulval,
212 (ULONGLONG *) array, &cdummy, anynul, status);
213 }
214 else if (datatype == TLONGLONG)
215 {
216 if (nulval == 0)
217 ffgcljj(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
218 (LONGLONG *) array, &cdummy, anynul, status);
219 else
220 ffgcljj(fptr, 2, 1, firstelem, nelem, 1, 1, *(LONGLONG *) nulval,
221 (LONGLONG *) array, &cdummy, anynul, status);
222 }
223 else if (datatype == TFLOAT)
224 {
225 if (nulval == 0)
226 ffgcle(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
227 (float *) array, &cdummy, anynul, status);
228 else
229 ffgcle(fptr, 2, 1, firstelem, nelem, 1, 1, *(float *) nulval,
230 (float *) array, &cdummy, anynul, status);
231 }
232 else if (datatype == TDOUBLE)
233 {
234 if (nulval == 0)
235 ffgcld(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
236 (double *) array, &cdummy, anynul, status);
237 else
238 ffgcld(fptr, 2, 1, firstelem, nelem, 1, 1, *(double *) nulval,
239 (double *) array, &cdummy, anynul, status);
240 }
241 else
242 *status = BAD_DATATYPE;
243
244 return(*status);
245 }
246 /*--------------------------------------------------------------------------*/
ffgpxf(fitsfile * fptr,int datatype,long * firstpix,LONGLONG nelem,void * array,char * nullarray,int * anynul,int * status)247 int ffgpxf( fitsfile *fptr, /* I - FITS file pointer */
248 int datatype, /* I - datatype of the value */
249 long *firstpix, /* I - coord of first pixel to read (1s based) */
250 LONGLONG nelem, /* I - number of values to read */
251 void *array, /* O - array of values that are returned */
252 char *nullarray, /* O - returned array of null value flags */
253 int *anynul, /* O - set to 1 if any values are null; else 0 */
254 int *status) /* IO - error status */
255 /*
256 Read an array of values from the primary array. The datatype of the
257 input array is defined by the 2nd argument. Data conversion
258 and scaling will be performed if necessary (e.g, if the datatype of
259 the FITS array is not the same as the array being read).
260 The nullarray values will = 1 if the corresponding array value is null.
261 ANYNUL is returned with a value of .true. if any pixels are undefined.
262 */
263 {
264 LONGLONG tfirstpix[99];
265 int naxis, ii;
266
267 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
268 return(*status);
269
270 /* get the size of the image */
271 ffgidm(fptr, &naxis, status);
272
273 for (ii=0; ii < naxis; ii++)
274 tfirstpix[ii] = firstpix[ii];
275
276 ffgpxfll(fptr, datatype, tfirstpix, nelem, array, nullarray, anynul, status);
277
278 return(*status);
279 }
280 /*--------------------------------------------------------------------------*/
ffgpxfll(fitsfile * fptr,int datatype,LONGLONG * firstpix,LONGLONG nelem,void * array,char * nullarray,int * anynul,int * status)281 int ffgpxfll( fitsfile *fptr, /* I - FITS file pointer */
282 int datatype, /* I - datatype of the value */
283 LONGLONG *firstpix, /* I - coord of first pixel to read (1s based) */
284 LONGLONG nelem, /* I - number of values to read */
285 void *array, /* O - array of values that are returned */
286 char *nullarray, /* O - returned array of null value flags */
287 int *anynul, /* O - set to 1 if any values are null; else 0 */
288 int *status) /* IO - error status */
289 /*
290 Read an array of values from the primary array. The datatype of the
291 input array is defined by the 2nd argument. Data conversion
292 and scaling will be performed if necessary (e.g, if the datatype of
293 the FITS array is not the same as the array being read).
294 The nullarray values will = 1 if the corresponding array value is null.
295 ANYNUL is returned with a value of .true. if any pixels are undefined.
296 */
297 {
298 int naxis, ii;
299 int nullcheck = 2;
300 LONGLONG naxes[9];
301 LONGLONG dimsize = 1, firstelem;
302
303 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
304 return(*status);
305
306 /* get the size of the image */
307 ffgidm(fptr, &naxis, status);
308 ffgiszll(fptr, 9, naxes, status);
309
310 /* calculate the position of the first element in the array */
311 firstelem = 0;
312 for (ii=0; ii < naxis; ii++)
313 {
314 firstelem += ((firstpix[ii] - 1) * dimsize);
315 dimsize *= naxes[ii];
316 }
317 firstelem++;
318
319 if (fits_is_compressed_image(fptr, status))
320 {
321 /* this is a compressed image in a binary table */
322
323 fits_read_compressed_pixels(fptr, datatype, firstelem, nelem,
324 nullcheck, NULL, array, nullarray, anynul, status);
325 return(*status);
326 }
327
328 /*
329 the primary array is represented as a binary table:
330 each group of the primary array is a row in the table,
331 where the first column contains the group parameters
332 and the second column contains the image itself.
333 */
334
335 if (datatype == TBYTE)
336 {
337 ffgclb(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
338 (unsigned char *) array, nullarray, anynul, status);
339 }
340 else if (datatype == TSBYTE)
341 {
342 ffgclsb(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
343 (signed char *) array, nullarray, anynul, status);
344 }
345 else if (datatype == TUSHORT)
346 {
347 ffgclui(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
348 (unsigned short *) array, nullarray, anynul, status);
349 }
350 else if (datatype == TSHORT)
351 {
352 ffgcli(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
353 (short *) array, nullarray, anynul, status);
354 }
355 else if (datatype == TUINT)
356 {
357 ffgcluk(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
358 (unsigned int *) array, nullarray, anynul, status);
359 }
360 else if (datatype == TINT)
361 {
362 ffgclk(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
363 (int *) array, nullarray, anynul, status);
364 }
365 else if (datatype == TULONG)
366 {
367 ffgcluj(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
368 (unsigned long *) array, nullarray, anynul, status);
369 }
370 else if (datatype == TLONG)
371 {
372 ffgclj(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
373 (long *) array, nullarray, anynul, status);
374 }
375 else if (datatype == TULONGLONG)
376 {
377 ffgclujj(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
378 (ULONGLONG *) array, nullarray, anynul, status);
379 }
380 else if (datatype == TLONGLONG)
381 {
382 ffgcljj(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
383 (LONGLONG *) array, nullarray, anynul, status);
384 }
385 else if (datatype == TFLOAT)
386 {
387 ffgcle(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
388 (float *) array, nullarray, anynul, status);
389 }
390 else if (datatype == TDOUBLE)
391 {
392 ffgcld(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
393 (double *) array, nullarray, anynul, status);
394 }
395 else
396 *status = BAD_DATATYPE;
397
398 return(*status);
399 }
400 /*--------------------------------------------------------------------------*/
ffgsv(fitsfile * fptr,int datatype,long * blc,long * trc,long * inc,void * nulval,void * array,int * anynul,int * status)401 int ffgsv( fitsfile *fptr, /* I - FITS file pointer */
402 int datatype, /* I - datatype of the value */
403 long *blc, /* I - 'bottom left corner' of the subsection */
404 long *trc , /* I - 'top right corner' of the subsection */
405 long *inc, /* I - increment to be applied in each dim. */
406 void *nulval, /* I - value for undefined pixels */
407 void *array, /* O - array of values that are returned */
408 int *anynul, /* O - set to 1 if any values are null; else 0 */
409 int *status) /* IO - error status */
410 /*
411 Read an section of values from the primary array. The datatype of the
412 input array is defined by the 2nd argument. Data conversion
413 and scaling will be performed if necessary (e.g, if the datatype of
414 the FITS array is not the same as the array being read).
415 Undefined elements will be set equal to NULVAL, unless NULVAL=0
416 in which case no checking for undefined values will be performed.
417 ANYNUL is returned with a value of .true. if any pixels are undefined.
418 */
419 {
420 int naxis, ii;
421 long naxes[9];
422 LONGLONG nelem = 1;
423
424 if (*status > 0) /* inherit input status value if > 0 */
425 return(*status);
426
427 /* get the size of the image */
428 ffgidm(fptr, &naxis, status);
429 ffgisz(fptr, 9, naxes, status);
430
431 /* test for the important special case where we are reading the whole image */
432 /* this is only useful for images that are not tile-compressed */
433 if (!fits_is_compressed_image(fptr, status)) {
434 for (ii = 0; ii < naxis; ii++) {
435 if (inc[ii] != 1 || blc[ii] !=1 || trc[ii] != naxes[ii])
436 break;
437
438 nelem = nelem * naxes[ii];
439 }
440
441 if (ii == naxis) {
442 /* read the whole image more efficiently */
443 ffgpxv(fptr, datatype, blc, nelem, nulval, array, anynul, status);
444 return(*status);
445 }
446 }
447
448 if (datatype == TBYTE)
449 {
450 if (nulval == 0)
451 ffgsvb(fptr, 1, naxis, naxes, blc, trc, inc, 0,
452 (unsigned char *) array, anynul, status);
453 else
454 ffgsvb(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned char *) nulval,
455 (unsigned char *) array, anynul, status);
456 }
457 else if (datatype == TSBYTE)
458 {
459 if (nulval == 0)
460 ffgsvsb(fptr, 1, naxis, naxes, blc, trc, inc, 0,
461 (signed char *) array, anynul, status);
462 else
463 ffgsvsb(fptr, 1, naxis, naxes, blc, trc, inc, *(signed char *) nulval,
464 (signed char *) array, anynul, status);
465 }
466 else if (datatype == TUSHORT)
467 {
468 if (nulval == 0)
469 ffgsvui(fptr, 1, naxis, naxes, blc, trc, inc, 0,
470 (unsigned short *) array, anynul, status);
471 else
472 ffgsvui(fptr, 1, naxis, naxes,blc, trc, inc, *(unsigned short *) nulval,
473 (unsigned short *) array, anynul, status);
474 }
475 else if (datatype == TSHORT)
476 {
477 if (nulval == 0)
478 ffgsvi(fptr, 1, naxis, naxes, blc, trc, inc, 0,
479 (short *) array, anynul, status);
480 else
481 ffgsvi(fptr, 1, naxis, naxes, blc, trc, inc, *(short *) nulval,
482 (short *) array, anynul, status);
483 }
484 else if (datatype == TUINT)
485 {
486 if (nulval == 0)
487 ffgsvuk(fptr, 1, naxis, naxes, blc, trc, inc, 0,
488 (unsigned int *) array, anynul, status);
489 else
490 ffgsvuk(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned int *) nulval,
491 (unsigned int *) array, anynul, status);
492 }
493 else if (datatype == TINT)
494 {
495 if (nulval == 0)
496 ffgsvk(fptr, 1, naxis, naxes, blc, trc, inc, 0,
497 (int *) array, anynul, status);
498 else
499 ffgsvk(fptr, 1, naxis, naxes, blc, trc, inc, *(int *) nulval,
500 (int *) array, anynul, status);
501 }
502 else if (datatype == TULONG)
503 {
504 if (nulval == 0)
505 ffgsvuj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
506 (unsigned long *) array, anynul, status);
507 else
508 ffgsvuj(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned long *) nulval,
509 (unsigned long *) array, anynul, status);
510 }
511 else if (datatype == TLONG)
512 {
513 if (nulval == 0)
514 ffgsvj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
515 (long *) array, anynul, status);
516 else
517 ffgsvj(fptr, 1, naxis, naxes, blc, trc, inc, *(long *) nulval,
518 (long *) array, anynul, status);
519 }
520 else if (datatype == TULONGLONG)
521 {
522 if (nulval == 0)
523 ffgsvujj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
524 (ULONGLONG *) array, anynul, status);
525 else
526 ffgsvujj(fptr, 1, naxis, naxes, blc, trc, inc, *(ULONGLONG *) nulval,
527 (ULONGLONG *) array, anynul, status);
528 }
529 else if (datatype == TLONGLONG)
530 {
531 if (nulval == 0)
532 ffgsvjj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
533 (LONGLONG *) array, anynul, status);
534 else
535 ffgsvjj(fptr, 1, naxis, naxes, blc, trc, inc, *(LONGLONG *) nulval,
536 (LONGLONG *) array, anynul, status);
537 }
538 else if (datatype == TFLOAT)
539 {
540 if (nulval == 0)
541 ffgsve(fptr, 1, naxis, naxes, blc, trc, inc, 0,
542 (float *) array, anynul, status);
543 else
544 ffgsve(fptr, 1, naxis, naxes, blc, trc, inc, *(float *) nulval,
545 (float *) array, anynul, status);
546 }
547 else if (datatype == TDOUBLE)
548 {
549 if (nulval == 0)
550 ffgsvd(fptr, 1, naxis, naxes, blc, trc, inc, 0,
551 (double *) array, anynul, status);
552 else
553 ffgsvd(fptr, 1, naxis, naxes, blc, trc, inc, *(double *) nulval,
554 (double *) array, anynul, status);
555 }
556 else
557 *status = BAD_DATATYPE;
558
559 return(*status);
560 }
561 /*--------------------------------------------------------------------------*/
ffgpv(fitsfile * fptr,int datatype,LONGLONG firstelem,LONGLONG nelem,void * nulval,void * array,int * anynul,int * status)562 int ffgpv( fitsfile *fptr, /* I - FITS file pointer */
563 int datatype, /* I - datatype of the value */
564 LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
565 LONGLONG nelem, /* I - number of values to read */
566 void *nulval, /* I - value for undefined pixels */
567 void *array, /* O - array of values that are returned */
568 int *anynul, /* O - set to 1 if any values are null; else 0 */
569 int *status) /* IO - error status */
570 /*
571 Read an array of values from the primary array. The datatype of the
572 input array is defined by the 2nd argument. Data conversion
573 and scaling will be performed if necessary (e.g, if the datatype of
574 the FITS array is not the same as the array being read).
575 Undefined elements will be set equal to NULVAL, unless NULVAL=0
576 in which case no checking for undefined values will be performed.
577 ANYNUL is returned with a value of .true. if any pixels are undefined.
578 */
579 {
580
581 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
582 return(*status);
583
584 /*
585 the primary array is represented as a binary table:
586 each group of the primary array is a row in the table,
587 where the first column contains the group parameters
588 and the second column contains the image itself.
589 */
590
591 if (datatype == TBYTE)
592 {
593 if (nulval == 0)
594 ffgpvb(fptr, 1, firstelem, nelem, 0,
595 (unsigned char *) array, anynul, status);
596 else
597 ffgpvb(fptr, 1, firstelem, nelem, *(unsigned char *) nulval,
598 (unsigned char *) array, anynul, status);
599 }
600 else if (datatype == TSBYTE)
601 {
602 if (nulval == 0)
603 ffgpvsb(fptr, 1, firstelem, nelem, 0,
604 (signed char *) array, anynul, status);
605 else
606 ffgpvsb(fptr, 1, firstelem, nelem, *(signed char *) nulval,
607 (signed char *) array, anynul, status);
608 }
609 else if (datatype == TUSHORT)
610 {
611 if (nulval == 0)
612 ffgpvui(fptr, 1, firstelem, nelem, 0,
613 (unsigned short *) array, anynul, status);
614 else
615 ffgpvui(fptr, 1, firstelem, nelem, *(unsigned short *) nulval,
616 (unsigned short *) array, anynul, status);
617 }
618 else if (datatype == TSHORT)
619 {
620 if (nulval == 0)
621 ffgpvi(fptr, 1, firstelem, nelem, 0,
622 (short *) array, anynul, status);
623 else
624 ffgpvi(fptr, 1, firstelem, nelem, *(short *) nulval,
625 (short *) array, anynul, status);
626 }
627 else if (datatype == TUINT)
628 {
629 if (nulval == 0)
630 ffgpvuk(fptr, 1, firstelem, nelem, 0,
631 (unsigned int *) array, anynul, status);
632 else
633 ffgpvuk(fptr, 1, firstelem, nelem, *(unsigned int *) nulval,
634 (unsigned int *) array, anynul, status);
635 }
636 else if (datatype == TINT)
637 {
638 if (nulval == 0)
639 ffgpvk(fptr, 1, firstelem, nelem, 0,
640 (int *) array, anynul, status);
641 else
642 ffgpvk(fptr, 1, firstelem, nelem, *(int *) nulval,
643 (int *) array, anynul, status);
644 }
645 else if (datatype == TULONG)
646 {
647 if (nulval == 0)
648 ffgpvuj(fptr, 1, firstelem, nelem, 0,
649 (unsigned long *) array, anynul, status);
650 else
651 ffgpvuj(fptr, 1, firstelem, nelem, *(unsigned long *) nulval,
652 (unsigned long *) array, anynul, status);
653 }
654 else if (datatype == TLONG)
655 {
656 if (nulval == 0)
657 ffgpvj(fptr, 1, firstelem, nelem, 0,
658 (long *) array, anynul, status);
659 else
660 ffgpvj(fptr, 1, firstelem, nelem, *(long *) nulval,
661 (long *) array, anynul, status);
662 }
663 else if (datatype == TULONGLONG)
664 {
665 if (nulval == 0)
666 ffgpvujj(fptr, 1, firstelem, nelem, 0,
667 (ULONGLONG *) array, anynul, status);
668 else
669 ffgpvujj(fptr, 1, firstelem, nelem, *(ULONGLONG *) nulval,
670 (ULONGLONG *) array, anynul, status);
671 }
672 else if (datatype == TLONGLONG)
673 {
674 if (nulval == 0)
675 ffgpvjj(fptr, 1, firstelem, nelem, 0,
676 (LONGLONG *) array, anynul, status);
677 else
678 ffgpvjj(fptr, 1, firstelem, nelem, *(LONGLONG *) nulval,
679 (LONGLONG *) array, anynul, status);
680 }
681 else if (datatype == TFLOAT)
682 {
683 if (nulval == 0)
684 ffgpve(fptr, 1, firstelem, nelem, 0,
685 (float *) array, anynul, status);
686 else
687 ffgpve(fptr, 1, firstelem, nelem, *(float *) nulval,
688 (float *) array, anynul, status);
689 }
690 else if (datatype == TDOUBLE)
691 {
692 if (nulval == 0)
693 ffgpvd(fptr, 1, firstelem, nelem, 0,
694 (double *) array, anynul, status);
695 else
696 {
697 ffgpvd(fptr, 1, firstelem, nelem, *(double *) nulval,
698 (double *) array, anynul, status);
699 }
700 }
701 else
702 *status = BAD_DATATYPE;
703
704 return(*status);
705 }
706 /*--------------------------------------------------------------------------*/
ffgpf(fitsfile * fptr,int datatype,LONGLONG firstelem,LONGLONG nelem,void * array,char * nullarray,int * anynul,int * status)707 int ffgpf( fitsfile *fptr, /* I - FITS file pointer */
708 int datatype, /* I - datatype of the value */
709 LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
710 LONGLONG nelem, /* I - number of values to read */
711 void *array, /* O - array of values that are returned */
712 char *nullarray, /* O - array of null value flags */
713 int *anynul, /* O - set to 1 if any values are null; else 0 */
714 int *status) /* IO - error status */
715 /*
716 Read an array of values from the primary array. The datatype of the
717 input array is defined by the 2nd argument. Data conversion
718 and scaling will be performed if necessary (e.g, if the datatype of
719 the FITS array is not the same as the array being read).
720 The nullarray values will = 1 if the corresponding array value is null.
721 ANYNUL is returned with a value of .true. if any pixels are undefined.
722 */
723 {
724
725 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
726 return(*status);
727
728 /*
729 the primary array is represented as a binary table:
730 each group of the primary array is a row in the table,
731 where the first column contains the group parameters
732 and the second column contains the image itself.
733 */
734
735 if (datatype == TBYTE)
736 {
737 ffgpfb(fptr, 1, firstelem, nelem,
738 (unsigned char *) array, nullarray, anynul, status);
739 }
740 else if (datatype == TSBYTE)
741 {
742 ffgpfsb(fptr, 1, firstelem, nelem,
743 (signed char *) array, nullarray, anynul, status);
744 }
745 else if (datatype == TUSHORT)
746 {
747 ffgpfui(fptr, 1, firstelem, nelem,
748 (unsigned short *) array, nullarray, anynul, status);
749 }
750 else if (datatype == TSHORT)
751 {
752 ffgpfi(fptr, 1, firstelem, nelem,
753 (short *) array, nullarray, anynul, status);
754 }
755 else if (datatype == TUINT)
756 {
757 ffgpfuk(fptr, 1, firstelem, nelem,
758 (unsigned int *) array, nullarray, anynul, status);
759 }
760 else if (datatype == TINT)
761 {
762 ffgpfk(fptr, 1, firstelem, nelem,
763 (int *) array, nullarray, anynul, status);
764 }
765 else if (datatype == TULONG)
766 {
767 ffgpfuj(fptr, 1, firstelem, nelem,
768 (unsigned long *) array, nullarray, anynul, status);
769 }
770 else if (datatype == TLONG)
771 {
772 ffgpfj(fptr, 1, firstelem, nelem,
773 (long *) array, nullarray, anynul, status);
774 }
775 else if (datatype == TULONGLONG)
776 {
777 ffgpfujj(fptr, 1, firstelem, nelem,
778 (ULONGLONG *) array, nullarray, anynul, status);
779 }
780 else if (datatype == TLONGLONG)
781 {
782 ffgpfjj(fptr, 1, firstelem, nelem,
783 (LONGLONG *) array, nullarray, anynul, status);
784 }
785 else if (datatype == TFLOAT)
786 {
787 ffgpfe(fptr, 1, firstelem, nelem,
788 (float *) array, nullarray, anynul, status);
789 }
790 else if (datatype == TDOUBLE)
791 {
792 ffgpfd(fptr, 1, firstelem, nelem,
793 (double *) array, nullarray, anynul, status);
794 }
795 else
796 *status = BAD_DATATYPE;
797
798 return(*status);
799 }
800 /*--------------------------------------------------------------------------*/
ffgcv(fitsfile * fptr,int datatype,int colnum,LONGLONG firstrow,LONGLONG firstelem,LONGLONG nelem,void * nulval,void * array,int * anynul,int * status)801 int ffgcv( fitsfile *fptr, /* I - FITS file pointer */
802 int datatype, /* I - datatype of the value */
803 int colnum, /* I - number of column to write (1 = 1st col) */
804 LONGLONG firstrow, /* I - first row to write (1 = 1st row) */
805 LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
806 LONGLONG nelem, /* I - number of values to read */
807 void *nulval, /* I - value for undefined pixels */
808 void *array, /* O - array of values that are returned */
809 int *anynul, /* O - set to 1 if any values are null; else 0 */
810 int *status) /* IO - error status */
811 /*
812 Read an array of values from a table column. The datatype of the
813 input array is defined by the 2nd argument. Data conversion
814 and scaling will be performed if necessary (e.g, if the datatype of
815 the FITS array is not the same as the array being read).
816 Undefined elements will be set equal to NULVAL, unless NULVAL=0
817 in which case no checking for undefined values will be performed.
818 ANYNUL is returned with a value of true if any pixels are undefined.
819 */
820 {
821 char cdummy[2];
822
823 if (*status > 0) /* inherit input status value if > 0 */
824 return(*status);
825
826 if (datatype == TBIT)
827 {
828 ffgcx(fptr, colnum, firstrow, firstelem, nelem, (char *) array, status);
829 }
830 else if (datatype == TBYTE)
831 {
832 if (nulval == 0)
833 ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
834 (unsigned char *) array, cdummy, anynul, status);
835 else
836 ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(unsigned char *)
837 nulval, (unsigned char *) array, cdummy, anynul, status);
838 }
839 else if (datatype == TSBYTE)
840 {
841 if (nulval == 0)
842 ffgclsb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
843 (signed char *) array, cdummy, anynul, status);
844 else
845 ffgclsb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(signed char *)
846 nulval, (signed char *) array, cdummy, anynul, status);
847 }
848 else if (datatype == TUSHORT)
849 {
850 if (nulval == 0)
851 ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
852 (unsigned short *) array, cdummy, anynul, status);
853 else
854 ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
855 *(unsigned short *) nulval,
856 (unsigned short *) array, cdummy, anynul, status);
857 }
858 else if (datatype == TSHORT)
859 {
860 if (nulval == 0)
861 ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
862 (short *) array, cdummy, anynul, status);
863 else
864 ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(short *)
865 nulval, (short *) array, cdummy, anynul, status);
866 }
867 else if (datatype == TUINT)
868 {
869 if (nulval == 0)
870 ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
871 (unsigned int *) array, cdummy, anynul, status);
872 else
873 ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
874 *(unsigned int *) nulval, (unsigned int *) array, cdummy, anynul,
875 status);
876 }
877 else if (datatype == TINT)
878 {
879 if (nulval == 0)
880 ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
881 (int *) array, cdummy, anynul, status);
882 else
883 ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(int *)
884 nulval, (int *) array, cdummy, anynul, status);
885 }
886 else if (datatype == TULONG)
887 {
888 if (nulval == 0)
889 ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
890 (unsigned long *) array, cdummy, anynul, status);
891 else
892 ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
893 *(unsigned long *) nulval,
894 (unsigned long *) array, cdummy, anynul, status);
895 }
896 else if (datatype == TLONG)
897 {
898 if (nulval == 0)
899 ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
900 (long *) array, cdummy, anynul, status);
901 else
902 ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(long *)
903 nulval, (long *) array, cdummy, anynul, status);
904 }
905 else if (datatype == TULONGLONG)
906 {
907 if (nulval == 0)
908 ffgclujj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
909 (ULONGLONG *) array, cdummy, anynul, status);
910 else
911 ffgclujj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(ULONGLONG *)
912 nulval, (ULONGLONG *) array, cdummy, anynul, status);
913 }
914 else if (datatype == TLONGLONG)
915 {
916 if (nulval == 0)
917 ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
918 (LONGLONG *) array, cdummy, anynul, status);
919 else
920 ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(LONGLONG *)
921 nulval, (LONGLONG *) array, cdummy, anynul, status);
922 }
923 else if (datatype == TFLOAT)
924 {
925 if (nulval == 0)
926 ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0.,
927 (float *) array, cdummy, anynul, status);
928 else
929 ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(float *)
930 nulval,(float *) array, cdummy, anynul, status);
931 }
932 else if (datatype == TDOUBLE)
933 {
934 if (nulval == 0)
935 ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0.,
936 (double *) array, cdummy, anynul, status);
937 else
938 ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(double *)
939 nulval, (double *) array, cdummy, anynul, status);
940 }
941 else if (datatype == TCOMPLEX)
942 {
943 if (nulval == 0)
944 ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
945 1, 1, 0., (float *) array, cdummy, anynul, status);
946 else
947 ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
948 1, 1, *(float *) nulval, (float *) array, cdummy, anynul, status);
949 }
950 else if (datatype == TDBLCOMPLEX)
951 {
952 if (nulval == 0)
953 ffgcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
954 1, 1, 0., (double *) array, cdummy, anynul, status);
955 else
956 ffgcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
957 1, 1, *(double *) nulval, (double *) array, cdummy, anynul, status);
958 }
959
960 else if (datatype == TLOGICAL)
961 {
962 if (nulval == 0)
963 ffgcll(fptr, colnum, firstrow, firstelem, nelem, 1, 0,
964 (char *) array, cdummy, anynul, status);
965 else
966 ffgcll(fptr, colnum, firstrow, firstelem, nelem, 1, *(char *) nulval,
967 (char *) array, cdummy, anynul, status);
968 }
969 else if (datatype == TSTRING)
970 {
971 if (nulval == 0)
972 {
973 cdummy[0] = '\0';
974 ffgcls(fptr, colnum, firstrow, firstelem, nelem, 1,
975 cdummy, (char **) array, cdummy, anynul, status);
976 }
977 else
978 ffgcls(fptr, colnum, firstrow, firstelem, nelem, 1, (char *)
979 nulval, (char **) array, cdummy, anynul, status);
980 }
981 else
982 *status = BAD_DATATYPE;
983
984 return(*status);
985 }
986 /*--------------------------------------------------------------------------*/
ffgcf(fitsfile * fptr,int datatype,int colnum,LONGLONG firstrow,LONGLONG firstelem,LONGLONG nelem,void * array,char * nullarray,int * anynul,int * status)987 int ffgcf( fitsfile *fptr, /* I - FITS file pointer */
988 int datatype, /* I - datatype of the value */
989 int colnum, /* I - number of column to write (1 = 1st col) */
990 LONGLONG firstrow, /* I - first row to write (1 = 1st row) */
991 LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
992 LONGLONG nelem, /* I - number of values to read */
993 void *array, /* O - array of values that are returned */
994 char *nullarray, /* O - array of null value flags */
995 int *anynul, /* O - set to 1 if any values are null; else 0 */
996 int *status) /* IO - error status */
997 /*
998 Read an array of values from a table column. The datatype of the
999 input array is defined by the 2nd argument. Data conversion
1000 and scaling will be performed if necessary (e.g, if the datatype of
1001 the FITS array is not the same as the array being read).
1002 ANYNUL is returned with a value of true if any pixels are undefined.
1003 */
1004 {
1005 double nulval = 0.;
1006 char cnulval[2];
1007
1008 if (*status > 0) /* inherit input status value if > 0 */
1009 return(*status);
1010
1011 if (datatype == TBIT)
1012 {
1013 ffgcx(fptr, colnum, firstrow, firstelem, nelem, (char *) array, status);
1014 }
1015 else if (datatype == TBYTE)
1016 {
1017 ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (unsigned char )
1018 nulval, (unsigned char *) array, nullarray, anynul, status);
1019 }
1020 else if (datatype == TSBYTE)
1021 {
1022 ffgclsb(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (signed char )
1023 nulval, (signed char *) array, nullarray, anynul, status);
1024 }
1025 else if (datatype == TUSHORT)
1026 {
1027 ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
1028 (unsigned short ) nulval,
1029 (unsigned short *) array, nullarray, anynul, status);
1030 }
1031 else if (datatype == TSHORT)
1032 {
1033 ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (short )
1034 nulval, (short *) array, nullarray, anynul, status);
1035 }
1036 else if (datatype == TUINT)
1037 {
1038 ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
1039 (unsigned int ) nulval, (unsigned int *) array, nullarray, anynul,
1040 status);
1041 }
1042 else if (datatype == TINT)
1043 {
1044 ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (int )
1045 nulval, (int *) array, nullarray, anynul, status);
1046 }
1047 else if (datatype == TULONG)
1048 {
1049 ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
1050 (unsigned long ) nulval,
1051 (unsigned long *) array, nullarray, anynul, status);
1052 }
1053 else if (datatype == TLONG)
1054 {
1055 ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (long )
1056 nulval, (long *) array, nullarray, anynul, status);
1057 }
1058 else if (datatype == TULONGLONG)
1059 {
1060 ffgclujj(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (ULONGLONG )
1061 nulval, (ULONGLONG *) array, nullarray, anynul, status);
1062 }
1063 else if (datatype == TLONGLONG)
1064 {
1065 ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (LONGLONG )
1066 nulval, (LONGLONG *) array, nullarray, anynul, status);
1067 }
1068 else if (datatype == TFLOAT)
1069 {
1070 ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (float )
1071 nulval,(float *) array, nullarray, anynul, status);
1072 }
1073 else if (datatype == TDOUBLE)
1074 {
1075 ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
1076 nulval, (double *) array, nullarray, anynul, status);
1077 }
1078 else if (datatype == TCOMPLEX)
1079 {
1080 ffgcfc(fptr, colnum, firstrow, firstelem, nelem,
1081 (float *) array, nullarray, anynul, status);
1082 }
1083 else if (datatype == TDBLCOMPLEX)
1084 {
1085 ffgcfm(fptr, colnum, firstrow, firstelem, nelem,
1086 (double *) array, nullarray, anynul, status);
1087 }
1088
1089 else if (datatype == TLOGICAL)
1090 {
1091 ffgcll(fptr, colnum, firstrow, firstelem, nelem, 2, (char ) nulval,
1092 (char *) array, nullarray, anynul, status);
1093 }
1094 else if (datatype == TSTRING)
1095 {
1096 ffgcls(fptr, colnum, firstrow, firstelem, nelem, 2,
1097 cnulval, (char **) array, nullarray, anynul, status);
1098 }
1099 else
1100 *status = BAD_DATATYPE;
1101
1102 return(*status);
1103 }
1104
1105