source: Sophya/trunk/SophyaExt/FitsIOServer/fitsfile.cc@ 1354

Last change on this file since 1354 was 1354, checked in by lemeur, 25 years ago

methode getStringKeyword

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