#include "pexceptions.h" #include "fitsntuple.h" /////////////////////////////////////////////////////////// // Les objets delegues pour la gestion de persistance sur fichiers fits // pout NTuple /////////////////////////////////////////////////////////// #define LONNOM 8 #define LONNOM1 (LONNOM+1) FITS_NTuple::FITS_NTuple() { dobj_ = new NTuple; column_ = NULL; ownobj=true; } FITS_NTuple::FITS_NTuple(char inputfile[],int hdunum) { dobj_ = new NTuple; column_ = NULL; ownobj=true; ReadF(inputfile,hdunum); } FITS_NTuple::FITS_NTuple(const NTuple & obj) { dobj_ = new NTuple(obj); column_ = NULL; ownobj=true; } FITS_NTuple::~FITS_NTuple() { if (ownobj && dobj_ != NULL) delete dobj_; if (column_ != NULL) delete [] column_; } void FITS_NTuple::Write(char outputfile[], bool OldFile) { WriteF(outputfile, OldFile); } void FITS_NTuple::ReadFromFits(FitsFile& fn) { if (!fn.IsFitsTable()) { throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table"); } int nbcols, nbentries; nbcols = fn.NbColsFromFits(); nbentries = 0; int k; for (k=0; kClean(); (*dobj_) = NTuple(nbcols,ColName); } for (k=0; kFill(ligne); delete [] ligne; for (k=0; kSetVal(nent,k, column_[nent]); } dobj_->Info()=fn.DVListFromFits(); } void FITS_NTuple::WriteToFits(FitsFile& fn) { if(dobj_ == NULL) { cout << " WriteToFits:: dobj_= null " << endl; return; } // table will have 'ncols' columns int ncols = dobj_->NVar(); // table will have 'nrows' rows int nentries = dobj_->NEntry(); // get names and values from the join DVList object DVList dvl= dobj_->Info(); // extension name char* extname = "NTuple_Binary_tbl"; dvl.Print(); char** Noms = new char*[ncols]; int k; for (k=0; k< ncols; k++) { Noms[k]= new char[LONNOM1]; strncpy(Noms[k],dobj_->NomIndex(k),LONNOM1); } // la librairie fitsio ecrit colonne par colonne char* type= new char[ncols+1]; for (k=0;k dummy; fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy); for (k=0; k< ncols; k++) { delete [] Noms[k]; } delete [] Noms; delete [] type; for (k=0; kNEntry()]; for(int j = 0; j < dobj_->NEntry(); j++) column_[j]= dobj_->GetVal(j,colNr); return column_; }