Changeset 2857 in Sophya for trunk/SophyaExt/FitsIOServer/fitsswapper.cc
- Timestamp:
- Dec 7, 2005, 7:12:03 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsswapper.cc
r2782 r2857 4 4 #include <iostream> 5 5 6 7 template <class T>8 FITSDataSwapper<T>::FITSDataSwapper()9 {10 SetInStream(NULL, 0);11 SetOutStream(NULL, 0);12 }13 14 template <class T>15 FITSDataSwapper<T>::FITSDataSwapper(fitsfile * is, int coli, fitsfile * os, int colo)16 {17 SetInStream(is, coli);18 if (os == NULL) SetOutStream(is, coli);19 else SetOutStream(os, colo);20 }21 22 template <class T>23 void FITSDataSwapper<T>::SetInStream(fitsfile * is, int col)24 {25 fitsis = is;26 colis = col;27 hduis = 0;28 int status=0, hdutype=0;29 if (is != NULL) {30 if ( fits_get_hdu_num(fitsis, &hduis) <= 0)31 throw IOExc("FITSDataSwapper<T>::SetInStream() fits_get_hdu_num Error");32 if (fits_get_hdu_type(fitsis, &hdutype, &status)) {33 fits_report_error(stdout,status); fflush(stdout);34 throw IOExc("FITSDataSwapper<T>::SetInStream() fits_get_hdu_type Error");35 }36 // cout << "DBG-SetInStream() : hduis= " << hduis37 // << " hdutype=" << hdutype << " BINARY_TBL= " << BINARY_TBL << endl;38 if ( (hdutype != ASCII_TBL) && (hdutype != BINARY_TBL) )39 throw IOExc("FITSDataSwapper<T>::SetInStream() current HDU not of BINARY_TBL or ASCII_TBL type");40 }41 }42 43 template <class T>44 void FITSDataSwapper<T>::SetOutStream(fitsfile * os, int col)45 {46 fitsos = os;47 colos = col;48 hduos = 0;49 rowos = 0;50 int status=0, hdutype=0;51 if (os != NULL) {52 if ( fits_get_hdu_num(fitsos, &hduos) <= 0 )53 throw IOExc("FITSDataSwapper<T>::SetOutStream() fits_get_hdu_num Error");54 if (fits_get_hdu_type(fitsos, &hdutype, &status)) {55 fits_report_error(stdout,status); fflush(stdout);56 throw IOExc("FITSDataSwapper<T>::SetOutStream() fits_get_hdu_type Error");57 }58 // cout << "DBG-SetOutStream() : hduos= " << hduos59 // << " hdutype=" << hdutype << " BINARY_TBL= " << BINARY_TBL << endl;60 if ( (hdutype != ASCII_TBL) && (hdutype != BINARY_TBL) )61 throw IOExc("FITSDataSwapper<T>::SetOutStream() current HDU not of BINARY_TBL or ASCII_TBL type");62 }63 }64 65 template <class T>66 FITSDataSwapper<T>& FITSDataSwapper<T>::operator = (FITSDataSwapper<T> const & a)67 {68 fitsos = a.fitsos;69 colos = a.colos;70 hduos = a.hduos;71 rowos = a.rowos;72 fitsis = a.fitsis;73 colis = a.colis;74 hduis = a.hduis;75 return *this;76 }77 78 79 static inline int _ConvertToFitsDataType(const r_8 * d) { return TDOUBLE; }80 static inline int _ConvertToFitsDataType(const r_4 * d) { return TFLOAT; }81 static inline int _ConvertToFitsDataType(const uint_2 * d) { return TUSHORT; }82 static inline int _ConvertToFitsDataType(const int_2 * d) { return TSHORT; }83 static inline int _ConvertToFitsDataType(const int_4 * d) { return (sizeof(long)==4) ? TLONG: TINT; }84 #ifdef TLONGLONG85 static inline int _ConvertToFitsDataType(const int_8 * d) { return TLONGLONG; }86 #else87 static inline int _ConvertToFitsDataType(const int_8 * d) { throw NotAvailableOperation("FITSDataSwapper<int_8> ; Unsupported data type ")}88 #endif89 90 template <class T>91 int_8 FITSDataSwapper<T>::WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp, bool osw)92 {93 if (fitsos == NULL) throw IOExc("FITSDataSwapper<T>::WriteToSwap() null output stream pointer (fitsos)" );94 int hdutype=0, status=0;95 if(fits_movabs_hdu(fitsos,hduos,&hdutype,&status)) {96 fits_report_error(stdout,status); fflush(stdout);97 throw IOExc("FITSDataSwapper<T>::WriteToSwap() fits_movabs_hdu Error");98 }99 int ftype = _ConvertToFitsDataType(d);100 long row;101 if (osw) row = oswp;102 else row = rowos;103 T * ncd = const_cast<T *>(d);104 if( fits_write_col(fitsos, ftype, colos+1, row+1, 1, sz, ncd, &status) ) {105 fits_report_error(stdout,status); fflush(stdout);106 throw IOExc("FITSDataSwapper<T>::WriteToSwap() fits_write_col Error");107 }108 if (!osw) rowos += sz; // On met a jour la position d'ecriture courante si pas de reecriture109 return row;110 }111 112 template <class T>113 void FITSDataSwapper<T>::ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz)114 {115 if (fitsis == NULL) throw IOExc("FITSDataSwapper<T>::ReadFromSwap() null input stream pointer (fitsis)" );116 int hdutype=0, status=0;117 if(fits_movabs_hdu(fitsis,hduos,&hdutype,&status)) {118 fits_report_error(stdout,status); fflush(stdout);119 throw IOExc("FITSDataSwapper<T>::ReadFromSwap() fits_movabs_hdu Error");120 }121 int ftype = _ConvertToFitsDataType(d);122 if( fits_read_col(fitsis, ftype, colis+1, swp+1, 1, sz, NULL, d, NULL, &status) ) {123 fits_report_error(stdout,status); fflush(stdout);124 throw IOExc("FITSDataSwapper<T>::ReadFromSwap() fits_read_col Error");125 }126 return;127 }128 6 129 7
Note:
See TracChangeset
for help on using the changeset viewer.