1 | #include "pexceptions.h"
|
---|
2 | #include "fitsbntbllinereader.h"
|
---|
3 | ///////////////////////////////////////////////////////////
|
---|
4 | //
|
---|
5 | //
|
---|
6 | ///////////////////////////////////////////////////////////
|
---|
7 |
|
---|
8 |
|
---|
9 | #define LONNOM 31
|
---|
10 |
|
---|
11 |
|
---|
12 | FITS_BntblLineReader::FITS_BntblLineReader()
|
---|
13 | {
|
---|
14 | InitNull();
|
---|
15 | }
|
---|
16 |
|
---|
17 | FITS_BntblLineReader::FITS_BntblLineReader(char inputfile[],int hdunum)
|
---|
18 | {
|
---|
19 | InitNull();
|
---|
20 |
|
---|
21 | // FitsFile* fn=ReadFInit(inputfile,hdunum);
|
---|
22 | // ReadFInit(inputfile,hdunum);
|
---|
23 | inFits_ = new FitsInFile (inputfile);
|
---|
24 | inFits_->ReadFInit(hdunum);
|
---|
25 |
|
---|
26 | // if (!fn->IsFitsTable())
|
---|
27 | if (!inFits_->IsFitsTable())
|
---|
28 | {
|
---|
29 | throw PException("FITS_BntblLineReader: the fits file seems not to be a bintable nor ASCII table");
|
---|
30 | }
|
---|
31 |
|
---|
32 | //
|
---|
33 | int nbcols, nbentries;
|
---|
34 | // nbcols = fn->NbColsFromFits();
|
---|
35 | nbcols = inFits_->NbColsFromFits();
|
---|
36 | nbentries = 0;
|
---|
37 | int k;
|
---|
38 | // for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn->NentriesFromFits(k) );
|
---|
39 | for (k=0; k<nbcols; k++) nbentries=max( nbentries, inFits_->NentriesFromFits(k) );
|
---|
40 |
|
---|
41 | //
|
---|
42 | // pour mettre les colonnes dans l'ordre double, float, int, char :
|
---|
43 | // tableau de correspondance
|
---|
44 | // DfitsCol(j)= numero dans le fichier fits de la jeme variable double du
|
---|
45 | // xntuple;
|
---|
46 | // FfitsCol(j)= numero dans le fichier fits de la jeme variable float du
|
---|
47 | // xntuple;
|
---|
48 | // etc.
|
---|
49 | vector<int> DfitsCol;
|
---|
50 | vector<int> FfitsCol;
|
---|
51 | vector<int> IfitsCol;
|
---|
52 | vector<int> SfitsCol;
|
---|
53 | for (k=0; k<nbcols;k++)
|
---|
54 | {
|
---|
55 | // char ss= fn->ColTypeFromFits(k);
|
---|
56 | char ss= inFits_->ColTypeFromFits(k);
|
---|
57 | if (ss == 'D') DfitsCol.push_back(k);
|
---|
58 | else if (ss == 'E') FfitsCol.push_back(k);
|
---|
59 | else if (ss == 'I') IfitsCol.push_back(k);
|
---|
60 | else if (ss == 'S') SfitsCol.push_back(k);
|
---|
61 | else {
|
---|
62 | cout << " FITS_XNTuple: colonne fits " << k << " type= " << ss << endl;
|
---|
63 | throw IOExc("type de champ inconnu");
|
---|
64 | }
|
---|
65 | }
|
---|
66 | ColName_ = new char*[nbcols];
|
---|
67 | int compt=0;
|
---|
68 | for (k=0; k<DfitsCol.size(); k++)
|
---|
69 | {
|
---|
70 | ColName_[compt] = new char[LONNOM+1];
|
---|
71 | // strncpy(ColName_[compt], fn->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
|
---|
72 | strncpy(ColName_[compt], inFits_->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
|
---|
73 | ColName_[compt++][ LONNOM] = '\0';
|
---|
74 | }
|
---|
75 | for (k=0; k<FfitsCol.size(); k++)
|
---|
76 | {
|
---|
77 | ColName_[compt] = new char[LONNOM+1];
|
---|
78 | // strncpy(ColName_[compt], fn->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
|
---|
79 | strncpy(ColName_[compt], inFits_->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
|
---|
80 | ColName_[compt++][ LONNOM] = '\0';
|
---|
81 | }
|
---|
82 | for (k=0; k<IfitsCol.size(); k++)
|
---|
83 | {
|
---|
84 | ColName_[compt] = new char[LONNOM+1];
|
---|
85 | // strncpy(ColName_[compt], fn->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
|
---|
86 | strncpy(ColName_[compt], inFits_->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
|
---|
87 | ColName_[compt++][ LONNOM] = '\0';
|
---|
88 | }
|
---|
89 | for (k=0; k<SfitsCol.size(); k++)
|
---|
90 | {
|
---|
91 | ColName_[compt] = new char[LONNOM+1];
|
---|
92 | // strncpy(ColName_[compt], fn->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
|
---|
93 | strncpy(ColName_[compt], inFits_->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
|
---|
94 | ColName_[compt++][LONNOM] = '\0';
|
---|
95 | }
|
---|
96 |
|
---|
97 | if (DfitsCol.size()>0)
|
---|
98 | {
|
---|
99 | dcount_ = DfitsCol.size();
|
---|
100 | ddata_ = new double[dcount_];
|
---|
101 | }
|
---|
102 | if (FfitsCol.size()>0)
|
---|
103 | {
|
---|
104 | fcount_ = FfitsCol.size();
|
---|
105 | fdata_ = new float[fcount_];
|
---|
106 | }
|
---|
107 | if (IfitsCol.size()>0)
|
---|
108 | {
|
---|
109 | icount_ = IfitsCol.size();
|
---|
110 | idata_ = new int[icount_];
|
---|
111 | }
|
---|
112 | if (SfitsCol.size()>0)
|
---|
113 | {
|
---|
114 | ccount_ = SfitsCol.size();
|
---|
115 | cdata_ = new char*[ccount_];
|
---|
116 | taille_des_chaines_ = 0;
|
---|
117 | // for (k=0; k< ccount_; k++) taille_des_chaines_ = max( taille_des_chaines_, fn->ColStringLengthFromFits(SfitsCol[k]) );
|
---|
118 | for (k=0; k< ccount_; k++) taille_des_chaines_ = max( taille_des_chaines_, inFits_->ColStringLengthFromFits(SfitsCol[k]) );
|
---|
119 | for (k=0; k<ccount_; k++) cdata_[k]=new char[taille_des_chaines_+1];
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | FITS_BntblLineReader::~FITS_BntblLineReader()
|
---|
125 | {
|
---|
126 | if (inFits_ != NULL) delete inFits_;
|
---|
127 | if (ddata_ != NULL) delete [] ddata_;
|
---|
128 | if (fdata_ != NULL) delete [] fdata_;
|
---|
129 | if (idata_ != NULL) delete [] idata_;
|
---|
130 | if (cdata_ != NULL)
|
---|
131 | {
|
---|
132 | if (ccount_ != 0)
|
---|
133 | {
|
---|
134 | for (int k=0; k< ccount_; k++)
|
---|
135 | {
|
---|
136 | delete [] cdata_[k];
|
---|
137 | delete [] ColName_[k];
|
---|
138 | }
|
---|
139 | delete [] cdata_;
|
---|
140 | delete [] ColName_;
|
---|
141 | }
|
---|
142 | else
|
---|
143 | {
|
---|
144 | cout << "FITS_BntblLineReader, destructeur: bizarre, cdata non vide, avec ccount=0 ?" << endl;; }
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | XNTuple FITS_BntblLineReader::ReadNextLine()
|
---|
150 | {
|
---|
151 | inFits_->GetBinTabLine(nextLineToBeRead_++, ddata_, fdata_, idata_, cdata_ );
|
---|
152 | XNTuple xnt(dcount_, fcount_, icount_,ccount_, ColName_);
|
---|
153 | xnt.Fill(ddata_, fdata_, idata_, cdata_);
|
---|
154 | return xnt;
|
---|
155 | }
|
---|
156 |
|
---|
157 | void FITS_BntblLineReader::ReadFromFits(FitsInFile&)
|
---|
158 | {
|
---|
159 | }
|
---|
160 |
|
---|
161 | void FITS_BntblLineReader::WriteToFits(FitsOutFile&)
|
---|
162 | {
|
---|
163 | }
|
---|