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 == TLONGLONG)
206 {
207 if (nulval == 0)
208 ffgcljj(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
209 (LONGLONG *) array, &cdummy, anynul, status);
210 else
211 ffgcljj(fptr, 2, 1, firstelem, nelem, 1, 1, *(LONGLONG *) nulval,
212 (LONGLONG *) array, &cdummy, anynul, status);
213 }
214 else if (datatype == TFLOAT)
215 {
216 if (nulval == 0)
217 ffgcle(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
218 (float *) array, &cdummy, anynul, status);
219 else
220 ffgcle(fptr, 2, 1, firstelem, nelem, 1, 1, *(float *) nulval,
221 (float *) array, &cdummy, anynul, status);
222 }
223 else if (datatype == TDOUBLE)
224 {
225 if (nulval == 0)
226 ffgcld(fptr, 2, 1, firstelem, nelem, 1, 1, 0,
227 (double *) array, &cdummy, anynul, status);
228 else
229 ffgcld(fptr, 2, 1, firstelem, nelem, 1, 1, *(double *) nulval,
230 (double *) array, &cdummy, anynul, status);
231 }
232 else
233 *status = BAD_DATATYPE;
234
235 return(*status);
236 }
237 /*--------------------------------------------------------------------------*/
ffgpxf(fitsfile * fptr,int datatype,long * firstpix,LONGLONG nelem,void * array,char * nullarray,int * anynul,int * status)238 int ffgpxf( fitsfile *fptr, /* I - FITS file pointer */
239 int datatype, /* I - datatype of the value */
240 long *firstpix, /* I - coord of first pixel to read (1s based) */
241 LONGLONG nelem, /* I - number of values to read */
242 void *array, /* O - array of values that are returned */
243 char *nullarray, /* O - returned array of null value flags */
244 int *anynul, /* O - set to 1 if any values are null; else 0 */
245 int *status) /* IO - error status */
246 /*
247 Read an array of values from the primary array. The datatype of the
248 input array is defined by the 2nd argument. Data conversion
249 and scaling will be performed if necessary (e.g, if the datatype of
250 the FITS array is not the same as the array being read).
251 The nullarray values will = 1 if the corresponding array value is null.
252 ANYNUL is returned with a value of .true. if any pixels are undefined.
253 */
254 {
255 LONGLONG tfirstpix[99];
256 int naxis, ii;
257
258 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
259 return(*status);
260
261 /* get the size of the image */
262 ffgidm(fptr, &naxis, status);
263
264 for (ii=0; ii < naxis; ii++)
265 tfirstpix[ii] = firstpix[ii];
266
267 ffgpxfll(fptr, datatype, tfirstpix, nelem, array, nullarray, anynul, status);
268
269 return(*status);
270 }
271 /*--------------------------------------------------------------------------*/
ffgpxfll(fitsfile * fptr,int datatype,LONGLONG * firstpix,LONGLONG nelem,void * array,char * nullarray,int * anynul,int * status)272 int ffgpxfll( fitsfile *fptr, /* I - FITS file pointer */
273 int datatype, /* I - datatype of the value */
274 LONGLONG *firstpix, /* I - coord of first pixel to read (1s based) */
275 LONGLONG nelem, /* I - number of values to read */
276 void *array, /* O - array of values that are returned */
277 char *nullarray, /* O - returned array of null value flags */
278 int *anynul, /* O - set to 1 if any values are null; else 0 */
279 int *status) /* IO - error status */
280 /*
281 Read an array of values from the primary array. The datatype of the
282 input array is defined by the 2nd argument. Data conversion
283 and scaling will be performed if necessary (e.g, if the datatype of
284 the FITS array is not the same as the array being read).
285 The nullarray values will = 1 if the corresponding array value is null.
286 ANYNUL is returned with a value of .true. if any pixels are undefined.
287 */
288 {
289 int naxis, ii;
290 int nullcheck = 2;
291 LONGLONG naxes[9];
292 LONGLONG dimsize = 1, firstelem;
293
294 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
295 return(*status);
296
297 /* get the size of the image */
298 ffgidm(fptr, &naxis, status);
299 ffgiszll(fptr, 9, naxes, status);
300
301 /* calculate the position of the first element in the array */
302 firstelem = 0;
303 for (ii=0; ii < naxis; ii++)
304 {
305 firstelem += ((firstpix[ii] - 1) * dimsize);
306 dimsize *= naxes[ii];
307 }
308 firstelem++;
309
310 if (fits_is_compressed_image(fptr, status))
311 {
312 /* this is a compressed image in a binary table */
313
314 fits_read_compressed_pixels(fptr, datatype, firstelem, nelem,
315 nullcheck, NULL, array, nullarray, anynul, status);
316 return(*status);
317 }
318
319 /*
320 the primary array is represented as a binary table:
321 each group of the primary array is a row in the table,
322 where the first column contains the group parameters
323 and the second column contains the image itself.
324 */
325
326 if (datatype == TBYTE)
327 {
328 ffgclb(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
329 (unsigned char *) array, nullarray, anynul, status);
330 }
331 else if (datatype == TSBYTE)
332 {
333 ffgclsb(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
334 (signed char *) array, nullarray, anynul, status);
335 }
336 else if (datatype == TUSHORT)
337 {
338 ffgclui(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
339 (unsigned short *) array, nullarray, anynul, status);
340 }
341 else if (datatype == TSHORT)
342 {
343 ffgcli(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
344 (short *) array, nullarray, anynul, status);
345 }
346 else if (datatype == TUINT)
347 {
348 ffgcluk(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
349 (unsigned int *) array, nullarray, anynul, status);
350 }
351 else if (datatype == TINT)
352 {
353 ffgclk(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
354 (int *) array, nullarray, anynul, status);
355 }
356 else if (datatype == TULONG)
357 {
358 ffgcluj(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
359 (unsigned long *) array, nullarray, anynul, status);
360 }
361 else if (datatype == TLONG)
362 {
363 ffgclj(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
364 (long *) array, nullarray, anynul, status);
365 }
366 else if (datatype == TLONGLONG)
367 {
368 ffgcljj(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
369 (LONGLONG *) array, nullarray, anynul, status);
370 }
371 else if (datatype == TFLOAT)
372 {
373 ffgcle(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
374 (float *) array, nullarray, anynul, status);
375 }
376 else if (datatype == TDOUBLE)
377 {
378 ffgcld(fptr, 2, 1, firstelem, nelem, 1, 2, 0,
379 (double *) array, nullarray, anynul, status);
380 }
381 else
382 *status = BAD_DATATYPE;
383
384 return(*status);
385 }
386 /*--------------------------------------------------------------------------*/
ffgsv(fitsfile * fptr,int datatype,long * blc,long * trc,long * inc,void * nulval,void * array,int * anynul,int * status)387 int ffgsv( fitsfile *fptr, /* I - FITS file pointer */
388 int datatype, /* I - datatype of the value */
389 long *blc, /* I - 'bottom left corner' of the subsection */
390 long *trc , /* I - 'top right corner' of the subsection */
391 long *inc, /* I - increment to be applied in each dim. */
392 void *nulval, /* I - value for undefined pixels */
393 void *array, /* O - array of values that are returned */
394 int *anynul, /* O - set to 1 if any values are null; else 0 */
395 int *status) /* IO - error status */
396 /*
397 Read an section of values from the primary array. The datatype of the
398 input array is defined by the 2nd argument. Data conversion
399 and scaling will be performed if necessary (e.g, if the datatype of
400 the FITS array is not the same as the array being read).
401 Undefined elements will be set equal to NULVAL, unless NULVAL=0
402 in which case no checking for undefined values will be performed.
403 ANYNUL is returned with a value of .true. if any pixels are undefined.
404 */
405 {
406 int naxis, ii;
407 long naxes[9];
408 LONGLONG nelem = 1;
409
410 if (*status > 0) /* inherit input status value if > 0 */
411 return(*status);
412
413 /* get the size of the image */
414 ffgidm(fptr, &naxis, status);
415 ffgisz(fptr, 9, naxes, status);
416
417 /* test for the important special case where we are reading the whole image */
418 /* this is only useful for images that are not tile-compressed */
419 if (!fits_is_compressed_image(fptr, status)) {
420 for (ii = 0; ii < naxis; ii++) {
421 if (inc[ii] != 1 || blc[ii] !=1 || trc[ii] != naxes[ii])
422 break;
423
424 nelem = nelem * naxes[ii];
425 }
426
427 if (ii == naxis) {
428 /* read the whole image more efficiently */
429 ffgpxv(fptr, datatype, blc, nelem, nulval, array, anynul, status);
430 return(*status);
431 }
432 }
433
434 if (datatype == TBYTE)
435 {
436 if (nulval == 0)
437 ffgsvb(fptr, 1, naxis, naxes, blc, trc, inc, 0,
438 (unsigned char *) array, anynul, status);
439 else
440 ffgsvb(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned char *) nulval,
441 (unsigned char *) array, anynul, status);
442 }
443 else if (datatype == TSBYTE)
444 {
445 if (nulval == 0)
446 ffgsvsb(fptr, 1, naxis, naxes, blc, trc, inc, 0,
447 (signed char *) array, anynul, status);
448 else
449 ffgsvsb(fptr, 1, naxis, naxes, blc, trc, inc, *(signed char *) nulval,
450 (signed char *) array, anynul, status);
451 }
452 else if (datatype == TUSHORT)
453 {
454 if (nulval == 0)
455 ffgsvui(fptr, 1, naxis, naxes, blc, trc, inc, 0,
456 (unsigned short *) array, anynul, status);
457 else
458 ffgsvui(fptr, 1, naxis, naxes,blc, trc, inc, *(unsigned short *) nulval,
459 (unsigned short *) array, anynul, status);
460 }
461 else if (datatype == TSHORT)
462 {
463 if (nulval == 0)
464 ffgsvi(fptr, 1, naxis, naxes, blc, trc, inc, 0,
465 (short *) array, anynul, status);
466 else
467 ffgsvi(fptr, 1, naxis, naxes, blc, trc, inc, *(short *) nulval,
468 (short *) array, anynul, status);
469 }
470 else if (datatype == TUINT)
471 {
472 if (nulval == 0)
473 ffgsvuk(fptr, 1, naxis, naxes, blc, trc, inc, 0,
474 (unsigned int *) array, anynul, status);
475 else
476 ffgsvuk(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned int *) nulval,
477 (unsigned int *) array, anynul, status);
478 }
479 else if (datatype == TINT)
480 {
481 if (nulval == 0)
482 ffgsvk(fptr, 1, naxis, naxes, blc, trc, inc, 0,
483 (int *) array, anynul, status);
484 else
485 ffgsvk(fptr, 1, naxis, naxes, blc, trc, inc, *(int *) nulval,
486 (int *) array, anynul, status);
487 }
488 else if (datatype == TULONG)
489 {
490 if (nulval == 0)
491 ffgsvuj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
492 (unsigned long *) array, anynul, status);
493 else
494 ffgsvuj(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned long *) nulval,
495 (unsigned long *) array, anynul, status);
496 }
497 else if (datatype == TLONG)
498 {
499 if (nulval == 0)
500 ffgsvj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
501 (long *) array, anynul, status);
502 else
503 ffgsvj(fptr, 1, naxis, naxes, blc, trc, inc, *(long *) nulval,
504 (long *) array, anynul, status);
505 }
506 else if (datatype == TLONGLONG)
507 {
508 if (nulval == 0)
509 ffgsvjj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
510 (LONGLONG *) array, anynul, status);
511 else
512 ffgsvjj(fptr, 1, naxis, naxes, blc, trc, inc, *(LONGLONG *) nulval,
513 (LONGLONG *) array, anynul, status);
514 }
515 else if (datatype == TFLOAT)
516 {
517 if (nulval == 0)
518 ffgsve(fptr, 1, naxis, naxes, blc, trc, inc, 0,
519 (float *) array, anynul, status);
520 else
521 ffgsve(fptr, 1, naxis, naxes, blc, trc, inc, *(float *) nulval,
522 (float *) array, anynul, status);
523 }
524 else if (datatype == TDOUBLE)
525 {
526 if (nulval == 0)
527 ffgsvd(fptr, 1, naxis, naxes, blc, trc, inc, 0,
528 (double *) array, anynul, status);
529 else
530 ffgsvd(fptr, 1, naxis, naxes, blc, trc, inc, *(double *) nulval,
531 (double *) array, anynul, status);
532 }
533 else
534 *status = BAD_DATATYPE;
535
536 return(*status);
537 }
538 /*--------------------------------------------------------------------------*/
ffgpv(fitsfile * fptr,int datatype,LONGLONG firstelem,LONGLONG nelem,void * nulval,void * array,int * anynul,int * status)539 int ffgpv( fitsfile *fptr, /* I - FITS file pointer */
540 int datatype, /* I - datatype of the value */
541 LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
542 LONGLONG nelem, /* I - number of values to read */
543 void *nulval, /* I - value for undefined pixels */
544 void *array, /* O - array of values that are returned */
545 int *anynul, /* O - set to 1 if any values are null; else 0 */
546 int *status) /* IO - error status */
547 /*
548 Read an array of values from the primary array. The datatype of the
549 input array is defined by the 2nd argument. Data conversion
550 and scaling will be performed if necessary (e.g, if the datatype of
551 the FITS array is not the same as the array being read).
552 Undefined elements will be set equal to NULVAL, unless NULVAL=0
553 in which case no checking for undefined values will be performed.
554 ANYNUL is returned with a value of .true. if any pixels are undefined.
555 */
556 {
557
558 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
559 return(*status);
560
561 /*
562 the primary array is represented as a binary table:
563 each group of the primary array is a row in the table,
564 where the first column contains the group parameters
565 and the second column contains the image itself.
566 */
567
568 if (datatype == TBYTE)
569 {
570 if (nulval == 0)
571 ffgpvb(fptr, 1, firstelem, nelem, 0,
572 (unsigned char *) array, anynul, status);
573 else
574 ffgpvb(fptr, 1, firstelem, nelem, *(unsigned char *) nulval,
575 (unsigned char *) array, anynul, status);
576 }
577 else if (datatype == TSBYTE)
578 {
579 if (nulval == 0)
580 ffgpvsb(fptr, 1, firstelem, nelem, 0,
581 (signed char *) array, anynul, status);
582 else
583 ffgpvsb(fptr, 1, firstelem, nelem, *(signed char *) nulval,
584 (signed char *) array, anynul, status);
585 }
586 else if (datatype == TUSHORT)
587 {
588 if (nulval == 0)
589 ffgpvui(fptr, 1, firstelem, nelem, 0,
590 (unsigned short *) array, anynul, status);
591 else
592 ffgpvui(fptr, 1, firstelem, nelem, *(unsigned short *) nulval,
593 (unsigned short *) array, anynul, status);
594 }
595 else if (datatype == TSHORT)
596 {
597 if (nulval == 0)
598 ffgpvi(fptr, 1, firstelem, nelem, 0,
599 (short *) array, anynul, status);
600 else
601 ffgpvi(fptr, 1, firstelem, nelem, *(short *) nulval,
602 (short *) array, anynul, status);
603 }
604 else if (datatype == TUINT)
605 {
606 if (nulval == 0)
607 ffgpvuk(fptr, 1, firstelem, nelem, 0,
608 (unsigned int *) array, anynul, status);
609 else
610 ffgpvuk(fptr, 1, firstelem, nelem, *(unsigned int *) nulval,
611 (unsigned int *) array, anynul, status);
612 }
613 else if (datatype == TINT)
614 {
615 if (nulval == 0)
616 ffgpvk(fptr, 1, firstelem, nelem, 0,
617 (int *) array, anynul, status);
618 else
619 ffgpvk(fptr, 1, firstelem, nelem, *(int *) nulval,
620 (int *) array, anynul, status);
621 }
622 else if (datatype == TULONG)
623 {
624 if (nulval == 0)
625 ffgpvuj(fptr, 1, firstelem, nelem, 0,
626 (unsigned long *) array, anynul, status);
627 else
628 ffgpvuj(fptr, 1, firstelem, nelem, *(unsigned long *) nulval,
629 (unsigned long *) array, anynul, status);
630 }
631 else if (datatype == TLONG)
632 {
633 if (nulval == 0)
634 ffgpvj(fptr, 1, firstelem, nelem, 0,
635 (long *) array, anynul, status);
636 else
637 ffgpvj(fptr, 1, firstelem, nelem, *(long *) nulval,
638 (long *) array, anynul, status);
639 }
640 else if (datatype == TLONGLONG)
641 {
642 if (nulval == 0)
643 ffgpvjj(fptr, 1, firstelem, nelem, 0,
644 (LONGLONG *) array, anynul, status);
645 else
646 ffgpvjj(fptr, 1, firstelem, nelem, *(LONGLONG *) nulval,
647 (LONGLONG *) array, anynul, status);
648 }
649 else if (datatype == TFLOAT)
650 {
651 if (nulval == 0)
652 ffgpve(fptr, 1, firstelem, nelem, 0,
653 (float *) array, anynul, status);
654 else
655 ffgpve(fptr, 1, firstelem, nelem, *(float *) nulval,
656 (float *) array, anynul, status);
657 }
658 else if (datatype == TDOUBLE)
659 {
660 if (nulval == 0)
661 ffgpvd(fptr, 1, firstelem, nelem, 0,
662 (double *) array, anynul, status);
663 else
664 {
665 ffgpvd(fptr, 1, firstelem, nelem, *(double *) nulval,
666 (double *) array, anynul, status);
667 }
668 }
669 else
670 *status = BAD_DATATYPE;
671
672 return(*status);
673 }
674 /*--------------------------------------------------------------------------*/
ffgpf(fitsfile * fptr,int datatype,LONGLONG firstelem,LONGLONG nelem,void * array,char * nullarray,int * anynul,int * status)675 int ffgpf( fitsfile *fptr, /* I - FITS file pointer */
676 int datatype, /* I - datatype of the value */
677 LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
678 LONGLONG nelem, /* I - number of values to read */
679 void *array, /* O - array of values that are returned */
680 char *nullarray, /* O - array of null value flags */
681 int *anynul, /* O - set to 1 if any values are null; else 0 */
682 int *status) /* IO - error status */
683 /*
684 Read an array of values from the primary array. The datatype of the
685 input array is defined by the 2nd argument. Data conversion
686 and scaling will be performed if necessary (e.g, if the datatype of
687 the FITS array is not the same as the array being read).
688 The nullarray values will = 1 if the corresponding array value is null.
689 ANYNUL is returned with a value of .true. if any pixels are undefined.
690 */
691 {
692
693 if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
694 return(*status);
695
696 /*
697 the primary array is represented as a binary table:
698 each group of the primary array is a row in the table,
699 where the first column contains the group parameters
700 and the second column contains the image itself.
701 */
702
703 if (datatype == TBYTE)
704 {
705 ffgpfb(fptr, 1, firstelem, nelem,
706 (unsigned char *) array, nullarray, anynul, status);
707 }
708 else if (datatype == TSBYTE)
709 {
710 ffgpfsb(fptr, 1, firstelem, nelem,
711 (signed char *) array, nullarray, anynul, status);
712 }
713 else if (datatype == TUSHORT)
714 {
715 ffgpfui(fptr, 1, firstelem, nelem,
716 (unsigned short *) array, nullarray, anynul, status);
717 }
718 else if (datatype == TSHORT)
719 {
720 ffgpfi(fptr, 1, firstelem, nelem,
721 (short *) array, nullarray, anynul, status);
722 }
723 else if (datatype == TUINT)
724 {
725 ffgpfuk(fptr, 1, firstelem, nelem,
726 (unsigned int *) array, nullarray, anynul, status);
727 }
728 else if (datatype == TINT)
729 {
730 ffgpfk(fptr, 1, firstelem, nelem,
731 (int *) array, nullarray, anynul, status);
732 }
733 else if (datatype == TULONG)
734 {
735 ffgpfuj(fptr, 1, firstelem, nelem,
736 (unsigned long *) array, nullarray, anynul, status);
737 }
738 else if (datatype == TLONG)
739 {
740 ffgpfj(fptr, 1, firstelem, nelem,
741 (long *) array, nullarray, anynul, status);
742 }
743 else if (datatype == TLONGLONG)
744 {
745 ffgpfjj(fptr, 1, firstelem, nelem,
746 (LONGLONG *) array, nullarray, anynul, status);
747 }
748 else if (datatype == TFLOAT)
749 {
750 ffgpfe(fptr, 1, firstelem, nelem,
751 (float *) array, nullarray, anynul, status);
752 }
753 else if (datatype == TDOUBLE)
754 {
755 ffgpfd(fptr, 1, firstelem, nelem,
756 (double *) array, nullarray, anynul, status);
757 }
758 else
759 *status = BAD_DATATYPE;
760
761 return(*status);
762 }
763 /*--------------------------------------------------------------------------*/
ffgcv(fitsfile * fptr,int datatype,int colnum,LONGLONG firstrow,LONGLONG firstelem,LONGLONG nelem,void * nulval,void * array,int * anynul,int * status)764 int ffgcv( fitsfile *fptr, /* I - FITS file pointer */
765 int datatype, /* I - datatype of the value */
766 int colnum, /* I - number of column to write (1 = 1st col) */
767 LONGLONG firstrow, /* I - first row to write (1 = 1st row) */
768 LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
769 LONGLONG nelem, /* I - number of values to read */
770 void *nulval, /* I - value for undefined pixels */
771 void *array, /* O - array of values that are returned */
772 int *anynul, /* O - set to 1 if any values are null; else 0 */
773 int *status) /* IO - error status */
774 /*
775 Read an array of values from a table column. The datatype of the
776 input array is defined by the 2nd argument. Data conversion
777 and scaling will be performed if necessary (e.g, if the datatype of
778 the FITS array is not the same as the array being read).
779 Undefined elements will be set equal to NULVAL, unless NULVAL=0
780 in which case no checking for undefined values will be performed.
781 ANYNUL is returned with a value of true if any pixels are undefined.
782 */
783 {
784 char cdummy[2];
785
786 if (*status > 0) /* inherit input status value if > 0 */
787 return(*status);
788
789 if (datatype == TBIT)
790 {
791 ffgcx(fptr, colnum, firstrow, firstelem, nelem, (char *) array, status);
792 }
793 else if (datatype == TBYTE)
794 {
795 if (nulval == 0)
796 ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
797 (unsigned char *) array, cdummy, anynul, status);
798 else
799 ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(unsigned char *)
800 nulval, (unsigned char *) array, cdummy, anynul, status);
801 }
802 else if (datatype == TSBYTE)
803 {
804 if (nulval == 0)
805 ffgclsb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
806 (signed char *) array, cdummy, anynul, status);
807 else
808 ffgclsb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(signed char *)
809 nulval, (signed char *) array, cdummy, anynul, status);
810 }
811 else if (datatype == TUSHORT)
812 {
813 if (nulval == 0)
814 ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
815 (unsigned short *) array, cdummy, anynul, status);
816 else
817 ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
818 *(unsigned short *) nulval,
819 (unsigned short *) array, cdummy, anynul, status);
820 }
821 else if (datatype == TSHORT)
822 {
823 if (nulval == 0)
824 ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
825 (short *) array, cdummy, anynul, status);
826 else
827 ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(short *)
828 nulval, (short *) array, cdummy, anynul, status);
829 }
830 else if (datatype == TUINT)
831 {
832 if (nulval == 0)
833 ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
834 (unsigned int *) array, cdummy, anynul, status);
835 else
836 ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
837 *(unsigned int *) nulval, (unsigned int *) array, cdummy, anynul,
838 status);
839 }
840 else if (datatype == TINT)
841 {
842 if (nulval == 0)
843 ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
844 (int *) array, cdummy, anynul, status);
845 else
846 ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(int *)
847 nulval, (int *) array, cdummy, anynul, status);
848 }
849 else if (datatype == TULONG)
850 {
851 if (nulval == 0)
852 ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
853 (unsigned long *) array, cdummy, anynul, status);
854 else
855 ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
856 *(unsigned long *) nulval,
857 (unsigned long *) array, cdummy, anynul, status);
858 }
859 else if (datatype == TLONG)
860 {
861 if (nulval == 0)
862 ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
863 (long *) array, cdummy, anynul, status);
864 else
865 ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(long *)
866 nulval, (long *) array, cdummy, anynul, status);
867 }
868 else if (datatype == TLONGLONG)
869 {
870 if (nulval == 0)
871 ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
872 (LONGLONG *) array, cdummy, anynul, status);
873 else
874 ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(LONGLONG *)
875 nulval, (LONGLONG *) array, cdummy, anynul, status);
876 }
877 else if (datatype == TFLOAT)
878 {
879 if (nulval == 0)
880 ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0.,
881 (float *) array, cdummy, anynul, status);
882 else
883 ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(float *)
884 nulval,(float *) array, cdummy, anynul, status);
885 }
886 else if (datatype == TDOUBLE)
887 {
888 if (nulval == 0)
889 ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0.,
890 (double *) array, cdummy, anynul, status);
891 else
892 ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(double *)
893 nulval, (double *) array, cdummy, anynul, status);
894 }
895 else if (datatype == TCOMPLEX)
896 {
897 if (nulval == 0)
898 ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
899 1, 1, 0., (float *) array, cdummy, anynul, status);
900 else
901 ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
902 1, 1, *(float *) nulval, (float *) array, cdummy, anynul, status);
903 }
904 else if (datatype == TDBLCOMPLEX)
905 {
906 if (nulval == 0)
907 ffgcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
908 1, 1, 0., (double *) array, cdummy, anynul, status);
909 else
910 ffgcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
911 1, 1, *(double *) nulval, (double *) array, cdummy, anynul, status);
912 }
913
914 else if (datatype == TLOGICAL)
915 {
916 if (nulval == 0)
917 ffgcll(fptr, colnum, firstrow, firstelem, nelem, 1, 0,
918 (char *) array, cdummy, anynul, status);
919 else
920 ffgcll(fptr, colnum, firstrow, firstelem, nelem, 1, *(char *) nulval,
921 (char *) array, cdummy, anynul, status);
922 }
923 else if (datatype == TSTRING)
924 {
925 if (nulval == 0)
926 {
927 cdummy[0] = '\0';
928 ffgcls(fptr, colnum, firstrow, firstelem, nelem, 1,
929 cdummy, (char **) array, cdummy, anynul, status);
930 }
931 else
932 ffgcls(fptr, colnum, firstrow, firstelem, nelem, 1, (char *)
933 nulval, (char **) array, cdummy, anynul, status);
934 }
935 else
936 *status = BAD_DATATYPE;
937
938 return(*status);
939 }
940 /*--------------------------------------------------------------------------*/
ffgcf(fitsfile * fptr,int datatype,int colnum,LONGLONG firstrow,LONGLONG firstelem,LONGLONG nelem,void * array,char * nullarray,int * anynul,int * status)941 int ffgcf( fitsfile *fptr, /* I - FITS file pointer */
942 int datatype, /* I - datatype of the value */
943 int colnum, /* I - number of column to write (1 = 1st col) */
944 LONGLONG firstrow, /* I - first row to write (1 = 1st row) */
945 LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
946 LONGLONG nelem, /* I - number of values to read */
947 void *array, /* O - array of values that are returned */
948 char *nullarray, /* O - array of null value flags */
949 int *anynul, /* O - set to 1 if any values are null; else 0 */
950 int *status) /* IO - error status */
951 /*
952 Read an array of values from a table column. The datatype of the
953 input array is defined by the 2nd argument. Data conversion
954 and scaling will be performed if necessary (e.g, if the datatype of
955 the FITS array is not the same as the array being read).
956 ANYNUL is returned with a value of true if any pixels are undefined.
957 */
958 {
959 double nulval = 0.;
960 char cnulval[2];
961
962 if (*status > 0) /* inherit input status value if > 0 */
963 return(*status);
964
965 if (datatype == TBIT)
966 {
967 ffgcx(fptr, colnum, firstrow, firstelem, nelem, (char *) array, status);
968 }
969 else if (datatype == TBYTE)
970 {
971 ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (unsigned char )
972 nulval, (unsigned char *) array, nullarray, anynul, status);
973 }
974 else if (datatype == TSBYTE)
975 {
976 ffgclsb(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (signed char )
977 nulval, (signed char *) array, nullarray, anynul, status);
978 }
979 else if (datatype == TUSHORT)
980 {
981 ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
982 (unsigned short ) nulval,
983 (unsigned short *) array, nullarray, anynul, status);
984 }
985 else if (datatype == TSHORT)
986 {
987 ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (short )
988 nulval, (short *) array, nullarray, anynul, status);
989 }
990 else if (datatype == TUINT)
991 {
992 ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
993 (unsigned int ) nulval, (unsigned int *) array, nullarray, anynul,
994 status);
995 }
996 else if (datatype == TINT)
997 {
998 ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (int )
999 nulval, (int *) array, nullarray, anynul, status);
1000 }
1001 else if (datatype == TULONG)
1002 {
1003 ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
1004 (unsigned long ) nulval,
1005 (unsigned long *) array, nullarray, anynul, status);
1006 }
1007 else if (datatype == TLONG)
1008 {
1009 ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (long )
1010 nulval, (long *) array, nullarray, anynul, status);
1011 }
1012 else if (datatype == TLONGLONG)
1013 {
1014 ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (LONGLONG )
1015 nulval, (LONGLONG *) array, nullarray, anynul, status);
1016 }
1017 else if (datatype == TFLOAT)
1018 {
1019 ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 2, (float )
1020 nulval,(float *) array, nullarray, anynul, status);
1021 }
1022 else if (datatype == TDOUBLE)
1023 {
1024 ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
1025 nulval, (double *) array, nullarray, anynul, status);
1026 }
1027 else if (datatype == TCOMPLEX)
1028 {
1029 ffgcfc(fptr, colnum, firstrow, firstelem, nelem,
1030 (float *) array, nullarray, anynul, status);
1031 }
1032 else if (datatype == TDBLCOMPLEX)
1033 {
1034 ffgcfm(fptr, colnum, firstrow, firstelem, nelem,
1035 (double *) array, nullarray, anynul, status);
1036 }
1037
1038 else if (datatype == TLOGICAL)
1039 {
1040 ffgcll(fptr, colnum, firstrow, firstelem, nelem, 2, (char ) nulval,
1041 (char *) array, nullarray, anynul, status);
1042 }
1043 else if (datatype == TSTRING)
1044 {
1045 ffgcls(fptr, colnum, firstrow, firstelem, nelem, 2,
1046 cnulval, (char **) array, nullarray, anynul, status);
1047 }
1048 else
1049 *status = BAD_DATATYPE;
1050
1051 return(*status);
1052 }
1053
1054