#include "pexceptions.h" #include "fitsxntuple.h" /////////////////////////////////////////////////////////// // Les objets delegues pour la gestion de persistance sur fichiers fits // pout XNTuple /////////////////////////////////////////////////////////// /*! \class SOPHYA::FITS_XNTuple \ingroup FitsIOServer FITS format I/O handler for SOPHYA::XNTuple objects. */ #define LONNOM 31 FITS_XNTuple::FITS_XNTuple() { dobj_ = new XNTuple; InitNull(); ownobj_ = true; } FITS_XNTuple::FITS_XNTuple(char inputfile[],int hdunum) { dobj_ = new XNTuple; InitNull(); ownobj_ = true; Read(inputfile,hdunum); } FITS_XNTuple::FITS_XNTuple(const XNTuple & obj) { dobj_ = new XNTuple(obj); InitNull(); ownobj_ = true; } FITS_XNTuple::FITS_XNTuple(XNTuple* obj) { dobj_ = obj; InitNull(); ownobj_ = false; } FITS_XNTuple::~FITS_XNTuple() { if (ownobj_ && dobj_ != NULL) delete dobj_; } void FITS_XNTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum) { fistLineToBeRead_ = firstLine; numberOfLinesToBeRead_ = numberOfLines; Read(inputfile,hdunum); } void FITS_XNTuple::ReadFromFits(FitsInFile& is) { if (!is.IsFitsTable()) { throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table"); } int nbcols, nbentries; nbcols = is.NbColsFromFits(); nbentries = 0; int k; for (k=0; k DfitsCol; vector FfitsCol; vector IfitsCol; vector SfitsCol; for (k=0; kNDVar() || NF != dobj_->NFVar() || NI != dobj_->NIVar() || NS != dobj_->NSVar()) { cout << " WARNING : FITS_XNTuple : XNTuple reconfigured " << endl; (*dobj_)= XNTuple(ND, NF, NI, NS,ColName); } } } for (k=0; k0) dligne = new double[ND]; else dligne=NULL; if (NF>0) fligne = new float[NF]; else fligne=NULL; if (NI) iligne = new int[NI]; else iligne=NULL; if (NS) { cligne = new char*[NS]; int taille_des_chaines=0; for (k=0; k< NS; k++) taille_des_chaines = max( taille_des_chaines, is.ColStringLengthFromFits(SfitsCol[k]) ); for (k=0; k 0) { firstln = fistLineToBeRead_; lastln = firstln + numberOfLinesToBeRead_; } else { firstln = 0; lastln = nbentries; } int numLigne; for (numLigne=firstln; numLigne < lastln; numLigne++) { is.GetBinTabLine(numLigne, dligne, fligne, iligne, cligne ); dobj_->Fill((r_8*)dligne, (r_4*)fligne, (int_4*)iligne, cligne); } delete [] dligne; delete [] fligne; delete [] iligne; for (k=0; k< SfitsCol.size(); k++) delete [] cligne[k]; delete [] cligne; dobj_->Info()=is.DVListFromFits(); } void FITS_XNTuple::WriteToFits(FitsOutFile& os) { if(dobj_ == NULL) { cout << " WriteToFits:: dobj_= null " << endl; return; } // table will have 'ncols' columns int ncols = dobj_->NVar(); // table will have 'nrows' rows int nrows = dobj_->NEntry(); cout << " FITS_XNTuple::WriteToFits : nombre de lignes a ecrire " << nrows << endl; // get names and values from the join DVList object DVList dvl= dobj_->Info(); // extension name string extname("XNTuple_Binary_tbl"); vector Noms(ncols); int k; for (k=0; k< ncols; k++) { Noms[k] = dobj_->NomIndex(k) ; } string types; for (k=0; kNDVar();k++) { types+='D'; } for (k=0; kNFVar();k++) { types+='E'; } for (k=0; kNIVar();k++) { types+='I'; } for (k=0; kNSVar();k++) { types+='A'; } vector StringSizes(dobj_->NSVar()); for (k=0; k< StringSizes.size(); k++) StringSizes[k]=dobj_->mStrSz; dvl["Content"]= "XNTuple"; dvl.SetComment("Content", "name of SOPHYA object"); os.makeHeaderBntblOnFits(types, Noms, nrows, ncols, &dvl, extname,StringSizes); int compt=0; if (dobj_->NDVar() > 0) { double* dcolumn = new double[nrows]; for (k=0; kNDVar();k++) { for(int j = 0; j < nrows; j++) dcolumn[j]= dobj_->GetDVal(j,compt); os.PutColToFits(compt, nrows, dcolumn); compt++; } delete [] dcolumn; } if (dobj_->NFVar() > 0) { float* fcolumn = new float[nrows]; for (k=0; kNFVar();k++) { for(int j = 0; j < nrows; j++) fcolumn[j]= dobj_->GetFVal(j,compt); os.PutColToFits(compt, nrows, fcolumn); compt++; } delete [] fcolumn; } if (dobj_->NIVar() > 0) { int_4* icolumn = new int_4[nrows]; for (k=0; kNIVar();k++) { for(int j = 0; j < nrows; j++) icolumn[j]= dobj_->GetIVal(j,compt); os.PutColToFits(compt, nrows, icolumn); compt++; } delete [] icolumn; } if (dobj_->NSVar() > 0) { char** ccolumn = new char*[nrows]; for (k=0; kNSVar();k++) { int j; for(j = 0; j < nrows; j++) { string s= dobj_->GetSVal(j,compt); ccolumn[j] = new char[dobj_->mStrSz+1]; strcpy(ccolumn[j],s.c_str()); } os.PutColToFits(compt, nrows, ccolumn); compt++; for(j = 0; j < nrows; j++) { delete [] ccolumn[j]; ccolumn[j] = NULL; } } delete [] ccolumn; } }