24 #include "FitsError.h"
281 #include "MSconfig.h"
284 template <
typename T>
285 void swap(T& left,T& right);
287 template <
typename T>
288 void swap(std::vector<T>& left, std::vector<T>& right);
290 string lowerCase(
const string& inputString);
292 string upperCase(
const string& inputString);
296 string::size_type checkForCompressString(
const string& fileName);
298 struct InvalidConversion :
public FitsException
300 InvalidConversion(
const string& diag,
bool silent=
false);
306 bool operator()(
const string& left,
const string& right)
const;
309 static const double d1(0);
310 static const float f1(0);
311 static const std::complex<float> c1(0.);
312 static const std::complex<double> d2(0.);
313 static const string s1(
"");
314 static const int i1(0);
315 static const unsigned int u1(0);
316 static const long l1(0);
317 static const unsigned long ul1(0);
318 static const LONGLONG ll1(0);
319 static const short s2(0);
320 static const unsigned short us1(0);
321 static const bool b1(
false);
322 static const unsigned char b2(0);
324 char** CharArray(
const std::vector<string>& inArray);
326 string FITSType2String(
int typeInt );
329 template <
typename S,
typename T>
330 void fill(std::vector<S>& outArray,
const std::vector<T>& inArray,
size_t first,
size_t last);
332 template <
typename S,
typename T>
333 void fill(std::valarray<S>& outArray,
const std::valarray<T>& inArray);
335 template <
typename S,
typename T>
336 void fill(std::valarray<S>& outArray,
const std::vector<T>& inArray,
size_t first,
size_t last);
339 template <
typename S,
typename T>
340 void fill(std::vector<S>& outArray,
const std::valarray<T>& inArray);
343 void fill(std::vector<std::complex<float> >& outArray,
344 const std::valarray<std::complex<float> >& inArray);
347 void fill(std::vector<std::complex<float> >& outArray,
348 const std::valarray<std::complex<double> >& inArray);
351 void fill(std::vector<std::complex<double> >& outArray,
352 const std::valarray<std::complex<double> >& inArray);
356 void fill(std::vector<std::complex<double> >& outArray,
357 const std::valarray<std::complex<float> >& inArray);
359 template <
typename T>
360 void fill(std::vector<string>& outArray,
const std::vector<T>& inArray,
size_t first,
size_t last);
362 template <
typename T>
363 void fill(std::vector<T>& outArray,
const std::vector<string>& inArray,
size_t first,
size_t last);
365 template <
typename S>
366 void fill(std::valarray<S>& outArray,
const std::vector<string>& inArray,
size_t first,
size_t last);
373 #ifdef TEMPLATE_AMBIG_DEFECT
374 void fillMSvfvf(std::vector<std::complex<float> >& outArray,
375 const std::vector<std::complex<float> >& inArray,
size_t first,
size_t last);
378 void fill(std::vector<std::complex<float> >& outArray,
379 const std::vector<std::complex<float> >& inArray,
size_t first,
size_t last);
382 #ifdef TEMPLATE_AMBIG_DEFECT
383 void fillMSvfvd(std::vector<std::complex<float> >& outArray,
384 const std::vector<std::complex<double> >& inArray,
size_t first,
size_t last);
387 void fill(std::vector<std::complex<float> >& outArray,
388 const std::vector<std::complex<double> >& inArray,
size_t first,
size_t last);
391 #ifdef TEMPLATE_AMBIG_DEFECT
392 void fillMSvdvd(std::vector<std::complex<double> >& outArray,
393 const std::vector<std::complex<double> >& inArray,
size_t first,
size_t last);
396 void fill(std::vector<std::complex<double> >& outArray,
397 const std::vector<std::complex<double> >& inArray,
size_t first,
size_t last);
399 #ifdef TEMPLATE_AMBIG_DEFECT
400 void fillMSvdvf(std::vector<std::complex<double> >& outArray,
401 const std::vector<std::complex<float> >& inArray,
402 size_t first,
size_t last);
404 void fill(std::vector<std::complex<double> >& outArray,
405 const std::vector<std::complex<float> >& inArray,
size_t first,
size_t last);
409 void fill(std::valarray<std::complex<float> >& outArray,
410 const std::vector<std::complex<double> >& inArray,
size_t first,
size_t last);
413 #ifdef TEMPLATE_AMBIG_DEFECT
414 void fillMSafvf(std::valarray<std::complex<float> >& outArray,
415 const std::vector<std::complex<float> >& inArray,
size_t first,
size_t last);
417 void fill(std::valarray<std::complex<float> >& outArray,
418 const std::vector<std::complex<float> >& inArray,
size_t first,
size_t last);
422 #ifdef TEMPLATE_AMBIG_DEFECT
423 void fillMSadvf(std::valarray<std::complex<double> >& outArray,
424 const std::vector<std::complex<float> >& inArray,
size_t first,
size_t last);
426 void fill(std::valarray<std::complex<double> >& outArray,
427 const std::vector<std::complex<float> >& inArray,
size_t first,
size_t last);
431 #ifdef TEMPLATE_AMBIG_DEFECT
432 void fillMSadvd(std::valarray<std::complex<double> >& outArray,
433 const std::vector<std::complex<double> >& inArray,
size_t first,
size_t last);
435 void fill(std::valarray<std::complex<double> >& outArray,
436 const std::vector<std::complex<double> >& inArray,
size_t first,
size_t last);
440 void fill(std::valarray<std::complex<float> >& outArray,
441 const std::valarray<std::complex<float> >& inArray);
443 void fill(std::valarray<std::complex<double> >& outArray,
444 const std::valarray<std::complex<double> >& inArray);
446 void fill(std::valarray<std::complex<float> >& outArray,
447 const std::valarray<std::complex<double> >& inArray);
449 void fill(std::valarray<std::complex<double> >& outArray,
450 const std::valarray<std::complex<float> >& inArray);
452 #if TEMPLATE_AMBIG_DEFECT || TEMPLATE_AMBIG7_DEFECT
453 void fillMSvsvs(std::vector<string>& outArray,
const std::vector<string>& inArray,
size_t first,
size_t last);
457 void fill(std::vector<string>& outArray,
const std::vector<string>& inArray,
size_t first,
size_t last);
459 template <
typename S,
typename T>
460 string errorMessage(
const S& out,
const T& in);
468 bool operator () (
const T& left,
const string& right)
const;
481 bool operator () (
const T& left,
const string& right)
const;
494 bool operator () (
const T& left,
const int& right)
const;
504 template <
typename T>
517 template <
typename T>
530 template <
typename T>
543 template <
typename T>
544 struct MatchImageType
546 ImageType operator () ();
559 bool operator () (
const T& left,
const int& right)
const;
570 template <
typename X>
584 X*
reset (X* p)
throw ();
585 static void remove (X*& x);
597 template <
typename T>
598 struct ComparePtrIndex
600 bool operator () (
const T* left,
const T* right);
610 template <
typename T>
623 template <
typename T>
626 T*
operator () (
const std::vector< std::valarray<T> >& inArray);
651 return left->name() == right;
657 inline bool MatchName<T>::operator () (
const T& left,
const string& right)
const
659 return left.name() == right;
665 inline bool MatchNum<T>::operator () (
const T& left,
const int& right)
const
667 return left.index() == right;
674 template <
typename T>
682 std::copy(inArray.begin(),inArray.end(),&c[0]);
688 template <
typename T>
689 inline T FitsNullValue<T>::operator () ()
701 inline bool MatchPtrNum<T>::operator () (
const T& left,
const int& right)
const
703 return left->index() == right;
724 template <
typename T>
728 if (
typeid(T) ==
typeid(d1) )
return Tdouble;
729 if (
typeid(T) ==
typeid(f1) )
return Tfloat;
730 if (
typeid(T) ==
typeid(c1) )
return Tcomplex;
731 if (
typeid(T) ==
typeid(d2) )
return Tdblcomplex;
732 if (
typeid(T) ==
typeid(s1) )
return Tstring;
733 if (
typeid(T) ==
typeid(i1) )
return Tint;
734 if (
typeid(T) ==
typeid(u1) )
return Tuint;
735 if (
typeid(T) ==
typeid(s2) )
return Tshort;
736 if (
typeid(T) ==
typeid(us1) )
return Tushort;
737 if (
typeid(T) ==
typeid(b1) )
return Tlogical;
738 if (
typeid(T) ==
typeid(b2) )
return Tbyte;
739 if (
typeid(T) ==
typeid(l1) )
return Tlong;
740 if (
typeid(T) ==
typeid(ul1) )
return Tulong;
743 if (
typeid(T) ==
typeid(ll1) )
return Tlonglong;
744 throw UnrecognizedType(
"Invalid data type for FITS Data I/O\n");
751 template <
typename T>
752 ImageType MatchImageType<T>::operator () ()
754 if (
typeid(T) ==
typeid(b2) )
return Ibyte;
755 if (
typeid(T) ==
typeid(s2) )
return Ishort;
756 if (
typeid(T) ==
typeid(l1) )
return Ilong;
757 if (
typeid(T) ==
typeid(f1) )
return Ifloat;
758 if (
typeid(T) ==
typeid(d1) )
return Idouble;
759 if (
typeid(T) ==
typeid(us1) )
return Iushort;
760 if (
typeid(T) ==
typeid(ul1) )
return Iulong;
761 if (
typeid(T) ==
typeid(ll1) )
return Ilonglong;
762 MatchType<T> errType;
763 string diag (
"Image: ");
764 diag += FITSType2String(errType());
765 throw UnrecognizedType(diag);
772 template <
typename X>
778 template <
typename X>
780 : m_p(right.release())
785 template <
typename X>
792 template <
typename X>
802 template <
typename X>
808 template <
typename X>
814 template <
typename X>
820 template <
typename X>
826 template <
typename X>
832 template <
typename X>
841 template <
typename X>
851 template <
typename T>
852 bool ComparePtrIndex<T>::operator () (
const T* left,
const T* right)
854 return (left->index() < right->index());
859 template <
typename T>
862 size_t n(inArray.size());
865 for (
size_t j = 0; j < n; ++j) c[j] = inArray[j];
871 template <
typename T>
875 size_t n(inArray.size());
877 std::vector<size_t> nr(n);
880 for ( i = 0; i < n; ++i)
882 nr[i] = inArray[i].size();
890 for ( i = 0; i < n; ++i)
893 const std::valarray<T>& current = inArray[i];
894 for (
size_t j=0; j < m ; ++j) c[k++] = current[j];
909 template <
typename T>
910 void swap(T& left, T& right)
917 template <
typename T>
918 void swap(std::vector<T>& left, std::vector<T>& right)
924 inline string FitsNullValue<string>::operator () ()
930 inline float FitsNullValue<float>::operator () ()
932 return FLOATNULLVALUE;
936 inline double FitsNullValue<double>::operator () ()
938 return DOUBLENULLVALUE;
942 inline std::complex<float> FitsNullValue<std::complex<float> >::operator () ()
944 return std::complex<float>(FLOATNULLVALUE);
948 inline std::complex<double> FitsNullValue<std::complex<double> >::operator () ()
950 return std::complex<double>(DOUBLENULLVALUE);
function object returning C array from a vector of valarrays. see CVarray for details ...
Definition: FITSUtil.h:624
X * release()
return underlying content of *this, transferring memory ownership
Definition: FITSUtil.h:827
as for MatchNum, only with the input class a pointer.
Definition: FITSUtil.h:557
X & operator[](size_t i)
return a reference to the ith element of the array
Definition: FITSUtil.h:809
A class that mimics the std:: library auto_ptr class, but works with arrays.
Definition: FITSUtil.h:571
predicate for classes that have a name attribute; match input string with instance name...
Definition: FITSUtil.h:479
X * reset(X *p)
change the content of the auto_array_ptr to p
Definition: FITSUtil.h:833
static void remove(X *&x)
utility function to delete the memory owned by x and set it to null.
Definition: FITSUtil.h:842
T * operator()(const std::vector< T > &inArray)
operator returning C array for use with scalar column data.
Definition: FITSUtil.h:675
function object returning C array from a valarray. see CVarray for details
Definition: FITSUtil.h:611
Function object class for returning C arrays from standard library objects used in the FITS library i...
Definition: FITSUtil.h:518
void operator=(auto_array_ptr< X > &right)
assignment operator: transfer of ownership semantics
Definition: FITSUtil.h:793
as for MatchName, only with the input class a pointer.
Definition: FITSUtil.h:465
function object that returns the FITS ValueType corresponding to an input intrinsic type ...
Definition: FITSUtil.h:505
predicate for classes that have an index attribute; match input index with instance value...
Definition: FITSUtil.h:492
FitsException is the base class for all exceptions thrown by this library.
Definition: FitsError.h:93
X * get() const
return a token for the underlying content of *this
Definition: FITSUtil.h:821
~auto_array_ptr()
destructor.
Definition: FITSUtil.h:786
auto_array_ptr(X *p=0)
constructor. allows creation of pointer to null, can be modified by reset()
Definition: FITSUtil.h:773
ValueType
CCfits value types and their CFITSIO equivalents (in caps)
Definition: CCfits.h:81
X & operator*()
deference operator
Definition: FITSUtil.h:803
T * operator()(const std::valarray< T > &inArray)
operator returning C array for use with image data.
Definition: FITSUtil.h:860
exception thrown by MatchType if it encounters data type incompatible with cfitsio.
Definition: FITSUtil.h:636
T * operator()(const std::vector< std::valarray< T > > &inArray)
operator returning C array for use with vector column data.
Definition: FITSUtil.h:872