16 #include "ColumnData.h"
17 #include "ColumnVectorData.h"
22 #include "NewKeyword.h"
44 read(vals,first,last,
static_cast<S*
>(0));
49 void Column::read(std::vector<S>& vals,
long first,
long last, S* nullValue)
54 long nelements = numberOfElements(first,last);
56 if (ColumnData<S>* col =
dynamic_cast<ColumnData<S>*
>(
this))
61 if (!
isRead()) col->readColumnData(first,nelements,nullValue);
63 FITSUtil::fill(vals,col->data(),first,last);
68 if ( outputType() ==
type() )
84 if (
type() == Tdouble )
86 ColumnData<double>& col
87 =
dynamic_cast<ColumnData<double>&
>(*this);
88 if (!
isRead()) col.readColumnData(first,nelements);
89 FITSUtil::fill(vals,col.data(),first,last);
92 else if (
type() == Tfloat)
94 ColumnData<float>& col
95 =
dynamic_cast<ColumnData<float>&
>(*this);
96 if (!
isRead()) col.readColumnData(first,nelements);
97 FITSUtil::fill(vals,col.data(),first,last);
99 else if (
type() == Tint)
102 if (nullValue) nullVal =
static_cast<int>(*nullValue);
104 =
dynamic_cast<ColumnData<int>&
>(*this);
105 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
106 FITSUtil::fill(vals,col.data(),first,last);
108 else if (
type() == Tshort)
111 if (nullValue) nullVal =
static_cast<short>(*nullValue);
112 ColumnData<short>& col
113 =
dynamic_cast<ColumnData<short>&
>(*this);
114 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
115 FITSUtil::fill(vals,col.data(),first,last);
117 else if (
type() == Tlong)
120 if (nullValue) nullVal =
static_cast<long>(*nullValue);
121 ColumnData<long>& col
122 =
dynamic_cast<ColumnData<long>&
>(*this);
123 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
124 FITSUtil::fill(vals,col.data(),first,last);
126 else if (
type() == Tlonglong)
129 if (nullValue) nullVal =
static_cast<LONGLONG
>(*nullValue);
130 ColumnData<LONGLONG>& col
131 =
dynamic_cast<ColumnData<LONGLONG>&
>(*this);
132 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
133 FITSUtil::fill(vals,col.data(),first,last);
135 else if (
type() == Tlogical)
138 if (nullValue) nullVal =
static_cast<bool>(*nullValue);
139 ColumnData<bool>& col
140 =
dynamic_cast<ColumnData<bool>&
>(*this);
141 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
142 FITSUtil::fill(vals,col.data(),first,last);
144 else if (
type() == Tbit ||
type() == Tbyte)
146 unsigned char nullVal(0);
147 if (nullValue) nullVal =
static_cast<unsigned char>(*nullValue);
148 ColumnData<unsigned char>& col
149 =
dynamic_cast<ColumnData<unsigned char>&
>(*this);
150 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
151 FITSUtil::fill(vals,col.data(),first,last);
153 else if (
type() == Tushort)
155 unsigned short nullVal(0);
156 if (nullValue) nullVal=
static_cast<unsigned short>(*nullValue);
157 ColumnData<unsigned short>& col
158 =
dynamic_cast<ColumnData<unsigned short>&
>(*this);
159 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
160 FITSUtil::fill(vals,col.data(),first,last);
162 else if (
type() == Tuint)
164 unsigned int nullVal(0);
165 if (nullValue) nullVal =
static_cast<unsigned int>(*nullValue);
166 ColumnData<unsigned int>& col
167 =
dynamic_cast<ColumnData<unsigned int>&
>(*this);
168 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
169 FITSUtil::fill(vals,col.data(),first,last);
171 else if (
type() == Tulong)
173 unsigned long nullVal(0);
174 if (nullValue) nullVal =
static_cast<unsigned long>(*nullValue);
175 ColumnData<unsigned long>& col
176 =
dynamic_cast<ColumnData<unsigned long>&
>(*this);
177 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
178 FITSUtil::fill(vals,col.data(),first,last);
187 catch (std::bad_cast&)
195 template <
typename S>
198 read(vals,first,last,
static_cast<S*
>(0));
202 template <
typename S>
203 void Column::read(std::valarray<S>& vals,
long first,
long last, S* nullValue)
208 long nelements = numberOfElements(first,last);
210 if ( ColumnData<S>* col =
dynamic_cast<ColumnData<S>*
>(
this))
215 if (!
isRead()) col->readColumnData(first,nelements,nullValue);
216 FITSUtil::fill(vals,col->data(),first,last);
222 if ( outputType() ==
type() )
238 if (
type() == Tdouble )
240 ColumnData<double>& col
241 =
dynamic_cast<ColumnData<double>&
>(*this);
242 if (!
isRead()) col.readColumnData(first,nelements);
243 FITSUtil::fill(vals,col.data(),first,last);
245 else if (
type() == Tfloat)
247 ColumnData<float>& col
248 =
dynamic_cast<ColumnData<float>&
>(*this);
249 if (!
isRead()) col.readColumnData(first,nelements);
250 FITSUtil::fill(vals,col.data(),first,last);
252 else if (
type() == Tint)
255 if (nullValue) nullVal =
static_cast<int>(*nullValue);
257 =
dynamic_cast<ColumnData<int>&
>(*this);
258 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
259 FITSUtil::fill(vals,col.data(),first,last);
261 else if (
type() == Tshort)
264 if (nullValue) nullVal =
static_cast<short>(*nullValue);
265 ColumnData<short>& col
266 =
dynamic_cast<ColumnData<short>&
>(*this);
267 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
268 FITSUtil::fill(vals,col.data(),first,last);
270 else if (
type() == Tlong)
273 if (nullValue) nullVal =
static_cast<long>(*nullValue);
274 ColumnData<long>& col
275 =
dynamic_cast<ColumnData<long>&
>(*this);
276 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
277 FITSUtil::fill(vals,col.data(),first,last);
279 else if (
type() == Tlonglong)
282 if (nullValue) nullVal =
static_cast<LONGLONG
>(*nullValue);
283 ColumnData<LONGLONG>& col
284 =
dynamic_cast<ColumnData<LONGLONG>&
>(*this);
285 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
286 FITSUtil::fill(vals,col.data(),first,last);
288 else if (
type() == Tlogical)
291 if (nullValue) nullVal =
static_cast<bool>(*nullValue);
292 ColumnData<bool>& col
293 =
dynamic_cast<ColumnData<bool>&
>(*this);
294 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
295 FITSUtil::fill(vals,col.data(),first,last);
297 else if (
type() == Tbit ||
type() == Tbyte)
299 unsigned char nullVal(0);
300 if (nullValue) nullVal =
static_cast<unsigned char>(*nullValue);
301 ColumnData<unsigned char>& col
302 =
dynamic_cast<ColumnData<unsigned char>&
>(*this);
303 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
304 FITSUtil::fill(vals,col.data(),first,last);
306 else if (
type() == Tushort)
308 unsigned short nullVal(0);
309 if (nullValue) nullVal
310 =
static_cast<unsigned short>(*nullValue);
311 ColumnData<unsigned short>& col
312 =
dynamic_cast<ColumnData<unsigned short>&
>(*this);
313 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
314 FITSUtil::fill(vals,col.data(),first,last);
316 else if (
type() == Tuint)
318 unsigned int nullVal(0);
319 if (nullValue) nullVal
320 =
static_cast<unsigned int>(*nullValue);
321 ColumnData<unsigned int>& col
322 =
dynamic_cast<ColumnData<unsigned int>&
>(*this);
323 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
324 FITSUtil::fill(vals,col.data(),first,last);
326 else if (
type() == Tulong)
328 unsigned long nullVal(0);
329 if (nullValue) nullVal
330 =
static_cast<unsigned long>(*nullValue);
331 ColumnData<unsigned long>& col
332 =
dynamic_cast<ColumnData<unsigned long>&
>(*this);
333 if (!
isRead()) col.readColumnData(first,nelements,&nullVal);
334 FITSUtil::fill(vals,col.data(),first,last);
343 catch (std::bad_cast&)
353 template <
typename S>
356 read(vals,row,
static_cast<S*
>(0));
358 template <
typename S>
361 read(vals,row,
static_cast<S*
>(0));
364 template <
typename S>
365 void Column::read(std::vector<S>& vals,
long row, S* nullValue)
373 if ( ColumnVectorData<S>* col =
dynamic_cast<ColumnVectorData<S>*
>(
this))
378 if (!
isRead()) col->readRow(row,nullValue);
379 FITSUtil::fill(vals,col->data(row));
383 FITSUtil::MatchType<S> outputType;
384 if ( outputType() ==
type() )
391 throw Column::WrongColumnType(
name());
403 if (
type() == Tdouble ||
type() == VTdouble )
405 ColumnVectorData<double>& col
406 =
dynamic_cast<ColumnVectorData<double>&
>(*this);
407 if (!
isRead()) col.readRow(row);
408 FITSUtil::fill(vals,col.data(row));
411 else if (
type() == Tfloat ||
type() == VTfloat )
413 ColumnVectorData<float>& col
414 =
dynamic_cast<ColumnVectorData<float>&
>(*this);
415 if (!
isRead()) col.readRow(row);
416 FITSUtil::fill(vals,col.data(row));
418 else if (
type() == Tint ||
type() == VTint )
421 if (nullValue) nullVal =
static_cast<int>(*nullValue);
422 ColumnVectorData<int>& col
423 =
dynamic_cast<ColumnVectorData<int>&
>(*this);
424 if (!
isRead()) col.readRow(row,&nullVal);
425 FITSUtil::fill(vals,col.data(row));
427 else if (
type() == Tshort ||
type() == VTshort )
430 if (nullValue) nullVal =
static_cast<short>(*nullValue);
431 ColumnVectorData<short>& col
432 =
dynamic_cast<ColumnVectorData<short>&
>(*this);
433 if (!
isRead()) col.readRow(row,&nullVal);
434 FITSUtil::fill(vals,col.data(row));
436 else if (
type() == Tlong ||
type() == VTlong )
439 if (nullValue) nullVal =
static_cast<long>(*nullValue);
440 ColumnVectorData<long>& col
441 =
dynamic_cast<ColumnVectorData<long>&
>(*this);
442 if (!
isRead()) col.readRow(row,&nullVal);
443 FITSUtil::fill(vals,col.data(row));
445 else if (
type() == Tlonglong ||
type() == VTlonglong )
448 if (nullValue) nullVal =
static_cast<LONGLONG
>(*nullValue);
449 ColumnVectorData<LONGLONG>& col
450 =
dynamic_cast<ColumnVectorData<LONGLONG>&
>(*this);
451 if (!
isRead()) col.readRow(row,&nullVal);
452 FITSUtil::fill(vals,col.data(row));
454 else if (
type() == Tlogical ||
type() == VTlogical )
457 if (nullValue) nullVal =
static_cast<bool>(*nullValue);
458 ColumnVectorData<bool>& col
459 =
dynamic_cast<ColumnVectorData<bool>&
>(*this);
460 if (!
isRead()) col.readRow(row,&nullVal);
461 FITSUtil::fill(vals,col.data(row));
463 else if (
type() == Tbit ||
type() == Tbyte ||
464 type() == VTbit ||
type() == VTbyte )
466 unsigned char nullVal(0);
467 if (nullValue) nullVal
468 =
static_cast<unsigned char>(*nullValue);
469 ColumnVectorData<unsigned char>& col
470 =
dynamic_cast<ColumnVectorData<unsigned char>&
>(*this);
471 if (!
isRead()) col.readRow(row,&nullVal);
472 FITSUtil::fill(vals,col.data(row));
474 else if (
type() == Tushort ||
type() == VTushort)
476 unsigned short nullVal(0);
477 if (nullValue) nullVal
478 =
static_cast<unsigned short>(*nullValue);
479 ColumnVectorData<unsigned short>& col
480 =
dynamic_cast<ColumnVectorData<unsigned short>&
>(*this);
481 if (!
isRead()) col.readRow(row,&nullVal);
482 FITSUtil::fill(vals,col.data(row));
484 else if (
type() == Tuint ||
type() == VTuint)
486 unsigned int nullVal(0);
487 if (nullValue) nullVal
488 =
static_cast<unsigned int>(*nullValue);
489 ColumnVectorData<unsigned int>& col
490 =
dynamic_cast<ColumnVectorData<unsigned int>&
>(*this);
491 if (!
isRead()) col.readRow(row,&nullVal);
492 FITSUtil::fill(vals,col.data(row));
494 else if (
type() == Tulong ||
type() == VTulong)
496 unsigned long nullVal(0);
497 if (nullValue) nullVal
498 =
static_cast<unsigned long>(*nullValue);
499 ColumnVectorData<unsigned long>& col
500 =
dynamic_cast<ColumnVectorData<unsigned long>&
>(*this);
501 if (!
isRead()) col.readRow(row,&nullVal);
502 FITSUtil::fill(vals,col.data(row));
506 throw InvalidDataType(
name());
511 catch (std::bad_cast&)
513 throw WrongColumnType(
name());
518 template <
typename S>
527 if ( ColumnVectorData<S>* col =
dynamic_cast<ColumnVectorData<S>*
>(
this))
539 if (!
isRead()) col->readRow(row,nullValue);
540 FITSUtil::fill(vals,col->data(row));
545 if ( outputType() ==
type() )
564 if (
type() == Tdouble ||
type() == VTdouble )
566 ColumnVectorData<double>& col
567 =
dynamic_cast<ColumnVectorData<double>&
>(*this);
568 if (!
isRead()) col.readRow(row);
569 FITSUtil::fill(vals,col.data(row));
572 else if (
type() == Tfloat ||
type() == VTfloat )
574 ColumnVectorData<float>& col
575 =
dynamic_cast<ColumnVectorData<float>&
>(*this);
576 if (!
isRead()) col.readRow(row);
577 FITSUtil::fill(vals,col.data(row));
579 else if (
type() == Tint ||
type() == VTint )
582 if (nullValue) nullVal =
static_cast<int>(*nullValue);
583 ColumnVectorData<int>& col
584 =
dynamic_cast<ColumnVectorData<int>&
>(*this);
585 if (!
isRead()) col.readRow(row,&nullVal);
586 FITSUtil::fill(vals,col.data(row));
588 else if (
type() == Tshort ||
type() == VTshort )
591 if (nullValue) nullVal =
static_cast<short>(*nullValue);
592 ColumnVectorData<short>& col
593 =
dynamic_cast<ColumnVectorData<short>&
>(*this);
594 if (!
isRead()) col.readRow(row,&nullVal);
595 FITSUtil::fill(vals,col.data(row));
597 else if (
type() == Tlong ||
type() == VTlong )
600 if (nullValue) nullVal =
static_cast<long>(*nullValue);
601 ColumnVectorData<long>& col
602 =
dynamic_cast<ColumnVectorData<long>&
>(*this);
603 if (!
isRead()) col.readRow(row,&nullVal);
604 FITSUtil::fill(vals,col.data(row));
606 else if (
type() == Tlonglong ||
type() == VTlonglong )
609 if (nullValue) nullVal =
static_cast<LONGLONG
>(*nullValue);
610 ColumnVectorData<LONGLONG>& col
611 =
dynamic_cast<ColumnVectorData<LONGLONG>&
>(*this);
612 if (!
isRead()) col.readRow(row,&nullVal);
613 FITSUtil::fill(vals,col.data(row));
615 else if (
type() == Tlogical ||
type() == VTlogical )
618 if (nullValue) nullVal =
static_cast<bool>(*nullValue);
619 ColumnVectorData<bool>& col
620 =
dynamic_cast<ColumnVectorData<bool>&
>(*this);
621 if (!
isRead()) col.readRow(row,&nullVal);
622 FITSUtil::fill(vals,col.data(row));
624 else if (
type() == Tbit ||
type() == Tbyte ||
625 type() == VTbit ||
type() == VTbyte )
627 unsigned char nullVal(0);
628 if (nullValue) nullVal
629 =
static_cast<unsigned char>(*nullValue);
630 ColumnVectorData<unsigned char>& col
631 =
dynamic_cast<ColumnVectorData<unsigned char>&
>(*this);
632 if (!
isRead()) col.readRow(row,&nullVal);
633 FITSUtil::fill(vals,col.data(row));
635 else if (
type() == Tushort ||
type() == VTushort)
637 unsigned short nullVal(0);
638 if (nullValue) nullVal
639 =
static_cast<unsigned short>(*nullValue);
640 ColumnVectorData<unsigned short>& col
641 =
dynamic_cast<ColumnVectorData<unsigned short>&
>(*this);
642 if (!
isRead()) col.readRow(row,&nullVal);
643 FITSUtil::fill(vals,col.data(row));
645 else if (
type() == Tuint ||
type() == VTuint)
647 unsigned int nullVal(0);
648 if (nullValue) nullVal
649 =
static_cast<unsigned int>(*nullValue);
650 ColumnVectorData<unsigned int>& col
651 =
dynamic_cast<ColumnVectorData<unsigned int>&
>(*this);
652 if (!
isRead()) col.readRow(row,&nullVal);
653 FITSUtil::fill(vals,col.data(row));
655 else if (
type() == Tulong ||
type() == VTulong)
657 unsigned long nullVal(0);
658 if (nullValue) nullVal
659 =
static_cast<unsigned long>(*nullValue);
660 ColumnVectorData<unsigned long>& col
661 =
dynamic_cast<ColumnVectorData<unsigned long>&
>(*this);
662 if (!
isRead()) col.readRow(row,&nullVal);
663 FITSUtil::fill(vals,col.data(row));
672 catch (std::bad_cast&)
679 template <
typename S>
682 readArrays(vals,first,last,
static_cast<S*
>(0));
685 template <
typename S>
687 long first,
long last, S* nullValue)
694 long range = numberOfElements(first,last);
699 if ( ColumnVectorData<S>* col =
dynamic_cast<ColumnVectorData<S>*
>(
this))
701 for (
int j = 0; j < range; ++j)
703 if (!
isRead()) col->readRow(j + first,nullValue);
704 FITSUtil::fill(vals[j],col->data(j+first));
710 if ( outputType() ==
type() )
720 if (
type() == Tdouble ||
type() == VTdouble )
722 ColumnVectorData<double>& col
723 =
dynamic_cast<ColumnVectorData<double>&
>(*this);
724 for (
int j = 0; j < range; ++j)
726 if (!
isRead()) col.readRow(j + first);
727 FITSUtil::fill(vals[j],col.data(j+first));
730 else if (
type() == Tfloat ||
type() == VTfloat )
732 ColumnVectorData<float>& col
733 =
dynamic_cast<ColumnVectorData<float>&
>(*this);
734 for (
int j = 0; j < range; ++j)
736 if (!
isRead()) col.readRow(j + first);
737 FITSUtil::fill(vals[j],col.data(j+first));
740 else if (
type() == Tint ||
type() == VTint )
743 if (nullValue) nullVal =
static_cast<int>(*nullValue);
744 ColumnVectorData<int>& col
745 =
dynamic_cast<ColumnVectorData<int>&
>(*this);
746 for (
int j = 0; j < range; ++j)
748 if (!
isRead()) col.readRow(j + first,&nullVal);
749 FITSUtil::fill(vals[j],col.data(j+first));
752 else if (
type() == Tshort ||
type() == VTshort )
755 if (nullValue) nullVal =
static_cast<short>(*nullValue);
756 ColumnVectorData<short>& col
757 =
dynamic_cast<ColumnVectorData<short>&
>(*this);
758 for (
int j = 0; j < range; ++j)
760 if (!
isRead()) col.readRow(j + first,&nullVal);
761 FITSUtil::fill(vals[j],col.data(j+first));
764 else if (
type() == Tlong ||
type() == VTlong )
767 if (nullValue) nullVal =
static_cast<long>(*nullValue);
768 ColumnVectorData<long>& col
769 =
dynamic_cast<ColumnVectorData<long>&
>(*this);
770 for (
int j = 0; j < range; ++j)
772 if (!
isRead()) col.readRow(j + first,&nullVal);
773 FITSUtil::fill(vals[j],col.data(j+first));
776 else if (
type() == Tlonglong ||
type() == VTlonglong )
779 if (nullValue) nullVal =
static_cast<LONGLONG
>(*nullValue);
780 ColumnVectorData<LONGLONG>& col
781 =
dynamic_cast<ColumnVectorData<LONGLONG>&
>(*this);
782 for (
int j = 0; j < range; ++j)
784 if (!
isRead()) col.readRow(j + first,&nullVal);
785 FITSUtil::fill(vals[j],col.data(j+first));
788 else if (
type() == Tlogical ||
type() == VTlogical )
791 if (nullValue) nullVal =
static_cast<bool>(*nullValue);
792 ColumnVectorData<bool>& col
793 =
dynamic_cast<ColumnVectorData<bool>&
>(*this);
794 for (
int j = 0; j < range; ++j)
796 if (!
isRead()) col.readRow(j + first,&nullVal);
797 FITSUtil::fill(vals[j],col.data(j+first));
800 else if (
type() == Tbit ||
type() == Tbyte ||
801 type() == VTbit ||
type() == VTbyte )
803 unsigned char nullVal(0);
804 if (nullValue) nullVal
805 =
static_cast<unsigned char>(*nullValue);
806 ColumnVectorData<unsigned char>& col
807 =
dynamic_cast<ColumnVectorData<unsigned char>&
>(*this);
808 for (
int j = 0; j < range; ++j)
810 if (!
isRead()) col.readRow(j + first,&nullVal);
811 FITSUtil::fill(vals[j],col.data(j+first));
814 else if (
type() == Tushort ||
type() == VTushort )
816 unsigned short nullVal(0);
817 if (nullValue) nullVal
818 =
static_cast<unsigned short>(*nullValue);
819 ColumnVectorData<unsigned short>& col
820 =
dynamic_cast<ColumnVectorData<unsigned short>&
>(*this);
821 for (
int j = 0; j < range; ++j)
823 if (!
isRead()) col.readRow(j + first,&nullVal);
824 FITSUtil::fill(vals[j],col.data(j+first));
827 else if (
type() == Tuint ||
type() == VTuint )
829 unsigned int nullVal(0);
830 if (nullValue) nullVal
831 =
static_cast<unsigned int>(*nullValue);
832 ColumnVectorData<unsigned int>& col
833 =
dynamic_cast<ColumnVectorData<unsigned int>&
>(*this);
834 for (
int j = 0; j < range; ++j)
836 if (!
isRead()) col.readRow(j + first,&nullVal);
837 FITSUtil::fill(vals[j],col.data(j+first));
840 else if (
type() == Tulong ||
type() == VTulong )
842 unsigned long nullVal(0);
843 if (nullValue) nullVal
844 =
static_cast<unsigned long>(*nullValue);
845 ColumnVectorData<unsigned long>& col
846 =
dynamic_cast<ColumnVectorData<unsigned long>&
>(*this);
847 for (
int j = 0; j < range; ++j)
849 if (!
isRead()) col.readRow(j + first,&nullVal);
850 FITSUtil::fill(vals[j],col.data(j+first));
859 catch (std::bad_cast&)
868 template <
typename S>
874 write(indata,firstRow,
static_cast<S*
>(0));
877 template <
typename S>
880 size_t n(indata.size());
881 std::vector<S> __tmp(n);
882 for (
size_t j = 0; j < n; ++j) __tmp[j] = indata[j];
883 write(__tmp,firstRow,
static_cast<S*
>(0));
886 template <
typename S>
889 write(indata,nRows,firstRow,
static_cast<S*
>(0));
893 template <
typename S>
894 void Column::write (
const std::vector<S>& indata,
long firstRow, S* nullValue)
904 firstRow = std::max(firstRow,
static_cast<long>(1));
905 if (ColumnData<S>* col =
dynamic_cast<ColumnData<S>*
>(
this))
907 col->writeData(indata,firstRow,nullValue);
914 if ( inType() ==
type())
916 String msg(
"Incorrect call: writing to vector column ");
918 msg +=
" requires specification of # rows or vector lengths";
923 if (
type() == Tdouble )
925 ColumnData<double>& col
926 =
dynamic_cast<ColumnData<double>&
>(*this);
927 std::vector<double> __tmp;
928 FITSUtil::fill(__tmp,indata,1,indata.size());
929 col.writeData(__tmp,firstRow);
931 else if (
type() == Tfloat )
933 ColumnData<float>& col
934 =
dynamic_cast<ColumnData<float>&
>(*this);
935 std::vector<float> __tmp;
936 FITSUtil::fill(__tmp,indata,1,indata.size());
937 col.writeData(__tmp,firstRow);
939 else if (
type() == Tint )
945 nullVal =
static_cast<int>(*nullValue);
948 if (nullValue) nullVal =
static_cast<int>(*nullValue);
950 =
dynamic_cast<ColumnData<int>&
>(*this);
951 std::vector<int> __tmp;
952 FITSUtil::fill(__tmp,indata,1,indata.size());
953 col.writeData(__tmp,firstRow,pNullVal);
955 else if (
type() == Tshort )
961 nullVal =
static_cast<short>(*nullValue);
964 ColumnData<short>& col
965 =
dynamic_cast<ColumnData<short>&
>(*this);
966 std::vector<short> __tmp;
967 FITSUtil::fill(__tmp,indata,1,indata.size());
968 col.writeData(__tmp,firstRow,pNullVal);
970 else if (
type() == Tlong )
976 nullVal =
static_cast<long>(*nullValue);
979 ColumnData<long>& col
980 =
dynamic_cast<ColumnData<long>&
>(*this);
981 std::vector<long> __tmp;
982 FITSUtil::fill(__tmp,indata,1,indata.size());
983 col.writeData(__tmp,firstRow,pNullVal);
985 else if (
type() == Tlonglong )
988 LONGLONG* pNullVal = 0;
991 nullVal =
static_cast<LONGLONG
>(*nullValue);
994 ColumnData<LONGLONG>& col
995 =
dynamic_cast<ColumnData<LONGLONG>&
>(*this);
996 std::vector<LONGLONG> __tmp;
997 FITSUtil::fill(__tmp,indata,1,indata.size());
998 col.writeData(__tmp,firstRow,pNullVal);
1000 else if (
type() == Tlogical )
1006 nullVal =
static_cast<bool>(*nullValue);
1007 pNullVal = &nullVal;
1009 ColumnData<bool>& col
1010 =
dynamic_cast<ColumnData<bool>&
>(*this);
1011 std::vector<bool> __tmp;
1012 FITSUtil::fill(__tmp,indata,1,indata.size());
1013 col.writeData(__tmp,firstRow,pNullVal);
1015 else if (
type() == Tbyte )
1017 unsigned char nullVal(0);
1018 unsigned char* pNullVal = 0;
1021 nullVal =
static_cast<unsigned char>(*nullValue);
1022 pNullVal = &nullVal;
1024 ColumnData<unsigned char>& col
1025 =
dynamic_cast<ColumnData<unsigned char>&
>(*this);
1026 std::vector<unsigned char> __tmp;
1027 FITSUtil::fill(__tmp,indata,1,indata.size());
1028 col.writeData(__tmp,firstRow,pNullVal);
1030 else if (
type() == Tushort )
1032 unsigned short nullVal(0);
1033 unsigned short* pNullVal = 0;
1036 nullVal =
static_cast<unsigned short>(*nullValue);
1037 pNullVal = &nullVal;
1039 ColumnData<unsigned short>& col
1040 =
dynamic_cast<ColumnData<unsigned short>&
>(*this);
1041 std::vector<unsigned short> __tmp;
1042 FITSUtil::fill(__tmp,indata,1,indata.size());
1043 col.writeData(__tmp,firstRow,pNullVal);
1045 else if (
type() == Tuint )
1047 unsigned int nullVal(0);
1048 unsigned int* pNullVal = 0;
1051 nullVal =
static_cast<unsigned int>(*nullValue);
1052 pNullVal = &nullVal;
1054 ColumnData<unsigned int>& col
1055 =
dynamic_cast<ColumnData<unsigned int>&
>(*this);
1056 std::vector<unsigned int> __tmp;
1057 FITSUtil::fill(__tmp,indata,1,indata.size());
1058 col.writeData(__tmp,firstRow,pNullVal);
1060 else if (
type() == Tulong )
1062 unsigned long nullVal(0);
1063 unsigned long* pNullVal = 0;
1066 nullVal =
static_cast<unsigned long>(*nullValue);
1067 pNullVal = &nullVal;
1069 ColumnData<unsigned long>& col
1070 =
dynamic_cast<ColumnData<unsigned long>&
>(*this);
1071 std::vector<unsigned long> __tmp;
1072 FITSUtil::fill(__tmp,indata,1,indata.size());
1073 col.writeData(__tmp,firstRow,pNullVal);
1084 template <
typename S>
1085 void Column::write (
const std::valarray<S>& indata,
long firstRow, S* nullValue)
1088 std::vector<S> __tmp;
1089 FITSUtil::fill(__tmp,indata);
1090 write(__tmp,firstRow,nullValue);
1093 template <
typename S>
1098 std::vector<S> __tmp(nRows);
1099 std::copy(&indata[0],&indata[nRows],__tmp.begin());
1100 write(__tmp,firstRow, nullValue);
1104 template <
typename S>
1105 void Column::write (
const std::valarray<S>& indata,
const std::vector<long>& vectorLengths,
1111 using namespace std;
1112 const size_t nRows = vectorLengths.size();
1115 vector<long> sums(nRows+1);
1117 vector<long>::iterator itSums = sums.begin() + 1;
1118 partial_sum(vectorLengths.begin(), vectorLengths.end(), itSums);
1119 if (indata.size() <
static_cast<size_t>(sums[nRows]))
1121 #ifdef SSTREAM_DEFECT
1124 ostringstream msgStr;
1126 msgStr <<
" input data size: " << indata.size() <<
" vector length sum: " << sums[nRows];
1127 #ifdef SSTREAM_DEFECT
1128 msgStr << std::ends;
1131 String msg(msgStr.str());
1134 vector<valarray<S> > vvArray(nRows);
1135 for (
size_t iRow=0; iRow<nRows; ++iRow)
1137 valarray<S>& vArray = vvArray[iRow];
1138 long first = sums[iRow];
1139 long last = sums[iRow+1];
1140 vArray.resize(last - first);
1141 for (
long iElem=first; iElem<last; ++iElem)
1143 vArray[iElem - first] = indata[iElem];
1146 writeArrays(vvArray, firstRow,
static_cast<S*
>(0));
1149 template <
typename S>
1150 void Column::write (
const std::vector<S>& indata,
const std::vector<long>& vectorLengths,
1155 std::valarray<S> __tmp(indata.size());
1156 std::copy(indata.begin(),indata.end(),&__tmp[0]);
1157 write(__tmp,vectorLengths,firstRow);
1161 template <
typename S>
1162 void Column::write (S* indata,
long nelements,
const std::vector<long>& vectorLengths,
1166 std::valarray<S> __tmp(indata,nelements);
1167 write(__tmp,vectorLengths,firstRow);
1170 template <
typename S>
1173 write(indata,nRows,firstRow,
static_cast<S*
>(0));
1176 template <
typename S>
1179 write(indata,nRows,firstRow,
static_cast<S*
>(0));
1182 template <
typename S>
1185 write(indata,nelements,nRows,firstRow,
static_cast<S*
>(0));
1190 template <
typename S>
1200 firstRow = std::max(firstRow,
static_cast<long>(1));
1201 #ifdef SSTREAM_DEFECT
1202 std::ostrstream msgStr;
1204 std::ostringstream msgStr;
1206 const size_t numRows =
static_cast<size_t>(nRows);
1207 if (indata.size() % numRows)
1209 msgStr <<
"To use this write function, input array size"
1210 <<
"\n must be exactly divisible by requested num rows: "
1215 const size_t cellsize = indata.size()/numRows;
1218 msgStr <<
"column: " <<
name()
1219 <<
"\n input data size: " << indata.size()
1220 <<
" required: " << nRows*
repeat();
1221 String msg(msgStr.str());
1225 std::vector<std::valarray<S> > vvArray(numRows);
1226 for (
size_t i=0; i<numRows; ++i)
1228 vvArray[i].resize(cellsize);
1229 vvArray[i] = indata[std::slice(cellsize*i,cellsize,1)];
1234 template <
typename S>
1235 void Column::write (
const std::vector<S>& indata,
long nRows,
long firstRow, S* nullValue)
1240 std::valarray<S> __tmp(indata.size());
1241 std::copy(indata.begin(),indata.end(),&__tmp[0]);
1242 write(__tmp,nRows,firstRow, nullValue);
1245 template <
typename S>
1246 void Column::write (S* indata,
long nelements,
long nRows,
long firstRow, S* nullValue)
1251 std::valarray<S> __tmp(indata,nelements);
1252 write(__tmp,nRows,firstRow, nullValue);
1256 template <
typename S>
1263 template <
typename S>
1270 using std::valarray;
1273 firstRow = std::max(firstRow,
static_cast<long>(1));
1274 if (ColumnVectorData<S>* col =
dynamic_cast<ColumnVectorData<S>*
>(
this))
1276 col->writeData(indata,firstRow,nullValue);
1283 if ( inType() ==
type())
1285 String msg(
"Incorrect call: writing vectors to scalar column ");
1290 size_t n(indata.size());
1291 if (
type() == Tdouble ||
type() == VTdouble)
1293 ColumnVectorData<double>& col
1294 =
dynamic_cast<ColumnVectorData<double>&
>(*this);
1295 vector<valarray<double> > __tmp(n);
1296 for (
size_t i = 0; i < n; ++i)
1298 FITSUtil::fill(__tmp[i],indata[i]);
1300 col.writeData(__tmp,firstRow);
1302 else if (
type() == Tfloat ||
type() == VTfloat)
1304 ColumnVectorData<float>& col
1305 =
dynamic_cast<ColumnVectorData<float>&
>(*this);
1306 vector<valarray<float> > __tmp(n);
1307 for (
size_t i = 0; i < n; ++i)
1309 FITSUtil::fill(__tmp[i],indata[i]);
1311 col.writeData(__tmp,firstRow);
1313 else if (
type() == Tint ||
type() == VTint)
1315 ColumnVectorData<int>& col
1316 =
dynamic_cast<ColumnVectorData<int>&
>(*this);
1317 vector<valarray<int> > __tmp(n);
1322 nullVal =
static_cast<int>(*nullValue);
1323 pNullVal = &nullVal;
1325 for (
size_t i = 0; i < n; ++i)
1327 FITSUtil::fill(__tmp[i],indata[i]);
1329 col.writeData(__tmp,firstRow,pNullVal);
1331 else if (
type() == Tshort ||
type() == VTshort)
1333 ColumnVectorData<short>& col
1334 =
dynamic_cast<ColumnVectorData<short>&
>(*this);
1335 vector<valarray<short> > __tmp(n);
1337 short* pNullVal = 0;
1340 nullVal =
static_cast<short>(*nullValue);
1341 pNullVal = &nullVal;
1343 for (
size_t i = 0; i < n; ++i)
1345 FITSUtil::fill(__tmp[i],indata[i]);
1347 col.writeData(__tmp,firstRow,pNullVal);
1349 else if (
type() == Tlong ||
type() == VTlong)
1351 ColumnVectorData<long>& col
1352 =
dynamic_cast<ColumnVectorData<long>&
>(*this);
1353 vector<valarray<long> > __tmp(n);
1358 nullVal =
static_cast<long>(*nullValue);
1359 pNullVal = &nullVal;
1361 for (
size_t i = 0; i < n; ++i)
1363 FITSUtil::fill(__tmp[i],indata[i]);
1365 col.writeData(__tmp,firstRow,pNullVal);
1367 else if (
type() == Tlonglong ||
type() == VTlonglong)
1369 ColumnVectorData<LONGLONG>& col
1370 =
dynamic_cast<ColumnVectorData<LONGLONG>&
>(*this);
1371 vector<valarray<LONGLONG> > __tmp(n);
1372 LONGLONG nullVal(0);
1373 LONGLONG* pNullVal = 0;
1376 nullVal =
static_cast<LONGLONG
>(*nullValue);
1377 pNullVal = &nullVal;
1379 for (
size_t i = 0; i < n; ++i)
1381 FITSUtil::fill(__tmp[i],indata[i]);
1383 col.writeData(__tmp,firstRow,pNullVal);
1385 else if (
type() == Tlogical ||
type() == VTlogical)
1387 ColumnVectorData<bool>& col
1388 =
dynamic_cast<ColumnVectorData<bool>&
>(*this);
1393 nullVal =
static_cast<bool>(*nullValue);
1394 pNullVal = &nullVal;
1396 vector<valarray<bool> > __tmp(n);
1397 for (
size_t i = 0; i < n; ++i)
1399 FITSUtil::fill(__tmp[i],indata[i]);
1401 col.writeData(__tmp,firstRow,pNullVal);
1403 else if (
type() == Tbyte ||
type() == VTbyte)
1405 ColumnVectorData<unsigned char>& col
1406 =
dynamic_cast<ColumnVectorData<unsigned char>&
>(*this);
1407 unsigned char nullVal(0);
1408 unsigned char* pNullVal = 0;
1411 nullVal =
static_cast<unsigned char>(*nullValue);
1412 pNullVal = &nullVal;
1414 vector<valarray<unsigned char> > __tmp(n);
1415 for (
size_t i = 0; i < n; ++i)
1417 FITSUtil::fill(__tmp[i],indata[i]);
1419 col.writeData(__tmp,firstRow,pNullVal);
1421 else if (
type() == Tushort ||
type() == VTushort)
1423 ColumnVectorData<unsigned short>& col
1424 =
dynamic_cast<ColumnVectorData<unsigned short>&
>(*this);
1425 unsigned short nullVal(0);
1426 unsigned short* pNullVal = 0;
1429 nullVal =
static_cast<unsigned short>(*nullValue);
1430 pNullVal = &nullVal;
1432 vector<valarray<unsigned short> > __tmp(n);
1433 for (
size_t i = 0; i < n; ++i)
1435 FITSUtil::fill(__tmp[i],indata[i]);
1437 col.writeData(__tmp,firstRow,pNullVal);
1439 else if (
type() == Tuint ||
type() == VTuint)
1441 ColumnVectorData<unsigned int>& col
1442 =
dynamic_cast<ColumnVectorData<unsigned int>&
>(*this);
1443 unsigned int nullVal(0);
1444 unsigned int* pNullVal = 0;
1447 nullVal =
static_cast<unsigned int>(*nullValue);
1448 pNullVal = &nullVal;
1450 vector<valarray<unsigned int> > __tmp(n);
1451 for (
size_t i = 0; i < n; ++i)
1453 FITSUtil::fill(__tmp[i],indata[i]);
1455 col.writeData(__tmp,firstRow,pNullVal);
1457 else if (
type() == Tulong ||
type() == VTulong)
1459 ColumnVectorData<unsigned long>& col
1460 =
dynamic_cast<ColumnVectorData<unsigned long>&
>(*this);
1461 unsigned long nullVal(0);
1462 unsigned long* pNullVal = 0;
1465 nullVal =
static_cast<unsigned long>(*nullValue);
1466 pNullVal = &nullVal;
1468 vector<valarray<unsigned long> > __tmp(n);
1469 for (
size_t i = 0; i < n; ++i)
1471 FITSUtil::fill(__tmp[i],indata[i]);
1473 col.writeData(__tmp,firstRow,pNullVal);
1484 template <
typename T>
1489 #ifdef SSTREAM_DEFECT
1490 std::ostrstream keyName;
1491 keyName <<
"TNULL" <<
index() << std::ends;
1492 char* nullKey =
const_cast<char*
>(keyName.str());
1494 std::ostringstream keyName;
1495 keyName <<
"TNULL" <<
index();
1496 String keyNameStr = keyName.str();
1497 char* nullKey =
const_cast<char*
>(keyNameStr.c_str());
1502 int dataType =
static_cast<int>(inputType());
1503 if (dataType ==
static_cast<int>(Tstring))
1509 if (fits_update_key(
fitsPointer(),dataType,nullKey,&nullVal,0,&status))
1519 template <
typename T>
1523 #ifdef SSTREAM_DEFECT
1524 std::ostrstream keyName;
1525 keyName <<
"TNULL" <<
index() << std::ends;
1526 char* nullKey =
const_cast<char*
>(keyName.str());
1528 std::ostringstream keyName;
1529 keyName <<
"TNULL" <<
index();
1530 String keyNameStr = keyName.str();
1531 char* nullKey =
const_cast<char*
>(keyNameStr.c_str());
1536 int dataType =
static_cast<int>(inputType());
1537 if (dataType ==
static_cast<int>(Tstring))
1541 bool keyExists =
false;
1542 if (fits_read_key(m_parent->
fitsPointer(), dataType, nullKey, &tmpVal, 0, &status))
1544 if (status == KEY_NO_EXIST || status == VALUE_UNDEFINED)
Exception thrown if the data supplied for a write operation is less than declared.
Definition: Column.h:921
Exception thrown for invalid data type inputs.
Definition: Column.h:861
Exception thrown if user enters a non-positive number for the number of rows to write.
Definition: Column.h:945
Exception thrown on attempting to read a row number beyond the end of a table.
Definition: Column.h:909
Exception thrown on attempting to access a scalar column as vector data.
Definition: Column.h:885
ValueType type() const
returns the data type of the column
Definition: Column.h:1437
void addNullValue(T nullVal)
Set the TNULLn keyword for the column.
Definition: ColumnT.h:1485
bool getNullValue(T *nullVal) const
Get the value of the TNULLn keyword for the column.
Definition: ColumnT.h:1520
void readArrays(std::vector< std::valarray< S > > &vals, long first, long last)
return a set of rows of a vector column into a vector of valarrays
Definition: ColumnT.h:680
int rows() const
return the number of rows in the table.
Definition: Column.cxx:275
void write(const std::vector< S > &indata, long firstRow)
write a vector of values into a scalar column starting with firstRow
Definition: ColumnT.h:869
Table * parent() const
return a pointer to the Table which owns this Column
Definition: Column.cxx:312
const String & name() const
return name of Column (TTYPEn keyword)
Definition: Column.h:1532
size_t repeat() const
get the repeat count for the rows
Definition: Column.h:1390
bool isRead() const
flag set to true if the entire column data has been read from disk
Definition: Column.h:1370
int index() const
get the Column index (the n in TTYPEn etc).
Definition: Column.h:1360
void read(std::vector< S > &vals, long first, long last)
Retrieve data from a scalar column into a std::vector.
Definition: ColumnT.h:42
bool varLength() const
boolean, set to true if Column has variable length vector rows.
Definition: Column.h:1395
fitsfile * fitsPointer()
fits pointer corresponding to fits file containing column data.
Definition: Column.cxx:264
void writeArrays(const std::vector< std::valarray< S > > &indata, long firstRow)
write a vector of valarray objects to the column, starting at row firstRow >= 1
Definition: ColumnT.h:1257
virtual void makeThisCurrent() const
move the fitsfile pointer to this current HDU.
Definition: ExtHDU.cxx:208
FitsError is the exception thrown by non-zero cfitsio status codes.
Definition: FitsError.h:113
fitsfile * fitsPointer() const
return the fitsfile pointer for the FITS object containing the HDU
Definition: HDU.cxx:308
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26
function object that returns the FITS ValueType corresponding to an input intrinsic type
Definition: FITSUtil.h:506