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