source: Sophya/trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.cc@ 1048

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

lecteur de bintable par lignes

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