00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef COLUMNT_H
00013 #define COLUMNT_H
00014
00015 #ifdef _MSC_VER
00016 #include "MSconfig.h"
00017 #endif
00018
00019 #include "ColumnData.h"
00020 #include "ColumnVectorData.h"
00021 #include "FITSUtil.h"
00022 #include <typeinfo>
00023 #include <vector>
00024 #include <algorithm>
00025 #include "NewKeyword.h"
00026
00027 #ifdef SSTREAM_DEFECT
00028 # include <strstream>
00029 #else
00030 # include <sstream>
00031 #endif
00032
00033
00034
00035
00036 using std::complex;
00037 using std::valarray;
00038
00039
00040
00041
00042 namespace CCfits
00043 {
00044 template <typename S>
00045 void Column::read(std::vector<S>& vals, long first, long last)
00046 {
00047 read(vals,first,last,static_cast<S*>(0));
00048 }
00049
00050
00051 template <typename S>
00052 void Column::read(std::vector<S>& vals, long first, long last, S* nullValue)
00053 {
00054
00055
00056 parent()->makeThisCurrent();
00057 long nelements = numberOfElements(first,last);
00058
00059 if (ColumnData<S>* col = dynamic_cast<ColumnData<S>*>(this))
00060 {
00061
00062
00063
00064 if (!isRead()) col->readColumnData(first,nelements,nullValue);
00065
00066 FITSUtil::fill(vals,col->data(),first,last);
00067 }
00068 else
00069 {
00070 FITSUtil::MatchType<S> outputType;
00071 if ( outputType() == type() )
00072 {
00073
00074
00075
00076 throw Column::WrongColumnType(name());
00077 }
00078
00079 try
00080 {
00081
00082
00083
00084
00085
00086
00087 if ( type() == Tdouble )
00088 {
00089 ColumnData<double>& col
00090 = dynamic_cast<ColumnData<double>&>(*this);
00091 if (!isRead()) col.readColumnData(first,nelements);
00092 FITSUtil::fill(vals,col.data(),first,last);
00093
00094 }
00095 else if (type() == Tfloat)
00096 {
00097 ColumnData<float>& col
00098 = dynamic_cast<ColumnData<float>&>(*this);
00099 if (!isRead()) col.readColumnData(first,nelements);
00100 FITSUtil::fill(vals,col.data(),first,last);
00101 }
00102 else if (type() == Tint)
00103 {
00104 int nullVal(0);
00105 if (nullValue) nullVal = static_cast<int>(*nullValue);
00106 ColumnData<int>& col
00107 = dynamic_cast<ColumnData<int>&>(*this);
00108 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00109 FITSUtil::fill(vals,col.data(),first,last);
00110 }
00111 else if (type() == Tshort)
00112 {
00113 short nullVal(0);
00114 if (nullValue) nullVal = static_cast<short>(*nullValue);
00115 ColumnData<short>& col
00116 = dynamic_cast<ColumnData<short>&>(*this);
00117 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00118 FITSUtil::fill(vals,col.data(),first,last);
00119 }
00120 else if (type() == Tlong)
00121 {
00122 long nullVal(0);
00123 if (nullValue) nullVal = static_cast<long>(*nullValue);
00124 ColumnData<long>& col
00125 = dynamic_cast<ColumnData<long>&>(*this);
00126 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00127 FITSUtil::fill(vals,col.data(),first,last);
00128 }
00129 else if (type() == Tlonglong)
00130 {
00131 LONGLONG nullVal(0);
00132 if (nullValue) nullVal = static_cast<LONGLONG>(*nullValue);
00133 ColumnData<LONGLONG>& col
00134 = dynamic_cast<ColumnData<LONGLONG>&>(*this);
00135 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00136 FITSUtil::fill(vals,col.data(),first,last);
00137 }
00138 else if (type() == Tlogical)
00139 {
00140 bool nullVal(0);
00141 if (nullValue) nullVal = static_cast<bool>(*nullValue);
00142 ColumnData<bool>& col
00143 = dynamic_cast<ColumnData<bool>&>(*this);
00144 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00145 FITSUtil::fill(vals,col.data(),first,last);
00146 }
00147 else if (type() == Tbit || type() == Tbyte)
00148 {
00149 unsigned char nullVal(0);
00150 if (nullValue) nullVal = static_cast<unsigned char>(*nullValue);
00151 ColumnData<unsigned char>& col
00152 = dynamic_cast<ColumnData<unsigned char>&>(*this);
00153 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00154 FITSUtil::fill(vals,col.data(),first,last);
00155 }
00156 else if (type() == Tushort)
00157 {
00158 unsigned short nullVal(0);
00159 if (nullValue) nullVal= static_cast<unsigned short>(*nullValue);
00160 ColumnData<unsigned short>& col
00161 = dynamic_cast<ColumnData<unsigned short>&>(*this);
00162 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00163 FITSUtil::fill(vals,col.data(),first,last);
00164 }
00165 else if (type() == Tuint)
00166 {
00167 unsigned int nullVal(0);
00168 if (nullValue) nullVal = static_cast<unsigned int>(*nullValue);
00169 ColumnData<unsigned int>& col
00170 = dynamic_cast<ColumnData<unsigned int>&>(*this);
00171 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00172 FITSUtil::fill(vals,col.data(),first,last);
00173 }
00174 else if (type() == Tulong)
00175 {
00176 unsigned long nullVal(0);
00177 if (nullValue) nullVal = static_cast<unsigned long>(*nullValue);
00178 ColumnData<unsigned long>& col
00179 = dynamic_cast<ColumnData<unsigned long>&>(*this);
00180 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00181 FITSUtil::fill(vals,col.data(),first,last);
00182 }
00183 else
00184 {
00185 throw InvalidDataType(name());
00186
00187 }
00188
00189 }
00190 catch (std::bad_cast)
00191 {
00192 throw WrongColumnType(name());
00193 }
00194 }
00195
00196 }
00197
00198 template <typename S>
00199 void Column::read(std::valarray<S>& vals, long first, long last)
00200 {
00201 read(vals,first,last,static_cast<S*>(0));
00202 }
00203
00204
00205 template <typename S>
00206 void Column::read(std::valarray<S>& vals, long first, long last, S* nullValue)
00207 {
00208
00209
00210
00211 long nelements = numberOfElements(first,last);
00212 parent()->makeThisCurrent();
00213 if ( ColumnData<S>* col = dynamic_cast<ColumnData<S>*>(this))
00214 {
00215
00216
00217
00218 if (!isRead()) col->readColumnData(first,nelements,nullValue);
00219 FITSUtil::fill(vals,col->data(),first,last);
00220
00221 }
00222 else
00223 {
00224 FITSUtil::MatchType<S> outputType;
00225 if ( outputType() == type() )
00226 {
00227
00228
00229
00230 throw Column::WrongColumnType(name());
00231 }
00232
00233 try
00234 {
00235
00236
00237
00238
00239
00240
00241 if ( type() == Tdouble )
00242 {
00243 ColumnData<double>& col
00244 = dynamic_cast<ColumnData<double>&>(*this);
00245 if (!isRead()) col.readColumnData(first,nelements);
00246 FITSUtil::fill(vals,col.data(),first,last);
00247 }
00248 else if (type() == Tfloat)
00249 {
00250 ColumnData<float>& col
00251 = dynamic_cast<ColumnData<float>&>(*this);
00252 if (!isRead()) col.readColumnData(first,nelements);
00253 FITSUtil::fill(vals,col.data(),first,last);
00254 }
00255 else if (type() == Tint)
00256 {
00257 int nullVal(0);
00258 if (nullValue) nullVal = static_cast<int>(*nullValue);
00259 ColumnData<int>& col
00260 = dynamic_cast<ColumnData<int>&>(*this);
00261 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00262 FITSUtil::fill(vals,col.data(),first,last);
00263 }
00264 else if (type() == Tshort)
00265 {
00266 short nullVal(0);
00267 if (nullValue) nullVal = static_cast<short>(*nullValue);
00268 ColumnData<short>& col
00269 = dynamic_cast<ColumnData<short>&>(*this);
00270 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00271 FITSUtil::fill(vals,col.data(),first,last);
00272 }
00273 else if (type() == Tlong)
00274 {
00275 long nullVal(0);
00276 if (nullValue) nullVal = static_cast<long>(*nullValue);
00277 ColumnData<long>& col
00278 = dynamic_cast<ColumnData<long>&>(*this);
00279 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00280 FITSUtil::fill(vals,col.data(),first,last);
00281 }
00282 else if (type() == Tlonglong)
00283 {
00284 LONGLONG nullVal(0);
00285 if (nullValue) nullVal = static_cast<LONGLONG>(*nullValue);
00286 ColumnData<LONGLONG>& col
00287 = dynamic_cast<ColumnData<LONGLONG>&>(*this);
00288 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00289 FITSUtil::fill(vals,col.data(),first,last);
00290 }
00291 else if (type() == Tlogical)
00292 {
00293 bool nullVal(0);
00294 if (nullValue) nullVal = static_cast<bool>(*nullValue);
00295 ColumnData<bool>& col
00296 = dynamic_cast<ColumnData<bool>&>(*this);
00297 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00298 FITSUtil::fill(vals,col.data(),first,last);
00299 }
00300 else if (type() == Tbit || type() == Tbyte)
00301 {
00302 unsigned char nullVal(0);
00303 if (nullValue) nullVal = static_cast<unsigned char>(*nullValue);
00304 ColumnData<unsigned char>& col
00305 = dynamic_cast<ColumnData<unsigned char>&>(*this);
00306 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00307 FITSUtil::fill(vals,col.data(),first,last);
00308 }
00309 else if (type() == Tushort)
00310 {
00311 unsigned short nullVal(0);
00312 if (nullValue) nullVal
00313 = static_cast<unsigned short>(*nullValue);
00314 ColumnData<unsigned short>& col
00315 = dynamic_cast<ColumnData<unsigned short>&>(*this);
00316 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00317 FITSUtil::fill(vals,col.data(),first,last);
00318 }
00319 else if (type() == Tuint)
00320 {
00321 unsigned int nullVal(0);
00322 if (nullValue) nullVal
00323 = static_cast<unsigned int>(*nullValue);
00324 ColumnData<unsigned int>& col
00325 = dynamic_cast<ColumnData<unsigned int>&>(*this);
00326 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00327 FITSUtil::fill(vals,col.data(),first,last);
00328 }
00329 else if (type() == Tulong)
00330 {
00331 unsigned long nullVal(0);
00332 if (nullValue) nullVal
00333 = static_cast<unsigned long>(*nullValue);
00334 ColumnData<unsigned long>& col
00335 = dynamic_cast<ColumnData<unsigned long>&>(*this);
00336 if (!isRead()) col.readColumnData(first,nelements,&nullVal);
00337 FITSUtil::fill(vals,col.data(),first,last);
00338 }
00339 else
00340 {
00341 throw InvalidDataType(name());
00342
00343 }
00344
00345 }
00346 catch (std::bad_cast)
00347 {
00348 throw WrongColumnType(name());
00349 }
00350 }
00351
00352 }
00353
00354
00355
00356 template <typename S>
00357 void Column::read(std::valarray<S>& vals, long row)
00358 {
00359 read(vals,row,static_cast<S*>(0));
00360 }
00361
00362
00363 template <typename S>
00364 void Column::read(std::valarray<S>& vals, long row, S* nullValue)
00365 {
00366 if (row > parent()->rows())
00367 {
00368 throw Column::InvalidRowNumber(name());
00369 }
00370 parent()->makeThisCurrent();
00371
00372 if ( ColumnVectorData<S>* col = dynamic_cast<ColumnVectorData<S>*>(this))
00373 {
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 if (!isRead()) col->readRow(row,nullValue);
00385 FITSUtil::fill(vals,col->data(row));
00386 }
00387 else
00388 {
00389 FITSUtil::MatchType<S> outputType;
00390 if ( outputType() == type() )
00391 {
00392
00393
00394
00395
00396
00397 throw Column::WrongColumnType(name());
00398 }
00399
00400
00401 try
00402 {
00403
00404
00405
00406
00407
00408
00409 if ( type() == Tdouble || type() == VTdouble )
00410 {
00411 ColumnVectorData<double>& col
00412 = dynamic_cast<ColumnVectorData<double>&>(*this);
00413 if (!isRead()) col.readRow(row);
00414 FITSUtil::fill(vals,col.data(row));
00415
00416 }
00417 else if (type() == Tfloat || type() == VTfloat )
00418 {
00419 ColumnVectorData<float>& col
00420 = dynamic_cast<ColumnVectorData<float>&>(*this);
00421 if (!isRead()) col.readRow(row);
00422 FITSUtil::fill(vals,col.data(row));
00423 }
00424 else if (type() == Tint || type() == VTint )
00425 {
00426 int nullVal(0);
00427 if (nullValue) nullVal = static_cast<int>(*nullValue);
00428 ColumnVectorData<int>& col
00429 = dynamic_cast<ColumnVectorData<int>&>(*this);
00430 if (!isRead()) col.readRow(row,&nullVal);
00431 FITSUtil::fill(vals,col.data(row));
00432 }
00433 else if (type() == Tshort || type() == VTshort )
00434 {
00435 short nullVal(0);
00436 if (nullValue) nullVal = static_cast<short>(*nullValue);
00437 ColumnVectorData<short>& col
00438 = dynamic_cast<ColumnVectorData<short>&>(*this);
00439 if (!isRead()) col.readRow(row,&nullVal);
00440 FITSUtil::fill(vals,col.data(row));
00441 }
00442 else if (type() == Tlong || type() == VTlong )
00443 {
00444 long nullVal(0);
00445 if (nullValue) nullVal = static_cast<long>(*nullValue);
00446 ColumnVectorData<long>& col
00447 = dynamic_cast<ColumnVectorData<long>&>(*this);
00448 if (!isRead()) col.readRow(row,&nullVal);
00449 FITSUtil::fill(vals,col.data(row));
00450 }
00451 else if (type() == Tlonglong || type() == VTlonglong )
00452 {
00453 LONGLONG nullVal(0);
00454 if (nullValue) nullVal = static_cast<LONGLONG>(*nullValue);
00455 ColumnVectorData<LONGLONG>& col
00456 = dynamic_cast<ColumnVectorData<LONGLONG>&>(*this);
00457 if (!isRead()) col.readRow(row,&nullVal);
00458 FITSUtil::fill(vals,col.data(row));
00459 }
00460 else if (type() == Tlogical || type() == VTlogical )
00461 {
00462 bool nullVal(0);
00463 if (nullValue) nullVal = static_cast<bool>(*nullValue);
00464 ColumnVectorData<bool>& col
00465 = dynamic_cast<ColumnVectorData<bool>&>(*this);
00466 if (!isRead()) col.readRow(row,&nullVal);
00467 FITSUtil::fill(vals,col.data(row));
00468 }
00469 else if (type() == Tbit || type() == Tbyte ||
00470 type() == VTbit || type() == VTbyte )
00471 {
00472 unsigned char nullVal(0);
00473 if (nullValue) nullVal
00474 = static_cast<unsigned char>(*nullValue);
00475 ColumnVectorData<unsigned char>& col
00476 = dynamic_cast<ColumnVectorData<unsigned char>&>(*this);
00477 if (!isRead()) col.readRow(row,&nullVal);
00478 FITSUtil::fill(vals,col.data(row));
00479 }
00480 else if (type() == Tushort || type() == VTushort)
00481 {
00482 unsigned short nullVal(0);
00483 if (nullValue) nullVal
00484 = static_cast<unsigned short>(*nullValue);
00485 ColumnVectorData<unsigned short>& col
00486 = dynamic_cast<ColumnVectorData<unsigned short>&>(*this);
00487 if (!isRead()) col.readRow(row,&nullVal);
00488 FITSUtil::fill(vals,col.data(row));
00489 }
00490 else if (type() == Tuint || type() == VTuint)
00491 {
00492 unsigned int nullVal(0);
00493 if (nullValue) nullVal
00494 = static_cast<unsigned int>(*nullValue);
00495 ColumnVectorData<unsigned int>& col
00496 = dynamic_cast<ColumnVectorData<unsigned int>&>(*this);
00497 if (!isRead()) col.readRow(row,&nullVal);
00498 FITSUtil::fill(vals,col.data(row));
00499 }
00500 else if (type() == Tulong || type() == VTulong)
00501 {
00502 unsigned long nullVal(0);
00503 if (nullValue) nullVal
00504 = static_cast<unsigned long>(*nullValue);
00505 ColumnVectorData<unsigned long>& col
00506 = dynamic_cast<ColumnVectorData<unsigned long>&>(*this);
00507 if (!isRead()) col.readRow(row,&nullVal);
00508 FITSUtil::fill(vals,col.data(row));
00509 }
00510 else
00511 {
00512 throw InvalidDataType(name());
00513
00514 }
00515
00516 }
00517 catch (std::bad_cast)
00518 {
00519 throw WrongColumnType(name());
00520 }
00521 }
00522 }
00523
00524 template <typename S>
00525 void Column::readArrays(std::vector<std::valarray<S> >& vals, long first, long last)
00526 {
00527 readArrays(vals,first,last,static_cast<S*>(0));
00528 }
00529
00530 template <typename S>
00531 void Column::readArrays(std::vector<std::valarray<S> >& vals,
00532 long first, long last, S* nullValue)
00533 {
00534
00535 parent()->makeThisCurrent();
00536
00537
00538
00539 long range = numberOfElements(first,last);
00540
00541 vals.resize(range);
00542
00543
00544 if ( ColumnVectorData<S>* col = dynamic_cast<ColumnVectorData<S>*>(this))
00545 {
00546 for (int j = 0; j < range; ++j)
00547 {
00548 if (!isRead()) col->readRow(j + first,nullValue);
00549 FITSUtil::fill(vals[j],col->data(j+first));
00550 }
00551 }
00552 else
00553 {
00554 FITSUtil::MatchType<S> outputType;
00555 if ( outputType() == type() )
00556 {
00557
00558
00559
00560 throw Column::WrongColumnType(name());
00561 }
00562
00563 try
00564 {
00565 if ( type() == Tdouble || type() == VTdouble )
00566 {
00567 ColumnVectorData<double>& col
00568 = dynamic_cast<ColumnVectorData<double>&>(*this);
00569 for (int j = 0; j < range; ++j)
00570 {
00571 if (!isRead()) col.readRow(j + first);
00572 FITSUtil::fill(vals[j],col.data(j+first));
00573 }
00574 }
00575 else if ( type() == Tfloat || type() == VTfloat )
00576 {
00577 ColumnVectorData<float>& col
00578 = dynamic_cast<ColumnVectorData<float>&>(*this);
00579 for (int j = 0; j < range; ++j)
00580 {
00581 if (!isRead()) col.readRow(j + first);
00582 FITSUtil::fill(vals[j],col.data(j+first));
00583 }
00584 }
00585 else if ( type() == Tint || type() == VTint )
00586 {
00587 int nullVal(0);
00588 if (nullValue) nullVal = static_cast<int>(*nullValue);
00589 ColumnVectorData<int>& col
00590 = dynamic_cast<ColumnVectorData<int>&>(*this);
00591 for (int j = 0; j < range; ++j)
00592 {
00593 if (!isRead()) col.readRow(j + first,&nullVal);
00594 FITSUtil::fill(vals[j],col.data(j+first));
00595 }
00596 }
00597 else if ( type() == Tshort || type() == VTshort )
00598 {
00599 short nullVal(0);
00600 if (nullValue) nullVal = static_cast<short>(*nullValue);
00601 ColumnVectorData<short>& col
00602 = dynamic_cast<ColumnVectorData<short>&>(*this);
00603 for (int j = 0; j < range; ++j)
00604 {
00605 if (!isRead()) col.readRow(j + first,&nullVal);
00606 FITSUtil::fill(vals[j],col.data(j+first));
00607 }
00608 }
00609 else if ( type() == Tlong || type() == VTlong )
00610 {
00611 long nullVal(0);
00612 if (nullValue) nullVal = static_cast<long>(*nullValue);
00613 ColumnVectorData<long>& col
00614 = dynamic_cast<ColumnVectorData<long>&>(*this);
00615 for (int j = 0; j < range; ++j)
00616 {
00617 if (!isRead()) col.readRow(j + first,&nullVal);
00618 FITSUtil::fill(vals[j],col.data(j+first));
00619 }
00620 }
00621 else if ( type() == Tlonglong || type() == VTlonglong )
00622 {
00623 LONGLONG nullVal(0);
00624 if (nullValue) nullVal = static_cast<LONGLONG>(*nullValue);
00625 ColumnVectorData<LONGLONG>& col
00626 = dynamic_cast<ColumnVectorData<LONGLONG>&>(*this);
00627 for (int j = 0; j < range; ++j)
00628 {
00629 if (!isRead()) col.readRow(j + first,&nullVal);
00630 FITSUtil::fill(vals[j],col.data(j+first));
00631 }
00632 }
00633 else if ( type() == Tlogical || type() == VTlogical )
00634 {
00635 bool nullVal(0);
00636 if (nullValue) nullVal = static_cast<bool>(*nullValue);
00637 ColumnVectorData<bool>& col
00638 = dynamic_cast<ColumnVectorData<bool>&>(*this);
00639 for (int j = 0; j < range; ++j)
00640 {
00641 if (!isRead()) col.readRow(j + first,&nullVal);
00642 FITSUtil::fill(vals[j],col.data(j+first));
00643 }
00644 }
00645 else if (type() == Tbit || type() == Tbyte ||
00646 type() == VTbit || type() == VTbyte )
00647 {
00648 unsigned char nullVal(0);
00649 if (nullValue) nullVal
00650 = static_cast<unsigned char>(*nullValue);
00651 ColumnVectorData<unsigned char>& col
00652 = dynamic_cast<ColumnVectorData<unsigned char>&>(*this);
00653 for (int j = 0; j < range; ++j)
00654 {
00655 if (!isRead()) col.readRow(j + first,&nullVal);
00656 FITSUtil::fill(vals[j],col.data(j+first));
00657 }
00658 }
00659 else if ( type() == Tushort || type() == VTushort )
00660 {
00661 unsigned short nullVal(0);
00662 if (nullValue) nullVal
00663 = static_cast<unsigned short>(*nullValue);
00664 ColumnVectorData<unsigned short>& col
00665 = dynamic_cast<ColumnVectorData<unsigned short>&>(*this);
00666 for (int j = 0; j < range; ++j)
00667 {
00668 if (!isRead()) col.readRow(j + first,&nullVal);
00669 FITSUtil::fill(vals[j],col.data(j+first));
00670 }
00671 }
00672 else if ( type() == Tuint || type() == VTuint )
00673 {
00674 unsigned int nullVal(0);
00675 if (nullValue) nullVal
00676 = static_cast<unsigned int>(*nullValue);
00677 ColumnVectorData<unsigned int>& col
00678 = dynamic_cast<ColumnVectorData<unsigned int>&>(*this);
00679 for (int j = 0; j < range; ++j)
00680 {
00681 if (!isRead()) col.readRow(j + first,&nullVal);
00682 FITSUtil::fill(vals[j],col.data(j+first));
00683 }
00684 }
00685 else if ( type() == Tulong || type() == VTulong )
00686 {
00687 unsigned long nullVal(0);
00688 if (nullValue) nullVal
00689 = static_cast<unsigned long>(*nullValue);
00690 ColumnVectorData<unsigned long>& col
00691 = dynamic_cast<ColumnVectorData<unsigned long>&>(*this);
00692 for (int j = 0; j < range; ++j)
00693 {
00694 if (!isRead()) col.readRow(j + first,&nullVal);
00695 FITSUtil::fill(vals[j],col.data(j+first));
00696 }
00697 }
00698 else
00699 {
00700 throw InvalidDataType(name());
00701 }
00702
00703 }
00704 catch (std::bad_cast)
00705 {
00706 throw WrongColumnType(name());
00707
00708 }
00709
00710 }
00711 }
00712
00713 template <typename S>
00714 void Column::write (const std::vector<S>& indata, long firstRow)
00715 {
00716
00717
00718
00719 write(indata,firstRow,static_cast<S*>(0));
00720 }
00721
00722 template <typename S>
00723 void Column::write (const std::valarray<S>& indata, long firstRow)
00724 {
00725 size_t n(indata.size());
00726 std::vector<S> __tmp(n);
00727 for (size_t j = 0; j < n; ++j) __tmp[j] = indata[j];
00728 write(__tmp,firstRow,static_cast<S*>(0));
00729 }
00730
00731 template <typename S>
00732 void Column::write (S* indata, long nRows, long firstRow)
00733 {
00734 write(indata,nRows,firstRow,static_cast<S*>(0));
00735 }
00736
00737
00738 template <typename S>
00739 void Column::write (const std::vector<S>& indata, long firstRow, S* nullValue)
00740 {
00741
00742
00743
00744
00745
00746
00747
00748 parent()->makeThisCurrent();
00749 firstRow = std::max(firstRow,static_cast<long>(1));
00750 if (ColumnData<S>* col = dynamic_cast<ColumnData<S>*>(this))
00751 {
00752 col->writeData(indata,firstRow,nullValue);
00753 }
00754 else
00755 {
00756
00757
00758 FITSUtil::MatchType<S> inType;
00759 if ( inType() == type())
00760 {
00761 String msg("Incorrect call: writing to vector column ");
00762 msg += name();
00763 msg += " requires specification of # rows or vector lengths";
00764 throw WrongColumnType(msg);
00765 }
00766 else
00767 {
00768 if ( type() == Tdouble )
00769 {
00770 ColumnData<double>& col
00771 = dynamic_cast<ColumnData<double>&>(*this);
00772 std::vector<double> __tmp;
00773 FITSUtil::fill(__tmp,indata,1,indata.size());
00774 col.writeData(__tmp,firstRow);
00775 }
00776 else if ( type() == Tfloat )
00777 {
00778 ColumnData<float>& col
00779 = dynamic_cast<ColumnData<float>&>(*this);
00780 std::vector<float> __tmp;
00781 FITSUtil::fill(__tmp,indata,1,indata.size());
00782 col.writeData(__tmp,firstRow);
00783 }
00784 else if ( type() == Tint )
00785 {
00786 int nullVal(0);
00787 if (nullValue) nullVal = static_cast<int>(*nullValue);
00788 ColumnData<int>& col
00789 = dynamic_cast<ColumnData<int>&>(*this);
00790 std::vector<int> __tmp;
00791 FITSUtil::fill(__tmp,indata,1,indata.size());
00792 col.writeData(__tmp,firstRow,&nullVal);
00793 }
00794 else if ( type() == Tshort )
00795 {
00796 short nullVal(0);
00797 if (nullValue) nullVal = static_cast<short>(*nullValue);
00798 ColumnData<short>& col
00799 = dynamic_cast<ColumnData<short>&>(*this);
00800 std::vector<short> __tmp;
00801 FITSUtil::fill(__tmp,indata,1,indata.size());
00802 col.writeData(__tmp,firstRow,&nullVal);
00803 }
00804 else if ( type() == Tlong )
00805 {
00806 long nullVal(0);
00807 if (nullValue) nullVal = static_cast<long>(*nullValue);
00808 ColumnData<long>& col
00809 = dynamic_cast<ColumnData<long>&>(*this);
00810 std::vector<long> __tmp;
00811 FITSUtil::fill(__tmp,indata,1,indata.size());
00812 col.writeData(__tmp,firstRow,&nullVal);
00813 }
00814 else if ( type() == Tlonglong )
00815 {
00816 LONGLONG nullVal(0);
00817 if (nullValue) nullVal = static_cast<LONGLONG>(*nullValue);
00818 ColumnData<LONGLONG>& col
00819 = dynamic_cast<ColumnData<LONGLONG>&>(*this);
00820 std::vector<LONGLONG> __tmp;
00821 FITSUtil::fill(__tmp,indata,1,indata.size());
00822 col.writeData(__tmp,firstRow,&nullVal);
00823 }
00824 else if ( type() == Tlogical )
00825 {
00826 bool nullVal(0);
00827 if (nullValue) nullVal = static_cast<bool>(*nullValue);
00828 ColumnData<bool>& col
00829 = dynamic_cast<ColumnData<bool>&>(*this);
00830 std::vector<bool> __tmp;
00831 FITSUtil::fill(__tmp,indata,1,indata.size());
00832 col.writeData(__tmp,firstRow,&nullVal);
00833 }
00834 else if ( type() == Tbyte )
00835 {
00836 unsigned char nullVal(0);
00837 if (nullValue) nullVal = static_cast<unsigned char>(*nullValue);
00838 ColumnData<unsigned char>& col
00839 = dynamic_cast<ColumnData<unsigned char>&>(*this);
00840 std::vector<unsigned char> __tmp;
00841 FITSUtil::fill(__tmp,indata,1,indata.size());
00842 col.writeData(__tmp,firstRow,&nullVal);
00843 }
00844 else if ( type() == Tushort )
00845 {
00846 unsigned short nullVal(0);
00847 if (nullValue) nullVal = static_cast<unsigned short>(*nullValue);
00848 ColumnData<unsigned short>& col
00849 = dynamic_cast<ColumnData<unsigned short>&>(*this);
00850 std::vector<unsigned short> __tmp;
00851 FITSUtil::fill(__tmp,indata,1,indata.size());
00852 col.writeData(__tmp,firstRow,&nullVal);
00853 }
00854 else if ( type() == Tuint )
00855 {
00856 unsigned int nullVal(0);
00857 if (nullValue) nullVal = static_cast<unsigned int>(*nullValue);
00858 ColumnData<unsigned int>& col
00859 = dynamic_cast<ColumnData<unsigned int>&>(*this);
00860 std::vector<unsigned int> __tmp;
00861 FITSUtil::fill(__tmp,indata,1,indata.size());
00862 col.writeData(__tmp,firstRow,&nullVal);
00863 }
00864 else if ( type() == Tulong )
00865 {
00866 unsigned long nullVal(0);
00867 if (nullValue) nullVal = static_cast<unsigned long>(*nullValue);
00868 ColumnData<unsigned long>& col
00869 = dynamic_cast<ColumnData<unsigned long>&>(*this);
00870 std::vector<unsigned long> __tmp;
00871 FITSUtil::fill(__tmp,indata,1,indata.size());
00872 col.writeData(__tmp,firstRow,&nullVal);
00873 }
00874 else
00875 {
00876 throw InvalidDataType(name());
00877 }
00878 }
00879 }
00880 }
00881
00882
00883 template <typename S>
00884 void Column::write (const std::valarray<S>& indata, long firstRow, S* nullValue)
00885 {
00886
00887 std::vector<S> __tmp;
00888 FITSUtil::fill(__tmp,indata);
00889 write(__tmp,firstRow,nullValue);
00890 }
00891
00892 template <typename S>
00893 void Column::write (S* indata, long nRows, long firstRow, S* nullValue)
00894 {
00895
00896 if (nRows <= 0) throw InvalidNumberOfRows(nRows);
00897 std::vector<S> __tmp(nRows);
00898 std::copy(&indata[0],&indata[nRows],__tmp.begin());
00899 write(__tmp,firstRow, nullValue);
00900
00901 }
00902
00903 template <typename S>
00904 void Column::write (const std::valarray<S>& indata, const std::vector<long>& vectorLengths,
00905 long firstRow)
00906 {
00907
00908
00909
00910 using std::valarray;
00911 parent()->makeThisCurrent();
00912 firstRow = std::max(firstRow,static_cast<long>(1));
00913 if (ColumnVectorData<S>* col = dynamic_cast<ColumnVectorData<S>*>(this))
00914 {
00915 col->writeData(indata,vectorLengths,firstRow);
00916 }
00917 else
00918 {
00919
00920
00921 FITSUtil::MatchType<S> inType;
00922 if ( inType() == type())
00923 {
00924 String msg("Incorrect call: scalar column ");
00925 msg += name();
00926 msg += " does not have vector lengths";
00927 throw WrongColumnType(msg);
00928 }
00929 else
00930 {
00931 if ( type() == Tdouble )
00932 {
00933 ColumnVectorData<double>& col
00934 = dynamic_cast<ColumnVectorData<double>&>(*this);
00935 valarray<double> __tmp;
00936 FITSUtil::fill(__tmp,indata);
00937 col.writeData(__tmp,vectorLengths,firstRow);
00938 }
00939 else if ( type() == Tfloat )
00940 {
00941 ColumnVectorData<float>& col
00942 = dynamic_cast<ColumnVectorData<float>&>(*this);
00943 valarray<float> __tmp;
00944 FITSUtil::fill(__tmp,indata);
00945 col.writeData(__tmp,vectorLengths,firstRow);
00946 }
00947 else if ( type() == Tint )
00948 {
00949 ColumnVectorData<int>& col
00950 = dynamic_cast<ColumnVectorData<int>&>(*this);
00951 valarray<int> __tmp;
00952 FITSUtil::fill(__tmp,indata);
00953 col.writeData(__tmp,vectorLengths,firstRow);
00954 }
00955 else if ( type() == Tshort )
00956 {
00957 ColumnVectorData<short>& col
00958 = dynamic_cast<ColumnVectorData<short>&>(*this);
00959 valarray<short> __tmp;
00960 FITSUtil::fill(__tmp,indata);
00961 col.writeData(__tmp,vectorLengths,firstRow);
00962 }
00963 else if ( type() == Tlong )
00964 {
00965 ColumnVectorData<long>& col
00966 = dynamic_cast<ColumnVectorData<long>&>(*this);
00967 valarray<long> __tmp;
00968 FITSUtil::fill(__tmp,indata);
00969 col.writeData(__tmp,vectorLengths,firstRow);
00970 }
00971 else if ( type() == Tlonglong )
00972 {
00973 ColumnVectorData<LONGLONG>& col
00974 = dynamic_cast<ColumnVectorData<LONGLONG>&>(*this);
00975 valarray<LONGLONG> __tmp;
00976 FITSUtil::fill(__tmp,indata);
00977 col.writeData(__tmp,vectorLengths,firstRow);
00978 }
00979 else if ( type() == Tlogical )
00980 {
00981 ColumnVectorData<bool>& col
00982 = dynamic_cast<ColumnVectorData<bool>&>(*this);
00983 valarray<bool> __tmp;
00984 FITSUtil::fill(__tmp,indata);
00985 col.writeData(__tmp,vectorLengths,firstRow);
00986 }
00987 else if ( type() == Tbyte )
00988 {
00989 ColumnVectorData<unsigned char>& col
00990 = dynamic_cast<ColumnVectorData<unsigned char>&>(*this);
00991 valarray<unsigned char> __tmp;
00992 FITSUtil::fill(__tmp,indata);
00993 col.writeData(__tmp,firstRow);
00994 }
00995 else if ( type() == Tushort )
00996 {
00997 ColumnVectorData<unsigned short>& col
00998 = dynamic_cast<ColumnVectorData<unsigned short>&>(*this);
00999 valarray<unsigned short> __tmp;
01000 FITSUtil::fill(__tmp,indata);
01001 col.writeData(__tmp,vectorLengths,firstRow);
01002 }
01003 else if ( type() == Tuint )
01004 {
01005 ColumnVectorData<unsigned int>& col
01006 = dynamic_cast<ColumnVectorData<unsigned int>&>(*this);
01007 valarray<unsigned int> __tmp;
01008 FITSUtil::fill(__tmp,indata);
01009 col.writeData(__tmp,vectorLengths,firstRow);
01010 }
01011 else if ( type() == Tulong )
01012 {
01013 ColumnVectorData<unsigned long>& col
01014 = dynamic_cast<ColumnVectorData<unsigned long>&>(*this);
01015 valarray<unsigned long> __tmp;
01016 FITSUtil::fill(__tmp,indata);
01017 col.writeData(__tmp,vectorLengths,firstRow);
01018 }
01019 else
01020 {
01021 throw InvalidDataType(name());
01022 }
01023 }
01024 }
01025 }
01026
01027 template <typename S>
01028 void Column::write (const std::vector<S>& indata,const std::vector<long>& vectorLengths,
01029 long firstRow)
01030 {
01031
01032
01033 std::valarray<S> __tmp(indata.size());
01034 std::copy(indata.begin(),indata.end(),&__tmp[0]);
01035 write(__tmp,vectorLengths,firstRow);
01036
01037 }
01038
01039 template <typename S>
01040 void Column::write (S* indata, long nelements, const std::vector<long>& vectorLengths,
01041 long firstRow)
01042 {
01043
01044 size_t n(vectorLengths.size());
01045 std::valarray<S> __tmp(indata,nelements);
01046 write(__tmp,vectorLengths,firstRow);
01047 }
01048
01049 template <typename S>
01050 void Column::write (const std::valarray<S>& indata, long nRows, long firstRow)
01051 {
01052 write(indata,nRows,firstRow,static_cast<S*>(0));
01053 }
01054
01055 template <typename S>
01056 void Column::write (const std::vector<S>& indata, long nRows, long firstRow)
01057 {
01058 write(indata,nRows,firstRow,static_cast<S*>(0));
01059 }
01060
01061 template <typename S>
01062 void Column::write (S* indata, long nelements, long nRows, long firstRow)
01063 {
01064 write(indata,nelements,nRows,firstRow,static_cast<S*>(0));
01065 }
01066
01067
01068
01069 template <typename S>
01070 void Column::write (const std::valarray<S>& indata, long nRows, long firstRow,
01071 S* nullValue)
01072 {
01073
01074
01075 if (nRows <= 0) throw InvalidNumberOfRows(nRows);
01076 parent()->makeThisCurrent();
01077 firstRow = std::max(firstRow,static_cast<long>(1));
01078 if (ColumnVectorData<S>* col = dynamic_cast<ColumnVectorData<S>*>(this))
01079 {
01080 col->writeData(indata,nRows,firstRow,nullValue);
01081 }
01082 else
01083 {
01084
01085
01086 FITSUtil::MatchType<S> inType;
01087 if ( inType() == type())
01088 {
01089 String
01090 msg("Incorrect call: writing to valarray data to scalar column: ");
01091 msg += name();
01092 msg += " does not require specification of number of rows";
01093 throw WrongColumnType(msg);
01094 }
01095 else
01096 {
01097 if ( type() == Tdouble )
01098 {
01099 ColumnVectorData<double>& col
01100 = dynamic_cast<ColumnVectorData<double>&>(*this);
01101 std::valarray<double> __tmp;
01102 FITSUtil::fill(__tmp,indata);
01103 col.writeData(__tmp,nRows,firstRow);
01104 }
01105 else if ( type() == Tfloat )
01106 {
01107 ColumnVectorData<float>& col
01108 = dynamic_cast<ColumnVectorData<float>&>(*this);
01109 std::valarray<float> __tmp;
01110 FITSUtil::fill(__tmp,indata);
01111 col.writeData(__tmp,nRows,firstRow);
01112 }
01113 else if ( type() == Tint )
01114 {
01115 int nullVal(0);
01116 if (nullValue) nullVal = static_cast<int>(*nullValue);
01117 ColumnVectorData<int>& col
01118 = dynamic_cast<ColumnVectorData<int>&>(*this);
01119 std::valarray<int> __tmp;
01120 FITSUtil::fill(__tmp,indata);
01121 col.writeData(__tmp,nRows,firstRow,&nullVal);
01122 }
01123 else if ( type() == Tshort )
01124 {
01125 short nullVal(0);
01126 if (nullValue) nullVal = static_cast<short>(*nullValue);
01127 ColumnVectorData<short>& col
01128 = dynamic_cast<ColumnVectorData<short>&>(*this);
01129 std::valarray<short> __tmp;
01130 FITSUtil::fill(__tmp,indata);
01131 col.writeData(__tmp,nRows,firstRow,&nullVal);
01132 }
01133 else if ( type() == Tlong )
01134 {
01135 long nullVal(0);
01136 if (nullValue) nullVal = static_cast<long>(*nullValue);
01137 ColumnVectorData<long>& col
01138 = dynamic_cast<ColumnVectorData<long>&>(*this);
01139 std::valarray<long> __tmp;
01140 FITSUtil::fill(__tmp,indata);
01141 col.writeData(__tmp,nRows,firstRow,&nullVal);
01142 }
01143 else if ( type() == Tlonglong )
01144 {
01145 LONGLONG nullVal(0);
01146 if (nullValue) nullVal = static_cast<LONGLONG>(*nullValue);
01147 ColumnVectorData<LONGLONG>& col
01148 = dynamic_cast<ColumnVectorData<LONGLONG>&>(*this);
01149 std::valarray<LONGLONG> __tmp;
01150 FITSUtil::fill(__tmp,indata);
01151 col.writeData(__tmp,nRows,firstRow,&nullVal);
01152 }
01153 else if ( type() == Tlogical )
01154 {
01155 bool nullVal(0);
01156 if (nullValue) nullVal = static_cast<bool>(*nullValue);
01157 ColumnVectorData<bool>& col
01158 = dynamic_cast<ColumnVectorData<bool>&>(*this);
01159 std::valarray<bool> __tmp;
01160 FITSUtil::fill(__tmp,indata);
01161 col.writeData(__tmp,nRows,firstRow,&nullVal);
01162 }
01163 else if ( type() == Tbyte )
01164 {
01165 unsigned char nullVal(0);
01166 if (nullValue) nullVal = static_cast<unsigned char>(*nullValue);
01167 ColumnVectorData<unsigned char>& col
01168 = dynamic_cast<ColumnVectorData<unsigned char>&>(*this);
01169 std::valarray<unsigned char> __tmp;
01170 FITSUtil::fill(__tmp,indata);
01171 col.writeData(__tmp,nRows,firstRow,&nullVal);
01172 }
01173 else if ( type() == Tushort )
01174 {
01175 unsigned short nullVal(0);
01176 if (nullValue) nullVal = static_cast<unsigned short>(*nullValue);
01177 ColumnVectorData<unsigned short>& col
01178 = dynamic_cast<ColumnVectorData<unsigned short>&>(*this);
01179 std::valarray<unsigned short> __tmp;
01180 FITSUtil::fill(__tmp,indata);
01181 col.writeData(__tmp,nRows,firstRow,&nullVal);
01182 }
01183 else if ( type() == Tuint )
01184 {
01185 unsigned int nullVal(0);
01186 if (nullValue) nullVal = static_cast<unsigned int>(*nullValue);
01187 ColumnVectorData<unsigned int>& col
01188 = dynamic_cast<ColumnVectorData<unsigned int>&>(*this);
01189 std::valarray<unsigned int> __tmp;
01190 FITSUtil::fill(__tmp,indata);
01191 col.writeData(__tmp,nRows,firstRow,&nullVal);
01192 }
01193 else if ( type() == Tulong )
01194 {
01195 unsigned long nullVal(0);
01196 if (nullValue) nullVal = static_cast<unsigned long>(*nullValue);
01197 ColumnVectorData<unsigned long>& col
01198 = dynamic_cast<ColumnVectorData<unsigned long>&>(*this);
01199 std::valarray<unsigned long> __tmp;
01200 FITSUtil::fill(__tmp,indata);
01201 col.writeData(__tmp,nRows,firstRow,&nullVal);
01202 }
01203 else
01204 {
01205 throw InvalidDataType(name());
01206 }
01207 }
01208 }
01209 }
01210
01211 template <typename S>
01212 void Column::write (const std::vector<S>& indata, long nRows, long firstRow, S* nullValue)
01213 {
01214
01215
01216 if (nRows <= 0) throw InvalidNumberOfRows(nRows);
01217 std::valarray<S> __tmp(indata.size());
01218 std::copy(indata.begin(),indata.end(),&__tmp[0]);
01219 write(__tmp,nRows,firstRow, nullValue);
01220 }
01221
01222 template <typename S>
01223 void Column::write (S* indata, long nelements, long nRows, long firstRow, S* nullValue)
01224 {
01225
01226
01227 if (nRows <= 0) throw InvalidNumberOfRows(nRows);
01228 std::valarray<S> __tmp(indata,nelements);
01229 write(__tmp,nRows,firstRow, nullValue);
01230 }
01231
01232
01233 template <typename S>
01234 void Column::writeArrays (const std::vector<std::valarray<S> >& indata, long firstRow)
01235 {
01236
01237 writeArrays(indata,firstRow,static_cast<S*>(0));
01238 }
01239
01240 template <typename S>
01241 void Column::writeArrays (const std::vector<std::valarray<S> >& indata, long firstRow,
01242 S* nullValue)
01243 {
01244
01245
01246
01247 using std::valarray;
01248 using std::vector;
01249 parent()->makeThisCurrent();
01250 firstRow = std::max(firstRow,static_cast<long>(1));
01251 if (ColumnVectorData<S>* col = dynamic_cast<ColumnVectorData<S>*>(this))
01252 {
01253 col->writeData(indata,firstRow,nullValue);
01254 }
01255 else
01256 {
01257
01258
01259 FITSUtil::MatchType<S> inType;
01260 if ( inType() == type())
01261 {
01262 String msg("Incorrect call: writing vectors to scalar column ");
01263 throw WrongColumnType(msg);
01264 }
01265 else
01266 {
01267 size_t n(indata.size());
01268 if ( type() == Tdouble )
01269 {
01270 ColumnVectorData<double>& col
01271 = dynamic_cast<ColumnVectorData<double>&>(*this);
01272 vector<valarray<double> > __tmp(n);
01273 for (size_t i = 0; i < n; ++i)
01274 {
01275 FITSUtil::fill(__tmp[i],indata[i]);
01276 }
01277 col.writeData(__tmp,firstRow);
01278 }
01279 else if ( type() == Tfloat )
01280 {
01281 ColumnVectorData<float>& col
01282 = dynamic_cast<ColumnVectorData<float>&>(*this);
01283 vector<valarray<float> > __tmp(n);
01284 for (size_t i = 0; i < n; ++i)
01285 {
01286 FITSUtil::fill(__tmp[i],indata[i]);
01287 }
01288 col.writeData(__tmp,firstRow);
01289 }
01290 else if ( type() == Tint )
01291 {
01292 ColumnVectorData<int>& col
01293 = dynamic_cast<ColumnVectorData<int>&>(*this);
01294 vector<valarray<int> > __tmp(n);
01295 int nullVal(0);
01296 if (nullValue) nullVal = static_cast<int>(*nullValue);
01297 for (size_t i = 0; i < n; ++i)
01298 {
01299 FITSUtil::fill(__tmp[i],indata[i]);
01300 }
01301 col.writeData(__tmp,firstRow,&nullVal);
01302 }
01303 else if ( type() == Tshort )
01304 {
01305 ColumnVectorData<short>& col
01306 = dynamic_cast<ColumnVectorData<short>&>(*this);
01307 vector<valarray<short> > __tmp(n);
01308 short nullVal(0);
01309 if (nullValue) nullVal = static_cast<short>(*nullValue);
01310 for (size_t i = 0; i < n; ++i)
01311 {
01312 FITSUtil::fill(__tmp[i],indata[i]);
01313 }
01314 col.writeData(__tmp,firstRow,&nullVal);
01315 }
01316 else if ( type() == Tlong )
01317 {
01318 ColumnVectorData<long>& col
01319 = dynamic_cast<ColumnVectorData<long>&>(*this);
01320 vector<valarray<long> > __tmp(n);
01321 long nullVal(0);
01322 if (nullValue) nullVal = static_cast<long>(*nullValue);
01323 for (size_t i = 0; i < n; ++i)
01324 {
01325 FITSUtil::fill(__tmp[i],indata[i]);
01326 }
01327 col.writeData(__tmp,firstRow,&nullVal);
01328 }
01329 else if ( type() == Tlonglong )
01330 {
01331 ColumnVectorData<LONGLONG>& col
01332 = dynamic_cast<ColumnVectorData<LONGLONG>&>(*this);
01333 vector<valarray<LONGLONG> > __tmp(n);
01334 LONGLONG nullVal(0);
01335 if (nullValue) nullVal = static_cast<LONGLONG>(*nullValue);
01336 for (size_t i = 0; i < n; ++i)
01337 {
01338 FITSUtil::fill(__tmp[i],indata[i]);
01339 }
01340 col.writeData(__tmp,firstRow,&nullVal);
01341 }
01342 else if ( type() == Tlogical )
01343 {
01344 ColumnVectorData<bool>& col
01345 = dynamic_cast<ColumnVectorData<bool>&>(*this);
01346 bool nullVal(0);
01347 if (nullValue) nullVal = static_cast<bool>(*nullValue);
01348 vector<valarray<bool> > __tmp(n);
01349 for (size_t i = 0; i < n; ++i)
01350 {
01351 FITSUtil::fill(__tmp[i],indata[i]);
01352 }
01353 col.writeData(__tmp,firstRow,&nullVal);
01354 }
01355 else if ( type() == Tbyte )
01356 {
01357 ColumnVectorData<unsigned char>& col
01358 = dynamic_cast<ColumnVectorData<unsigned char>&>(*this);
01359 unsigned char nullVal(0);
01360 if (nullValue) nullVal = static_cast<unsigned char>(*nullValue);
01361 vector<valarray<unsigned char> > __tmp(n);
01362 for (size_t i = 0; i < n; ++i)
01363 {
01364 FITSUtil::fill(__tmp[i],indata[i]);
01365 }
01366 col.writeData(__tmp,firstRow,&nullVal);
01367 }
01368 else if ( type() == Tushort )
01369 {
01370 ColumnVectorData<unsigned short>& col
01371 = dynamic_cast<ColumnVectorData<unsigned short>&>(*this);
01372 unsigned short nullVal(0);
01373 if (nullValue) nullVal = static_cast<unsigned short>(*nullValue);
01374 vector<valarray<unsigned short> > __tmp(n);
01375 for (size_t i = 0; i < n; ++i)
01376 {
01377 FITSUtil::fill(__tmp[i],indata[i]);
01378 }
01379 col.writeData(__tmp,firstRow,&nullVal);
01380 }
01381 else if ( type() == Tuint )
01382 {
01383 ColumnVectorData<unsigned int>& col
01384 = dynamic_cast<ColumnVectorData<unsigned int>&>(*this);
01385 unsigned int nullVal(0);
01386 if (nullValue) nullVal = static_cast<unsigned int>(*nullValue);
01387 vector<valarray<unsigned int> > __tmp(n);
01388 for (size_t i = 0; i < n; ++i)
01389 {
01390 FITSUtil::fill(__tmp[i],indata[i]);
01391 }
01392 col.writeData(__tmp,firstRow,&nullVal);
01393 }
01394 else if ( type() == Tulong )
01395 {
01396 ColumnVectorData<unsigned long>& col
01397 = dynamic_cast<ColumnVectorData<unsigned long>&>(*this);
01398 unsigned long nullVal(0);
01399 if (nullValue) nullVal = static_cast<unsigned long>(*nullValue);
01400 vector<valarray<unsigned long> > __tmp(n);
01401 for (size_t i = 0; i < n; ++i)
01402 {
01403 FITSUtil::fill(__tmp[i],indata[i]);
01404 }
01405 col.writeData(__tmp,firstRow,&nullVal);
01406 }
01407 else
01408 {
01409 throw InvalidDataType(name());
01410 }
01411 }
01412 }
01413 }
01414
01415
01416 template <typename T>
01417 void Column::addNullValue(T nullVal)
01418 {
01419 parent()->makeThisCurrent();
01420 int status(0);
01421 #ifdef SSTREAM_DEFECT
01422 std::ostrstream keyName;
01423 keyName << "TNULL" << index() << std::ends;
01424 char* nullKey = const_cast<char*>(keyName.str());
01425 #else
01426 std::ostringstream keyName;
01427 keyName << "TNULL" << index();
01428 char* nullKey = const_cast<char*>(keyName.str().c_str());
01429 #endif
01430
01431
01432 FITSUtil::MatchType<T> type;
01433
01434 T dataType(type());
01435
01436
01437
01438 if (fits_update_key(fitsPointer(),dataType,nullKey,&nullVal,0,&status))
01439 throw FitsError(status);
01440
01441 if (fits_set_hdustruc(fitsPointer(),&status)) throw FitsError(status);
01442
01443
01444 if (ColumnVectorData<T>* col = dynamic_cast<ColumnVectorData<T>*>(this))
01445 {
01446
01447 col->nullValue(nullVal);
01448 }
01449 else
01450 {
01451 try
01452 {
01453 ColumnData<T>& col
01454 = dynamic_cast<ColumnData<T>&>(*this);
01455 col.nullValue(nullVal);
01456 }
01457 catch (std::bad_cast)
01458 {
01459 throw InvalidDataType(" setting null value for column ");
01460 }
01461 }
01462
01463 }
01464 }
01465
01466 #endif