1
/* This file, getcolb.c, contains routines that read data elements from */
2
/* a FITS image or table, with unsigned char (unsigned byte) data type. */
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 ffgpvb( 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 char nulval, /* I - value for undefined pixels */
20
unsigned char *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 char 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, TBYTE, firstelem, nelem,
43
nullcheck, &nullvalue, array, NULL, anynul, status);
47
the primary array is represented as a binary table:
48
each group of the primary array is a row in the table,
49
where the first column contains the group parameters
50
and the second column contains the image itself.
53
row=maxvalue(1,group);
55
ffgclb(fptr, 2, row, firstelem, nelem, 1, 1, nulval,
56
array, &cdummy, anynul, status);
59
/*--------------------------------------------------------------------------*/
60
int ffgpfb( fitsfile *fptr, /* I - FITS file pointer */
61
long group, /* I - group to read (1 = 1st group) */
62
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
63
LONGLONG nelem, /* I - number of values to read */
64
unsigned char *array, /* O - array of values that are returned */
65
char *nularray, /* O - array of null pixel flags */
66
int *anynul, /* O - set to 1 if any values are null; else 0 */
67
int *status) /* IO - error status */
69
Read an array of values from the primary array. Data conversion
70
and scaling will be performed if necessary (e.g, if the datatype of
71
the FITS array is not the same as the array being read).
72
Any undefined pixels in the returned array will be set = 0 and the
73
corresponding nularray value will be set = 1.
74
ANYNUL is returned with a value of .true. if any pixels are undefined.
80
if (fits_is_compressed_image(fptr, status))
82
/* this is a compressed image in a binary table */
84
fits_read_compressed_pixels(fptr, TBYTE, firstelem, nelem,
85
nullcheck, NULL, array, nularray, anynul, status);
90
the primary array is represented as a binary table:
91
each group of the primary array is a row in the table,
92
where the first column contains the group parameters
93
and the second column contains the image itself.
96
row=maxvalue(1,group);
98
ffgclb(fptr, 2, row, firstelem, nelem, 1, 2, 0,
99
array, nularray, anynul, status);
102
/*--------------------------------------------------------------------------*/
103
int ffg2db(fitsfile *fptr, /* I - FITS file pointer */
104
long group, /* I - group to read (1 = 1st group) */
105
unsigned char nulval, /* set undefined pixels equal to this */
106
LONGLONG ncols, /* I - number of pixels in each row of array */
107
LONGLONG naxis1, /* I - FITS image NAXIS1 value */
108
LONGLONG naxis2, /* I - FITS image NAXIS2 value */
109
unsigned char *array, /* O - array to be filled and returned */
110
int *anynul, /* O - set to 1 if any values are null; else 0 */
111
int *status) /* IO - error status */
113
Read an entire 2-D array of values to the primary array. Data conversion
114
and scaling will be performed if necessary (e.g, if the datatype of the
115
FITS array is not the same as the array being read). Any null
116
values in the array will be set equal to the value of nulval, unless
117
nulval = 0 in which case no null checking will be performed.
120
/* call the 3D reading routine, with the 3rd dimension = 1 */
122
ffg3db(fptr, group, nulval, ncols, naxis2, naxis1, naxis2, 1, array,
127
/*--------------------------------------------------------------------------*/
128
int ffg3db(fitsfile *fptr, /* I - FITS file pointer */
129
long group, /* I - group to read (1 = 1st group) */
130
unsigned char nulval, /* set undefined pixels equal to this */
131
LONGLONG ncols, /* I - number of pixels in each row of array */
132
LONGLONG nrows, /* I - number of rows in each plane of array */
133
LONGLONG naxis1, /* I - FITS image NAXIS1 value */
134
LONGLONG naxis2, /* I - FITS image NAXIS2 value */
135
LONGLONG naxis3, /* I - FITS image NAXIS3 value */
136
unsigned char *array, /* O - array to be filled and returned */
137
int *anynul, /* O - set to 1 if any values are null; else 0 */
138
int *status) /* IO - error status */
140
Read an entire 3-D array of values to the primary array. Data conversion
141
and scaling will be performed if necessary (e.g, if the datatype of the
142
FITS array is not the same as the array being read). Any null
143
values in the array will be set equal to the value of nulval, unless
144
nulval = 0 in which case no null checking will be performed.
147
long tablerow, ii, jj;
148
LONGLONG narray, nfits;
151
long inc[] = {1,1,1};
152
LONGLONG fpixel[] = {1,1,1};
154
unsigned char 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, TBYTE, 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
ffgclb(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 (ffgclb(fptr, 2, tablerow, nfits, naxis1, 1, 1, nulval,
201
&array[narray], &cdummy, anynul, status) > 0)
207
narray += (nrows - naxis2) * ncols;
212
/*--------------------------------------------------------------------------*/
213
int ffgsvb(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 char nulval, /* I - value to set undefined pixels */
221
unsigned char *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], dir[9];
231
long nelem, nultyp, ninc, numcol;
232
LONGLONG felem, dsize[10], blcll[9], trcll[9];
234
char ldummy, msg[FLEN_ERRMSG];
236
unsigned char nullvalue;
238
if (naxis < 1 || naxis > 9)
240
sprintf(msg, "NAXIS = %d in call to ffgsvb 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, TBYTE, 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++)
308
for (ii = 0; ii < naxis; ii++)
310
if (trc[ii] < blc[ii])
312
if (hdutype == IMAGE_HDU)
318
sprintf(msg, "ffgsvb: illegal range specified for axis %ld", ii + 1);
320
return(*status = BAD_PIX_NUM);
327
dsize[ii + 1] = dsize[ii] * naxes[ii];
328
dsize[ii] = dsize[ii] * dir[ii];
330
dsize[naxis] = dsize[naxis] * dir[naxis];
332
if (naxis == 1 && naxes[0] == 1)
334
/* This is not a vector column, so read all the rows at once */
335
nelem = (rstp - rstr) / rinc + 1;
341
/* have to read each row individually, in all dimensions */
342
nelem = (stp[0]*dir[0] - str[0]*dir[0]) / inc[0] + 1;
343
ninc = incr[0] * dir[0];
346
for (row = rstr; row <= rstp; row += rinc)
348
for (i8 = str[8]*dir[8]; i8 <= stp[8]*dir[8]; i8 += incr[8])
350
for (i7 = str[7]*dir[7]; i7 <= stp[7]*dir[7]; i7 += incr[7])
352
for (i6 = str[6]*dir[6]; i6 <= stp[6]*dir[6]; i6 += incr[6])
354
for (i5 = str[5]*dir[5]; i5 <= stp[5]*dir[5]; i5 += incr[5])
356
for (i4 = str[4]*dir[4]; i4 <= stp[4]*dir[4]; i4 += incr[4])
358
for (i3 = str[3]*dir[3]; i3 <= stp[3]*dir[3]; i3 += incr[3])
360
for (i2 = str[2]*dir[2]; i2 <= stp[2]*dir[2]; i2 += incr[2])
362
for (i1 = str[1]*dir[1]; i1 <= stp[1]*dir[1]; i1 += incr[1])
365
felem=str[0] + (i1 - dir[1]) * dsize[1] + (i2 - dir[2]) * dsize[2] +
366
(i3 - dir[3]) * dsize[3] + (i4 - dir[4]) * dsize[4] +
367
(i5 - dir[5]) * dsize[5] + (i6 - dir[6]) * dsize[6] +
368
(i7 - dir[7]) * dsize[7] + (i8 - dir[8]) * dsize[8];
370
if ( ffgclb(fptr, numcol, row, felem, nelem, ninc, nultyp,
371
nulval, &array[i0], &ldummy, &anyf, status) > 0)
389
/*--------------------------------------------------------------------------*/
390
int ffgsfb(fitsfile *fptr, /* I - FITS file pointer */
391
int colnum, /* I - number of the column to read (1 = 1st) */
392
int naxis, /* I - number of dimensions in the FITS array */
393
long *naxes, /* I - size of each dimension */
394
long *blc, /* I - 'bottom left corner' of the subsection */
395
long *trc, /* I - 'top right corner' of the subsection */
396
long *inc, /* I - increment to be applied in each dimension */
397
unsigned char *array, /* O - array to be filled and returned */
398
char *flagval, /* O - set to 1 if corresponding value is null */
399
int *anynul, /* O - set to 1 if any values are null; else 0 */
400
int *status) /* IO - error status */
402
Read a subsection of data values from an image or a table column.
403
This routine is set up to handle a maximum of nine dimensions.
406
long ii,i0, i1,i2,i3,i4,i5,i6,i7,i8,row,rstr,rstp,rinc;
407
long str[9],stp[9],incr[9],dsize[10];
408
LONGLONG blcll[9], trcll[9];
409
long felem, nelem, nultyp, ninc, numcol;
411
unsigned char nulval = 0;
412
char msg[FLEN_ERRMSG];
415
if (naxis < 1 || naxis > 9)
417
sprintf(msg, "NAXIS = %d in call to ffgsvb is out of range", naxis);
419
return(*status = BAD_DIMEN);
422
if (fits_is_compressed_image(fptr, status))
424
/* this is a compressed image in a binary table */
426
for (ii=0; ii < naxis; ii++) {
431
fits_read_compressed_img(fptr, TBYTE, blcll, trcll, inc,
432
nullcheck, NULL, array, flagval, anynul, status);
437
if this is a primary array, then the input COLNUM parameter should
438
be interpreted as the row number, and we will alway read the image
439
data from column 2 (any group parameters are in column 1).
441
if (ffghdt(fptr, &hdutype, status) > 0)
444
if (hdutype == IMAGE_HDU)
446
/* this is a primary array, or image extension */
462
/* this is a table, so the row info is in the (naxis+1) elements */
474
for (ii = 0; ii < 9; ii++)
482
for (ii = 0; ii < naxis; ii++)
484
if (trc[ii] < blc[ii])
486
sprintf(msg, "ffgsvb: illegal range specified for axis %ld", ii + 1);
488
return(*status = BAD_PIX_NUM);
494
dsize[ii + 1] = dsize[ii] * naxes[ii];
497
if (naxis == 1 && naxes[0] == 1)
499
/* This is not a vector column, so read all the rows at once */
500
nelem = (rstp - rstr) / rinc + 1;
506
/* have to read each row individually, in all dimensions */
507
nelem = (stp[0] - str[0]) / inc[0] + 1;
511
for (row = rstr; row <= rstp; row += rinc)
513
for (i8 = str[8]; i8 <= stp[8]; i8 += incr[8])
515
for (i7 = str[7]; i7 <= stp[7]; i7 += incr[7])
517
for (i6 = str[6]; i6 <= stp[6]; i6 += incr[6])
519
for (i5 = str[5]; i5 <= stp[5]; i5 += incr[5])
521
for (i4 = str[4]; i4 <= stp[4]; i4 += incr[4])
523
for (i3 = str[3]; i3 <= stp[3]; i3 += incr[3])
525
for (i2 = str[2]; i2 <= stp[2]; i2 += incr[2])
527
for (i1 = str[1]; i1 <= stp[1]; i1 += incr[1])
529
felem=str[0] + (i1 - 1) * dsize[1] + (i2 - 1) * dsize[2] +
530
(i3 - 1) * dsize[3] + (i4 - 1) * dsize[4] +
531
(i5 - 1) * dsize[5] + (i6 - 1) * dsize[6] +
532
(i7 - 1) * dsize[7] + (i8 - 1) * dsize[8];
534
if ( ffgclb(fptr, numcol, row, felem, nelem, ninc, nultyp,
535
nulval, &array[i0], &flagval[i0], &anyf, status) > 0)
553
/*--------------------------------------------------------------------------*/
554
int ffggpb( fitsfile *fptr, /* I - FITS file pointer */
555
long group, /* I - group to read (1 = 1st group) */
556
long firstelem, /* I - first vector element to read (1 = 1st) */
557
long nelem, /* I - number of values to read */
558
unsigned char *array, /* O - array of values that are returned */
559
int *status) /* IO - error status */
561
Read an array of group parameters from the primary array. Data conversion
562
and scaling will be performed if necessary (e.g, if the datatype of
563
the FITS array is not the same as the array being read).
570
the primary array is represented as a binary table:
571
each group of the primary array is a row in the table,
572
where the first column contains the group parameters
573
and the second column contains the image itself.
576
row=maxvalue(1,group);
578
ffgclb(fptr, 1, row, firstelem, nelem, 1, 1, 0,
579
array, &cdummy, &idummy, status);
582
/*--------------------------------------------------------------------------*/
583
int ffgcvb(fitsfile *fptr, /* I - FITS file pointer */
584
int colnum, /* I - number of column to read (1 = 1st col) */
585
LONGLONG firstrow, /* I - first row to read (1 = 1st row) */
586
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
587
LONGLONG nelem, /* I - number of values to read */
588
unsigned char nulval, /* I - value for null pixels */
589
unsigned char *array, /* O - array of values that are read */
590
int *anynul, /* O - set to 1 if any values are null; else 0 */
591
int *status) /* IO - error status */
593
Read an array of values from a column in the current FITS HDU. Automatic
594
datatype conversion will be performed if the datatype of the column does not
595
match the datatype of the array parameter. The output values will be scaled
596
by the FITS TSCALn and TZEROn values if these values have been defined.
597
Any undefined pixels will be set equal to the value of 'nulval' unless
598
nulval = 0 in which case no checks for undefined pixels will be made.
603
ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, nulval,
604
array, &cdummy, anynul, status);
607
/*--------------------------------------------------------------------------*/
608
int ffgcfb(fitsfile *fptr, /* I - FITS file pointer */
609
int colnum, /* I - number of column to read (1 = 1st col) */
610
LONGLONG firstrow, /* I - first row to read (1 = 1st row) */
611
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
612
LONGLONG nelem, /* I - number of values to read */
613
unsigned char *array, /* O - array of values that are read */
614
char *nularray, /* O - array of flags: 1 if null pixel; else 0 */
615
int *anynul, /* O - set to 1 if any values are null; else 0 */
616
int *status) /* IO - error status */
618
Read an array of values from a column in the current FITS HDU. Automatic
619
datatype conversion will be performed if the datatype of the column does not
620
match the datatype of the array parameter. The output values will be scaled
621
by the FITS TSCALn and TZEROn values if these values have been defined.
622
Nularray will be set = 1 if the corresponding array pixel is undefined,
623
otherwise nularray will = 0.
626
unsigned char dummy = 0;
628
ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 2, dummy,
629
array, nularray, anynul, status);
632
/*--------------------------------------------------------------------------*/
633
int ffgclb( fitsfile *fptr, /* I - FITS file pointer */
634
int colnum, /* I - number of column to read (1 = 1st col) */
635
LONGLONG firstrow, /* I - first row to read (1 = 1st row) */
636
LONGLONG firstelem, /* I - first vector element to read (1 = 1st) */
637
LONGLONG nelem, /* I - number of values to read */
638
long elemincre, /* I - pixel increment; e.g., 2 = every other */
639
int nultyp, /* I - null value handling code: */
640
/* 1: set undefined pixels = nulval */
641
/* 2: set nularray=1 for undefined pixels */
642
unsigned char nulval, /* I - value for null pixels if nultyp = 1 */
643
unsigned char *array, /* O - array of values that are read */
644
char *nularray, /* O - array of flags = 1 if nultyp = 2 */
645
int *anynul, /* O - set to 1 if any values are null; else 0 */
646
int *status) /* IO - error status */
648
Read an array of values from a column in the current FITS HDU.
649
The column number may refer to a real column in an ASCII or binary table,
650
or it may refer be a virtual column in a 1 or more grouped FITS primary
651
array or image extension. FITSIO treats a primary array as a binary table
652
with 2 vector columns: the first column contains the group parameters (often
653
with length = 0) and the second column contains the array of image pixels.
654
Each row of the table represents a group in the case of multigroup FITS
657
The output array of values will be converted from the datatype of the column
658
and will be scaled by the FITS TSCALn and TZEROn values if necessary.
661
double scale, zero, power = 1., dtemp;
662
int tcode, maxelem2, hdutype, xcode, decimals;
663
long twidth, incre, ntodo;
665
int convert, nulcheck, readcheck = 0;
666
LONGLONG repeat, startpos, elemnum, readptr, tnull;
667
LONGLONG rowlen, rownum, remain, next, rowincre, maxelem;
670
char snull[20]; /* the FITS null value if reading from ASCII table */
672
double cbuff[DBUFFSIZE / sizeof(double)]; /* align cbuff on word boundary */
677
unsigned char ucharval;
680
if (*status > 0 || nelem == 0) /* inherit input status value if > 0 */
689
memset(nularray, 0, (size_t) nelem); /* initialize nullarray */
691
/*---------------------------------------------------*/
692
/* Check input and get parameters about the column: */
693
/*---------------------------------------------------*/
695
readcheck = -1; /* don't do range checking in this case */
697
ffgcprll( fptr, colnum, firstrow, firstelem, nelem, readcheck, &scale, &zero,
698
tform, &twidth, &tcode, &maxelem2, &startpos, &elemnum, &incre,
699
&repeat, &rowlen, &hdutype, &tnull, snull, status);
703
if (tcode == TLOGICAL && elemincre == 1)
706
ffgcll(fptr, colnum, firstrow, firstelem, nelem, nultyp,
707
u.charval, (char *) array, nularray, anynul, status);
712
if (strchr(tform,'A') != NULL)
714
if (*status == BAD_ELEM_NUM)
716
/* ignore this error message */
718
ffcmsg(); /* clear error stack */
721
/* interpret a 'A' ASCII column as a 'B' byte column ('8A' == '8B') */
722
/* This is an undocumented 'feature' in CFITSIO */
724
/* we have to reset some of the values returned by ffgcpr */
727
incre = 1; /* each element is 1 byte wide */
728
repeat = twidth; /* total no. of chars in the col */
729
twidth = 1; /* width of each element */
730
scale = 1.0; /* no scaling */
732
tnull = NULL_UNDEFINED; /* don't test for nulls */
739
incre *= elemincre; /* multiply incre to just get every nth pixel */
741
if (tcode == TSTRING && hdutype == ASCII_TBL) /* setup for ASCII tables */
743
/* get the number of implied decimal places if no explicit decmal point */
744
ffasfm(tform, &xcode, &xwidth, &decimals, status);
745
for(ii = 0; ii < decimals; ii++)
748
/*------------------------------------------------------------------*/
749
/* Decide whether to check for null values in the input FITS file: */
750
/*------------------------------------------------------------------*/
751
nulcheck = nultyp; /* by default, check for null values in the FITS file */
753
if (nultyp == 1 && nulval == 0)
754
nulcheck = 0; /* calling routine does not want to check for nulls */
756
else if (tcode%10 == 1 && /* if reading an integer column, and */
757
tnull == NULL_UNDEFINED) /* if a null value is not defined, */
758
nulcheck = 0; /* then do not check for null values. */
760
else if (tcode == TSHORT && (tnull > SHRT_MAX || tnull < SHRT_MIN) )
761
nulcheck = 0; /* Impossible null value */
763
else if (tcode == TBYTE && (tnull > 255 || tnull < 0) )
764
nulcheck = 0; /* Impossible null value */
766
else if (tcode == TSTRING && snull[0] == ASCII_NULL_UNDEFINED)
769
/*----------------------------------------------------------------------*/
770
/* If FITS column and output data array have same datatype, then we do */
771
/* not need to use a temporary buffer to store intermediate datatype. */
772
/*----------------------------------------------------------------------*/
774
if (tcode == TBYTE) /* Special Case: */
775
{ /* no type convertion required, so read */
776
maxelem = nelem; /* data directly into output buffer. */
778
if (nulcheck == 0 && scale == 1. && zero == 0.)
779
convert = 0; /* no need to scale data or find nulls */
782
/*---------------------------------------------------------------------*/
783
/* Now read the pixels from the FITS column. If the column does not */
784
/* have the same datatype as the output array, then we have to read */
785
/* the raw values into a temporary buffer (of limited size). In */
786
/* the case of a vector colum read only 1 vector of values at a time */
787
/* then skip to the next row if more values need to be read. */
788
/* After reading the raw values, then call the fffXXYY routine to (1) */
789
/* test for undefined values, (2) convert the datatype if necessary, */
790
/* and (3) scale the values by the FITS TSCALn and TZEROn linear */
791
/* scaling parameters. */
792
/*---------------------------------------------------------------------*/
793
remain = nelem; /* remaining number of values to read */
794
next = 0; /* next element in array to be read */
795
rownum = 0; /* row number, relative to firstrow */
799
/* limit the number of pixels to read at one time to the number that
800
will fit in the buffer or to the number of pixels that remain in
801
the current vector, which ever is smaller.
803
ntodo = (long) minvalue(remain, maxelem);
806
ntodo = (long) minvalue(ntodo, ((repeat - elemnum - 1)/elemincre +1));
810
ntodo = (long) minvalue(ntodo, (elemnum/(-elemincre) +1));
813
readptr = startpos + ((LONGLONG)rownum * rowlen) + (elemnum * (incre / elemincre));
818
ffgi1b(fptr, readptr, ntodo, incre, &array[next], status);
820
fffi1i1(&array[next], ntodo, scale, zero, nulcheck,
821
(unsigned char) tnull, nulval, &nularray[next], anynul,
822
&array[next], status);
825
ffgi2b(fptr, readptr, ntodo, incre, (short *) buffer, status);
826
fffi2i1((short *) buffer, ntodo, scale, zero, nulcheck,
827
(short) tnull, nulval, &nularray[next], anynul,
828
&array[next], status);
831
ffgi4b(fptr, readptr, ntodo, incre, (INT32BIT *) buffer,
833
fffi4i1((INT32BIT *) buffer, ntodo, scale, zero, nulcheck,
834
(INT32BIT) tnull, nulval, &nularray[next], anynul,
835
&array[next], status);
838
ffgi8b(fptr, readptr, ntodo, incre, (long *) buffer, status);
839
fffi8i1( (LONGLONG *) buffer, ntodo, scale, zero,
840
nulcheck, tnull, nulval, &nularray[next],
841
anynul, &array[next], status);
844
ffgr4b(fptr, readptr, ntodo, incre, (float *) buffer, status);
845
fffr4i1((float *) buffer, ntodo, scale, zero, nulcheck,
846
nulval, &nularray[next], anynul,
847
&array[next], status);
850
ffgr8b(fptr, readptr, ntodo, incre, (double *) buffer, status);
851
fffr8i1((double *) buffer, ntodo, scale, zero, nulcheck,
852
nulval, &nularray[next], anynul,
853
&array[next], status);
856
ffmbyt(fptr, readptr, REPORT_EOF, status);
858
if (incre == twidth) /* contiguous bytes */
859
ffgbyt(fptr, ntodo * twidth, buffer, status);
861
ffgbytoff(fptr, twidth, ntodo, incre - twidth, buffer,
864
/* interpret the string as an ASCII formated number */
865
fffstri1((char *) buffer, ntodo, scale, zero, twidth, power,
866
nulcheck, snull, nulval, &nularray[next], anynul,
867
&array[next], status);
870
default: /* error trap for invalid column format */
872
"Cannot read bytes from column %d which has format %s",
875
if (hdutype == ASCII_TBL)
876
return(*status = BAD_ATABLE_FORMAT);
878
return(*status = BAD_BTABLE_FORMAT);
880
} /* End of switch block */
882
/*-------------------------*/
883
/* Check for fatal error */
884
/*-------------------------*/
885
if (*status > 0) /* test for error during previous read operation */
887
dtemp = (double) next;
890
"Error reading elements %.0f thru %.0f from column %d (ffgclb).",
891
dtemp+1., dtemp+ntodo, colnum);
894
"Error reading elements %.0f thru %.0f from image (ffgclb).",
895
dtemp+1., dtemp+ntodo);
901
/*--------------------------------------------*/
902
/* increment the counters for the next loop */
903
/*--------------------------------------------*/
908
elemnum = elemnum + (ntodo * elemincre);
910
if (elemnum >= repeat) /* completed a row; start on later row */
912
rowincre = elemnum / repeat;
914
elemnum = elemnum - (rowincre * repeat);
916
else if (elemnum < 0) /* completed a row; start on a previous row */
918
rowincre = (-elemnum - 1) / repeat + 1;
920
elemnum = (rowincre * repeat) + elemnum;
923
} /* End of main while Loop */
926
/*--------------------------------*/
927
/* check for numerical overflow */
928
/*--------------------------------*/
929
if (*status == OVERFLOW_ERR)
932
"Numerical overflow during type conversion while reading FITS data.");
933
*status = NUM_OVERFLOW;
938
/*--------------------------------------------------------------------------*/
939
int ffgextn( fitsfile *fptr, /* I - FITS file pointer */
940
LONGLONG offset, /* I - byte offset from start of extension data */
941
LONGLONG nelem, /* I - number of elements to read */
942
void *buffer, /* I - stream of bytes to read */
943
int *status) /* IO - error status */
945
Read a stream of bytes from the current FITS HDU. This primative routine is mainly
946
for reading non-standard "conforming" extensions and should not be used
947
for standard IMAGE, TABLE or BINTABLE extensions.
950
if (*status > 0) /* inherit input status value if > 0 */
953
/* reset position to the correct HDU if necessary */
954
if (fptr->HDUposition != (fptr->Fptr)->curhdu)
955
ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status);
957
/* rescan header if data structure is undefined */
958
else if ((fptr->Fptr)->datastart == DATA_UNDEFINED)
959
if ( ffrdef(fptr, status) > 0)
962
/* move to write position */
963
ffmbyt(fptr, (fptr->Fptr)->datastart+ offset, IGNORE_EOF, status);
965
/* read the buffer */
966
ffgbyt(fptr, nelem, buffer, status);
970
/*--------------------------------------------------------------------------*/
971
int fffi1i1(unsigned char *input, /* I - array of values to be converted */
972
long ntodo, /* I - number of elements in the array */
973
double scale, /* I - FITS TSCALn or BSCALE value */
974
double zero, /* I - FITS TZEROn or BZERO value */
975
int nullcheck, /* I - null checking code; 0 = don't check */
976
/* 1:set null pixels = nullval */
977
/* 2: if null pixel, set nullarray = 1 */
978
unsigned char tnull, /* I - value of FITS TNULLn keyword if any */
979
unsigned char nullval,/* I - set null pixels, if nullcheck = 1 */
980
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
981
int *anynull, /* O - set to 1 if any pixels are null */
982
unsigned char *output,/* O - array of converted pixels */
983
int *status) /* IO - error status */
985
Copy input to output following reading of the input from a FITS file.
986
Check for null values and do datatype conversion and scaling if required.
987
The nullcheck code value determines how any null values in the input array
988
are treated. A null value is an input pixel that is equal to tnull. If
989
nullcheck = 0, then no checking for nulls is performed and any null values
990
will be transformed just like any other pixel. If nullcheck = 1, then the
991
output pixel will be set = nullval if the corresponding input pixel is null.
992
If nullcheck = 2, then if the pixel is null then the corresponding value of
993
nullarray will be set to 1; the value of nullarray for non-null pixels
994
will = 0. The anynull parameter will be set = 1 if any of the returned
995
pixels are null, otherwise anynull will be returned with a value = 0;
1001
if (nullcheck == 0) /* no null checking required */
1003
if (scale == 1. && zero == 0.) /* no scaling */
1004
{ /* this routine is normally not called in this case */
1005
memcpy(output, input, ntodo );
1007
else /* must scale the data */
1009
for (ii = 0; ii < ntodo; ii++)
1011
dvalue = input[ii] * scale + zero;
1013
if (dvalue < DUCHAR_MIN)
1015
*status = OVERFLOW_ERR;
1018
else if (dvalue > DUCHAR_MAX)
1020
*status = OVERFLOW_ERR;
1021
output[ii] = UCHAR_MAX;
1024
output[ii] = (unsigned char) dvalue;
1028
else /* must check for null values */
1030
if (scale == 1. && zero == 0.) /* no scaling */
1032
for (ii = 0; ii < ntodo; ii++)
1034
if (input[ii] == tnull)
1038
output[ii] = nullval;
1043
output[ii] = input[ii];
1046
else /* must scale the data */
1048
for (ii = 0; ii < ntodo; ii++)
1050
if (input[ii] == tnull)
1054
output[ii] = nullval;
1060
dvalue = input[ii] * scale + zero;
1062
if (dvalue < DUCHAR_MIN)
1064
*status = OVERFLOW_ERR;
1067
else if (dvalue > DUCHAR_MAX)
1069
*status = OVERFLOW_ERR;
1070
output[ii] = UCHAR_MAX;
1073
output[ii] = (unsigned char) dvalue;
1080
/*--------------------------------------------------------------------------*/
1081
int fffi2i1(short *input, /* I - array of values to be converted */
1082
long ntodo, /* I - number of elements in the array */
1083
double scale, /* I - FITS TSCALn or BSCALE value */
1084
double zero, /* I - FITS TZEROn or BZERO value */
1085
int nullcheck, /* I - null checking code; 0 = don't check */
1086
/* 1:set null pixels = nullval */
1087
/* 2: if null pixel, set nullarray = 1 */
1088
short tnull, /* I - value of FITS TNULLn keyword if any */
1089
unsigned char nullval,/* I - set null pixels, if nullcheck = 1 */
1090
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1091
int *anynull, /* O - set to 1 if any pixels are null */
1092
unsigned char *output,/* O - array of converted pixels */
1093
int *status) /* IO - error status */
1095
Copy input to output following reading of the input from a FITS file.
1096
Check for null values and do datatype conversion and scaling if required.
1097
The nullcheck code value determines how any null values in the input array
1098
are treated. A null value is an input pixel that is equal to tnull. If
1099
nullcheck = 0, then no checking for nulls is performed and any null values
1100
will be transformed just like any other pixel. If nullcheck = 1, then the
1101
output pixel will be set = nullval if the corresponding input pixel is null.
1102
If nullcheck = 2, then if the pixel is null then the corresponding value of
1103
nullarray will be set to 1; the value of nullarray for non-null pixels
1104
will = 0. The anynull parameter will be set = 1 if any of the returned
1105
pixels are null, otherwise anynull will be returned with a value = 0;
1111
if (nullcheck == 0) /* no null checking required */
1113
if (scale == 1. && zero == 0.) /* no scaling */
1115
for (ii = 0; ii < ntodo; ii++)
1119
*status = OVERFLOW_ERR;
1122
else if (input[ii] > UCHAR_MAX)
1124
*status = OVERFLOW_ERR;
1125
output[ii] = UCHAR_MAX;
1128
output[ii] = (unsigned char) input[ii];
1131
else /* must scale the data */
1133
for (ii = 0; ii < ntodo; ii++)
1135
dvalue = input[ii] * scale + zero;
1137
if (dvalue < DUCHAR_MIN)
1139
*status = OVERFLOW_ERR;
1142
else if (dvalue > DUCHAR_MAX)
1144
*status = OVERFLOW_ERR;
1145
output[ii] = UCHAR_MAX;
1148
output[ii] = (unsigned char) dvalue;
1152
else /* must check for null values */
1154
if (scale == 1. && zero == 0.) /* no scaling */
1156
for (ii = 0; ii < ntodo; ii++)
1158
if (input[ii] == tnull)
1162
output[ii] = nullval;
1171
*status = OVERFLOW_ERR;
1174
else if (input[ii] > UCHAR_MAX)
1176
*status = OVERFLOW_ERR;
1177
output[ii] = UCHAR_MAX;
1180
output[ii] = (unsigned char) input[ii];
1184
else /* must scale the data */
1186
for (ii = 0; ii < ntodo; ii++)
1188
if (input[ii] == tnull)
1192
output[ii] = nullval;
1198
dvalue = input[ii] * scale + zero;
1200
if (dvalue < DUCHAR_MIN)
1202
*status = OVERFLOW_ERR;
1205
else if (dvalue > DUCHAR_MAX)
1207
*status = OVERFLOW_ERR;
1208
output[ii] = UCHAR_MAX;
1211
output[ii] = (unsigned char) dvalue;
1218
/*--------------------------------------------------------------------------*/
1219
int fffi4i1(INT32BIT *input, /* I - array of values to be converted */
1220
long ntodo, /* I - number of elements in the array */
1221
double scale, /* I - FITS TSCALn or BSCALE value */
1222
double zero, /* I - FITS TZEROn or BZERO value */
1223
int nullcheck, /* I - null checking code; 0 = don't check */
1224
/* 1:set null pixels = nullval */
1225
/* 2: if null pixel, set nullarray = 1 */
1226
INT32BIT tnull, /* I - value of FITS TNULLn keyword if any */
1227
unsigned char nullval,/* I - set null pixels, if nullcheck = 1 */
1228
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1229
int *anynull, /* O - set to 1 if any pixels are null */
1230
unsigned char *output,/* O - array of converted pixels */
1231
int *status) /* IO - error status */
1233
Copy input to output following reading of the input from a FITS file.
1234
Check for null values and do datatype conversion and scaling if required.
1235
The nullcheck code value determines how any null values in the input array
1236
are treated. A null value is an input pixel that is equal to tnull. If
1237
nullcheck = 0, then no checking for nulls is performed and any null values
1238
will be transformed just like any other pixel. If nullcheck = 1, then the
1239
output pixel will be set = nullval if the corresponding input pixel is null.
1240
If nullcheck = 2, then if the pixel is null then the corresponding value of
1241
nullarray will be set to 1; the value of nullarray for non-null pixels
1242
will = 0. The anynull parameter will be set = 1 if any of the returned
1243
pixels are null, otherwise anynull will be returned with a value = 0;
1249
if (nullcheck == 0) /* no null checking required */
1251
if (scale == 1. && zero == 0.) /* no scaling */
1253
for (ii = 0; ii < ntodo; ii++)
1257
*status = OVERFLOW_ERR;
1260
else if (input[ii] > UCHAR_MAX)
1262
*status = OVERFLOW_ERR;
1263
output[ii] = UCHAR_MAX;
1266
output[ii] = (unsigned char) input[ii];
1269
else /* must scale the data */
1271
for (ii = 0; ii < ntodo; ii++)
1273
dvalue = input[ii] * scale + zero;
1275
if (dvalue < DUCHAR_MIN)
1277
*status = OVERFLOW_ERR;
1280
else if (dvalue > DUCHAR_MAX)
1282
*status = OVERFLOW_ERR;
1283
output[ii] = UCHAR_MAX;
1286
output[ii] = (unsigned char) dvalue;
1290
else /* must check for null values */
1292
if (scale == 1. && zero == 0.) /* no scaling */
1294
for (ii = 0; ii < ntodo; ii++)
1296
if (input[ii] == tnull)
1300
output[ii] = nullval;
1308
*status = OVERFLOW_ERR;
1311
else if (input[ii] > UCHAR_MAX)
1313
*status = OVERFLOW_ERR;
1314
output[ii] = UCHAR_MAX;
1317
output[ii] = (unsigned char) input[ii];
1321
else /* must scale the data */
1323
for (ii = 0; ii < ntodo; ii++)
1325
if (input[ii] == tnull)
1329
output[ii] = nullval;
1335
dvalue = input[ii] * scale + zero;
1337
if (dvalue < DUCHAR_MIN)
1339
*status = OVERFLOW_ERR;
1342
else if (dvalue > DUCHAR_MAX)
1344
*status = OVERFLOW_ERR;
1345
output[ii] = UCHAR_MAX;
1348
output[ii] = (unsigned char) dvalue;
1355
/*--------------------------------------------------------------------------*/
1356
int fffi8i1(LONGLONG *input, /* I - array of values to be converted */
1357
long ntodo, /* I - number of elements in the array */
1358
double scale, /* I - FITS TSCALn or BSCALE value */
1359
double zero, /* I - FITS TZEROn or BZERO value */
1360
int nullcheck, /* I - null checking code; 0 = don't check */
1361
/* 1:set null pixels = nullval */
1362
/* 2: if null pixel, set nullarray = 1 */
1363
LONGLONG tnull, /* I - value of FITS TNULLn keyword if any */
1364
unsigned char nullval,/* I - set null pixels, if nullcheck = 1 */
1365
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1366
int *anynull, /* O - set to 1 if any pixels are null */
1367
unsigned char *output,/* O - array of converted pixels */
1368
int *status) /* IO - error status */
1370
Copy input to output following reading of the input from a FITS file.
1371
Check for null values and do datatype conversion and scaling if required.
1372
The nullcheck code value determines how any null values in the input array
1373
are treated. A null value is an input pixel that is equal to tnull. If
1374
nullcheck = 0, then no checking for nulls is performed and any null values
1375
will be transformed just like any other pixel. If nullcheck = 1, then the
1376
output pixel will be set = nullval if the corresponding input pixel is null.
1377
If nullcheck = 2, then if the pixel is null then the corresponding value of
1378
nullarray will be set to 1; the value of nullarray for non-null pixels
1379
will = 0. The anynull parameter will be set = 1 if any of the returned
1380
pixels are null, otherwise anynull will be returned with a value = 0;
1386
if (nullcheck == 0) /* no null checking required */
1388
if (scale == 1. && zero == 0.) /* no scaling */
1390
for (ii = 0; ii < ntodo; ii++)
1394
*status = OVERFLOW_ERR;
1397
else if (input[ii] > UCHAR_MAX)
1399
*status = OVERFLOW_ERR;
1400
output[ii] = UCHAR_MAX;
1403
output[ii] = (unsigned char) input[ii];
1406
else /* must scale the data */
1408
for (ii = 0; ii < ntodo; ii++)
1410
dvalue = input[ii] * scale + zero;
1412
if (dvalue < DUCHAR_MIN)
1414
*status = OVERFLOW_ERR;
1417
else if (dvalue > DUCHAR_MAX)
1419
*status = OVERFLOW_ERR;
1420
output[ii] = UCHAR_MAX;
1423
output[ii] = (unsigned char) dvalue;
1427
else /* must check for null values */
1429
if (scale == 1. && zero == 0.) /* no scaling */
1431
for (ii = 0; ii < ntodo; ii++)
1433
if (input[ii] == tnull)
1437
output[ii] = nullval;
1445
*status = OVERFLOW_ERR;
1448
else if (input[ii] > UCHAR_MAX)
1450
*status = OVERFLOW_ERR;
1451
output[ii] = UCHAR_MAX;
1454
output[ii] = (unsigned char) input[ii];
1458
else /* must scale the data */
1460
for (ii = 0; ii < ntodo; ii++)
1462
if (input[ii] == tnull)
1466
output[ii] = nullval;
1472
dvalue = input[ii] * scale + zero;
1474
if (dvalue < DUCHAR_MIN)
1476
*status = OVERFLOW_ERR;
1479
else if (dvalue > DUCHAR_MAX)
1481
*status = OVERFLOW_ERR;
1482
output[ii] = UCHAR_MAX;
1485
output[ii] = (unsigned char) dvalue;
1492
/*--------------------------------------------------------------------------*/
1493
int fffr4i1(float *input, /* I - array of values to be converted */
1494
long ntodo, /* I - number of elements in the array */
1495
double scale, /* I - FITS TSCALn or BSCALE value */
1496
double zero, /* I - FITS TZEROn or BZERO value */
1497
int nullcheck, /* I - null checking code; 0 = don't check */
1498
/* 1:set null pixels = nullval */
1499
/* 2: if null pixel, set nullarray = 1 */
1500
unsigned char nullval,/* I - set null pixels, if nullcheck = 1 */
1501
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1502
int *anynull, /* O - set to 1 if any pixels are null */
1503
unsigned char *output,/* O - array of converted pixels */
1504
int *status) /* IO - error status */
1506
Copy input to output following reading of the input from a FITS file.
1507
Check for null values and do datatype conversion and scaling if required.
1508
The nullcheck code value determines how any null values in the input array
1509
are treated. A null value is an input pixel that is equal to NaN. If
1510
nullcheck = 0, then no checking for nulls is performed and any null values
1511
will be transformed just like any other pixel. If nullcheck = 1, then the
1512
output pixel will be set = nullval if the corresponding input pixel is null.
1513
If nullcheck = 2, then if the pixel is null then the corresponding value of
1514
nullarray will be set to 1; the value of nullarray for non-null pixels
1515
will = 0. The anynull parameter will be set = 1 if any of the returned
1516
pixels are null, otherwise anynull will be returned with a value = 0;
1523
if (nullcheck == 0) /* no null checking required */
1525
if (scale == 1. && zero == 0.) /* no scaling */
1527
for (ii = 0; ii < ntodo; ii++)
1529
if (input[ii] < DUCHAR_MIN)
1531
*status = OVERFLOW_ERR;
1534
else if (input[ii] > DUCHAR_MAX)
1536
*status = OVERFLOW_ERR;
1537
output[ii] = UCHAR_MAX;
1540
output[ii] = (unsigned char) input[ii];
1543
else /* must scale the data */
1545
for (ii = 0; ii < ntodo; ii++)
1547
dvalue = input[ii] * scale + zero;
1549
if (dvalue < DUCHAR_MIN)
1551
*status = OVERFLOW_ERR;
1554
else if (dvalue > DUCHAR_MAX)
1556
*status = OVERFLOW_ERR;
1557
output[ii] = UCHAR_MAX;
1560
output[ii] = (unsigned char) dvalue;
1564
else /* must check for null values */
1566
sptr = (short *) input;
1568
#if BYTESWAPPED && MACHINE != VAXVMS && MACHINE != ALPHAVMS
1569
sptr++; /* point to MSBs */
1571
if (scale == 1. && zero == 0.) /* no scaling */
1573
for (ii = 0; ii < ntodo; ii++, sptr += 2)
1575
/* use redundant boolean logic in following statement */
1576
/* to suppress irritating Borland compiler warning message */
1577
if (0 != (iret = fnan(*sptr) ) ) /* test for NaN or underflow */
1579
if (iret == 1) /* is it a NaN? */
1583
output[ii] = nullval;
1587
else /* it's an underflow */
1592
if (input[ii] < DUCHAR_MIN)
1594
*status = OVERFLOW_ERR;
1597
else if (input[ii] > DUCHAR_MAX)
1599
*status = OVERFLOW_ERR;
1600
output[ii] = UCHAR_MAX;
1603
output[ii] = (unsigned char) input[ii];
1607
else /* must scale the data */
1609
for (ii = 0; ii < ntodo; ii++, sptr += 2)
1611
if (0 != (iret = fnan(*sptr) ) ) /* test for NaN or underflow */
1613
if (iret == 1) /* is it a NaN? */
1617
output[ii] = nullval;
1621
else /* it's an underflow */
1623
if (zero < DUCHAR_MIN)
1625
*status = OVERFLOW_ERR;
1628
else if (zero > DUCHAR_MAX)
1630
*status = OVERFLOW_ERR;
1631
output[ii] = UCHAR_MAX;
1634
output[ii] = (unsigned char) zero;
1639
dvalue = input[ii] * scale + zero;
1641
if (dvalue < DUCHAR_MIN)
1643
*status = OVERFLOW_ERR;
1646
else if (dvalue > DUCHAR_MAX)
1648
*status = OVERFLOW_ERR;
1649
output[ii] = UCHAR_MAX;
1652
output[ii] = (unsigned char) dvalue;
1659
/*--------------------------------------------------------------------------*/
1660
int fffr8i1(double *input, /* I - array of values to be converted */
1661
long ntodo, /* I - number of elements in the array */
1662
double scale, /* I - FITS TSCALn or BSCALE value */
1663
double zero, /* I - FITS TZEROn or BZERO value */
1664
int nullcheck, /* I - null checking code; 0 = don't check */
1665
/* 1:set null pixels = nullval */
1666
/* 2: if null pixel, set nullarray = 1 */
1667
unsigned char nullval,/* I - set null pixels, if nullcheck = 1 */
1668
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1669
int *anynull, /* O - set to 1 if any pixels are null */
1670
unsigned char *output,/* O - array of converted pixels */
1671
int *status) /* IO - error status */
1673
Copy input to output following reading of the input from a FITS file.
1674
Check for null values and do datatype conversion and scaling if required.
1675
The nullcheck code value determines how any null values in the input array
1676
are treated. A null value is an input pixel that is equal to NaN. If
1677
nullcheck = 0, then no checking for nulls is performed and any null values
1678
will be transformed just like any other pixel. If nullcheck = 1, then the
1679
output pixel will be set = nullval if the corresponding input pixel is null.
1680
If nullcheck = 2, then if the pixel is null then the corresponding value of
1681
nullarray will be set to 1; the value of nullarray for non-null pixels
1682
will = 0. The anynull parameter will be set = 1 if any of the returned
1683
pixels are null, otherwise anynull will be returned with a value = 0;
1690
if (nullcheck == 0) /* no null checking required */
1692
if (scale == 1. && zero == 0.) /* no scaling */
1694
for (ii = 0; ii < ntodo; ii++)
1696
if (input[ii] < DUCHAR_MIN)
1698
*status = OVERFLOW_ERR;
1701
else if (input[ii] > DUCHAR_MAX)
1703
*status = OVERFLOW_ERR;
1704
output[ii] = UCHAR_MAX;
1707
output[ii] = (unsigned char) input[ii];
1710
else /* must scale the data */
1712
for (ii = 0; ii < ntodo; ii++)
1714
dvalue = input[ii] * scale + zero;
1716
if (dvalue < DUCHAR_MIN)
1718
*status = OVERFLOW_ERR;
1721
else if (dvalue > DUCHAR_MAX)
1723
*status = OVERFLOW_ERR;
1724
output[ii] = UCHAR_MAX;
1727
output[ii] = (unsigned char) dvalue;
1731
else /* must check for null values */
1733
sptr = (short *) input;
1735
#if BYTESWAPPED && MACHINE != VAXVMS && MACHINE != ALPHAVMS
1736
sptr += 3; /* point to MSBs */
1738
if (scale == 1. && zero == 0.) /* no scaling */
1740
for (ii = 0; ii < ntodo; ii++, sptr += 4)
1742
if (0 != (iret = dnan(*sptr)) ) /* test for NaN or underflow */
1744
if (iret == 1) /* is it a NaN? */
1748
output[ii] = nullval;
1752
else /* it's an underflow */
1757
if (input[ii] < DUCHAR_MIN)
1759
*status = OVERFLOW_ERR;
1762
else if (input[ii] > DUCHAR_MAX)
1764
*status = OVERFLOW_ERR;
1765
output[ii] = UCHAR_MAX;
1768
output[ii] = (unsigned char) input[ii];
1772
else /* must scale the data */
1774
for (ii = 0; ii < ntodo; ii++, sptr += 4)
1776
if (0 != (iret = dnan(*sptr)) ) /* test for NaN or underflow */
1778
if (iret == 1) /* is it a NaN? */
1782
output[ii] = nullval;
1786
else /* it's an underflow */
1788
if (zero < DUCHAR_MIN)
1790
*status = OVERFLOW_ERR;
1793
else if (zero > DUCHAR_MAX)
1795
*status = OVERFLOW_ERR;
1796
output[ii] = UCHAR_MAX;
1799
output[ii] = (unsigned char) zero;
1804
dvalue = input[ii] * scale + zero;
1806
if (dvalue < DUCHAR_MIN)
1808
*status = OVERFLOW_ERR;
1811
else if (dvalue > DUCHAR_MAX)
1813
*status = OVERFLOW_ERR;
1814
output[ii] = UCHAR_MAX;
1817
output[ii] = (unsigned char) dvalue;
1824
/*--------------------------------------------------------------------------*/
1825
int fffstri1(char *input, /* I - array of values to be converted */
1826
long ntodo, /* I - number of elements in the array */
1827
double scale, /* I - FITS TSCALn or BSCALE value */
1828
double zero, /* I - FITS TZEROn or BZERO value */
1829
long twidth, /* I - width of each substring of chars */
1830
double implipower, /* I - power of 10 of implied decimal */
1831
int nullcheck, /* I - null checking code; 0 = don't check */
1832
/* 1:set null pixels = nullval */
1833
/* 2: if null pixel, set nullarray = 1 */
1834
char *snull, /* I - value of FITS null string, if any */
1835
unsigned char nullval, /* I - set null pixels, if nullcheck = 1 */
1836
char *nullarray, /* I - bad pixel array, if nullcheck = 2 */
1837
int *anynull, /* O - set to 1 if any pixels are null */
1838
unsigned char *output, /* O - array of converted pixels */
1839
int *status) /* IO - error status */
1841
Copy input to output following reading of the input from a FITS file. Check
1842
for null values and do scaling if required. The nullcheck code value
1843
determines how any null values in the input array are treated. A null
1844
value is an input pixel that is equal to snull. If nullcheck= 0, then
1845
no special checking for nulls is performed. If nullcheck = 1, then the
1846
output pixel will be set = nullval if the corresponding input pixel is null.
1847
If nullcheck = 2, then if the pixel is null then the corresponding value of
1848
nullarray will be set to 1; the value of nullarray for non-null pixels
1849
will = 0. The anynull parameter will be set = 1 if any of the returned
1850
pixels are null, otherwise anynull will be returned with a value = 0;
1856
char *cstring, message[81];
1858
char tempstore, chrzero = '0';
1860
int exponent, sign, esign, decpt;
1862
nullen = strlen(snull);
1863
cptr = input; /* pointer to start of input string */
1864
for (ii = 0; ii < ntodo; ii++)
1867
/* temporarily insert a null terminator at end of the string */
1868
tpos = cptr + twidth;
1872
/* check if null value is defined, and if the */
1873
/* column string is identical to the null string */
1874
if (snull[0] != ASCII_NULL_UNDEFINED &&
1875
!strncmp(snull, cptr, nullen) )
1881
output[ii] = nullval;
1889
/* value is not the null value, so decode it */
1890
/* remove any embedded blank characters from the string */
1899
while (*cptr == ' ') /* skip leading blanks */
1902
if (*cptr == '-' || *cptr == '+') /* check for leading sign */
1909
while (*cptr == ' ') /* skip blanks between sign and value */
1913
while (*cptr >= '0' && *cptr <= '9')
1915
val = val * 10. + *cptr - chrzero; /* accumulate the value */
1918
while (*cptr == ' ') /* skip embedded blanks in the value */
1922
if (*cptr == '.' || *cptr == ',') /* check for decimal point */
1926
while (*cptr == ' ') /* skip any blanks */
1929
while (*cptr >= '0' && *cptr <= '9')
1931
val = val * 10. + *cptr - chrzero; /* accumulate the value */
1932
power = power * 10.;
1935
while (*cptr == ' ') /* skip embedded blanks in the value */
1940
if (*cptr == 'E' || *cptr == 'D') /* check for exponent */
1943
while (*cptr == ' ') /* skip blanks */
1946
if (*cptr == '-' || *cptr == '+') /* check for exponent sign */
1953
while (*cptr == ' ') /* skip blanks between sign and exp */
1957
while (*cptr >= '0' && *cptr <= '9')
1959
exponent = exponent * 10 + *cptr - chrzero; /* accumulate exp */
1962
while (*cptr == ' ') /* skip embedded blanks */
1967
if (*cptr != 0) /* should end up at the null terminator */
1969
sprintf(message, "Cannot read number from ASCII table");
1971
sprintf(message, "Column field = %s.", cstring);
1973
/* restore the char that was overwritten by the null */
1975
return(*status = BAD_C2D);
1978
if (!decpt) /* if no explicit decimal, use implied */
1981
dvalue = (sign * val / power) * pow(10., (double) (esign * exponent));
1983
dvalue = dvalue * scale + zero; /* apply the scaling */
1985
if (dvalue < DUCHAR_MIN)
1987
*status = OVERFLOW_ERR;
1990
else if (dvalue > DUCHAR_MAX)
1992
*status = OVERFLOW_ERR;
1993
output[ii] = UCHAR_MAX;
1996
output[ii] = (unsigned char) dvalue;
1998
/* restore the char that was overwritten by the null */