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));
360 template <
typename S>
369 if ( ColumnVectorData<S>* col =
dynamic_cast<ColumnVectorData<S>*
>(
this))
381 if (!
isRead()) col->readRow(row,nullValue);
382 FITSUtil::fill(vals,col->data(row));
387 if ( outputType() ==
type() )
406 if (
type() == Tdouble ||
type() == VTdouble )
408 ColumnVectorData<double>& col
409 =
dynamic_cast<ColumnVectorData<double>&
>(*this);
410 if (!
isRead()) col.readRow(row);
411 FITSUtil::fill(vals,col.data(row));
414 else if (
type() == Tfloat ||
type() == VTfloat )
416 ColumnVectorData<float>& col
417 =
dynamic_cast<ColumnVectorData<float>&
>(*this);
418 if (!
isRead()) col.readRow(row);
419 FITSUtil::fill(vals,col.data(row));
421 else if (
type() == Tint ||
type() == VTint )
424 if (nullValue) nullVal =
static_cast<int>(*nullValue);
425 ColumnVectorData<int>& col
426 =
dynamic_cast<ColumnVectorData<int>&
>(*this);
427 if (!
isRead()) col.readRow(row,&nullVal);
428 FITSUtil::fill(vals,col.data(row));
430 else if (
type() == Tshort ||
type() == VTshort )
433 if (nullValue) nullVal =
static_cast<short>(*nullValue);
434 ColumnVectorData<short>& col
435 =
dynamic_cast<ColumnVectorData<short>&
>(*this);
436 if (!
isRead()) col.readRow(row,&nullVal);
437 FITSUtil::fill(vals,col.data(row));
439 else if (
type() == Tlong ||
type() == VTlong )
442 if (nullValue) nullVal =
static_cast<long>(*nullValue);
443 ColumnVectorData<long>& col
444 =
dynamic_cast<ColumnVectorData<long>&
>(*this);
445 if (!
isRead()) col.readRow(row,&nullVal);
446 FITSUtil::fill(vals,col.data(row));
448 else if (
type() == Tlonglong ||
type() == VTlonglong )
451 if (nullValue) nullVal =
static_cast<LONGLONG
>(*nullValue);
452 ColumnVectorData<LONGLONG>& col
453 =
dynamic_cast<ColumnVectorData<LONGLONG>&
>(*this);
454 if (!
isRead()) col.readRow(row,&nullVal);
455 FITSUtil::fill(vals,col.data(row));
457 else if (
type() == Tlogical ||
type() == VTlogical )
460 if (nullValue) nullVal =
static_cast<bool>(*nullValue);
461 ColumnVectorData<bool>& col
462 =
dynamic_cast<ColumnVectorData<bool>&
>(*this);
463 if (!
isRead()) col.readRow(row,&nullVal);
464 FITSUtil::fill(vals,col.data(row));
466 else if (
type() == Tbit ||
type() == Tbyte ||
467 type() == VTbit ||
type() == VTbyte )
469 unsigned char nullVal(0);
470 if (nullValue) nullVal
471 =
static_cast<unsigned char>(*nullValue);
472 ColumnVectorData<unsigned char>& col
473 =
dynamic_cast<ColumnVectorData<unsigned char>&
>(*this);
474 if (!
isRead()) col.readRow(row,&nullVal);
475 FITSUtil::fill(vals,col.data(row));
477 else if (
type() == Tushort ||
type() == VTushort)
479 unsigned short nullVal(0);
480 if (nullValue) nullVal
481 =
static_cast<unsigned short>(*nullValue);
482 ColumnVectorData<unsigned short>& col
483 =
dynamic_cast<ColumnVectorData<unsigned short>&
>(*this);
484 if (!
isRead()) col.readRow(row,&nullVal);
485 FITSUtil::fill(vals,col.data(row));
487 else if (
type() == Tuint ||
type() == VTuint)
489 unsigned int nullVal(0);
490 if (nullValue) nullVal
491 =
static_cast<unsigned int>(*nullValue);
492 ColumnVectorData<unsigned int>& col
493 =
dynamic_cast<ColumnVectorData<unsigned int>&
>(*this);
494 if (!
isRead()) col.readRow(row,&nullVal);
495 FITSUtil::fill(vals,col.data(row));
497 else if (
type() == Tulong ||
type() == VTulong)
499 unsigned long nullVal(0);
500 if (nullValue) nullVal
501 =
static_cast<unsigned long>(*nullValue);
502 ColumnVectorData<unsigned long>& col
503 =
dynamic_cast<ColumnVectorData<unsigned long>&
>(*this);
504 if (!
isRead()) col.readRow(row,&nullVal);
505 FITSUtil::fill(vals,col.data(row));
514 catch (std::bad_cast)
521 template <
typename S>
524 readArrays(vals,first,last,static_cast<S*>(0));
527 template <
typename S>
529 long first,
long last, S* nullValue)
536 long range = numberOfElements(first,last);
541 if ( ColumnVectorData<S>* col =
dynamic_cast<ColumnVectorData<S>*
>(
this))
543 for (
int j = 0; j < range; ++j)
545 if (!
isRead()) col->readRow(j + first,nullValue);
546 FITSUtil::fill(vals[j],col->data(j+first));
552 if ( outputType() ==
type() )
562 if (
type() == Tdouble ||
type() == VTdouble )
564 ColumnVectorData<double>& col
565 =
dynamic_cast<ColumnVectorData<double>&
>(*this);
566 for (
int j = 0; j < range; ++j)
568 if (!
isRead()) col.readRow(j + first);
569 FITSUtil::fill(vals[j],col.data(j+first));
572 else if (
type() == Tfloat ||
type() == VTfloat )
574 ColumnVectorData<float>& col
575 =
dynamic_cast<ColumnVectorData<float>&
>(*this);
576 for (
int j = 0; j < range; ++j)
578 if (!
isRead()) col.readRow(j + first);
579 FITSUtil::fill(vals[j],col.data(j+first));
582 else if (
type() == Tint ||
type() == VTint )
585 if (nullValue) nullVal =
static_cast<int>(*nullValue);
586 ColumnVectorData<int>& col
587 =
dynamic_cast<ColumnVectorData<int>&
>(*this);
588 for (
int j = 0; j < range; ++j)
590 if (!
isRead()) col.readRow(j + first,&nullVal);
591 FITSUtil::fill(vals[j],col.data(j+first));
594 else if (
type() == Tshort ||
type() == VTshort )
597 if (nullValue) nullVal =
static_cast<short>(*nullValue);
598 ColumnVectorData<short>& col
599 =
dynamic_cast<ColumnVectorData<short>&
>(*this);
600 for (
int j = 0; j < range; ++j)
602 if (!
isRead()) col.readRow(j + first,&nullVal);
603 FITSUtil::fill(vals[j],col.data(j+first));
606 else if (
type() == Tlong ||
type() == VTlong )
609 if (nullValue) nullVal =
static_cast<long>(*nullValue);
610 ColumnVectorData<long>& col
611 =
dynamic_cast<ColumnVectorData<long>&
>(*this);
612 for (
int j = 0; j < range; ++j)
614 if (!
isRead()) col.readRow(j + first,&nullVal);
615 FITSUtil::fill(vals[j],col.data(j+first));
618 else if (
type() == Tlonglong ||
type() == VTlonglong )
621 if (nullValue) nullVal =
static_cast<LONGLONG
>(*nullValue);
622 ColumnVectorData<LONGLONG>& col
623 =
dynamic_cast<ColumnVectorData<LONGLONG>&
>(*this);
624 for (
int j = 0; j < range; ++j)
626 if (!
isRead()) col.readRow(j + first,&nullVal);
627 FITSUtil::fill(vals[j],col.data(j+first));
630 else if (
type() == Tlogical ||
type() == VTlogical )
633 if (nullValue) nullVal =
static_cast<bool>(*nullValue);
634 ColumnVectorData<bool>& col
635 =
dynamic_cast<ColumnVectorData<bool>&
>(*this);
636 for (
int j = 0; j < range; ++j)
638 if (!
isRead()) col.readRow(j + first,&nullVal);
639 FITSUtil::fill(vals[j],col.data(j+first));
642 else if (
type() == Tbit ||
type() == Tbyte ||
643 type() == VTbit ||
type() == VTbyte )
645 unsigned char nullVal(0);
646 if (nullValue) nullVal
647 =
static_cast<unsigned char>(*nullValue);
648 ColumnVectorData<unsigned char>& col
649 =
dynamic_cast<ColumnVectorData<unsigned char>&
>(*this);
650 for (
int j = 0; j < range; ++j)
652 if (!
isRead()) col.readRow(j + first,&nullVal);
653 FITSUtil::fill(vals[j],col.data(j+first));
656 else if (
type() == Tushort ||
type() == VTushort )
658 unsigned short nullVal(0);
659 if (nullValue) nullVal
660 =
static_cast<unsigned short>(*nullValue);
661 ColumnVectorData<unsigned short>& col
662 =
dynamic_cast<ColumnVectorData<unsigned short>&
>(*this);
663 for (
int j = 0; j < range; ++j)
665 if (!
isRead()) col.readRow(j + first,&nullVal);
666 FITSUtil::fill(vals[j],col.data(j+first));
669 else if (
type() == Tuint ||
type() == VTuint )
671 unsigned int nullVal(0);
672 if (nullValue) nullVal
673 =
static_cast<unsigned int>(*nullValue);
674 ColumnVectorData<unsigned int>& col
675 =
dynamic_cast<ColumnVectorData<unsigned int>&
>(*this);
676 for (
int j = 0; j < range; ++j)
678 if (!
isRead()) col.readRow(j + first,&nullVal);
679 FITSUtil::fill(vals[j],col.data(j+first));
682 else if (
type() == Tulong ||
type() == VTulong )
684 unsigned long nullVal(0);
685 if (nullValue) nullVal
686 =
static_cast<unsigned long>(*nullValue);
687 ColumnVectorData<unsigned long>& col
688 =
dynamic_cast<ColumnVectorData<unsigned long>&
>(*this);
689 for (
int j = 0; j < range; ++j)
691 if (!
isRead()) col.readRow(j + first,&nullVal);
692 FITSUtil::fill(vals[j],col.data(j+first));
701 catch (std::bad_cast)
710 template <
typename S>
716 write(indata,firstRow,static_cast<S*>(0));
719 template <
typename S>
722 size_t n(indata.size());
723 std::vector<S> __tmp(n);
724 for (
size_t j = 0; j < n; ++j) __tmp[j] = indata[j];
725 write(__tmp,firstRow,static_cast<S*>(0));
728 template <
typename S>
731 write(indata,nRows,firstRow,static_cast<S*>(0));
735 template <
typename S>
736 void Column::write (
const std::vector<S>& indata,
long firstRow, S* nullValue)
746 firstRow = std::max(firstRow,static_cast<long>(1));
747 if (ColumnData<S>* col =
dynamic_cast<ColumnData<S>*
>(
this))
749 col->writeData(indata,firstRow,nullValue);
756 if ( inType() ==
type())
758 String msg(
"Incorrect call: writing to vector column ");
760 msg +=
" requires specification of # rows or vector lengths";
765 if (
type() == Tdouble )
767 ColumnData<double>& col
768 =
dynamic_cast<ColumnData<double>&
>(*this);
769 std::vector<double> __tmp;
770 FITSUtil::fill(__tmp,indata,1,indata.size());
771 col.writeData(__tmp,firstRow);
773 else if (
type() == Tfloat )
775 ColumnData<float>& col
776 =
dynamic_cast<ColumnData<float>&
>(*this);
777 std::vector<float> __tmp;
778 FITSUtil::fill(__tmp,indata,1,indata.size());
779 col.writeData(__tmp,firstRow);
781 else if (
type() == Tint )
787 nullVal =
static_cast<int>(*nullValue);
790 if (nullValue) nullVal =
static_cast<int>(*nullValue);
792 =
dynamic_cast<ColumnData<int>&
>(*this);
793 std::vector<int> __tmp;
794 FITSUtil::fill(__tmp,indata,1,indata.size());
795 col.writeData(__tmp,firstRow,pNullVal);
797 else if (
type() == Tshort )
803 nullVal =
static_cast<short>(*nullValue);
806 ColumnData<short>& col
807 =
dynamic_cast<ColumnData<short>&
>(*this);
808 std::vector<short> __tmp;
809 FITSUtil::fill(__tmp,indata,1,indata.size());
810 col.writeData(__tmp,firstRow,pNullVal);
812 else if (
type() == Tlong )
818 nullVal =
static_cast<long>(*nullValue);
821 ColumnData<long>& col
822 =
dynamic_cast<ColumnData<long>&
>(*this);
823 std::vector<long> __tmp;
824 FITSUtil::fill(__tmp,indata,1,indata.size());
825 col.writeData(__tmp,firstRow,pNullVal);
827 else if (
type() == Tlonglong )
830 LONGLONG* pNullVal = 0;
833 nullVal =
static_cast<LONGLONG
>(*nullValue);
836 ColumnData<LONGLONG>& col
837 =
dynamic_cast<ColumnData<LONGLONG>&
>(*this);
838 std::vector<LONGLONG> __tmp;
839 FITSUtil::fill(__tmp,indata,1,indata.size());
840 col.writeData(__tmp,firstRow,pNullVal);
842 else if (
type() == Tlogical )
848 nullVal =
static_cast<bool>(*nullValue);
851 ColumnData<bool>& col
852 =
dynamic_cast<ColumnData<bool>&
>(*this);
853 std::vector<bool> __tmp;
854 FITSUtil::fill(__tmp,indata,1,indata.size());
855 col.writeData(__tmp,firstRow,pNullVal);
857 else if (
type() == Tbyte )
859 unsigned char nullVal(0);
860 unsigned char* pNullVal = 0;
863 nullVal =
static_cast<unsigned char>(*nullValue);
866 ColumnData<unsigned char>& col
867 =
dynamic_cast<ColumnData<unsigned char>&
>(*this);
868 std::vector<unsigned char> __tmp;
869 FITSUtil::fill(__tmp,indata,1,indata.size());
870 col.writeData(__tmp,firstRow,pNullVal);
872 else if (
type() == Tushort )
874 unsigned short nullVal(0);
875 unsigned short* pNullVal = 0;
878 nullVal =
static_cast<unsigned short>(*nullValue);
881 ColumnData<unsigned short>& col
882 =
dynamic_cast<ColumnData<unsigned short>&
>(*this);
883 std::vector<unsigned short> __tmp;
884 FITSUtil::fill(__tmp,indata,1,indata.size());
885 col.writeData(__tmp,firstRow,pNullVal);
887 else if (
type() == Tuint )
889 unsigned int nullVal(0);
890 unsigned int* pNullVal = 0;
893 nullVal =
static_cast<unsigned int>(*nullValue);
896 ColumnData<unsigned int>& col
897 =
dynamic_cast<ColumnData<unsigned int>&
>(*this);
898 std::vector<unsigned int> __tmp;
899 FITSUtil::fill(__tmp,indata,1,indata.size());
900 col.writeData(__tmp,firstRow,pNullVal);
902 else if (
type() == Tulong )
904 unsigned long nullVal(0);
905 unsigned long* pNullVal = 0;
908 nullVal =
static_cast<unsigned long>(*nullValue);
911 ColumnData<unsigned long>& col
912 =
dynamic_cast<ColumnData<unsigned long>&
>(*this);
913 std::vector<unsigned long> __tmp;
914 FITSUtil::fill(__tmp,indata,1,indata.size());
915 col.writeData(__tmp,firstRow,pNullVal);
926 template <
typename S>
927 void Column::write (
const std::valarray<S>& indata,
long firstRow, S* nullValue)
930 std::vector<S> __tmp;
931 FITSUtil::fill(__tmp,indata);
932 write(__tmp,firstRow,nullValue);
935 template <
typename S>
940 std::vector<S> __tmp(nRows);
941 std::copy(&indata[0],&indata[nRows],__tmp.begin());
942 write(__tmp,firstRow, nullValue);
946 template <
typename S>
947 void Column::write (
const std::valarray<S>& indata,
const std::vector<long>& vectorLengths,
954 const size_t nRows = vectorLengths.size();
957 vector<long> sums(nRows+1);
959 vector<long>::iterator itSums = sums.begin() + 1;
960 partial_sum(vectorLengths.begin(), vectorLengths.end(), itSums);
961 if (indata.size() <
static_cast<size_t>(sums[nRows]))
963 #ifdef SSTREAM_DEFECT
966 ostringstream msgStr;
968 msgStr <<
" input data size: " << indata.size() <<
" vector length sum: " << sums[nRows];
969 #ifdef SSTREAM_DEFECT
973 String msg(msgStr.str());
976 vector<valarray<S> > vvArray(nRows);
977 for (
size_t iRow=0; iRow<nRows; ++iRow)
979 valarray<S>& vArray = vvArray[iRow];
980 long first = sums[iRow];
981 long last = sums[iRow+1];
982 vArray.resize(last - first);
983 for (
long iElem=first; iElem<last; ++iElem)
985 vArray[iElem - first] = indata[iElem];
988 writeArrays(vvArray, firstRow, static_cast<S*>(0));
991 template <
typename S>
992 void Column::write (
const std::vector<S>& indata,
const std::vector<long>& vectorLengths,
997 std::valarray<S> __tmp(indata.size());
998 std::copy(indata.begin(),indata.end(),&__tmp[0]);
999 write(__tmp,vectorLengths,firstRow);
1003 template <
typename S>
1004 void Column::write (S* indata,
long nelements,
const std::vector<long>& vectorLengths,
1008 size_t n(vectorLengths.size());
1009 std::valarray<S> __tmp(indata,nelements);
1010 write(__tmp,vectorLengths,firstRow);
1013 template <
typename S>
1016 write(indata,nRows,firstRow,static_cast<S*>(0));
1019 template <
typename S>
1022 write(indata,nRows,firstRow,static_cast<S*>(0));
1025 template <
typename S>
1028 write(indata,nelements,nRows,firstRow,static_cast<S*>(0));
1033 template <
typename S>
1043 firstRow = std::max(firstRow,static_cast<long>(1));
1044 #ifdef SSTREAM_DEFECT
1045 std::ostrstream msgStr;
1047 std::ostringstream msgStr;
1049 const size_t numRows =
static_cast<size_t>(nRows);
1050 if (indata.size() % numRows)
1052 msgStr <<
"To use this write function, input array size"
1053 <<
"\n must be exactly divisible by requested num rows: "
1058 const size_t cellsize = indata.size()/numRows;
1061 msgStr <<
"column: " <<
name()
1062 <<
"\n input data size: " << indata.size()
1063 <<
" required: " << nRows*
repeat();
1064 String msg(msgStr.str());
1068 std::vector<std::valarray<S> > vvArray(numRows);
1069 for (
size_t i=0; i<numRows; ++i)
1071 vvArray[i].resize(cellsize);
1072 vvArray[i] = indata[std::slice(cellsize*i,cellsize,1)];
1077 template <
typename S>
1078 void Column::write (
const std::vector<S>& indata,
long nRows,
long firstRow, S* nullValue)
1083 std::valarray<S> __tmp(indata.size());
1084 std::copy(indata.begin(),indata.end(),&__tmp[0]);
1085 write(__tmp,nRows,firstRow, nullValue);
1088 template <
typename S>
1089 void Column::write (S* indata,
long nelements,
long nRows,
long firstRow, S* nullValue)
1094 std::valarray<S> __tmp(indata,nelements);
1095 write(__tmp,nRows,firstRow, nullValue);
1099 template <
typename S>
1106 template <
typename S>
1113 using std::valarray;
1116 firstRow = std::max(firstRow,static_cast<long>(1));
1117 if (ColumnVectorData<S>* col =
dynamic_cast<ColumnVectorData<S>*
>(
this))
1119 col->writeData(indata,firstRow,nullValue);
1126 if ( inType() ==
type())
1128 String msg(
"Incorrect call: writing vectors to scalar column ");
1133 size_t n(indata.size());
1134 if (
type() == Tdouble ||
type() == VTdouble)
1136 ColumnVectorData<double>& col
1137 =
dynamic_cast<ColumnVectorData<double>&
>(*this);
1138 vector<valarray<double> > __tmp(n);
1139 for (
size_t i = 0; i < n; ++i)
1141 FITSUtil::fill(__tmp[i],indata[i]);
1143 col.writeData(__tmp,firstRow);
1145 else if (
type() == Tfloat ||
type() == VTfloat)
1147 ColumnVectorData<float>& col
1148 =
dynamic_cast<ColumnVectorData<float>&
>(*this);
1149 vector<valarray<float> > __tmp(n);
1150 for (
size_t i = 0; i < n; ++i)
1152 FITSUtil::fill(__tmp[i],indata[i]);
1154 col.writeData(__tmp,firstRow);
1156 else if (
type() == Tint ||
type() == VTint)
1158 ColumnVectorData<int>& col
1159 =
dynamic_cast<ColumnVectorData<int>&
>(*this);
1160 vector<valarray<int> > __tmp(n);
1165 nullVal =
static_cast<int>(*nullValue);
1166 pNullVal = &nullVal;
1168 for (
size_t i = 0; i < n; ++i)
1170 FITSUtil::fill(__tmp[i],indata[i]);
1172 col.writeData(__tmp,firstRow,pNullVal);
1174 else if (
type() == Tshort ||
type() == VTshort)
1176 ColumnVectorData<short>& col
1177 =
dynamic_cast<ColumnVectorData<short>&
>(*this);
1178 vector<valarray<short> > __tmp(n);
1180 short* pNullVal = 0;
1183 nullVal =
static_cast<short>(*nullValue);
1184 pNullVal = &nullVal;
1186 for (
size_t i = 0; i < n; ++i)
1188 FITSUtil::fill(__tmp[i],indata[i]);
1190 col.writeData(__tmp,firstRow,pNullVal);
1192 else if (
type() == Tlong ||
type() == VTlong)
1194 ColumnVectorData<long>& col
1195 =
dynamic_cast<ColumnVectorData<long>&
>(*this);
1196 vector<valarray<long> > __tmp(n);
1201 nullVal =
static_cast<long>(*nullValue);
1202 pNullVal = &nullVal;
1204 for (
size_t i = 0; i < n; ++i)
1206 FITSUtil::fill(__tmp[i],indata[i]);
1208 col.writeData(__tmp,firstRow,pNullVal);
1210 else if (
type() == Tlonglong ||
type() == VTlonglong)
1212 ColumnVectorData<LONGLONG>& col
1213 =
dynamic_cast<ColumnVectorData<LONGLONG>&
>(*this);
1214 vector<valarray<LONGLONG> > __tmp(n);
1215 LONGLONG nullVal(0);
1216 LONGLONG* pNullVal = 0;
1219 nullVal =
static_cast<LONGLONG
>(*nullValue);
1220 pNullVal = &nullVal;
1222 for (
size_t i = 0; i < n; ++i)
1224 FITSUtil::fill(__tmp[i],indata[i]);
1226 col.writeData(__tmp,firstRow,pNullVal);
1228 else if (
type() == Tlogical ||
type() == VTlogical)
1230 ColumnVectorData<bool>& col
1231 =
dynamic_cast<ColumnVectorData<bool>&
>(*this);
1236 nullVal =
static_cast<bool>(*nullValue);
1237 pNullVal = &nullVal;
1239 vector<valarray<bool> > __tmp(n);
1240 for (
size_t i = 0; i < n; ++i)
1242 FITSUtil::fill(__tmp[i],indata[i]);
1244 col.writeData(__tmp,firstRow,pNullVal);
1246 else if (
type() == Tbyte ||
type() == VTbyte)
1248 ColumnVectorData<unsigned char>& col
1249 =
dynamic_cast<ColumnVectorData<unsigned char>&
>(*this);
1250 unsigned char nullVal(0);
1251 unsigned char* pNullVal = 0;
1254 nullVal =
static_cast<unsigned char>(*nullValue);
1255 pNullVal = &nullVal;
1257 vector<valarray<unsigned char> > __tmp(n);
1258 for (
size_t i = 0; i < n; ++i)
1260 FITSUtil::fill(__tmp[i],indata[i]);
1262 col.writeData(__tmp,firstRow,&nullVal);
1264 else if (
type() == Tushort ||
type() == VTushort)
1266 ColumnVectorData<unsigned short>& col
1267 =
dynamic_cast<ColumnVectorData<unsigned short>&
>(*this);
1268 unsigned short nullVal(0);
1269 unsigned short* pNullVal = 0;
1272 nullVal =
static_cast<unsigned short>(*nullValue);
1273 pNullVal = &nullVal;
1275 vector<valarray<unsigned short> > __tmp(n);
1276 for (
size_t i = 0; i < n; ++i)
1278 FITSUtil::fill(__tmp[i],indata[i]);
1280 col.writeData(__tmp,firstRow,pNullVal);
1282 else if (
type() == Tuint ||
type() == VTuint)
1284 ColumnVectorData<unsigned int>& col
1285 =
dynamic_cast<ColumnVectorData<unsigned int>&
>(*this);
1286 unsigned int nullVal(0);
1287 unsigned int* pNullVal = 0;
1290 nullVal =
static_cast<unsigned int>(*nullValue);
1291 pNullVal = &nullVal;
1293 vector<valarray<unsigned int> > __tmp(n);
1294 for (
size_t i = 0; i < n; ++i)
1296 FITSUtil::fill(__tmp[i],indata[i]);
1298 col.writeData(__tmp,firstRow,pNullVal);
1300 else if (
type() == Tulong ||
type() == VTulong)
1302 ColumnVectorData<unsigned long>& col
1303 =
dynamic_cast<ColumnVectorData<unsigned long>&
>(*this);
1304 unsigned long nullVal(0);
1305 unsigned long* pNullVal = 0;
1308 nullVal =
static_cast<unsigned long>(*nullValue);
1309 pNullVal = &nullVal;
1311 vector<valarray<unsigned long> > __tmp(n);
1312 for (
size_t i = 0; i < n; ++i)
1314 FITSUtil::fill(__tmp[i],indata[i]);
1316 col.writeData(__tmp,firstRow,pNullVal);
1327 template <
typename T>
1332 #ifdef SSTREAM_DEFECT
1333 std::ostrstream keyName;
1334 keyName <<
"TNULL" <<
index() << std::ends;
1335 char* nullKey =
const_cast<char*
>(keyName.str());
1337 std::ostringstream keyName;
1338 keyName <<
"TNULL" <<
index();
1339 String keyNameStr = keyName.str();
1340 char* nullKey =
const_cast<char*
>(keyNameStr.c_str());
1345 int dataType =
static_cast<int>(inputType());
1346 if (dataType == static_cast<int>(Tstring))
1352 if (fits_update_key(
fitsPointer(),dataType,nullKey,&nullVal,0,&status))
1362 template <
typename T>
1366 #ifdef SSTREAM_DEFECT
1367 std::ostrstream keyName;
1368 keyName <<
"TNULL" <<
index() << std::ends;
1369 char* nullKey =
const_cast<char*
>(keyName.str());
1371 std::ostringstream keyName;
1372 keyName <<
"TNULL" <<
index();
1373 String keyNameStr = keyName.str();
1374 char* nullKey =
const_cast<char*
>(keyNameStr.c_str());
1379 int dataType =
static_cast<int>(inputType());
1380 if (dataType == static_cast<int>(Tstring))
1384 bool keyExists =
false;
1385 if (fits_read_key(m_parent->
fitsPointer(), dataType, nullKey, &tmpVal, 0, &status))
1387 if (status == KEY_NO_EXIST || status == VALUE_UNDEFINED)