Changeset 1047 in Sophya for trunk


Ignore:
Timestamp:
Jun 15, 2000, 12:22:23 PM (25 years ago)
Author:
ansari
Message:

modifs pour introduction lecteur de fits par lignes

Location:
trunk/SophyaExt/FitsIOServer
Files:
10 edited

Legend:

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

    r1045 r1047  
    3333  nrows_ = 0;
    3434  nbcols_ = 0;
     35  fits_status_ = 0;
    3536  naxisn_.clear();
    3637  repeat_.clear();
     
    125126{
    126127  ReadFInit(flnm, hdunum);
    127   /*
     128  //  ReadFromFits(*this);
     129    ReadFromFits();
     130}
     131
     132
     133//FitsFile* FitsFile::ReadFInit(char flnm[],int hdunum)
     134void FitsFile::ReadFInit(char flnm[],int hdunum)
     135{
    128136  InitNull();
    129137  int status = 0;
     
    163171      moveToFollowingHeader();
    164172    }
    165   */
    166   ReadFromFits(*this);
    167 }
    168 
    169 
    170 FitsFile* FitsFile::ReadFInit(char flnm[],int hdunum)
    171 {
    172   InitNull();
    173   int status = 0;
    174   //  hdutype_= 0;
    175  
    176   fits_open_file(&fptr_,flnm,READONLY,&status);
    177   if( status ) printerror( status );
    178   //
    179   if (hdunum <= 1)
    180     {
    181       hdunum_ = 1;
    182       // presence of image ?
    183       int naxis= 0;
    184       fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
    185       if( status ) printerror( status );
    186       if (naxis > 0 )       // there is an image
    187         {
    188           hdutype_ = IMAGE_HDU;
    189           GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
    190           nbData_ =  1;
    191           int k;
    192           for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
    193           KeywordsIntoDVList(fptr_, dvl_,hdunum_);
    194         }
    195       else
    196         {
    197           throw PException(" first header : no image, probably error in hdunum");
    198         }
    199   //
    200     }
    201   else
    202     {
    203       hdunum_ = hdunum-1;
    204       int hdutype;
    205       fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    206       if( status ) printerror( status,":FitsFile::ReadF : erreur movabs");
    207       moveToFollowingHeader();
    208     }
    209   return this;
    210 }
    211 
    212 void FitsFile::ReadFFromFits()
    213 {
    214   ReadFromFits(*this);
    215 }
     173  //  return this;
     174}
     175
    216176void FitsFile::moveToFollowingHeader()
    217177{
     
    261221
    262222    }
    263   WriteToFits(*this);
     223  //  WriteToFits(*this);
     224  WriteToFits();
    264225}
    265226void FitsFile::GetSingleColumn(double* map, int nentries) const
     
    636597
    637598
    638 void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const
     599void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
    639600{
    640601  int status= 0;
     
    656617        case 'D' :
    657618          fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
    658           if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne double" );
    659619            break;
    660620        case 'E' :
    661621          fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
    662           if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
    663622          break;
    664623        case 'I' :
    665624          fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
    666625                        &anull,&status);
    667           if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne tint" );
    668626          break;
    669627        case 'S' :
    670628          fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
    671           if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne char" );
    672629          break;
    673630        }
    674     }
    675 }
    676 
    677 void FitsFile::GetBinTabLine(int NoLine, float* fdata) const
     631      if (status)
     632        {
     633          ResetStatus(status);
     634          break;
     635        }
     636      //          if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne char" );
     637    }
     638}
     639
     640void FitsFile::GetBinTabLine(int NoLine, float* fdata)
    678641{
    679642  int status= 0;
     
    685648    {
    686649      fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
    687       if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
     650      if (status)
     651        {
     652          ResetStatus(status);
     653          break;
     654        }
     655       //      if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
    688656    }
    689657}
     
    10661034
    10671035
    1068 void FitsFile::readheader()
    1069   //*************************************/
    1070   //* Print out all the header keywords */
    1071   //*************************************/
    1072 {
    1073   // standard string lengths defined in fitsioc.h
    1074   char card[FLEN_CARD];
    1075 
    1076   int status = 0;
    1077 
    1078   // get the number of keywords
    1079   int nkeys, keypos;
    1080   if( fits_get_hdrpos(fptr_,&nkeys,&keypos,&status) )
    1081     printerror( status );
    1082 
    1083   cout << " Header listing for HDU : " << hdunum_ << endl;
    1084   int jj;
    1085   for(jj = 1; jj <= nkeys; jj++) 
    1086     {
    1087       if( fits_read_record(fptr_,jj,card,&status) )
    1088         printerror( status );
    1089      
    1090       // print the keyword card
    1091       cout << card << endl;
    1092     }
    1093   cout << "END" << endl;
    1094 }
    10951036
    10961037
     
    11431084  throw IOExc("FitsFile:: error FITSIO status");
    11441085}
     1086
     1087int FitsFile::statusF() const
     1088{
     1089  return fits_status_;
     1090}
     1091void FitsFile::ResetStatus(int& status)
     1092{
     1093  fits_status_ = status;
     1094  status = 0;
     1095}
     1096
     1097string FitsFile::getErrStatus(int status)
     1098{
     1099  char text[31];
     1100  fits_get_errstatus(status, text);
     1101  return string(text);
     1102}
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1045 r1047  
    4848  static int NbBlocks(char flnm[]);
    4949  static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl  );
    50 /*! return true if the current header  corresponds to a FITS image extension */
    51 inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
    52 
    53 /*! return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
    54 inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
    55 
    56 /*!
    57 this method is called from inherited objects :
    58 
    59 moves to header 'hdunum' on file 'flnm'
    60 
    61 gets parameters in header
    62 
    63 calls the method 'ReadFromFits' from the inherited delegated object
    64 
    65 */
    66   void   ReadF(char flnm[],int hdunum= 0);
    67   FitsFile* ReadFInit(char flnm[],int hdunum=0);
    68   void ReadFFromFits();
     50
     51  protected:
    6952 
    7053/*!
    7154this method is called from inherited objects :
    7255
     56moves to header 'hdunum' on file 'flnm'
     57
     58gets parameters in header
     59
     60calls 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/*!
     68this method is called from inherited objects :
     69
    7370opens a file 'flnm'
    7471
    7572gets parameters in header
    7673
    77 calls the method 'ReadFromFits' from the inherited delegated object
     74calls the method 'ReadFromFits' from the inherited object
    7875
    7976*/
    80   void    WriteF(char flnm[], bool OldFile=false);
    81 
    82 
    83   /*!
    84 fill the array 'map' with double data from the current extension on FITS file.
    85 If the extension is BINTABLE, the first column is provided.
    86 
    87 \param <nentries>  number of data to be read
    88   */
    89   void    GetSingleColumn(double* map, int nentries) const;
    90 
    91   /*! same as above with float data */
    92   void    GetSingleColumn(float*  map, int nentries) const;
    93 
    94   /*! same as above with int data */
    95   void    GetSingleColumn(int* map, int nentries) const;
     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
     96  /*! return a reference on a DVList containing the keywords from FITS file
     97   */
     98  inline const DVList& DVListFromFits() const { return dvl_;}
     99
     100  void moveToFollowingHeader();
     101  int statusF() const;
     102
     103
     104/////////////////////////////////////////////////////////////
     105  //       methods for managing FITS IMAGE extension
     106  ///////////////////////////////////////////////////
     107
     108
     109  //read
     110  //----
     111
     112/*! return true if the current header  corresponds to a FITS image extension */
     113inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
    96114
    97115  /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
    98116   */
    99117inline int nbDimOfImage() const {return naxis_;}
    100 
     118/*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
     119 */
     120 inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
    101121/*!
    102122 total number of data in the current IMAGE extension
     
    104124inline int nbOfImageData() const { return nbData_; }
    105125
    106 /*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
    107  */
    108  inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
    109 
     126
     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
     151
     152//////////////////////////////////////////////////////////////////////////
     153  //       methods for managing FITS BINARY TABLE or ASCII TABLE extension
     154  ////////////////////////////////////////////////////////////////////////
     155
     156
     157
     158// read
     159//-----
     160
     161/*! return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
     162inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
    110163 /*! return number of columns (return 1 if IMAGE) */
    111164  int     NbColsFromFits() const;
    112 
     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;
    113169  /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
    114170
     
    123179  */
    124180  char    ColTypeFromFits(int nocol) const;
    125 
    126   /*! number of data in the current IMAGE extension on FITS file, or number
    127  of data of column number 'nocol' of the current BINTABLE extension
    128   */
    129   int     NentriesFromFits(int nocol) const;
    130 
    131181  /*! name of the column number 'nocol' of the current BINTABLE extension
    132182   */
    133183  string  ColNameFromFits(int nocol) const;
    134184
    135  
    136185  /*! number of characters of each data  for the column number 'nocol' (if char* typed) of the current BINTABLE extension
    137186   */
    138187  int     ColStringLengthFromFits(int nocol) const;
    139188
    140   /*! return a reference on a DVList containing the keywords from FITS file
    141    */
    142   inline const DVList& DVListFromFits() const { return dvl_;}
     189
     190
     191  /*!
     192get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
     193  */
     194  void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
     195** cdata) ;
     196
     197  /*!
     198get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
     199  */
     200  void GetBinTabLine(int NoLine, float* fdata) ;
     201
     202
     203
    143204
    144205
     
    158219  // Write elements into the FITS data array
    159220
    160   /*!
    161 get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
    162   */
    163   void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
    164 ** cdata) const;
    165   /*!
    166 get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
    167   */
    168   void GetBinTabLine(int NoLine, float* fdata) const;
    169 
    170 
    171 
    172 
    173   /*! write double data from array 'map'on an IMAGE extension
    174 \param <nbData>  number of data to be written
    175 
    176    */
    177   void putImageToFits( int nbData, double* map) const;
    178 
    179   /*! same as previous method with float data */
    180   void putImageToFits(int nbData, float* map ) const;
    181 
    182   /*! same as previous method with int data */
    183   void putImageToFits(int nbData, int* map) const;
    184 
    185   /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE  extension.
    186 \param <nentries>  number of data to be written
    187 
    188    */
    189   void putColToFits(int nocol, int nentries, double* donnees) const;
    190 
    191   /*! same as previous method with float data */
    192   void putColToFits(int nocol, int nentries, float* donnees) const;
    193 
    194   /*! same as previous method with int data */
    195   void putColToFits(int nocol, int nentries, int* donnees) const;
    196 
    197   /*! same as previous method with char* data */
    198   void putColToFits(int nocol, int nentries, char** donnees) const;
    199 
    200   /*! create an IMAGE header on FITS file.
    201 \param <type> type of data (see method ColTypeFromFits)
    202 \param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
    203 \param <naxisn>  array containind sizes of the different dimensions
    204   */
    205   void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
     221
     222
     223  //write
     224  //-----
    206225
    207226  /*! create an BINTABLE header on FITS file.
     
    216235  void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname,  vector<int> taille_des_chaines) ;
    217236
    218   void moveToFollowingHeader();
    219   void readheader();
    220 static  void printerror(int&) ;
    221 static  void printerror(int&,char* texte) ;
    222   protected: 
    223     virtual void    ReadFromFits(FitsFile& ff)=0;           
    224     virtual void    WriteToFits(FitsFile& ff)=0;           
     237  /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE  extension.
     238\param <nentries>  number of data to be written
     239
     240   */
     241  void putColToFits(int nocol, int nentries, double* donnees) const;
     242
     243  /*! same as previous method with float data */
     244  void putColToFits(int nocol, int nentries, float* donnees) const;
     245
     246  /*! same as previous method with int data */
     247  void putColToFits(int nocol, int nentries, int* donnees) const;
     248
     249  /*! same as previous method with char* data */
     250  void putColToFits(int nocol, int nentries, char** donnees) const;
     251
     252
     253/////////////////////////////////////////////////////////////
     254  //       methods for managing any type of FITS extension
     255  ////////////////////////////////////////////////////////
     256
     257
     258  /*!
     259fill the array 'map' with double data from the current extension on FITS file.
     260If 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
    225274private:
    226275
    227276   void InitNull();
     277   void ResetStatus(int& status) ;
     278   static  void printerror(int&) ;
     279   static  void printerror(int&,char* texte) ;
    228280
    229281static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
     
    279331  DVList dvl_;
    280332
     333
     334
     335  //! last status returned by fitsio library. updated only by several methods
     336  int fits_status_;
    281337};
    282338
  • trunk/SophyaExt/FitsIOServer/fitsntuple.cc

    r972 r1047  
    1515{
    1616  dobj_ = new NTuple;
    17   column_ = NULL;
    18   ownobj=true;
     17  InitNull();
     18  ownobj_ = true;
    1919}
    2020
     
    2222{
    2323  dobj_ = new NTuple;
    24   column_ = NULL;
    25   ownobj=true;
     24  InitNull();
     25  ownobj_ = true;
    2626
    2727  ReadF(inputfile,hdunum);
     
    3232{
    3333  dobj_ = new NTuple(obj);
    34   column_ = NULL;
    35   ownobj=true;
     34  InitNull();
     35  ownobj_ = true;
     36}
     37FITS_NTuple::FITS_NTuple(NTuple* obj)
     38{
     39  dobj_ = obj;
     40  InitNull();
     41  ownobj_ = false;
    3642}
    3743
     
    3945FITS_NTuple::~FITS_NTuple()
    4046{
    41   if (ownobj && dobj_ != NULL) delete dobj_;
     47  if (ownobj_ && dobj_ != NULL) delete dobj_;
    4248  if (column_ != NULL) delete [] column_;
    4349}
    4450
     51void FITS_NTuple::Read(char inputfile[],int hdunum)
     52{
     53  ReadF(inputfile,hdunum);
     54}
     55void FITS_NTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum)
     56{
     57  fistLineToBeRead_ = firstLine;
     58  numberOfLinesToBeRead_ = numberOfLines;
     59  ReadF(inputfile,hdunum);
     60}
     61
     62
     63
    4564void FITS_NTuple::Write(char outputfile[], bool OldFile)
    4665{
     
    4867}
    4968
    50 void FITS_NTuple::ReadFromFits(FitsFile& fn)
    51 {
    52   if (!fn.IsFitsTable())
     69void FITS_NTuple::ReadFromFits()
     70{
     71  //  if (!fn.IsFitsTable())
     72    if (!IsFitsTable())
    5373    {
    5474      throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table");
    5575    }
    5676  int nbcols, nbentries;
    57   nbcols = fn.NbColsFromFits();
     77  //  nbcols = fn.NbColsFromFits();
     78  nbcols = NbColsFromFits();
    5879  nbentries = 0;
    5980  int k;
    60   for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(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) );
    6183 
    6284  char ** ColName = new char*[nbcols];
     
    6587    {
    6688      ColName[k] = new char[LONNOM1];
    67       strncpy(ColName[k], fn.ColNameFromFits(k).c_str(),LONNOM);
     89      //      strncpy(ColName[k], fn.ColNameFromFits(k).c_str(),LONNOM);
     90      strncpy(ColName[k], ColNameFromFits(k).c_str(),LONNOM);
    6891      ColName[k][LONNOM] =  '\0';
    6992    }
    7093  for (k=0; k<nbcols;k++)
    7194    {
    72       char ss= fn.ColTypeFromFits(k);
     95      //      char ss= fn.ColTypeFromFits(k);
     96      char ss= ColTypeFromFits(k);
    7397      string type;
    7498      if (ss != 'E')
     
    87111    {
    88112      dobj_= new NTuple(nbcols,ColName);
    89       ownobj= true;     
     113      ownobj_ = true;     
    90114    }
    91115  else
     
    99123    }
    100124  delete [] ColName;
    101     if (column_ != NULL) delete [] column_;
    102     column_ = new float[nbentries];
     125  //   if (column_ != NULL) delete [] column_;
     126  //  column_ = new float[nbentries];
    103127
    104128  // j'initialise le NTuple a zero, pour le dimensionner
    105129  // (SetVal suppose que le ntuple est deja dimensionne)
    106130  r_4* ligne = new r_4[nbcols];
    107     for (k=0; k<nbcols; k++) ligne[k]=0.;
    108     for (k=0; k<nbentries;k++) dobj_->Fill(ligne);
     131  //  for (k=0; k<nbcols; k++) ligne[k]=0.;
     132  //  for (k=0; k<nbentries;k++) dobj_->Fill(ligne);
     133  //  delete [] ligne;
     134
     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      }
    109154    delete [] ligne;
    110   for (k=0; k<nbcols;k++)
    111     {
    112       fn.GetBinTabFCol(column_, nbentries, k);
    113       for (int nent=0; nent<nbentries; nent++) dobj_->SetVal(nent,k, column_[nent]);
    114     }
    115   dobj_->Info()=fn.DVListFromFits();
    116 }
    117 void FITS_NTuple::WriteToFits(FitsFile& fn)
     155
     156    //%%%%%%%
     157
     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}
     167void FITS_NTuple::WriteToFits()
    118168{
    119169  if(dobj_ == NULL)
     
    147197  type[ncols]='\0';
    148198  vector<int> dummy;
    149   fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
     199  //  fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
     200  makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
    150201   for (k=0; k< ncols; k++)
    151202    {
  • trunk/SophyaExt/FitsIOServer/fitsntuple.h

    r972 r1047  
    2222FITS_NTuple(char inputfile[],int hdunum=2);
    2323FITS_NTuple(const NTuple & obj);
     24 FITS_NTuple(NTuple* obj);
    2425virtual ~FITS_NTuple();
     26 void Read(char inputfile[],int hdunum=2);
     27/*!
     28fill the XNTuple only with lines from firstLine-th to (firstLine+numberOfLines-1)-th of the FITS-file inputfile.
     29\param <firstLine>  first line  to be read (the first line of the file is numbered 0)
     30\param <numberOfLines>  number of lines to be read
     31*/
     32 void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2);
    2533void Write(char outputfile[], bool OldFile=false);
    2634inline operator NTuple() { return(*dobj_); }
     
    2937
    3038  // implementation de FitsFile
    31 virtual void ReadFromFits(FitsFile& fn);
    32 virtual void WriteToFits(FitsFile& fn);
     39//virtual void ReadFromFits(FitsFile& fn);
     40virtual void ReadFromFits();
     41virtual void WriteToFits();
    3342
    3443float*  getColFromObj(int colNr);
    3544
     45 private :
     46
     47inline void InitNull()
     48   {
     49     fistLineToBeRead_= -1;
     50     numberOfLinesToBeRead_= -1;
     51     column_ = NULL;
     52   }
     53
     54
    3655  // attributs de classe
    3756  NTuple* dobj_;
    38   bool ownobj;
     57  bool ownobj_;
     58  int fistLineToBeRead_;
     59  int numberOfLinesToBeRead_;
    3960  float* column_;
    4061};
  • trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc

    r1004 r1047  
    8080
    8181template <class T>
    82 void FITS_SphereHEALPix<T>::WriteToFits(FitsFile& fn)
     82void FITS_SphereHEALPix<T>::WriteToFits()
    8383{
    8484  if(dobj_ == NULL)
     
    130130  Type[1]='\0';
    131131  vector<int> dummy;
    132   fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
     132  //  fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
     133  makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
    133134  delete [] Noms[0];
    134135  delete [] Noms;
     
    137138
    138139template <class T>
    139 void FITS_SphereHEALPix<T>::ReadFromFits(FitsFile& fn)
     140void FITS_SphereHEALPix<T>::ReadFromFits()
    140141{
    141142  if(dobj_ == NULL)
     
    148149 
    149150  int nbcols, nbentries;
    150   nbcols = fn.NbColsFromFits();
     151  //  nbcols = fn.NbColsFromFits();
     152  nbcols = NbColsFromFits();
    151153  if (nbcols != 1)
    152154    {
     
    154156    }
    155157  //   const DVList* dvl = &fn.DVListFromFits();
    156   DVList dvl=fn.DVListFromFits();
     158  //  DVList dvl=fn.DVListFromFits();
     159  DVList dvl=DVListFromFits();
    157160  //  dvl.Print();
    158    nbentries = fn.NentriesFromFits(0);
     161  //   nbentries = fn.NentriesFromFits(0);
     162   nbentries = NentriesFromFits(0);
    159163  int lastpix=dvl.GetI("LASTPIX");
    160164  if (lastpix>0)
     
    207211  // On lit les DataBlocks;
    208212  dobj_->pixels_.ReSize(nPix);
    209   fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
     213  //  fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
     214  GetSingleColumn(dobj_->pixels_.Data(),nPix);
    210215
    211216  // on effectue le decoupage en tranches
    212217  dobj_->SetThetaSlices();
    213   dobj_->Info()=fn.DVListFromFits();
     218  //  dobj_->Info()=fn.DVListFromFits();
     219  dobj_->Info()=DVListFromFits();
    214220
    215221
  • trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h

    r1011 r1047  
    3535protected:
    3636
    37 virtual void ReadFromFits(FitsFile& fn);
    38 virtual void WriteToFits(FitsFile& fn);
     37//virtual void ReadFromFits(FitsFile& fn);
     38virtual void ReadFromFits();
     39virtual void WriteToFits();
    3940SphereHEALPix<T>* dobj_;
    4041bool ownobj;
  • trunk/SophyaExt/FitsIOServer/fitstarray.cc

    r972 r1047  
    6060
    6161template <class T>
    62 void FITS_TArray<T>::ReadFromFits(FitsFile& fn)
     62void FITS_TArray<T>::ReadFromFits()
    6363{
    6464
    65   if (!fn.IsFitsImage())
     65  //  if (!fn.IsFitsImage())
     66  if (!IsFitsImage())
    6667    {
    6768      throw PException("ReadFromFits: the fits file seems not to be an image");
    6869    }
    69   int dimension = fn.nbDimOfImage();
     70  //  int dimension = fn.nbDimOfImage();
     71  int dimension = nbDimOfImage();
    7072  cout << " dimension de l'image a lire: " << dimension << endl;
    7173   
    7274  uint_4* siz = new uint_4[dimension];
    73   for (int k=0; k< dimension; k++) siz[k] = fn.dimOfImageAxes()[k];
     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];
    7477  if(dobj_ == NULL)
    7578    dobj_ = new TArray<T>(dimension,siz);
     
    7881 
    7982  delete [] siz;
    80   if (dobj_->Size() != fn.nbOfImageData() )
     83  //  if (dobj_->Size() != fn.nbOfImageData() )
     84  if (dobj_->Size() != nbOfImageData() )
    8185  {
    8286    cout << " total size of TArray: " << dobj_->Size() << endl;
    83     cout << " total size from fits file: " << fn.nbOfImageData() << endl;
     87    cout << " total size from fits file: " << nbOfImageData() << endl;
    8488      throw PException("ReadFromFits: size conflict");
    8589  }
    8690  // On lit le tableau
    87   fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
     91  //  fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
     92  GetSingleColumn( dobj_->Data(),dobj_->Size());
    8893
    8994}
     
    9196
    9297  template <class T>
    93 void FITS_TArray<T>::WriteToFits(FitsFile& fn
     98void FITS_TArray<T>::WriteToFits(
    9499{
    95100  if(dobj_ == NULL) return;
     
    125130    }
    126131  cout << " nombre total d'elements a copier " << nbels << endl;
    127   fn.makeHeaderImageOnFits(type, nbdim, naxisn);
     132  //  fn.makeHeaderImageOnFits(type, nbdim, naxisn);
     133  makeHeaderImageOnFits(type, nbdim, naxisn);
    128134  if (!dobj_->IsPacked())
    129135    {
     
    138144     
    139145    }
    140   fn.putImageToFits(nbels, dobj_->Data());
     146  //  fn.putImageToFits(nbels, dobj_->Data());
     147  putImageToFits(nbels, dobj_->Data());
    141148 
    142149  delete [] naxisn;
  • trunk/SophyaExt/FitsIOServer/fitstarray.h

    r1044 r1047  
    3535protected :
    3636
    37 void ReadFromFits(FitsFile& fn);
    38 void WriteToFits(FitsFile& fn);
     37  //void ReadFromFits(FitsFile& fn);
     38void ReadFromFits();
     39void WriteToFits();
    3940
    4041  TArray<T> * dobj_;
  • trunk/SophyaExt/FitsIOServer/fitsxntuple.cc

    r972 r1047  
    1313{
    1414  dobj_ = new XNTuple;
    15   dcolumn_ = NULL;
    16   fcolumn_ = NULL;
    17   icolumn_ = NULL;
    18   ccolumn_ = NULL;
    19   ownobj=true;
     15  InitNull();
     16  ownobj_ = true;
    2017}
    2118
     
    2320{
    2421  dobj_ = new XNTuple;
    25   dcolumn_ = NULL;
    26   fcolumn_ = NULL;
    27   icolumn_ = NULL;
    28   ccolumn_ = NULL;
    29   ownobj=true;
     22  InitNull();
     23  ownobj_ = true;
    3024
    3125  ReadF(inputfile,hdunum);
     
    3630{
    3731  dobj_ = new XNTuple(obj);
    38   dcolumn_ = NULL;
    39   fcolumn_ = NULL;
    40   icolumn_ = NULL;
    41   ccolumn_ = NULL;
    42   ownobj=true;
     32  InitNull();
     33  ownobj_ = true;
     34}
     35FITS_XNTuple::FITS_XNTuple(XNTuple* obj)
     36{
     37  dobj_ = obj;
     38  InitNull();
     39  ownobj_ = false;
    4340}
    4441FITS_XNTuple::~FITS_XNTuple()
     42{
     43  Clean();
     44}
     45
     46void FITS_XNTuple::Clean()
    4547{
    4648  if (dcolumn_ != NULL) delete [] dcolumn_;
     
    5860          cout << "FITS_XNTuple, destructeur: bizarre, ccolumn non vide, sans objet?" << endl;;         }
    5961    }
    60   if (ownobj && dobj_ != NULL) delete dobj_;
    61 }
     62  if (ownobj_ && dobj_ != NULL) delete dobj_;
     63}
     64
     65void FITS_XNTuple::Read(char inputfile[],int hdunum)
     66{
     67  ReadF(inputfile,hdunum);
     68}
     69
     70void FITS_XNTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum)
     71{
     72  fistLineToBeRead_ = firstLine;
     73  numberOfLinesToBeRead_ = numberOfLines;
     74  ReadF(inputfile,hdunum);
     75  //  return dobj_;
     76}
     77
     78
    6279void FITS_XNTuple::Write(char outputfile[], bool OldFile)
    6380{       
     
    6582}
    6683 
    67 void FITS_XNTuple::ReadFromFits(FitsFile& fn)
     84void FITS_XNTuple::ReadFromFits()
    6885{   
    69   if (!fn.IsFitsTable())
     86  //  if (!fn.IsFitsTable())
     87  if (!IsFitsTable())
    7088    {
    7189      throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table");
    7290    }
    7391  int nbcols, nbentries;
    74   nbcols = fn.NbColsFromFits();
     92  //  nbcols = fn.NbColsFromFits();
     93  nbcols = NbColsFromFits();
    7594  nbentries = 0;
    7695  int k;
    77   for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(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) );
    7898
    7999  //
     
    91111  for (k=0; k<nbcols;k++)
    92112    {
    93       char ss= fn.ColTypeFromFits(k);
     113      //      char ss= fn.ColTypeFromFits(k);
     114      char ss= ColTypeFromFits(k);
    94115      if (ss == 'D') DfitsCol.push_back(k);
    95116      else if (ss == 'E') FfitsCol.push_back(k);
     
    106127    {
    107128      ColName[compt] = new char[LONNOM+1];
    108       strncpy(ColName[compt], fn.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
     129      //      strncpy(ColName[compt], fn.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
     130      strncpy(ColName[compt], ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
    109131      ColName[compt++][ LONNOM] =  '\0';
    110132    }
     
    112134    {
    113135      ColName[compt] = new char[LONNOM+1];
    114       strncpy(ColName[compt], fn.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
     136      //      strncpy(ColName[compt], fn.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
     137      strncpy(ColName[compt], ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
    115138      ColName[compt++][ LONNOM] =  '\0';
    116139    }
     
    118141    {
    119142      ColName[compt] = new char[LONNOM+1];
    120       strncpy(ColName[compt], fn.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
     143      //      strncpy(ColName[compt], fn.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
     144      strncpy(ColName[compt], ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
    121145      ColName[compt++][ LONNOM] =  '\0';
    122146    }
     
    124148    {
    125149      ColName[compt] = new char[LONNOM+1];
    126       strncpy(ColName[compt], fn.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
     150      //      strncpy(ColName[compt], fn.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
     151      strncpy(ColName[compt], ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
    127152      ColName[compt++][LONNOM] =  '\0';
    128153    }
    129 
    130154
    131155  if(dobj_ == NULL)
    132156    {
    133157      dobj_= new XNTuple(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(),ColName);
    134       ownobj= true;     
     158      ownobj_ = true;     
    135159    }
    136160  else
    137161    {
    138       dobj_->clean();
     162      if (ownobj_)
     163        {
    139164      (*dobj_)= XNTuple(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(),ColName);
    140     }
     165        }
     166      else
     167        {
     168        if (DfitsCol.size() != dobj_->NDVar() || FfitsCol.size() != dobj_->NFVar() ||  IfitsCol.size() != dobj_->NIVar() || SfitsCol.size() != dobj_->NSVar())
     169
     170          throw  SzMismatchError("FITS_XNTuple : structure incorrecte du ntuple");
     171        }
     172    }
     173
    141174  for (k=0; k<nbcols;k++)
    142175    {
     
    145178  delete [] ColName;
    146179
    147   // j'initialise le NTuple a zero, pour le dimensionner
    148   // (SetXVal suppose que le ntuple est deja dimensionne)
    149   r_8* dligne;
    150   r_4* fligne;
    151   int_4* iligne;
    152   char** cligne;
    153   if (DfitsCol.size()>0)
    154     {
    155       if (dcolumn_ != NULL) delete [] dcolumn_;
    156       dcolumn_ = new double[nbentries];
    157       dligne = new r_8[DfitsCol.size()];
    158       for (k=0; k<DfitsCol.size(); k++) dligne[k]=0.;
    159     }
     180    r_8* dligne;
     181    r_4* fligne;
     182    int_4* iligne;
     183    char** cligne;
     184
     185  if (DfitsCol.size()>0) dligne = new r_8[DfitsCol.size()];
    160186  else dligne=NULL;
    161   if (FfitsCol.size()>0)
    162     {
    163       if (fcolumn_ != NULL) delete [] fcolumn_;
    164       fcolumn_ = new float[nbentries];
    165       fligne = new r_4[FfitsCol.size()];
    166       for (k=0; k<FfitsCol.size(); k++) fligne[k]=0.;
    167     }
     187  if (FfitsCol.size()>0) fligne = new r_4[FfitsCol.size()];
    168188  else fligne=NULL;
    169   if (IfitsCol.size()>0)
    170     {
    171       if (icolumn_ != NULL) delete [] icolumn_;
    172       icolumn_ = new int[nbentries];
    173       iligne = new int_4[IfitsCol.size()];
    174       for (k=0; k<IfitsCol.size(); k++) iligne[k]=0;
    175     }
     189  if (IfitsCol.size()>0) iligne = new int_4[IfitsCol.size()];
    176190  else iligne=NULL;
    177191  if (SfitsCol.size()>0)
    178192    {
    179       if (ccolumn_ != NULL)
    180         {
    181           for (k=0; k<dobj_->NEntry(); k++) delete [] ccolumn_[k];
    182           delete [] ccolumn_;
    183           ccolumn_ = NULL;
    184         }
    185       ccolumn_ = new char*[nbentries];
     193      cligne = new char*[SfitsCol.size()];
    186194      int  taille_des_chaines=0;
    187       for (k=0; k< SfitsCol.size(); k++)  taille_des_chaines = max( taille_des_chaines, fn.ColStringLengthFromFits(SfitsCol[k]) );
    188       for (k=0; k<nbentries;k++) ccolumn_[k]= new char[taille_des_chaines+1];
    189       cligne = new char*[SfitsCol.size()];
    190       for (k=0; k<SfitsCol.size(); k++) cligne[k]=" ";
     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]) );
     197      for (k=0; k<SfitsCol.size(); k++) cligne[k]=new char[taille_des_chaines+1];
    191198    }
    192199  else cligne=NULL;
    193 
    194   for (k=0; k<nbentries;k++) dobj_->Fill(dligne, fligne, iligne, cligne);
    195   delete [] dligne;
    196   delete [] fligne;
    197   delete [] iligne;
    198   for (k=0; k< SfitsCol.size(); k++) delete []  cligne[k];
    199   delete [] cligne;
    200    
    201   compt=0;
    202   for (k=0; k<DfitsCol.size(); k++)
    203     {
    204       fn.GetBinTabFCol(dcolumn_, nbentries, DfitsCol[k]);
    205       for (int nent=0; nent<nbentries; nent++) dobj_->SetDVal(nent,compt, dcolumn_[nent]);
    206       compt++;
    207     }
    208  
    209   for (k=0; k<FfitsCol.size(); k++)
    210     {
    211       fn.GetBinTabFCol(fcolumn_,nbentries, FfitsCol[k]);
    212       for (int nent=0; nent<nbentries; nent++) dobj_->SetFVal(nent,compt, fcolumn_[nent]);
    213       compt++;
    214     }
    215              
    216   for (k=0; k<IfitsCol.size(); k++)
    217     {
    218       fn.GetBinTabFCol(icolumn_,nbentries, IfitsCol[k]);
    219       for (int nent=0; nent<nbentries; nent++) dobj_->SetIVal(nent,compt, icolumn_[nent]);
    220       compt++;
    221     }
    222  
    223   for (k=0; k<SfitsCol.size(); k++)
    224     {
    225       fn.GetBinTabFCol(ccolumn_,nbentries, SfitsCol[k]);
    226             for (int nent=0; nent<nbentries; nent++) dobj_->SetSVal(nent,compt, ccolumn_[nent]);
    227       compt++;
    228     }
    229   dobj_->Info()=fn.DVListFromFits();
    230 
    231 }
    232 void FITS_XNTuple::WriteToFits(FitsFile& fn)
     200  int firstln, lastln;
     201  if (numberOfLinesToBeRead_ > 0)
     202    {
     203      firstln = fistLineToBeRead_;
     204      lastln = firstln + numberOfLinesToBeRead_;
     205    }
     206  else
     207    {
     208      firstln = 0;
     209      lastln  = nbentries;
     210    }
     211  int numLigne;
     212  for (numLigne=firstln; numLigne < lastln; numLigne++)
     213    {
     214      //      fn.GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
     215      GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
     216      dobj_->Fill(dligne, fligne, iligne, cligne);   
     217    }
     218    delete [] dligne;
     219    delete [] fligne;
     220    delete [] iligne;
     221    for (k=0; k< SfitsCol.size(); k++) delete []  cligne[k];
     222    delete [] cligne;
     223    //  dobj_->Info()=fn.DVListFromFits();
     224  dobj_->Info()=DVListFromFits();
     225
     226}
     227void FITS_XNTuple::WriteToFits()
    233228{
    234229  if(dobj_ == NULL)
     
    276271  for (k=0; k< StringSizes.size(); k++) StringSizes[k]=dobj_->mStrSz;
    277272  // la librairie fitsio ecrit colonne par colonne
    278     fn.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes);
     273  //    fn.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes);
     274    makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes);
    279275   for (k=0; k< ncols; k++)
    280276    {
  • trunk/SophyaExt/FitsIOServer/fitsxntuple.h

    r972 r1047  
    2222FITS_XNTuple(char inputfile[],int hdunum=2);
    2323FITS_XNTuple(const XNTuple & obj);
     24FITS_XNTuple(XNTuple* obj);
    2425~FITS_XNTuple();
     26 void Read(char inputfile[],int hdunum=2);
     27
     28/*!
     29fill the XNTuple only with lines from firstLine-th to (firstLine+numberOfLines-1)-th of the FITS-file inputfile.
     30\param <firstLine>  first line  to be read (the first line of the file is numbered 0)
     31\param <numberOfLines>  number of lines to be read
     32*/
     33void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2);
    2534void Write(char outputfile[], bool OldFile=false);
    2635inline operator XNTuple() { return(*dobj_); }
     
    2938
    3039  // implementation de FitsFile
    31   virtual void  ReadFromFits(FitsFile& fn);
    32 virtual void    WriteToFits(FitsFile& fn);
     40//  virtual void  ReadFromFits(FitsFile& fn);
     41 virtual void  ReadFromFits();
     42virtual void    WriteToFits();
    3343void*   getColFromObj(int colNr);
    3444double* getColDFromObj(int colNr);
     
    3747char**  getColSFromObj(int colNr);
    3848
     49 private :
     50
     51 void Clean();
     52
     53inline void InitNull()
     54   {
     55     fistLineToBeRead_= -1;
     56     numberOfLinesToBeRead_= -1;
     57     dcolumn_ = NULL;
     58     fcolumn_ = NULL;
     59     icolumn_ = NULL;
     60     ccolumn_ = NULL;
     61   }
     62
    3963  // attributs de classe
    4064  XNTuple* dobj_;
    41   bool    ownobj;
     65  bool    ownobj_;
     66  int fistLineToBeRead_;
     67  int numberOfLinesToBeRead_;
    4268  double* dcolumn_;
    4369  float*  fcolumn_;
Note: See TracChangeset for help on using the changeset viewer.