1
/* This file, putcolb.c, contains routines that write data elements to */
2
/* a FITS image or table with char (byte) 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. */
13
/* declare variable for passing large firstelem values between routines */
14
extern OFF_T large_first_elem_val;
16
/*--------------------------------------------------------------------------*/
17
int ffpprb( fitsfile *fptr, /* I - FITS file pointer */
18
long group, /* I - group to write(1 = 1st group) */
19
long firstelem, /* I - first vector element to write(1 = 1st) */
20
long nelem, /* I - number of values to write */
21
unsigned char *array, /* I - array of values that are written */
22
int *status) /* IO - error status */
24
Write an array of values to 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 written).
30
unsigned char nullvalue;
33
the primary array is represented as a binary table:
34
each group of the primary array is a row in the table,
35
where the first column contains the group parameters
36
and the second column contains the image itself.
39
if (fits_is_compressed_image(fptr, status))
41
/* this is a compressed image in a binary table */
43
/* use the OFF_T variable to pass the first element value */
44
if (firstelem != USE_LARGE_VALUE)
45
large_first_elem_val = firstelem;
47
fits_write_compressed_pixels(fptr, TBYTE, large_first_elem_val, nelem,
48
0, array, &nullvalue, status);
52
row=maxvalue(1,group);
54
ffpclb(fptr, 2, row, firstelem, nelem, array, status);
57
/*--------------------------------------------------------------------------*/
58
int ffppnb( fitsfile *fptr, /* I - FITS file pointer */
59
long group, /* I - group to write(1 = 1st group) */
60
long firstelem, /* I - first vector element to write(1 = 1st) */
61
long nelem, /* I - number of values to write */
62
unsigned char *array, /* I - array of values that are written */
63
unsigned char nulval, /* I - undefined pixel value */
64
int *status) /* IO - error status */
66
Write an array of values to the primary array. Data conversion
67
and scaling will be performed if necessary (e.g, if the datatype of the
68
FITS array is not the same as the array being written). Any array values
69
that are equal to the value of nulval will be replaced with the null
70
pixel value that is appropriate for this column.
74
unsigned char nullvalue;
77
the primary array is represented as a binary table:
78
each group of the primary array is a row in the table,
79
where the first column contains the group parameters
80
and the second column contains the image itself.
83
if (fits_is_compressed_image(fptr, status))
85
/* this is a compressed image in a binary table */
87
/* use the OFF_T variable to pass the first element value */
88
if (firstelem != USE_LARGE_VALUE)
89
large_first_elem_val = firstelem;
91
nullvalue = nulval; /* set local variable */
92
fits_write_compressed_pixels(fptr, TBYTE, large_first_elem_val, nelem,
93
1, array, &nullvalue, status);
97
row=maxvalue(1,group);
99
ffpcnb(fptr, 2, row, firstelem, nelem, array, nulval, status);
102
/*--------------------------------------------------------------------------*/
103
int ffp2db(fitsfile *fptr, /* I - FITS file pointer */
104
long group, /* I - group to write(1 = 1st group) */
105
long ncols, /* I - number of pixels in each row of array */
106
long naxis1, /* I - FITS image NAXIS1 value */
107
long naxis2, /* I - FITS image NAXIS2 value */
108
unsigned char *array, /* I - array to be written */
109
int *status) /* IO - error status */
111
Write an entire 2-D array of values to the primary array. Data conversion
112
and scaling will be performed if necessary (e.g, if the datatype of the
113
FITS array is not the same as the array being written).
116
/* call the 3D writing routine, with the 3rd dimension = 1 */
118
ffp3db(fptr, group, ncols, naxis2, naxis1, naxis2, 1, array, status);
122
/*--------------------------------------------------------------------------*/
123
int ffp3db(fitsfile *fptr, /* I - FITS file pointer */
124
long group, /* I - group to write(1 = 1st group) */
125
long ncols, /* I - number of pixels in each row of array */
126
long nrows, /* I - number of rows in each plane of array */
127
long naxis1, /* I - FITS image NAXIS1 value */
128
long naxis2, /* I - FITS image NAXIS2 value */
129
long naxis3, /* I - FITS image NAXIS3 value */
130
unsigned char *array, /* I - array to be written */
131
int *status) /* IO - error status */
133
Write an entire 3-D cube of values to the primary array. Data conversion
134
and scaling will be performed if necessary (e.g, if the datatype of the
135
FITS array is not the same as the array being written).
138
long tablerow, nfits, narray, ii, jj;
139
long fpixel[3]= {1,1,1}, lpixel[3];
141
the primary array is represented as a binary table:
142
each group of the primary array is a row in the table,
143
where the first column contains the group parameters
144
and the second column contains the image itself.
147
if (fits_is_compressed_image(fptr, status))
149
/* this is a compressed image in a binary table */
154
fits_write_compressed_img(fptr, TBYTE, fpixel, lpixel,
155
0, array, NULL, status);
160
tablerow=maxvalue(1,group);
162
if (ncols == naxis1 && nrows == naxis2) /* arrays have same size? */
164
/* all the image pixels are contiguous, so write all at once */
165
ffpclb(fptr, 2, tablerow, 1L, naxis1 * naxis2 * naxis3, array, status);
169
if (ncols < naxis1 || nrows < naxis2)
170
return(*status = BAD_DIMEN);
172
nfits = 1; /* next pixel in FITS image to write to */
173
narray = 0; /* next pixel in input array to be written */
175
/* loop over naxis3 planes in the data cube */
176
for (jj = 0; jj < naxis3; jj++)
178
/* loop over the naxis2 rows in the FITS image, */
179
/* writing naxis1 pixels to each row */
181
for (ii = 0; ii < naxis2; ii++)
183
if (ffpclb(fptr, 2, tablerow, nfits, naxis1,&array[narray],status) > 0)
189
narray += (nrows - naxis2) * ncols;
193
/*--------------------------------------------------------------------------*/
194
int ffpssb(fitsfile *fptr, /* I - FITS file pointer */
195
long group, /* I - group to write(1 = 1st group) */
196
long naxis, /* I - number of data axes in array */
197
long *naxes, /* I - size of each FITS axis */
198
long *fpixel, /* I - 1st pixel in each axis to write (1=1st) */
199
long *lpixel, /* I - last pixel in each axis to write */
200
unsigned char *array, /* I - array to be written */
201
int *status) /* IO - error status */
203
Write a subsection of pixels to the primary array or image.
204
A subsection is defined to be any contiguous rectangular
205
array of pixels within the n-dimensional FITS data file.
206
Data conversion and scaling will be performed if necessary
207
(e.g, if the datatype of the FITS array is not the same as
208
the array being written).
212
long fpix[7], irange[7], dimen[7], astart, pstart;
213
long off2, off3, off4, off5, off6, off7;
214
long st10, st20, st30, st40, st50, st60, st70;
215
long st1, st2, st3, st4, st5, st6, st7;
216
long ii, i1, i2, i3, i4, i5, i6, i7;
221
if (fits_is_compressed_image(fptr, status))
223
/* this is a compressed image in a binary table */
225
fits_write_compressed_img(fptr, TBYTE, fpixel, lpixel,
226
0, array, NULL, status);
231
if (naxis < 1 || naxis > 7)
232
return(*status = BAD_DIMEN);
234
tablerow=maxvalue(1,group);
236
/* calculate the size and number of loops to perform in each dimension */
237
for (ii = 0; ii < 7; ii++)
244
for (ii = 0; ii < naxis; ii++)
247
irange[ii]=lpixel[ii]-fpixel[ii]+1;
253
/* compute the pixel offset between each dimension */
255
off3 = off2 * dimen[1];
256
off4 = off3 * dimen[2];
257
off5 = off4 * dimen[3];
258
off6 = off5 * dimen[4];
259
off7 = off6 * dimen[5];
262
st20 = (fpix[1] - 1) * off2;
263
st30 = (fpix[2] - 1) * off3;
264
st40 = (fpix[3] - 1) * off4;
265
st50 = (fpix[4] - 1) * off5;
266
st60 = (fpix[5] - 1) * off6;
267
st70 = (fpix[6] - 1) * off7;
269
/* store the initial offset in each dimension */
280
for (i7 = 0; i7 < irange[6]; i7++)
282
for (i6 = 0; i6 < irange[5]; i6++)
284
for (i5 = 0; i5 < irange[4]; i5++)
286
for (i4 = 0; i4 < irange[3]; i4++)
288
for (i3 = 0; i3 < irange[2]; i3++)
290
pstart = st1 + st2 + st3 + st4 + st5 + st6 + st7;
291
for (i2 = 0; i2 < irange[1]; i2++)
293
if (ffpclb(fptr, 2, tablerow, pstart, i1, &array[astart],
317
/*--------------------------------------------------------------------------*/
318
int ffpgpb( fitsfile *fptr, /* I - FITS file pointer */
319
long group, /* I - group to write(1 = 1st group) */
320
long firstelem, /* I - first vector element to write(1 = 1st) */
321
long nelem, /* I - number of values to write */
322
unsigned char *array, /* I - array of values that are written */
323
int *status) /* IO - error status */
325
Write an array of group parameters to the primary array. Data conversion
326
and scaling will be performed if necessary (e.g, if the datatype of
327
the FITS array is not the same as the array being written).
333
the primary array is represented as a binary table:
334
each group of the primary array is a row in the table,
335
where the first column contains the group parameters
336
and the second column contains the image itself.
339
row=maxvalue(1,group);
341
ffpclb(fptr, 1L, row, firstelem, nelem, array, status);
344
/*--------------------------------------------------------------------------*/
345
int ffpclb( fitsfile *fptr, /* I - FITS file pointer */
346
int colnum, /* I - number of column to write (1 = 1st col) */
347
long firstrow, /* I - first row to write (1 = 1st row) */
348
long firstelem, /* I - first vector element to write (1 = 1st) */
349
long nelem, /* I - number of values to write */
350
unsigned char *array, /* I - array of values to write */
351
int *status) /* IO - error status */
353
Write an array of values to a column in the current FITS HDU.
354
The column number may refer to a real column in an ASCII or binary table,
355
or it may refer to a virtual column in a 1 or more grouped FITS primary
356
array. FITSIO treats a primary array as a binary table with
357
2 vector columns: the first column contains the group parameters (often
358
with length = 0) and the second column contains the array of image pixels.
359
Each row of the table represents a group in the case of multigroup FITS
362
The input array of values will be converted to the datatype of the column
363
and will be inverse-scaled by the FITS TSCALn and TZEROn values if necessary.
366
int tcode, maxelem, hdutype, writeraw;
367
long twidth, incre, rownum, remain, next, ntodo;
369
OFF_T repeat, startpos, elemnum, large_elem, wrtptr, rowlen;
371
char tform[20], cform[20];
372
char message[FLEN_ERRMSG];
374
char snull[20]; /* the FITS null value */
376
double cbuff[DBUFFSIZE / sizeof(double)]; /* align cbuff on word boundary */
379
if (*status > 0) /* inherit input status value if > 0 */
384
if (firstelem == USE_LARGE_VALUE)
385
large_elem = large_first_elem_val;
387
large_elem = firstelem;
389
/*---------------------------------------------------*/
390
/* Check input and get parameters about the column: */
391
/*---------------------------------------------------*/
392
if (ffgcpr( fptr, colnum, firstrow, large_elem, nelem, 1, &scale, &zero,
393
tform, &twidth, &tcode, &maxelem, &startpos, &elemnum, &incre,
394
&repeat, &rowlen, &hdutype, &tnull, snull, status) > 0)
397
if (tcode == TSTRING)
398
ffcfmt(tform, cform); /* derive C format for writing strings */
401
if there is no scaling
402
then we can simply write the raw data bytes into the FITS file if the
403
datatype of the FITS column is the same as the input values. Otherwise,
404
we must convert the raw values into the scaled and/or machine dependent
405
format in a temporary buffer that has been allocated for this purpose.
407
if (scale == 1. && zero == 0. && tcode == TBYTE)
410
maxelem = nelem; /* we can write the entire array at one time */
415
/*---------------------------------------------------------------------*/
416
/* Now write the pixels to the FITS column. */
417
/* First call the ffXXfYY routine to (1) convert the datatype */
418
/* if necessary, and (2) scale the values by the FITS TSCALn and */
419
/* TZEROn linear scaling parameters into a temporary buffer. */
420
/*---------------------------------------------------------------------*/
421
remain = nelem; /* remaining number of values to write */
422
next = 0; /* next element in array to be written */
423
rownum = 0; /* row number, relative to firstrow */
427
/* limit the number of pixels to process a one time to the number that
428
will fit in the buffer space or to the number of pixels that remain
429
in the current vector, which ever is smaller.
431
ntodo = minvalue(remain, maxelem);
432
ntodo = minvalue(ntodo, (repeat - elemnum));
434
wrtptr = startpos + ((OFF_T)rownum * rowlen) + (elemnum * incre);
435
ffmbyt(fptr, wrtptr, IGNORE_EOF, status); /* move to write position */
442
/* write raw input bytes without conversion */
443
ffpi1b(fptr, ntodo, incre, &array[next], status);
447
/* convert the raw data before writing to FITS file */
448
ffi1fi1(&array[next], ntodo, scale, zero,
449
(unsigned char *) buffer, status);
450
ffpi1b(fptr, ntodo, incre, (unsigned char *) buffer, status);
457
ffi1fi8(&array[next], ntodo, scale, zero,
458
(LONGLONG *) buffer, status);
459
ffpi8b(fptr, ntodo, incre, (long *) buffer, status);
464
ffi1fi2(&array[next], ntodo, scale, zero,
465
(short *) buffer, status);
466
ffpi2b(fptr, ntodo, incre, (short *) buffer, status);
471
ffi1fi4(&array[next], ntodo, scale, zero,
472
(INT32BIT *) buffer, status);
473
ffpi4b(fptr, ntodo, incre, (INT32BIT *) buffer, status);
478
ffi1fr4(&array[next], ntodo, scale, zero,
479
(float *) buffer, status);
480
ffpr4b(fptr, ntodo, incre, (float *) buffer, status);
484
ffi1fr8(&array[next], ntodo, scale, zero,
485
(double *) buffer, status);
486
ffpr8b(fptr, ntodo, incre, (double *) buffer, status);
489
case (TSTRING): /* numerical column in an ASCII table */
491
if (strchr(tform,'A'))
493
/* write raw input bytes without conversion */
494
/* This case is a hack to let users write a stream */
495
/* of bytes directly to the 'A' format column */
498
ffpbyt(fptr, ntodo, &array[next], status);
500
ffpbytoff(fptr, twidth, ntodo/twidth, incre - twidth,
501
&array[next], status);
504
else if (cform[1] != 's') /* "%s" format is a string */
506
ffi1fstr(&array[next], ntodo, scale, zero, cform,
507
twidth, (char *) buffer, status);
509
if (incre == twidth) /* contiguous bytes */
510
ffpbyt(fptr, ntodo * twidth, buffer, status);
512
ffpbytoff(fptr, twidth, ntodo, incre - twidth, buffer,
516
/* can't write to string column, so fall thru to default: */
518
default: /* error trap */
520
"Cannot write numbers to column %d which has format %s",
523
if (hdutype == ASCII_TBL)
524
return(*status = BAD_ATABLE_FORMAT);
526
return(*status = BAD_BTABLE_FORMAT);
528
} /* End of switch block */
530
/*-------------------------*/
531
/* Check for fatal error */
532
/*-------------------------*/
533
if (*status > 0) /* test for error during previous write operation */
536
"Error writing elements %ld thru %ld of input data array (ffpclb).",
542
/*--------------------------------------------*/
543
/* increment the counters for the next loop */
544
/*--------------------------------------------*/
550
if (elemnum == repeat) /* completed a row; start on next row */
556
} /* End of main while Loop */
559
/*--------------------------------*/
560
/* check for numerical overflow */
561
/*--------------------------------*/
562
if (*status == OVERFLOW_ERR)
565
"Numerical overflow during type conversion while writing FITS data.");
566
*status = NUM_OVERFLOW;
571
/*--------------------------------------------------------------------------*/
572
int ffpcnb( fitsfile *fptr, /* I - FITS file pointer */
573
int colnum, /* I - number of column to write (1 = 1st col) */
574
long firstrow, /* I - first row to write (1 = 1st row) */
575
long firstelem, /* I - first vector element to write (1 = 1st) */
576
long nelem, /* I - number of values to write */
577
unsigned char *array, /* I - array of values to write */
578
unsigned char nulvalue, /* I - flag for undefined pixels */
579
int *status) /* IO - error status */
581
Write an array of elements to the specified column of a table. Any input
582
pixels equal to the value of nulvalue will be replaced by the appropriate
583
null value in the output FITS file.
585
The input array of values will be converted to the datatype of the column
586
and will be inverse-scaled by the FITS TSCALn and TZEROn values if necessary
590
long ngood = 0, nbad = 0, ii, fstrow;
591
OFF_T large_elem, repeat, first, fstelm;
596
/* reset position to the correct HDU if necessary */
597
if (fptr->HDUposition != (fptr->Fptr)->curhdu)
599
ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status);
601
else if ((fptr->Fptr)->datastart == DATA_UNDEFINED)
603
if ( ffrdef(fptr, status) > 0) /* rescan header */
607
colptr = (fptr->Fptr)->tableptr; /* point to first column */
608
colptr += (colnum - 1); /* offset to correct column structure */
610
repeat = colptr->trepeat; /* repeat count for this column */
612
if (firstelem == USE_LARGE_VALUE)
613
large_elem = large_first_elem_val;
615
large_elem = firstelem;
617
/* hereafter, pass first element parameter via global variable */
618
firstelem = USE_LARGE_VALUE;
620
/* absolute element number in the column */
621
first = (firstrow - 1) * repeat + large_elem;
623
for (ii = 0; ii < nelem; ii++)
625
if (array[ii] != nulvalue) /* is this a good pixel? */
627
if (nbad) /* write previous string of bad pixels */
629
fstelm = ii - nbad + first; /* absolute element number */
630
fstrow = (fstelm - 1) / repeat + 1; /* starting row number */
631
fstelm = fstelm - (fstrow - 1) * repeat; /* relative number */
632
large_first_elem_val = fstelm;
634
if (ffpclu(fptr, colnum, fstrow, firstelem, nbad, status) > 0)
640
ngood = ngood + 1; /* the consecutive number of good pixels */
644
if (ngood) /* write previous string of good pixels */
646
fstelm = ii - ngood + first; /* absolute element number */
647
fstrow = (fstelm - 1) / repeat + 1; /* starting row number */
648
fstelm = fstelm - (fstrow - 1) * repeat; /* relative number */
649
large_first_elem_val = fstelm;
651
if (ffpclb(fptr, colnum, fstrow, firstelem, ngood, &array[ii-ngood],
658
nbad = nbad + 1; /* the consecutive number of bad pixels */
662
/* finished loop; now just write the last set of pixels */
664
if (ngood) /* write last string of good pixels */
666
fstelm = ii - ngood + first; /* absolute element number */
667
fstrow = (fstelm - 1) / repeat + 1; /* starting row number */
668
fstelm = fstelm - (fstrow - 1) * repeat; /* relative number */
669
large_first_elem_val = fstelm;
671
ffpclb(fptr, colnum, fstrow, firstelem, ngood, &array[ii-ngood], status);
673
else if (nbad) /* write last string of bad pixels */
675
fstelm = ii - nbad + first; /* absolute element number */
676
fstrow = (fstelm - 1) / repeat + 1; /* starting row number */
677
fstelm = fstelm - (fstrow - 1) * repeat; /* relative number */
678
large_first_elem_val = fstelm;
680
ffpclu(fptr, colnum, fstrow, firstelem, nbad, status);
685
/*--------------------------------------------------------------------------*/
686
int ffi1fi1(unsigned char *input, /* I - array of values to be converted */
687
long ntodo, /* I - number of elements in the array */
688
double scale, /* I - FITS TSCALn or BSCALE value */
689
double zero, /* I - FITS TZEROn or BZERO value */
690
unsigned char *output, /* O - output array of converted values */
691
int *status) /* IO - error status */
693
Copy input to output prior to writing output to a FITS file.
694
Do datatype conversion and scaling if required
700
if (scale == 1. && zero == 0.)
702
memcpy(output, input, ntodo); /* just copy input to output */
706
for (ii = 0; ii < ntodo; ii++)
708
dvalue = ( ((double) input[ii]) - zero) / scale;
710
if (dvalue < DUCHAR_MIN)
712
*status = OVERFLOW_ERR;
715
else if (dvalue > DUCHAR_MAX)
717
*status = OVERFLOW_ERR;
718
output[ii] = UCHAR_MAX;
721
output[ii] = (unsigned char) (dvalue + .5);
726
/*--------------------------------------------------------------------------*/
727
int ffi1fi2(unsigned char *input, /* I - array of values to be converted */
728
long ntodo, /* I - number of elements in the array */
729
double scale, /* I - FITS TSCALn or BSCALE value */
730
double zero, /* I - FITS TZEROn or BZERO value */
731
short *output, /* O - output array of converted values */
732
int *status) /* IO - error status */
734
Copy input to output prior to writing output to a FITS file.
735
Do datatype conversion and scaling if required
741
if (scale == 1. && zero == 0.)
743
for (ii = 0; ii < ntodo; ii++)
744
output[ii] = input[ii]; /* just copy input to output */
748
for (ii = 0; ii < ntodo; ii++)
750
dvalue = (((double) input[ii]) - zero) / scale;
752
if (dvalue < DSHRT_MIN)
754
*status = OVERFLOW_ERR;
755
output[ii] = SHRT_MIN;
757
else if (dvalue > DSHRT_MAX)
759
*status = OVERFLOW_ERR;
760
output[ii] = SHRT_MAX;
765
output[ii] = (short) (dvalue + .5);
767
output[ii] = (short) (dvalue - .5);
773
/*--------------------------------------------------------------------------*/
774
int ffi1fi4(unsigned char *input, /* I - array of values to be converted */
775
long ntodo, /* I - number of elements in the array */
776
double scale, /* I - FITS TSCALn or BSCALE value */
777
double zero, /* I - FITS TZEROn or BZERO value */
778
INT32BIT *output, /* O - output array of converted values */
779
int *status) /* IO - error status */
781
Copy input to output prior to writing output to a FITS file.
782
Do datatype conversion and scaling if required
788
if (scale == 1. && zero == 0.)
790
for (ii = 0; ii < ntodo; ii++)
791
output[ii] = (INT32BIT) input[ii]; /* copy input to output */
795
for (ii = 0; ii < ntodo; ii++)
797
dvalue = (((double) input[ii]) - zero) / scale;
799
if (dvalue < DINT_MIN)
801
*status = OVERFLOW_ERR;
802
output[ii] = INT32_MIN;
804
else if (dvalue > DINT_MAX)
806
*status = OVERFLOW_ERR;
807
output[ii] = INT32_MAX;
812
output[ii] = (INT32BIT) (dvalue + .5);
814
output[ii] = (INT32BIT) (dvalue - .5);
820
/*--------------------------------------------------------------------------*/
821
int ffi1fi8(unsigned char *input, /* I - array of values to be converted */
822
long ntodo, /* I - number of elements in the array */
823
double scale, /* I - FITS TSCALn or BSCALE value */
824
double zero, /* I - FITS TZEROn or BZERO value */
825
LONGLONG *output, /* O - output array of converted values */
826
int *status) /* IO - error status */
828
Copy input to output prior to writing output to a FITS file.
829
Do datatype conversion and scaling if required
832
#if (LONGSIZE == 32) && (! defined HAVE_LONGLONG)
834
/* don't have a native 8-byte integer, so have to construct the */
835
/* 2 equivalent 4-byte integers have the same bit pattern */
837
unsigned long *uoutput;
838
long ii, jj, kk, temp;
841
uoutput = (unsigned long *) output;
843
#if BYTESWAPPED /* jj points to the most significant part of the 8-byte int */
851
if (scale == 1. && zero == 0.)
853
for (ii = 0; ii < ntodo; ii++, jj += 2, kk += 2)
856
output[kk] = input[ii];
861
for (ii = 0; ii < ntodo; ii++, jj += 2, kk += 2)
863
dvalue = (input[ii] - zero) / scale;
865
if (dvalue < DLONGLONG_MIN)
867
*status = OVERFLOW_ERR;
868
output[jj] = LONG_MIN;
871
else if (dvalue > DLONGLONG_MAX)
873
*status = OVERFLOW_ERR;
874
output[jj] = LONG_MAX;
881
temp = (dvalue + 1.) / 4294967296. - 1.;
883
uoutput[kk] = 4294967296. +
884
(dvalue - (double) (temp + 1) * 4294967296.);
888
temp = dvalue / 4294967296.;
890
uoutput[kk] = dvalue - (double) temp * 4294967296.;
898
/* this is the much simpler case where the native 8-byte integer exists */
903
if (scale == 1. && zero == 0.)
905
for (ii = 0; ii < ntodo; ii++)
906
output[ii] = input[ii];
910
for (ii = 0; ii < ntodo; ii++)
912
dvalue = (input[ii] - zero) / scale;
914
if (dvalue < DLONGLONG_MIN)
916
*status = OVERFLOW_ERR;
917
output[ii] = LONGLONG_MIN;
919
else if (dvalue > DLONGLONG_MAX)
921
*status = OVERFLOW_ERR;
922
output[ii] = LONGLONG_MAX;
927
output[ii] = (LONGLONG) (dvalue + .5);
929
output[ii] = (LONGLONG) (dvalue - .5);
938
/*--------------------------------------------------------------------------*/
939
int ffi1fr4(unsigned char *input, /* I - array of values to be converted */
940
long ntodo, /* I - number of elements in the array */
941
double scale, /* I - FITS TSCALn or BSCALE value */
942
double zero, /* I - FITS TZEROn or BZERO value */
943
float *output, /* O - output array of converted values */
944
int *status) /* IO - error status */
946
Copy input to output prior to writing output to a FITS file.
947
Do datatype conversion and scaling if required.
952
if (scale == 1. && zero == 0.)
954
for (ii = 0; ii < ntodo; ii++)
955
output[ii] = (float) input[ii];
959
for (ii = 0; ii < ntodo; ii++)
960
output[ii] = ( ( (double) input[ii] ) - zero) / scale;
964
/*--------------------------------------------------------------------------*/
965
int ffi1fr8(unsigned char *input, /* I - array of values to be converted */
966
long ntodo, /* I - number of elements in the array */
967
double scale, /* I - FITS TSCALn or BSCALE value */
968
double zero, /* I - FITS TZEROn or BZERO value */
969
double *output, /* O - output array of converted values */
970
int *status) /* IO - error status */
972
Copy input to output prior to writing output to a FITS file.
973
Do datatype conversion and scaling if required.
978
if (scale == 1. && zero == 0.)
980
for (ii = 0; ii < ntodo; ii++)
981
output[ii] = (double) input[ii];
985
for (ii = 0; ii < ntodo; ii++)
986
output[ii] = ( ( (double) input[ii] ) - zero) / scale;
990
/*--------------------------------------------------------------------------*/
991
int ffi1fstr(unsigned char *input, /* I - array of values to be converted */
992
long ntodo, /* I - number of elements in the array */
993
double scale, /* I - FITS TSCALn or BSCALE value */
994
double zero, /* I - FITS TZEROn or BZERO value */
995
char *cform, /* I - format for output string values */
996
long twidth, /* I - width of each field, in chars */
997
char *output, /* O - output array of converted values */
998
int *status) /* IO - error status */
1000
Copy input to output prior to writing output to a FITS file.
1001
Do scaling if required.
1007
if (scale == 1. && zero == 0.)
1009
for (ii = 0; ii < ntodo; ii++)
1011
sprintf(output, cform, (double) input[ii]);
1014
if (*output) /* if this char != \0, then overflow occurred */
1015
*status = OVERFLOW_ERR;
1020
for (ii = 0; ii < ntodo; ii++)
1022
dvalue = ((double) input[ii] - zero) / scale;
1023
sprintf(output, cform, dvalue);
1026
if (*output) /* if this char != \0, then overflow occurred */
1027
*status = OVERFLOW_ERR;