1 | #include "machdefs.h"
|
---|
2 | #include "sopnamsp.h"
|
---|
3 |
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <string.h>
|
---|
6 | #include <iostream>
|
---|
7 | #include <typeinfo>
|
---|
8 |
|
---|
9 | #include "histos.h"
|
---|
10 | #include "hisprof.h"
|
---|
11 | #include "histos2.h"
|
---|
12 |
|
---|
13 | #include "fitsblkrw.h"
|
---|
14 | #include "fitshandler.h"
|
---|
15 |
|
---|
16 |
|
---|
17 | ////////////////////////////////////////////////////////////////
|
---|
18 | ///////////////////////// Histo , HProf ////////////////////////
|
---|
19 | ////////////////////////////////////////////////////////////////
|
---|
20 |
|
---|
21 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
22 | int FitsHandler<Histo>::CheckReadability(FitsInOutFile& is)
|
---|
23 | {
|
---|
24 | if (is.CurrentHDUType() == IMAGE_HDU ) return 0;
|
---|
25 | string key = "SOPCLSNM";
|
---|
26 | string clsnm = is.KeyValue(key);
|
---|
27 | if ( (clsnm == "SOPHYA::Histo")
|
---|
28 | || (clsnm == "SOPHYA::HProf") ) return 2;
|
---|
29 | return 0;
|
---|
30 | }
|
---|
31 |
|
---|
32 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
33 | int FitsHandler<Histo>::CheckHandling(AnyDataObj & o)
|
---|
34 | {
|
---|
35 | if (typeid(o) == typeid(Histo)) return 2;
|
---|
36 | Histo * po = dynamic_cast< Histo * >(& o);
|
---|
37 | if (po != NULL) return 2;
|
---|
38 | return 0;
|
---|
39 | }
|
---|
40 |
|
---|
41 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
42 | void FitsHandler<Histo>::Write(FitsInOutFile& os)
|
---|
43 | {
|
---|
44 | if(dobj==NULL)
|
---|
45 | throw NullPtrError("FitsHandler<Histo>::Write() NULL dobj pointer ");
|
---|
46 |
|
---|
47 | //--- Le type d'objet et son pointeur
|
---|
48 | Histo* h = dynamic_cast< Histo *> (dobj);
|
---|
49 | HProf* hp = dynamic_cast< HProf *> (dobj);
|
---|
50 |
|
---|
51 | //--- Les noms de colonnes
|
---|
52 | int tbltyp = os.GetDef_TableType();
|
---|
53 | vector<string> colnames, tform, tunit;
|
---|
54 | // les valeurs du bin
|
---|
55 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D");
|
---|
56 | colnames.push_back("val");
|
---|
57 | tunit.push_back("");
|
---|
58 | // Les erreurs
|
---|
59 | if(h->mErr2) {
|
---|
60 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D");
|
---|
61 | colnames.push_back("e2");
|
---|
62 | tunit.push_back("");
|
---|
63 | }
|
---|
64 | // Le nombre d'entrees dans le bin
|
---|
65 | if(hp!=NULL) {
|
---|
66 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D");
|
---|
67 | colnames.push_back("nb");
|
---|
68 | tunit.push_back("");
|
---|
69 | }
|
---|
70 |
|
---|
71 | //--- On cree la table
|
---|
72 | string extname = os.NextExtensionName();
|
---|
73 | os.CreateTable(os.GetDef_TableType(),extname,colnames,tform, tunit);
|
---|
74 |
|
---|
75 | // Ecriture des donnees des colonnes
|
---|
76 | int n = h->NBins();
|
---|
77 | if(n>0) {
|
---|
78 | if(hp) hp->UpdateHisto();
|
---|
79 | FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,h->mData,n);
|
---|
80 | if(h->mErr2) FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,h->mErr2,n);
|
---|
81 | if(hp!=NULL) FitsBlockRW<r_8>::WriteColumnData(os,3,1,1,hp->mSumW,n);
|
---|
82 | }
|
---|
83 |
|
---|
84 | // Ecriture des clefs fits
|
---|
85 | MuTyV mtv;
|
---|
86 |
|
---|
87 | mtv = "SOPHYA::Histo";
|
---|
88 | if(hp) mtv = "SOPHYA::HProf";
|
---|
89 | os.WriteKey("SOPCLSNM",mtv," SOPHYA class name");
|
---|
90 |
|
---|
91 | mtv = "Histo";
|
---|
92 | if(hp) mtv = "HProf";
|
---|
93 | os.WriteKey("CONTENT",mtv," name of SOPHYA object");
|
---|
94 |
|
---|
95 | mtv = h->mBins;
|
---|
96 | os.WriteKey("NBIN",mtv," number of bins");
|
---|
97 |
|
---|
98 | mtv = h->mMin;
|
---|
99 | os.WriteKey("XMIN",mtv," absc of beginning of 1srt bin");
|
---|
100 |
|
---|
101 | mtv = h->mMax;
|
---|
102 | os.WriteKey("XMAX",mtv," absc of end of last bin");
|
---|
103 |
|
---|
104 | mtv = h->binWidth;
|
---|
105 | os.WriteKey("WBIN",mtv," bin width");
|
---|
106 |
|
---|
107 | mtv = h->mUnder;
|
---|
108 | os.WriteKey("UNDER",mtv," number of bins");
|
---|
109 |
|
---|
110 | mtv = h->mOver;
|
---|
111 | os.WriteKey("OVER",mtv," underflow");
|
---|
112 |
|
---|
113 | mtv = h->nHist;
|
---|
114 | os.WriteKey("NHIST",mtv," entries weighted somme");
|
---|
115 |
|
---|
116 | double x = h->nEntries; mtv = x;
|
---|
117 | os.WriteKey("NENTRIES",mtv," number of entries");
|
---|
118 |
|
---|
119 | int_4 haserr =(h->mErr2) ? 1: 0;
|
---|
120 | mtv = haserr;
|
---|
121 | os.WriteKey("HASERR2",mtv," square errors associated");
|
---|
122 |
|
---|
123 | if(hp) {
|
---|
124 | int_4 ok = (hp->mOk)? 1: 0;
|
---|
125 | mtv = ok;
|
---|
126 | os.WriteKey("UPDOK",mtv," update status flag");
|
---|
127 |
|
---|
128 | mtv = (int_4)hp->mOpt;
|
---|
129 | os.WriteKey("SIGOPT",mtv," sigma statistic flag");
|
---|
130 |
|
---|
131 | mtv = hp->mYMin;
|
---|
132 | os.WriteKey("YMIN",mtv," sum low limit");
|
---|
133 |
|
---|
134 | mtv = hp->mYMax;
|
---|
135 | os.WriteKey("YMAX",mtv," sum high limit");
|
---|
136 | }
|
---|
137 |
|
---|
138 | return;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
143 | void FitsHandler<Histo>::Read(FitsInOutFile& is)
|
---|
144 | {
|
---|
145 | int hdutyp = is.CurrentHDUType();
|
---|
146 | if( (hdutyp != BINARY_TBL ) && (hdutyp != ASCII_TBL) )
|
---|
147 | throw FitsIOException("FitsHandler<Histo>::Read() Not a binary or ascii table HDU");
|
---|
148 |
|
---|
149 | //--- Nb de lignes et de colonnes
|
---|
150 | vector<string> colnames;
|
---|
151 | vector<int> coltypes;
|
---|
152 | vector<LONGLONG> repcnt, width;
|
---|
153 | is.GetColInfo(colnames,coltypes,repcnt,width);
|
---|
154 | long ncol = colnames.size();
|
---|
155 | if(ncol<=0)
|
---|
156 | throw FitsIOException("FitsHandler<Histo>::Read() bad number of table columns");
|
---|
157 | long nbrows = is.GetNbRows();
|
---|
158 | if(nbrows<=0)
|
---|
159 | throw FitsIOException("FitsHandler<Histo>::Read() number of rows is zero, no reading");
|
---|
160 |
|
---|
161 | //--- Lecture entete FITS
|
---|
162 | string key = "SOPCLSNM"; string clsnm = is.KeyValue(key);
|
---|
163 | DVList dvl; is.GetHeaderRecords(dvl,true,false);
|
---|
164 |
|
---|
165 | int_4 nbin = dvl.GetI("NBIN",-1);
|
---|
166 | if(nbin<=0 && nbin!=nbrows)
|
---|
167 | throw FitsIOException("FitsHandler<Histo>::Read() number of bins is zero or bad, no reading");
|
---|
168 |
|
---|
169 | r_8 xmin = dvl.GetD("XMIN",-1.);
|
---|
170 | r_8 xmax = dvl.GetD("XMAX",+1.);
|
---|
171 |
|
---|
172 | //--- Creation de l'objet si necessaire
|
---|
173 | if(dobj == NULL) {
|
---|
174 | if(clsnm == "SOPHYA::Histo") dobj = new Histo;
|
---|
175 | else if(clsnm == "SOPHYA::HProf") dobj = new HProf;
|
---|
176 | }
|
---|
177 |
|
---|
178 | //--- Type de l'histo
|
---|
179 | Histo* h = dynamic_cast< Histo *> (dobj);
|
---|
180 | HProf* hp = dynamic_cast< HProf *> (dobj);
|
---|
181 |
|
---|
182 | //--- Allocation pour histo
|
---|
183 | if(hp&& (clsnm=="SOPHYA::HProf")) {
|
---|
184 | if(ncol<3)
|
---|
185 | throw FitsIOException("FitsHandler<Histo>::Read() wrong number of columns for HProf");
|
---|
186 | r_8 ymin = dvl.GetD("YMIN",1.);
|
---|
187 | r_8 ymax = dvl.GetD("YMAX",-1.);
|
---|
188 | hp->CreateOrResize(xmin,xmax,nbin,ymin,ymax);
|
---|
189 | } else if(h && clsnm == "SOPHYA::Histo" ) {
|
---|
190 | h->CreateOrResize(xmin,xmax,nbin);
|
---|
191 | int_4 haserr2 = dvl.GetI("HASERR2",0);
|
---|
192 | if(ncol>1 && haserr2>0) h->Errors();
|
---|
193 | } else {
|
---|
194 | throw FitsIOException("FitsHandler<Histo>::Read() No assocaition classe/fits_header");
|
---|
195 | }
|
---|
196 |
|
---|
197 | //--- remplissage des variables d'entete
|
---|
198 | h->mUnder = dvl.GetD("UNDER",0.);
|
---|
199 | h->mOver = dvl.GetD("OVER",0.);
|
---|
200 | h->nHist = dvl.GetD("NHIST",0.);
|
---|
201 | double x = dvl.GetD("NENTRIES",0.); h->nEntries = uint_8(x);
|
---|
202 |
|
---|
203 | if(hp) {
|
---|
204 | int_4 ok = dvl.GetI("UPDOK",0); hp->mOk = (ok)? true : false;
|
---|
205 | hp->mOpt = (uint_2)dvl.GetI("SIGOPT",0);
|
---|
206 | hp->mYMin = dvl.GetD("YMIN",1.);
|
---|
207 | hp->mYMax = dvl.GetD("YMAX",-1.);
|
---|
208 | }
|
---|
209 |
|
---|
210 | //--- remplissage de l'histo
|
---|
211 | FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,h->mData,nbin);
|
---|
212 | if(h->mErr2) FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,h->mErr2,nbin);
|
---|
213 | if(hp) FitsBlockRW<r_8>::ReadColumnData(is,3,1,1,hp->mSumW,nbin);
|
---|
214 |
|
---|
215 | return;
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | ///////////////////////////////////////////////////////////////////////////
|
---|
220 | ///////////////////////////////// Histo2D ////////////////////////////////
|
---|
221 | ///////////////////////////////////////////////////////////////////////////
|
---|
222 |
|
---|
223 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
224 | int FitsHandler<Histo2D>::CheckReadability(FitsInOutFile& is)
|
---|
225 | {
|
---|
226 | if (is.CurrentHDUType() == IMAGE_HDU ) return 0;
|
---|
227 | string key = "SOPCLSNM";
|
---|
228 | string clsnm = is.KeyValue(key);
|
---|
229 | if( clsnm == "SOPHYA::Histo2D") return 2;
|
---|
230 | return 0;
|
---|
231 | }
|
---|
232 |
|
---|
233 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
234 | int FitsHandler<Histo2D>::CheckHandling(AnyDataObj & o)
|
---|
235 | {
|
---|
236 | if (typeid(o) == typeid(Histo2D)) return 2;
|
---|
237 | Histo2D * po = dynamic_cast< Histo2D * >(& o);
|
---|
238 | if (po != NULL) return 2;
|
---|
239 | return 0;
|
---|
240 | }
|
---|
241 |
|
---|
242 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
243 | void FitsHandler<Histo2D>::Write(FitsInOutFile& os)
|
---|
244 | {
|
---|
245 | if(dobj==NULL)
|
---|
246 | throw NullPtrError("FitsHandler<Histo2D>::Write() NULL dobj pointer ");
|
---|
247 |
|
---|
248 | //--- Le type d'objet et son pointeur
|
---|
249 | Histo2D* h2 = dynamic_cast< Histo2D *> (dobj);
|
---|
250 |
|
---|
251 | //--- Les noms de colonnes
|
---|
252 | int tbltyp = os.GetDef_TableType();
|
---|
253 | vector<string> colnames, tform, tunit;
|
---|
254 | // les valeurs du bin
|
---|
255 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D");
|
---|
256 | colnames.push_back("val");
|
---|
257 | tunit.push_back("");
|
---|
258 | // Les erreurs
|
---|
259 | if(h2->mErr2) {
|
---|
260 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D");
|
---|
261 | colnames.push_back("e2");
|
---|
262 | tunit.push_back("");
|
---|
263 | }
|
---|
264 |
|
---|
265 | //--- On cree la table
|
---|
266 | string extname = os.NextExtensionName();
|
---|
267 | os.CreateTable(os.GetDef_TableType(),extname,colnames,tform, tunit);
|
---|
268 |
|
---|
269 | // Ecriture des donnees des colonnes
|
---|
270 | long n = h2->mNxy;
|
---|
271 | if(n>0) {
|
---|
272 | FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,h2->mData,n);
|
---|
273 | if(h2->mErr2) FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,h2->mErr2,n);
|
---|
274 | }
|
---|
275 |
|
---|
276 | // Ecriture des clefs fits
|
---|
277 | MuTyV mtv;
|
---|
278 |
|
---|
279 | mtv = "SOPHYA::Histo2D";
|
---|
280 | os.WriteKey("SOPCLSNM",mtv," SOPHYA class name");
|
---|
281 |
|
---|
282 | mtv = "Histo2D";
|
---|
283 | os.WriteKey("CONTENT",mtv," name of SOPHYA object");
|
---|
284 |
|
---|
285 | mtv = h2->mNx;
|
---|
286 | os.WriteKey("NBINX",mtv," number of bins in X");
|
---|
287 | mtv = h2->mNy;
|
---|
288 | os.WriteKey("NBINY",mtv," number of bins in Y");
|
---|
289 | mtv = h2->mNxy;
|
---|
290 | os.WriteKey("NBINXY",mtv," number of elements");
|
---|
291 |
|
---|
292 | mtv = h2->mXmin;
|
---|
293 | os.WriteKey("XMIN",mtv," absc of beginning of 1srt bin in X");
|
---|
294 | mtv = h2->mXmax;
|
---|
295 | os.WriteKey("XMAX",mtv," absc of end of last bin in X");
|
---|
296 | mtv = h2->mYmin;
|
---|
297 | os.WriteKey("YMIN",mtv," absc of beginning of 1srt bin in Y");
|
---|
298 | mtv = h2->mYmax;
|
---|
299 | os.WriteKey("YMAX",mtv," absc of end of last bin in Y");
|
---|
300 |
|
---|
301 | mtv = h2->mWBinx;
|
---|
302 | os.WriteKey("WBINX",mtv," bin width in X");
|
---|
303 | mtv = h2->mWBiny;
|
---|
304 | os.WriteKey("WBINY",mtv," bin width in Y");
|
---|
305 |
|
---|
306 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) {
|
---|
307 | char str[16]; sprintf(str,"OUT%1d%1d",i,j);
|
---|
308 | mtv = h2->mOver[i][j];
|
---|
309 | os.WriteKey(str,mtv," under/over X/Y");
|
---|
310 | }
|
---|
311 |
|
---|
312 | mtv = h2->nHist;
|
---|
313 | os.WriteKey("NHIST",mtv," entries weighted somme");
|
---|
314 |
|
---|
315 | mtv = h2->nEntries;
|
---|
316 | os.WriteKey("NENTRIES",mtv," number of entries");
|
---|
317 |
|
---|
318 | int_4 haserr =(h2->mErr2) ? 1: 0;
|
---|
319 | mtv = haserr;
|
---|
320 | os.WriteKey("HASERR2",mtv," square errors associated");
|
---|
321 |
|
---|
322 |
|
---|
323 |
|
---|
324 | //-------------------------------------------------------------
|
---|
325 | //------ Gestion des Histo1D de projx/y bandx/t slicex/y ------
|
---|
326 | //-------------------------------------------------------------
|
---|
327 |
|
---|
328 | int_4 nrel = 0;
|
---|
329 | if(h2->HProjX()) {nrel++; mtv=nrel; os.WriteKey("PROJX",mtv," relative HDU with HProjX");}
|
---|
330 | if(h2->HProjY()) {nrel++; mtv=nrel; os.WriteKey("PROJY",mtv," relative HDU with HProjY");}
|
---|
331 | if(h2->NSliX()>0) {
|
---|
332 | mtv=h2->NSliX(); os.WriteKey("NSLICEX",mtv," number of SliX");
|
---|
333 | nrel++;
|
---|
334 | mtv=nrel; os.WriteKey("SLICEX",mtv," relative HDU with first SliX");
|
---|
335 | nrel += h2->NSliX()-1;
|
---|
336 | }
|
---|
337 | if(h2->NSliY()>0) {
|
---|
338 | mtv=h2->NSliY(); os.WriteKey("NSLICEY",mtv," number of SliY");
|
---|
339 | nrel++;
|
---|
340 | mtv=nrel; os.WriteKey("SLICEY",mtv," relative HDU with first SliY");
|
---|
341 | nrel += h2->NSliY()-1;
|
---|
342 | }
|
---|
343 | if(h2->NBandX()>0) {
|
---|
344 | mtv=h2->NBandX(); os.WriteKey("NBANDEX",mtv," number of BandX");
|
---|
345 | nrel++;
|
---|
346 | mtv=nrel; os.WriteKey("BANDEX",mtv," relative HDU with first BandX");
|
---|
347 | nrel += h2->NBandX()-1;
|
---|
348 | for(int i=0;i<h2->NBandX();i++) {
|
---|
349 | char str[32]; r_8 vmin,vmax;
|
---|
350 | h2->GetBandX(i,vmin,vmax);
|
---|
351 | sprintf(str,"BXL%d",i);
|
---|
352 | mtv = vmin; os.WriteKey(str,mtv," low Y limit for BandX");
|
---|
353 | sprintf(str,"BXH%d",i);
|
---|
354 | mtv = vmax; os.WriteKey(str,mtv," high Y limit for BandX");
|
---|
355 | }
|
---|
356 | }
|
---|
357 | if(h2->NBandY()>0) {
|
---|
358 | mtv=h2->NBandY(); os.WriteKey("NBANDEY",mtv," number of BandY");
|
---|
359 | nrel++;
|
---|
360 | mtv=nrel; os.WriteKey("BANDEY",mtv," relative HDU with first BandY");
|
---|
361 | nrel += h2->NBandY()-1;
|
---|
362 | for(int i=0;i<h2->NBandY();i++) {
|
---|
363 | char str[32]; r_8 vmin,vmax;
|
---|
364 | h2->GetBandY(i,vmin,vmax);
|
---|
365 | sprintf(str,"BYL%d",i);
|
---|
366 | mtv = vmin; os.WriteKey(str,mtv," low X limit for BandY");
|
---|
367 | sprintf(str,"BYH%d",i);
|
---|
368 | mtv = vmax; os.WriteKey(str,mtv," high X limit for BandY");
|
---|
369 | }
|
---|
370 | }
|
---|
371 | mtv=nrel; os.WriteKey("NH1ASS",mtv," number of associated Histo1D");
|
---|
372 |
|
---|
373 | if(h2->HProjX()) {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HProjX()))); fio.Write(os);}
|
---|
374 | if(h2->HProjY()) {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HProjY()))); fio.Write(os);}
|
---|
375 | if(h2->NSliX()>0) for(int i=0;i<h2->NSliX();i++)
|
---|
376 | {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HSliX(i)))); fio.Write(os);}
|
---|
377 | if(h2->NSliY()>0) for(int i=0;i<h2->NSliY();i++)
|
---|
378 | {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HSliY(i)))); fio.Write(os);}
|
---|
379 | if(h2->NBandX()>0) for(int i=0;i<h2->NBandX();i++)
|
---|
380 | {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HBandX(i)))); fio.Write(os);}
|
---|
381 | if(h2->NBandY()>0) for(int i=0;i<h2->NBandY();i++)
|
---|
382 | {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HBandY(i)))); fio.Write(os);}
|
---|
383 |
|
---|
384 | return;
|
---|
385 | }
|
---|
386 |
|
---|
387 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
388 | void FitsHandler<Histo2D>::Read(FitsInOutFile& is)
|
---|
389 | {
|
---|
390 | int hdutyp = is.CurrentHDUType();
|
---|
391 | if( (hdutyp != BINARY_TBL ) && (hdutyp != ASCII_TBL) )
|
---|
392 | throw FitsIOException("FitsHandler<Histo2D>::Read() Not a binary or ascii table HDU");
|
---|
393 |
|
---|
394 | //--- Nb de lignes et de colonnes
|
---|
395 | vector<string> colnames; vector<int> coltypes; vector<LONGLONG> repcnt, width;
|
---|
396 | is.GetColInfo(colnames,coltypes,repcnt,width);
|
---|
397 | long ncol = colnames.size();
|
---|
398 | if(ncol<=0)
|
---|
399 | throw FitsIOException("FitsHandler<Histo2D>::Read() bad number of table columns");
|
---|
400 | long nbrows = is.GetNbRows();
|
---|
401 | if(nbrows<=0)
|
---|
402 | throw FitsIOException("FitsHandler<Histo2D>::Read() number of rows is zero, no reading");
|
---|
403 |
|
---|
404 | //--- Lecture entete FITS
|
---|
405 | DVList dvl; is.GetHeaderRecords(dvl,true,false);
|
---|
406 |
|
---|
407 | int_4 nbinx = dvl.GetI("NBINX",-1);
|
---|
408 | int_4 nbiny = dvl.GetI("NBINY",-1);
|
---|
409 | int_8 nbinxy = nbinx*nbiny;
|
---|
410 | if(nbinx<=0 || nbiny<=0 || nbinxy!=nbrows)
|
---|
411 | throw FitsIOException("FitsHandler<Histo2D>::Read() number of bins is zero or bad, no reading");
|
---|
412 |
|
---|
413 | r_8 xmin = dvl.GetD("XMIN",-1.);
|
---|
414 | r_8 xmax = dvl.GetD("XMAX",1.);
|
---|
415 | r_8 ymin = dvl.GetD("YMIN",-1.);
|
---|
416 | r_8 ymax = dvl.GetD("YMAX",1.);
|
---|
417 |
|
---|
418 | //--- Creation de l'objet
|
---|
419 | if(dobj == NULL) dobj = new Histo2D;
|
---|
420 | dobj->CreateOrResize(xmin,xmax,nbinx,ymin,ymax,nbiny);
|
---|
421 | int_4 haserr2 = dvl.GetI("HASERR2",0);
|
---|
422 | if(ncol>1 && haserr2>0) dobj->Errors();
|
---|
423 |
|
---|
424 | //--- remplissage des variables d'entete
|
---|
425 | dobj->nHist = dvl.GetD("NHIST",0.);
|
---|
426 | dobj->nEntries = dvl.GetI("NENTRIES",0);
|
---|
427 |
|
---|
428 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) {
|
---|
429 | char str[16]; sprintf(str,"OUT%1d%1d",i,j);
|
---|
430 | dobj->mOver[i][j] = dvl.GetD(str,0.);
|
---|
431 | }
|
---|
432 |
|
---|
433 | //--- remplissage de l'histo
|
---|
434 | FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,dobj->mData,nbinxy);
|
---|
435 | if(dobj->mErr2) FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,dobj->mErr2,nbinxy);
|
---|
436 |
|
---|
437 |
|
---|
438 |
|
---|
439 | //-------------------------------------------------------------
|
---|
440 | //------ Gestion des Histo1D de projx/y bandx/t slicex/y ------
|
---|
441 | //-------------------------------------------------------------
|
---|
442 |
|
---|
443 | int_4 nh1ass = dvl.GetI("NH1ASS",-1);
|
---|
444 | if(nh1ass<=0) return;
|
---|
445 | int hducur = is.CurrentHDU();
|
---|
446 |
|
---|
447 | try { // ProjX
|
---|
448 | int_4 ipr = dvl.GetI("PROJX",-1);
|
---|
449 | is.MoveAbsToHDU(hducur+ipr);
|
---|
450 | dobj->SetProjX();
|
---|
451 | Histo *h = dobj->HProjX();
|
---|
452 | FitsHandler<Histo> fio(*h); fio.Read(is);
|
---|
453 | if(h->NBins()!=dobj->NBinX())
|
---|
454 | throw FitsIOException("unmatched bin number");
|
---|
455 | } catch (...) {
|
---|
456 | dobj->DelProjX();
|
---|
457 | cout<<"FitsHandler<Histo2D>::Read: Error reading PROJX"<<endl;
|
---|
458 | }
|
---|
459 |
|
---|
460 | try { // ProjY
|
---|
461 | int_4 ipr = dvl.GetI("PROJY",-1);
|
---|
462 | is.MoveAbsToHDU(hducur+ipr);
|
---|
463 | dobj->SetProjY();
|
---|
464 | Histo *h = dobj->HProjY();
|
---|
465 | FitsHandler<Histo> fio(*h); fio.Read(is);
|
---|
466 | if(h->NBins()!=dobj->NBinY())
|
---|
467 | throw FitsIOException("unmatched bin number");
|
---|
468 | } catch (...) {
|
---|
469 | dobj->DelProjY();
|
---|
470 | cout<<"FitsHandler<Histo2D>::Read: Error reading PROJY"<<endl;
|
---|
471 | }
|
---|
472 |
|
---|
473 | try { // SliX
|
---|
474 | int_4 nb = dvl.GetI("NSLICEX",-1);
|
---|
475 | int_4 ipr = dvl.GetI("SLICEX",-1);
|
---|
476 | dobj->SetSliX(nb);
|
---|
477 | for(int i=0;i<nb;i++) {
|
---|
478 | is.MoveAbsToHDU(hducur+ipr+i);
|
---|
479 | Histo *h = dobj->HSliX(i);
|
---|
480 | FitsHandler<Histo> fio(*h); fio.Read(is);
|
---|
481 | if(h->NBins()!=dobj->NBinX())
|
---|
482 | throw FitsIOException("unmatched bin number");
|
---|
483 | }
|
---|
484 | } catch (...) {
|
---|
485 | dobj->DelSliX();
|
---|
486 | cout<<"FitsHandler<Histo2D>::Read: Error reading SLICEX"<<endl;
|
---|
487 | }
|
---|
488 |
|
---|
489 | try { // SliY
|
---|
490 | int_4 nb = dvl.GetI("NSLICEY",-1);
|
---|
491 | int_4 ipr = dvl.GetI("SLICEY",-1);
|
---|
492 | dobj->SetSliY(nb);
|
---|
493 | for(int i=0;i<nb;i++) {
|
---|
494 | is.MoveAbsToHDU(hducur+ipr+i);
|
---|
495 | Histo *h = dobj->HSliY(i);
|
---|
496 | FitsHandler<Histo> fio(*h); fio.Read(is);
|
---|
497 | if(h->NBins()!=dobj->NBinY())
|
---|
498 | throw FitsIOException("unmatched bin number");
|
---|
499 | }
|
---|
500 | } catch (...) {
|
---|
501 | dobj->DelSliY();
|
---|
502 | cout<<"FitsHandler<Histo2D>::Read: Error reading SLICEY"<<endl;
|
---|
503 | }
|
---|
504 |
|
---|
505 | try { // BandeX
|
---|
506 | int_4 nb = dvl.GetI("NBANDEX",-1);
|
---|
507 | int_4 ipr = dvl.GetI("BANDEX",-1);
|
---|
508 | for(int i=0;i<nb;i++) {
|
---|
509 | char str[32];
|
---|
510 | sprintf(str,"BXL%d",i); r_8 vmin = dvl.GetD(str,0.);
|
---|
511 | sprintf(str,"BXH%d",i); r_8 vmax = dvl.GetD(str,0.);
|
---|
512 | dobj->SetBandX(vmin,vmax);
|
---|
513 | is.MoveAbsToHDU(hducur+ipr+i);
|
---|
514 | Histo *h = dobj->HBandX(i);
|
---|
515 | FitsHandler<Histo> fio(*h); fio.Read(is);
|
---|
516 | if(h->NBins()!=dobj->NBinX())
|
---|
517 | throw FitsIOException("unmatched bin number");
|
---|
518 | }
|
---|
519 | } catch (...) {
|
---|
520 | dobj->DelBandX();
|
---|
521 | cout<<"FitsHandler<Histo2D>::Read: Error reading BANDEX"<<endl;
|
---|
522 | }
|
---|
523 |
|
---|
524 | try { // BandeY
|
---|
525 | int_4 nb = dvl.GetI("NBANDEY",-1);
|
---|
526 | int_4 ipr = dvl.GetI("BANDEY",-1);
|
---|
527 | for(int i=0;i<nb;i++) {
|
---|
528 | char str[32];
|
---|
529 | sprintf(str,"BYL%d",i); r_8 vmin = dvl.GetD(str,0.);
|
---|
530 | sprintf(str,"BYH%d",i); r_8 vmax = dvl.GetD(str,0.);
|
---|
531 | dobj->SetBandY(vmin,vmax);
|
---|
532 | is.MoveAbsToHDU(hducur+ipr+i);
|
---|
533 | Histo *h = dobj->HBandY(i);
|
---|
534 | FitsHandler<Histo> fio(*h); fio.Read(is);
|
---|
535 | if(h->NBins()!=dobj->NBinY())
|
---|
536 | throw FitsIOException("unmatched bin number");
|
---|
537 | }
|
---|
538 | } catch (...) {
|
---|
539 | dobj->DelBandY();
|
---|
540 | cout<<"FitsHandler<Histo2D>::Read: Error reading BANDEY"<<endl;
|
---|
541 | }
|
---|
542 |
|
---|
543 | return;
|
---|
544 | }
|
---|