1
/* This file, putcole.c, contains routines that write data elements to */
2
/* a FITS image or table, with float 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 ffppre( 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
float *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).
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, TFLOAT, large_first_elem_val, nelem,
48
0, array, &nullvalue, status);
52
row=maxvalue(1,group);
54
ffpcle(fptr, 2, row, firstelem, nelem, array, status);
57
/*--------------------------------------------------------------------------*/
58
int ffppne( 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
float *array, /* I - array of values that are written */
63
float 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.
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, TFLOAT, large_first_elem_val, nelem,
93
1, array, &nullvalue, status);
97
row=maxvalue(1,group);
99
ffpcne(fptr, 2, row, firstelem, nelem, array, nulval, status);
102
/*--------------------------------------------------------------------------*/
103
int ffp2de(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
float *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
ffp3de(fptr, group, ncols, naxis2, naxis1, naxis2, 1, array, status);
122
/*--------------------------------------------------------------------------*/
123
int ffp3de(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
float *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, TFLOAT, 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
ffpcle(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 (ffpcle(fptr, 2, tablerow, nfits, naxis1,&array[narray],status) > 0)
189
narray += (nrows - naxis2) * ncols;
193
/*--------------------------------------------------------------------------*/
194
int ffpsse(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
float *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, TFLOAT, 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 (ffpcle(fptr, 2, tablerow, pstart, i1, &array[astart],
317
/*--------------------------------------------------------------------------*/
318
int ffpgpe( 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
float *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
ffpcle(fptr, 1L, row, firstelem, nelem, array, status);
344
/*--------------------------------------------------------------------------*/
345
int ffpcle( 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
float *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
357
with 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)
398
if (tcode == TSTRING)
399
ffcfmt(tform, cform); /* derive C format for writing strings */
402
if there is no scaling and the native machine format is not byteswapped
403
then we can simply write the raw data bytes into the FITS file if the
404
datatype of the FITS column is the same as the input values. Otherwise,
405
we must convert the raw values into the scaled and/or machine dependent
406
format in a temporary buffer that has been allocated for this purpose.
408
if (scale == 1. && zero == 0. &&
409
MACHINE == NATIVE && tcode == TFLOAT)
412
maxelem = nelem; /* we can write the entire array at one time */
417
/*---------------------------------------------------------------------*/
418
/* Now write the pixels to the FITS column. */
419
/* First call the ffXXfYY routine to (1) convert the datatype */
420
/* if necessary, and (2) scale the values by the FITS TSCALn and */
421
/* TZEROn linear scaling parameters into a temporary buffer. */
422
/*---------------------------------------------------------------------*/
423
remain = nelem; /* remaining number of values to write */
424
next = 0; /* next element in array to be written */
425
rownum = 0; /* row number, relative to firstrow */
429
/* limit the number of pixels to process a one time to the number that
430
will fit in the buffer space or to the number of pixels that remain
431
in the current vector, which ever is smaller.
433
ntodo = minvalue(remain, maxelem);
434
ntodo = minvalue(ntodo, (repeat - elemnum));
436
wrtptr = startpos + ((OFF_T)rownum * rowlen) + (elemnum * incre);
438
ffmbyt(fptr, wrtptr, IGNORE_EOF, status); /* move to write position */
445
/* write raw input bytes without conversion */
446
ffpr4b(fptr, ntodo, incre, &array[next], status);
450
/* convert the raw data before writing to FITS file */
451
ffr4fr4(&array[next], ntodo, scale, zero,
452
(float *) buffer, status);
453
ffpr4b(fptr, ntodo, incre, (float *) buffer, status);
460
ffr4fi8(&array[next], ntodo, scale, zero,
461
(LONGLONG *) buffer, status);
462
ffpi8b(fptr, ntodo, incre, (long *) buffer, status);
467
ffr4fi1(&array[next], ntodo, scale, zero,
468
(unsigned char *) buffer, status);
469
ffpi1b(fptr, ntodo, incre, (unsigned char *) buffer, status);
474
ffr4fi2(&array[next], ntodo, scale, zero,
475
(short *) buffer, status);
476
ffpi2b(fptr, ntodo, incre, (short *) buffer, status);
481
ffr4fi4(&array[next], ntodo, scale, zero,
482
(INT32BIT *) buffer, status);
483
ffpi4b(fptr, ntodo, incre, (INT32BIT *) buffer, status);
487
ffr4fr8(&array[next], ntodo, scale, zero,
488
(double *) buffer, status);
489
ffpr8b(fptr, ntodo, incre, (double *) buffer, status);
492
case (TSTRING): /* numerical column in an ASCII table */
494
if (cform[1] != 's') /* "%s" format is a string */
496
ffr4fstr(&array[next], ntodo, scale, zero, cform,
497
twidth, (char *) buffer, status);
499
if (incre == twidth) /* contiguous bytes */
500
ffpbyt(fptr, ntodo * twidth, buffer, status);
502
ffpbytoff(fptr, twidth, ntodo, incre - twidth, buffer,
507
/* can't write to string column, so fall thru to default: */
509
default: /* error trap */
511
"Cannot write numbers to column %d which has format %s",
514
if (hdutype == ASCII_TBL)
515
return(*status = BAD_ATABLE_FORMAT);
517
return(*status = BAD_BTABLE_FORMAT);
519
} /* End of switch block */
521
/*-------------------------*/
522
/* Check for fatal error */
523
/*-------------------------*/
524
if (*status > 0) /* test for error during previous write operation */
527
"Error writing elements %ld thru %ld of input data array (ffpcle).",
533
/*--------------------------------------------*/
534
/* increment the counters for the next loop */
535
/*--------------------------------------------*/
541
if (elemnum == repeat) /* completed a row; start on next row */
547
} /* End of main while Loop */
550
/*--------------------------------*/
551
/* check for numerical overflow */
552
/*--------------------------------*/
553
if (*status == OVERFLOW_ERR)
556
"Numerical overflow during type conversion while writing FITS data.");
557
*status = NUM_OVERFLOW;
562
/*--------------------------------------------------------------------------*/
563
int ffpclc( fitsfile *fptr, /* I - FITS file pointer */
564
int colnum, /* I - number of column to write (1 = 1st col) */
565
long firstrow, /* I - first row to write (1 = 1st row) */
566
long firstelem, /* I - first vector element to write (1 = 1st) */
567
long nelem, /* I - number of values to write */
568
float *array, /* I - array of values to write */
569
int *status) /* IO - error status */
571
Write an array of complex values to a column in the current FITS HDU.
572
Each complex number if interpreted as a pair of float values.
573
The column number may refer to a real column in an ASCII or binary table,
574
or it may refer to a virtual column in a 1 or more grouped FITS primary
575
array. FITSIO treats a primary array as a binary table
576
with 2 vector columns: the first column contains the group parameters (often
577
with length = 0) and the second column contains the array of image pixels.
578
Each row of the table represents a group in the case of multigroup FITS
581
The input array of values will be converted to the datatype of the column
582
if necessary, but normally complex values should only be written to a binary
583
table with TFORMn = 'rC' where r is an optional repeat count. The TSCALn and
584
TZERO keywords should not be used with complex numbers because mathmatically
585
the scaling should only be applied to the real (first) component of the
589
/* simply multiply the number of elements by 2, and call ffpcle */
591
ffpcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1,
592
nelem * 2, array, status);
595
/*--------------------------------------------------------------------------*/
596
int ffpcne( fitsfile *fptr, /* I - FITS file pointer */
597
int colnum, /* I - number of column to write (1 = 1st col) */
598
long firstrow, /* I - first row to write (1 = 1st row) */
599
long firstelem, /* I - first vector element to write (1 = 1st) */
600
long nelem, /* I - number of values to write */
601
float *array, /* I - array of values to write */
602
float nulvalue, /* I - value used to flag undefined pixels */
603
int *status) /* IO - error status */
605
Write an array of elements to the specified column of a table. Any input
606
pixels equal to the value of nulvalue will be replaced by the appropriate
607
null value in the output FITS file.
609
The input array of values will be converted to the datatype of the column
610
and will be inverse-scaled by the FITS TSCALn and TZEROn values if necessary
614
long ngood = 0, nbad = 0, ii, fstrow;
615
OFF_T large_elem, repeat, first, fstelm;
620
/* reset position to the correct HDU if necessary */
621
if (fptr->HDUposition != (fptr->Fptr)->curhdu)
623
ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status);
625
else if ((fptr->Fptr)->datastart == DATA_UNDEFINED)
627
if ( ffrdef(fptr, status) > 0) /* rescan header */
631
colptr = (fptr->Fptr)->tableptr; /* point to first column */
632
colptr += (colnum - 1); /* offset to correct column structure */
634
repeat = colptr->trepeat; /* repeat count for this column */
636
if (firstelem == USE_LARGE_VALUE)
637
large_elem = large_first_elem_val;
639
large_elem = firstelem;
641
/* hereafter, pass first element parameter via global variable */
642
firstelem = USE_LARGE_VALUE;
644
/* absolute element number in the column */
645
first = (firstrow - 1) * repeat + large_elem;
647
for (ii = 0; ii < nelem; ii++)
649
if (array[ii] != nulvalue) /* is this a good pixel? */
651
if (nbad) /* write previous string of bad pixels */
653
fstelm = ii - nbad + first; /* absolute element number */
654
fstrow = (fstelm - 1) / repeat + 1; /* starting row number */
655
fstelm = fstelm - (fstrow - 1) * repeat; /* relative number */
656
large_first_elem_val = fstelm;
658
if (ffpclu(fptr, colnum, fstrow, firstelem, nbad, status) > 0)
664
ngood = ngood +1; /* the consecutive number of good pixels */
668
if (ngood) /* write previous string of good pixels */
670
fstelm = ii - ngood + first; /* absolute element number */
671
fstrow = (fstelm - 1) / repeat + 1; /* starting row number */
672
fstelm = fstelm - (fstrow - 1) * repeat; /* relative number */
673
large_first_elem_val = fstelm;
675
if (ffpcle(fptr, colnum, fstrow, firstelem, ngood, &array[ii-ngood],
682
nbad = nbad +1; /* the consecutive number of bad pixels */
686
/* finished loop; now just write the last set of pixels */
688
if (ngood) /* write last string of good pixels */
690
fstelm = ii - ngood + first; /* absolute element number */
691
fstrow = (fstelm - 1) / repeat + 1; /* starting row number */
692
fstelm = fstelm - (fstrow - 1) * repeat; /* relative number */
693
large_first_elem_val = fstelm;
695
ffpcle(fptr, colnum, fstrow, firstelem, ngood, &array[ii-ngood], status);
697
else if (nbad) /* write last string of bad pixels */
699
fstelm = ii - nbad + first; /* absolute element number */
700
fstrow = (fstelm - 1) / repeat + 1; /* starting row number */
701
fstelm = fstelm - (fstrow - 1) * repeat; /* relative number */
702
large_first_elem_val = fstelm;
703
ffpclu(fptr, colnum, fstrow, firstelem, nbad, status);
708
/*--------------------------------------------------------------------------*/
709
int ffr4fi1(float *input, /* I - array of values to be converted */
710
long ntodo, /* I - number of elements in the array */
711
double scale, /* I - FITS TSCALn or BSCALE value */
712
double zero, /* I - FITS TZEROn or BZERO value */
713
unsigned char *output, /* O - output array of converted values */
714
int *status) /* IO - error status */
716
Copy input to output prior to writing output to a FITS file.
717
Do datatype conversion and scaling if required.
723
if (scale == 1. && zero == 0.)
725
for (ii = 0; ii < ntodo; ii++)
727
if (input[ii] < DUCHAR_MIN)
729
*status = OVERFLOW_ERR;
732
else if (input[ii] > DUCHAR_MAX)
734
*status = OVERFLOW_ERR;
735
output[ii] = UCHAR_MAX;
738
output[ii] = (unsigned char) input[ii];
743
for (ii = 0; ii < ntodo; ii++)
745
dvalue = (input[ii] - zero) / scale;
747
if (dvalue < DUCHAR_MIN)
749
*status = OVERFLOW_ERR;
752
else if (dvalue > DUCHAR_MAX)
754
*status = OVERFLOW_ERR;
755
output[ii] = UCHAR_MAX;
758
output[ii] = (unsigned char) (dvalue + .5);
763
/*--------------------------------------------------------------------------*/
764
int ffr4fi2(float *input, /* I - array of values to be converted */
765
long ntodo, /* I - number of elements in the array */
766
double scale, /* I - FITS TSCALn or BSCALE value */
767
double zero, /* I - FITS TZEROn or BZERO value */
768
short *output, /* O - output array of converted values */
769
int *status) /* IO - error status */
771
Copy input to output prior to writing output to a FITS file.
772
Do datatype conversion and scaling if required.
778
if (scale == 1. && zero == 0.)
780
for (ii = 0; ii < ntodo; ii++)
782
if (input[ii] < DSHRT_MIN)
784
*status = OVERFLOW_ERR;
785
output[ii] = SHRT_MIN;
787
else if (input[ii] > DSHRT_MAX)
789
*status = OVERFLOW_ERR;
790
output[ii] = SHRT_MAX;
793
output[ii] = (short) input[ii];
798
for (ii = 0; ii < ntodo; ii++)
800
dvalue = (input[ii] - zero) / scale;
802
if (dvalue < DSHRT_MIN)
804
*status = OVERFLOW_ERR;
805
output[ii] = SHRT_MIN;
807
else if (dvalue > DSHRT_MAX)
809
*status = OVERFLOW_ERR;
810
output[ii] = SHRT_MAX;
815
output[ii] = (short) (dvalue + .5);
817
output[ii] = (short) (dvalue - .5);
823
/*--------------------------------------------------------------------------*/
824
int ffr4fi4(float *input, /* I - array of values to be converted */
825
long ntodo, /* I - number of elements in the array */
826
double scale, /* I - FITS TSCALn or BSCALE value */
827
double zero, /* I - FITS TZEROn or BZERO value */
828
INT32BIT *output, /* O - output array of converted values */
829
int *status) /* IO - error status */
831
Copy input to output prior to writing output to a FITS file.
832
Do datatype conversion and scaling if required.
838
if (scale == 1. && zero == 0.)
840
for (ii = 0; ii < ntodo; ii++)
842
if (input[ii] < DINT_MIN)
844
*status = OVERFLOW_ERR;
845
output[ii] = INT32_MIN;
847
else if (input[ii] > DINT_MAX)
849
*status = OVERFLOW_ERR;
850
output[ii] = INT32_MAX;
853
output[ii] = (INT32BIT) input[ii];
858
for (ii = 0; ii < ntodo; ii++)
860
dvalue = (input[ii] - zero) / scale;
862
if (dvalue < DINT_MIN)
864
*status = OVERFLOW_ERR;
865
output[ii] = INT32_MIN;
867
else if (dvalue > DINT_MAX)
869
*status = OVERFLOW_ERR;
870
output[ii] = INT32_MAX;
875
output[ii] = (INT32BIT) (dvalue + .5);
877
output[ii] = (INT32BIT) (dvalue - .5);
883
/*--------------------------------------------------------------------------*/
884
int ffr4fi8(float *input, /* I - array of values to be converted */
885
long ntodo, /* I - number of elements in the array */
886
double scale, /* I - FITS TSCALn or BSCALE value */
887
double zero, /* I - FITS TZEROn or BZERO value */
888
LONGLONG *output, /* O - output array of converted values */
889
int *status) /* IO - error status */
891
Copy input to output prior to writing output to a FITS file.
892
Do datatype conversion and scaling if required.
895
#if (LONGSIZE == 32) && (! defined HAVE_LONGLONG)
897
/* don't have a native 8-byte integer, so have to construct the */
898
/* 2 equivalent 4-byte integers have the same bit pattern */
900
unsigned long *uoutput;
901
long ii, jj, kk, temp;
904
uoutput = (unsigned long *) output;
906
#if BYTESWAPPED /* jj points to the most significant part of the 8-byte int */
914
if (scale == 1. && zero == 0.)
916
for (ii = 0; ii < ntodo; ii++, jj += 2, kk += 2)
918
if (input[ii] < DLONGLONG_MIN)
920
*status = OVERFLOW_ERR;
921
output[jj] = LONG_MIN;
924
else if (input[ii] > DLONGLONG_MAX)
926
*status = OVERFLOW_ERR;
927
output[jj] = LONG_MAX;
934
temp = (input[ii] + 1.) / 4294967296. - 1.;
936
uoutput[kk] = 4294967296. +
937
(input[ii] - (double) (temp + 1) * 4294967296.);
941
temp = input[ii] / 4294967296.;
943
uoutput[kk] = input[ii] - (double) temp * 4294967296.;
950
for (ii = 0; ii < ntodo; ii++, jj += 2, kk += 2)
952
dvalue = (input[ii] - zero) / scale;
954
if (dvalue < DLONGLONG_MIN)
956
*status = OVERFLOW_ERR;
957
output[jj] = LONG_MIN;
960
else if (dvalue > DLONGLONG_MAX)
962
*status = OVERFLOW_ERR;
963
output[jj] = LONG_MAX;
970
temp = (dvalue + 1.) / 4294967296. - 1.;
972
uoutput[kk] = 4294967296. +
973
(dvalue - (double) (temp + 1) * 4294967296.);
977
temp = dvalue / 4294967296.;
979
uoutput[kk] = dvalue - (double) temp * 4294967296.;
987
/* this is the much simpler case where the native 8-byte integer exists */
992
if (scale == 1. && zero == 0.)
994
for (ii = 0; ii < ntodo; ii++)
996
if (input[ii] < DLONGLONG_MIN)
998
*status = OVERFLOW_ERR;
999
output[ii] = LONGLONG_MIN;
1001
else if (input[ii] > DLONGLONG_MAX)
1003
*status = OVERFLOW_ERR;
1004
output[ii] = LONGLONG_MAX;
1007
output[ii] = (long) input[ii];
1012
for (ii = 0; ii < ntodo; ii++)
1014
dvalue = (input[ii] - zero) / scale;
1016
if (dvalue < DLONGLONG_MIN)
1018
*status = OVERFLOW_ERR;
1019
output[ii] = LONGLONG_MIN;
1021
else if (dvalue > DINT_MAX)
1023
*status = OVERFLOW_ERR;
1024
output[ii] = LONGLONG_MAX;
1029
output[ii] = (LONGLONG) (dvalue + .5);
1031
output[ii] = (LONGLONG) (dvalue - .5);
1040
/*--------------------------------------------------------------------------*/
1041
int ffr4fr4(float *input, /* I - array of values to be converted */
1042
long ntodo, /* I - number of elements in the array */
1043
double scale, /* I - FITS TSCALn or BSCALE value */
1044
double zero, /* I - FITS TZEROn or BZERO value */
1045
float *output, /* O - output array of converted values */
1046
int *status) /* IO - error status */
1048
Copy input to output prior to writing output to a FITS file.
1049
Do datatype conversion and scaling if required.
1054
if (scale == 1. && zero == 0.)
1056
memcpy(output, input, ntodo * sizeof(float) ); /* copy input to output */
1060
for (ii = 0; ii < ntodo; ii++)
1061
output[ii] = (input[ii] - zero) / scale;
1065
/*--------------------------------------------------------------------------*/
1066
int ffr4fr8(float *input, /* I - array of values to be converted */
1067
long ntodo, /* I - number of elements in the array */
1068
double scale, /* I - FITS TSCALn or BSCALE value */
1069
double zero, /* I - FITS TZEROn or BZERO value */
1070
double *output, /* O - output array of converted values */
1071
int *status) /* IO - error status */
1073
Copy input to output prior to writing output to a FITS file.
1074
Do datatype conversion and scaling if required.
1079
if (scale == 1. && zero == 0.)
1081
for (ii = 0; ii < ntodo; ii++)
1082
output[ii] = (double) input[ii];
1086
for (ii = 0; ii < ntodo; ii++)
1087
output[ii] = (input[ii] - zero) / scale;
1091
/*--------------------------------------------------------------------------*/
1092
int ffr4fstr(float *input, /* I - array of values to be converted */
1093
long ntodo, /* I - number of elements in the array */
1094
double scale, /* I - FITS TSCALn or BSCALE value */
1095
double zero, /* I - FITS TZEROn or BZERO value */
1096
char *cform, /* I - format for output string values */
1097
long twidth, /* I - width of each field, in chars */
1098
char *output, /* O - output array of converted values */
1099
int *status) /* IO - error status */
1101
Copy input to output prior to writing output to a FITS file.
1102
Do scaling if required.
1108
if (scale == 1. && zero == 0.)
1110
for (ii = 0; ii < ntodo; ii++)
1112
sprintf(output, cform, (double) input[ii]);
1115
if (*output) /* if this char != \0, then overflow occurred */
1116
*status = OVERFLOW_ERR;
1121
for (ii = 0; ii < ntodo; ii++)
1123
dvalue = (input[ii] - zero) / scale;
1124
sprintf(output, cform, dvalue);
1127
if (*output) /* if this char != \0, then overflow occurred */
1128
*status = OVERFLOW_ERR;