Changeset 2860 in Sophya
- Timestamp:
- Dec 20, 2005, 7:25:51 PM (20 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r2615 r2860 6 6 #include "strutil.h" 7 7 #include "anydataobj.h" 8 #include "fitsspherehealpix.h"9 8 10 9 /*! … … 281 280 282 281 283 284 282 FitsFile::FitsFile() 283 : FitsInOutFile() 284 { 285 InitNull(); 286 } 287 288 FitsFile::FitsFile(FitsInOutFile const& fios) 289 : FitsInOutFile(fios) 290 { 291 InitNull(); 292 } 293 294 295 /*RzDel 285 296 FitsFile::~FitsFile() 286 297 { 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 } 298 // Close fait par le destructeur de FitsInOutFile - Reza , Dec 2005 299 // int status = 0; 300 // if( fptr_ != NULL) 301 // fits_close_file(fptr_,&status); 302 // if( status ) printerror( status ); 303 } 304 */ 296 305 297 306 … … 353 362 354 363 FitsInFile::FitsInFile() 364 : FitsFile() 365 355 366 { 356 367 InitNull(); … … 358 369 359 370 FitsInFile::FitsInFile(string const & flnm) 360 { 361 InitNull(); 371 : FitsFile() 372 { 373 InitNull(); 374 Open(flnm.c_str(), Fits_RO); 375 /*RZDEL 362 376 int status = 0; 363 377 fits_open_file(&fptr_,flnm.c_str(),READONLY,&status); 364 378 if( status ) printerror( status ); 379 */ 365 380 } 366 381 367 382 FitsInFile::FitsInFile(const char * flnm) 368 { 369 InitNull(); 370 int status = 0; 383 : FitsFile() 384 { 385 InitNull(); 386 Open(flnm, Fits_RO); 387 /*RZDEL 388 int status = 0; 371 389 fits_open_file(&fptr_,flnm,READONLY,&status); 372 390 if( status ) printerror( status ); 391 */ 392 } 393 394 FitsInFile::FitsInFile(FitsInOutFile const& fios) 395 : FitsFile(fios) 396 397 { 398 InitNull(); 399 if (mode_ == Fits_Create) 400 throw FitsIOException("FitsInFile::FitsInFile(FitsInOutFile const& fios) newly created fits file"); 373 401 } 374 402 … … 1569 1597 1570 1598 FitsOutFile::FitsOutFile() 1599 : FitsFile() 1571 1600 { 1572 1601 InitNull(); … … 1580 1609 1581 1610 FitsOutFile::FitsOutFile(string const & flnm, WriteMode wrm) 1611 : FitsFile() 1582 1612 { 1583 1613 InitNull(); … … 1586 1616 1587 1617 FitsOutFile::FitsOutFile(const char * flnm, WriteMode wrm) 1618 : FitsFile() 1588 1619 { 1589 1620 InitNull(); … … 1591 1622 } 1592 1623 1624 FitsOutFile::FitsOutFile(FitsInOutFile const& fios) 1625 : FitsFile(fios) 1626 { 1627 InitNull(); 1628 if (mode_ == Fits_RO) 1629 throw FitsIOException("FitsOutFile::FitsOutFile(FitsInOutFile const& ) ReadOnly Fits file"); 1630 } 1631 1632 FitsOutFile::~FitsOutFile() 1633 { 1634 if (dvlToPrimary_ != NULL) delete dvlToPrimary_; 1635 } 1636 1593 1637 void FitsOutFile::openoutputfitsfile(const char * flnm, WriteMode wrm) 1594 1638 { … … 1597 1641 // create new FITS file 1598 1642 fits_create_file(&fptr_,flnm,&status); 1599 if( status ) 1600 { 1601 1602 switch (wrm) 1603 { 1643 if( status ) { 1644 switch (wrm) { 1604 1645 // si on veut ecrire a la fin de ce fichier 1605 case append : 1646 case append : 1647 status = 0; 1648 fits_clear_errmsg(); 1649 fits_open_file(&fptr_,flnm,READWRITE,&status); 1650 if( status ) { 1651 cout << " error opening file: " << flnm << endl; 1652 printerror(status, "failure opening a file supposed to exist"); 1653 } 1654 else cout << " file " << flnm << " opened, new objects will be appended " << endl; 1655 fits_get_num_hdus(fptr_, &hdunum_, &status); 1656 int hdutype; 1657 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 1658 if( status ) { 1659 printerror( status,":FitsFile::WriteF : erreur movabs"); 1660 throw FitsIOException("FitsOutFile::openoutputfitsfile()/fits movabs error"); 1661 break; 1662 1663 case clear : 1664 { 1606 1665 status = 0; 1607 1666 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 } 1667 char* newname = new char[strlen(flnm)+2]; 1668 // 1669 newname[0] = '!'; 1670 newname[1] = '\0'; 1671 strcat(newname, flnm); 1672 fits_create_file(&fptr_,newname,&status); 1673 delete [] newname; 1674 if (status) { 1675 cout << " error opening file: " << flnm << endl; 1676 printerror(status, "unable to open file, supposed to exist"); 1677 throw FitsIOException("FitsOutFile::openoutputfitsfile()/fits open Error "); 1678 } 1679 else cout << " WARNING : file " << flnm << " is overwritten " << endl; 1680 break; 1681 } 1682 case unknown : 1683 printerror(status, " file seems already to exist"); 1684 throw FitsIOException("FitsOutFile::openoutputfitsfile()/fits open Error - existing file"); 1685 break; 1686 } 1687 } 1688 } 1689 fname_ = flnm; 1690 if ( wrm == append ) mode_ = Fits_RW; 1691 else mode_ = Fits_Create; 1692 ownfptr = true; 1646 1693 } 1647 1694 -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r2197 r2860 4 4 #include "ndatablock.h" 5 5 #include "dvlist.h" 6 #include " FitsIO/fitsio.h"6 #include "fitsinoutfile.h" 7 7 8 8 #define OPENFILE 0 … … 75 75 76 76 //! Class (virtual) for managing FITS format files 77 class FitsFile {77 class FitsFile : public FitsInOutFile { 78 78 79 79 public: … … 148 148 149 149 150 FitsFile() { InitNull(); }; 151 virtual ~FitsFile(); 150 FitsFile(); 151 FitsFile(FitsInOutFile const& fios); 152 // RzDel virtual ~FitsFile(); 152 153 static string GetErrStatus(int status); 153 154 inline int statusF() const { return fits_status_;} … … 169 170 inline void InitNull() 170 171 { 171 fptr_ = NULL;172 172 hdutype_= FitsExtensionType_NULL; 173 173 hdunum_ = 0; … … 177 177 178 178 179 180 fitsfile *fptr_; /**< pointer to the FITS file, defined in fitsio.h */181 179 FitsExtensionType hdutype_; /**< image or bintable ? */ 182 180 int hdunum_; /**< index of header to be read/written */ … … 197 195 FitsInFile(string const & flnm); 198 196 FitsInFile(const char * flnm); 199 ~FitsInFile() { ; }; 197 FitsInFile(FitsInOutFile const& fios); 198 // virtual ~FitsInFile(); 200 199 201 200 static int NbBlocks(char flnm[]); … … 342 341 FitsOutFile(string const & flnm, WriteMode wrm = unknown ); 343 342 FitsOutFile(const char * flnm, WriteMode wrm = unknown ); 344 ~FitsOutFile() { if (dvlToPrimary_ != NULL) delete dvlToPrimary_;}; 343 FitsOutFile(FitsInOutFile const& fios); 344 virtual ~FitsOutFile(); 345 345 inline void InitNull() {dvlToPrimary_ = NULL;} 346 346 -
trunk/SophyaExt/FitsIOServer/fitsinoutfile.cc
r2844 r2860 111 111 // cout << " DBG - FitsInOutFile(string name= " << name << ")" << endl; 112 112 fptr_ = NULL; 113 ownfptr = true; 113 114 SetDef_BinTable(); 114 115 SetDef_StrColWidth(); … … 122 123 // cout << " DBG - FitsInOutFile(char* name= " << name << ")" << endl; 123 124 fptr_ = NULL; 125 ownfptr = true; 124 126 SetDef_BinTable(); 125 127 SetDef_StrColWidth(); 126 128 Open(name, mode); 129 } 130 131 /*! \brief Copy constructor 132 The fits file pointer is owned by the original object and should not be closed 133 as long as the new object is being used. 134 */ 135 FitsInOutFile::FitsInOutFile(FitsInOutFile const& fios) 136 { 137 fptr_ = fios.fptr_; 138 fname_ = fios.fname_; 139 mode_ = fios.mode_; 140 ownfptr = false; 141 SetDef_BinTable(); 142 SetDef_StrColWidth(); 127 143 } 128 144 … … 177 193 fname_ = name; 178 194 mode_ = mode; 195 ownfptr = true; 179 196 return; 180 197 } … … 184 201 void FitsInOutFile::Close() 185 202 { 203 if (ownfptr == false) return; 186 204 if (fptr_ == NULL) return; 187 205 int status = 0; -
trunk/SophyaExt/FitsIOServer/fitsinoutfile.h
r2843 r2860 82 82 FitsInOutFile(string const & name, FitsIOMode mode); 83 83 FitsInOutFile(const char* name, FitsIOMode mode); 84 FitsInOutFile(FitsInOutFile const& fios); 84 85 virtual ~FitsInOutFile(); 85 86 … … 191 192 string fname_; // File name as passed to creator 192 193 FitsIOMode mode_; 194 bool ownfptr; // If true, owns the FitsPointer, which will be closed by the destructor 193 195 194 196 // Default extension name
Note:
See TracChangeset
for help on using the changeset viewer.