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)
46 const std::valarray<S>& __tmp
47 = extimage->readImage(first,nElements,nulValue);
48 image.resize(__tmp.size());
58 if (nulValue) nulVal =
static_cast<float>(*nulValue);
60 extimage.readImage(first,nElements,&nulVal));
62 else if (
bitpix() == Idouble)
67 if (nulValue) nulVal =
static_cast<double>(*nulValue);
69 extimage.readImage(first,nElements,&nulVal));
71 else if (
bitpix() == Ibyte)
75 unsigned char nulVal(0);
76 if (nulValue) nulVal =
static_cast<unsigned char>(*nulValue);
78 extimage.readImage(first,nElements,&nulVal));
80 else if (
bitpix() == Ilong)
86 unsigned INT32BIT nulVal(0);
88 =
static_cast<unsigned INT32BIT
>(*nulValue);
90 extimage.readImage(first,nElements,&nulVal));
97 if (nulValue) nulVal =
static_cast<INT32BIT
>(*nulValue);
99 extimage.readImage(first,nElements,&nulVal));
102 else if (
bitpix() == Ishort)
108 unsigned short nulVal(0);
110 =
static_cast<unsigned short>(*nulValue);
111 FITSUtil::fill(image,
112 extimage.readImage(first,nElements,&nulVal));
119 if (nulValue) nulVal =
static_cast<short>(*nulValue);
120 FITSUtil::fill(image,
121 extimage.readImage(first,nElements,&nulVal));
133 void ExtHDU::read (std::valarray<S>& image,
const std::vector<long>& first,
138 long firstElement(0);
140 std::vector<long> inputDimensions(naxis(),1);
141 size_t sNaxis =
static_cast<size_t>(naxis());
142 size_t n(std::min(sNaxis,first.size()));
143 std::copy(&first[0],&first[0]+n,&inputDimensions[0]);
144 for (
long i = 0; i < naxis(); ++i)
147 firstElement += ((inputDimensions[i] - 1)*dimSize);
153 read(image, firstElement,nElements,nulValue);
160 void ExtHDU::read (std::valarray<S>& image,
const std::vector<long>& first,
164 read(image, first,nElements,static_cast<S*>(0));
169 void ExtHDU::read (std::valarray<S>& image,
const std::vector<long>& firstVertex,
170 const std::vector<long>& lastVertex,
171 const std::vector<long>& stride,
177 const std::valarray<S>& __tmp
178 = extimage->readImage(firstVertex,lastVertex,stride,nulValue);
179 image.resize(__tmp.size());
188 if (nulValue) nulVal =
static_cast<float>(*nulValue);
190 FITSUtil::fill(image,
191 extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
193 else if (
bitpix() == Idouble)
197 if (nulValue) nulVal =
static_cast<double>(*nulValue);
198 FITSUtil::fill(image,
199 extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
201 else if (
bitpix() == Ibyte)
205 unsigned char nulVal(0);
206 if (nulValue) nulVal =
static_cast<unsigned char>(*nulValue);
207 FITSUtil::fill(image,
208 extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
210 else if (
bitpix() == Ilong)
216 unsigned INT32BIT nulVal(0);
218 nulVal =
static_cast<unsigned INT32BIT
>(*nulValue);
219 FITSUtil::fill(image,
220 extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
226 if (nulValue) nulVal =
static_cast<INT32BIT
>(*nulValue);
227 FITSUtil::fill(image,
228 extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
231 else if (
bitpix() == Ishort)
237 unsigned short nulVal(0);
239 =
static_cast<unsigned short>(*nulValue);
240 FITSUtil::fill(image,
241 extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
248 if (nulValue) nulVal =
static_cast<short>(*nulValue);
249 FITSUtil::fill(image,
250 extimage.readImage(firstVertex,lastVertex,stride,&nulVal));
261 void ExtHDU::read (std::valarray<S>& image,
const std::vector<long>& firstVertex,
262 const std::vector<long>& lastVertex,
263 const std::vector<long>& stride)
266 read(image, firstVertex,lastVertex,stride,static_cast<S*>(0));
269 template <
typename S>
270 void ExtHDU::write(
long first,
long nElements,
const std::valarray<S>& data,S* nulValue)
276 extimage->writeImage(first,nElements,data,nulValue);
282 std::valarray<float> __tmp;
284 FITSUtil::fill(__tmp,data);
285 float* pfNullValue = 0;
286 float fNullValue = 0.0;
289 fNullValue =
static_cast<float>(*nulValue);
290 pfNullValue = &fNullValue;
292 imageExt.writeImage(first,nElements,__tmp, pfNullValue);
294 else if (
bitpix() == Idouble)
296 std::valarray<double> __tmp;
299 FITSUtil::fill(__tmp,data);
300 double* pdNullValue = 0;
301 double dNullValue = 0.0;
304 dNullValue =
static_cast<double>(*nulValue);
305 pdNullValue = &dNullValue;
307 imageExt.writeImage(first,nElements,__tmp,pdNullValue);
309 else if (
bitpix() == Ibyte)
313 std::valarray<unsigned char> __tmp;
314 FITSUtil::fill(__tmp,data);
315 unsigned char *pbNull=0;
316 unsigned char bNull=0;
319 bNull =
static_cast<unsigned char>(*nulValue);
322 imageExt.writeImage(first,nElements,__tmp, pbNull);
325 else if (
bitpix() == Ilong)
331 std::valarray<unsigned INT32BIT> __tmp;
333 FITSUtil::fill(__tmp,data);
334 unsigned INT32BIT *plNull=0;
335 unsigned INT32BIT lNull=0;
338 lNull =
static_cast<unsigned INT32BIT
>(*nulValue);
341 imageExt.writeImage(first,nElements,__tmp,plNull);
347 std::valarray<INT32BIT> __tmp;
348 FITSUtil::fill(__tmp,data);
353 lNull =
static_cast<INT32BIT
>(*nulValue);
356 imageExt.writeImage(first,nElements,__tmp,plNull);
359 else if (
bitpix() == Ishort)
365 std::valarray<unsigned short> __tmp;
366 FITSUtil::fill(__tmp,data);
367 unsigned short *psNull=0;
368 unsigned short sNull=0;
371 sNull =
static_cast<unsigned short>(*nulValue);
374 imageExt.writeImage(first,nElements,__tmp,psNull);
380 std::valarray<short> __tmp;
381 FITSUtil::fill(__tmp,data);
386 sNull =
static_cast<short>(*nulValue);
389 imageExt.writeImage(first,nElements,__tmp,psNull);
400 template <
typename S>
402 long nElements,
const std::valarray<S>& data)
404 write(first, nElements, data, static_cast<S*>(0));
407 template <
typename S>
410 const std::valarray<S>& data,
415 size_t n(first.size());
416 long firstElement(0);
418 for (
long i = 0; i < first.size(); ++i)
420 firstElement += ((first[i] - 1)*dimSize);
425 write(firstElement,nElements,data,nulValue);
428 template <
typename S>
431 const std::valarray<S>& data)
435 size_t n(first.size());
436 long firstElement(0);
438 for (
long i = 0; i < first.size(); ++i)
441 firstElement += ((first[i] - 1)*dimSize);
446 write(firstElement,nElements,data);
450 template <
typename S>
452 const std::vector<long>& lastVertex,
453 const std::valarray<S>& data)
458 extimage->writeImage(firstVertex,lastVertex,data);
467 size_t n(data.size());
468 std::valarray<float> __tmp(n);
469 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
470 extimage.writeImage(firstVertex,lastVertex,__tmp);
473 else if (
bitpix() == Idouble)
477 size_t n(data.size());
478 std::valarray<double> __tmp(n);
479 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
480 extimage.writeImage(firstVertex,lastVertex,__tmp);
482 else if (
bitpix() == Ibyte)
486 size_t n(data.size());
487 std::valarray<unsigned char> __tmp(n);
488 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
489 extimage.writeImage(firstVertex,lastVertex,__tmp);
491 else if (
bitpix() == Ilong)
497 size_t n(data.size());
498 std::valarray<unsigned INT32BIT> __tmp(n);
499 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
500 extimage.writeImage(firstVertex,lastVertex,__tmp);
506 size_t n(data.size());
507 std::valarray<INT32BIT> __tmp(n);
508 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
509 extimage.writeImage(firstVertex,lastVertex,__tmp);
512 else if (
bitpix() == Ishort)
518 size_t n(data.size());
519 std::valarray<unsigned short> __tmp(n);
520 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
521 extimage.writeImage(firstVertex,lastVertex,__tmp);
527 size_t n(data.size());
528 std::valarray<short> __tmp(n);
529 for (
size_t j= 0; j < n; ++j) __tmp[j] = data[j];
530 extimage.writeImage(firstVertex,lastVertex,__tmp);