1
/* This file, getcolui.c, contains routines that read data elements from */
2
/* a FITS image or table, with unsigned short datatype. */
4
/* The FITSIO software was written by William Pence at the High Energy */
5
/* Astrophysic Science Archive Research Center (HEASARC) at the NASA */
6
/* Goddard Space Flight Center. */
14
/*--------------------------------------------------------------------------*/
15
int ffgpvui( fitsfile *fptr, /* I - FITS file pointer */
16
long group, /* I - group to read (1 = 1st group) */
17
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
18
LONGLONG nelem, /* I - number of values to read */
19
unsigned short nulval, /* I - value for undefined pixels */
20
unsigned short *array, /* O - array of values that are returned */
21
int *anynul, /* O - set to 1 if any values are null; else 0 */
22
int *status) /* IO - error status */
24
Read an array of values from the primary array. Data conversion
25
and scaling will be performed if necessary (e.g, if the datatype of
26
the FITS array is not the same as the array being read).
27
Undefined elements will be set equal to NULVAL, unless NULVAL=0
28
in which case no checking for undefined values will be performed.
29
ANYNUL is returned with a value of .true. if any pixels are undefined.
35
unsigned short nullvalue;
37
if (fits_is_compressed_image(fptr, status))
39
/* this is a compressed image in a binary table */
40
nullvalue = nulval; /* set local variable */
42
fits_read_compressed_pixels(fptr, TUSHORT, firstelem, nelem,
43
nullcheck, &nullvalue, array, NULL, anynul, status);
48
the primary array is represented as a binary table:
49
each group of the primary array is a row in the table,
50
where the first column contains the group parameters
51
and the second column contains the image itself.
54
row=maxvalue(1,group);
56
ffgclui(fptr, 2, row, firstelem, nelem, 1, 1, nulval,
57
array, &cdummy, anynul, status);
60
/*--------------------------------------------------------------------------*/
61
int ffgpfui( fitsfile *fptr, /* I - FITS file pointer */
62
long group, /* I - group to read (1 = 1st group) */
63
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
64
LONGLONG nelem, /* I - number of values to read */
65
unsigned short *array, /* O - array of values that are returned */
66
char *nularray, /* O - array of null pixel flags */
67
int *anynul, /* O - set to 1 if any values are null; else 0 */
68
int *status) /* IO - error status */
70
Read an array of values from the primary array. Data conversion
71
and scaling will be performed if necessary (e.g, if the datatype of
72
the FITS array is not the same as the array being read).
73
Any undefined pixels in the returned array will be set = 0 and the
74
corresponding nularray value will be set = 1.
75
ANYNUL is returned with a value of .true. if any pixels are undefined.
81
if (fits_is_compressed_image(fptr, status))
83
/* this is a compressed image in a binary table */
85
fits_read_compressed_pixels(fptr, TUSHORT, firstelem, nelem,
86
nullcheck, NULL, array, nularray, anynul, status);
91
the primary array is represented as a binary table:
92
each group of the primary array is a row in the table,
93
where the first column contains the group parameters
94
and the second column contains the image itself.
97
row=maxvalue(1,group);
99
ffgclui(fptr, 2, row, firstelem, nelem, 1, 2, 0,
100
array, nularray, anynul, status);
103
/*--------------------------------------------------------------------------*/
104
int ffg2dui(fitsfile *fptr, /* I - FITS file pointer */
105
long group, /* I - group to read (1 = 1st group) */
106
unsigned short nulval, /* set undefined pixels equal to this */
107
LONGLONG ncols, /* I - number of pixels in each row of array */
108
LONGLONG naxis1, /* I - FITS image NAXIS1 value */
109
LONGLONG naxis2, /* I - FITS image NAXIS2 value */
110
unsigned short *array, /* O - array to be filled and returned */
111
int *anynul, /* O - set to 1 if any values are null; else 0 */
112
int *status) /* IO - error status */
114
Read an entire 2-D array of values to the primary array. Data conversion
115
and scaling will be performed if necessary (e.g, if the datatype of the
116
FITS array is not the same as the array being read). Any null
117
values in the array will be set equal to the value of nulval, unless
118
nulval = 0 in which case no null checking will be performed.
121
/* call the 3D reading routine, with the 3rd dimension = 1 */
123
ffg3dui(fptr, group, nulval, ncols, naxis2, naxis1, naxis2, 1, array,
128
/*--------------------------------------------------------------------------*/
129
int ffg3dui(fitsfile *fptr, /* I - FITS file pointer */
130
long group, /* I - group to read (1 = 1st group) */
131
unsigned short nulval, /* set undefined pixels equal to this */
132
LONGLONG ncols, /* I - number of pixels in each row of array */
133
LONGLONG nrows, /* I - number of rows in each plane of array */
134
LONGLONG naxis1, /* I - FITS image NAXIS1 value */
135
LONGLONG naxis2, /* I - FITS image NAXIS2 value */
136
LONGLONG naxis3, /* I - FITS image NAXIS3 value */
137
unsigned short *array, /* O - array to be filled and returned */
138
int *anynul, /* O - set to 1 if any values are null; else 0 */
139
int *status) /* IO - error status */
141
Read an entire 3-D array of values to the primary array. Data conversion
142
and scaling will be performed if necessary (e.g, if the datatype of the
143
FITS array is not the same as the array being read). Any null
144
values in the array will be set equal to the value of nulval, unless
145
nulval = 0 in which case no null checking will be performed.
148
long tablerow, ii, jj;
151
long inc[] = {1,1,1};
152
LONGLONG fpixel[] = {1,1,1}, nfits, narray;
154
unsigned short nullvalue;
156
if (fits_is_compressed_image(fptr, status))
158
/* this is a compressed image in a binary table */
163
nullvalue = nulval; /* set local variable */
165
fits_read_compressed_img(fptr, TUSHORT, fpixel, lpixel, inc,
166
nullcheck, &nullvalue, array, NULL, anynul, status);
171
the primary array is represented as a binary table:
172
each group of the primary array is a row in the table,
173
where the first column contains the group parameters
174
and the second column contains the image itself.
176
tablerow=maxvalue(1,group);
178
if (ncols == naxis1 && nrows == naxis2) /* arrays have same size? */
180
/* all the image pixels are contiguous, so read all at once */
181
ffgclui(fptr, 2, tablerow, 1, naxis1 * naxis2 * naxis3, 1, 1, nulval,
182
array, &cdummy, anynul, status);
186
if (ncols < naxis1 || nrows < naxis2)
187
return(*status = BAD_DIMEN);
189
nfits = 1; /* next pixel in FITS image to read */
190
narray = 0; /* next pixel in output array to be filled */
192
/* loop over naxis3 planes in the data cube */
193
for (jj = 0; jj < naxis3; jj++)
195
/* loop over the naxis2 rows in the FITS image, */
196
/* reading naxis1 pixels to each row */
198
for (ii = 0; ii < naxis2; ii++)
200
if (ffgclui(fptr, 2, tablerow, nfits, naxis1, 1, 1, nulval,
201
&array[narray], &cdummy, anynul, status) > 0)
207
narray += (nrows - naxis2) * ncols;
212
/*--------------------------------------------------------------------------*/
213
int ffgsvui(fitsfile *fptr, /* I - FITS file pointer */
214
int colnum, /* I - number of the column to read (1 = 1st) */
215
int naxis, /* I - number of dimensions in the FITS array */
216
long *naxes, /* I - size of each dimension */
217
long *blc, /* I - 'bottom left corner' of the subsection */
218
long *trc, /* I - 'top right corner' of the subsection */
219
long *inc, /* I - increment to be applied in each dimension */
220
unsigned short nulval, /* I - value to set undefined pixels */
221
unsigned short *array, /* O - array to be filled and returned */
222
int *anynul, /* O - set to 1 if any values are null; else 0 */
223
int *status) /* IO - error status */
225
Read a subsection of data values from an image or a table column.
226
This routine is set up to handle a maximum of nine dimensions.
229
long ii,i0, i1,i2,i3,i4,i5,i6,i7,i8,row,rstr,rstp,rinc;
230
long str[9],stp[9],incr[9];
231
long nelem, nultyp, ninc, numcol;
232
LONGLONG felem, dsize[10], blcll[9], trcll[9];
234
char ldummy, msg[FLEN_ERRMSG];
236
unsigned short nullvalue;
238
if (naxis < 1 || naxis > 9)
240
sprintf(msg, "NAXIS = %d in call to ffgsvui is out of range", naxis);
242
return(*status = BAD_DIMEN);
245
if (fits_is_compressed_image(fptr, status))
247
/* this is a compressed image in a binary table */
249
for (ii=0; ii < naxis; ii++) {
254
nullvalue = nulval; /* set local variable */
256
fits_read_compressed_img(fptr, TUSHORT, blcll, trcll, inc,
257
nullcheck, &nullvalue, array, NULL, anynul, status);
262
if this is a primary array, then the input COLNUM parameter should
263
be interpreted as the row number, and we will alway read the image
264
data from column 2 (any group parameters are in column 1).
266
if (ffghdt(fptr, &hdutype, status) > 0)
269
if (hdutype == IMAGE_HDU)
271
/* this is a primary array, or image extension */
287
/* this is a table, so the row info is in the (naxis+1) elements */
299
for (ii = 0; ii < 9; ii++)
307
for (ii = 0; ii < naxis; ii++)
309
if (trc[ii] < blc[ii])
311
sprintf(msg, "ffgsvui: illegal range specified for axis %ld", ii + 1);
313
return(*status = BAD_PIX_NUM);
319
dsize[ii + 1] = dsize[ii] * naxes[ii];
322
if (naxis == 1 && naxes[0] == 1)
324
/* This is not a vector column, so read all the rows at once */
325
nelem = (rstp - rstr) / rinc + 1;
331
/* have to read each row individually, in all dimensions */
332
nelem = (stp[0] - str[0]) / inc[0] + 1;
336
for (row = rstr; row <= rstp; row += rinc)
338
for (i8 = str[8]; i8 <= stp[8]; i8 += incr[8])
340
for (i7 = str[7]; i7 <= stp[7]; i7 += incr[7])
342
for (i6 = str[6]; i6 <= stp[6]; i6 += incr[6])
344
for (i5 = str[5]; i5 <= stp[5]; i5 += incr[5])
346
for (i4 = str[4]; i4 <= stp[4]; i4 += incr[4])
348
for (i3 = str[3]; i3 <= stp[3]; i3 += incr[3])
350
for (i2 = str[2]; i2 <= stp[2]; i2 += incr[2])
352
for (i1 = str[1]; i1 <= stp[1]; i1 += incr[1])
354
felem=str[0] + (i1 - 1) * dsize[1] + (i2 - 1) * dsize[2] +
355
(i3 - 1) * dsize[3] + (i4 - 1) * dsize[4] +
356
(i5 - 1) * dsize[5] + (i6 - 1) * dsize[6] +
357
(i7 - 1) * dsize[7] + (i8 - 1) * dsize[8];
358
if ( ffgclui(fptr, numcol, row, felem, nelem, ninc, nultyp,
359
nulval, &array[i0], &ldummy, &anyf, status) > 0)
377
/*--------------------------------------------------------------------------*/
378
int ffgsfui(fitsfile *fptr, /* I - FITS file pointer */
379
int colnum, /* I - number of the column to read (1 = 1st) */
380
int naxis, /* I - number of dimensions in the FITS array */
381
long *naxes, /* I - size of each dimension */
382
long *blc, /* I - 'bottom left corner' of the subsection */
383
long *trc, /* I - 'top right corner' of the subsection */
384
long *inc, /* I - increment to be applied in each dimension */
385
unsigned short *array, /* O - array to be filled and returned */
386
char *flagval, /* O - set to 1 if corresponding value is null */
387
int *anynul, /* O - set to 1 if any values are null; else 0 */
388
int *status) /* IO - error status */
390
Read a subsection of data values from an image or a table column.
391
This routine is set up to handle a maximum of nine dimensions.
394
long ii,i0, i1,i2,i3,i4,i5,i6,i7,i8,row,rstr,rstp,rinc;
395
long str[9],stp[9],incr[9],dsize[10];
396
LONGLONG blcll[9], trcll[9];
397
long felem, nelem, nultyp, ninc, numcol;
399
unsigned short nulval = 0;
400
char msg[FLEN_ERRMSG];
403
if (naxis < 1 || naxis > 9)
405
sprintf(msg, "NAXIS = %d in call to ffgsvi is out of range", naxis);
407
return(*status = BAD_DIMEN);
410
if (fits_is_compressed_image(fptr, status))
412
/* this is a compressed image in a binary table */
414
for (ii=0; ii < naxis; ii++) {
419
fits_read_compressed_img(fptr, TUSHORT, blcll, trcll, inc,
420
nullcheck, NULL, array, flagval, anynul, status);
425
if this is a primary array, then the input COLNUM parameter should
426
be interpreted as the row number, and we will alway read the image
427
data from column 2 (any group parameters are in column 1).
429
if (ffghdt(fptr, &hdutype, status) > 0)
432
if (hdutype == IMAGE_HDU)
434
/* this is a primary array, or image extension */
450
/* this is a table, so the row info is in the (naxis+1) elements */
462
for (ii = 0; ii < 9; ii++)
470
for (ii = 0; ii < naxis; ii++)
472
if (trc[ii] < blc[ii])
474
sprintf(msg, "ffgsvi: illegal range specified for axis %ld", ii + 1);
476
return(*status = BAD_PIX_NUM);
482
dsize[ii + 1] = dsize[ii] * naxes[ii];
485
if (naxis == 1 && naxes[0] == 1)
487
/* This is not a vector column, so read all the rows at once */
488
nelem = (rstp - rstr) / rinc + 1;
494
/* have to read each row individually, in all dimensions */
495
nelem = (stp[0] - str[0]) / inc[0] + 1;
499
for (row = rstr; row <= rstp; row += rinc)
501
for (i8 = str[8]; i8 <= stp[8]; i8 += incr[8])
503
for (i7 = str[7]; i7 <= stp[7]; i7 += incr[7])
505
for (i6 = str[6]; i6 <= stp[6]; i6 += incr[6])
507
for (i5 = str[5]; i5 <= stp[5]; i5 += incr[5])
509
for (i4 = str[4]; i4 <= stp[4]; i4 += incr[4])
511
for (i3 = str[3]; i3 <= stp[3]; i3 += incr[3])
513
for (i2 = str[2]; i2 <= stp[2]; i2 += incr[2])
515
for (i1 = str[1]; i1 <= stp[1]; i1 += incr[1])
517
felem=str[0] + (i1 - 1) * dsize[1] + (i2 - 1) * dsize[2] +
518
(i3 - 1) * dsize[3] + (i4 - 1) * dsize[4] +
519
(i5 - 1) * dsize[5] + (i6 - 1) * dsize[6] +
520
(i7 - 1) * dsize[7] + (i8 - 1) * dsize[8];
522
if ( ffgclui(fptr, numcol, row, felem, nelem, ninc, nultyp,
523
nulval, &array[i0], &flagval[i0], &anyf, status) > 0)
541
/*--------------------------------------------------------------------------*/
542
int ffggpui( fitsfile *fptr, /* I - FITS file pointer */
543
long group, /* I - group to read (1 = 1st group) */
544
long firstelem, /* I - first vector element to read (1 = 1st) */
545
long nelem, /* I - number of values to read */
546
unsigned short *array, /* O - array of values that are returned */
547
int *status) /* IO - error status */
549
Read an array of group parameters from the primary array. 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).
558
the primary array is represented as a binary table:
559
each group of the primary array is a row in the table,
560
where the first column contains the group parameters
561
and the second column contains the image itself.
564
row=maxvalue(1,group);
566
ffgclui(fptr, 1, row, firstelem, nelem, 1, 1, 0,
567
array, &cdummy, &idummy, status);
570
/*--------------------------------------------------------------------------*/
571
int ffgcvui(fitsfile *fptr, /* I - FITS file pointer */
572
int colnum, /* I - number of column to read (1 = 1st col) */
573
LONGLONG firstrow, /* I - first row to read (1 = 1st row) */
574
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
575
LONGLONG nelem, /* I - number of values to read */
576
unsigned short nulval, /* I - value for null pixels */
577
unsigned short *array, /* O - array of values that are read */
578
int *anynul, /* O - set to 1 if any values are null; else 0 */
579
int *status) /* IO - error status */
581
Read an array of values from a column in the current FITS HDU. Automatic
582
datatype conversion will be performed if the datatype of the column does not
583
match the datatype of the array parameter. The output values will be scaled
584
by the FITS TSCALn and TZEROn values if these values have been defined.
585
Any undefined pixels will be set equal to the value of 'nulval' unless
586
nulval = 0 in which case no checks for undefined pixels will be made.
591
ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 1, nulval,
592
array, &cdummy, anynul, status);
595
/*--------------------------------------------------------------------------*/
596
int ffgcfui(fitsfile *fptr, /* I - FITS file pointer */
597
int colnum, /* I - number of column to read (1 = 1st col) */
598
LONGLONG firstrow, /* I - first row to read (1 = 1st row) */
599
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
600
LONGLONG nelem, /* I - number of values to read */
601
unsigned short *array, /* O - array of values that are read */
602
char *nularray, /* O - array of flags: 1 if null pixel; else 0 */
603
int *anynul, /* O - set to 1 if any values are null; else 0 */
604
int *status) /* IO - error status */
606
Read an array of values from a column in the current FITS HDU. Automatic
607
datatype conversion will be performed if the datatype of the column does not
608
match the datatype of the array parameter. The output values will be scaled
609
by the FITS TSCALn and TZEROn values if these values have been defined.
610
Nularray will be set = 1 if the corresponding array pixel is undefined,
611
otherwise nularray will = 0.
614
unsigned short dummy = 0;
616
ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 2, dummy,
617
array, nularray, anynul, status);
620
/*--------------------------------------------------------------------------*/
621
int ffgclui( fitsfile *fptr, /* I - FITS file pointer */
622
int colnum, /* I - number of column to read (1 = 1st col) */
623
LONGLONG firstrow, /* I - first row to read (1 = 1st row) */
624
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
625
LONGLONG nelem, /* I - number of values to read */
626
long elemincre, /* I - pixel increment; e.g., 2 = every other */
627
int nultyp, /* I - null value handling code: */
628
/* 1: set undefined pixels = nulval */
629
/* 2: set nularray=1 for undefined pixels */
630
unsigned short nulval, /* I - value for null pixels if nultyp = 1 */
631
unsigned short *array, /* O - array of values that are read */
632
char *nularray, /* O - array of flags = 1 if nultyp = 2 */
633
int *anynul, /* O - set to 1 if any values are null; else 0 */
634
int *status) /* IO - error status */
636
Read an array of values from a column in the current FITS HDU.
637
The column number may refer to a real column in an ASCII or binary table,
638
or it may refer be a virtual column in a 1 or more grouped FITS primary
639
array or image extension. FITSIO treats a primary array as a binary table
640
with 2 vector columns: the first column contains the group parameters (often
641
with length = 0) and the second column contains the array of image pixels.
642
Each row of the table represents a group in the case of multigroup FITS
645
The output array of values will be converted from the datatype of the column
646
and will be scaled by the FITS TSCALn and TZEROn values if necessary.
649
double scale, zero, power = 1., dtemp;
650
int tcode, maxelem2, hdutype, xcode, decimals;
652
long ii, xwidth, ntodo;
654
LONGLONG repeat, startpos, elemnum, readptr, tnull;
655
LONGLONG rowlen, rownum, remain, next, rowincre, maxelem;
658
char snull[20]; /* the FITS null value if reading from ASCII table */
660
double cbuff[DBUFFSIZE / sizeof(double)]; /* align cbuff on word boundary */
663
if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
672
memset(nularray, 0, (size_t) nelem); /* initialize nullarray */
674
/*---------------------------------------------------*/
675
/* Check input and get parameters about the column: */
676
/*---------------------------------------------------*/
677
if ( ffgcprll( fptr, colnum, firstrow, firstelem, nelem, 0, &scale, &zero,
678
tform, &twidth, &tcode, &maxelem2, &startpos, &elemnum, &incre,
679
&repeat, &rowlen, &hdutype, &tnull, snull, status) > 0 )
683
incre *= elemincre; /* multiply incre to just get every nth pixel */
685
if (tcode == TSTRING) /* setup for ASCII tables */
687
/* get the number of implied decimal places if no explicit decmal point */
688
ffasfm(tform, &xcode, &xwidth, &decimals, status);
689
for(ii = 0; ii < decimals; ii++)
692
/*------------------------------------------------------------------*/
693
/* Decide whether to check for null values in the input FITS file: */
694
/*------------------------------------------------------------------*/
695
nulcheck = nultyp; /* by default check for null values in the FITS file */
697
if (nultyp == 1 && nulval == 0)
698
nulcheck = 0; /* calling routine does not want to check for nulls */
700
else if (tcode%10 == 1 && /* if reading an integer column, and */
701
tnull == NULL_UNDEFINED) /* if a null value is not defined, */
702
nulcheck = 0; /* then do not check for null values. */
704
else if (tcode == TSHORT && (tnull > SHRT_MAX || tnull < SHRT_MIN) )
705
nulcheck = 0; /* Impossible null value */
707
else if (tcode == TBYTE && (tnull > 255 || tnull < 0) )
708
nulcheck = 0; /* Impossible null value */
710
else if (tcode == TSTRING && snull[0] == ASCII_NULL_UNDEFINED)
713
/*----------------------------------------------------------------------*/
714
/* If FITS column and output data array have same datatype, then we do */
715
/* not need to use a temporary buffer to store intermediate datatype. */
716
/*----------------------------------------------------------------------*/
717
if (tcode == TSHORT) /* Special Case: */
718
{ /* no type convertion required, so read */
719
maxelem = nelem; /* data directly into output buffer. */
722
/*---------------------------------------------------------------------*/
723
/* Now read the pixels from the FITS column. If the column does not */
724
/* have the same datatype as the output array, then we have to read */
725
/* the raw values into a temporary buffer (of limited size). In */
726
/* the case of a vector colum read only 1 vector of values at a time */
727
/* then skip to the next row if more values need to be read. */
728
/* After reading the raw values, then call the fffXXYY routine to (1) */
729
/* test for undefined values, (2) convert the datatype if necessary, */
730
/* and (3) scale the values by the FITS TSCALn and TZEROn linear */
731
/* scaling parameters. */
732
/*---------------------------------------------------------------------*/
733
remain = nelem; /* remaining number of values to read */
734
next = 0; /* next element in array to be read */
735
rownum = 0; /* row number, relative to firstrow */
739
/* limit the number of pixels to read at one time to the number that
740
will fit in the buffer or to the number of pixels that remain in
741
the current vector, which ever is smaller.
743
ntodo = (long) minvalue(remain, maxelem);
744
ntodo = (long) minvalue(ntodo, ((repeat - elemnum - 1)/elemincre +1));
746
readptr = startpos + ((LONGLONG)rownum * rowlen) + (elemnum * (incre / elemincre));
751
ffgi2b(fptr, readptr, ntodo, incre,
752
(short *) &array[next], status);
753
fffi2u2((short *) &array[next], ntodo, scale,
754
zero, nulcheck, (short) tnull, nulval, &nularray[next],
755
anynul, &array[next], status);
759
ffgi8b(fptr, readptr, ntodo, incre, (long *) buffer, status);
760
fffi8u2( (LONGLONG *) buffer, ntodo, scale, zero,
761
nulcheck, tnull, nulval, &nularray[next],
762
anynul, &array[next], status);
765
ffgi1b(fptr, readptr, ntodo, incre, (unsigned char *) buffer,
767
fffi1u2((unsigned char *) buffer, ntodo, scale, zero, nulcheck,
768
(unsigned char) tnull, nulval, &nularray[next], anynul,
769
&array[next], status);
772
ffgi4b(fptr, readptr, ntodo, incre, (INT32BIT *) buffer,
774
fffi4u2((INT32BIT *) buffer, ntodo, scale, zero, nulcheck,
775
(INT32BIT) tnull, nulval, &nularray[next], anynul,
776
&array[next], status);
779
ffgr4b(fptr, readptr, ntodo, incre, (float *) buffer, status);
780
fffr4u2((float *) buffer, ntodo, scale, zero, nulcheck,
781
nulval, &nularray[next], anynul,
782
&array[next], status);
785
ffgr8b(fptr, readptr, ntodo, incre, (double *) buffer, status);
786
fffr8u2((double *) buffer, ntodo, scale, zero, nulcheck,
787
nulval, &nularray[next], anynul,
788
&array[next], status);
791
ffmbyt(fptr, readptr, REPORT_EOF, status);
793
if (incre == twidth) /* contiguous bytes */
794
ffgbyt(fptr, ntodo * twidth, buffer, status);
796
ffgbytoff(fptr, twidth, ntodo, incre - twidth, buffer,
799
fffstru2((char *) buffer, ntodo, scale, zero, twidth, power,
800
nulcheck, snull, nulval, &nularray[next], anynul,
801
&array[next], status);
804
default: /* error trap for invalid column format */
806
"Cannot read numbers from column %d which has format %s",
809
if (hdutype == ASCII_TBL)
810
return(*status = BAD_ATABLE_FORMAT);
812
return(*status = BAD_BTABLE_FORMAT);
814
} /* End of switch block */
816
/*-------------------------*/
817
/* Check for fatal error */
818
/*-------------------------*/
819
if (*status > 0) /* test for error during previous read operation */
821
dtemp = (double) next;
824
"Error reading elements %.0f thru %.0f from column %d (ffgclui).",
825
dtemp+1., dtemp+ntodo, colnum);
828
"Error reading elements %.0f thru %.0f from image (ffgclui).",
829
dtemp+1., dtemp+ntodo);
835
/*--------------------------------------------*/
836
/* increment the counters for the next loop */
837
/*--------------------------------------------*/
842
elemnum = elemnum + (ntodo * elemincre);
844
if (elemnum >= repeat) /* completed a row; start on later row */
846
rowincre = elemnum / repeat;
848
elemnum = elemnum - (rowincre * repeat);
851
} /* End of main while Loop */
854
/*--------------------------------*/
855
/* check for numerical overflow */
856
/*--------------------------------*/
857
if (*status == OVERFLOW_ERR)
860
"Numerical overflow during type conversion while reading FITS data.");
861
*status = NUM_OVERFLOW;
866
/*--------------------------------------------------------------------------*/
867
int fffi1u2(unsigned char *input, /* I - array of values to be converted */
868
long ntodo, /* I - number of elements in the array */
869
double scale, /* I - FITS TSCALn or BSCALE value */
870
double zero, /* I - FITS TZEROn or BZERO value */
871
int nullcheck, /* I - null checking code; 0 = don't check */
872
/* 1:set null pixels = nullval */
873
/* 2: if null pixel, set nullarray = 1 */
874
unsigned char tnull, /* I - value of FITS TNULLn keyword if any */
875
unsigned short nullval, /* I - set null pixels, if nullcheck = 1 */
876
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
877
int *anynull, /* O - set to 1 if any pixels are null */
878
unsigned short *output, /* O - array of converted pixels */
879
int *status) /* IO - error status */
881
Copy input to output following reading of the input from a FITS file.
882
Check for null values and do datatype conversion and scaling if required.
883
The nullcheck code value determines how any null values in the input array
884
are treated. A null value is an input pixel that is equal to tnull. If
885
nullcheck = 0, then no checking for nulls is performed and any null values
886
will be transformed just like any other pixel. If nullcheck = 1, then the
887
output pixel will be set = nullval if the corresponding input pixel is null.
888
If nullcheck = 2, then if the pixel is null then the corresponding value of
889
nullarray will be set to 1; the value of nullarray for non-null pixels
890
will = 0. The anynull parameter will be set = 1 if any of the returned
891
pixels are null, otherwise anynull will be returned with a value = 0;
897
if (nullcheck == 0) /* no null checking required */
899
if (scale == 1. && zero == 0.) /* no scaling */
901
for (ii = 0; ii < ntodo; ii++)
902
output[ii] = (unsigned short) input[ii]; /* copy input */
904
else /* must scale the data */
906
for (ii = 0; ii < ntodo; ii++)
908
dvalue = input[ii] * scale + zero;
910
if (dvalue < DUSHRT_MIN)
912
*status = OVERFLOW_ERR;
915
else if (dvalue > DUSHRT_MAX)
917
*status = OVERFLOW_ERR;
918
output[ii] = USHRT_MAX;
921
output[ii] = (unsigned short) dvalue;
925
else /* must check for null values */
927
if (scale == 1. && zero == 0.) /* no scaling */
929
for (ii = 0; ii < ntodo; ii++)
931
if (input[ii] == tnull)
935
output[ii] = nullval;
940
output[ii] = (unsigned short) input[ii];
943
else /* must scale the data */
945
for (ii = 0; ii < ntodo; ii++)
947
if (input[ii] == tnull)
951
output[ii] = nullval;
957
dvalue = input[ii] * scale + zero;
959
if (dvalue < DUSHRT_MIN)
961
*status = OVERFLOW_ERR;
964
else if (dvalue > DUSHRT_MAX)
966
*status = OVERFLOW_ERR;
967
output[ii] = USHRT_MAX;
970
output[ii] = (unsigned short) dvalue;
977
/*--------------------------------------------------------------------------*/
978
int fffi2u2(short *input, /* I - array of values to be converted */
979
long ntodo, /* I - number of elements in the array */
980
double scale, /* I - FITS TSCALn or BSCALE value */
981
double zero, /* I - FITS TZEROn or BZERO value */
982
int nullcheck, /* I - null checking code; 0 = don't check */
983
/* 1:set null pixels = nullval */
984
/* 2: if null pixel, set nullarray = 1 */
985
short tnull, /* I - value of FITS TNULLn keyword if any */
986
unsigned short nullval, /* I - set null pixels, if nullcheck = 1 */
987
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
988
int *anynull, /* O - set to 1 if any pixels are null */
989
unsigned short *output, /* O - array of converted pixels */
990
int *status) /* IO - error status */
992
Copy input to output following reading of the input from a FITS file.
993
Check for null values and do datatype conversion and scaling if required.
994
The nullcheck code value determines how any null values in the input array
995
are treated. A null value is an input pixel that is equal to tnull. If
996
nullcheck = 0, then no checking for nulls is performed and any null values
997
will be transformed just like any other pixel. If nullcheck = 1, then the
998
output pixel will be set = nullval if the corresponding input pixel is null.
999
If nullcheck = 2, then if the pixel is null then the corresponding value of
1000
nullarray will be set to 1; the value of nullarray for non-null pixels
1001
will = 0. The anynull parameter will be set = 1 if any of the returned
1002
pixels are null, otherwise anynull will be returned with a value = 0;
1008
if (nullcheck == 0) /* no null checking required */
1010
if (scale == 1. && zero == 32768.)
1012
/* Instead of adding 32768, it is more efficient */
1013
/* to just flip the sign bit with the XOR operator */
1015
for (ii = 0; ii < ntodo; ii++)
1016
output[ii] = ( *(unsigned short *) &input[ii] ) ^ 0x8000;
1018
else if (scale == 1. && zero == 0.) /* no scaling */
1020
for (ii = 0; ii < ntodo; ii++)
1024
*status = OVERFLOW_ERR;
1028
output[ii] = (unsigned short) input[ii]; /* copy input */
1031
else /* must scale the data */
1033
for (ii = 0; ii < ntodo; ii++)
1035
dvalue = input[ii] * scale + zero;
1037
if (dvalue < DUSHRT_MIN)
1039
*status = OVERFLOW_ERR;
1042
else if (dvalue > DUSHRT_MAX)
1044
*status = OVERFLOW_ERR;
1045
output[ii] = USHRT_MAX;
1048
output[ii] = (unsigned short) dvalue;
1052
else /* must check for null values */
1054
if (scale == 1. && zero == 32768.) /* no scaling */
1056
for (ii = 0; ii < ntodo; ii++)
1058
if (input[ii] == tnull)
1062
output[ii] = nullval;
1067
output[ii] = ( *(unsigned short *) &input[ii] ) ^ 0x8000;
1070
else if (scale == 1. && zero == 0.) /* no scaling */
1072
for (ii = 0; ii < ntodo; ii++)
1074
if (input[ii] == tnull)
1078
output[ii] = nullval;
1082
else if (input[ii] < 0)
1084
*status = OVERFLOW_ERR;
1088
output[ii] = (unsigned short) input[ii]; /* copy input */
1091
else /* must scale the data */
1093
for (ii = 0; ii < ntodo; ii++)
1095
if (input[ii] == tnull)
1099
output[ii] = nullval;
1105
dvalue = input[ii] * scale + zero;
1107
if (dvalue < DUSHRT_MIN)
1109
*status = OVERFLOW_ERR;
1112
else if (dvalue > DUSHRT_MAX)
1114
*status = OVERFLOW_ERR;
1115
output[ii] = USHRT_MAX;
1118
output[ii] = (unsigned short) dvalue;
1125
/*--------------------------------------------------------------------------*/
1126
int fffi4u2(INT32BIT *input, /* I - array of values to be converted */
1127
long ntodo, /* I - number of elements in the array */
1128
double scale, /* I - FITS TSCALn or BSCALE value */
1129
double zero, /* I - FITS TZEROn or BZERO value */
1130
int nullcheck, /* I - null checking code; 0 = don't check */
1131
/* 1:set null pixels = nullval */
1132
/* 2: if null pixel, set nullarray = 1 */
1133
INT32BIT tnull, /* I - value of FITS TNULLn keyword if any */
1134
unsigned short nullval, /* I - set null pixels, if nullcheck = 1 */
1135
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1136
int *anynull, /* O - set to 1 if any pixels are null */
1137
unsigned short *output, /* O - array of converted pixels */
1138
int *status) /* IO - error status */
1140
Copy input to output following reading of the input from a FITS file.
1141
Check for null values and do datatype conversion and scaling if required.
1142
The nullcheck code value determines how any null values in the input array
1143
are treated. A null value is an input pixel that is equal to tnull. If
1144
nullcheck = 0, then no checking for nulls is performed and any null values
1145
will be transformed just like any other pixel. If nullcheck = 1, then the
1146
output pixel will be set = nullval if the corresponding input pixel is null.
1147
If nullcheck = 2, then if the pixel is null then the corresponding value of
1148
nullarray will be set to 1; the value of nullarray for non-null pixels
1149
will = 0. The anynull parameter will be set = 1 if any of the returned
1150
pixels are null, otherwise anynull will be returned with a value = 0;
1156
if (nullcheck == 0) /* no null checking required */
1158
if (scale == 1. && zero == 0.) /* no scaling */
1160
for (ii = 0; ii < ntodo; ii++)
1164
*status = OVERFLOW_ERR;
1167
else if (input[ii] > USHRT_MAX)
1169
*status = OVERFLOW_ERR;
1170
output[ii] = USHRT_MAX;
1173
output[ii] = (unsigned short) input[ii];
1176
else /* must scale the data */
1178
for (ii = 0; ii < ntodo; ii++)
1180
dvalue = input[ii] * scale + zero;
1182
if (dvalue < DUSHRT_MIN)
1184
*status = OVERFLOW_ERR;
1187
else if (dvalue > DUSHRT_MAX)
1189
*status = OVERFLOW_ERR;
1190
output[ii] = USHRT_MAX;
1193
output[ii] = (unsigned short) dvalue;
1197
else /* must check for null values */
1199
if (scale == 1. && zero == 0.) /* no scaling */
1201
for (ii = 0; ii < ntodo; ii++)
1203
if (input[ii] == tnull)
1207
output[ii] = nullval;
1215
*status = OVERFLOW_ERR;
1218
else if (input[ii] > USHRT_MAX)
1220
*status = OVERFLOW_ERR;
1221
output[ii] = USHRT_MAX;
1224
output[ii] = (unsigned short) input[ii];
1228
else /* must scale the data */
1230
for (ii = 0; ii < ntodo; ii++)
1232
if (input[ii] == tnull)
1236
output[ii] = nullval;
1242
dvalue = input[ii] * scale + zero;
1244
if (dvalue < DUSHRT_MIN)
1246
*status = OVERFLOW_ERR;
1249
else if (dvalue > DUSHRT_MAX)
1251
*status = OVERFLOW_ERR;
1252
output[ii] = USHRT_MAX;
1255
output[ii] = (unsigned short) dvalue;
1262
/*--------------------------------------------------------------------------*/
1263
int fffi8u2(LONGLONG *input, /* I - array of values to be converted */
1264
long ntodo, /* I - number of elements in the array */
1265
double scale, /* I - FITS TSCALn or BSCALE value */
1266
double zero, /* I - FITS TZEROn or BZERO value */
1267
int nullcheck, /* I - null checking code; 0 = don't check */
1268
/* 1:set null pixels = nullval */
1269
/* 2: if null pixel, set nullarray = 1 */
1270
LONGLONG tnull, /* I - value of FITS TNULLn keyword if any */
1271
unsigned short nullval, /* I - set null pixels, if nullcheck = 1 */
1272
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1273
int *anynull, /* O - set to 1 if any pixels are null */
1274
unsigned short *output, /* O - array of converted pixels */
1275
int *status) /* IO - error status */
1277
Copy input to output following reading of the input from a FITS file.
1278
Check for null values and do datatype conversion and scaling if required.
1279
The nullcheck code value determines how any null values in the input array
1280
are treated. A null value is an input pixel that is equal to tnull. If
1281
nullcheck = 0, then no checking for nulls is performed and any null values
1282
will be transformed just like any other pixel. If nullcheck = 1, then the
1283
output pixel will be set = nullval if the corresponding input pixel is null.
1284
If nullcheck = 2, then if the pixel is null then the corresponding value of
1285
nullarray will be set to 1; the value of nullarray for non-null pixels
1286
will = 0. The anynull parameter will be set = 1 if any of the returned
1287
pixels are null, otherwise anynull will be returned with a value = 0;
1293
if (nullcheck == 0) /* no null checking required */
1295
if (scale == 1. && zero == 0.) /* no scaling */
1297
for (ii = 0; ii < ntodo; ii++)
1301
*status = OVERFLOW_ERR;
1304
else if (input[ii] > USHRT_MAX)
1306
*status = OVERFLOW_ERR;
1307
output[ii] = USHRT_MAX;
1310
output[ii] = (unsigned short) input[ii];
1313
else /* must scale the data */
1315
for (ii = 0; ii < ntodo; ii++)
1317
dvalue = input[ii] * scale + zero;
1319
if (dvalue < DUSHRT_MIN)
1321
*status = OVERFLOW_ERR;
1324
else if (dvalue > DUSHRT_MAX)
1326
*status = OVERFLOW_ERR;
1327
output[ii] = USHRT_MAX;
1330
output[ii] = (unsigned short) dvalue;
1334
else /* must check for null values */
1336
if (scale == 1. && zero == 0.) /* no scaling */
1338
for (ii = 0; ii < ntodo; ii++)
1340
if (input[ii] == tnull)
1344
output[ii] = nullval;
1352
*status = OVERFLOW_ERR;
1355
else if (input[ii] > USHRT_MAX)
1357
*status = OVERFLOW_ERR;
1358
output[ii] = USHRT_MAX;
1361
output[ii] = (unsigned short) input[ii];
1365
else /* must scale the data */
1367
for (ii = 0; ii < ntodo; ii++)
1369
if (input[ii] == tnull)
1373
output[ii] = nullval;
1379
dvalue = input[ii] * scale + zero;
1381
if (dvalue < DUSHRT_MIN)
1383
*status = OVERFLOW_ERR;
1386
else if (dvalue > DUSHRT_MAX)
1388
*status = OVERFLOW_ERR;
1389
output[ii] = USHRT_MAX;
1392
output[ii] = (unsigned short) dvalue;
1399
/*--------------------------------------------------------------------------*/
1400
int fffr4u2(float *input, /* I - array of values to be converted */
1401
long ntodo, /* I - number of elements in the array */
1402
double scale, /* I - FITS TSCALn or BSCALE value */
1403
double zero, /* I - FITS TZEROn or BZERO value */
1404
int nullcheck, /* I - null checking code; 0 = don't check */
1405
/* 1:set null pixels = nullval */
1406
/* 2: if null pixel, set nullarray = 1 */
1407
unsigned short nullval, /* I - set null pixels, if nullcheck = 1 */
1408
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1409
int *anynull, /* O - set to 1 if any pixels are null */
1410
unsigned short *output, /* O - array of converted pixels */
1411
int *status) /* IO - error status */
1413
Copy input to output following reading of the input from a FITS file.
1414
Check for null values and do datatype conversion and scaling if required.
1415
The nullcheck code value determines how any null values in the input array
1416
are treated. A null value is an input pixel that is equal to NaN. If
1417
nullcheck = 0, then no checking for nulls is performed and any null values
1418
will be transformed just like any other pixel. If nullcheck = 1, then the
1419
output pixel will be set = nullval if the corresponding input pixel is null.
1420
If nullcheck = 2, then if the pixel is null then the corresponding value of
1421
nullarray will be set to 1; the value of nullarray for non-null pixels
1422
will = 0. The anynull parameter will be set = 1 if any of the returned
1423
pixels are null, otherwise anynull will be returned with a value = 0;
1430
if (nullcheck == 0) /* no null checking required */
1432
if (scale == 1. && zero == 0.) /* no scaling */
1434
for (ii = 0; ii < ntodo; ii++)
1436
if (input[ii] < DUSHRT_MIN)
1438
*status = OVERFLOW_ERR;
1441
else if (input[ii] > DUSHRT_MAX)
1443
*status = OVERFLOW_ERR;
1444
output[ii] = USHRT_MAX;
1447
output[ii] = (unsigned short) input[ii];
1450
else /* must scale the data */
1452
for (ii = 0; ii < ntodo; ii++)
1454
dvalue = input[ii] * scale + zero;
1456
if (dvalue < DUSHRT_MIN)
1458
*status = OVERFLOW_ERR;
1461
else if (dvalue > DUSHRT_MAX)
1463
*status = OVERFLOW_ERR;
1464
output[ii] = USHRT_MAX;
1467
output[ii] = (unsigned short) dvalue;
1471
else /* must check for null values */
1473
sptr = (short *) input;
1475
#if BYTESWAPPED && MACHINE != VAXVMS && MACHINE != ALPHAVMS
1476
sptr++; /* point to MSBs */
1479
if (scale == 1. && zero == 0.) /* no scaling */
1481
for (ii = 0; ii < ntodo; ii++, sptr += 2)
1483
if (0 != (iret = fnan(*sptr) ) ) /* test for NaN or underflow */
1485
if (iret == 1) /* is it a NaN? */
1489
output[ii] = nullval;
1493
else /* it's an underflow */
1498
if (input[ii] < DUSHRT_MIN)
1500
*status = OVERFLOW_ERR;
1503
else if (input[ii] > DUSHRT_MAX)
1505
*status = OVERFLOW_ERR;
1506
output[ii] = USHRT_MAX;
1509
output[ii] = (unsigned short) input[ii];
1513
else /* must scale the data */
1515
for (ii = 0; ii < ntodo; ii++, sptr += 2)
1517
if (0 != (iret = fnan(*sptr) ) ) /* test for NaN or underflow */
1519
if (iret == 1) /* is it a NaN? */
1523
output[ii] = nullval;
1527
else /* it's an underflow */
1529
if (zero < DUSHRT_MIN)
1531
*status = OVERFLOW_ERR;
1534
else if (zero > DUSHRT_MAX)
1536
*status = OVERFLOW_ERR;
1537
output[ii] = USHRT_MAX;
1540
output[ii] = (unsigned short) zero;
1545
dvalue = input[ii] * scale + zero;
1547
if (dvalue < DUSHRT_MIN)
1549
*status = OVERFLOW_ERR;
1552
else if (dvalue > DUSHRT_MAX)
1554
*status = OVERFLOW_ERR;
1555
output[ii] = USHRT_MAX;
1558
output[ii] = (unsigned short) dvalue;
1565
/*--------------------------------------------------------------------------*/
1566
int fffr8u2(double *input, /* I - array of values to be converted */
1567
long ntodo, /* I - number of elements in the array */
1568
double scale, /* I - FITS TSCALn or BSCALE value */
1569
double zero, /* I - FITS TZEROn or BZERO value */
1570
int nullcheck, /* I - null checking code; 0 = don't check */
1571
/* 1:set null pixels = nullval */
1572
/* 2: if null pixel, set nullarray = 1 */
1573
unsigned short nullval, /* I - set null pixels, if nullcheck = 1 */
1574
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1575
int *anynull, /* O - set to 1 if any pixels are null */
1576
unsigned short *output, /* O - array of converted pixels */
1577
int *status) /* IO - error status */
1579
Copy input to output following reading of the input from a FITS file.
1580
Check for null values and do datatype conversion and scaling if required.
1581
The nullcheck code value determines how any null values in the input array
1582
are treated. A null value is an input pixel that is equal to NaN. If
1583
nullcheck = 0, then no checking for nulls is performed and any null values
1584
will be transformed just like any other pixel. If nullcheck = 1, then the
1585
output pixel will be set = nullval if the corresponding input pixel is null.
1586
If nullcheck = 2, then if the pixel is null then the corresponding value of
1587
nullarray will be set to 1; the value of nullarray for non-null pixels
1588
will = 0. The anynull parameter will be set = 1 if any of the returned
1589
pixels are null, otherwise anynull will be returned with a value = 0;
1596
if (nullcheck == 0) /* no null checking required */
1598
if (scale == 1. && zero == 0.) /* no scaling */
1600
for (ii = 0; ii < ntodo; ii++)
1602
if (input[ii] < DUSHRT_MIN)
1604
*status = OVERFLOW_ERR;
1607
else if (input[ii] > DUSHRT_MAX)
1609
*status = OVERFLOW_ERR;
1610
output[ii] = USHRT_MAX;
1613
output[ii] = (unsigned short) input[ii];
1616
else /* must scale the data */
1618
for (ii = 0; ii < ntodo; ii++)
1620
dvalue = input[ii] * scale + zero;
1622
if (dvalue < DUSHRT_MIN)
1624
*status = OVERFLOW_ERR;
1627
else if (dvalue > DUSHRT_MAX)
1629
*status = OVERFLOW_ERR;
1630
output[ii] = USHRT_MAX;
1633
output[ii] = (unsigned short) dvalue;
1637
else /* must check for null values */
1639
sptr = (short *) input;
1641
#if BYTESWAPPED && MACHINE != VAXVMS && MACHINE != ALPHAVMS
1642
sptr += 3; /* point to MSBs */
1644
if (scale == 1. && zero == 0.) /* no scaling */
1646
for (ii = 0; ii < ntodo; ii++, sptr += 4)
1648
if (0 != (iret = dnan(*sptr)) ) /* test for NaN or underflow */
1650
if (iret == 1) /* is it a NaN? */
1654
output[ii] = nullval;
1658
else /* it's an underflow */
1663
if (input[ii] < DUSHRT_MIN)
1665
*status = OVERFLOW_ERR;
1668
else if (input[ii] > DUSHRT_MAX)
1670
*status = OVERFLOW_ERR;
1671
output[ii] = USHRT_MAX;
1674
output[ii] = (unsigned short) input[ii];
1678
else /* must scale the data */
1680
for (ii = 0; ii < ntodo; ii++, sptr += 4)
1682
if (0 != (iret = dnan(*sptr)) ) /* test for NaN or underflow */
1684
if (iret == 1) /* is it a NaN? */
1688
output[ii] = nullval;
1692
else /* it's an underflow */
1694
if (zero < DUSHRT_MIN)
1696
*status = OVERFLOW_ERR;
1699
else if (zero > DUSHRT_MAX)
1701
*status = OVERFLOW_ERR;
1702
output[ii] = USHRT_MAX;
1705
output[ii] = (unsigned short) zero;
1710
dvalue = input[ii] * scale + zero;
1712
if (dvalue < DUSHRT_MIN)
1714
*status = OVERFLOW_ERR;
1717
else if (dvalue > DUSHRT_MAX)
1719
*status = OVERFLOW_ERR;
1720
output[ii] = USHRT_MAX;
1723
output[ii] = (unsigned short) dvalue;
1730
/*--------------------------------------------------------------------------*/
1731
int fffstru2(char *input, /* I - array of values to be converted */
1732
long ntodo, /* I - number of elements in the array */
1733
double scale, /* I - FITS TSCALn or BSCALE value */
1734
double zero, /* I - FITS TZEROn or BZERO value */
1735
long twidth, /* I - width of each substring of chars */
1736
double implipower, /* I - power of 10 of implied decimal */
1737
int nullcheck, /* I - null checking code; 0 = don't check */
1738
/* 1:set null pixels = nullval */
1739
/* 2: if null pixel, set nullarray = 1 */
1740
char *snull, /* I - value of FITS null string, if any */
1741
unsigned short nullval, /* I - set null pixels, if nullcheck = 1 */
1742
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1743
int *anynull, /* O - set to 1 if any pixels are null */
1744
unsigned short *output, /* O - array of converted pixels */
1745
int *status) /* IO - error status */
1747
Copy input to output following reading of the input from a FITS file. Check
1748
for null values and do scaling if required. The nullcheck code value
1749
determines how any null values in the input array are treated. A null
1750
value is an input pixel that is equal to snull. If nullcheck= 0, then
1751
no special checking for nulls is performed. If nullcheck = 1, then the
1752
output pixel will be set = nullval if the corresponding input pixel is null.
1753
If nullcheck = 2, then if the pixel is null then the corresponding value of
1754
nullarray will be set to 1; the value of nullarray for non-null pixels
1755
will = 0. The anynull parameter will be set = 1 if any of the returned
1756
pixels are null, otherwise anynull will be returned with a value = 0;
1762
char *cstring, message[81];
1764
char tempstore, chrzero = '0';
1766
int exponent, sign, esign, decpt;
1768
nullen = strlen(snull);
1769
cptr = input; /* pointer to start of input string */
1770
for (ii = 0; ii < ntodo; ii++)
1773
/* temporarily insert a null terminator at end of the string */
1774
tpos = cptr + twidth;
1778
/* check if null value is defined, and if the */
1779
/* column string is identical to the null string */
1780
if (snull[0] != ASCII_NULL_UNDEFINED &&
1781
!strncmp(snull, cptr, nullen) )
1787
output[ii] = nullval;
1795
/* value is not the null value, so decode it */
1796
/* remove any embedded blank characters from the string */
1805
while (*cptr == ' ') /* skip leading blanks */
1808
if (*cptr == '-' || *cptr == '+') /* check for leading sign */
1815
while (*cptr == ' ') /* skip blanks between sign and value */
1819
while (*cptr >= '0' && *cptr <= '9')
1821
val = val * 10. + *cptr - chrzero; /* accumulate the value */
1824
while (*cptr == ' ') /* skip embedded blanks in the value */
1828
if (*cptr == '.' || *cptr == ',') /* check for decimal point */
1830
decpt = 1; /* set flag to show there was a decimal point */
1832
while (*cptr == ' ') /* skip any blanks */
1835
while (*cptr >= '0' && *cptr <= '9')
1837
val = val * 10. + *cptr - chrzero; /* accumulate the value */
1838
power = power * 10.;
1841
while (*cptr == ' ') /* skip embedded blanks in the value */
1846
if (*cptr == 'E' || *cptr == 'D') /* check for exponent */
1849
while (*cptr == ' ') /* skip blanks */
1852
if (*cptr == '-' || *cptr == '+') /* check for exponent sign */
1859
while (*cptr == ' ') /* skip blanks between sign and exp */
1863
while (*cptr >= '0' && *cptr <= '9')
1865
exponent = exponent * 10 + *cptr - chrzero; /* accumulate exp */
1868
while (*cptr == ' ') /* skip embedded blanks */
1873
if (*cptr != 0) /* should end up at the null terminator */
1875
sprintf(message, "Cannot read number from ASCII table");
1877
sprintf(message, "Column field = %s.", cstring);
1879
/* restore the char that was overwritten by the null */
1881
return(*status = BAD_C2D);
1884
if (!decpt) /* if no explicit decimal, use implied */
1887
dvalue = (sign * val / power) * pow(10., (double) (esign * exponent));
1889
dvalue = dvalue * scale + zero; /* apply the scaling */
1891
if (dvalue < DUSHRT_MIN)
1893
*status = OVERFLOW_ERR;
1896
else if (dvalue > DUSHRT_MAX)
1898
*status = OVERFLOW_ERR;
1899
output[ii] = USHRT_MAX;
1902
output[ii] = (unsigned short) dvalue;
1904
/* restore the char that was overwritten by the null */