-
Notifications
You must be signed in to change notification settings - Fork 1
/
putcol.c
2186 lines (1998 loc) · 72.7 KB
/
putcol.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This file, putcol.c, contains routines that write data elements to */
/* a FITS image or table. These are the generic routines. */
/* The FITSIO software was written by William Pence at the High Energy */
/* Astrophysic Science Archive Research Center (HEASARC) at the NASA */
/* Goddard Space Flight Center. */
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include "fitsio2.h"
/*--------------------------------------------------------------------------*/
int ffppx( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
long *firstpix, /* I - coord of first pixel to write(1 based) */
LONGLONG nelem, /* I - number of values to write */
void *array, /* I - array of values that are written */
int *status) /* IO - error status */
/*
Write an array of pixels to the primary array. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS array is not the same as the array being written).
This routine is simillar to ffppr, except it supports writing to
large images with more than 2**31 pixels.
*/
{
int naxis, ii;
long group = 1;
LONGLONG firstelem, dimsize = 1, naxes[9];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
/* get the size of the image */
ffgidm(fptr, &naxis, status);
ffgiszll(fptr, 9, naxes, status);
firstelem = 0;
for (ii=0; ii < naxis; ii++)
{
firstelem += ((firstpix[ii] - 1) * dimsize);
dimsize *= naxes[ii];
}
firstelem++;
if (datatype == TBYTE)
{
ffpprb(fptr, group, firstelem, nelem, (unsigned char *) array, status);
}
else if (datatype == TSBYTE)
{
ffpprsb(fptr, group, firstelem, nelem, (signed char *) array, status);
}
else if (datatype == TUSHORT)
{
ffpprui(fptr, group, firstelem, nelem, (unsigned short *) array,
status);
}
else if (datatype == TSHORT)
{
ffppri(fptr, group, firstelem, nelem, (short *) array, status);
}
else if (datatype == TUINT)
{
ffppruk(fptr, group, firstelem, nelem, (unsigned int *) array, status);
}
else if (datatype == TINT)
{
ffpprk(fptr, group, firstelem, nelem, (int *) array, status);
}
else if (datatype == TULONG)
{
ffppruj(fptr, group, firstelem, nelem, (unsigned long *) array, status);
}
else if (datatype == TLONG)
{
ffpprj(fptr, group, firstelem, nelem, (long *) array, status);
}
else if (datatype == TULONGLONG)
{
ffpprujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, status);
}
else if (datatype == TLONGLONG)
{
ffpprjj(fptr, group, firstelem, nelem, (LONGLONG *) array, status);
}
else if (datatype == TFLOAT)
{
ffppre(fptr, group, firstelem, nelem, (float *) array, status);
}
else if (datatype == TDOUBLE)
{
ffpprd(fptr, group, firstelem, nelem, (double *) array, status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffppxll( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
LONGLONG *firstpix, /* I - coord of first pixel to write(1 based) */
LONGLONG nelem, /* I - number of values to write */
void *array, /* I - array of values that are written */
int *status) /* IO - error status */
/*
Write an array of pixels to the primary array. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS array is not the same as the array being written).
This routine is simillar to ffppr, except it supports writing to
large images with more than 2**31 pixels.
*/
{
int naxis, ii;
long group = 1;
LONGLONG firstelem, dimsize = 1, naxes[9];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
/* get the size of the image */
ffgidm(fptr, &naxis, status);
ffgiszll(fptr, 9, naxes, status);
firstelem = 0;
for (ii=0; ii < naxis; ii++)
{
firstelem += ((firstpix[ii] - 1) * dimsize);
dimsize *= naxes[ii];
}
firstelem++;
if (datatype == TBYTE)
{
ffpprb(fptr, group, firstelem, nelem, (unsigned char *) array, status);
}
else if (datatype == TSBYTE)
{
ffpprsb(fptr, group, firstelem, nelem, (signed char *) array, status);
}
else if (datatype == TUSHORT)
{
ffpprui(fptr, group, firstelem, nelem, (unsigned short *) array,
status);
}
else if (datatype == TSHORT)
{
ffppri(fptr, group, firstelem, nelem, (short *) array, status);
}
else if (datatype == TUINT)
{
ffppruk(fptr, group, firstelem, nelem, (unsigned int *) array, status);
}
else if (datatype == TINT)
{
ffpprk(fptr, group, firstelem, nelem, (int *) array, status);
}
else if (datatype == TULONG)
{
ffppruj(fptr, group, firstelem, nelem, (unsigned long *) array, status);
}
else if (datatype == TLONG)
{
ffpprj(fptr, group, firstelem, nelem, (long *) array, status);
}
else if (datatype == TULONGLONG)
{
ffpprujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, status);
}
else if (datatype == TLONGLONG)
{
ffpprjj(fptr, group, firstelem, nelem, (LONGLONG *) array, status);
}
else if (datatype == TFLOAT)
{
ffppre(fptr, group, firstelem, nelem, (float *) array, status);
}
else if (datatype == TDOUBLE)
{
ffpprd(fptr, group, firstelem, nelem, (double *) array, status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffppxn( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
long *firstpix, /* I - first vector element to write(1 = 1st) */
LONGLONG nelem, /* I - number of values to write */
void *array, /* I - array of values that are written */
void *nulval, /* I - pointer to the null value */
int *status) /* IO - error status */
/*
Write an array of values to the primary array. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS array is not the same as the array being written).
This routine supports writing to large images with
more than 2**31 pixels.
*/
{
int naxis, ii;
long group = 1;
LONGLONG firstelem, dimsize = 1, naxes[9];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (nulval == NULL) /* null value not defined? */
{
ffppx(fptr, datatype, firstpix, nelem, array, status);
return(*status);
}
/* get the size of the image */
ffgidm(fptr, &naxis, status);
ffgiszll(fptr, 9, naxes, status);
firstelem = 0;
for (ii=0; ii < naxis; ii++)
{
firstelem += ((firstpix[ii] - 1) * dimsize);
dimsize *= naxes[ii];
}
firstelem++;
if (datatype == TBYTE)
{
ffppnb(fptr, group, firstelem, nelem, (unsigned char *) array,
*(unsigned char *) nulval, status);
}
else if (datatype == TSBYTE)
{
ffppnsb(fptr, group, firstelem, nelem, (signed char *) array,
*(signed char *) nulval, status);
}
else if (datatype == TUSHORT)
{
ffppnui(fptr, group, firstelem, nelem, (unsigned short *) array,
*(unsigned short *) nulval,status);
}
else if (datatype == TSHORT)
{
ffppni(fptr, group, firstelem, nelem, (short *) array,
*(short *) nulval, status);
}
else if (datatype == TUINT)
{
ffppnuk(fptr, group, firstelem, nelem, (unsigned int *) array,
*(unsigned int *) nulval, status);
}
else if (datatype == TINT)
{
ffppnk(fptr, group, firstelem, nelem, (int *) array,
*(int *) nulval, status);
}
else if (datatype == TULONG)
{
ffppnuj(fptr, group, firstelem, nelem, (unsigned long *) array,
*(unsigned long *) nulval,status);
}
else if (datatype == TLONG)
{
ffppnj(fptr, group, firstelem, nelem, (long *) array,
*(long *) nulval, status);
}
else if (datatype == TULONGLONG)
{
ffppnujj(fptr, group, firstelem, nelem, (ULONGLONG *) array,
*(ULONGLONG *) nulval, status);
}
else if (datatype == TLONGLONG)
{
ffppnjj(fptr, group, firstelem, nelem, (LONGLONG *) array,
*(LONGLONG *) nulval, status);
}
else if (datatype == TFLOAT)
{
ffppne(fptr, group, firstelem, nelem, (float *) array,
*(float *) nulval, status);
}
else if (datatype == TDOUBLE)
{
ffppnd(fptr, group, firstelem, nelem, (double *) array,
*(double *) nulval, status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffppxnll( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
LONGLONG *firstpix, /* I - first vector element to write(1 = 1st) */
LONGLONG nelem, /* I - number of values to write */
void *array, /* I - array of values that are written */
void *nulval, /* I - pointer to the null value */
int *status) /* IO - error status */
/*
Write an array of values to the primary array. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS array is not the same as the array being written).
This routine supports writing to large images with
more than 2**31 pixels.
*/
{
int naxis, ii;
long group = 1;
LONGLONG firstelem, dimsize = 1, naxes[9];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (nulval == NULL) /* null value not defined? */
{
ffppxll(fptr, datatype, firstpix, nelem, array, status);
return(*status);
}
/* get the size of the image */
ffgidm(fptr, &naxis, status);
ffgiszll(fptr, 9, naxes, status);
firstelem = 0;
for (ii=0; ii < naxis; ii++)
{
firstelem += ((firstpix[ii] - 1) * dimsize);
dimsize *= naxes[ii];
}
firstelem++;
if (datatype == TBYTE)
{
ffppnb(fptr, group, firstelem, nelem, (unsigned char *) array,
*(unsigned char *) nulval, status);
}
else if (datatype == TSBYTE)
{
ffppnsb(fptr, group, firstelem, nelem, (signed char *) array,
*(signed char *) nulval, status);
}
else if (datatype == TUSHORT)
{
ffppnui(fptr, group, firstelem, nelem, (unsigned short *) array,
*(unsigned short *) nulval,status);
}
else if (datatype == TSHORT)
{
ffppni(fptr, group, firstelem, nelem, (short *) array,
*(short *) nulval, status);
}
else if (datatype == TUINT)
{
ffppnuk(fptr, group, firstelem, nelem, (unsigned int *) array,
*(unsigned int *) nulval, status);
}
else if (datatype == TINT)
{
ffppnk(fptr, group, firstelem, nelem, (int *) array,
*(int *) nulval, status);
}
else if (datatype == TULONG)
{
ffppnuj(fptr, group, firstelem, nelem, (unsigned long *) array,
*(unsigned long *) nulval,status);
}
else if (datatype == TLONG)
{
ffppnj(fptr, group, firstelem, nelem, (long *) array,
*(long *) nulval, status);
}
else if (datatype == TULONGLONG)
{
ffppnujj(fptr, group, firstelem, nelem, (ULONGLONG *) array,
*(ULONGLONG *) nulval, status);
}
else if (datatype == TLONGLONG)
{
ffppnjj(fptr, group, firstelem, nelem, (LONGLONG *) array,
*(LONGLONG *) nulval, status);
}
else if (datatype == TFLOAT)
{
ffppne(fptr, group, firstelem, nelem, (float *) array,
*(float *) nulval, status);
}
else if (datatype == TDOUBLE)
{
ffppnd(fptr, group, firstelem, nelem, (double *) array,
*(double *) nulval, status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffppr( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
LONGLONG firstelem, /* I - first vector element to write(1 = 1st) */
LONGLONG nelem, /* I - number of values to write */
void *array, /* I - array of values that are written */
int *status) /* IO - error status */
/*
Write an array of values to the primary array. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS array is not the same as the array being written).
*/
{
long group = 1;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (datatype == TBYTE)
{
ffpprb(fptr, group, firstelem, nelem, (unsigned char *) array, status);
}
else if (datatype == TSBYTE)
{
ffpprsb(fptr, group, firstelem, nelem, (signed char *) array, status);
}
else if (datatype == TUSHORT)
{
ffpprui(fptr, group, firstelem, nelem, (unsigned short *) array,
status);
}
else if (datatype == TSHORT)
{
ffppri(fptr, group, firstelem, nelem, (short *) array, status);
}
else if (datatype == TUINT)
{
ffppruk(fptr, group, firstelem, nelem, (unsigned int *) array, status);
}
else if (datatype == TINT)
{
ffpprk(fptr, group, firstelem, nelem, (int *) array, status);
}
else if (datatype == TULONG)
{
ffppruj(fptr, group, firstelem, nelem, (unsigned long *) array, status);
}
else if (datatype == TLONG)
{
ffpprj(fptr, group, firstelem, nelem, (long *) array, status);
}
else if (datatype == TULONGLONG)
{
ffpprujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, status);
}
else if (datatype == TLONGLONG)
{
ffpprjj(fptr, group, firstelem, nelem, (LONGLONG *) array, status);
}
else if (datatype == TFLOAT)
{
ffppre(fptr, group, firstelem, nelem, (float *) array, status);
}
else if (datatype == TDOUBLE)
{
ffpprd(fptr, group, firstelem, nelem, (double *) array, status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffppn( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
LONGLONG firstelem, /* I - first vector element to write(1 = 1st) */
LONGLONG nelem, /* I - number of values to write */
void *array, /* I - array of values that are written */
void *nulval, /* I - pointer to the null value */
int *status) /* IO - error status */
/*
Write an array of values to the primary array. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS array is not the same as the array being written).
*/
{
long group = 1;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (nulval == NULL) /* null value not defined? */
{
ffppr(fptr, datatype, firstelem, nelem, array, status);
return(*status);
}
if (datatype == TBYTE)
{
ffppnb(fptr, group, firstelem, nelem, (unsigned char *) array,
*(unsigned char *) nulval, status);
}
else if (datatype == TSBYTE)
{
ffppnsb(fptr, group, firstelem, nelem, (signed char *) array,
*(signed char *) nulval, status);
}
else if (datatype == TUSHORT)
{
ffppnui(fptr, group, firstelem, nelem, (unsigned short *) array,
*(unsigned short *) nulval,status);
}
else if (datatype == TSHORT)
{
ffppni(fptr, group, firstelem, nelem, (short *) array,
*(short *) nulval, status);
}
else if (datatype == TUINT)
{
ffppnuk(fptr, group, firstelem, nelem, (unsigned int *) array,
*(unsigned int *) nulval, status);
}
else if (datatype == TINT)
{
ffppnk(fptr, group, firstelem, nelem, (int *) array,
*(int *) nulval, status);
}
else if (datatype == TULONG)
{
ffppnuj(fptr, group, firstelem, nelem, (unsigned long *) array,
*(unsigned long *) nulval,status);
}
else if (datatype == TLONG)
{
ffppnj(fptr, group, firstelem, nelem, (long *) array,
*(long *) nulval, status);
}
else if (datatype == TULONGLONG)
{
ffppnujj(fptr, group, firstelem, nelem, (ULONGLONG *) array,
*(ULONGLONG *) nulval, status);
}
else if (datatype == TLONGLONG)
{
ffppnjj(fptr, group, firstelem, nelem, (LONGLONG *) array,
*(LONGLONG *) nulval, status);
}
else if (datatype == TFLOAT)
{
ffppne(fptr, group, firstelem, nelem, (float *) array,
*(float *) nulval, status);
}
else if (datatype == TDOUBLE)
{
ffppnd(fptr, group, firstelem, nelem, (double *) array,
*(double *) nulval, status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpss( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
long *blc, /* I - 'bottom left corner' of the subsection */
long *trc , /* I - 'top right corner' of the subsection */
void *array, /* I - array of values that are written */
int *status) /* IO - error status */
/*
Write a section of values to the primary array. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS array is not the same as the array being written).
This routine supports writing to large images with
more than 2**31 pixels.
*/
{
int naxis;
long naxes[9];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
/* get the size of the image */
ffgidm(fptr, &naxis, status);
ffgisz(fptr, 9, naxes, status);
if (datatype == TBYTE)
{
ffpssb(fptr, 1, naxis, naxes, blc, trc,
(unsigned char *) array, status);
}
else if (datatype == TSBYTE)
{
ffpsssb(fptr, 1, naxis, naxes, blc, trc,
(signed char *) array, status);
}
else if (datatype == TUSHORT)
{
ffpssui(fptr, 1, naxis, naxes, blc, trc,
(unsigned short *) array, status);
}
else if (datatype == TSHORT)
{
ffpssi(fptr, 1, naxis, naxes, blc, trc,
(short *) array, status);
}
else if (datatype == TUINT)
{
ffpssuk(fptr, 1, naxis, naxes, blc, trc,
(unsigned int *) array, status);
}
else if (datatype == TINT)
{
ffpssk(fptr, 1, naxis, naxes, blc, trc,
(int *) array, status);
}
else if (datatype == TULONG)
{
ffpssuj(fptr, 1, naxis, naxes, blc, trc,
(unsigned long *) array, status);
}
else if (datatype == TLONG)
{
ffpssj(fptr, 1, naxis, naxes, blc, trc,
(long *) array, status);
}
else if (datatype == TULONGLONG)
{
ffpssujj(fptr, 1, naxis, naxes, blc, trc,
(ULONGLONG *) array, status);
}
else if (datatype == TLONGLONG)
{
ffpssjj(fptr, 1, naxis, naxes, blc, trc,
(LONGLONG *) array, status);
}
else if (datatype == TFLOAT)
{
ffpsse(fptr, 1, naxis, naxes, blc, trc,
(float *) array, status);
}
else if (datatype == TDOUBLE)
{
ffpssd(fptr, 1, naxis, naxes, blc, trc,
(double *) array, status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpcl( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
int colnum, /* I - number of column to write (1 = 1st col) */
LONGLONG firstrow, /* I - first row to write (1 = 1st row) */
LONGLONG firstelem, /* I - first vector element to write (1 = 1st) */
LONGLONG nelem, /* I - number of elements to write */
void *array, /* I - array of values that are written */
int *status) /* IO - error status */
/*
Write an array of values to a table column. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS column is not the same as the array being written).
*/
{
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (datatype == TBIT)
{
ffpclx(fptr, colnum, firstrow, (long) firstelem, (long) nelem, (char *) array,
status);
}
else if (datatype == TBYTE)
{
ffpclb(fptr, colnum, firstrow, firstelem, nelem, (unsigned char *) array,
status);
}
else if (datatype == TSBYTE)
{
ffpclsb(fptr, colnum, firstrow, firstelem, nelem, (signed char *) array,
status);
}
else if (datatype == TUSHORT)
{
ffpclui(fptr, colnum, firstrow, firstelem, nelem,
(unsigned short *) array, status);
}
else if (datatype == TSHORT)
{
ffpcli(fptr, colnum, firstrow, firstelem, nelem, (short *) array,
status);
}
else if (datatype == TUINT)
{
ffpcluk(fptr, colnum, firstrow, firstelem, nelem, (unsigned int *) array,
status);
}
else if (datatype == TINT)
{
ffpclk(fptr, colnum, firstrow, firstelem, nelem, (int *) array,
status);
}
else if (datatype == TULONG)
{
ffpcluj(fptr, colnum, firstrow, firstelem, nelem, (unsigned long *) array,
status);
}
else if (datatype == TLONG)
{
ffpclj(fptr, colnum, firstrow, firstelem, nelem, (long *) array,
status);
}
else if (datatype == TULONGLONG)
{
ffpclujj(fptr, colnum, firstrow, firstelem, nelem, (ULONGLONG *) array,
status);
}
else if (datatype == TLONGLONG)
{
ffpcljj(fptr, colnum, firstrow, firstelem, nelem, (LONGLONG *) array,
status);
}
else if (datatype == TFLOAT)
{
ffpcle(fptr, colnum, firstrow, firstelem, nelem, (float *) array,
status);
}
else if (datatype == TDOUBLE)
{
ffpcld(fptr, colnum, firstrow, firstelem, nelem, (double *) array,
status);
}
else if (datatype == TCOMPLEX)
{
ffpcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
(float *) array, status);
}
else if (datatype == TDBLCOMPLEX)
{
ffpcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
(double *) array, status);
}
else if (datatype == TLOGICAL)
{
ffpcll(fptr, colnum, firstrow, firstelem, nelem, (char *) array,
status);
}
else if (datatype == TSTRING)
{
ffpcls(fptr, colnum, firstrow, firstelem, nelem, (char **) array,
status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpcn( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
int colnum, /* I - number of column to write (1 = 1st col) */
LONGLONG firstrow, /* I - first row to write (1 = 1st row) */
LONGLONG firstelem, /* I - first vector element to write (1 = 1st) */
LONGLONG nelem, /* I - number of elements to write */
void *array, /* I - array of values that are written */
void *nulval, /* I - pointer to the null value */
int *status) /* IO - error status */
/*
Write an array of values to a table column. The datatype of the
input array is defined by the 2nd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS column is not the same as the array being written).
*/
{
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (nulval == NULL) /* null value not defined? */
{
ffpcl(fptr, datatype, colnum, firstrow, firstelem, nelem, array,
status);
return(*status);
}
if (datatype == TBYTE)
{
ffpcnb(fptr, colnum, firstrow, firstelem, nelem, (unsigned char *) array,
*(unsigned char *) nulval, status);
}
else if (datatype == TSBYTE)
{
ffpcnsb(fptr, colnum, firstrow, firstelem, nelem, (signed char *) array,
*(signed char *) nulval, status);
}
else if (datatype == TUSHORT)
{
ffpcnui(fptr, colnum, firstrow, firstelem, nelem, (unsigned short *) array,
*(unsigned short *) nulval, status);
}
else if (datatype == TSHORT)
{
ffpcni(fptr, colnum, firstrow, firstelem, nelem, (short *) array,
*(unsigned short *) nulval, status);
}
else if (datatype == TUINT)
{
ffpcnuk(fptr, colnum, firstrow, firstelem, nelem, (unsigned int *) array,
*(unsigned int *) nulval, status);
}
else if (datatype == TINT)
{
ffpcnk(fptr, colnum, firstrow, firstelem, nelem, (int *) array,
*(int *) nulval, status);
}
else if (datatype == TULONG)
{
ffpcnuj(fptr, colnum, firstrow, firstelem, nelem, (unsigned long *) array,
*(unsigned long *) nulval, status);
}
else if (datatype == TLONG)
{
ffpcnj(fptr, colnum, firstrow, firstelem, nelem, (long *) array,
*(long *) nulval, status);
}
else if (datatype == TULONGLONG)
{
ffpcnujj(fptr, colnum, firstrow, firstelem, nelem, (ULONGLONG *) array,
*(ULONGLONG *) nulval, status);
}
else if (datatype == TLONGLONG)
{
ffpcnjj(fptr, colnum, firstrow, firstelem, nelem, (LONGLONG *) array,
*(LONGLONG *) nulval, status);
}
else if (datatype == TFLOAT)
{
ffpcne(fptr, colnum, firstrow, firstelem, nelem, (float *) array,
*(float *) nulval, status);
}
else if (datatype == TDOUBLE)
{
ffpcnd(fptr, colnum, firstrow, firstelem, nelem, (double *) array,
*(double *) nulval, status);
}
else if (datatype == TCOMPLEX)
{
ffpcne(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
(float *) array, *(float *) nulval, status);
}
else if (datatype == TDBLCOMPLEX)
{
ffpcnd(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
(double *) array, *(double *) nulval, status);
}
else if (datatype == TLOGICAL)
{
ffpcnl(fptr, colnum, firstrow, firstelem, nelem, (char *) array,
*(char *) nulval, status);
}
else if (datatype == TSTRING)
{
ffpcns(fptr, colnum, firstrow, firstelem, nelem, (char **) array,
(char *) nulval, status);
}
else
*status = BAD_DATATYPE;
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpcln( fitsfile *fptr, /* I - FITS file pointer */
int ncols, /* I - number of columns to write */
int *datatype, /* I - datatypes of the values */
int *colnum, /* I - columns numbers to write (1 = 1st col) */
LONGLONG firstrow, /* I - first row to write (1 = 1st row) */
LONGLONG nrows, /* I - number of rows to write */
void **array, /* I - array of pointers to values to write */
void **nulval, /* I - array of pointers to values for undefined pixels */
int *status) /* IO - error status */
/*
Write arrays of values to NCOLS table columns. This is an optimization
to write all columns in one pass through the table. The datatypes of the
input arrays are defined by the 3rd argument. Data conversion
and scaling will be performed if necessary (e.g, if the datatype of
the FITS array is not the same as the array being written).
Undefined elements for column i that are equal to *(nulval[i]) are set to
the defined null value, unless nulval[i]=0,
in which case no checking for undefined values will be performed.
*/
{
LONGLONG ntotrows, ndone, nwrite, currow;
long nrowbuf;
LONGLONG *repeats = 0;
size_t sizes[255] = {0};
int icol;
sizes[TBYTE] = sizes[TSBYTE] = sizes[TLOGICAL] = sizeof(char);
sizes[TUSHORT] = sizes[TSHORT] = sizeof(short int);
sizes[TINT] = sizes[TUINT] = sizeof(int);
sizes[TLONG] = sizes[TULONG] = sizeof(long int);
sizes[TLONGLONG] = sizes[TULONGLONG] = sizeof(LONGLONG);
sizes[TFLOAT] = sizeof(float);
sizes[TDOUBLE] = sizeof(double);
sizes[TDBLCOMPLEX] = 2*sizeof(double);
if (*status > 0)
return(*status);
if (ncols <= 0) return (*status=0);
repeats = malloc(sizeof(LONGLONG)*ncols);
if (repeats == 0) return (*status=MEMORY_ALLOCATION);
fits_get_num_rowsll(fptr, &ntotrows, status);
fits_get_rowsize(fptr, &nrowbuf, status);
/* Retrieve column repeats */
for (icol = 0; (icol < ncols) && (icol < 1000); icol++) {
int typecode;
LONGLONG repeat, width;
fits_get_coltypell(fptr, colnum[icol], &typecode,
&repeat, &width, status);
repeats[icol] = repeat;
if (datatype[icol] == TBIT || datatype[icol] == TSTRING ||
sizes[datatype[icol]] == 0) {
ffpmsg("Cannot write to TBIT or TSTRING datatypes (ffpcln)");
*status = BAD_DATATYPE;
}
if (typecode < 0) {
ffpmsg("Cannot write to variable-length data (ffpcln)");
*status = BAD_DIMEN;
}
if (*status) break;
}
if (*status) {
free(repeats);
return *status;
}
/* Optimize for 1 column */
if (ncols == 1) {
fits_write_colnull(fptr, datatype[0], colnum[0], firstrow, 1,
nrows*repeats[0],
array[0], nulval[0], status);
free(repeats);
return *status;
}
/* Scan through file, in chunks of nrowbuf */
currow = firstrow;
ndone = 0;
while (ndone < nrows) {
int icol;
nwrite = (nrows-ndone);
if (nwrite > nrowbuf) nwrite = nrowbuf;
for (icol=0; icol<ncols; icol++) {
LONGLONG nelem1 = (nwrite*repeats[icol]);
char *array1 = (char *) array[icol] + repeats[icol]*ndone*sizes[datatype[icol]];
fits_write_colnull(fptr, datatype[icol], colnum[icol], ndone+1, 1,
nelem1, array1, nulval[icol], status);
if (*status) {
char errmsg[100];
sprintf(errmsg,
"Failed to write column %d data rows %lld-%lld (ffpcln)",
colnum[icol], currow, currow+nwrite-1);
ffpmsg(errmsg);
break;
}
}
if (*status) break;
currow += nwrite;
ndone += nwrite;
}