22 long nElements(std::accumulate(
naxes().begin(),
naxes().end(),init,
23 std::multiplies<long>()));
24 read(image,1,nElements,
static_cast<S*
>(0));
32 void ExtHDU::read (std::valarray<S>& image,
long first,
long nElements)
35 read(image, first,nElements,
static_cast<S*
>(0));
39 void ExtHDU::read (std::valarray<S>& image,
long first,
long nElements, S* nulValue)
43 if ( ImageExt<S>* extimage =
dynamic_cast<ImageExt<S>*
>(
this))
46 const std::valarray<S>& __tmp =
47 extimage->readImage(first,nElements,nulValue);
48 image.resize(__tmp.size());
55 ImageExt<float>& extimage
56 =
dynamic_cast<ImageExt<float>&
>(*this);
58 if (nulValue) nulVal =
static_cast<float>(*nulValue);
59 FITSUtil::fill(image,extimage.readImage(first,nElements, &nulVal));
61 else if (
bitpix() == Idouble)
63 ImageExt<double>& extimage
64 =
dynamic_cast<ImageExt<double>&
>(*this);
66 if (nulValue) nulVal =
static_cast<double>(*nulValue);
67 FITSUtil::fill(image,extimage.readImage(first,nElements, &nulVal));
69 else if (
bitpix() == Ibyte)
71 ImageExt<unsigned char>& extimage
72 =
dynamic_cast<ImageExt<unsigned char>&
>(*this);
73 unsigned char nulVal(0);
74 if (nulValue) nulVal =
static_cast<unsigned char>(*nulValue);
75 FITSUtil::fill(image,extimage.readImage(first,nElements, &nulVal));
77 else if (
bitpix() == Ilong)
81 ImageExt<unsigned INT32BIT>& extimage
82 =
dynamic_cast<ImageExt<unsigned INT32BIT>&
>(*this);
83 unsigned INT32BIT nulVal(0);
85 =
static_cast<unsigned INT32BIT
>(*nulValue);
86 FITSUtil::fill(image,extimage.readImage(first,nElements, &nulVal));
90 ImageExt<INT32BIT>& extimage
91 =
dynamic_cast<ImageExt<INT32BIT>&
>(*this);
93 if (nulValue) nulVal =
static_cast<INT32BIT
>(*nulValue);
94 FITSUtil::fill(image,extimage.readImage(first,nElements, &nulVal));
97 else if (
bitpix() == Ilonglong)
99 ImageExt<LONGLONG>& extimage
100 =
dynamic_cast<ImageExt<LONGLONG>&
>(*this);
102 if (nulValue) nulVal =
static_cast<LONGLONG
>(*nulValue);
103 FITSUtil::fill(image,extimage.readImage(first,nElements, &nulVal));
105 else if (
bitpix() == Ishort)
109 ImageExt<unsigned short>& extimage
110 =
dynamic_cast<ImageExt<unsigned short>&
>(*this);
111 unsigned short nulVal(0);
113 =
static_cast<unsigned short>(*nulValue);
114 FITSUtil::fill(image,extimage.readImage(first,nElements, &nulVal));
118 ImageExt<short>& extimage
119 =
dynamic_cast<ImageExt<short>&
>(*this);
121 if (nulValue) nulVal =
static_cast<short>(*nulValue);
122 FITSUtil::fill(image,extimage.readImage(first,nElements, &nulVal));
134 void ExtHDU::read (std::valarray<S>& image,
const std::vector<long>& first,
139 long firstElement(0);
141 std::vector<long> inputDimensions(naxis(),1);
142 size_t sNaxis =
static_cast<size_t>(naxis());
143 size_t n(std::min(sNaxis,first.size()));
144 std::copy(&first[0],&first[0]+n,&inputDimensions[0]);
145 for (
long i = 0; i < naxis(); ++i)
148 firstElement += ((inputDimensions[i] - 1)*dimSize);
154 read(image, firstElement,nElements,nulValue);
161 void ExtHDU::read (std::valarray<S>& image,
const std::vector<long>& first,
165 read(image, first,nElements,
static_cast<S*
>(0));
170 void ExtHDU::read (std::valarray<S>& image,
const std::vector<long>& firstVertex,
171 const std::vector<long>& lastVertex,
172 const std::vector<long>& stride,
176 if (ImageExt<S>* extimage =
dynamic_cast<ImageExt<S>*
>(
this))
178 const std::valarray<S>& __tmp =
179 extimage->readImage(firstVertex,lastVertex,stride,nulValue);
180 image.resize(__tmp.size());
189 if (nulValue) nulVal =
static_cast<float>(*nulValue);
190 ImageExt<float>& extimage =
dynamic_cast<ImageExt<float>&
>(*this);
191 FITSUtil::fill(image,extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
193 else if (
bitpix() == Idouble)
195 ImageExt<double>& extimage =
dynamic_cast<ImageExt<double>&
>(*this);
197 if (nulValue) nulVal =
static_cast<double>(*nulValue);
198 FITSUtil::fill(image,extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
200 else if (
bitpix() == Ibyte)
202 ImageExt<unsigned char>& extimage
203 =
dynamic_cast<ImageExt<unsigned char>&
>(*this);
204 unsigned char nulVal(0);
205 if (nulValue) nulVal =
static_cast<unsigned char>(*nulValue);
206 FITSUtil::fill(image,extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
208 else if (
bitpix() == Ilong)
212 ImageExt<unsigned INT32BIT>& extimage
213 =
dynamic_cast<ImageExt<unsigned INT32BIT>&
>(*this);
214 unsigned INT32BIT nulVal(0);
216 nulVal =
static_cast<unsigned INT32BIT
>(*nulValue);
217 FITSUtil::fill(image,extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
221 ImageExt<INT32BIT>& extimage =
dynamic_cast<ImageExt<INT32BIT>&
>(*this);
223 if (nulValue) nulVal =
static_cast<INT32BIT
>(*nulValue);
224 FITSUtil::fill(image,extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
227 else if (
bitpix() == Ilonglong)
229 ImageExt<LONGLONG>& extimage
230 =
dynamic_cast<ImageExt<LONGLONG>&
>(*this);
232 if (nulValue) nulVal =
static_cast<LONGLONG
>(*nulValue);
233 FITSUtil::fill(image,extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
235 else if (
bitpix() == Ishort)
239 ImageExt<unsigned short>& extimage
240 =
dynamic_cast<ImageExt<unsigned short>&
>(*this);
241 unsigned short nulVal(0);
243 =
static_cast<unsigned short>(*nulValue);
244 FITSUtil::fill(image,extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
248 ImageExt<short>& extimage
249 =
dynamic_cast<ImageExt<short>&
>(*this);
251 if (nulValue) nulVal =
static_cast<short>(*nulValue);
252 FITSUtil::fill(image,extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
263 void ExtHDU::read (std::valarray<S>& image,
const std::vector<long>& firstVertex,
264 const std::vector<long>& lastVertex,
265 const std::vector<long>& stride)
268 read(image, firstVertex,lastVertex,stride,
static_cast<S*
>(0));
271 template <
typename S>
272 void ExtHDU::write(
long first,
long nElements,
const std::valarray<S>& data,S* nulValue)
276 if (ImageExt<S>* extimage =
dynamic_cast<ImageExt<S>*
>(
this))
278 extimage->writeImage(first,nElements,data,nulValue);
284 std::valarray<float> __tmp;
285 ImageExt<float>& imageExt =
dynamic_cast<ImageExt<float>&
>(*this);
286 FITSUtil::fill(__tmp,data);
287 float* pfNullValue = 0;
288 float fNullValue = 0.0;
291 fNullValue =
static_cast<float>(*nulValue);
292 pfNullValue = &fNullValue;
294 imageExt.writeImage(first,nElements,__tmp, pfNullValue);
296 else if (
bitpix() == Idouble)
298 std::valarray<double> __tmp;
299 ImageExt<double>& imageExt
300 =
dynamic_cast<ImageExt<double>&
>(*this);
301 FITSUtil::fill(__tmp,data);
302 double* pdNullValue = 0;
303 double dNullValue = 0.0;
306 dNullValue =
static_cast<double>(*nulValue);
307 pdNullValue = &dNullValue;
309 imageExt.writeImage(first,nElements,__tmp,pdNullValue);
311 else if (
bitpix() == Ibyte)
313 ImageExt<unsigned char>& imageExt
314 =
dynamic_cast<ImageExt<unsigned char>&
>(*this);
315 std::valarray<unsigned char> __tmp;
316 FITSUtil::fill(__tmp,data);
317 unsigned char *pbNull=0;
318 unsigned char bNull=0;
321 bNull =
static_cast<unsigned char>(*nulValue);
324 imageExt.writeImage(first,nElements,__tmp, pbNull);
327 else if (
bitpix() == Ilong)
331 ImageExt<unsigned INT32BIT>& imageExt
332 =
dynamic_cast<ImageExt<unsigned INT32BIT>&
>(*this);
333 std::valarray<unsigned INT32BIT> __tmp;
335 FITSUtil::fill(__tmp,data);
336 unsigned INT32BIT *plNull=0;
337 unsigned INT32BIT lNull=0;
340 lNull =
static_cast<unsigned INT32BIT
>(*nulValue);
343 imageExt.writeImage(first,nElements,__tmp,plNull);
347 ImageExt<INT32BIT>& imageExt
348 =
dynamic_cast<ImageExt<INT32BIT>&
>(*this);
349 std::valarray<INT32BIT> __tmp;
350 FITSUtil::fill(__tmp,data);
355 lNull =
static_cast<INT32BIT
>(*nulValue);
358 imageExt.writeImage(first,nElements,__tmp,plNull);
361 else if (
bitpix() == Ilonglong)
363 ImageExt<LONGLONG>& imageExt
364 =
dynamic_cast<ImageExt<LONGLONG>&
>(*this);
365 std::valarray<LONGLONG> __tmp;
366 FITSUtil::fill(__tmp,data);
371 llNull =
static_cast<LONGLONG
>(*nulValue);
374 imageExt.writeImage(first,nElements,__tmp, pllNull);
377 else if (
bitpix() == Ishort)
381 ImageExt<unsigned short>& imageExt
382 =
dynamic_cast<ImageExt<unsigned short>&
>(*this);
383 std::valarray<unsigned short> __tmp;
384 FITSUtil::fill(__tmp,data);
385 unsigned short *psNull=0;
386 unsigned short sNull=0;
389 sNull =
static_cast<unsigned short>(*nulValue);
392 imageExt.writeImage(first,nElements,__tmp,psNull);
396 ImageExt<short>& imageExt
397 =
dynamic_cast<ImageExt<short>&
>(*this);
398 std::valarray<short> __tmp;
399 FITSUtil::fill(__tmp,data);
404 sNull =
static_cast<short>(*nulValue);
407 imageExt.writeImage(first,nElements,__tmp,psNull);
418 template <
typename S>
420 long nElements,
const std::valarray<S>& data)
422 write(first, nElements, data,
static_cast<S*
>(0));
425 template <
typename S>
428 const std::valarray<S>& data,
433 size_t n(first.size());
434 long firstElement(0);
436 for (
long i = 0; i < n; ++i)
438 firstElement += ((first[i] - 1)*dimSize);
443 write(firstElement,nElements,data,nulValue);
446 template <
typename S>
449 const std::valarray<S>& data)
453 size_t n(first.size());
454 long firstElement(0);
456 for (
long i = 0; i < n; ++i)
459 firstElement += ((first[i] - 1)*dimSize);
464 write(firstElement,nElements,data);
468 template <
typename S>
470 const std::vector<long>& lastVertex,
471 const std::valarray<S>& data)
474 if (ImageExt<S>* extimage =
dynamic_cast<ImageExt<S>*
>(
this))
476 extimage->writeImage(firstVertex,lastVertex,data);
484 ImageExt<float>& extimage =
dynamic_cast<ImageExt<float>&
>(*this);
485 size_t n(data.size());
486 std::valarray<float> __tmp(n);
487 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
488 extimage.writeImage(firstVertex,lastVertex,__tmp);
491 else if (
bitpix() == Idouble)
493 ImageExt<double>& extimage
494 =
dynamic_cast<ImageExt<double>&
>(*this);
495 size_t n(data.size());
496 std::valarray<double> __tmp(n);
497 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
498 extimage.writeImage(firstVertex,lastVertex,__tmp);
500 else if (
bitpix() == Ibyte)
502 ImageExt<unsigned char>& extimage
503 =
dynamic_cast<ImageExt<unsigned char>&
>(*this);
504 size_t n(data.size());
505 std::valarray<unsigned char> __tmp(n);
506 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
507 extimage.writeImage(firstVertex,lastVertex,__tmp);
509 else if (
bitpix() == Ilong)
513 ImageExt<unsigned INT32BIT>& extimage
514 =
dynamic_cast<ImageExt<unsigned INT32BIT>&
>(*this);
515 size_t n(data.size());
516 std::valarray<unsigned INT32BIT> __tmp(n);
517 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
518 extimage.writeImage(firstVertex,lastVertex,__tmp);
522 ImageExt<INT32BIT>& extimage
523 =
dynamic_cast<ImageExt<INT32BIT>&
>(*this);
524 size_t n(data.size());
525 std::valarray<INT32BIT> __tmp(n);
526 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
527 extimage.writeImage(firstVertex,lastVertex,__tmp);
530 else if (
bitpix() == Ilonglong)
532 ImageExt<LONGLONG>& extimage
533 =
dynamic_cast<ImageExt<LONGLONG>&
>(*this);
534 size_t n(data.size());
535 std::valarray<LONGLONG> __tmp(n);
536 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
537 extimage.writeImage(firstVertex,lastVertex,__tmp);
539 else if (
bitpix() == Ishort)
543 ImageExt<unsigned short>& extimage
544 =
dynamic_cast<ImageExt<unsigned short>&
>(*this);
545 size_t n(data.size());
546 std::valarray<unsigned short> __tmp(n);
547 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
548 extimage.writeImage(firstVertex,lastVertex,__tmp);
552 ImageExt<short>& extimage
553 =
dynamic_cast<ImageExt<short>&
>(*this);
554 size_t n(data.size());
555 std::valarray<short> __tmp(n);
556 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
557 extimage.writeImage(firstVertex,lastVertex,__tmp);
void read(std::valarray< S > &image)
Read image data into container.
Definition: ExtHDUT.h:18
virtual void makeThisCurrent() const
move the fitsfile pointer to this current HDU.
Definition: ExtHDU.cxx:208
void write(const std::vector< long > &first, long nElements, const std::valarray< S > &data, S *nullValue)
Write a set of pixels to an image extension with the first pixel specified by an n-tuple,...
Definition: ExtHDUT.h:426
exception thrown by MatchType if it encounters data type incompatible with cfitsio.
Definition: FITSUtil.h:637
[potential] base class for exceptions to be thrown on internal library error.
Definition: FitsError.h:127
std::vector< long > & naxes()
return the HDU data axis array.
Definition: HDU.h:1086
virtual double scale() const
return the BSCALE keyword value
Definition: HDU.h:1008
long bitpix() const
return the data type keyword.
Definition: HDU.h:998
virtual double zero() const
return the BZERO keyword value
Definition: HDU.h:1018
Namespace enclosing all CCfits classes and globals definitions.
Definition: AsciiTable.cxx:26
function object that returns the FITS ValueType corresponding to an input intrinsic type
Definition: FITSUtil.h:506