Changeset 2857 in Sophya for trunk/SophyaExt/FitsIOServer
- Timestamp:
- Dec 7, 2005, 7:12:03 PM (20 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 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 -
trunk/SophyaExt/FitsIOServer/fitsswapper.h
r2785 r2857 9 9 #include "machdefs.h" 10 10 #include "swsegdb.h" 11 #include "FitsIO/fitsio.h" 11 #include "fitsinoutfile.h" 12 #include "fitsblkrw.h" 12 13 13 14 namespace SOPHYA { … … 15 16 \class SOPHYA::FITSDataSwapper 16 17 \ingroup FitsIOServer 17 Implementation of SOPHYA::DataSwapperInterface interface on FITS streams18 ( fitsfile *) to be used with SOPHYA::SwSegDataBlock classes.18 Implementation of SOPHYA::DataSwapperInterface interface on FITS files 19 (FitsInOutFile) to be used with SOPHYA::SwSegDataBlock classes. 19 20 */ 20 21 … … 22 23 class FITSDataSwapper : public DataSwapperInterface<T> { 23 24 public: 24 FITSDataSwapper(); 25 FITSDataSwapper(fitsfile * is, int coli, fitsfile * os=NULL, int colo=0); 25 FITSDataSwapper() 26 { 27 SetInOutStream(NULL, 0); 28 } 29 FITSDataSwapper(FitsInOutFile * ios, int col) 30 { 31 SetInOutStream(ios, col); 32 } 26 33 27 inline fitsfile * InStream() { return fitsis; } 28 inline fitsfile * OutStream() { return fitsos; } 29 void SetInStream(fitsfile * is, int col); 30 void SetOutStream(fitsfile * os, int col); 34 inline FitsInOutFile * InOutStream() { return fios; } 35 void SetInOutStream(FitsInOutFile * ios, int col) 36 { 37 fios = ios; 38 fcol = col; 39 rowos = 1; 40 if ( fios != NULL) { 41 fhdu = fios->CurrentHDU(); 42 if (fios->CurrentHDUType() != BINARY_TBL) 43 throw FitsIOException("FITSDataSwapper<T>::SetInOutStream() CurrHDU not a BINARY_TBL"); 44 } 45 } 31 46 32 47 // Operateur = , on recopie les pointeurs des streams 33 FITSDataSwapper<T>& operator = (FITSDataSwapper<T> const & a); 48 FITSDataSwapper<T>& operator = (FITSDataSwapper<T> const & a) 49 { 50 fios = a.fios; 51 fcol = a.fcol; 52 rowos = a.rowos; 53 fhdu = a.fhdu; 54 } 34 55 35 virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false); 36 virtual void ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz); 56 virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false) 57 { 58 if (fios == NULL) 59 FitsIOException("FITSDataSwapper<T>::ReadFromSwap() null InOutFile pointer"); 60 fios->MoveAbsToHDU(fhdu); 61 long row = rowos; 62 if (osw) row = oswp; 63 FitsBlockRW<T>::WriteColumnData(*fios, fcol, row, 1, d, sz); 64 if (!osw) rowos += sz; 65 return row; 66 } 67 68 virtual void ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz) 69 { 70 if (fios == NULL) 71 FitsIOException("FITSDataSwapper<T>::ReadFromSwap() null InOutFile pointer"); 72 FitsBlockRW<T>::ReadColumnData(*fios, fcol, swp, 1, d, sz); 73 } 37 74 38 75 protected: 39 fitsfile * fitsos;40 int colos, hduos;76 FitsInOutFile * fios; 77 int fcol, fhdu; 41 78 long rowos; 42 fitsfile * fitsis;43 int colis, hduis;44 79 }; 45 80
Note:
See TracChangeset
for help on using the changeset viewer.