Changeset 2846 in Sophya for trunk/SophyaExt/FitsIOServer/fitsblkrw.h
- Timestamp:
- Nov 21, 2005, 9:32:49 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsblkrw.h
r2843 r2846 9 9 \ingroup FitsIOServer 10 10 \brief Template class with static methods for handling bloc data 11 read from / write to fits files 11 read from / write to fits filesz 12 12 */ 13 13 … … 114 114 }; 115 115 116 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 117 class FitsBlockRW<std::string> { 118 public: 119 //! Write image HDU with string data type not supported (throws exception) 120 static void WriteImageData(FitsInOutFile& fios, const std::string * d, size_t sz, 121 long * fpixel=NULL) 122 { 123 throw FitsIOException( 124 "FitsBlockRW<string>::WriteImageData() string data type Unsupported for image HDU"); 125 } 126 //! Read image HDU with string data type not supported (throws exception) 127 static void ReadImageData(FitsInOutFile& fios, std::string * d, size_t sz, 128 long * fpixel=NULL) 129 { 130 throw FitsIOException( 131 "FitsBlockRW<string>::ReadImageData() string data type Unsupported for image HDU"); 132 } 116 133 117 /*! 118 Write character string data to binary/ascii HDU data in a fits file. 119 See cfitsio function fits_write_col() for more detail. 120 \param colnum : table column number (starting from 1) 121 \param firstrow : the write operation starting row (starting from 1) 122 \param firstelem : the firstelem (for vector type columns) 123 \param d : pointer to string type array to be written 124 \param sz : number of data elements to be written 125 \param width : column width 126 */ 127 void WriteStringColumnData(FitsInOutFile& fios, int colnum, long firstrow, 128 long firstelem, const string * d, size_t sz, 129 long width=0) 134 //! Write character string data to binary/ascii HDU data in a fits file. 135 static void WriteColumnData(FitsInOutFile& fios, int colnum, long firstrow, 136 long firstelem, const std::string * d, size_t sz) 130 137 { 131 138 int status = 0; 132 if (width < 1) width = 16; 139 char sbuff[1024]; 140 char * cp[4] = {sbuff, sbuff+256, sbuff+512, sbuff+768}; 141 //cout << " --- Getting in WriteColumnData<string>() colnum=" << colnum << endl; 133 142 for(size_t kk=0; kk<sz; kk++) { 134 char * cp = const_cast<char *>(d[kk].c_str()); 143 strncpy(sbuff, d[kk].c_str(), 1023); 144 // char * cp = const_cast<char *>(d[kk].c_str()); 145 sbuff[1023] = '\0'; 135 146 status = 0; 136 fits_write_col(fios.FitsPtr(), FitsTypes::DataType(cp), colnum, 137 firstrow+kk, firstelem, 1, &cp, &status); 147 //cout <<"DBG-Write2Fits : appel a fits_write_col() kk=" << kk << " / sz=" << sz << endl; 148 fits_write_col(fios.FitsPtr(), FitsTypes::DataType(sbuff), colnum, 149 firstrow+kk, firstelem, 1, cp, &status); 138 150 if ( status ) { 139 151 fits_report_error(stderr, status); 140 152 char buff[32]; 141 153 fits_get_errstatus(status, buff); 142 string msg = " WriteStringColumnDataError: " ;154 string msg = "FitsBlockRW<std::string>::WriteColumnData() Error: " ; 143 155 msg += buff; 144 156 sprintf(buff," kk=%ld",kk); msg += buff; … … 149 161 } 150 162 151 /*! 152 Read character string data to binary/ascii HDU data in a fits file. 153 See cfitsio function fits_read_col() for more detail. 154 \param colnum : table column number (starting from 1) 155 \param firstrow : the read operation starting point (row) (starting from 1) 156 \param firstelem : the firstelem (for vector type columns) 157 \param d : pointer to string type array to be read 158 \param sz : number of data elements to be read 159 \param width : column width 160 */ 161 void ReadStringColumnData(FitsInOutFile& fios, int colnum, long firstrow, 162 long firstelem, string * d, size_t sz, long width) 163 164 //! Read character string data to binary/ascii HDU data in a fits file. 165 static void ReadColumnData(FitsInOutFile& fios, int colnum, long firstrow, 166 long firstelem, std::string * d, size_t sz) 163 167 { 164 168 int status = 0; 165 169 int anynul = 0; 166 char buff[1024]; 170 char sbuff[1024]; 171 char * cp[4] = {sbuff, sbuff+256, sbuff+512, sbuff+768}; 172 // cout << " --- Getting in ReadColumnData<string>() colnum=" << colnum << endl; 167 173 for(size_t kk=0; kk<sz; kk++) { 168 fits_read_col(fios.FitsPtr(), FitsTypes::DataType(buff), colnum, 169 firstrow, firstelem+kk, 1, NULL, &buff, &anynul, &status); 170 d[kk] = buff; 174 // cout <<"DBG-ReadFrFits : appel a fits_read_col() kk=" << kk << " / sz=" << sz << endl; 175 fits_read_col(fios.FitsPtr(), FitsTypes::DataType(sbuff), colnum, 176 firstrow+kk, firstelem, 1, NULL, cp, &anynul, &status); 177 sbuff[1023] = '\0'; d[kk] = sbuff; 171 178 if ( status ) { 172 179 fits_report_error(stderr, status); 173 180 char buff[32]; 174 181 fits_get_errstatus(status, buff); 175 string msg = " ReadStringColumnDataError: " ;182 string msg = "FitsBlockRW<std::string>::ReadColumnData() Error: " ; 176 183 msg += buff; 177 184 sprintf(buff," kk=%ld",kk); msg += buff; … … 182 189 } 183 190 191 }; // Fin classe FitsBlockRW<std::string> 192 184 193 } // Fin du namespace 185 194
Note:
See TracChangeset
for help on using the changeset viewer.