1 | #include "sopnamsp.h"
|
---|
2 | #include "machdefs.h"
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include "fitsfile.h"
|
---|
5 | #include "pexceptions.h"
|
---|
6 | #include "strutil.h"
|
---|
7 | #include "anydataobj.h"
|
---|
8 | #include "fitsspherehealpix.h"
|
---|
9 |
|
---|
10 | /*!
|
---|
11 | \defgroup FitsIOServer FitsIOServer module
|
---|
12 | This module contains classes which handle FITS format I/O for
|
---|
13 | SOPHYA objects. This module uses cfitsio library.
|
---|
14 | */
|
---|
15 |
|
---|
16 | void BnTblLine::setFormat(int dc, int fc, int ic, int lc, int bc,int cc, vector<string> names)
|
---|
17 | {
|
---|
18 | int nbcols = dc + fc + ic + cc + lc + bc;
|
---|
19 | int maxName = names.size();
|
---|
20 | if (nbcols != maxName)
|
---|
21 | {
|
---|
22 | cout << " WARNING: BnTblLine:: length of vector of column names not equal to total number of columns" << endl;
|
---|
23 | maxName = nbcols < maxName ? nbcols : maxName;
|
---|
24 | }
|
---|
25 | ColName_ = vector<string>(nbcols);
|
---|
26 | int k;
|
---|
27 | for (k=0; k < maxName; k++) ColName_[k] = names[k];
|
---|
28 | if (dc >0) ddata_ = vector<double>(dc);
|
---|
29 | if (fc >0) fdata_ = vector<float>(fc);
|
---|
30 | if (ic >0) idata_ = vector<int>(ic);
|
---|
31 | if (lc >0) ldata_ = vector<long>(lc);
|
---|
32 | if (bc >0) bdata_ = vector<unsigned char>(bc);
|
---|
33 | if (cc >0) cdata_ = vector<string>(cc);
|
---|
34 | }
|
---|
35 |
|
---|
36 | bool BnTblLine::sameFormat(const BnTblLine& btl) const
|
---|
37 | {
|
---|
38 | if (btl.ddata_.size() == ddata_.size() && btl.fdata_.size() == fdata_.size() && btl.idata_.size() == idata_.size() && btl.cdata_.size() == cdata_.size() && btl.ldata_.size() == ldata_.size() && btl.bdata_.size() == bdata_.size()) return true;
|
---|
39 | else return false;
|
---|
40 | }
|
---|
41 |
|
---|
42 | void BnTblLine::Print()
|
---|
43 | {
|
---|
44 | int k;
|
---|
45 | cout << " ********* ligne ************* " << endl;
|
---|
46 | cout << " *** noms de variables " << endl;
|
---|
47 | for (k=0; k < ColName_.size(); k++) cout << ColName_[k] << " ";
|
---|
48 | cout << endl;
|
---|
49 | cout << " *** variables doubles " << endl;
|
---|
50 | for (k=0; k < ddata_.size(); k++) cout << ddata_[k] << " ";
|
---|
51 | cout << endl;
|
---|
52 | cout << " *** variables float " << endl;
|
---|
53 | for (k=0; k < fdata_.size(); k++) cout << fdata_[k] << " ";
|
---|
54 | cout << endl;
|
---|
55 | cout << " *** variables int " << endl;
|
---|
56 | for (k=0; k < idata_.size(); k++) cout << idata_[k] << " ";
|
---|
57 | cout << endl;
|
---|
58 | cout << " *** variables string " << endl;
|
---|
59 | for (k=0; k < cdata_.size(); k++) cout << cdata_[k] << " ";
|
---|
60 | cout << endl;
|
---|
61 | cout << " *** variables long " << endl;
|
---|
62 | for (k=0; k < ldata_.size(); k++) cout << ldata_[k] << " ";
|
---|
63 | cout << endl;
|
---|
64 | cout << " *** variables byte " << endl;
|
---|
65 | for (k=0; k < bdata_.size(); k++) cout << (int)bdata_[k] << " ";
|
---|
66 | cout << endl;
|
---|
67 | cout << " ***************************** " << endl;
|
---|
68 | }
|
---|
69 |
|
---|
70 | FitsFile::BufferLine::BufferLine(const vector<FitsFile::FitsDataType>& types)
|
---|
71 | {
|
---|
72 |
|
---|
73 |
|
---|
74 | int dc=0;
|
---|
75 | int fc=0;
|
---|
76 | int shc=0;
|
---|
77 | int ic=0;
|
---|
78 | int lc=0;
|
---|
79 | int cc=0;
|
---|
80 | int bc=0;
|
---|
81 | id_ = vector< pair<FitsFile::FitsDataType, int> >(types.size());
|
---|
82 | int k;
|
---|
83 | for (k= 0; k < types.size(); k++)
|
---|
84 | {
|
---|
85 | switch( types[k] )
|
---|
86 | {
|
---|
87 | case FitsFile::FitsDataType_double :
|
---|
88 | {
|
---|
89 | id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_double, dc);
|
---|
90 | dc++;
|
---|
91 | break;
|
---|
92 | }
|
---|
93 | case FitsFile::FitsDataType_float :
|
---|
94 | {
|
---|
95 | id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_float, fc);
|
---|
96 | fc++;
|
---|
97 | break;
|
---|
98 | }
|
---|
99 | case FitsFile::FitsDataType_short :
|
---|
100 | {
|
---|
101 | id_[k] = pair<FitsFile::FitsDataType, int>(FitsDataType_short, shc);
|
---|
102 | shc++;
|
---|
103 | break;
|
---|
104 | }
|
---|
105 | case FitsFile::FitsDataType_int :
|
---|
106 | {
|
---|
107 | id_[k] = pair<FitsFile::FitsDataType, int>(FitsDataType_int, ic);
|
---|
108 | ic++;
|
---|
109 | break;
|
---|
110 | }
|
---|
111 | case FitsFile::FitsDataType_long :
|
---|
112 | {
|
---|
113 | id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_long, lc);
|
---|
114 | lc++;
|
---|
115 | break;
|
---|
116 | }
|
---|
117 | case FitsFile::FitsDataType_byte :
|
---|
118 | {
|
---|
119 | id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_byte, bc);
|
---|
120 | bc++;
|
---|
121 | break;
|
---|
122 | }
|
---|
123 | case FitsDataType_char :
|
---|
124 | {
|
---|
125 | id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_char, cc);
|
---|
126 | cc++;
|
---|
127 | break;
|
---|
128 | }
|
---|
129 | default:
|
---|
130 | {
|
---|
131 | throw PException(" FitsFile::getHeaderWithSophyaObject() : unsupported FITS data type");
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | if (dc >0) ddata_ = vector<r_8>(dc);
|
---|
137 | if (fc >0) fdata_ = vector<r_4>(fc);
|
---|
138 | if (shc >0) shdata_ = vector<int_2>(shc);
|
---|
139 | if (ic >0) idata_ = vector<int_4>(ic);
|
---|
140 | if (lc >0) ldata_ = vector<int_8>(lc);
|
---|
141 | if (cc >0) cdata_ = vector<string>(cc);
|
---|
142 | if (bc >0) bdata_ = vector<unsigned char>(bc);
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | void FitsFile::BufferLine::Print() const
|
---|
147 | {
|
---|
148 | cout << " impression de la ligne: " << endl;
|
---|
149 |
|
---|
150 | cout << " doubles : " << endl;
|
---|
151 | int k;
|
---|
152 | for (k=0; k< ddata_.size(); k++)
|
---|
153 | {
|
---|
154 | cout << ddata_[k] << " " ;
|
---|
155 | }
|
---|
156 | cout << endl;
|
---|
157 |
|
---|
158 | cout << " floats : " << endl;
|
---|
159 | for (k=0; k< fdata_.size(); k++)
|
---|
160 | {
|
---|
161 | cout << fdata_[k] << " " ;
|
---|
162 | }
|
---|
163 | cout << endl;
|
---|
164 |
|
---|
165 | cout << " entiers courts: " << endl;
|
---|
166 | for (k=0; k< shdata_.size(); k++)
|
---|
167 | {
|
---|
168 | cout << shdata_[k] << " " ;
|
---|
169 | }
|
---|
170 | cout << endl;
|
---|
171 | cout << " entiers : " << endl;
|
---|
172 | for (k=0; k< idata_.size(); k++)
|
---|
173 | {
|
---|
174 | cout << idata_[k] << " " ;
|
---|
175 | }
|
---|
176 | cout << endl;
|
---|
177 |
|
---|
178 | cout << " entiers longs : " << endl;
|
---|
179 | for (k=0; k< ldata_.size(); k++)
|
---|
180 | {
|
---|
181 | cout << ldata_[k] << " " ;
|
---|
182 | }
|
---|
183 | cout << endl;
|
---|
184 |
|
---|
185 | cout << " chaines carac. : " << endl;
|
---|
186 | for (k=0; k< cdata_.size(); k++)
|
---|
187 | {
|
---|
188 | cout << cdata_[k] << " " ;
|
---|
189 | }
|
---|
190 | cout << endl;
|
---|
191 |
|
---|
192 | cout << " bytes : " << endl;
|
---|
193 | for (k=0; k< bdata_.size(); k++)
|
---|
194 | {
|
---|
195 | cout << (char)bdata_[k] << " " ;
|
---|
196 | }
|
---|
197 | cout << endl;
|
---|
198 |
|
---|
199 |
|
---|
200 | }
|
---|
201 |
|
---|
202 | /*!
|
---|
203 | \class SOPHYA::FitsIOHandler
|
---|
204 | \ingroup FitsIOServer
|
---|
205 | The class structure is analogous to Sophya-PPersist system :
|
---|
206 | Each SOPHYA object XXX is associated with a object of class FITS_XXX
|
---|
207 | (inheriting from FitsFileHandler), to which input/output operations with FITS
|
---|
208 | files are delegated (through a class Hierarchy : FitsFile (virtual),
|
---|
209 | FitsInFile, FitsOutFile) . A typical example of use is the following :
|
---|
210 |
|
---|
211 | \verbatim
|
---|
212 | int m=... ;
|
---|
213 | SphereHEALPix<r_8> sphere1(m); // definition of the SOPHYA object
|
---|
214 | .... fill the sphere ....
|
---|
215 |
|
---|
216 | FITS_SphereHEALPix<r_8> fits_sph1(sphere1);
|
---|
217 | // delegated object
|
---|
218 | fits_sph.Write("myfile.fits"); // writing on FITS file
|
---|
219 |
|
---|
220 | FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits");
|
---|
221 | // load a delegated object
|
---|
222 | // from FITS file
|
---|
223 | SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2;
|
---|
224 | // casting the delegated object
|
---|
225 | // into a SOPHYA object
|
---|
226 | \endverbatim
|
---|
227 |
|
---|
228 |
|
---|
229 | */
|
---|
230 |
|
---|
231 | /*! \fn void SOPHYA::FitsIOHandler::Read(char flnm[],int hdunum)
|
---|
232 |
|
---|
233 | this method is called from inherited objects :
|
---|
234 |
|
---|
235 | opens a file 'flnm'
|
---|
236 |
|
---|
237 | gets parameters in extension-header (hdunum)
|
---|
238 |
|
---|
239 | calls the method 'ReadFromFits' from the inherited object
|
---|
240 | */
|
---|
241 | void FitsIOHandler::Read(char flnm[],int hdunum)
|
---|
242 | {
|
---|
243 | FitsInFile ifts(flnm);
|
---|
244 | Read(ifts, hdunum);
|
---|
245 | }
|
---|
246 |
|
---|
247 | /*! \fn void SOPHYA::FitsIOHandler::Read(FitsInFile& is, int hdunum)
|
---|
248 | Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. If hdunum is not addressed, , one reads the next extension, with respect to the current position.
|
---|
249 | */
|
---|
250 | void FitsIOHandler::Read(FitsInFile& is, int hdunum)
|
---|
251 | {
|
---|
252 | is.ReadHeader(hdunum);
|
---|
253 | ReadFromFits(is);
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | /*! \fn void SOPHYA::FitsIOHandler::Write(char flnm[])
|
---|
258 | this method is called from inherited objects.
|
---|
259 |
|
---|
260 | for writing a new object in a new fits-extension :
|
---|
261 |
|
---|
262 | \warning By convention, primary header may contain fits-image data.
|
---|
263 | For switching off this convention (i.e. to make sure that all data will be on fits-extensions) use the method :
|
---|
264 |
|
---|
265 | firstImageOnPrimaryHeader() (see below)
|
---|
266 |
|
---|
267 | calls the method 'WriteToFits' from the inherited object
|
---|
268 |
|
---|
269 | */
|
---|
270 | void FitsIOHandler::Write(char flnm[])
|
---|
271 |
|
---|
272 | {
|
---|
273 | FitsOutFile of(flnm, FitsFile::unknown);
|
---|
274 | Write(of);
|
---|
275 | }
|
---|
276 |
|
---|
277 | void FitsIOHandler::Write(FitsOutFile& os)
|
---|
278 | {
|
---|
279 | WriteToFits(os);
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 |
|
---|
284 |
|
---|
285 | FitsFile::~FitsFile()
|
---|
286 | {
|
---|
287 | int status = 0;
|
---|
288 | if( fptr_ != NULL)
|
---|
289 | {
|
---|
290 | fits_close_file(fptr_,&status);
|
---|
291 | // je ne fais pas delete fptr_, c'est la lib. fitsio qui a fait
|
---|
292 | // new...
|
---|
293 | }
|
---|
294 | if( status ) printerror( status );
|
---|
295 | }
|
---|
296 |
|
---|
297 |
|
---|
298 | void FitsFile::printerror(int &status)
|
---|
299 | //*****************************************************/
|
---|
300 | //* Print out cfitsio error messages and exit program */
|
---|
301 | //*****************************************************/
|
---|
302 | {
|
---|
303 | if( status )
|
---|
304 | {
|
---|
305 | fits_report_error(stderr,status);
|
---|
306 | throw IOExc("FitsFile:: error FITSIO status");
|
---|
307 | }
|
---|
308 | return;
|
---|
309 | }
|
---|
310 |
|
---|
311 | void FitsFile::printerror(int& status, char* texte)
|
---|
312 | //*****************************************************/
|
---|
313 | //* Print out cfitsio error messages and exit program */
|
---|
314 | //*****************************************************/
|
---|
315 | {
|
---|
316 | // print out cfitsio error messages and exit program
|
---|
317 | // print error report
|
---|
318 | fits_report_error(stderr, status);
|
---|
319 | cout << " erreur:: " << texte << endl;
|
---|
320 | throw IOExc("FitsFile:: error FITSIO status");
|
---|
321 | }
|
---|
322 | void FitsFile::printerrorAndContinue(int& status, char* texte)
|
---|
323 | //*****************************************************/
|
---|
324 | //* Print out cfitsio error messages and exit program */
|
---|
325 | //*****************************************************/
|
---|
326 | {
|
---|
327 | // print out cfitsio error messages and exit program
|
---|
328 | // print error report
|
---|
329 | fits_report_error(stderr, status);
|
---|
330 | cout << " erreur:: " << texte << endl;
|
---|
331 | // throw IOExc("FitsFile:: error FITSIO status");
|
---|
332 | }
|
---|
333 |
|
---|
334 | void FitsFile::ResetStatus(int& status)
|
---|
335 | {
|
---|
336 | fits_status_ = status;
|
---|
337 | status = 0;
|
---|
338 | fits_clear_errmsg();
|
---|
339 | }
|
---|
340 |
|
---|
341 | string FitsFile::GetErrStatus(int status)
|
---|
342 | {
|
---|
343 | char text[31];
|
---|
344 | fits_get_errstatus(status, text);
|
---|
345 | return string(text);
|
---|
346 | }
|
---|
347 |
|
---|
348 | /*!
|
---|
349 | \class SOPHYA::FitsInFile
|
---|
350 | \ingroup FitsIOServer
|
---|
351 | class for reading SOPHYA objects from FITS Format Files (uses cfitsio lib)
|
---|
352 | */
|
---|
353 |
|
---|
354 | FitsInFile::FitsInFile()
|
---|
355 | {
|
---|
356 | InitNull();
|
---|
357 | }
|
---|
358 |
|
---|
359 | FitsInFile::FitsInFile(string const & flnm)
|
---|
360 | {
|
---|
361 | InitNull();
|
---|
362 | int status = 0;
|
---|
363 | fits_open_file(&fptr_,flnm.c_str(),READONLY,&status);
|
---|
364 | if( status ) printerror( status );
|
---|
365 | }
|
---|
366 |
|
---|
367 | FitsInFile::FitsInFile(const char * flnm)
|
---|
368 | {
|
---|
369 | InitNull();
|
---|
370 | int status = 0;
|
---|
371 | fits_open_file(&fptr_,flnm,READONLY,&status);
|
---|
372 | if( status ) printerror( status );
|
---|
373 | }
|
---|
374 |
|
---|
375 |
|
---|
376 | void FitsInFile::InitNull()
|
---|
377 | {
|
---|
378 | imageDataType_ = FitsDataType_NULL;
|
---|
379 | naxis_ = 0;
|
---|
380 | nbData_ = 0;
|
---|
381 | nrows_ = 0;
|
---|
382 | nbcols_ = 0;
|
---|
383 | naxisn_.clear();
|
---|
384 | repeat_.clear();
|
---|
385 | noms_.clear();
|
---|
386 | taille_des_chaines_.clear();
|
---|
387 | dvl_.Clear();
|
---|
388 |
|
---|
389 | dnull_ = 1.e-300;
|
---|
390 | fnull_ = 1.e-33;
|
---|
391 | inull_= 99999;
|
---|
392 | cnull_= string("xxx");
|
---|
393 |
|
---|
394 |
|
---|
395 | }
|
---|
396 |
|
---|
397 | //////////////////////////////////////////////////////////
|
---|
398 | // methods with general purpose
|
---|
399 | /////////////////////////////////////////////////////////
|
---|
400 |
|
---|
401 | int FitsInFile::NbBlocks(char flnm[])
|
---|
402 | {
|
---|
403 | int status = 0;
|
---|
404 | int nbhdu = 0;
|
---|
405 | fitsfile* fileptr;
|
---|
406 | fits_open_file(&fileptr,flnm,READONLY,&status);
|
---|
407 | if( status ) printerror( status, "NbBlocks: erreur ouverture fichier" );
|
---|
408 | fits_get_num_hdus(fileptr, &nbhdu, &status);
|
---|
409 | fits_close_file(fileptr,&status);
|
---|
410 | return nbhdu;
|
---|
411 | }
|
---|
412 | int FitsInFile::NbBlocks()
|
---|
413 | {
|
---|
414 | int status = 0;
|
---|
415 | int nbhdu = 0;
|
---|
416 | fits_get_num_hdus(fptr_, &nbhdu, &status);
|
---|
417 | return nbhdu;
|
---|
418 | }
|
---|
419 |
|
---|
420 | void FitsInFile::GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl )
|
---|
421 | {
|
---|
422 | int status = 0;
|
---|
423 | fitsfile* fileptr;
|
---|
424 | fits_open_file(&fileptr,flnm,READONLY,&status);
|
---|
425 | if( status ) printerror( status, "GetBlockType: erreur ouverture fichier" );
|
---|
426 | // move to the specified HDU number
|
---|
427 | int hdutype = 0;
|
---|
428 | fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
|
---|
429 | if( status ) printerror( status,"GetBlockType: erreur movabs");
|
---|
430 | if(hdutype == IMAGE_HDU)
|
---|
431 | {
|
---|
432 | typeOfExtension = FitsExtensionType_IMAGE;
|
---|
433 | GetImageParameters (fileptr, dataType, naxis, naxisn);
|
---|
434 | }
|
---|
435 | else
|
---|
436 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
437 | {
|
---|
438 | int nrows = 0;
|
---|
439 | vector<string> noms;
|
---|
440 | vector<FitsDataType> types;
|
---|
441 | vector<int> taille_des_chaines;
|
---|
442 | GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines);
|
---|
443 | int k;
|
---|
444 | for (k=0; k< naxisn.size(); k++) naxisn[k] *= nrows;
|
---|
445 | if(hdutype == ASCII_TBL)
|
---|
446 | {
|
---|
447 | typeOfExtension = FitsExtensionType_ASCII_TBL;
|
---|
448 | dataType = FitsDataType_ASCII;
|
---|
449 | }
|
---|
450 | else
|
---|
451 | {
|
---|
452 | typeOfExtension = FitsExtensionType_BINARY_TBL;
|
---|
453 | dataType = types[0];
|
---|
454 | }
|
---|
455 | }
|
---|
456 | else
|
---|
457 | {
|
---|
458 | cout << " hdutype= " << hdutype << endl;
|
---|
459 | throw IOExc("FitsFile::GetBlockType: this HDU type is unknown");
|
---|
460 | }
|
---|
461 |
|
---|
462 | KeywordsIntoDVList(fileptr, dvl, hdunum);
|
---|
463 | fits_close_file(fileptr,&status);
|
---|
464 | }
|
---|
465 |
|
---|
466 |
|
---|
467 | void FitsInFile::ReadHeader(int hdunum)
|
---|
468 | {
|
---|
469 | // InitNull();
|
---|
470 | int status = 0;
|
---|
471 | if (hdunum<0)
|
---|
472 | {
|
---|
473 | throw PException(" FitsInFile::ReadHeader : hdu number must be not negative");
|
---|
474 | }
|
---|
475 | if (hdunum != 0 ) hdunum_ = hdunum;
|
---|
476 |
|
---|
477 | // si le numero de header non precise
|
---|
478 | else
|
---|
479 | {
|
---|
480 | // si c'est le premier objet a lire
|
---|
481 | if (hdunum_ == 0)
|
---|
482 | {
|
---|
483 | // on calcule le numero de header a lire
|
---|
484 | if (imageOnPrimary_ == true ) hdunum_ = 1;
|
---|
485 | else hdunum_ = 2;
|
---|
486 | }
|
---|
487 | // sinon objet suivant
|
---|
488 | else hdunum_++;
|
---|
489 | }
|
---|
490 | getHeaderWithSophyaObject();
|
---|
491 | if ( hdutype_ == FitsExtensionType_NULL )
|
---|
492 | {
|
---|
493 | if (hdunum == 0 && hdunum_ == 1)
|
---|
494 | {
|
---|
495 | hdunum_++;
|
---|
496 | getHeaderWithSophyaObject();
|
---|
497 | }
|
---|
498 | else
|
---|
499 | {
|
---|
500 | cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
|
---|
501 | }
|
---|
502 | }
|
---|
503 | if ( hdutype_ == FitsExtensionType_EOF )
|
---|
504 | {
|
---|
505 | throw PException("FitsFile::ReadHeader, attempt to read through EOF");
|
---|
506 | }
|
---|
507 | }
|
---|
508 |
|
---|
509 | string FitsInFile::getStringKeyword(int hdunum, string keyw, int& retStatus)
|
---|
510 | {
|
---|
511 | string s;
|
---|
512 | retStatus = 0;
|
---|
513 | int status = 0;
|
---|
514 | if (hdunum != hdunum_ )
|
---|
515 | {
|
---|
516 | int hdutype;
|
---|
517 | fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
|
---|
518 | }
|
---|
519 |
|
---|
520 | char value[FLEN_VALUE];
|
---|
521 | char* keyname= const_cast<char*>(keyw.c_str());
|
---|
522 | fits_read_key_str(fptr_,keyname,value,NULL,&status);
|
---|
523 | if (status == 0)
|
---|
524 | s = string(value);
|
---|
525 | else retStatus = status;
|
---|
526 | if (hdunum != hdunum_ )
|
---|
527 | {
|
---|
528 | int hdutype;
|
---|
529 | if (hdunum_ != 0)
|
---|
530 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
531 | else fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
532 |
|
---|
533 | }
|
---|
534 | return s;
|
---|
535 | }
|
---|
536 | bool FitsInFile::hasKeyword(int hdunum, string keyw)
|
---|
537 | {
|
---|
538 | bool has=false;
|
---|
539 | int status = 0;
|
---|
540 | if (hdunum != hdunum_ )
|
---|
541 | {
|
---|
542 | int hdutype;
|
---|
543 | fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
|
---|
544 | }
|
---|
545 |
|
---|
546 | char value[FLEN_VALUE];
|
---|
547 | char* keyname= const_cast<char*>(keyw.c_str());
|
---|
548 | fits_read_keyword(fptr_,keyname,value,NULL,&status);
|
---|
549 | if (status == 0)
|
---|
550 | has = true;
|
---|
551 | else
|
---|
552 | if (status == KEY_NO_EXIST ) status =0;
|
---|
553 | else fits_report_error(stderr,status);
|
---|
554 | if (hdunum != hdunum_ )
|
---|
555 | {
|
---|
556 | int hdutype;
|
---|
557 | if (hdunum_ != 0)
|
---|
558 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
559 | else fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
560 |
|
---|
561 | }
|
---|
562 | return has;
|
---|
563 | }
|
---|
564 |
|
---|
565 | void FitsInFile::GetKeywordsFromHeader (int hdunum, list<FitsKeyword>& mots_cles) const
|
---|
566 | {
|
---|
567 | int status = 0;
|
---|
568 | int hdutype;
|
---|
569 | fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
|
---|
570 | if( status ) fits_report_error(stderr,status);
|
---|
571 |
|
---|
572 | // get number of keywords
|
---|
573 | int nkeys,keypos;
|
---|
574 | fits_get_hdrpos(fptr_, &nkeys, &keypos,&status);
|
---|
575 | if( status ) fits_report_error(stderr,status);
|
---|
576 | // shift with the number of mandatory keywords
|
---|
577 | int num= 0;
|
---|
578 | // if primary header
|
---|
579 | if (hdunum == 1)
|
---|
580 | {
|
---|
581 | // read NAXIS
|
---|
582 | int naxis=0;
|
---|
583 | fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
584 | // number of mandatory keywords
|
---|
585 | num = naxis+3;
|
---|
586 | }
|
---|
587 | // extensions
|
---|
588 | else
|
---|
589 | {
|
---|
590 | if (hdutype == IMAGE_HDU)
|
---|
591 | {
|
---|
592 | // read NAXIS
|
---|
593 | int naxis=0;
|
---|
594 | fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
595 | // number of mandatory keywords
|
---|
596 | num = naxis+5;
|
---|
597 | }
|
---|
598 | else
|
---|
599 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
600 | {
|
---|
601 | // number of mandatory keywords
|
---|
602 | num = 8;
|
---|
603 | }
|
---|
604 | }
|
---|
605 | int j;
|
---|
606 | char keyname[LEN_KEYWORD];
|
---|
607 | char value[FLEN_VALUE];
|
---|
608 | char comment[FLEN_COMMENT];
|
---|
609 | for(j = num+1; j <= nkeys; j++)
|
---|
610 | {
|
---|
611 | char dtype;
|
---|
612 | fits_read_keyn(fptr_,j,keyname,value,comment,&status);
|
---|
613 | if(status)
|
---|
614 | {
|
---|
615 | fits_report_error(stderr,status);
|
---|
616 | status=0;
|
---|
617 | }
|
---|
618 | string kn(keyname);
|
---|
619 | string cm(comment);
|
---|
620 | string val(value);
|
---|
621 | FitsKeyword kw(kn, val, cm);
|
---|
622 | mots_cles.push_back(kw);
|
---|
623 | }
|
---|
624 | if (hdunum_ > 0) fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
625 |
|
---|
626 | }
|
---|
627 | void FitsInFile::GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn)
|
---|
628 | {
|
---|
629 | int hdunum=0;
|
---|
630 | // cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum) << endl;
|
---|
631 | int status= 0;
|
---|
632 |
|
---|
633 | // bits per pixels
|
---|
634 | int bitpix=0;
|
---|
635 | fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
|
---|
636 | if( status ) printerror( status );
|
---|
637 | if(bitpix == DOUBLE_IMG) dataType = FitsDataType_double;
|
---|
638 | else if(bitpix == FLOAT_IMG) dataType = FitsDataType_float;
|
---|
639 | else if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = FitsDataType_int;
|
---|
640 | else if (bitpix == BYTE_IMG) dataType = FitsDataType_char;
|
---|
641 | else
|
---|
642 | {
|
---|
643 | cout << " bitpix= " << bitpix << endl;
|
---|
644 | throw PException(" FitsFile::GetImageParameters : unsupported FITS data type");
|
---|
645 | }
|
---|
646 |
|
---|
647 | // number of dimensions in the FITS array
|
---|
648 | naxis= 0;
|
---|
649 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
650 | if( status ) printerror( status );
|
---|
651 | // read the NAXISn keywords to get image size
|
---|
652 | long* naxes = new long[naxis] ;
|
---|
653 | int nfound;
|
---|
654 | fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
|
---|
655 | if( status ) printerror( status );
|
---|
656 | if (nfound != naxis )
|
---|
657 | cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
|
---|
658 | int k;
|
---|
659 | for (k=0; k<naxis; k++)
|
---|
660 | {
|
---|
661 | naxisn.push_back( (int)naxes[k] );
|
---|
662 | }
|
---|
663 | delete [] naxes;
|
---|
664 | }
|
---|
665 |
|
---|
666 |
|
---|
667 |
|
---|
668 |
|
---|
669 | /*! \fn DVList SOPHYA::FitsInFile::DVListFromPrimaryHeader() const
|
---|
670 |
|
---|
671 | \return the keywords of primary header in a DVList
|
---|
672 |
|
---|
673 | */
|
---|
674 | DVList FitsInFile::DVListFromPrimaryHeader() const
|
---|
675 | {
|
---|
676 | int status;
|
---|
677 | DVList dvl;
|
---|
678 | KeywordsIntoDVList(fptr_, dvl, 1);
|
---|
679 | int hdutype = 0;
|
---|
680 | if (hdunum_ > 0) fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
681 | return dvl;
|
---|
682 | }
|
---|
683 |
|
---|
684 | void FitsInFile::getHeaderWithSophyaObject()
|
---|
685 | {
|
---|
686 | // si hdunum_ > 1 lit le header correspondant
|
---|
687 | // si hdunum_ = 1 se positionne au (et lit le) premier header qui
|
---|
688 | // contient reellement un objet
|
---|
689 | int status=0;
|
---|
690 | if (hdunum_ < 1) throw PException(" attempt to read hdunum < 1");
|
---|
691 | InitNull();
|
---|
692 | if (hdunum_ == 1)
|
---|
693 | {
|
---|
694 | // presence of image ?
|
---|
695 | int naxis= 0;
|
---|
696 | fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
697 | if( status ) printerror( status );
|
---|
698 | if (naxis > 0 ) // there is an image
|
---|
699 | {
|
---|
700 | hdutype_ = FitsExtensionType_IMAGE;
|
---|
701 | GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
|
---|
702 | nbData_ = 1;
|
---|
703 | int k;
|
---|
704 | for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
|
---|
705 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
706 | }
|
---|
707 | else
|
---|
708 | {
|
---|
709 | hdutype_ = FitsExtensionType_NULL;
|
---|
710 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
711 | }
|
---|
712 | }
|
---|
713 | else
|
---|
714 | {
|
---|
715 | int hdutype;
|
---|
716 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
717 |
|
---|
718 | if( status )
|
---|
719 | {
|
---|
720 | if (status == END_OF_FILE)
|
---|
721 | {
|
---|
722 | hdutype_= FitsExtensionType_EOF;
|
---|
723 | status =0;
|
---|
724 | return;
|
---|
725 | }
|
---|
726 | else
|
---|
727 | {
|
---|
728 | cout << "WARNING (FitsInFile::getHeaderWithSophyaObject) : error during movabs" << endl;
|
---|
729 | hdutype_= FitsExtensionType_ERROR;
|
---|
730 | status =0;
|
---|
731 | return;
|
---|
732 | }
|
---|
733 | // printerror( status,":FitsInFile::getHeader : erreur movabs");
|
---|
734 | }
|
---|
735 |
|
---|
736 |
|
---|
737 | if(hdutype == IMAGE_HDU)
|
---|
738 | {
|
---|
739 | hdutype_= FitsExtensionType_IMAGE;
|
---|
740 | GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
|
---|
741 | nbData_ = 1;
|
---|
742 | int k;
|
---|
743 | for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
|
---|
744 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
745 | }
|
---|
746 | else if(hdutype == ASCII_TBL)
|
---|
747 | {
|
---|
748 | hdutype_= FitsExtensionType_ASCII_TBL;
|
---|
749 | GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
|
---|
750 | KeywordsIntoDVList(fptr_, dvl_, hdunum_);
|
---|
751 | }
|
---|
752 | else if(hdutype == BINARY_TBL)
|
---|
753 | {
|
---|
754 | hdutype_= FitsExtensionType_BINARY_TBL;
|
---|
755 | GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
|
---|
756 | KeywordsIntoDVList(fptr_, dvl_, hdunum_);
|
---|
757 | }
|
---|
758 | else
|
---|
759 | {
|
---|
760 | hdutype_= FitsExtensionType_NULL;
|
---|
761 | KeywordsIntoDVList(fptr_, dvl_, hdunum_);
|
---|
762 | }
|
---|
763 |
|
---|
764 | }
|
---|
765 | if (hdutype_ == FitsExtensionType_BINARY_TBL || hdutype_ == FitsExtensionType_ASCII_TBL)
|
---|
766 | {
|
---|
767 | bfl_ = BufferLine(types_);
|
---|
768 | }
|
---|
769 | }
|
---|
770 |
|
---|
771 |
|
---|
772 | void FitsInFile::moveToFollowingHeader()
|
---|
773 | {
|
---|
774 | int status = 0;
|
---|
775 | hdunum_++;
|
---|
776 | getHeaderWithSophyaObject();
|
---|
777 | if ( hdutype_ == FitsExtensionType_NULL )
|
---|
778 | {
|
---|
779 | cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
|
---|
780 |
|
---|
781 | }
|
---|
782 | }
|
---|
783 |
|
---|
784 |
|
---|
785 |
|
---|
786 |
|
---|
787 |
|
---|
788 | /*! \fn int SOPHYA::FitsInFile::NbColsFromFits() const
|
---|
789 | \return number of columns (return 1 if IMAGE)
|
---|
790 | */
|
---|
791 | int FitsInFile::NbColsFromFits() const
|
---|
792 | {
|
---|
793 | if(hdutype_ == FitsExtensionType_BINARY_TBL) return nbcols_;
|
---|
794 | else
|
---|
795 | if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_IMAGE) return 1;
|
---|
796 | else
|
---|
797 | {
|
---|
798 | cout << " hdutype= " << (int) hdutype_ << endl;
|
---|
799 | throw PException("FitsFile::NbColsFromFits, HDU not supported");
|
---|
800 | }
|
---|
801 | }
|
---|
802 |
|
---|
803 | /*! \fn int SOPHYA::FitsInFile::NentriesFromFits(int nocol) const
|
---|
804 | \return number of data in the current IMAGE extension on FITS file, or number
|
---|
805 | of data of column number 'nocol' of the current BINTABLE extension
|
---|
806 | */
|
---|
807 | int FitsInFile::NentriesFromFits(int nocol) const
|
---|
808 | {
|
---|
809 | if(hdutype_ == FitsExtensionType_BINARY_TBL) return nrows_*repeat_[nocol];
|
---|
810 | else
|
---|
811 | if(hdutype_ == FitsExtensionType_ASCII_TBL) return nrows_;
|
---|
812 | else
|
---|
813 | if(hdutype_ == FitsExtensionType_IMAGE) return nbData_;
|
---|
814 | else
|
---|
815 | {
|
---|
816 | cout << "hdutype= " << (int) hdutype_ << endl;
|
---|
817 | throw PException("FitsFile::NentriesFromFits, this HDU is not supported");
|
---|
818 | }
|
---|
819 | }
|
---|
820 |
|
---|
821 | /*! \fn char SOPHYA::FitsInFile::ColTypeFromFits(int nocol) const
|
---|
822 |
|
---|
823 | return a character denoting data type of column number 'nocol' in a BINTABLE :
|
---|
824 |
|
---|
825 | D : double
|
---|
826 |
|
---|
827 | E : float
|
---|
828 |
|
---|
829 | I : integer
|
---|
830 |
|
---|
831 | S : character string
|
---|
832 |
|
---|
833 | */
|
---|
834 |
|
---|
835 | FitsFile::FitsDataType FitsInFile::ColTypeFromFits(int nocol) const
|
---|
836 | {
|
---|
837 | if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
|
---|
838 | {
|
---|
839 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
840 | }
|
---|
841 | return types_[nocol];
|
---|
842 | }
|
---|
843 |
|
---|
844 |
|
---|
845 | /*! \fn string SOPHYA::FitsInFile::ColNameFromFits(int nocol) const
|
---|
846 |
|
---|
847 | \return name of the column number 'nocol' of the current BINTABLE extension
|
---|
848 | */
|
---|
849 |
|
---|
850 | string FitsInFile::ColNameFromFits(int nocol) const
|
---|
851 | {
|
---|
852 | if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
|
---|
853 | {
|
---|
854 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
855 | }
|
---|
856 | return noms_[nocol];
|
---|
857 | }
|
---|
858 |
|
---|
859 | /*! \fn int DSOPHYA::FitsInFile::ColStringLengthFromFits(int nocol) const
|
---|
860 |
|
---|
861 | \return number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension
|
---|
862 | */
|
---|
863 |
|
---|
864 | int FitsInFile::ColStringLengthFromFits(int nocol) const
|
---|
865 | {
|
---|
866 | if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
|
---|
867 | {
|
---|
868 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
869 | }
|
---|
870 | int index=-1;
|
---|
871 | int k;
|
---|
872 | for (k=0; k<=nocol; k++)
|
---|
873 | {
|
---|
874 | if (types_[k] == FitsDataType_char) index++;
|
---|
875 | }
|
---|
876 | return taille_des_chaines_[index];
|
---|
877 | }
|
---|
878 |
|
---|
879 | const FitsFile::BufferLine& FitsInFile::GetBufferLine(long NoLine)
|
---|
880 | {
|
---|
881 | int status= 0;
|
---|
882 | int anynul;
|
---|
883 | double dnull= dnull_;
|
---|
884 | float fnull= fnull_;
|
---|
885 | int inull= inull_;
|
---|
886 | char* cnull= const_cast<char*>(cnull_.c_str());
|
---|
887 | int ncol;
|
---|
888 | long nels=1;
|
---|
889 | double dval;
|
---|
890 | float fval;
|
---|
891 | int ival;
|
---|
892 |
|
---|
893 | // pas d'entier de longueur superieure a 32 bits, pour cfitsio
|
---|
894 | int lval;
|
---|
895 |
|
---|
896 | unsigned char usval;
|
---|
897 | int rang = 0;
|
---|
898 | int ccount = 0;
|
---|
899 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
900 | {
|
---|
901 | rang = bfl_.identificateur()[ncol].second;
|
---|
902 | // cout << " fitsfile : relecture col " << ncol << " type " << bfl_.identificateur()[ncol].first << " rang " << rang << endl;
|
---|
903 | switch (bfl_.identificateur()[ncol].first)
|
---|
904 | {
|
---|
905 | case FitsDataType_double :
|
---|
906 | fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull, &dval,&anynul,&status);
|
---|
907 | bfl_.r_8Array(rang) = (r_8)dval;
|
---|
908 | break;
|
---|
909 | case FitsDataType_float :
|
---|
910 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fval,&anynul,&status);
|
---|
911 | bfl_.r_4Array(rang) = (r_4)fval;
|
---|
912 | break;
|
---|
913 | case FitsDataType_short :
|
---|
914 | fits_read_col(fptr_,TSHORT,ncol+1,NoLine+1,1,1,&inull,&ival, &anynul,&status);
|
---|
915 | bfl_.int_2Array(rang) = (int_2)ival;
|
---|
916 | break;
|
---|
917 | case FitsDataType_int :
|
---|
918 | fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ival, &anynul,&status);
|
---|
919 | bfl_.int_4Array(rang) = (int_4)ival;
|
---|
920 | break;
|
---|
921 | case FitsDataType_long :
|
---|
922 | fits_read_col(fptr_,TLONG,ncol+1,NoLine+1,1,1,&inull,&lval, &anynul,&status);
|
---|
923 | bfl_.int_8Array(rang) = (int_8)lval;
|
---|
924 | break;
|
---|
925 | case FitsDataType_byte :
|
---|
926 | fits_read_col(fptr_,TBYTE,ncol+1,NoLine+1,1,1,&inull, &usval, &anynul,&status);
|
---|
927 | bfl_.u_charArray(rang) = usval;
|
---|
928 | break;
|
---|
929 | case FitsDataType_char :
|
---|
930 | char* chaine = new char[taille_des_chaines_[ccount++]];
|
---|
931 | fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anynul,&status);
|
---|
932 | bfl_.stringArray(rang) = string(chaine);
|
---|
933 | break;
|
---|
934 | }
|
---|
935 | if (status)
|
---|
936 | {
|
---|
937 | ResetStatus(status);
|
---|
938 | break;
|
---|
939 | }
|
---|
940 | }
|
---|
941 | // cout << " fitsfile : ligne relue " << endl;
|
---|
942 | // bfl_.Print();
|
---|
943 | return bfl_;
|
---|
944 | }
|
---|
945 |
|
---|
946 |
|
---|
947 |
|
---|
948 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
|
---|
949 |
|
---|
950 | Get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
|
---|
951 | */
|
---|
952 |
|
---|
953 | void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
|
---|
954 | {
|
---|
955 | int status= 0;
|
---|
956 | int anynul;
|
---|
957 | double dnull= dnull_;
|
---|
958 | float fnull= fnull_;
|
---|
959 | int inull= inull_;
|
---|
960 | char* cnull= const_cast<char*>(cnull_.c_str());
|
---|
961 | int dcount = 0.;
|
---|
962 | int fcount = 0.;
|
---|
963 | int icount = 0;
|
---|
964 | int ccount =0;
|
---|
965 | int ncol;
|
---|
966 | long nels=1;
|
---|
967 | int ligneAsolue = NoLine+1;
|
---|
968 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
969 | {
|
---|
970 | int repetition =repeat_[ncol];
|
---|
971 | int ligneALire = ligneAsolue/repetition;
|
---|
972 | int premierElement = ligneAsolue-ligneALire*repetition;
|
---|
973 | if (premierElement != 0 )
|
---|
974 | {
|
---|
975 | ligneALire++;
|
---|
976 | }
|
---|
977 | else premierElement = repetition;
|
---|
978 |
|
---|
979 | switch (types_[ncol])
|
---|
980 | {
|
---|
981 | case FitsDataType_double :
|
---|
982 | {
|
---|
983 | fits_read_col(fptr_,TDOUBLE,ncol+1,ligneALire,premierElement,1,&dnull,&ddata[dcount++],&anynul,&status);
|
---|
984 | break;
|
---|
985 | }
|
---|
986 | case FitsDataType_float :
|
---|
987 | {
|
---|
988 | fits_read_col(fptr_,TFLOAT,ncol+1,ligneALire,premierElement,1,&fnull,&fdata[fcount++],&anynul,&status);
|
---|
989 | break;
|
---|
990 | }
|
---|
991 | case FitsDataType_int :
|
---|
992 | {
|
---|
993 | fits_read_col(fptr_,TINT,ncol+1,ligneALire,premierElement,1,&inull,&idata[icount++],
|
---|
994 | &anynul,&status);
|
---|
995 | break;
|
---|
996 | }
|
---|
997 | case FitsDataType_long :
|
---|
998 | {
|
---|
999 | fits_read_col(fptr_,TLONG,ncol+1,ligneALire,premierElement,1,&inull,&idata[icount++], &anynul,&status);
|
---|
1000 | break;
|
---|
1001 | }
|
---|
1002 | case FitsDataType_byte :
|
---|
1003 | {
|
---|
1004 | unsigned char uschar = 0;
|
---|
1005 | fits_read_col(fptr_,TBYTE,ncol+1,ligneALire,premierElement,1,&inull,&uschar, &anynul,&status);
|
---|
1006 | idata[icount++] = (int)uschar;
|
---|
1007 | break;
|
---|
1008 | }
|
---|
1009 | case FitsDataType_char :
|
---|
1010 | {
|
---|
1011 | fits_read_col(fptr_,TSTRING,ncol+1,ligneALire,premierElement,1,cnull,&cdata[ccount++],&anynul,&status);
|
---|
1012 | break;
|
---|
1013 | }
|
---|
1014 | default:
|
---|
1015 | {
|
---|
1016 | throw PException(" FitsInFile::GetBinTabLine : unsupported FITS data type");
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 | if (status)
|
---|
1020 | {
|
---|
1021 | ResetStatus(status);
|
---|
1022 | break;
|
---|
1023 | }
|
---|
1024 | }
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne)
|
---|
1028 | Get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
|
---|
1029 | */
|
---|
1030 | void FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne)
|
---|
1031 | {
|
---|
1032 | int status= 0;
|
---|
1033 | int anynul;
|
---|
1034 | double dnull= dnull_;
|
---|
1035 | float fnull= fnull_;
|
---|
1036 | int inull= inull_;
|
---|
1037 | char* cnull= const_cast<char*>(cnull_.c_str());
|
---|
1038 | int dcount = 0.;
|
---|
1039 | int fcount = 0.;
|
---|
1040 | int icount = 0;
|
---|
1041 | int lcount = 0;
|
---|
1042 | int bcount = 0;
|
---|
1043 | int ccount =0;
|
---|
1044 | int ncol;
|
---|
1045 | long nels=1;
|
---|
1046 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
1047 | {
|
---|
1048 | switch (types_[ncol])
|
---|
1049 | {
|
---|
1050 | case FitsDataType_double :
|
---|
1051 | {
|
---|
1052 | fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ligne.ddata_[dcount++],&anynul,&status);
|
---|
1053 | break;
|
---|
1054 | }
|
---|
1055 | case FitsDataType_float :
|
---|
1056 | {
|
---|
1057 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&ligne.fdata_[fcount++],&anynul,&status);
|
---|
1058 | break;
|
---|
1059 | }
|
---|
1060 | case FitsDataType_int :
|
---|
1061 | {
|
---|
1062 | fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ligne.idata_[icount++], &anynul,&status);
|
---|
1063 | break;
|
---|
1064 | }
|
---|
1065 | case FitsDataType_long :
|
---|
1066 | {
|
---|
1067 | fits_read_col(fptr_,TLONG,ncol+1,NoLine+1,1,1,&inull,&ligne.ldata_[lcount++], &anynul,&status);
|
---|
1068 | break;
|
---|
1069 | }
|
---|
1070 | case FitsDataType_byte :
|
---|
1071 | {
|
---|
1072 | fits_read_col(fptr_,TBYTE,ncol+1,NoLine+1,1,1,&inull,&ligne.bdata_[bcount++], &anynul,&status);
|
---|
1073 | break;
|
---|
1074 | }
|
---|
1075 | case FitsDataType_char :
|
---|
1076 | {
|
---|
1077 | char* chaine = new char[taille_des_chaines_[ccount]];
|
---|
1078 | fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anynul,&status);
|
---|
1079 | ligne.cdata_[ccount++] = string(chaine);
|
---|
1080 | break;
|
---|
1081 | }
|
---|
1082 | default:
|
---|
1083 | {
|
---|
1084 | throw PException(" FitsInFile::GetBinTabLine : unsupported FITS data type");
|
---|
1085 | }
|
---|
1086 | }
|
---|
1087 | if (status)
|
---|
1088 | {
|
---|
1089 | ResetStatus(status);
|
---|
1090 | break;
|
---|
1091 | }
|
---|
1092 | }
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 |
|
---|
1096 |
|
---|
1097 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, float* fdata)
|
---|
1098 |
|
---|
1099 | Get the NoLine-th float 'line' from the current BINTABLE extension on FITS file,
|
---|
1100 | */
|
---|
1101 | void FitsInFile::GetBinTabLine(int NoLine, float* fdata)
|
---|
1102 | {
|
---|
1103 | int status= 0;
|
---|
1104 | int anynul;
|
---|
1105 | float fnull= fnull_;
|
---|
1106 | long nels=1;
|
---|
1107 | int ncol;
|
---|
1108 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
1109 | {
|
---|
1110 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anynul,&status);
|
---|
1111 | if (status)
|
---|
1112 | {
|
---|
1113 | ResetStatus(status);
|
---|
1114 | break;
|
---|
1115 | }
|
---|
1116 | }
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 |
|
---|
1120 | /*! \fn void SPOPHYA::FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
|
---|
1121 |
|
---|
1122 | fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
|
---|
1123 |
|
---|
1124 | \param <nentries> number of data to be read
|
---|
1125 | */
|
---|
1126 | void FitsInFile::GetBinTabFCol(r_8* valeurs,int nentries, int NoCol) const
|
---|
1127 | {
|
---|
1128 | int status= 0;
|
---|
1129 | int DTYPE;
|
---|
1130 | long repeat,width;
|
---|
1131 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
1132 | if( DTYPE != TDOUBLE)
|
---|
1133 | {
|
---|
1134 | if (DTYPE == TFLOAT) cout << " WARNING: reading double from float : conversion will be made by fitsio library" << endl;
|
---|
1135 | else
|
---|
1136 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
|
---|
1137 | }
|
---|
1138 | long nels=nentries;
|
---|
1139 | int anynul;
|
---|
1140 | double dnull= dnull_;
|
---|
1141 |
|
---|
1142 | fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
|
---|
1143 | &anynul,&status);
|
---|
1144 | if( status )
|
---|
1145 | {
|
---|
1146 | printerrorAndContinue( status,"erreur lecture de colonne" );
|
---|
1147 | }
|
---|
1148 | }
|
---|
1149 |
|
---|
1150 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
|
---|
1151 |
|
---|
1152 | same as previous method with float data
|
---|
1153 | */
|
---|
1154 | void FitsInFile::GetBinTabFCol(r_4* valeurs,int nentries, int NoCol) const
|
---|
1155 | {
|
---|
1156 | int status= 0;
|
---|
1157 | int DTYPE;
|
---|
1158 | long repeat,width;
|
---|
1159 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
1160 | if( DTYPE != TFLOAT)
|
---|
1161 | {
|
---|
1162 | if (DTYPE == TDOUBLE) cout << " WARNING: reading float from double : conversion will be made by fitsio library" << endl;
|
---|
1163 | else
|
---|
1164 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
|
---|
1165 | }
|
---|
1166 | long nels=nentries;
|
---|
1167 | int anynul;
|
---|
1168 | float fnull= fnull_;
|
---|
1169 | fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
|
---|
1170 | &anynul,&status);
|
---|
1171 | if( status ) printerrorAndContinue( status,"erreur lecture de colonne" );
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
|
---|
1175 |
|
---|
1176 | same as previous method with int data
|
---|
1177 | */
|
---|
1178 |
|
---|
1179 | void FitsInFile::GetBinTabFCol(int_4* valeurs,int nentries, int NoCol) const
|
---|
1180 | {
|
---|
1181 | int status= 0;
|
---|
1182 | int DTYPE;
|
---|
1183 | long repeat,width;
|
---|
1184 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
1185 | if( DTYPE != TLONG && DTYPE != TINT)
|
---|
1186 | {
|
---|
1187 | throw IOExc("FitsFile::GetBinTabFCol, probleme de lecture d'entiers");
|
---|
1188 | }
|
---|
1189 | long nels=nentries;
|
---|
1190 | int anynul;
|
---|
1191 | int inull= inull_;
|
---|
1192 |
|
---|
1193 |
|
---|
1194 |
|
---|
1195 | // voir commentaire dans putColToFits()
|
---|
1196 | fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
|
---|
1197 | &anynul,&status);
|
---|
1198 | if( status ) printerrorAndContinue( status,"erreur lecture de colonne" );
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
|
---|
1202 |
|
---|
1203 | same as previous method with char* data
|
---|
1204 | */
|
---|
1205 |
|
---|
1206 | void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
|
---|
1207 | {
|
---|
1208 | int status= 0;
|
---|
1209 | int DTYPE;
|
---|
1210 | long repeat,width;
|
---|
1211 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
1212 | if( DTYPE != TSTRING && DTYPE != TBYTE)
|
---|
1213 | {
|
---|
1214 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non string");
|
---|
1215 | }
|
---|
1216 | long nels=nentries;
|
---|
1217 | int anynul;
|
---|
1218 | char* cnull= const_cast<char*>(cnull_.c_str());
|
---|
1219 | long frow=1;
|
---|
1220 | long felem=1;
|
---|
1221 | fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
|
---|
1222 | &anynul,&status);
|
---|
1223 | if( status ) printerrorAndContinue( status,"erreur lecture de colonne" );
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(double* map, int nentries) const
|
---|
1227 | fill the array 'map' with double data from the current extension on FITS file.
|
---|
1228 | If the extension is BINTABLE, the first column is provided.
|
---|
1229 |
|
---|
1230 | \param <nentries> number of data to be read
|
---|
1231 | */
|
---|
1232 | void FitsInFile::GetSingleColumn(r_8* map, int nentries) const
|
---|
1233 | {
|
---|
1234 | int status = 0;
|
---|
1235 | if(hdutype_ == FitsExtensionType_IMAGE)
|
---|
1236 | {
|
---|
1237 |
|
---|
1238 | if(imageDataType_ != FitsDataType_double)
|
---|
1239 | {
|
---|
1240 | cout << " The data type on fits file is not double...";
|
---|
1241 | cout << " Conversion to double achieved by cfitsio lib" << endl;
|
---|
1242 | }
|
---|
1243 |
|
---|
1244 | int anynul;
|
---|
1245 | double dnull= dnull_;
|
---|
1246 |
|
---|
1247 | long nels= nentries;
|
---|
1248 | fits_read_img(fptr_,TDOUBLE,1,nels,&dnull,map,&anynul,&status);
|
---|
1249 | if( status ) printerror( status );
|
---|
1250 | }
|
---|
1251 | else
|
---|
1252 | if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
|
---|
1253 | {
|
---|
1254 | GetBinTabFCol(map,nentries, 0);
|
---|
1255 | }
|
---|
1256 | else
|
---|
1257 | {
|
---|
1258 | cout << " hdutype= " << (int) hdutype_ << endl;
|
---|
1259 | throw IOExc("FitsFile::GetSingleColumn, this HDU is unknown");
|
---|
1260 | }
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
|
---|
1264 | same as above with float data
|
---|
1265 | */
|
---|
1266 | void FitsInFile::GetSingleColumn(r_4* map, int nentries) const
|
---|
1267 | {
|
---|
1268 | int status = 0;
|
---|
1269 | if(hdutype_ == FitsExtensionType_IMAGE)
|
---|
1270 | {
|
---|
1271 | if(imageDataType_ != FitsDataType_float)
|
---|
1272 | {
|
---|
1273 | cout << " The data type on fits file is not float ";
|
---|
1274 | cout << " Conversion to float achieved by cfitsio lib" << endl;
|
---|
1275 | }
|
---|
1276 | int anynul;
|
---|
1277 | float fnull= fnull_;
|
---|
1278 |
|
---|
1279 | long nels= nentries;
|
---|
1280 | fits_read_img(fptr_,TFLOAT,1,nels,&fnull, map,&anynul,&status);
|
---|
1281 | if( status ) printerror( status );
|
---|
1282 | }
|
---|
1283 | else
|
---|
1284 | if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
|
---|
1285 | {
|
---|
1286 | GetBinTabFCol(map,nentries, 0);
|
---|
1287 | }
|
---|
1288 | else
|
---|
1289 | {
|
---|
1290 | cout << " hdutype= " << (int) hdutype_ << endl;
|
---|
1291 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
1292 | }
|
---|
1293 | }
|
---|
1294 |
|
---|
1295 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
|
---|
1296 | same as above with int data
|
---|
1297 | */
|
---|
1298 | void FitsInFile::GetSingleColumn( int_4* map, int nentries) const
|
---|
1299 | {
|
---|
1300 | int status = 0;
|
---|
1301 | if(hdutype_ == FitsExtensionType_IMAGE)
|
---|
1302 | {
|
---|
1303 | if(imageDataType_ != FitsDataType_int)
|
---|
1304 | {
|
---|
1305 | cout << " The data type on fits file is not int ";
|
---|
1306 | cout << " Conversion to float achieved by cfitsio lib" << endl;
|
---|
1307 | }
|
---|
1308 | int anynul;
|
---|
1309 | float fnull= fnull_;
|
---|
1310 |
|
---|
1311 | long nels= nentries;
|
---|
1312 | fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anynul,&status);
|
---|
1313 | if( status ) printerror( status );
|
---|
1314 | }
|
---|
1315 | else
|
---|
1316 | if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
|
---|
1317 | {
|
---|
1318 | GetBinTabFCol(map,nentries, 0);
|
---|
1319 | }
|
---|
1320 | else
|
---|
1321 | {
|
---|
1322 | cout << " hdutype= " << (int) hdutype_ << endl;
|
---|
1323 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
1324 | }
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
|
---|
1328 | vector<int>& repeat,
|
---|
1329 | vector<string>& noms,
|
---|
1330 | vector<FitsDataType>& types,
|
---|
1331 | vector<int>& taille_des_chaines)
|
---|
1332 | {
|
---|
1333 | int status= 0;
|
---|
1334 | int hdunum=0;
|
---|
1335 | int hdutype=0;
|
---|
1336 | fits_get_hdu_num(fileptr,&hdunum);
|
---|
1337 | fits_get_hdu_type(fileptr, &hdutype, &status);
|
---|
1338 |
|
---|
1339 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
1340 | {
|
---|
1341 | throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
|
---|
1342 | }
|
---|
1343 | // if(hdutype == ASCII_TBL)
|
---|
1344 | // cout << " Reading a FITS ascii table in HDU : " << hdunum << endl;
|
---|
1345 | // if(hdutype == BINARY_TBL)
|
---|
1346 | // cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
|
---|
1347 |
|
---|
1348 | // get the number of columns
|
---|
1349 | fits_get_num_cols(fileptr, &nbcols,&status);
|
---|
1350 | if( status ) printerror( status );
|
---|
1351 |
|
---|
1352 | // get the number of rows
|
---|
1353 | long naxis2= 0;
|
---|
1354 | fits_get_num_rows(fileptr,&naxis2,&status);
|
---|
1355 | if( status ) printerror( status );
|
---|
1356 | nrows = (int)naxis2;
|
---|
1357 |
|
---|
1358 | // get the datatype, names and the repeat count
|
---|
1359 | noms.clear();
|
---|
1360 | noms.reserve(nbcols);
|
---|
1361 | types.clear();
|
---|
1362 | types.reserve(nbcols);
|
---|
1363 | repeat.clear();
|
---|
1364 | repeat.reserve(nbcols);
|
---|
1365 | taille_des_chaines.clear();
|
---|
1366 | char **ttype = new char*[nbcols];
|
---|
1367 | int ii;
|
---|
1368 | //
|
---|
1369 | //
|
---|
1370 | for (ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
|
---|
1371 | int nfound;
|
---|
1372 | fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
|
---|
1373 | if( status ) printerror( status,"erreur lecture des noms de colonne");
|
---|
1374 | int rept=0;
|
---|
1375 | if(hdutype == ASCII_TBL)
|
---|
1376 | {
|
---|
1377 | for(ii = 0; ii < nbcols; ii++)
|
---|
1378 | {
|
---|
1379 | int DTYPE;
|
---|
1380 | long width;
|
---|
1381 | long repete = 0;
|
---|
1382 | fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
|
---|
1383 | if( status ) printerror( status,"erreur lecture type de colonne");
|
---|
1384 | rept = repete;
|
---|
1385 | noms.push_back(string(ttype[ii]));
|
---|
1386 | switch (DTYPE)
|
---|
1387 | {
|
---|
1388 | case TDOUBLE :
|
---|
1389 | types.push_back(FitsDataType_double);
|
---|
1390 | break;
|
---|
1391 | case TFLOAT :
|
---|
1392 | types.push_back(FitsDataType_float);
|
---|
1393 | break;
|
---|
1394 | case TLONG :
|
---|
1395 | types.push_back(FitsDataType_long);
|
---|
1396 | break;
|
---|
1397 | case TINT :
|
---|
1398 | types.push_back(FitsDataType_int);
|
---|
1399 | break;
|
---|
1400 | case TSHORT :
|
---|
1401 | types.push_back(FitsDataType_short);
|
---|
1402 | break;
|
---|
1403 | case TSTRING :
|
---|
1404 | types.push_back(FitsDataType_char);
|
---|
1405 | taille_des_chaines.push_back(width);
|
---|
1406 | rept/=width;
|
---|
1407 | break;
|
---|
1408 | default :
|
---|
1409 | cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
|
---|
1410 | throw IOExc("FitsFile::GetBinTabParameters, unsupported data type of field, for ASCII table");
|
---|
1411 | }
|
---|
1412 | repeat.push_back(rept);
|
---|
1413 | }
|
---|
1414 | }
|
---|
1415 | else
|
---|
1416 | {
|
---|
1417 | for(ii = 0; ii < nbcols; ii++)
|
---|
1418 | {
|
---|
1419 | int DTYPE;
|
---|
1420 | long width;
|
---|
1421 | long repete = 0;
|
---|
1422 | fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
|
---|
1423 | if( status ) printerror( status,"erreur lecture type de colonne");
|
---|
1424 | rept = repete;
|
---|
1425 | noms.push_back(string(ttype[ii]));
|
---|
1426 | switch (DTYPE)
|
---|
1427 | {
|
---|
1428 | case TDOUBLE :
|
---|
1429 | types.push_back(FitsDataType_double);
|
---|
1430 | break;
|
---|
1431 | case TFLOAT :
|
---|
1432 | types.push_back(FitsDataType_float);
|
---|
1433 | break;
|
---|
1434 | case TLONG :
|
---|
1435 | types.push_back(FitsDataType_long);
|
---|
1436 | break;
|
---|
1437 | case TINT :
|
---|
1438 | types.push_back(FitsDataType_int);
|
---|
1439 | break;
|
---|
1440 | case TSHORT :
|
---|
1441 | types.push_back(FitsDataType_short);
|
---|
1442 | break;
|
---|
1443 | case TSTRING :
|
---|
1444 | types.push_back(FitsDataType_char);
|
---|
1445 | taille_des_chaines.push_back(width);
|
---|
1446 | rept/=width;
|
---|
1447 | break;
|
---|
1448 | case TBYTE :
|
---|
1449 | types.push_back(FitsDataType_byte);
|
---|
1450 | break;
|
---|
1451 | default :
|
---|
1452 | cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
|
---|
1453 | throw IOExc("FitsFile::GetBinTabParameters, unsupported data type of field, for BINTABLE");
|
---|
1454 | }
|
---|
1455 | repeat.push_back(rept);
|
---|
1456 | }
|
---|
1457 | }
|
---|
1458 | for (ii=0; ii < nbcols; ii++) delete [] ttype[ii];
|
---|
1459 | delete [] ttype;
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | void FitsInFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum)
|
---|
1463 | {
|
---|
1464 | int status = 0;
|
---|
1465 | int hdutype;
|
---|
1466 | fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
|
---|
1467 | if( status ) printerror( status,":KeywordsIntoDVList : erreur movabs");
|
---|
1468 | // get number of keywords
|
---|
1469 | int nkeys,keypos;
|
---|
1470 | fits_get_hdrpos(fileptr,&nkeys,&keypos,&status);
|
---|
1471 | if( status ) printerror( status );
|
---|
1472 |
|
---|
1473 | // put keywords in a DVList object
|
---|
1474 | char keyname[LEN_KEYWORD]= "";
|
---|
1475 | char strval[FLEN_VALUE]= "";
|
---|
1476 | char dtype;
|
---|
1477 | char card[FLEN_CARD];
|
---|
1478 | char *comkey = "COMMENT";
|
---|
1479 | char comment[FLEN_COMMENT];
|
---|
1480 |
|
---|
1481 | // shift with the number of mandatory keywords
|
---|
1482 | // int num= 8;
|
---|
1483 | int num= 0;
|
---|
1484 | // primary header
|
---|
1485 | if (hdunum == 1)
|
---|
1486 | {
|
---|
1487 | // read NAXIS
|
---|
1488 | int naxis=0;
|
---|
1489 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
1490 | // number of mandatory keywords
|
---|
1491 | num = naxis+3;
|
---|
1492 | }
|
---|
1493 | // extensions
|
---|
1494 | else
|
---|
1495 | {
|
---|
1496 | if (hdutype == IMAGE_HDU)
|
---|
1497 | {
|
---|
1498 | // read NAXIS
|
---|
1499 | int naxis=0;
|
---|
1500 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
1501 | // number of mandatory keywords
|
---|
1502 | num = naxis+5;
|
---|
1503 | }
|
---|
1504 | else
|
---|
1505 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
1506 | {
|
---|
1507 | // number of mandatory keywords
|
---|
1508 | num = 8;
|
---|
1509 | }
|
---|
1510 | }
|
---|
1511 | int j;
|
---|
1512 | for(j = num+1; j <= nkeys; j++)
|
---|
1513 | {
|
---|
1514 | fits_read_keyn(fileptr,j,card,strval,NULL,&status);
|
---|
1515 | if(status) printerror(status);
|
---|
1516 |
|
---|
1517 | strncpy(keyname,card,LEN_KEYWORD-1);
|
---|
1518 | if(strncmp(keyname,comkey,LEN_KEYWORD-1) != 0 && strlen(keyname) != 0
|
---|
1519 | && strlen(strval) != 0)
|
---|
1520 | {
|
---|
1521 | fits_get_keytype(strval,&dtype,&status);
|
---|
1522 | if(status) printerror(status);
|
---|
1523 |
|
---|
1524 | strip(keyname, 'B',' ');
|
---|
1525 | strip(strval, 'B',' ');
|
---|
1526 | strip(strval, 'B','\'');
|
---|
1527 |
|
---|
1528 | switch( dtype )
|
---|
1529 | {
|
---|
1530 | case 'C':
|
---|
1531 | fits_read_key(fileptr,TSTRING,keyname,strval,comment,&status);
|
---|
1532 | if ( strncmp(keyname,"TTYPE",5) == 0 ||
|
---|
1533 | strncmp(keyname,"TFORM",5) == 0 ||
|
---|
1534 | strncmp(keyname,"TBCOL",5) == 0 ) break;
|
---|
1535 | dvl[keyname]= strval;
|
---|
1536 | dvl.SetComment(keyname, comment);
|
---|
1537 | break;
|
---|
1538 | case 'I':
|
---|
1539 | int ival;
|
---|
1540 | fits_read_key(fileptr,TINT,keyname,&ival,comment,&status);
|
---|
1541 | dvl[keyname]= (int_4) ival; // Portage mac DY
|
---|
1542 | dvl.SetComment(keyname, comment);
|
---|
1543 | break;
|
---|
1544 | case 'L':
|
---|
1545 | int ilog;
|
---|
1546 | fits_read_key(fileptr,TLOGICAL,keyname,&ilog,comment,&status);
|
---|
1547 | dvl[keyname]= (int_4) ilog;
|
---|
1548 | dvl.SetComment(keyname, comment);
|
---|
1549 | break;
|
---|
1550 | case 'F':
|
---|
1551 | double dval;
|
---|
1552 | fits_read_key(fileptr,TDOUBLE,keyname,&dval,comment,&status);
|
---|
1553 | dvl[keyname]= dval;
|
---|
1554 | dvl.SetComment(keyname, comment);
|
---|
1555 | break;
|
---|
1556 | }
|
---|
1557 |
|
---|
1558 | }
|
---|
1559 | }
|
---|
1560 | // dvl.Print();
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 |
|
---|
1564 | /*!
|
---|
1565 | \class SOPHYA::FitsOutFile
|
---|
1566 | \ingroup FitsIOServer
|
---|
1567 | Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib)
|
---|
1568 | */
|
---|
1569 |
|
---|
1570 | FitsOutFile::FitsOutFile()
|
---|
1571 | {
|
---|
1572 | InitNull();
|
---|
1573 | }
|
---|
1574 |
|
---|
1575 | /*! \fn SOPHYA::FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
|
---|
1576 |
|
---|
1577 | \param <WriteMode> enum , WriteMode = clear -> if alreadyy exists, the file will be overwritten (else created) ; WriteMode = append -> further objects will be appended to the file if it exists (else : file created). WriteMode = unknown -> file created if does not exist, else : exception. (the last situation is the default)
|
---|
1578 |
|
---|
1579 | */
|
---|
1580 |
|
---|
1581 | FitsOutFile::FitsOutFile(string const & flnm, WriteMode wrm)
|
---|
1582 | {
|
---|
1583 | InitNull();
|
---|
1584 | openoutputfitsfile(flnm.c_str(), wrm);
|
---|
1585 | }
|
---|
1586 |
|
---|
1587 | FitsOutFile::FitsOutFile(const char * flnm, WriteMode wrm)
|
---|
1588 | {
|
---|
1589 | InitNull();
|
---|
1590 | openoutputfitsfile(flnm, wrm);
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | void FitsOutFile::openoutputfitsfile(const char * flnm, WriteMode wrm)
|
---|
1594 | {
|
---|
1595 | int status = 0;
|
---|
1596 |
|
---|
1597 | // create new FITS file
|
---|
1598 | fits_create_file(&fptr_,flnm,&status);
|
---|
1599 | if( status )
|
---|
1600 | {
|
---|
1601 |
|
---|
1602 | switch (wrm)
|
---|
1603 | {
|
---|
1604 | // si on veut ecrire a la fin de ce fichier
|
---|
1605 | case append :
|
---|
1606 | status = 0;
|
---|
1607 | fits_clear_errmsg();
|
---|
1608 | fits_open_file(&fptr_,flnm,READWRITE,&status);
|
---|
1609 | if( status )
|
---|
1610 | {
|
---|
1611 | cout << " error opening file: " << flnm << endl;
|
---|
1612 | printerror(status, "failure opening a file supposed to exist");
|
---|
1613 | }
|
---|
1614 | else cout << " file " << flnm << " opened, new objects will be appended " << endl;
|
---|
1615 | fits_get_num_hdus(fptr_, &hdunum_, &status);
|
---|
1616 | int hdutype;
|
---|
1617 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
1618 | if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
|
---|
1619 | break;
|
---|
1620 |
|
---|
1621 | case clear :
|
---|
1622 | {
|
---|
1623 | status = 0;
|
---|
1624 | fits_clear_errmsg();
|
---|
1625 | char* newname = new char[strlen(flnm)+2];
|
---|
1626 | //
|
---|
1627 | newname[0] = '!';
|
---|
1628 | newname[1] = '\0';
|
---|
1629 | strcat(newname, flnm);
|
---|
1630 | fits_create_file(&fptr_,newname,&status);
|
---|
1631 | delete [] newname;
|
---|
1632 | if (status)
|
---|
1633 | {
|
---|
1634 | cout << " error opening file: " << flnm << endl;
|
---|
1635 | printerror(status, "unable to open file, supposed to exist");
|
---|
1636 | }
|
---|
1637 | else cout << " WARNING : file " << flnm << " is overwritten " << endl;
|
---|
1638 | break;
|
---|
1639 | }
|
---|
1640 | case unknown :
|
---|
1641 | printerror(status, " file seems already to exist");
|
---|
1642 | break;
|
---|
1643 |
|
---|
1644 | }
|
---|
1645 | }
|
---|
1646 | }
|
---|
1647 |
|
---|
1648 |
|
---|
1649 |
|
---|
1650 | /*! \fn void SOPHYA::FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList &dvl)
|
---|
1651 |
|
---|
1652 | create an IMAGE header on FITS file.
|
---|
1653 | \param <type> type of data (see method ColTypeFromFits)
|
---|
1654 | \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS
|
---|
1655 | \param <naxisn> array containind sizes of the different dimensions
|
---|
1656 | */
|
---|
1657 | void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* ptr_dvl)
|
---|
1658 | {
|
---|
1659 | int status = 0;
|
---|
1660 | long naxis = nbdim;
|
---|
1661 | long* naxes = new long[nbdim];
|
---|
1662 | bool hdunfirst= (hdunum_ == 0);
|
---|
1663 | if (hdunfirst)
|
---|
1664 | {
|
---|
1665 | if (imageOnPrimary_ == false)
|
---|
1666 | {
|
---|
1667 | hdunum_ = 1;
|
---|
1668 | fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
|
---|
1669 | }
|
---|
1670 | }
|
---|
1671 | int k;
|
---|
1672 | for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k];
|
---|
1673 | if (type == 'D')
|
---|
1674 | fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status);
|
---|
1675 | else
|
---|
1676 | if (type == 'E')
|
---|
1677 | fits_create_img(fptr_,FLOAT_IMG,naxis,naxes,&status);
|
---|
1678 | else
|
---|
1679 | if (type == 'I')
|
---|
1680 | fits_create_img(fptr_,LONG_IMG,naxis,naxes,&status);
|
---|
1681 | else
|
---|
1682 | {
|
---|
1683 | cout << " type of data: " << type << endl;
|
---|
1684 | throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
|
---|
1685 | }
|
---|
1686 |
|
---|
1687 | // on ajoute eventuellement un dvlist prepare et la doc SOPHYA
|
---|
1688 | hdunum_++;
|
---|
1689 | if (hdunfirst)
|
---|
1690 | {
|
---|
1691 | addDVListOnPrimary();
|
---|
1692 | writeSignatureOnFits(1);
|
---|
1693 | }
|
---|
1694 |
|
---|
1695 | // header format FITS
|
---|
1696 |
|
---|
1697 | writeAppendedHeaderOnFits();
|
---|
1698 |
|
---|
1699 | // write supplementary keywords (from SOPHYA)
|
---|
1700 | // dvl.Print();
|
---|
1701 | if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl);
|
---|
1702 |
|
---|
1703 | delete [] naxes;
|
---|
1704 | if( status ) printerror( status, "erreur creation HDU IMAGE" );
|
---|
1705 |
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 |
|
---|
1709 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, double* map) const
|
---|
1710 |
|
---|
1711 | write double data from array 'map'on an IMAGE extension
|
---|
1712 | \param <nbData> number of data to be written
|
---|
1713 | */
|
---|
1714 | void FitsOutFile::PutImageToFits(int nbData, r_8* map) const
|
---|
1715 | {
|
---|
1716 | int status = 0;
|
---|
1717 | long npix= nbData;
|
---|
1718 | fits_write_img(fptr_,TDOUBLE,1,npix,map,&status);
|
---|
1719 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
1720 | }
|
---|
1721 |
|
---|
1722 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, float* map) const
|
---|
1723 |
|
---|
1724 | same as previous method with float data
|
---|
1725 | */
|
---|
1726 | void FitsOutFile::PutImageToFits(int nbData, r_4* map) const
|
---|
1727 | {
|
---|
1728 | int status = 0;
|
---|
1729 | long npix= nbData;
|
---|
1730 | fits_write_img(fptr_,TFLOAT,1,npix, map,&status);
|
---|
1731 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
1732 |
|
---|
1733 | }
|
---|
1734 |
|
---|
1735 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits( int nbData, int* map) const
|
---|
1736 |
|
---|
1737 | same as previous method with int data */
|
---|
1738 | void FitsOutFile::PutImageToFits( int nbData, int_4* map) const
|
---|
1739 | {
|
---|
1740 | int status = 0;
|
---|
1741 |
|
---|
1742 | long npix= nbData;
|
---|
1743 | fits_write_img(fptr_,TINT,1,npix,map,&status);
|
---|
1744 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
1745 | }
|
---|
1746 |
|
---|
1747 |
|
---|
1748 |
|
---|
1749 | /*! \fn void SOPHYA::FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
|
---|
1750 |
|
---|
1751 | create an BINTABLE header on FITS file.
|
---|
1752 | \param <fieldType> array conta
|
---|
1753 | ining characters denoting types of the different column (see method ColTypeFromFits)
|
---|
1754 | \param <Noms> array of the names of columns
|
---|
1755 | \param <nentries> number of data of each column
|
---|
1756 | \param <tfields> number of columns
|
---|
1757 | \param <dvl> a SOPHYA DVList containing keywords to be appended
|
---|
1758 | \param <extname> keyword EXTNAME for FITS file
|
---|
1759 | \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType'
|
---|
1760 | */
|
---|
1761 | void FitsOutFile::makeHeaderBntblOnFits(string fieldType, vector<string> Noms, int nentries, int tfields, DVList* ptr_dvl, string extname, vector<int> taille_des_chaines)
|
---|
1762 | {
|
---|
1763 | int k;
|
---|
1764 | int status = 0;
|
---|
1765 | long nrows;
|
---|
1766 | // verifications de coherences
|
---|
1767 |
|
---|
1768 | if (fieldType.length() != tfields)
|
---|
1769 | {
|
---|
1770 | cout << " nombre de champs :" << tfields << "nombre de types: " << fieldType.length() << endl;
|
---|
1771 | throw ParmError("FitsFile:: fields and types don't match");
|
---|
1772 |
|
---|
1773 | }
|
---|
1774 | if (tfields > Noms.size())
|
---|
1775 | {
|
---|
1776 | cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of column names not equal to total number of columns" << endl;
|
---|
1777 | for (k=0; k<(tfields-Noms.size()); k++) Noms.push_back( string(" "));
|
---|
1778 | }
|
---|
1779 |
|
---|
1780 | // nombre de variables "chaines de caracteres"
|
---|
1781 | int nbString = 0;
|
---|
1782 | for (k=0; k<tfields;k++) if (fieldType[k] == 'A') nbString++;
|
---|
1783 | // coherence de la longueur du vecteur des tailles
|
---|
1784 | if (nbString > taille_des_chaines.size())
|
---|
1785 | {
|
---|
1786 | cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of string lengths not equal to total number of columns" << endl;
|
---|
1787 | int strSz=0;
|
---|
1788 | for (k=0; k<taille_des_chaines.size(); k++) if ( taille_des_chaines[k] > strSz) strSz = taille_des_chaines[k];
|
---|
1789 | for (k=0; k<(nbString-taille_des_chaines.size()); k++) taille_des_chaines.push_back(strSz);
|
---|
1790 | }
|
---|
1791 | char ** ttype= new char*[tfields];
|
---|
1792 | char ** tform= new char*[tfields];
|
---|
1793 | char largeur[FLEN_VALUE];
|
---|
1794 | int noColString=0;
|
---|
1795 | for (k=0; k<tfields;k++)
|
---|
1796 | {
|
---|
1797 | char format[FLEN_VALUE];
|
---|
1798 |
|
---|
1799 | if(nentries < 1024)
|
---|
1800 | {
|
---|
1801 | nrows= nentries;
|
---|
1802 | if (fieldType[k] == 'A')
|
---|
1803 | {
|
---|
1804 | sprintf(largeur,"%d",taille_des_chaines[noColString++]);
|
---|
1805 | strcpy(format,largeur);
|
---|
1806 | }
|
---|
1807 | else strcpy(format,"1");
|
---|
1808 | }
|
---|
1809 | else
|
---|
1810 | {
|
---|
1811 | nrows = nentries/1024;
|
---|
1812 | if(nentries%1024 != 0) nrows++;
|
---|
1813 | if (fieldType[k] == 'A')
|
---|
1814 | {
|
---|
1815 | char largaux[FLEN_VALUE];
|
---|
1816 | sprintf(largeur,"%d",taille_des_chaines[noColString]);
|
---|
1817 | sprintf(largaux,"%d",1024*taille_des_chaines[noColString]);
|
---|
1818 | noColString++;
|
---|
1819 | strcpy(format, largaux);
|
---|
1820 | }
|
---|
1821 | else strcpy(format,"1024");
|
---|
1822 | }
|
---|
1823 | strncat(format,&fieldType[k],1);
|
---|
1824 | if (fieldType[k] == 'A')
|
---|
1825 | {
|
---|
1826 | strcat(format,largeur);
|
---|
1827 | }
|
---|
1828 | ttype[k] = const_cast<char*>(Noms[k].c_str());
|
---|
1829 | tform[k]= new char[FLEN_VALUE];
|
---|
1830 | strcpy(tform[k],format);
|
---|
1831 | }
|
---|
1832 | char* extn = const_cast<char*>(extname.c_str());
|
---|
1833 |
|
---|
1834 | // create a new empty binary table onto the FITS file
|
---|
1835 | // physical units if they exist, are defined in the DVList object
|
---|
1836 | // so the NULL pointer is given for the tunit parameters.
|
---|
1837 | nrows=0;
|
---|
1838 | fits_create_tbl(fptr_,BINARY_TBL,nrows,tfields,ttype,tform,
|
---|
1839 | NULL,extn,&status);
|
---|
1840 | if( status ) printerror( status );
|
---|
1841 |
|
---|
1842 | int ii;
|
---|
1843 | for(ii = 0; ii < tfields; ii++)
|
---|
1844 | {
|
---|
1845 | delete [] tform[ii];
|
---|
1846 | }
|
---|
1847 | delete [] ttype;
|
---|
1848 | delete [] tform;
|
---|
1849 |
|
---|
1850 | // on ajoute eventuellement des mots-cles
|
---|
1851 |
|
---|
1852 | if ( hdunum_ == 0 )
|
---|
1853 | {
|
---|
1854 | hdunum_ = 2;
|
---|
1855 | addDVListOnPrimary();
|
---|
1856 | writeSignatureOnFits(1);
|
---|
1857 | }
|
---|
1858 | else hdunum_++;
|
---|
1859 |
|
---|
1860 | // header format FITS
|
---|
1861 |
|
---|
1862 | writeAppendedHeaderOnFits();
|
---|
1863 |
|
---|
1864 | // write SOPHYA keywords
|
---|
1865 | if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl);
|
---|
1866 | }
|
---|
1867 |
|
---|
1868 |
|
---|
1869 |
|
---|
1870 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
|
---|
1871 |
|
---|
1872 | write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension.
|
---|
1873 | \param <nentries> number of data to be written
|
---|
1874 | */
|
---|
1875 |
|
---|
1876 | void FitsOutFile::PutColToFits(int nocol, int nentries, r_8* donnees) const
|
---|
1877 | {
|
---|
1878 | int status = 0;
|
---|
1879 | int hdutype;
|
---|
1880 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
1881 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
1882 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
1883 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
1884 | {
|
---|
1885 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
1886 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
1887 | }
|
---|
1888 | int code;
|
---|
1889 | long repeat, width;
|
---|
1890 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
1891 | if( code != TDOUBLE)
|
---|
1892 | {
|
---|
1893 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " to be written= DOUBLE " << endl;
|
---|
1894 | }
|
---|
1895 | // cout << " 10 elements de colonne " << endl;
|
---|
1896 | // for (int toto=0; toto < 10; toto++) cout << donnees[toto] << endl;
|
---|
1897 | fits_write_col(fptr_,TDOUBLE,nocol+1,1,1,nentries, donnees ,&status);
|
---|
1898 | if( status ) printerror( status,"erreur ecriture col. double, dans fichier fits" );
|
---|
1899 | }
|
---|
1900 |
|
---|
1901 |
|
---|
1902 |
|
---|
1903 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
|
---|
1904 |
|
---|
1905 | same as previous method with float data
|
---|
1906 | */
|
---|
1907 | void FitsOutFile::PutColToFits(int nocol, int nentries, r_4* donnees) const
|
---|
1908 | {
|
---|
1909 | int status = 0;
|
---|
1910 | int hdutype;
|
---|
1911 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
1912 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
1913 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
1914 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
1915 | {
|
---|
1916 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
1917 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
1918 | }
|
---|
1919 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
1920 | {
|
---|
1921 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
1922 | }
|
---|
1923 | int code;
|
---|
1924 | long repeat, width;
|
---|
1925 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
1926 | if( code != TFLOAT)
|
---|
1927 | {
|
---|
1928 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl;
|
---|
1929 | }
|
---|
1930 | fits_write_col(fptr_,TFLOAT,nocol+1,1,1,nentries, donnees ,&status);
|
---|
1931 | if( status ) printerror( status,"erreur ecriture col. floats, dans fichier fits" );
|
---|
1932 | }
|
---|
1933 |
|
---|
1934 |
|
---|
1935 | /*! \fn void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
|
---|
1936 |
|
---|
1937 | same as previous method with int data
|
---|
1938 | */
|
---|
1939 | void FitsOutFile::PutColToFits(int nocol, int nentries, int_4* donnees) const
|
---|
1940 | {
|
---|
1941 | int status = 0;
|
---|
1942 | int hdutype;
|
---|
1943 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
1944 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
1945 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
1946 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
1947 | {
|
---|
1948 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
1949 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
1950 | }
|
---|
1951 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
1952 | {
|
---|
1953 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
1954 | }
|
---|
1955 | int code;
|
---|
1956 | long repeat, width;
|
---|
1957 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
1958 |
|
---|
1959 |
|
---|
1960 |
|
---|
1961 | if (code == TINT || code == TLONG)
|
---|
1962 | {
|
---|
1963 | // cfitsio n'a que des entiers de longueur inferieure a 32 bits.
|
---|
1964 | // ici, a l'ecriture TLONG impliquerait que le tableau de donnees
|
---|
1965 | // soit un tableau int_8. Donc c'est toujours TINT qu;il faut mettre
|
---|
1966 | // De plus, j'ai l'impression que TINT va devenir obsolete dans cfitsio
|
---|
1967 | // (GLM)
|
---|
1968 | fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status);
|
---|
1969 | }
|
---|
1970 | else
|
---|
1971 | {
|
---|
1972 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= integers " << endl;
|
---|
1973 | }
|
---|
1974 | if( status ) printerror( status,"erreur ecriture col. entiers, dans fichier fits" );
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 |
|
---|
1978 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
|
---|
1979 | same as previous method with char* data
|
---|
1980 | */
|
---|
1981 | void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
|
---|
1982 | {
|
---|
1983 | int status = 0;
|
---|
1984 | int hdutype;
|
---|
1985 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
1986 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
1987 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
1988 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
1989 | {
|
---|
1990 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
1991 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
1992 | }
|
---|
1993 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
1994 | {
|
---|
1995 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
1996 | }
|
---|
1997 | int code;
|
---|
1998 | long repeat, width;
|
---|
1999 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
2000 | if( code != TSTRING)
|
---|
2001 | {
|
---|
2002 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= char** " << endl;
|
---|
2003 | }
|
---|
2004 | fits_write_col(fptr_,TSTRING,nocol+1,1,1,nentries, donnees ,&status);
|
---|
2005 | if( status ) printerror( status,"erreur ecriture col. chars, dans fichier fits" );
|
---|
2006 | }
|
---|
2007 |
|
---|
2008 | void FitsOutFile::PutBinTabLine(long NoLine, BnTblLine& ligne) const
|
---|
2009 | {
|
---|
2010 | // on ne fait pas de verification de type, ni de dimension ici, pour
|
---|
2011 | // des raisons de performances
|
---|
2012 | int k;
|
---|
2013 | int status= 0;
|
---|
2014 | int anynul;
|
---|
2015 | int ncol=0;
|
---|
2016 | long nels=1;
|
---|
2017 | // int nbcols;
|
---|
2018 | // fits_get_num_cols(fptr_, &nbcols,&status);
|
---|
2019 | for (k=0; k<ligne.ddata_.size(); k++, ncol++)
|
---|
2020 | {
|
---|
2021 | fits_write_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1, &ligne.ddata_[k] ,&status);
|
---|
2022 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture double" );
|
---|
2023 | }
|
---|
2024 | for (k=0; k<ligne.fdata_.size(); k++, ncol++)
|
---|
2025 | {
|
---|
2026 | fits_write_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1, &ligne.fdata_[k] ,&status);
|
---|
2027 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture float" );
|
---|
2028 | }
|
---|
2029 | for (k=0; k<ligne.idata_.size(); k++, ncol++)
|
---|
2030 | {
|
---|
2031 | fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &ligne.idata_[k] ,&status);
|
---|
2032 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture entier" );
|
---|
2033 | }
|
---|
2034 | for (k=0; k<ligne.ldata_.size(); k++, ncol++)
|
---|
2035 | {
|
---|
2036 | fits_write_col(fptr_,TLONG,ncol+1,NoLine+1,1,1, &ligne.ldata_[k] ,&status);
|
---|
2037 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture entier long" );
|
---|
2038 | }
|
---|
2039 | for (k=0; k<ligne.bdata_.size(); k++, ncol++)
|
---|
2040 | {
|
---|
2041 | fits_write_col(fptr_,TBYTE,ncol+1,NoLine+1,1,1, &ligne.bdata_[k] ,&status);
|
---|
2042 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture byte" );
|
---|
2043 | }
|
---|
2044 |
|
---|
2045 | for (k=0; k<ligne.cdata_.size(); k++, ncol++)
|
---|
2046 | {
|
---|
2047 | fits_write_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1, (void*)ligne.cdata_[k].c_str() ,&status);
|
---|
2048 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture caracteres" );
|
---|
2049 | }
|
---|
2050 | }
|
---|
2051 |
|
---|
2052 |
|
---|
2053 | /* \fn void SOPHYA::FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
|
---|
2054 |
|
---|
2055 | Put keywords from a DVList into the primary header of the fits-file
|
---|
2056 | */
|
---|
2057 | void FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl)
|
---|
2058 | {
|
---|
2059 | int status = 0;
|
---|
2060 | int hdutype;
|
---|
2061 | if (hdunum_ == 0)
|
---|
2062 | {
|
---|
2063 | if (dvlToPrimary_ == NULL) dvlToPrimary_ = new DVList(dvl);
|
---|
2064 | else dvlToPrimary_->Merge(dvl);
|
---|
2065 | }
|
---|
2066 | else
|
---|
2067 | {
|
---|
2068 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
2069 | addKeywordsOfDVList(dvl);
|
---|
2070 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
2071 | }
|
---|
2072 | }
|
---|
2073 |
|
---|
2074 |
|
---|
2075 | void FitsOutFile::writeSignatureOnFits(int hdunum) const
|
---|
2076 | {
|
---|
2077 | int status = 0;
|
---|
2078 | int hdutype;
|
---|
2079 | char keyname[LEN_KEYWORD];
|
---|
2080 | char strval[FLEN_VALUE];
|
---|
2081 | char comment[FLEN_COMMENT];
|
---|
2082 | if (hdunum_ == 0)
|
---|
2083 | {
|
---|
2084 | cerr << " WARNING : can't write keywords on non existing primary header" << endl;
|
---|
2085 | return;
|
---|
2086 | }
|
---|
2087 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
2088 | //
|
---|
2089 | strncpy(keyname, "CREATOR", LEN_KEYWORD);
|
---|
2090 | keyname[7] = '\0';
|
---|
2091 | strcpy(strval, "SOPHYA");
|
---|
2092 | strcpy(comment," SOPHYA Package - FITSIOServer ");
|
---|
2093 | fits_write_key(fptr_, TSTRING, keyname, &strval, comment, &status);
|
---|
2094 | if( status ) printerror( status );
|
---|
2095 | fits_write_date(fptr_, &status);
|
---|
2096 | fits_write_comment(fptr_,"..............................................", &status);
|
---|
2097 | fits_write_comment(fptr_, " SOPHYA package - FITSIOSever ", &status);
|
---|
2098 | fits_write_comment(fptr_, " (C) LAL/IN2P3-CNRS Orsay, FRANCE 2000", &status);
|
---|
2099 | fits_write_comment(fptr_, " (C) DAPNIA/CEA Saclay, FRANCE 2000", &status);
|
---|
2100 | fits_write_comment(fptr_,"..............................................", &status);
|
---|
2101 | if( status ) printerror( status, "erreur writeSignatureOnFits" );
|
---|
2102 | //
|
---|
2103 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
2104 | }
|
---|
2105 |
|
---|
2106 |
|
---|
2107 | void FitsOutFile::addKeywordsOfDVList( DVList& dvl) const
|
---|
2108 | {
|
---|
2109 | int status = 0;
|
---|
2110 | fits_write_comment(fptr_,"---------- keywords from SOPHYA ---------", &status);
|
---|
2111 | DVList::ValList::const_iterator it;
|
---|
2112 | for(it = dvl.Begin(); it != dvl.End(); it++)
|
---|
2113 | {
|
---|
2114 | MuTyV::MTVType keytype= (*it).second.elval.Type();
|
---|
2115 | char keyname[LEN_KEYWORD];
|
---|
2116 | strncpy(keyname,(*it).first.substr(0,64).c_str(),LEN_KEYWORD);
|
---|
2117 | int bout = ((*it).first.substr(0,64).length() < LEN_KEYWORD) ? (*it).first.substr(0,64).length() : LEN_KEYWORD-1;
|
---|
2118 | keyname[bout] = '\0';
|
---|
2119 | string key((*it).first.substr(0,64));
|
---|
2120 | // string key(keyname);
|
---|
2121 | char comment[FLEN_COMMENT];
|
---|
2122 | char strval[FLEN_VALUE]= "";
|
---|
2123 | char *comkey = "COMMENT";
|
---|
2124 | // fits_read_keyword(fptr_, keyname, strval, NULL, &status);
|
---|
2125 | // if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 )
|
---|
2126 | {
|
---|
2127 | string coco = dvl.GetComment(key);
|
---|
2128 | coco.copy( comment, FLEN_COMMENT-1);
|
---|
2129 | int bout = (coco.length() < FLEN_COMMENT) ? coco.length() : FLEN_COMMENT-1;
|
---|
2130 | comment[bout]= '\0';
|
---|
2131 | status = 0;
|
---|
2132 | switch (keytype)
|
---|
2133 | {
|
---|
2134 | case MuTyV::MTVInteger :
|
---|
2135 | {
|
---|
2136 | int ival = (int)dvl.GetI(key);
|
---|
2137 | fits_write_key(fptr_,TINT,keyname,&ival, comment,&status);
|
---|
2138 | break;
|
---|
2139 | }
|
---|
2140 | case MuTyV::MTVFloat :
|
---|
2141 | {
|
---|
2142 | double dval= (double)dvl.GetD(key);
|
---|
2143 | fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status);
|
---|
2144 | break;
|
---|
2145 | }
|
---|
2146 | case MuTyV::MTVString :
|
---|
2147 | {
|
---|
2148 | char strvaleur[FLEN_VALUE]= "";
|
---|
2149 | string valChaine = dvl.GetS(key);
|
---|
2150 | valChaine.copy(strvaleur, FLEN_VALUE-1);
|
---|
2151 | int fin = (valChaine.length() < FLEN_VALUE) ? valChaine.length() : FLEN_VALUE-1;
|
---|
2152 | strvaleur[fin]= '\0';
|
---|
2153 |
|
---|
2154 | fits_write_key(fptr_,TSTRING,keyname,&strvaleur,comment,&status);
|
---|
2155 | break;
|
---|
2156 | }
|
---|
2157 | }
|
---|
2158 | }
|
---|
2159 | if( status ) printerror( status,"fitsfile: probleme ecriture mot-cle du dvlist" );
|
---|
2160 | }
|
---|
2161 | fits_write_comment(fptr_,"--------------------------------------", &status);
|
---|
2162 | }
|
---|
2163 |
|
---|
2164 |
|
---|
2165 | void FitsOutFile::addDVListOnPrimary()
|
---|
2166 | {
|
---|
2167 | int status = 0;
|
---|
2168 | int hdutype;
|
---|
2169 | if (hdunum_ == 0)
|
---|
2170 | {
|
---|
2171 | cerr << " WARNING : can't write keywords on non existing primary header" << endl;
|
---|
2172 | return;
|
---|
2173 | }
|
---|
2174 | if (dvlToPrimary_ != NULL)
|
---|
2175 | {
|
---|
2176 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
2177 | addKeywordsOfDVList(*dvlToPrimary_);
|
---|
2178 | delete dvlToPrimary_;
|
---|
2179 | dvlToPrimary_ = NULL;
|
---|
2180 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
2181 | }
|
---|
2182 | }
|
---|
2183 |
|
---|
2184 |
|
---|
2185 | /*! \fn void FitsOutFile::appendInHeader(FitsInFile& infits, int hdunum)
|
---|
2186 |
|
---|
2187 | get a header from FitsInFile and append to the header beeing built
|
---|
2188 | (shifting mandatory keywords)
|
---|
2189 | */
|
---|
2190 |
|
---|
2191 | void FitsOutFile::appendInputHeader(FitsInFile& infits, int hdunum)
|
---|
2192 | {
|
---|
2193 |
|
---|
2194 | infits.GetKeywordsFromHeader(hdunum, mots_cles_);
|
---|
2195 | /*
|
---|
2196 | int status = 0;
|
---|
2197 | int hdutype;
|
---|
2198 | fitsfile* fptr=infits.fitsfilePtr();
|
---|
2199 | fits_movabs_hdu(fptr,hdunum,&hdutype,&status);
|
---|
2200 | if( status ) fits_report_error(stderr,status);
|
---|
2201 |
|
---|
2202 | // get number of keywords
|
---|
2203 | int nkeys,keypos;
|
---|
2204 | fits_get_hdrpos(fptr,&nkeys,&keypos,&status);
|
---|
2205 | if( status ) fits_report_error(stderr,status);
|
---|
2206 | // shift with the number of mandatory keywords
|
---|
2207 | int num= 0;
|
---|
2208 | // if primary header
|
---|
2209 | if (hdunum == 1)
|
---|
2210 | {
|
---|
2211 | // read NAXIS
|
---|
2212 | int naxis=0;
|
---|
2213 | fits_read_key(fptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
2214 | // number of mandatory keywords
|
---|
2215 | num = naxis+3;
|
---|
2216 | }
|
---|
2217 | // extensions
|
---|
2218 | else
|
---|
2219 | {
|
---|
2220 | if (hdutype == IMAGE_HDU)
|
---|
2221 | {
|
---|
2222 | // read NAXIS
|
---|
2223 | int naxis=0;
|
---|
2224 | fits_read_key(fptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
2225 | // number of mandatory keywords
|
---|
2226 | num = naxis+5;
|
---|
2227 | }
|
---|
2228 | else
|
---|
2229 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
2230 | {
|
---|
2231 | // number of mandatory keywords
|
---|
2232 | num = 8;
|
---|
2233 | }
|
---|
2234 | }
|
---|
2235 | int j;
|
---|
2236 | char keyname[LEN_KEYWORD];
|
---|
2237 | char value[FLEN_VALUE];
|
---|
2238 | char comment[FLEN_COMMENT];
|
---|
2239 | for(j = num+1; j <= nkeys; j++)
|
---|
2240 | {
|
---|
2241 | char dtype;
|
---|
2242 | fits_read_keyn(fptr,j,keyname,value,comment,&status);
|
---|
2243 | if(status)
|
---|
2244 | {
|
---|
2245 | fits_report_error(stderr,status);
|
---|
2246 | status=0;
|
---|
2247 | }
|
---|
2248 | string kn(keyname);
|
---|
2249 | string cm(comment);
|
---|
2250 | string val(value);
|
---|
2251 | FitsKeyword kw(kn, val, cm);
|
---|
2252 | mots_cles_.push_back(kw);
|
---|
2253 | }
|
---|
2254 | */
|
---|
2255 | }
|
---|
2256 | void FitsOutFile::writeAppendedHeaderOnFits()
|
---|
2257 | {
|
---|
2258 | for (list<FitsKeyword>::iterator it=mots_cles_.begin(); it !=mots_cles_.end(); it++)
|
---|
2259 | {
|
---|
2260 | (*it).writeOnFits(fptr_);
|
---|
2261 | }
|
---|
2262 | mots_cles_.clear();
|
---|
2263 | }
|
---|
2264 |
|
---|
2265 | void FitsOutFile::insertKeywordOnHeader(string keyname, double value, string comment)
|
---|
2266 | {
|
---|
2267 | char cvalue[16];
|
---|
2268 | sprintf(cvalue,"%e",value);
|
---|
2269 | FitsKeyword kw(keyname, string(cvalue), comment, 'F');
|
---|
2270 | mots_cles_.push_back(kw);
|
---|
2271 | }
|
---|
2272 | void FitsOutFile::insertKeywordOnHeader(string keyname, int value, string comment)
|
---|
2273 | {
|
---|
2274 | char cvalue[16];
|
---|
2275 | sprintf(cvalue,"%d",value);
|
---|
2276 | FitsKeyword kw(keyname, string(cvalue), comment, 'I');
|
---|
2277 | mots_cles_.push_back(kw);
|
---|
2278 | }
|
---|
2279 | void FitsOutFile::insertKeywordOnHeader(string keyname, string value, string comment)
|
---|
2280 | {
|
---|
2281 | FitsKeyword kw(keyname, value , comment, 'C');
|
---|
2282 | mots_cles_.push_back(kw);
|
---|
2283 | }
|
---|
2284 |
|
---|
2285 | void FitsOutFile::insertCommentLineOnHeader(string comment)
|
---|
2286 | {
|
---|
2287 | FitsKeyword kw(comment);
|
---|
2288 | mots_cles_.push_back(kw);
|
---|
2289 | }
|
---|
2290 |
|
---|
2291 | void FitsOutFile::PrintHeaderToBeAppended()
|
---|
2292 | {
|
---|
2293 | cout << " contenu du header en cours de fabrication " << endl;
|
---|
2294 | for (list<FitsKeyword>::iterator it=mots_cles_.begin(); it !=mots_cles_.end(); it++)
|
---|
2295 | {
|
---|
2296 | (*it).Print();
|
---|
2297 | }
|
---|
2298 | }
|
---|
2299 |
|
---|
2300 |
|
---|
2301 | FitsKeyword::FitsKeyword()
|
---|
2302 | {
|
---|
2303 | datatype_=' ';
|
---|
2304 | keyname_ = string("");
|
---|
2305 | dvalue_=0.;
|
---|
2306 | ivalue_=1;
|
---|
2307 | svalue_=string("");
|
---|
2308 | comment_=string("");
|
---|
2309 | }
|
---|
2310 |
|
---|
2311 | FitsKeyword::FitsKeyword(string comment)
|
---|
2312 | {
|
---|
2313 | datatype_=' ';
|
---|
2314 | keyname_=string("COMMENT");
|
---|
2315 | comment_=comment;
|
---|
2316 | }
|
---|
2317 |
|
---|
2318 | FitsKeyword::FitsKeyword(string keyname, string value, string comment) : keyname_(keyname), comment_(comment)
|
---|
2319 | {
|
---|
2320 | int status=0;
|
---|
2321 | char dtype;
|
---|
2322 | const char* val= value.c_str();
|
---|
2323 | char* valk = const_cast<char*>(val);
|
---|
2324 | fits_get_keytype(valk,&dtype,&status);
|
---|
2325 | if(status)
|
---|
2326 | {
|
---|
2327 | status=0;
|
---|
2328 | if (status == VALUE_UNDEFINED) cout << "WARNING (FitsKeyword) : undefined keyword value " << endl;
|
---|
2329 | datatype_=' ';
|
---|
2330 | }
|
---|
2331 | else datatype_=dtype;
|
---|
2332 |
|
---|
2333 | switch( datatype_ )
|
---|
2334 | {
|
---|
2335 | case 'C':
|
---|
2336 | {
|
---|
2337 | strip(valk, 'B','\'');
|
---|
2338 | svalue_ = string(valk);
|
---|
2339 | break;
|
---|
2340 | }
|
---|
2341 | case 'I':
|
---|
2342 | {
|
---|
2343 | ivalue_ = atoi(val);
|
---|
2344 | break;
|
---|
2345 | }
|
---|
2346 | case 'L':
|
---|
2347 | {
|
---|
2348 | bool bb = value.c_str();
|
---|
2349 | ivalue_ = (int)bb;
|
---|
2350 | break;
|
---|
2351 | }
|
---|
2352 | case 'F':
|
---|
2353 | {
|
---|
2354 | dvalue_ = atof(val);
|
---|
2355 | break;
|
---|
2356 | }
|
---|
2357 | case 'X':
|
---|
2358 | {
|
---|
2359 | throw IOExc("FitsKeyword , complex keyword value not supported");
|
---|
2360 | }
|
---|
2361 | }
|
---|
2362 | }
|
---|
2363 |
|
---|
2364 | // constructeur pour les mots-cles maison (ne prvenant pas de la lecture d'un fichier fits)
|
---|
2365 | FitsKeyword::FitsKeyword(string keyname, string value, string comment, char type) : keyname_(keyname), comment_(comment), datatype_(type)
|
---|
2366 | {
|
---|
2367 | char dtype;
|
---|
2368 | const char* val= value.c_str();
|
---|
2369 | char* valk = const_cast<char*>(val);
|
---|
2370 | switch( datatype_ )
|
---|
2371 | {
|
---|
2372 | case 'C':
|
---|
2373 | {
|
---|
2374 | strip(valk, 'B','\'');
|
---|
2375 | svalue_ = string(valk);
|
---|
2376 | break;
|
---|
2377 | }
|
---|
2378 | case 'I':
|
---|
2379 | {
|
---|
2380 | ivalue_ = atoi(val);
|
---|
2381 | break;
|
---|
2382 | }
|
---|
2383 | case 'L':
|
---|
2384 | {
|
---|
2385 | bool bb = value.c_str();
|
---|
2386 | ivalue_ = (int)bb;
|
---|
2387 | break;
|
---|
2388 | }
|
---|
2389 | case 'F':
|
---|
2390 | {
|
---|
2391 | dvalue_ = atof(val);
|
---|
2392 | break;
|
---|
2393 | }
|
---|
2394 | case 'X':
|
---|
2395 | {
|
---|
2396 | throw IOExc("FitsKeyword , complex keyword value not supported");
|
---|
2397 | }
|
---|
2398 | }
|
---|
2399 | }
|
---|
2400 |
|
---|
2401 | void FitsKeyword::writeOnFits(fitsfile* ptr)
|
---|
2402 | {
|
---|
2403 | int status=0;
|
---|
2404 | char keyname[LEN_KEYWORD];
|
---|
2405 | char comment[FLEN_COMMENT];
|
---|
2406 | keyname_.copy(keyname, LEN_KEYWORD);
|
---|
2407 | int bout = (keyname_.length() < LEN_KEYWORD) ? keyname_.length() : LEN_KEYWORD-1;
|
---|
2408 | keyname[bout] = '\0';
|
---|
2409 | comment_.copy( comment, FLEN_COMMENT);
|
---|
2410 | bout = (comment_.length() < FLEN_COMMENT) ? comment_.length() : FLEN_COMMENT-1;
|
---|
2411 | comment[bout]= '\0';
|
---|
2412 |
|
---|
2413 | int nkeys,keypos;
|
---|
2414 | fits_get_hdrpos(ptr,&nkeys,&keypos,&status);
|
---|
2415 | switch( datatype_ )
|
---|
2416 | {
|
---|
2417 | case 'C':
|
---|
2418 | {
|
---|
2419 | char value[FLEN_VALUE]="";
|
---|
2420 | svalue_.copy(value, FLEN_VALUE-1);
|
---|
2421 | int fin = (svalue_.length() < FLEN_VALUE) ? svalue_.length() : FLEN_VALUE-1;
|
---|
2422 | value[fin]= '\0';
|
---|
2423 | fits_write_key(ptr,TSTRING,keyname,&value, comment,&status);
|
---|
2424 | fits_report_error(stderr,status);
|
---|
2425 | break;
|
---|
2426 | }
|
---|
2427 | case 'I':
|
---|
2428 | {
|
---|
2429 | fits_write_key(ptr,TINT,keyname,&ivalue_, comment,&status);
|
---|
2430 | fits_report_error(stderr,status);
|
---|
2431 | break;
|
---|
2432 | }
|
---|
2433 | case 'L':
|
---|
2434 | {
|
---|
2435 | fits_write_key(ptr,TLOGICAL,keyname,&ivalue_, comment,&status);
|
---|
2436 | fits_report_error(stderr,status);
|
---|
2437 | break;
|
---|
2438 | }
|
---|
2439 | case 'F':
|
---|
2440 | {
|
---|
2441 | fits_write_key(ptr,TDOUBLE,keyname,&dvalue_, comment,&status);
|
---|
2442 | fits_report_error(stderr,status);
|
---|
2443 | break;
|
---|
2444 | }
|
---|
2445 | case 'X':
|
---|
2446 | {
|
---|
2447 | cout << "FitsKeyword : complex keyword value not supported" << endl;;
|
---|
2448 | break;
|
---|
2449 | }
|
---|
2450 | default :
|
---|
2451 | {
|
---|
2452 | char *comkey = "COMMENT";
|
---|
2453 | if(strncmp(keyname,comkey,LEN_KEYWORD-1) == 0)
|
---|
2454 | {
|
---|
2455 | fits_write_comment(ptr,comment,&status);
|
---|
2456 | fits_report_error(stderr,status);
|
---|
2457 | }
|
---|
2458 | else
|
---|
2459 | {
|
---|
2460 | cout << " WARNING (FitsKeyword::writeOnFits) : unrecognized keyword : " << keyname_ << endl;
|
---|
2461 | }
|
---|
2462 | }
|
---|
2463 | }
|
---|
2464 | }
|
---|
2465 |
|
---|
2466 | void FitsKeyword::Print()
|
---|
2467 | {
|
---|
2468 | switch( datatype_ )
|
---|
2469 | {
|
---|
2470 | case 'C':
|
---|
2471 | {
|
---|
2472 | cout << " mot cle : " << keyname_ << " valeur : " << svalue_ << " commentaire : " << comment_ <<endl;
|
---|
2473 | break;
|
---|
2474 | }
|
---|
2475 | case 'I':
|
---|
2476 | {
|
---|
2477 | cout << " mot cle : " << keyname_ << " valeur : " << ivalue_ << " commentaire : " << comment_ <<endl;
|
---|
2478 | break;
|
---|
2479 | }
|
---|
2480 | case 'L':
|
---|
2481 | {
|
---|
2482 | cout << " mot cle : " << keyname_ << " valeur : " << ivalue_ << " commentaire : " << comment_ <<endl;
|
---|
2483 | break;
|
---|
2484 | }
|
---|
2485 | case 'F':
|
---|
2486 | {
|
---|
2487 | cout << " mot cle : " << keyname_ << " valeur : " << dvalue_ << " commentaire : " << comment_ <<endl;
|
---|
2488 | break;
|
---|
2489 | }
|
---|
2490 | case 'X':
|
---|
2491 | {
|
---|
2492 | cout << "FitsKeyword : complex keyword value not supported" << endl;;
|
---|
2493 | }
|
---|
2494 | default :
|
---|
2495 | {
|
---|
2496 | cout << " mot cle : " << keyname_ << " commentaire : " << comment_ <<endl;
|
---|
2497 | }
|
---|
2498 | }
|
---|
2499 | }
|
---|