Changeset 1136 in Sophya for trunk/SophyaExt/FitsIOServer


Ignore:
Timestamp:
Aug 24, 2000, 12:18:02 PM (25 years ago)
Author:
ansari
Message:

structuration a la ppersist+ convention sur hdu

Location:
trunk/SophyaExt/FitsIOServer
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.cc

    r1048 r1136  
    2020
    2121  //  FitsFile* fn=ReadFInit(inputfile,hdunum);
    22   ReadFInit(inputfile,hdunum);
    23 
     22  //  ReadFInit(inputfile,hdunum);
     23  inFits_  = new FitsInFile (inputfile);
     24  inFits_->ReadFInit(hdunum);
    2425
    2526  //  if (!fn->IsFitsTable())
    26   if (!IsFitsTable())
     27  if (!inFits_->IsFitsTable())
    2728    {
    2829      throw PException("FITS_BntblLineReader: the fits file seems not to be a bintable nor ASCII table");
     
    3233  int nbcols, nbentries;
    3334  //  nbcols = fn->NbColsFromFits();
    34   nbcols = NbColsFromFits();
     35  nbcols = inFits_->NbColsFromFits();
    3536  nbentries = 0;
    3637  int k;
    3738  //  for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn->NentriesFromFits(k) );
    38   for (k=0; k<nbcols; k++) nbentries=max( nbentries, NentriesFromFits(k) );
     39  for (k=0; k<nbcols; k++) nbentries=max( nbentries, inFits_->NentriesFromFits(k) );
    3940
    4041  //
     
    5354    {
    5455      //      char ss= fn->ColTypeFromFits(k);
    55       char ss= ColTypeFromFits(k);
     56      char ss= inFits_->ColTypeFromFits(k);
    5657      if (ss == 'D') DfitsCol.push_back(k);
    5758      else if (ss == 'E') FfitsCol.push_back(k);
     
    6970      ColName_[compt] = new char[LONNOM+1];
    7071      //      strncpy(ColName_[compt], fn->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
    71       strncpy(ColName_[compt], ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
     72      strncpy(ColName_[compt], inFits_->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
    7273      ColName_[compt++][ LONNOM] =  '\0';
    7374    }
     
    7677      ColName_[compt] = new char[LONNOM+1];
    7778      //      strncpy(ColName_[compt], fn->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
    78       strncpy(ColName_[compt], ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
     79      strncpy(ColName_[compt], inFits_->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
    7980      ColName_[compt++][ LONNOM] =  '\0';
    8081    }
     
    8384      ColName_[compt] = new char[LONNOM+1];
    8485      //      strncpy(ColName_[compt], fn->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
    85       strncpy(ColName_[compt], ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
     86      strncpy(ColName_[compt], inFits_->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
    8687      ColName_[compt++][ LONNOM] =  '\0';
    8788    }
     
    9091      ColName_[compt] = new char[LONNOM+1];
    9192      //      strncpy(ColName_[compt], fn->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
    92       strncpy(ColName_[compt], ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
     93      strncpy(ColName_[compt], inFits_->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
    9394      ColName_[compt++][LONNOM] =  '\0';
    9495    }
     
    115116      taille_des_chaines_ = 0;
    116117      //      for (k=0; k< ccount_; k++)  taille_des_chaines_ = max( taille_des_chaines_, fn->ColStringLengthFromFits(SfitsCol[k]) );
    117       for (k=0; k< ccount_; k++)  taille_des_chaines_ = max( taille_des_chaines_, ColStringLengthFromFits(SfitsCol[k]) );
     118      for (k=0; k< ccount_; k++)  taille_des_chaines_ = max( taille_des_chaines_, inFits_->ColStringLengthFromFits(SfitsCol[k]) );
    118119      for (k=0; k<ccount_; k++) cdata_[k]=new char[taille_des_chaines_+1];
    119120    }
     
    123124FITS_BntblLineReader::~FITS_BntblLineReader()
    124125{
     126  if (inFits_ != NULL) delete inFits_;
    125127  if (ddata_ != NULL) delete [] ddata_;
    126128  if (fdata_ != NULL) delete [] fdata_;
     
    147149XNTuple FITS_BntblLineReader::ReadNextLine()
    148150{
    149   GetBinTabLine(nextLineToBeRead_++, ddata_, fdata_, idata_, cdata_ );
     151  inFits_->GetBinTabLine(nextLineToBeRead_++, ddata_, fdata_, idata_, cdata_ );
    150152  XNTuple xnt(dcount_, fcount_, icount_,ccount_, ColName_);
    151153  xnt.Fill(ddata_, fdata_, idata_, cdata_);   
     
    153155}
    154156
    155 void  FITS_BntblLineReader::ReadFromFits()
     157void  FITS_BntblLineReader::ReadFromFits(FitsInFile&)
    156158{   
    157159}
    158160
    159 void FITS_BntblLineReader::WriteToFits()
     161void FITS_BntblLineReader::WriteToFits(FitsOutFile&)
    160162{
    161163}
  • trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.h

    r1048 r1136  
    1313///////////////////////////////////////////////////////////
    1414
    15 class  FITS_BntblLineReader : public FitsFile 
     15class  FITS_BntblLineReader : public FitsIOHandler 
    1616{
    1717
     
    2525 inline  void SetStartingLineIndex(long n)  { nextLineToBeRead_ = n;}
    2626
    27  inline int status() const {return statusF();};
    28  inline string getStatus(int status) const {return getErrStatus(status);};
     27 inline int status() const {return inFits_->statusF();};
     28 inline string getStatus(int status) const {return inFits_->getErrStatus(status);};
    2929
    3030
     
    3434  // implementation de FitsFile
    3535 //  virtual void  ReadFromFits(FitsFile& fn);
    36   virtual void  ReadFromFits();
    37 virtual void    WriteToFits();
     36  virtual void  ReadFromFits(FitsInFile& is);
     37virtual void    WriteToFits(FitsOutFile& os);
    3838
    3939 private :
     
    4141inline void InitNull()
    4242   {
     43     inFits_ = NULL;
    4344     nextLineToBeRead_= 0;
    4445     dcount_ = 0;
     
    5455   }
    5556  // attributs de classe
     57
     58 FitsInFile* inFits_;
    5659  long nextLineToBeRead_;
    5760  int dcount_;
  • trunk/SophyaExt/FitsIOServer/fitsfile.cc

    r1082 r1136  
    66#include "anydataobj.h"
    77#include "fitsspherehealpix.h"
    8 FitsFile::FitsFile()
    9 {
    10   InitNull();
    11 }
     8
     9
     10void   FitsIOHandler::Read(char flnm[],int hdunum)
     11{
     12  //  FitsInFile ifts(flnm, hdunum);
     13  FitsInFile ifts(flnm);
     14  Read(ifts, hdunum);
     15}
     16void FitsIOHandler::Read(FitsInFile& is, int hdunum)
     17{
     18  if (hdunum == 0)  is.moveToFollowingHeader();
     19  else is.ReadFInit(hdunum);
     20  ReadFromFits(is);
     21}
     22
     23
     24void FitsIOHandler::Write(char flnm[], bool OldFile)
     25
     26{
     27
     28  FitsOutFile of(flnm, OldFile);
     29  Write(of);
     30}
     31
     32void FitsIOHandler::Write(FitsOutFile& os)
     33{
     34  WriteToFits(os);
     35}
     36
     37
     38
    1239 
    1340FitsFile::~FitsFile()
    1441{
     42  cout << " destructeur FitsFile " << endl;
    1543  int status = 0;
    1644  if( fptr_ != NULL)
     
    2250}
    2351
    24 void FitsFile::InitNull()
    25 {
    26   fptr_= NULL;
    27   hdutype_= 0;
    28   hdunum_ = 0;
    29 
     52
     53void FitsFile::printerror(int &status)
     54  //*****************************************************/
     55  //* Print out cfitsio error messages and exit program */
     56  //*****************************************************/
     57{
     58  if( status )
     59    {
     60      fits_report_error(stderr,status);
     61      throw IOExc("FitsFile:: error FITSIO status");
     62    }
     63  return;
     64}
     65
     66void FitsFile::printerror(int& status, char* texte)
     67  //*****************************************************/
     68  //* Print out cfitsio error messages and exit program */
     69  //*****************************************************/
     70{
     71  // print out cfitsio error messages and exit program
     72  // print error report 
     73  fits_report_error(stderr, status);
     74  cout << " erreur:: " << texte << endl;
     75  throw IOExc("FitsFile:: error FITSIO status");
     76}
     77
     78void FitsFile::ResetStatus(int& status)
     79{
     80  fits_status_ = status;
     81  status = 0;
     82}
     83
     84string FitsFile::getErrStatus(int status)
     85{
     86  char text[31];
     87  fits_get_errstatus(status, text);
     88  return string(text);
     89}
     90
     91FitsInFile::FitsInFile()
     92{
     93  InitNull();
     94}
     95//FitsInFile::FitsInFile(char flnm[], int hdunum)
     96FitsInFile::FitsInFile(char flnm[])
     97{
     98  InitNull();
     99  int status = 0;
     100  fits_open_file(&fptr_,flnm,READONLY,&status);
     101  if( status ) printerror( status );
     102  //  ReadFInit(flnm, hdunum);
     103}
     104
     105
     106void FitsInFile::InitNull()
     107{
     108  cout << " init FitsInFile " << endl;
    30109  bitpix_ = 0;
    31110  naxis_ = 0;
     
    33112  nrows_ = 0;
    34113  nbcols_ = 0;
    35   fits_status_ = 0;
    36114  naxisn_.clear();
    37115  repeat_.clear();
     
    42120
    43121
    44 int FitsFile::NbBlocks(char flnm[])
     122int FitsInFile::NbBlocks(char flnm[])
    45123{
    46124  int status = 0;
     
    54132}
    55133
    56 void FitsFile::getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
     134void FitsInFile::getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
    57135{
    58136  int status = 0;
     
    123201}
    124202
    125 void FitsFile::ReadF(char flnm[],int hdunum)
    126 {
    127   ReadFInit(flnm, hdunum);
    128   //  ReadFromFits(*this);
    129     ReadFromFits();
    130 }
    131 
    132 
    133 //FitsFile* FitsFile::ReadFInit(char flnm[],int hdunum)
    134 void FitsFile::ReadFInit(char flnm[],int hdunum)
    135 {
    136   InitNull();
    137   int status = 0;
    138   //  hdutype_= 0;
     203void FitsInFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
     204{
     205  int hdunum=0;
     206  cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
     207  int status= 0;
     208
     209  // bits per pixels
     210  fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
     211  if( status )  printerror( status );
     212
     213  // number of dimensions in the FITS array
     214  naxis= 0;
     215  fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
     216  if( status ) printerror( status );
     217  //  cout << " dimension lue " << naxis << endl;
     218  // read the NAXISn keywords to get image size
     219  long* naxes = new long[naxis] ;
     220  int nfound;
     221  fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
     222  if( status ) printerror( status );
     223  if (nfound != naxis )
     224    cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
     225  int k;
     226  for (k=0; k<naxis; k++)
     227    {
     228      naxisn.push_back( (int)naxes[k] );
     229    }
     230  delete [] naxes;
     231}
     232
     233
     234//void FitsInFile::ReadFInit(char flnm[],int hdunum)
     235void FitsInFile::ReadFInit(int hdunum)
     236{
     237  // InitNull();
     238  // int status = 0;
    139239 
    140   fits_open_file(&fptr_,flnm,READONLY,&status);
    141   if( status ) printerror( status );
    142   //
     240  //  fits_open_file(&fptr_,flnm,READONLY,&status);
     241  //  if( status ) printerror( status );
     242
     243  int status = 0;
     244
    143245  if (hdunum <= 1)
    144246    {
     
    171273      moveToFollowingHeader();
    172274    }
    173   //  return this;
    174 }
    175 
    176 void FitsFile::moveToFollowingHeader()
     275}
     276
     277
     278
     279void FitsInFile::moveToFollowingHeader()
    177280{
    178281  int status = 0;
     
    197300}
    198301
    199  
    200 void FitsFile::WriteF(char flnm[], bool OldFile)
    201 {
    202   int status = 0;
    203   hdutype_= 0;
    204   hdunum_ = 0;
    205 
    206  
    207   // create new FITS file
    208   if (!OldFile)
    209     {
    210       fits_create_file(&fptr_,flnm,&status);
    211       if( status ) printerror(status,"file already exists");
    212     }
     302
     303int  FitsInFile::NbColsFromFits() const
     304{
     305  if(hdutype_ ==  BINARY_TBL) return nbcols_;
    213306  else
    214     {
    215       fits_open_file(&fptr_,flnm,READWRITE,&status);
    216       if( status ) printerror(status,"file does not exist");
    217       fits_get_num_hdus(fptr_, &hdunum_, &status);
    218       int hdutype;
    219       fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    220       if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
    221 
    222     }
    223   //  WriteToFits(*this);
    224   WriteToFits();
    225 }
    226 void FitsFile::GetSingleColumn(double* map, int nentries) const
     307    if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
     308    else
     309      {
     310        cout << " hdutype= " << hdutype_ << endl;
     311        throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
     312      }
     313}
     314
     315int FitsInFile::NentriesFromFits(int nocol) const
     316{
     317  if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
     318  else
     319    if(hdutype_ == ASCII_TBL) return nrows_;
     320    else
     321      if(hdutype_ == IMAGE_HDU) return nbData_;
     322      else
     323        {
     324          cout << "hdutype= " << hdutype_ << endl;
     325          throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
     326        }
     327}
     328
     329char FitsInFile::ColTypeFromFits(int nocol) const
     330{
     331  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     332    {
     333      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     334    }
     335  return types_[nocol];
     336}
     337string FitsInFile::ColNameFromFits(int nocol) const
     338{
     339  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     340    {
     341      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     342    }
     343  return noms_[nocol];
     344}
     345
     346int FitsInFile::ColStringLengthFromFits(int nocol) const
     347{
     348  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     349    {
     350      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
     351    }
     352  int index=-1;
     353  int k;
     354  for (k=0; k<=nocol; k++)
     355    {
     356      if (types_[k] == 'S') index++;
     357    }
     358  return  taille_des_chaines_[index];
     359}
     360void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
     361{
     362  int status= 0;
     363  int    anull;
     364  double dnull= 0.;
     365  float fnull= 0.;
     366  int inull= 0;
     367  char* cnull= "";
     368  int dcount = 0.;
     369  int fcount = 0.;
     370  int icount = 0;
     371  int ccount =0;
     372  int ncol;
     373  long nels=1;
     374  for (ncol=0; ncol<nbcols_; ncol++)
     375    {
     376      switch (types_[ncol])
     377        {
     378        case 'D' :
     379          fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
     380            break;
     381        case 'E' :
     382          fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
     383          break;
     384        case 'I' :
     385          fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
     386                        &anull,&status);
     387          break;
     388        case 'S' :
     389          fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
     390          break;
     391        }
     392      if (status)
     393        {
     394          ResetStatus(status);
     395          break;
     396        }
     397    }
     398}
     399
     400void FitsInFile::GetBinTabLine(int NoLine, float* fdata)
     401{
     402  int status= 0;
     403  int    anull;
     404  float fnull= 0.;
     405  long nels=1;
     406  int ncol;
     407  for (ncol=0; ncol<nbcols_; ncol++)
     408    {
     409      fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
     410      if (status)
     411        {
     412          ResetStatus(status);
     413          break;
     414        }
     415    }
     416}
     417
     418
     419void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
     420    {
     421      int status= 0;
     422      int DTYPE;
     423      long repeat,width;
     424            fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
     425      if( DTYPE != TDOUBLE)
     426        {
     427          if (DTYPE == TFLOAT)  cout << " WARNING: reading double from float : conversion will be made by fitsio library" << endl;
     428          else
     429            throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
     430        }
     431      long nels=nentries;
     432      int    anull;
     433      // no checking for undefined pixels
     434      double dnull= 0.;
     435      //     fits_read_key(fptr_,TDOUBLE,"BAD_DATA",&dnull,NULL,&status);
     436      //  if (status != 0)
     437      //        {
     438      //          dnull = -1.6375e30;  // default value
     439      //          status = 0;
     440      //        }
     441      if (nentries != nrows_*repeat)
     442        {
     443          cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
     444          throw PException(" FitsFile:::GetBinTabFCol ");
     445        }
     446      fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
     447                            &anull,&status);
     448      if( status ) printerror( status,"erreur lecture de colonne" );
     449     
     450    }
     451
     452void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
     453    {
     454      int status= 0;
     455      int DTYPE;
     456      long repeat,width;
     457      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
     458      if( DTYPE != TFLOAT)
     459        {
     460          if (DTYPE == TDOUBLE)  cout << " WARNING: reading float from double : conversion will be made by fitsio library" << endl;
     461          else
     462            throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
     463        }
     464      long nels=nentries;
     465      int    anull;
     466      // no checking for undefined pixels
     467      float fnull= 0.;
     468      //     fits_read_key(fptr_,TFLOAT,"BAD_DATA",&fnull,NULL,&status);
     469      //    if (status != 0)
     470      //        {
     471      //          fnull = -1.6375e30;  // default value
     472      //          status = 0;
     473      //        }
     474      if (nentries != nrows_*repeat)
     475        {
     476          cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
     477          throw PException(" FitsFile:::GetBinTabFCol ");
     478        }
     479      fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
     480                            &anull,&status);
     481      if( status ) printerror( status,"erreur lecture de colonne" );
     482    }
     483
     484void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
     485    {
     486      cout <<" entree GetBinTabFCol " << endl;
     487      int status= 0;
     488      int DTYPE;
     489      long repeat,width;
     490      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
     491      if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT )
     492        {
     493          throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
     494        }
     495      long nels=nentries;
     496      // no checking for undefined pixels
     497      int    anull;
     498      int inull= 0;
     499      //     fits_read_key(fptr_,TINT,"BAD_DATA",&inull,NULL,&status);
     500      //     if (status != 0)
     501      //        {
     502      //          inull = -999999;  // default value
     503      //          status = 0;
     504      //        }
     505      if (nentries != nrows_*repeat)
     506        {
     507          cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
     508          throw PException(" FitsFile:::GetBinTabFCol ");
     509        }
     510      fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
     511                            &anull,&status);
     512      if( status ) printerror( status,"erreur lecture de colonne" );
     513    }
     514
     515void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
     516    {
     517      int status= 0;
     518      int DTYPE;
     519      long repeat,width;
     520      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
     521      if( DTYPE != TSTRING )
     522        {
     523          throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
     524        }
     525      long nels=nentries;
     526      // no checking for undefined pixels
     527      int    anull;
     528      char* cnull= "";
     529      if (nentries != nrows_*repeat/width)
     530        {
     531          cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat/width << endl;
     532          throw PException(" FitsFile:::GetBinTabFCol ");
     533        }
     534      long frow=1;
     535      long felem=1;
     536      fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
     537                    &anull,&status);
     538      if( status ) printerror( status,"erreur lecture de colonne" );
     539    }
     540
     541void FitsInFile::GetSingleColumn(double* map, int nentries) const
    227542{
    228543  int status = 0;
     
    256571}
    257572
    258 void FitsFile::GetSingleColumn(float* map, int nentries) const
     573void FitsInFile::GetSingleColumn(float* map, int nentries) const
    259574{
    260575  int status = 0;
     
    286601}
    287602
    288 void FitsFile::GetSingleColumn( int* map, int nentries) const
     603void FitsInFile::GetSingleColumn( int* map, int nentries) const
    289604{
    290605  int status = 0;
     
    315630      }
    316631}
    317 void FitsFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn)
    318 {
    319   int status = 0;
    320   long naxis = nbdim;
    321   long* naxes = new long[nbdim];
    322   if (hdunum_ == 0)
    323     {
    324       fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
    325       hdunum_ = 1;
    326     }
    327   int k;
    328   for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k];
    329   if (type == 'D')
    330     fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status);
    331   else
    332     if  (type == 'E')
    333       fits_create_img(fptr_,FLOAT_IMG,naxis,naxes,&status);
    334     else
    335       if  (type == 'I')
    336         fits_create_img(fptr_,LONG_IMG,naxis,naxes,&status);
    337       else
    338         {
    339           cout << " type of data: " << type << endl;
    340           throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
    341         }
    342 
    343   hdunum_++;
    344   delete [] naxes;
    345   if( status ) printerror( status, "erreur creation HDU IMAGE"  );
    346 
    347 }
    348 void FitsFile::putImageToFits(int nbData, double* map) const
    349 {
    350   int status = 0;
    351   long npix= nbData;
    352   fits_write_img(fptr_,TDOUBLE,1,npix,map,&status);
    353   if( status ) printerror( status, "erreur ecriture putImageToFits" );
    354   writeSignatureOnFits();
    355 }
    356 
    357 void FitsFile::putImageToFits(int nbData, float* map) const
    358 {
    359   int status = 0;
    360   long npix= nbData;
    361   fits_write_img(fptr_,TFLOAT,1,npix, map,&status);
    362   if( status ) printerror( status, "erreur ecriture putImageToFits" );
    363   writeSignatureOnFits();
    364 
    365 }
    366 void FitsFile::putImageToFits( int nbData, int* map) const
    367 {
    368   int status = 0;
    369 
    370   long npix= nbData;
    371   fits_write_img(fptr_,TINT,1,npix,map,&status);
    372   if( status ) printerror( status, "erreur ecriture putImageToFits" );
    373   writeSignatureOnFits();
    374 }
    375 
    376 
    377 
    378 void FitsFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
    379 {
     632
     633void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
     634                                  vector<int>& repeat,
     635                                  vector<string>& noms,
     636                                  vector<char>& types,   
     637                                  vector<int>&  taille_des_chaines)
     638{
     639  int status= 0;
    380640  int hdunum=0;
    381   cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
    382   int status= 0;
    383 
    384   // bits per pixels
    385   fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
    386   if( status )  printerror( status );
    387 
    388   // number of dimensions in the FITS array
    389   naxis= 0;
    390   fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
     641  int hdutype=0;
     642  fits_get_hdu_num(fileptr,&hdunum);
     643  fits_get_hdu_type(fileptr, &hdutype, &status);
     644
     645  if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
     646    {
     647      throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
     648    }
     649  if(hdutype == ASCII_TBL)
     650    cout << " Reading a FITS ascii table in HDU : " << hdunum << endl; 
     651  if(hdutype == BINARY_TBL)
     652    cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
     653
     654  // get the number of columns
     655  fits_get_num_cols(fileptr, &nbcols,&status);
    391656  if( status ) printerror( status );
    392657
    393   // read the NAXISn keywords to get image size
    394   long* naxes = new long[naxis] ;
     658  // get the number of rows
     659  long naxis2= 0;
     660  fits_get_num_rows(fileptr,&naxis2,&status);
     661  if( status ) printerror( status );
     662  nrows = (int)naxis2;
     663
     664  // get the datatype,  names and the repeat count
     665  noms.clear();
     666  noms.reserve(nbcols);
     667  types.clear();
     668  types.reserve(nbcols);
     669  repeat.clear();
     670  repeat.reserve(nbcols);
     671  taille_des_chaines.clear();
     672  char **ttype = new char*[nbcols];
     673  int ii;
     674  for (ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
    395675  int nfound;
    396   fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
    397   if( status ) printerror( status );
    398   if (nfound != naxis )
    399     cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
    400   int k;
    401   for (k=0; k<naxis; k++)
    402     {
    403       naxisn.push_back( (int)naxes[k] );
    404     }
    405   delete [] naxes;
    406 }
    407 
    408 void FitsFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum)
     676  fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
     677  if( status ) printerror( status,"erreur lecture des noms de colonne");
     678  int rept=0;
     679  for(ii = 0; ii <  nbcols; ii++)
     680    {
     681      int DTYPE;
     682      long width;
     683      long repete = 0;
     684      fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
     685      if( status ) printerror( status,"erreur lecture type de colonne");
     686      rept = repete;
     687      noms.push_back(string(ttype[ii]));
     688      switch (DTYPE)
     689        {
     690        case TDOUBLE :
     691          types.push_back('D');
     692          break;
     693        case TFLOAT :
     694          types.push_back('E');
     695          break;
     696        case TLONG :
     697          types.push_back('I');
     698          break;
     699        case TINT :
     700          types.push_back('I');
     701          break;
     702        case TSHORT :
     703          types.push_back('I');
     704          break;
     705        case TSTRING :
     706          types.push_back('S');
     707          taille_des_chaines.push_back(width);
     708          rept/=width;
     709          break;
     710        default :
     711          cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
     712          throw IOExc("FitsFile:: unknown type of field");
     713        }
     714      repeat.push_back(rept);
     715    }
     716  for (ii=0; ii < nbcols; ii++) delete [] ttype[ii];
     717  delete [] ttype;
     718}
     719
     720void FitsInFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum)
    409721{
    410722  int status = 0;
     
    473785}
    474786
    475 
    476  
    477   void FitsFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
    478     {
    479       int status= 0;
    480       int DTYPE;
    481       long repeat,width;
    482             fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
    483       if( DTYPE != TDOUBLE)
    484         {
    485           if (DTYPE == TFLOAT)  cout << " WARNING: reading double from float : conversion will be made by fitsio library" << endl;
    486           else
    487             throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
    488         }
    489       long nels=nentries;
    490       int    anull;
    491       // no checking for undefined pixels
    492       double dnull= 0.;
    493       //     fits_read_key(fptr_,TDOUBLE,"BAD_DATA",&dnull,NULL,&status);
    494       //  if (status != 0)
    495       //        {
    496       //          dnull = -1.6375e30;  // default value
    497       //          status = 0;
    498       //        }
    499       if (nentries != nrows_*repeat)
    500         {
    501           cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
    502           throw PException(" FitsFile:::GetBinTabFCol ");
    503         }
    504       fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
    505                             &anull,&status);
    506       if( status ) printerror( status,"erreur lecture de colonne" );
    507      
    508     }
    509 
    510   void FitsFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
    511     {
    512       int status= 0;
    513       int DTYPE;
    514       long repeat,width;
    515       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
    516       if( DTYPE != TFLOAT)
    517         {
    518           if (DTYPE == TDOUBLE)  cout << " WARNING: reading float from double : conversion will be made by fitsio library" << endl;
    519           else
    520             throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
    521         }
    522       long nels=nentries;
    523       int    anull;
    524       // no checking for undefined pixels
    525       float fnull= 0.;
    526       //     fits_read_key(fptr_,TFLOAT,"BAD_DATA",&fnull,NULL,&status);
    527       //    if (status != 0)
    528       //        {
    529       //          fnull = -1.6375e30;  // default value
    530       //          status = 0;
    531       //        }
    532       if (nentries != nrows_*repeat)
    533         {
    534           cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
    535           throw PException(" FitsFile:::GetBinTabFCol ");
    536         }
    537       fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
    538                             &anull,&status);
    539       if( status ) printerror( status,"erreur lecture de colonne" );
    540     }
    541   void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
    542     {
    543       cout <<" entree GetBinTabFCol " << endl;
    544       int status= 0;
    545       int DTYPE;
    546       long repeat,width;
    547       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
    548       if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT )
    549         {
    550           throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
    551         }
    552       long nels=nentries;
    553       // no checking for undefined pixels
    554       int    anull;
    555       int inull= 0;
    556       //     fits_read_key(fptr_,TINT,"BAD_DATA",&inull,NULL,&status);
    557       //     if (status != 0)
    558       //        {
    559       //          inull = -999999;  // default value
    560       //          status = 0;
    561       //        }
    562       if (nentries != nrows_*repeat)
    563         {
    564           cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
    565           throw PException(" FitsFile:::GetBinTabFCol ");
    566         }
    567       fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
    568                             &anull,&status);
    569       if( status ) printerror( status,"erreur lecture de colonne" );
    570     }
    571   void FitsFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
    572     {
    573       int status= 0;
    574       int DTYPE;
    575       long repeat,width;
    576       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
    577       if( DTYPE != TSTRING )
    578         {
    579           throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
    580         }
    581       long nels=nentries;
    582       // no checking for undefined pixels
    583       int    anull;
    584       char* cnull= "";
    585       if (nentries != nrows_*repeat/width)
    586         {
    587           cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat/width << endl;
    588           throw PException(" FitsFile:::GetBinTabFCol ");
    589         }
    590       long frow=1;
    591       long felem=1;
    592       fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
    593                     &anull,&status);
    594       if( status ) printerror( status,"erreur lecture de colonne" );
    595     }
    596 
    597 
    598 
    599 void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
    600 {
    601   int status= 0;
    602   int    anull;
    603   double dnull= 0.;
    604   float fnull= 0.;
    605   int inull= 0;
    606   char* cnull= "";
    607   int dcount = 0.;
    608   int fcount = 0.;
    609   int icount = 0;
    610   int ccount =0;
    611   int ncol;
    612   long nels=1;
    613   for (ncol=0; ncol<nbcols_; ncol++)
    614     {
    615       switch (types_[ncol])
    616         {
    617         case 'D' :
    618           fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
    619             break;
    620         case 'E' :
    621           fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
    622           break;
    623         case 'I' :
    624           fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
    625                         &anull,&status);
    626           break;
    627         case 'S' :
    628           fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
    629           break;
    630         }
    631       if (status)
    632         {
    633           ResetStatus(status);
    634           break;
    635         }
    636       //          if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne char" );
    637     }
    638 }
    639 
    640 void FitsFile::GetBinTabLine(int NoLine, float* fdata)
    641 {
    642   int status= 0;
    643   int    anull;
    644   float fnull= 0.;
    645   long nels=1;
    646   int ncol;
    647   for (ncol=0; ncol<nbcols_; ncol++)
    648     {
    649       fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
    650       if (status)
    651         {
    652           ResetStatus(status);
    653           break;
    654         }
    655        //      if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
    656     }
    657 }
    658 
    659      
    660 
    661 
    662 
    663 
    664 
    665 
    666 int  FitsFile::NbColsFromFits() const
    667 {
    668   if(hdutype_ ==  BINARY_TBL) return nbcols_;
     787FitsOutFile::FitsOutFile()
     788{
     789  InitNull();
     790}
     791
     792FitsOutFile::FitsOutFile(char flnm[], bool OldFile)
     793{
     794
     795  InitNull();
     796  int status = 0;
     797
     798  // create new FITS file
     799  if (!OldFile)
     800    {
     801      fits_create_file(&fptr_,flnm,&status);
     802      if( status ) printerror(status,"file already exists");
     803    }
    669804  else
    670     if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
     805    {
     806      fits_open_file(&fptr_,flnm,READWRITE,&status);
     807      if( status ) printerror(status,"file does not exist");
     808      fits_get_num_hdus(fptr_, &hdunum_, &status);
     809      int hdutype;
     810      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
     811      if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
     812
     813    }
     814
     815}
     816
     817
     818
     819void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn)
     820{
     821  int status = 0;
     822  long naxis = nbdim;
     823  long* naxes = new long[nbdim];
     824  if (hdunum_ == 1)
     825    {
     826      if (imageOnPrimary_ == false) fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
     827      else  hdunum_--;
     828    }
     829  int k;
     830  for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k];
     831  if (type == 'D')
     832    fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status);
     833  else
     834    if  (type == 'E')
     835      fits_create_img(fptr_,FLOAT_IMG,naxis,naxes,&status);
    671836    else
    672       {
    673         cout << " hdutype= " << hdutype_ << endl;
    674         throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
    675       }
    676 }
    677 
    678 char FitsFile::ColTypeFromFits(int nocol) const
    679 {
    680   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
    681     {
    682       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
    683     }
    684   return types_[nocol];
    685 }
    686 int FitsFile::NentriesFromFits(int nocol) const
    687 {
    688   if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
    689   else
    690     if(hdutype_ == ASCII_TBL) return nrows_;
    691     else
    692       if(hdutype_ == IMAGE_HDU) return nbData_;
     837      if  (type == 'I')
     838        fits_create_img(fptr_,LONG_IMG,naxis,naxes,&status);
    693839      else
    694840        {
    695           cout << "hdutype= " << hdutype_ << endl;
    696           throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
    697         }
    698 }
    699 
    700 string FitsFile::ColNameFromFits(int nocol) const
    701 {
    702   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
    703     {
    704       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
    705     }
    706   return noms_[nocol];
    707 }
    708 int FitsFile::ColStringLengthFromFits(int nocol) const
    709 {
    710   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
    711     {
    712       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
    713     }
    714   int index=-1;
    715   int k;
    716   for (k=0; k<=nocol; k++)
    717     {
    718       if (types_[k] == 'S') index++;
    719     }
    720   return  taille_des_chaines_[index];
    721 }
    722 
    723 
    724 
    725 void FitsFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
    726                                   vector<int>& repeat,
    727                                   vector<string>& noms,
    728                                   vector<char>& types,   
    729                                   vector<int>&  taille_des_chaines)
    730 {
    731   int status= 0;
    732   int hdunum=0;
    733   int hdutype=0;
    734   fits_get_hdu_num(fileptr,&hdunum);
    735   fits_get_hdu_type(fileptr, &hdutype, &status);
    736 
    737   if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
    738     {
    739       throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
    740     }
    741   if(hdutype == ASCII_TBL)
    742     cout << " Reading a FITS ascii table in HDU : " << hdunum << endl; 
    743   if(hdutype == BINARY_TBL)
    744     cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
    745 
    746   // get the number of columns
    747   fits_get_num_cols(fileptr, &nbcols,&status);
    748   if( status ) printerror( status );
    749 
    750   // get the number of rows
    751   long naxis2= 0;
    752   fits_get_num_rows(fileptr,&naxis2,&status);
    753   if( status ) printerror( status );
    754   nrows = (int)naxis2;
    755 
    756   // get the datatype,  names and the repeat count
    757   noms.clear();
    758   noms.reserve(nbcols);
    759   types.clear();
    760   types.reserve(nbcols);
    761   repeat.clear();
    762   repeat.reserve(nbcols);
    763   taille_des_chaines.clear();
    764   char **ttype = new char*[nbcols];
    765   int ii;
    766   for (ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
    767   int nfound;
    768   fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
    769   if( status ) printerror( status,"erreur lecture des noms de colonne");
    770   int rept=0;
    771   for(ii = 0; ii <  nbcols; ii++)
    772     {
    773       int DTYPE;
    774       long width;
    775       long repete = 0;
    776       fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
    777       if( status ) printerror( status,"erreur lecture type de colonne");
    778       rept = repete;
    779       noms.push_back(string(ttype[ii]));
    780       switch (DTYPE)
    781         {
    782         case TDOUBLE :
    783           types.push_back('D');
    784           break;
    785         case TFLOAT :
    786           types.push_back('E');
    787           break;
    788         case TLONG :
    789           types.push_back('I');
    790           break;
    791         case TINT :
    792           types.push_back('I');
    793           break;
    794         case TSHORT :
    795           types.push_back('I');
    796           break;
    797         case TSTRING :
    798           types.push_back('S');
    799           taille_des_chaines.push_back(width);
    800           rept/=width;
    801           break;
    802         default :
    803           cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
    804           throw IOExc("FitsFile:: unknown type of field");
    805         }
    806       repeat.push_back(rept);
    807     }
    808 }
    809 
    810 
    811 
    812 void FitsFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines)
     841          cout << " type of data: " << type << endl;
     842          throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
     843        }
     844
     845  hdunum_++;
     846  delete [] naxes;
     847  if( status ) printerror( status, "erreur creation HDU IMAGE"  );
     848
     849}
     850void FitsOutFile::putImageToFits(int nbData, double* map) const
     851{
     852  int status = 0;
     853  long npix= nbData;
     854  fits_write_img(fptr_,TDOUBLE,1,npix,map,&status);
     855  if( status ) printerror( status, "erreur ecriture putImageToFits" );
     856  writeSignatureOnFits();
     857}
     858
     859void FitsOutFile::putImageToFits(int nbData, float* map) const
     860{
     861  int status = 0;
     862  long npix= nbData;
     863  fits_write_img(fptr_,TFLOAT,1,npix, map,&status);
     864  if( status ) printerror( status, "erreur ecriture putImageToFits" );
     865  writeSignatureOnFits();
     866
     867}
     868void FitsOutFile::putImageToFits( int nbData, int* map) const
     869{
     870  int status = 0;
     871
     872  long npix= nbData;
     873  fits_write_img(fptr_,TINT,1,npix,map,&status);
     874  if( status ) printerror( status, "erreur ecriture putImageToFits" );
     875  writeSignatureOnFits();
     876}
     877
     878
     879
     880void FitsOutFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines)
    813881{
    814882  int status = 0;
     
    817885    {
    818886      cout << " nombre de champs :" << tfields << "nombre de types: " << strlen(fieldType) << endl;
    819               throw ParmError("FitsFile:: fields and types don't match");
     887      throw ParmError("FitsFile:: fields and types don't match");
    820888
    821889    }
     
    824892  char largeur[FLEN_VALUE];
    825893  int noColString=0;
    826 
    827 
    828894  int k;
    829895  for (k=0; k<tfields;k++)
     
    847913          if (fieldType[k] == 'A')
    848914            {
    849             char largaux[FLEN_VALUE];
    850             sprintf(largeur,"%d",taille_des_chaines[noColString]);
    851             sprintf(largaux,"%d",1024*taille_des_chaines[noColString]);
    852             noColString++;
    853             strcpy(format, largaux);   
     915              char largaux[FLEN_VALUE];
     916              sprintf(largeur,"%d",taille_des_chaines[noColString]);
     917              sprintf(largaux,"%d",1024*taille_des_chaines[noColString]);
     918              noColString++;
     919              strcpy(format, largaux);   
    854920            }
    855921          else strcpy(format,"1024");
     
    930996}
    931997
    932 void FitsFile::putColToFits(int nocol, int nentries, double* donnees) const
     998void FitsOutFile::putColToFits(int nocol, int nentries, double* donnees) const
    933999{
    9341000  int status = 0;
     
    9521018  if( status )  printerror( status,"erreur ecriture du fichier fits" );
    9531019}
    954 void FitsFile::putColToFits(int nocol, int nentries, float* donnees) const
     1020void FitsOutFile::putColToFits(int nocol, int nentries, float* donnees) const
    9551021{
    9561022  int status = 0;
     
    9781044  if( status )  printerror( status,"erreur ecriture du fichier fits" );
    9791045}
    980 void FitsFile::putColToFits(int nocol, int nentries, int* donnees) const
     1046void FitsOutFile::putColToFits(int nocol, int nentries, int* donnees) const
    9811047{
    9821048  int status = 0;
     
    10041070  if( status )  printerror( status," ecriture du fichier fits" );
    10051071}
    1006 void FitsFile::putColToFits(int nocol, int nentries, char** donnees) const
     1072void FitsOutFile::putColToFits(int nocol, int nentries, char** donnees) const
    10071073{
    10081074  int status = 0;
     
    10321098
    10331099
    1034 
    1035 
    1036 
    1037 
    1038 void FitsFile::writeSignatureOnFits() const
     1100void FitsOutFile::writeSignatureOnFits() const
    10391101{
    10401102  int status = 0;
     
    10601122
    10611123
    1062 void FitsFile::printerror(int &status)
    1063   //*****************************************************/
    1064   //* Print out cfitsio error messages and exit program */
    1065   //*****************************************************/
    1066 {
    1067   if( status )
    1068     {
    1069       fits_report_error(stderr,status);
    1070       throw IOExc("FitsFile:: error FITSIO status");
    1071     }
    1072   return;
    1073 }
    1074 
    1075 void FitsFile::printerror(int& status, char* texte)
    1076   //*****************************************************/
    1077   //* Print out cfitsio error messages and exit program */
    1078   //*****************************************************/
    1079 {
    1080   // print out cfitsio error messages and exit program
    1081   // print error report 
    1082   fits_report_error(stderr, status);
    1083   cout << " erreur:: " << texte << endl;
    1084   throw IOExc("FitsFile:: error FITSIO status");
    1085 }
    1086 
    1087 int FitsFile::statusF() const
    1088 {
    1089   return fits_status_;
    1090 }
    1091 void FitsFile::ResetStatus(int& status)
    1092 {
    1093   fits_status_ = status;
    1094   status = 0;
    1095 }
    1096 
    1097 string FitsFile::getErrStatus(int status)
    1098 {
    1099   char text[31];
    1100   fits_get_errstatus(status, text);
    1101   return string(text);
    1102 }
     1124
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1047 r1136  
    1212namespace SOPHYA {
    1313
     14 class FitsFile;
     15 class FitsInFile;
     16 class FitsOutFile;
     17
     18
     19
    1420//
    15 //! Virtual Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
     21//! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
    1622
    1723/*!
    18 
     24The class structure is analogous to Sophya-PPersist system :
    1925Each SOPHYA object XXX is associated with a object of class FITS_XXX
    20  (inheriting from FitsFile), to which input/output operations with FITS
    21  files are delegated. A typical example of use is the following :
     26 (inheriting from FitsFileHandler), to which input/output operations with FITS
     27 files are delegated (through a class Hierarchy : FitsFile (virtual),
     28 FitsInFile, FitsOutFile) . A typical example of use is the following :
    2229
    2330\verbatim
     
    3946
    4047*/
     48
     49class FitsIOHandler {
     50
     51
     52  public:
     53
     54virtual ~FitsIOHandler() {}
     55/*!
     56this method is called from inherited objects :
     57
     58opens a file 'flnm'
     59
     60gets parameters in header (hdunum)
     61
     62calls the method 'ReadFromFits' from the inherited  object
     63
     64
     65*/
     66  void   Read(char flnm[],int hdunum= 2);
     67/*!
     68this method is called from inherited objects :
     69
     70for writing a new object in a new fits-extension, at the end of
     71
     72the existing file (flnm), if OldFile=true.
     73
     74If OldFile=false, an exception occurs
     75 
     76By convention, primary header does not contain fits-image data : i.e.
     77all data are fits-extensions. The first relevant header will have hdunum=2.
     78For switching off this convention use the method :
     79
     80firstImageOnPrimaryHeader() (see below)
     81
     82In that case do not forget to precise hdunum=1 when reading data on primary header.
     83
     84calls the method 'WriteToFits' from the inherited  object
     85
     86*/
     87  void   Write(char flnm[], bool OldFile=false) ;
     88
     89  /*!
     90Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. With default value for hdunum, one reads the next extension, with respect to the current position.
     91   */
     92  void   Read(FitsInFile& ifts, int hdunum=0);
     93  void   Write(FitsOutFile& ofts) ;
     94
     95
     96  protected: 
     97  virtual void    ReadFromFits(FitsInFile& is)=0;           
     98  virtual void    WriteToFits(FitsOutFile& os) =0;           
     99  friend class FitsInFile;
     100  friend class FitsOutFile;
     101
     102  };
     103
     104
     105
    41106class FitsFile
    42107{
     
    44109public:
    45110
    46   FitsFile();
     111  FitsFile() { InitNull();};
    47112  virtual ~FitsFile();
     113
     114  static string getErrStatus(int status);
     115
     116
     117
     118
     119inline  int statusF() const { return fits_status_;}
     120 
     121
     122protected:
     123
     124   void ResetStatus(int& status) ;
     125   static  void printerror(int&) ;
     126   static  void printerror(int&,char* texte) ;
     127   inline void InitNull() { cout << " init fitsfile " << endl; fptr_= NULL; hdutype_= 0; hdunum_ = 1;
     128   fits_status_ = 0;}
     129
     130  //! pointer to the FITS file, defined in fitsio.h
     131  fitsfile *fptr_;
     132 
     133  //!  image or bintable ?
     134  int hdutype_;
     135
     136//! index of header to be read/written
     137  int hdunum_; 
     138
     139  //! last status returned by fitsio library. updated only by several methods
     140  int fits_status_;
     141
     142   
     143};
     144
     145
     146 class FitsInFile : public  FitsFile {
     147
     148 public:
     149   FitsInFile();
     150   //   FitsInFile(char flnm[], int hdunum=0);
     151   FitsInFile(char flnm[]);
     152   ~FitsInFile() {  cout << " destructeur FitsInFile " << endl; };
     153
     154
     155//////////////////////////////////////////////////////////
     156//     methods with general purpose
     157///////////////////////////////////////
     158
     159
     160
    48161  static int NbBlocks(char flnm[]);
    49162  static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl  );
    50163
    51   protected:
     164
     165
     166  //  void ReadFInit(char flnm[],int hdunum=0);
     167  void ReadFInit(int hdunum);
    52168 
    53 /*!
    54 this method is called from inherited objects :
    55 
    56 moves to header 'hdunum' on file 'flnm'
    57 
    58 gets parameters in header
    59 
    60 calls the method 'ReadFromFits' from the inherited  object
    61 
    62 */
    63   void   ReadF(char flnm[],int hdunum= 0);
    64   //  FitsFile* ReadFInit(char flnm[],int hdunum=0);
    65   void ReadFInit(char flnm[],int hdunum=0);
    66  
    67 /*!
    68 this method is called from inherited objects :
    69 
    70 opens a file 'flnm'
    71 
    72 gets parameters in header
    73 
    74 calls the method 'ReadFromFits' from the inherited  object
    75 
    76 */
    77   void    WriteF(char flnm[], bool OldFile=false);
    78  //    virtual void    ReadFromFits(FitsFile& ff)=0;           
    79 
    80 
    81 
    82   virtual void    ReadFromFits()=0;           
    83   virtual void    WriteToFits()=0;           
    84 
    85   static string getErrStatus(int status);
    86 
    87 
    88   //////////////////////////////////////////////////////////
    89   ///////   methods for managing extensions ////////////////
    90   //////////////////////////////////////////////////////////
    91 
    92 //////////////////////////////////////////////////////////
    93     //     methods with general purpose
    94     ///////////////////////////////////////
    95 
    96169  /*! return a reference on a DVList containing the keywords from FITS file
    97170   */
    98   inline const DVList& DVListFromFits() const { return dvl_;}
    99 
    100   void moveToFollowingHeader();
    101   int statusF() const;
     171inline const DVList& DVListFromFits() const { return dvl_;}
     172
     173void moveToFollowingHeader();
     174
     175
     176       //////////////////////////////////////////////////////////
     177       ///////   methods for managing extensions ////////////////
     178       //////////////////////////////////////////////////////////
     179
    102180
    103181
    104182/////////////////////////////////////////////////////////////
    105   //       methods for managing FITS IMAGE extension
    106   ///////////////////////////////////////////////////
    107 
    108 
    109   //read
    110   //----
     183//       methods for managing FITS IMAGE extension
     184///////////////////////////////////////////////////
     185
    111186
    112187/*! return true if the current header  corresponds to a FITS image extension */
    113188inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
     189
     190
    114191
    115192  /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
     
    125202
    126203
    127 //write
    128 //-----
    129 
    130 
    131   /*! create an IMAGE header on FITS file.
    132 \param <type> type of data (see method ColTypeFromFits)
    133 \param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
    134 \param <naxisn>  array containind sizes of the different dimensions
    135   */
    136   void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
    137 
    138   /*! write double data from array 'map'on an IMAGE extension
    139 \param <nbData>  number of data to be written
    140 
    141    */
    142   void putImageToFits( int nbData, double* map) const;
    143 
    144   /*! same as previous method with float data */
    145   void putImageToFits(int nbData, float* map ) const;
    146 
    147   /*! same as previous method with int data */
    148   void putImageToFits(int nbData, int* map) const;
    149 
    150 
    151204
    152205//////////////////////////////////////////////////////////////////////////
    153   //       methods for managing FITS BINARY TABLE or ASCII TABLE extension
    154   ////////////////////////////////////////////////////////////////////////
    155 
    156 
    157 
    158 // read
    159 //-----
     206//       methods for managing FITS BINARY TABLE or ASCII TABLE extension
     207////////////////////////////////////////////////////////////////////////
     208
     209
     210
    160211
    161212/*! return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
    162213inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
    163  /*! return number of columns (return 1 if IMAGE) */
    164   int     NbColsFromFits() const;
    165   /*! number of data in the current IMAGE extension on FITS file, or number
    166  of data of column number 'nocol' of the current BINTABLE extension
    167   */
    168   int     NentriesFromFits(int nocol) const;
     214
     215
     216static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
     217                                  vector<int>& repeat,
     218                                  vector<string>& noms,
     219                                  vector<char>& types,   
     220                                  vector<int>&  taille_des_chaines);
     221
     222
     223
    169224  /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
    170225
     
    200255  void GetBinTabLine(int NoLine, float* fdata) ;
    201256
    202 
    203 
    204 
    205 
    206   /*!
     257/*!
    207258fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
    208259
     
    219270  // Write elements into the FITS data array
    220271
    221 
    222 
    223   //write
    224   //-----
     272/////////////////////////////////////////////////////////////
     273//       methods for managing any type of FITS extension
     274////////////////////////////////////////////////////////
     275
     276 /*! return number of columns (return 1 if IMAGE) */
     277  int     NbColsFromFits() const;
     278  /*! number of data in the current IMAGE extension on FITS file, or number
     279 of data of column number 'nocol' of the current BINTABLE extension
     280  */
     281  int     NentriesFromFits(int nocol) const;
     282
     283
     284/*!
     285fill the array 'map' with double data from the current extension on FITS file.
     286If the extension is BINTABLE, the first column is provided.
     287
     288\param <nentries>  number of data to be read
     289  */
     290  void    GetSingleColumn(double* map, int nentries) const;
     291
     292  /*! same as above with float data */
     293  void    GetSingleColumn(float*  map, int nentries) const;
     294
     295  /*! same as above with int data */
     296  void    GetSingleColumn(int* map, int nentries) const;
     297
     298  private :
     299
     300void InitNull();
     301static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
     302static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
     303
     304
     305 
     306
     307  //! fits-Image parameter
     308  int bitpix_;
     309
     310  //! fits-Image parameter
     311  int naxis_;
     312
     313  //! fits-Image parameters : sizes of dimensions
     314  vector<int> naxisn_;
     315
     316  //! fits-Image parameter: number of data
     317  int nbData_;
     318
     319  //! Bintable parameter
     320  int nrows_;
     321
     322  //! Bintable parameter
     323  vector<int> repeat_;
     324
     325  //! Bintable parameter
     326  int nbcols_;
     327
     328  //! Bintable parameter: column names
     329  vector<string> noms_;
     330
     331  //! Bintable parameters: types of columns (D: double, E: float, I: integers,  A: char*)
     332  vector<char> types_;   
     333
     334  //! Bintable parameters:   length of the char* variables                 
     335  vector<int>  taille_des_chaines_;
     336
     337  //! DVList for transferring keywords
     338  DVList dvl_;
     339
     340
     341 };
     342
     343
     344 class FitsOutFile : public  FitsFile {
     345
     346 public:
     347   FitsOutFile();
     348   FitsOutFile(char flnm[], bool OldFile=false);
     349   ~FitsOutFile() {  cout << " destructeur FitsOutFile " << endl;};
     350   inline void InitNull() {imageOnPrimary_=false;}
     351
     352       //////////////////////////////////////////////////////////
     353       ///////   methods for managing extensions ////////////////
     354       //////////////////////////////////////////////////////////
     355
     356
     357
     358/////////////////////////////////////////////////////////////
     359//       methods for managing FITS IMAGE extension
     360///////////////////////////////////////////////////
     361
     362
     363   inline void firstImageOnPrimaryHeader() {imageOnPrimary_=true;}
     364
     365  /*! create an IMAGE header on FITS file.
     366\param <type> type of data (see method ColTypeFromFits)
     367\param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
     368\param <naxisn>  array containind sizes of the different dimensions
     369  */
     370  void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
     371
     372  /*! write double data from array 'map'on an IMAGE extension
     373\param <nbData>  number of data to be written
     374
     375   */
     376  void putImageToFits( int nbData, double* map) const;
     377
     378  /*! same as previous method with float data */
     379  void putImageToFits(int nbData, float* map ) const;
     380
     381  /*! same as previous method with int data */
     382  void putImageToFits(int nbData, int* map) const;
     383
     384
     385
     386//////////////////////////////////////////////////////////////////////////
     387//       methods for managing FITS BINARY TABLE or ASCII TABLE extension
     388////////////////////////////////////////////////////////////////////////
     389
     390
    225391
    226392  /*! create an BINTABLE header on FITS file.
     
    250416  void putColToFits(int nocol, int nentries, char** donnees) const;
    251417
    252 
    253 /////////////////////////////////////////////////////////////
    254   //       methods for managing any type of FITS extension
    255   ////////////////////////////////////////////////////////
    256 
    257 
    258   /*!
    259 fill the array 'map' with double data from the current extension on FITS file.
    260 If the extension is BINTABLE, the first column is provided.
    261 
    262 \param <nentries>  number of data to be read
    263   */
    264   void    GetSingleColumn(double* map, int nentries) const;
    265 
    266   /*! same as above with float data */
    267   void    GetSingleColumn(float*  map, int nentries) const;
    268 
    269   /*! same as above with int data */
    270   void    GetSingleColumn(int* map, int nentries) const;
    271 
    272 
    273 
    274 private:
    275 
    276    void InitNull();
    277    void ResetStatus(int& status) ;
    278    static  void printerror(int&) ;
    279    static  void printerror(int&,char* texte) ;
    280 
    281 static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
    282 static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
    283                                   vector<int>& repeat,
    284                                   vector<string>& noms,
    285                                   vector<char>& types,   
    286                                   vector<int>&  taille_des_chaines);
    287 static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
     418  private :
     419
    288420  void writeSignatureOnFits() const;
    289421
    290   //! pointer to the FITS file, defined in fitsio.h
    291   fitsfile *fptr_;
    292  
    293   //!  image or bintable ?
    294   int hdutype_;
    295 
    296 //! index of header to be read/written
    297   int hdunum_; 
    298 
    299 
    300   //! fits-Image parameter
    301   int bitpix_;
    302 
    303   //! fits-Image parameter
    304   int naxis_;
    305 
    306   //! fits-Image parameters : sizes of dimensions
    307   vector<int> naxisn_;
    308 
    309   //! fits-Image parameter: number of data
    310   int nbData_;
    311 
    312   //! Bintable parameter
    313   int nrows_;
    314 
    315   //! Bintable parameter
    316   vector<int> repeat_;
    317 
    318   //! Bintable parameter
    319   int nbcols_;
    320 
    321   //! Bintable parameter: column names
    322   vector<string> noms_;
    323  
    324   //! Bintable parameters: types of columns (D: double, E: float, I: integers,  A: char*)
    325   vector<char> types_;   
    326    
    327   //! Bintable parameters:   length of the char* variables                 
    328   vector<int>  taille_des_chaines_;
    329 
    330   //! DVList for transferring keywords
    331   DVList dvl_;
    332 
    333 
    334 
    335   //! last status returned by fitsio library. updated only by several methods
    336   int fits_status_;
    337 };
     422
     423  bool imageOnPrimary_;
     424
     425 };
     426
    338427
    339428
  • trunk/SophyaExt/FitsIOServer/fitsntuple.cc

    r1047 r1136  
    2525  ownobj_ = true;
    2626
    27   ReadF(inputfile,hdunum);
     27  Read(inputfile,hdunum);
    2828}
    2929
     
    4646{
    4747  if (ownobj_ && dobj_ != NULL) delete dobj_;
    48   if (column_ != NULL) delete [] column_;
     48  //  if (column_ != NULL) delete [] column_;
    4949}
    5050
    51 void FITS_NTuple::Read(char inputfile[],int hdunum)
    52 {
    53   ReadF(inputfile,hdunum);
    54 }
     51//void FITS_NTuple::Read(char inputfile[],int hdunum)
     52//{
     53//  ReadF(inputfile,hdunum);
     54//}
    5555void FITS_NTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum)
    5656{
    5757  fistLineToBeRead_ = firstLine;
    5858  numberOfLinesToBeRead_ = numberOfLines;
    59   ReadF(inputfile,hdunum);
     59  Read(inputfile,hdunum);
    6060}
    6161
    6262
    6363
    64 void FITS_NTuple::Write(char outputfile[], bool OldFile)
     64//void FITS_NTuple::Write(char outputfile[], bool OldFile)
     65//{
     66//  WriteF(outputfile, OldFile);
     67//}
     68
     69void FITS_NTuple::ReadFromFits(FitsInFile& is)
    6570{
    66   WriteF(outputfile, OldFile);
    67 }
    68 
    69 void FITS_NTuple::ReadFromFits()
    70 {
    71   //  if (!fn.IsFitsTable())
    72     if (!IsFitsTable())
     71  if (!is.IsFitsTable())
    7372    {
    7473      throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table");
    7574    }
    7675  int nbcols, nbentries;
    77   //  nbcols = fn.NbColsFromFits();
    78   nbcols = NbColsFromFits();
     76  nbcols = is.NbColsFromFits();
    7977  nbentries = 0;
    8078  int k;
    81   //  for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(k) );
    82   for (k=0; k<nbcols; k++) nbentries=max( nbentries, NentriesFromFits(k) );
     79  for (k=0; k<nbcols; k++) nbentries=max( nbentries, is.NentriesFromFits(k) );
    8380 
    8481  char ** ColName = new char*[nbcols];
     
    8784    {
    8885      ColName[k] = new char[LONNOM1];
    89       //      strncpy(ColName[k], fn.ColNameFromFits(k).c_str(),LONNOM);
    90       strncpy(ColName[k], ColNameFromFits(k).c_str(),LONNOM);
     86      strncpy(ColName[k], is.ColNameFromFits(k).c_str(),LONNOM);
    9187      ColName[k][LONNOM] =  '\0';
    9288    }
    9389  for (k=0; k<nbcols;k++)
    9490    {
    95       //      char ss= fn.ColTypeFromFits(k);
    96       char ss= ColTypeFromFits(k);
     91      char ss= is.ColTypeFromFits(k);
    9792      string type;
    9893      if (ss != 'E')
     
    123118    }
    124119  delete [] ColName;
    125   //   if (column_ != NULL) delete [] column_;
    126   //  column_ = new float[nbentries];
    127120
    128   // j'initialise le NTuple a zero, pour le dimensionner
    129   // (SetVal suppose que le ntuple est deja dimensionne)
    130121  r_4* ligne = new r_4[nbcols];
    131   //  for (k=0; k<nbcols; k++) ligne[k]=0.;
    132   //  for (k=0; k<nbentries;k++) dobj_->Fill(ligne);
    133   //  delete [] ligne;
    134122
    135   //%%%%%%
    136     int firstln, lastln;
    137     if (numberOfLinesToBeRead_ > 0)
    138       {
    139         firstln = fistLineToBeRead_;
    140         lastln = firstln + numberOfLinesToBeRead_;
    141       }
    142     else
    143       {
    144         firstln = 0;
    145         lastln  = nbentries;
    146       }
    147     int numLigne;
    148     for (numLigne=firstln; numLigne < lastln; numLigne++)
    149       {
    150         //      fn.GetBinTabLine(numLigne, ligne);
    151         GetBinTabLine(numLigne, ligne);
    152         dobj_->Fill(ligne);
    153       }
    154     delete [] ligne;
     123  int firstln, lastln;
     124  if (numberOfLinesToBeRead_ > 0)
     125    {
     126      firstln = fistLineToBeRead_;
     127      lastln = firstln + numberOfLinesToBeRead_;
     128    }
     129  else
     130    {
     131      firstln = 0;
     132      lastln  = nbentries;
     133    }
     134  int numLigne;
     135  for (numLigne=firstln; numLigne < lastln; numLigne++)
     136    {
     137      is.GetBinTabLine(numLigne, ligne);
     138      dobj_->Fill(ligne);
     139    }
     140  delete [] ligne;
    155141
    156     //%%%%%%%
     142  dobj_->Info()=is.DVListFromFits();
     143}
    157144
    158 
    159     //  for (k=0; k<nbcols;k++)
    160     //    {
    161     //     fn.GetBinTabFCol(column_, nbentries, k);
    162     //     for (int nent=0; nent<nbentries; nent++) dobj_->SetVal(nent,k, column_[nent]);
    163     //   }
    164     //  dobj_->Info()=fn.DVListFromFits();
    165   dobj_->Info()=DVListFromFits();
    166 }
    167 void FITS_NTuple::WriteToFits()
     145void FITS_NTuple::WriteToFits(FitsOutFile& os)
    168146{
    169147  if(dobj_ == NULL)
     
    192170      strncpy(Noms[k],dobj_->NomIndex(k),LONNOM1);
    193171    }
    194   // la librairie fitsio ecrit colonne par colonne
     172
    195173  char* type= new char[ncols+1];
    196174  for (k=0;k<ncols+1;k++) type[k]='E';
    197175  type[ncols]='\0';
    198176  vector<int> dummy;
    199   //  fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
    200   makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
     177
     178  os.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
    201179   for (k=0; k< ncols; k++)
    202180    {
     
    205183   delete [] Noms;
    206184   delete [] type;
    207    for (k=0; k<ncols;k++) putColToFits(k, nentries, getColFromObj(k));
     185   float* column =  new float[nentries];
     186   for (k=0; k<ncols;k++)
     187     {
     188       for(int j = 0; j < nentries; j++) column[j]= dobj_->GetVal(j,k);
     189       os.putColToFits(k, nentries, column);
     190     }
     191   delete [] column;
    208192
    209193}
    210194
    211 float* FITS_NTuple::getColFromObj(int colNr)
    212 {
    213   if (column_ != NULL)
    214     {
    215       delete [] column_;
    216       column_ = NULL;
    217     }
    218   column_ = new float[dobj_->NEntry()];
    219   for(int j = 0; j < dobj_->NEntry(); j++) column_[j]= dobj_->GetVal(j,colNr);
    220   return column_;
    221 }
  • trunk/SophyaExt/FitsIOServer/fitsntuple.h

    r1049 r1136  
    44#ifndef FITSNTuple_SEEN
    55#define FITSNTuple_SEEN
     6#include "machdefs.h"
    67#include "ntuple.h"
    78#include "anydataobj.h"
     
    1415// pout NTuple
    1516////////////////////////////////////////////////////////////////
    16 class  FITS_NTuple : public FitsFile 
     17class  FITS_NTuple : public FitsIOHandler 
    1718{
    1819
     
    2425 FITS_NTuple(NTuple* obj);
    2526virtual ~FITS_NTuple();
    26  void Read(char inputfile[],int hdunum=2);
     27
     28virtual   AnyDataObj* DataObj() { return(dobj_); }
     29virtual   void        SetDataObj(AnyDataObj & o)
     30  {   
     31    NTuple* po = dynamic_cast<  NTuple* >(& o);
     32    if (po == NULL) return;
     33    if (ownobj_ && dobj_) delete dobj_; 
     34    dobj_ = po;
     35    ownobj_ = false;
     36  }   
     37
     38
    2739/*!
    2840fill the XNTuple only with lines from firstLine-th to (firstLine+numberOfLines-1)-th of the FITS-file inputfile.
     
    3143*/
    3244 void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2);
    33 void Write(char outputfile[], bool OldFile=false);
     45
    3446inline operator NTuple() { return(*dobj_); }
    3547inline NTuple * getObj() { return(dobj_); }
     
    3850
    3951  // implementation de FitsFile
    40 //virtual void ReadFromFits(FitsFile& fn);
    41 virtual void ReadFromFits();
    42 virtual void WriteToFits();
    43 
    44 float*  getColFromObj(int colNr);
     52virtual void ReadFromFits(FitsInFile& is);
     53virtual void WriteToFits(FitsOutFile& os) ;
    4554
    4655 private :
    4756
    48 inline void InitNull()
    49    {
    50      fistLineToBeRead_= -1;
    51      numberOfLinesToBeRead_= -1;
    52      column_ = NULL;
    53    }
     57inline void InitNull() { fistLineToBeRead_= -1; numberOfLinesToBeRead_= -1;}
    5458
    5559
     
    5963  int fistLineToBeRead_;
    6064  int numberOfLinesToBeRead_;
    61   float* column_;
    6265};
    6366//////////////////////////////////////////////////////////////////
  • trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc

    r1047 r1136  
    1515{
    1616  dobj_= new SphereHEALPix<T>;
    17   ownobj= true;
     17  ownobj_= true;
    1818}
    1919 
     
    2222{
    2323  dobj_= new SphereHEALPix<T>;
    24   ownobj= true;
    25 
    26   ReadF(inputfile,hdunum);
    27   dobj_->SetTemp(true);
     24  ownobj_= true;
     25
     26  Read(inputfile,hdunum);
     27  //  dobj_->SetTemp(true);
    2828}
    2929
     
    3333{
    3434  dobj_= new SphereHEALPix<T>(obj, true);
    35   dobj_->SetTemp(true);
    36   ownobj= true;
     35  //  dobj_->SetTemp(true);
     36  ownobj_= true;
    3737}
    3838
     
    4141{
    4242  dobj_= obj;
    43   ownobj= false;
     43  ownobj_= false;
    4444}
    4545
     
    4747FITS_SphereHEALPix<T>::~FITS_SphereHEALPix()
    4848{
    49   if (ownobj && dobj_) delete dobj_;
     49  if (ownobj_ && dobj_) delete dobj_;
    5050}
    5151
     
    6161  SphereHEALPix<T> * po = dynamic_cast< SphereHEALPix<T> * >(&o);
    6262  if (po == NULL) return;
    63   if (ownobj && dobj_) delete dobj_;
     63  if (ownobj_ && dobj_) delete dobj_;
    6464  dobj_ = po;
    65   ownobj = false;
     65  ownobj_ = false;
    6666}
    6767
    6868
    6969
    70 template <class T>
    71 void FITS_SphereHEALPix<T>::Write(char outputfile[], bool OldFile)
    72 {
    73   WriteF(outputfile, OldFile);
    74 }
    75 template <class T>
    76 void FITS_SphereHEALPix<T>::Read(char inputfile[],int hdunum)
    77 {
    78   ReadF(inputfile,hdunum);
    79 }
    80 
    81 template <class T>
    82 void FITS_SphereHEALPix<T>::WriteToFits()
     70
     71template <class T>
     72void FITS_SphereHEALPix<T>::WriteToFits(FitsOutFile& os)
    8373{
    8474  if(dobj_ == NULL)
     
    130120  Type[1]='\0';
    131121  vector<int> dummy;
    132   //  fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
    133   makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
     122  os.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
    134123  delete [] Noms[0];
    135124  delete [] Noms;
    136   putColToFits(0,  nPix, dobj_->pixels_.Data());
     125  os.putColToFits(0,  nPix, dobj_->pixels_.Data());
    137126}
    138127
    139128template <class T>
    140 void FITS_SphereHEALPix<T>::ReadFromFits()
     129void FITS_SphereHEALPix<T>::ReadFromFits(FitsInFile& is)
    141130{
    142131  if(dobj_ == NULL)
    143132    {
    144133      dobj_= new SphereHEALPix<T>;
    145       dobj_->SetTemp(true);
    146       ownobj= true;     
     134      ownobj_= true;     
    147135    }
    148136
    149137 
    150138  int nbcols, nbentries;
    151   //  nbcols = fn.NbColsFromFits();
    152   nbcols = NbColsFromFits();
     139  nbcols = is.NbColsFromFits();
    153140  if (nbcols != 1)
    154141    {
    155142      throw IOExc("le fichier fits n'est pas une sphere Healpix");
    156143    }
    157   //   const DVList* dvl = &fn.DVListFromFits();
    158   //  DVList dvl=fn.DVListFromFits();
    159   DVList dvl=DVListFromFits();
    160   //  dvl.Print();
    161   //   nbentries = fn.NentriesFromFits(0);
    162    nbentries = NentriesFromFits(0);
     144  DVList dvl=is.DVListFromFits();
     145   nbentries = is.NentriesFromFits(0);
    163146  int lastpix=dvl.GetI("LASTPIX");
    164147  if (lastpix>0)
     
    211194  // On lit les DataBlocks;
    212195  dobj_->pixels_.ReSize(nPix);
    213   //  fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
    214   GetSingleColumn(dobj_->pixels_.Data(),nPix);
     196  is.GetSingleColumn(dobj_->pixels_.Data(),nPix);
    215197
    216198  // on effectue le decoupage en tranches
    217199  dobj_->SetThetaSlices();
    218   //  dobj_->Info()=fn.DVListFromFits();
    219   dobj_->Info()=DVListFromFits();
     200  dobj_->Info()=is.DVListFromFits();
    220201
    221202
  • trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h

    r1047 r1136  
    1717//////////////////////////////////////////////////////////////////////
    1818template <class T>
    19 class FITS_SphereHEALPix : public FitsFile 
     19class FITS_SphereHEALPix : public FitsIOHandler 
    2020{
    2121public:
     
    3030
    3131inline operator SphereHEALPix<T>() { return(*dobj_); }
    32  void Read(char inputfile[],int hdunum=2);
    33 void Write(char outputfile[], bool Oldfile=false);
    3432
    3533protected:
    3634
    3735//virtual void ReadFromFits(FitsFile& fn);
    38 virtual void ReadFromFits();
    39 virtual void WriteToFits();
     36virtual void ReadFromFits(FitsInFile& is);
     37virtual void WriteToFits(FitsOutFile& os) ;
    4038SphereHEALPix<T>* dobj_;
    41 bool ownobj;
     39bool ownobj_;
    4240};
    4341
  • trunk/SophyaExt/FitsIOServer/fitstarray.cc

    r1047 r1136  
    1212FITS_TArray<T>::FITS_TArray()
    1313{
    14   dobj_=new TArray<T>;
    15   ownobj=true;
     14  dobj_= NULL;
     15  ownobj_=false;
    1616}
    1717
     
    1919FITS_TArray<T>::FITS_TArray(char inputfile[],int hdunum)
    2020{
    21   dobj_=new TArray<T>;
    22   ownobj=true;
    23   ReadF(inputfile,hdunum);
     21  dobj_=NULL;
     22  ownobj_=false;
     23  Read(inputfile,hdunum);
    2424}
    2525
     
    2727FITS_TArray<T>::FITS_TArray(const TArray<T> & obj)
    2828{
    29   dobj_ = new TArray<T>(obj);
    30   ownobj=true;
     29    dobj_ = new TArray<T>(obj);
     30  ownobj_=true;
    3131}
    3232
     
    3535{
    3636  dobj_ = obj;
    37   ownobj=false;
     37  ownobj_=false;
    3838}
    3939
     
    4242FITS_TArray<T>::~FITS_TArray()
    4343{
    44   if (ownobj && dobj_) delete dobj_;
     44  if (ownobj_ && dobj_) delete dobj_;
    4545}
    46 
    47 template <class T>
    48 void FITS_TArray<T>::Write(char outputfile[], bool OldFile)
    49 {
    50   WriteF(outputfile, OldFile);
    51 }
    52 
    5346
    5447
     
    5952}
    6053
     54
    6155template <class T>
    62 void FITS_TArray<T>::ReadFromFits()
     56void   FITS_TArray<T>::SetDataObj(AnyDataObj & o)
     57  {   
     58    TArray<T>* po = dynamic_cast<  TArray<T>* >(& o);
     59    if (po == NULL) return;
     60    if (ownobj_ && dobj_) delete dobj_; 
     61    dobj_ = po;
     62    ownobj_ = false;
     63  }   
     64
     65
     66
     67template <class T>
     68void FITS_TArray<T>::ReadFromFits(FitsInFile& is)
    6369{
    64 
    65   //  if (!fn.IsFitsImage())
    66   if (!IsFitsImage())
     70  if (!is.IsFitsImage())
    6771    {
    6872      throw PException("ReadFromFits: the fits file seems not to be an image");
    6973    }
    70   //  int dimension = fn.nbDimOfImage();
    71   int dimension = nbDimOfImage();
     74  int dimension = is.nbDimOfImage();
    7275  cout << " dimension de l'image a lire: " << dimension << endl;
    7376   
    7477  uint_4* siz = new uint_4[dimension];
    75   //  for (int k=0; k< dimension; k++) siz[k] = fn.dimOfImageAxes()[k];
    76   for (int k=0; k< dimension; k++) siz[k] = dimOfImageAxes()[k];
     78  for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
    7779  if(dobj_ == NULL)
    78     dobj_ = new TArray<T>(dimension,siz);
     80    {
     81      dobj_ = new TArray<T>(dimension,siz);
     82      ownobj_ = true;
     83    }
    7984  else
    8085    dobj_->ReSize(dimension,siz);
    8186 
    8287  delete [] siz;
    83   //  if (dobj_->Size() != fn.nbOfImageData() )
    84   if (dobj_->Size() != nbOfImageData() )
     88  if (dobj_->Size() != is.nbOfImageData() )
    8589  {
    8690    cout << " total size of TArray: " << dobj_->Size() << endl;
    87     cout << " total size from fits file: " << nbOfImageData() << endl;
     91    cout << " total size from fits file: " << is.nbOfImageData() << endl;
    8892      throw PException("ReadFromFits: size conflict");
    8993  }
    9094  // On lit le tableau
    91   //  fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
    92   GetSingleColumn( dobj_->Data(),dobj_->Size());
     95  is.GetSingleColumn( dobj_->Data(),dobj_->Size());
    9396
    9497}
    9598
    9699
    97   template <class T>
    98 void FITS_TArray<T>::WriteToFits(
     100template <class T>
     101void FITS_TArray<T>::WriteToFits(FitsOutFile& os
    99102{
    100103  if(dobj_ == NULL) return;
     
    130133    }
    131134  cout << " nombre total d'elements a copier " << nbels << endl;
    132   //  fn.makeHeaderImageOnFits(type, nbdim, naxisn);
    133   makeHeaderImageOnFits(type, nbdim, naxisn);
     135  os.makeHeaderImageOnFits(type, nbdim, naxisn);
    134136  if (!dobj_->IsPacked())
    135137    {
     
    144146     
    145147    }
    146   //  fn.putImageToFits(nbels, dobj_->Data());
    147   putImageToFits(nbels, dobj_->Data());
     148  os.putImageToFits(nbels, dobj_->Data());
    148149 
    149150  delete [] naxisn;
  • trunk/SophyaExt/FitsIOServer/fitstarray.h

    r1047 r1136  
    2020
    2121template <class T>
    22 class FITS_TArray : public FitsFile {
     22class FITS_TArray : public FitsIOHandler {
    2323
    2424public:
     
    3030virtual ~FITS_TArray();
    3131virtual AnyDataObj* DataObj();
     32virtual   void      SetDataObj(AnyDataObj & o);
    3233inline operator TArray<T>() { return(*dobj_); }
    33 void Write(char outputfile[], bool OldFile=false);
    3434
    3535protected :
    3636
    37   //void ReadFromFits(FitsFile& fn);
    38 void ReadFromFits();
    39 void WriteToFits();
     37void ReadFromFits(FitsInFile& is);
     38void WriteToFits(FitsOutFile& os) ;
    4039
    4140  TArray<T> * dobj_;
    42   bool ownobj;
     41  bool ownobj_;
    4342};
    4443//////////////////////////////////////////////////////////////////
  • trunk/SophyaExt/FitsIOServer/fitsxntuple.cc

    r1047 r1136  
    2323  ownobj_ = true;
    2424
    25   ReadF(inputfile,hdunum);
     25  Read(inputfile,hdunum);
    2626}
    2727
     
    4141FITS_XNTuple::~FITS_XNTuple()
    4242{
    43   Clean();
    44 }
    45 
    46 void FITS_XNTuple::Clean()
    47 {
    48   if (dcolumn_ != NULL) delete [] dcolumn_;
    49   if (fcolumn_ != NULL) delete [] fcolumn_;
    50   if (icolumn_ != NULL) delete [] icolumn_;
    51   if (ccolumn_ != NULL)
    52     {
    53       if (dobj_ != NULL)
    54         {
    55           for (int k=0; k<dobj_->NEntry(); k++) delete [] ccolumn_[k];
    56           delete [] ccolumn_;
    57         }
    58       else
    59         {
    60           cout << "FITS_XNTuple, destructeur: bizarre, ccolumn non vide, sans objet?" << endl;;         }
    61     }
    6243  if (ownobj_ && dobj_ != NULL) delete dobj_;
    6344}
    6445
    65 void FITS_XNTuple::Read(char inputfile[],int hdunum)
    66 {
    67   ReadF(inputfile,hdunum);
    68 }
    6946
    7047void FITS_XNTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum)
     
    7249  fistLineToBeRead_ = firstLine;
    7350  numberOfLinesToBeRead_ = numberOfLines;
    74   ReadF(inputfile,hdunum);
    75   //  return dobj_;
    76 }
    77 
    78 
    79 void FITS_XNTuple::Write(char outputfile[], bool OldFile)
    80 {       
    81   WriteF(outputfile, OldFile);
    82 }
     51  Read(inputfile,hdunum);
     52}
     53
     54
    8355 
    84 void FITS_XNTuple::ReadFromFits()
     56void FITS_XNTuple::ReadFromFits(FitsInFile& is)
    8557{   
    86   //  if (!fn.IsFitsTable())
    87   if (!IsFitsTable())
     58  if (!is.IsFitsTable())
    8859    {
    8960      throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table");
    9061    }
    9162  int nbcols, nbentries;
    92   //  nbcols = fn.NbColsFromFits();
    93   nbcols = NbColsFromFits();
     63  nbcols = is.NbColsFromFits();
    9464  nbentries = 0;
    9565  int k;
    96   //  for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(k) );
    97   for (k=0; k<nbcols; k++) nbentries=max( nbentries, NentriesFromFits(k) );
     66  for (k=0; k<nbcols; k++) nbentries=max( nbentries, is.NentriesFromFits(k) );
    9867
    9968  //
     
    11180  for (k=0; k<nbcols;k++)
    11281    {
    113       //      char ss= fn.ColTypeFromFits(k);
    114       char ss= ColTypeFromFits(k);
     82      char ss= is.ColTypeFromFits(k);
    11583      if (ss == 'D') DfitsCol.push_back(k);
    11684      else if (ss == 'E') FfitsCol.push_back(k);
     
    12795    {
    12896      ColName[compt] = new char[LONNOM+1];
    129       //      strncpy(ColName[compt], fn.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
    130       strncpy(ColName[compt], ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
     97      strncpy(ColName[compt], is.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
    13198      ColName[compt++][ LONNOM] =  '\0';
    13299    }
     
    134101    {
    135102      ColName[compt] = new char[LONNOM+1];
    136       //      strncpy(ColName[compt], fn.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
    137       strncpy(ColName[compt], ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
     103      strncpy(ColName[compt], is.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
    138104      ColName[compt++][ LONNOM] =  '\0';
    139105    }
     
    141107    {
    142108      ColName[compt] = new char[LONNOM+1];
    143       //      strncpy(ColName[compt], fn.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
    144       strncpy(ColName[compt], ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
     109      strncpy(ColName[compt], is.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
    145110      ColName[compt++][ LONNOM] =  '\0';
    146111    }
     
    148113    {
    149114      ColName[compt] = new char[LONNOM+1];
    150       //      strncpy(ColName[compt], fn.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
    151       strncpy(ColName[compt], ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
     115      strncpy(ColName[compt], is.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
    152116      ColName[compt++][LONNOM] =  '\0';
    153117    }
     
    193157      cligne = new char*[SfitsCol.size()];
    194158      int  taille_des_chaines=0;
    195       //      for (k=0; k< SfitsCol.size(); k++)  taille_des_chaines = max( taille_des_chaines, fn.ColStringLengthFromFits(SfitsCol[k]) );
    196       for (k=0; k< SfitsCol.size(); k++)  taille_des_chaines = max( taille_des_chaines, ColStringLengthFromFits(SfitsCol[k]) );
     159      for (k=0; k< SfitsCol.size(); k++)  taille_des_chaines = max( taille_des_chaines, is.ColStringLengthFromFits(SfitsCol[k]) );
    197160      for (k=0; k<SfitsCol.size(); k++) cligne[k]=new char[taille_des_chaines+1];
    198161    }
     
    212175  for (numLigne=firstln; numLigne < lastln; numLigne++)
    213176    {
    214       //      fn.GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
    215       GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
     177      is.GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
    216178      dobj_->Fill(dligne, fligne, iligne, cligne);   
    217179    }
     
    221183    for (k=0; k< SfitsCol.size(); k++) delete []  cligne[k];
    222184    delete [] cligne;
    223     //  dobj_->Info()=fn.DVListFromFits();
    224   dobj_->Info()=DVListFromFits();
    225 
    226 }
    227 void FITS_XNTuple::WriteToFits()
     185  dobj_->Info()=is.DVListFromFits();
     186
     187}
     188void FITS_XNTuple::WriteToFits(FitsOutFile& os)
    228189{
    229190  if(dobj_ == NULL)
     
    270231  vector<int> StringSizes(dobj_->NSVar());
    271232  for (k=0; k< StringSizes.size(); k++) StringSizes[k]=dobj_->mStrSz;
    272   // la librairie fitsio ecrit colonne par colonne
    273   //    fn.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes);
    274     makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes);
     233  os.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes);
    275234   for (k=0; k< ncols; k++)
    276235    {
     
    279238   delete [] Noms;
    280239   delete [] types;
     240
     241   
    281242  compt=0; 
    282   for (k=0; k<dobj_->NDVar();k++)
    283     {
    284       putColToFits(compt, dobj_->NEntry(), getColDFromObj(compt));
    285       compt++;
    286     }
    287   for (k=0; k<dobj_->NFVar();k++)
    288     {
    289       putColToFits(compt, dobj_->NEntry(), getColFFromObj(compt));
    290       compt++;
    291     }
    292   for (k=0; k<dobj_->NIVar();k++)
    293     {
    294       putColToFits(compt, dobj_->NEntry(), getColIFromObj(compt));
    295       compt++;
    296     }
    297   for (k=0; k<dobj_->NSVar();k++)
    298     {
    299       putColToFits(compt, dobj_->NEntry(), getColSFromObj(compt));
    300       compt++;
    301     }
    302 }
    303 double* FITS_XNTuple::getColDFromObj(int colNr)
    304 {
    305   if (dcolumn_ != NULL)
    306     {
    307       delete [] dcolumn_;
    308       dcolumn_ = NULL;
    309     }
    310   dcolumn_ = new double[dobj_->NEntry()];
    311   for(int j = 0; j < dobj_->NEntry(); j++) dcolumn_[j]= dobj_->GetDVal(j,colNr);
    312   return dcolumn_;
    313 }
    314 
    315 float* FITS_XNTuple::getColFFromObj(int colNr)
    316 {
    317   if (fcolumn_ != NULL)
    318     {
    319       delete [] fcolumn_;
    320       fcolumn_ = NULL;
    321     }
    322   fcolumn_ = new float[dobj_->NEntry()];
    323   for(int j = 0; j < dobj_->NEntry(); j++) fcolumn_[j]= dobj_->GetFVal(j,colNr);
    324   return fcolumn_;
    325 }
    326  
    327 int* FITS_XNTuple::getColIFromObj(int colNr)
    328 {
    329   if (icolumn_ != NULL)
    330     {
    331       delete [] icolumn_;
    332       icolumn_ = NULL;
    333     }
    334   icolumn_ = new int[dobj_->NEntry()];
    335   for(int j = 0; j < dobj_->NEntry(); j++) icolumn_[j]= dobj_->GetIVal(j,colNr);
    336   return icolumn_;
    337 }
    338 char** FITS_XNTuple::getColSFromObj(int colNr)
    339 {
    340   if (ccolumn_ != NULL)
    341     {
    342       for (int k=0; k<dobj_->NEntry(); k++) delete [] ccolumn_[k];
    343       delete [] ccolumn_;
    344       ccolumn_ = NULL;
    345     }
    346   ccolumn_ = new char*[dobj_->NEntry()];
    347   for(int j = 0; j < dobj_->NEntry(); j++)
    348     {
    349       string s= dobj_->GetSVal(j,colNr);
    350       ccolumn_[j] = new char[dobj_->mStrSz+1];
    351       strcpy(ccolumn_[j],s.c_str());
    352     }
    353   return ccolumn_;
    354 }
     243   if (dobj_->NDVar() > 0)
     244     {
     245       double* dcolumn = new double[nrows];
     246       for (k=0; k<dobj_->NDVar();k++)
     247         {
     248           for(int j = 0; j < nrows; j++) dcolumn[j]= dobj_->GetDVal(j,compt);
     249           os.putColToFits(compt, nrows, dcolumn);
     250           compt++;
     251         }
     252       delete [] dcolumn;
     253     }
     254
     255   if (dobj_->NFVar() > 0)
     256     {
     257       float* fcolumn = new float[nrows];
     258       for (k=0; k<dobj_->NFVar();k++)
     259         {
     260           for(int j = 0; j < nrows; j++) fcolumn[j]= dobj_->GetFVal(j,compt);
     261           os.putColToFits(compt, nrows, fcolumn);
     262           compt++;
     263         }
     264       delete [] fcolumn;
     265     }
     266
     267   if (dobj_->NIVar() > 0)
     268     {
     269       int* icolumn = new int[nrows];
     270       for (k=0; k<dobj_->NIVar();k++)
     271         {
     272           for(int j = 0; j < nrows; j++) icolumn[j]= dobj_->GetIVal(j,compt);
     273           os.putColToFits(compt, nrows, icolumn);
     274           compt++;
     275         }
     276       delete [] icolumn;
     277     }
     278
     279   if (dobj_->NSVar() > 0)
     280     {
     281      char**  ccolumn = new char*[nrows];
     282      for (k=0; k<dobj_->NSVar();k++)
     283        {
     284          int j;
     285          for(j = 0; j < nrows; j++)
     286            {
     287              string s= dobj_->GetSVal(j,compt);
     288              ccolumn[j] = new char[dobj_->mStrSz+1];
     289              strcpy(ccolumn[j],s.c_str());
     290            }
     291          os.putColToFits(compt, nrows, ccolumn);
     292          compt++;
     293          for(j = 0; j < nrows; j++)
     294            {
     295              delete [] ccolumn[j];
     296              ccolumn[j] = NULL;
     297            }
     298        }
     299      delete [] ccolumn;
     300     }
     301}
  • trunk/SophyaExt/FitsIOServer/fitsxntuple.h

    r1049 r1136  
    44#ifndef FITSXNTuple_SEEN
    55#define FITSXNTuple_SEEN
     6#include "machdefs.h"
    67#include "xntuple.h"
    78#include "anydataobj.h"
     
    1516///////////////////////////////////////////////////////////
    1617
    17 class  FITS_XNTuple : public FitsFile 
     18class  FITS_XNTuple : public FitsIOHandler 
    1819{
    1920
     
    2425FITS_XNTuple(XNTuple* obj);
    2526~FITS_XNTuple();
    26  void Read(char inputfile[],int hdunum=2);
     27
     28virtual   AnyDataObj* DataObj() { return(dobj_); }
     29virtual   void        SetDataObj(AnyDataObj & o)
     30  {   
     31    XNTuple* po = dynamic_cast<  XNTuple* >(& o);
     32    if (po == NULL) return;
     33    if (ownobj_ && dobj_) delete dobj_; 
     34    dobj_ = po;
     35    ownobj_ = false;
     36  }   
     37
    2738
    2839/*!
     
    3243*/
    3344void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2);
    34 void Write(char outputfile[], bool OldFile=false);
    3545inline operator XNTuple() { return(*dobj_); }
    3646inline XNTuple * getObj() { return(dobj_); }
     
    3949
    4050  // implementation de FitsFile
    41 //  virtual void  ReadFromFits(FitsFile& fn);
    42  virtual void  ReadFromFits();
    43 virtual void    WriteToFits();
    44 void*   getColFromObj(int colNr);
    45 double* getColDFromObj(int colNr);
    46 float*  getColFFromObj(int colNr);
    47 int*    getColIFromObj(int colNr);
    48 char**  getColSFromObj(int colNr);
     51 virtual void  ReadFromFits(FitsInFile& is);
     52virtual void    WriteToFits(FitsOutFile& os) ;
    4953
    5054 private :
    5155
    52  void Clean();
    5356
    5457inline void InitNull()
     
    5659     fistLineToBeRead_= -1;
    5760     numberOfLinesToBeRead_= -1;
    58      dcolumn_ = NULL;
    59      fcolumn_ = NULL;
    60      icolumn_ = NULL;
    61      ccolumn_ = NULL;
    6261   }
    6362
     
    6766  int fistLineToBeRead_;
    6867  int numberOfLinesToBeRead_;
    69   double* dcolumn_;
    70   float*  fcolumn_;
    71   int*    icolumn_;
    72   char**  ccolumn_;
    7368};
    7469//////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.