#include "fitsswapper.h" #include "sopnamsp.h" #include #include template FITSDataSwapper::FITSDataSwapper() { SetInStream(NULL, 0); SetOutStream(NULL, 0); } template FITSDataSwapper::FITSDataSwapper(fitsfile * is, int coli, fitsfile * os, int colo) { SetInStream(is, coli); if (os == NULL) SetOutStream(is, coli); else SetOutStream(os, colo); } template void FITSDataSwapper::SetInStream(fitsfile * is, int col) { fitsis = is; colis = col; hduis = 0; int status=0, hdutype=0; if (is != NULL) { if ( fits_get_hdu_num(fitsis, &hduis) <= 0) throw IOExc("FITSDataSwapper::SetInStream() fits_get_hdu_num Error"); if (fits_get_hdu_type(fitsis, &hdutype, &status)) { fits_report_error(stdout,status); fflush(stdout); throw IOExc("FITSDataSwapper::SetInStream() fits_get_hdu_type Error"); } // cout << "DBG-SetInStream() : hduis= " << hduis // << " hdutype=" << hdutype << " BINARY_TBL= " << BINARY_TBL << endl; if ( (hdutype != ASCII_TBL) && (hdutype != BINARY_TBL) ) throw IOExc("FITSDataSwapper::SetInStream() current HDU not of BINARY_TBL or ASCII_TBL type"); } } template void FITSDataSwapper::SetOutStream(fitsfile * os, int col) { fitsos = os; colos = col; hduos = 0; rowos = 0; int status=0, hdutype=0; if (os != NULL) { if ( fits_get_hdu_num(fitsos, &hduos) <= 0 ) throw IOExc("FITSDataSwapper::SetOutStream() fits_get_hdu_num Error"); if (fits_get_hdu_type(fitsos, &hdutype, &status)) { fits_report_error(stdout,status); fflush(stdout); throw IOExc("FITSDataSwapper::SetOutStream() fits_get_hdu_type Error"); } // cout << "DBG-SetOutStream() : hduos= " << hduos // << " hdutype=" << hdutype << " BINARY_TBL= " << BINARY_TBL << endl; if ( (hdutype != ASCII_TBL) && (hdutype != BINARY_TBL) ) throw IOExc("FITSDataSwapper::SetOutStream() current HDU not of BINARY_TBL or ASCII_TBL type"); } } template FITSDataSwapper& FITSDataSwapper::operator = (FITSDataSwapper const & a) { fitsos = a.fitsos; colos = a.colos; hduos = a.hduos; rowos = a.rowos; fitsis = a.fitsis; colis = a.colis; hduis = a.hduis; return *this; } static inline int _ConvertToFitsDataType(const r_8 * d) { return TDOUBLE; } static inline int _ConvertToFitsDataType(const r_4 * d) { return TFLOAT; } static inline int _ConvertToFitsDataType(const uint_2 * d) { return TUSHORT; } static inline int _ConvertToFitsDataType(const int_2 * d) { return TSHORT; } static inline int _ConvertToFitsDataType(const int_4 * d) { return (sizeof(long)==4) ? TLONG: TINT; } #ifdef TLONGLONG static inline int _ConvertToFitsDataType(const int_8 * d) { return TLONGLONG; } #else static inline int _ConvertToFitsDataType(const int_8 * d) { throw NotAvailableOperation("FITSDataSwapper ; Unsupported data type ")} #endif template int_8 FITSDataSwapper::WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp, bool osw) { if (fitsos == NULL) throw IOExc("FITSDataSwapper::WriteToSwap() null output stream pointer (fitsos)" ); int hdutype=0, status=0; if(fits_movabs_hdu(fitsos,hduos,&hdutype,&status)) { fits_report_error(stdout,status); fflush(stdout); throw IOExc("FITSDataSwapper::WriteToSwap() fits_movabs_hdu Error"); } int ftype = _ConvertToFitsDataType(d); long row; if (osw) row = oswp; else row = rowos; T * ncd = const_cast(d); if( fits_write_col(fitsos, ftype, colos+1, row+1, 1, sz, ncd, &status) ) { fits_report_error(stdout,status); fflush(stdout); throw IOExc("FITSDataSwapper::WriteToSwap() fits_write_col Error"); } if (!osw) rowos += sz; // On met a jour la position d'ecriture courante si pas de reecriture return row; } template void FITSDataSwapper::ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz) { if (fitsis == NULL) throw IOExc("FITSDataSwapper::ReadFromSwap() null input stream pointer (fitsis)" ); int hdutype=0, status=0; if(fits_movabs_hdu(fitsis,hduos,&hdutype,&status)) { fits_report_error(stdout,status); fflush(stdout); throw IOExc("FITSDataSwapper::ReadFromSwap() fits_movabs_hdu Error"); } int ftype = _ConvertToFitsDataType(d); if( fits_read_col(fitsis, ftype, colis+1, swp+1, 1, sz, NULL, d, NULL, &status) ) { fits_report_error(stdout,status); fflush(stdout); throw IOExc("FITSDataSwapper::ReadFromSwap() fits_read_col Error"); } return; } /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// #ifdef __CXX_PRAGMA_TEMPLATES__ #pragma define_template FITSDataSwapper #pragma define_template FITSDataSwapper #pragma define_template FITSDataSwapper #pragma define_template FITSDataSwapper #pragma define_template FITSDataSwapper #pragma define_template FITSDataSwapper #endif #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) template class FITSDataSwapper; template class FITSDataSwapper; template class FITSDataSwapper; template class FITSDataSwapper; template class FITSDataSwapper; template class FITSDataSwapper; #endif