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

Last change on this file since 2130 was 1371, checked in by ansari, 25 years ago

MAJ documentation, Makefile, ... - Reza 5/1/2001

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