source: Sophya/trunk/SophyaExt/FitsIOServer/fitsntuple.cc@ 1354

Last change on this file since 1354 was 1300, checked in by ansari, 25 years ago

classe FITS_AutoReader

File size: 4.0 KB
RevLine 
[860]1#include "pexceptions.h"
2#include "fitsntuple.h"
3///////////////////////////////////////////////////////////
4// Les objets delegues pour la gestion de persistance sur fichiers fits
5// pout NTuple
6///////////////////////////////////////////////////////////
7
8
9#define LONNOM 8
10#define LONNOM1 (LONNOM+1)
11
12
13
14FITS_NTuple::FITS_NTuple()
15{
16 dobj_ = new NTuple;
[1047]17 InitNull();
18 ownobj_ = true;
[860]19}
20
21FITS_NTuple::FITS_NTuple(char inputfile[],int hdunum)
22{
23 dobj_ = new NTuple;
[1047]24 InitNull();
25 ownobj_ = true;
[860]26
[1136]27 Read(inputfile,hdunum);
[860]28}
29
30
31FITS_NTuple::FITS_NTuple(const NTuple & obj)
32{
33 dobj_ = new NTuple(obj);
[1047]34 InitNull();
35 ownobj_ = true;
[860]36}
[1047]37FITS_NTuple::FITS_NTuple(NTuple* obj)
38{
39 dobj_ = obj;
40 InitNull();
41 ownobj_ = false;
42}
[860]43
44
45FITS_NTuple::~FITS_NTuple()
46{
[1047]47 if (ownobj_ && dobj_ != NULL) delete dobj_;
[1136]48 // if (column_ != NULL) delete [] column_;
[860]49}
50
[1136]51//void FITS_NTuple::Read(char inputfile[],int hdunum)
52//{
53// ReadF(inputfile,hdunum);
54//}
[1047]55void FITS_NTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum)
56{
57 fistLineToBeRead_ = firstLine;
58 numberOfLinesToBeRead_ = numberOfLines;
[1136]59 Read(inputfile,hdunum);
[1047]60}
61
62
63
[1136]64//void FITS_NTuple::Write(char outputfile[], bool OldFile)
65//{
66// WriteF(outputfile, OldFile);
67//}
[860]68
[1136]69void FITS_NTuple::ReadFromFits(FitsInFile& is)
[860]70{
[1136]71 if (!is.IsFitsTable())
[860]72 {
73 throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table");
74 }
75 int nbcols, nbentries;
[1136]76 nbcols = is.NbColsFromFits();
[860]77 nbentries = 0;
[923]78 int k;
[1136]79 for (k=0; k<nbcols; k++) nbentries=max( nbentries, is.NentriesFromFits(k) );
[860]80
81 char ** ColName = new char*[nbcols];
82
[923]83 for (k=0; k<nbcols;k++)
[860]84 {
85 ColName[k] = new char[LONNOM1];
[1136]86 strncpy(ColName[k], is.ColNameFromFits(k).c_str(),LONNOM);
[860]87 ColName[k][LONNOM] = '\0';
88 }
[923]89 for (k=0; k<nbcols;k++)
[860]90 {
[1300]91 FitsFile::FitsDataType ss= is.ColTypeFromFits(k);
[860]92 string type;
[1300]93 if (ss != FitsFile::FitsDataType_float)
[860]94 {
[1300]95 if (ss == FitsFile::FitsDataType_double) type= string("double");
[860]96 else
[1300]97 if (ss == FitsFile::FitsDataType_int) type= string("integer");
[860]98 else
[1300]99 if (ss == FitsFile::FitsDataType_char) type = string("char*");
[860]100 else
101 type = string("unknown");
102 cout << " WARNING: the column " << k << " on fits file is not float but : " << type << endl;
103 }
104 }
105 if(dobj_ == NULL)
106 {
107 dobj_= new NTuple(nbcols,ColName);
[1047]108 ownobj_ = true;
[860]109 }
110 else
111 {
112 dobj_->Clean();
113 (*dobj_) = NTuple(nbcols,ColName);
114 }
[923]115 for (k=0; k<nbcols;k++)
[860]116 {
117 delete [] ColName[k];
118 }
119 delete [] ColName;
120
[1143]121 float* ligne = new float[nbcols];
[1047]122
[1136]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);
[1143]138 dobj_->Fill((r_4*)ligne);
[1136]139 }
140 delete [] ligne;
[1047]141
[1136]142 dobj_->Info()=is.DVListFromFits();
143}
[1047]144
[1136]145void FITS_NTuple::WriteToFits(FitsOutFile& os)
[860]146{
147 if(dobj_ == NULL)
148 {
149 cout << " WriteToFits:: dobj_= null " << endl;
150 return;
151 }
152
153 // table will have 'ncols' columns
154 int ncols = dobj_->NVar();
155
156 // table will have 'nrows' rows
157 int nentries = dobj_->NEntry();
158
159 // get names and values from the join DVList object
160 DVList dvl= dobj_->Info();
[1300]161 dvl["Content"]= "NTuple";
162 dvl.SetComment("Content", "name of SOPHYA object");
[860]163 // extension name
[1194]164 string extname("NTuple_Binary_tbl");
[860]165
[1194]166 vector<string> Noms(ncols);
[923]167 int k;
168 for (k=0; k< ncols; k++)
[860]169 {
[1194]170 Noms[k]= dobj_->NomIndex(k);
[860]171 }
[1136]172
[1194]173 string type(ncols, 'E');
[860]174 vector<int> dummy;
[1136]175
[1221]176 os.makeHeaderBntblOnFits(type,Noms, nentries, ncols, &dvl, extname, dummy);
[1136]177 float* column = new float[nentries];
178 for (k=0; k<ncols;k++)
179 {
180 for(int j = 0; j < nentries; j++) column[j]= dobj_->GetVal(j,k);
[1210]181 os.PutColToFits(k, nentries, column);
[1136]182 }
183 delete [] column;
[860]184
185}
186
Note: See TracBrowser for help on using the repository browser.