Ignore:
Timestamp:
Nov 21, 2005, 9:32:49 AM (20 years ago)
Author:
ansari
Message:

Nouveau fits: Codage I/O colonnes string et complex (suite) + prise en charge dans handler FITS - Reza 21/11/2005

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fitsblkrw.h

    r2843 r2846  
    99  \ingroup FitsIOServer
    1010  \brief Template class with static methods for handling bloc data
    11   read from / write to fits files
     11  read from / write to fits filesz
    1212*/
    1313
     
    114114};
    115115
     116DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
     117class FitsBlockRW<std::string> {
     118public:
     119//! Write image HDU with string data type not supported (throws exception)
     120static 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)
     127static 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}
    116133
    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.
     135static void WriteColumnData(FitsInOutFile& fios, int colnum, long firstrow,
     136                            long firstelem, const std::string * d, size_t sz)
    130137{
    131138  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;
    133142  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';
    135146    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);
    138150    if ( status ) {
    139151      fits_report_error(stderr, status);
    140152      char buff[32];
    141153      fits_get_errstatus(status, buff);
    142       string msg = "WriteStringColumnData Error: " ;
     154      string msg = "FitsBlockRW<std::string>::WriteColumnData() Error: " ;
    143155      msg += buff;
    144156      sprintf(buff," kk=%ld",kk);  msg += buff;
     
    149161}
    150162
    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.
     165static void ReadColumnData(FitsInOutFile& fios, int colnum, long firstrow,
     166                           long firstelem, std::string * d, size_t sz)
    163167{
    164168  int status = 0;
    165169  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;
    167173  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;
    171178    if ( status ) {
    172179      fits_report_error(stderr, status);
    173180      char buff[32];
    174181      fits_get_errstatus(status, buff);
    175       string msg = "ReadStringColumnData Error: " ;
     182      string msg = "FitsBlockRW<std::string>::ReadColumnData() Error: " ;
    176183      msg += buff;
    177184      sprintf(buff," kk=%ld",kk);  msg += buff;
     
    182189}
    183190
     191};  // Fin classe   FitsBlockRW<std::string>
     192
    184193} // Fin du namespace
    185194
Note: See TracChangeset for help on using the changeset viewer.