Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 2615)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 2860)
@@ -6,5 +6,4 @@
 #include "strutil.h"
 #include "anydataobj.h" 
-#include "fitsspherehealpix.h"
 
 /*!
@@ -281,17 +280,27 @@
 
 
-
- 
+FitsFile::FitsFile()
+  : FitsInOutFile()
+{
+  InitNull();
+}
+
+FitsFile::FitsFile(FitsInOutFile const& fios)
+  : FitsInOutFile(fios)
+{
+  InitNull();
+}
+
+
+/*RzDel 
 FitsFile::~FitsFile()
 {
-  int status = 0;
-    if( fptr_ != NULL)
-    {
-      fits_close_file(fptr_,&status);
-      // je ne fais pas      delete fptr_, c'est la lib. fitsio qui a fait 
-      // new...
-    }
-   if( status )  printerror( status );
-}
+  //  Close fait par le destructeur de FitsInOutFile - Reza , Dec 2005
+  //  int status = 0;
+  //  if( fptr_ != NULL)
+  //    fits_close_file(fptr_,&status);
+  // if( status )  printerror( status );
+}
+*/
 
 
@@ -353,4 +362,6 @@
 
 FitsInFile::FitsInFile()
+  : FitsFile()
+
 {
   InitNull();
@@ -358,17 +369,34 @@
 
 FitsInFile::FitsInFile(string const & flnm)
-{
-    InitNull();
+  : FitsFile()
+{
+  InitNull();
+  Open(flnm.c_str(), Fits_RO);
+  /*RZDEL
    int status = 0;
    fits_open_file(&fptr_,flnm.c_str(),READONLY,&status);
    if( status ) printerror( status );
+  */
 }
 
 FitsInFile::FitsInFile(const char * flnm)
-{
-    InitNull();
-   int status = 0;
+  : FitsFile()
+{
+  InitNull();
+  Open(flnm, Fits_RO);
+  /*RZDEL
+  int status = 0;
    fits_open_file(&fptr_,flnm,READONLY,&status);
    if( status ) printerror( status );
+  */
+}
+
+FitsInFile::FitsInFile(FitsInOutFile const& fios)
+  : FitsFile(fios)
+
+{
+  InitNull();
+  if (mode_ == Fits_Create)
+    throw FitsIOException("FitsInFile::FitsInFile(FitsInOutFile const& fios) newly created fits file");
 }
 
@@ -1569,4 +1597,5 @@
 
 FitsOutFile::FitsOutFile()
+  : FitsFile()
 {
   InitNull(); 
@@ -1580,4 +1609,5 @@
 
 FitsOutFile::FitsOutFile(string const & flnm, WriteMode wrm)
+  : FitsFile()
 {
   InitNull();
@@ -1586,4 +1616,5 @@
 
 FitsOutFile::FitsOutFile(const char * flnm, WriteMode wrm)
+  : FitsFile()
 {
   InitNull();
@@ -1591,4 +1622,17 @@
 }
 
+FitsOutFile::FitsOutFile(FitsInOutFile const& fios)
+  : FitsFile(fios)
+{
+  InitNull(); 
+  if (mode_ == Fits_RO)
+    throw FitsIOException("FitsOutFile::FitsOutFile(FitsInOutFile const& ) ReadOnly Fits file");
+}
+
+FitsOutFile::~FitsOutFile()
+{
+  if (dvlToPrimary_ != NULL) delete dvlToPrimary_;
+}
+
 void FitsOutFile::openoutputfitsfile(const char * flnm, WriteMode wrm)
 {
@@ -1597,51 +1641,54 @@
   // create new FITS file
   fits_create_file(&fptr_,flnm,&status);
-  if( status )
-    {
-
-      switch (wrm)
-	{
+  if( status )    {
+    switch (wrm) {
       // si on veut ecrire a la fin de ce fichier
-	case append :
+    case append :
+      status = 0;
+      fits_clear_errmsg();
+      fits_open_file(&fptr_,flnm,READWRITE,&status);
+      if( status ) {
+	cout << " error opening file: " << flnm << endl;
+	printerror(status, "failure opening a file supposed to exist");
+      }
+      else cout << " file " << flnm << " opened, new objects will be appended " << endl;
+      fits_get_num_hdus(fptr_, &hdunum_, &status);
+      int hdutype;
+      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
+      if( status ) { 
+	printerror( status,":FitsFile::WriteF : erreur movabs");
+	throw FitsIOException("FitsOutFile::openoutputfitsfile()/fits movabs error");
+	break;
+	
+      case clear :
+	{
 	  status = 0;
 	  fits_clear_errmsg();
-	  fits_open_file(&fptr_,flnm,READWRITE,&status);
-	  if( status )
-	    {
-	      cout << " error opening file: " << flnm << endl;
-	      printerror(status, "failure opening a file supposed to exist");
-	    }
-	  else cout << " file " << flnm << " opened, new objects will be appended " << endl;
-	  fits_get_num_hdus(fptr_, &hdunum_, &status);
-	  int hdutype;
-	  fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
-	  if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
-	  break;
-       
-	case clear :
-	  {
-	    status = 0;
-	    fits_clear_errmsg();
-	    char* newname = new char[strlen(flnm)+2];
-	    //
-	    newname[0] = '!';
-	    newname[1] = '\0';
-	    strcat(newname, flnm);
-	    fits_create_file(&fptr_,newname,&status);
-	    delete [] newname;
-	    if (status)
-	      {
-		cout << " error opening file: " << flnm << endl;
-		printerror(status, "unable to open file, supposed to exist");
-	      }
-	    else  cout << "  WARNING : file " << flnm << " is overwritten " << endl;
-	    break;
-	  }
-	case unknown : 
-	  printerror(status, " file seems already to exist");
-	  break;
-      
-	}
-    }
+	  char* newname = new char[strlen(flnm)+2];
+	  //
+	  newname[0] = '!';
+	  newname[1] = '\0';
+	  strcat(newname, flnm);
+	  fits_create_file(&fptr_,newname,&status);
+	  delete [] newname;
+	  if (status) {
+	    cout << " error opening file: " << flnm << endl;
+	    printerror(status, "unable to open file, supposed to exist");
+	    throw FitsIOException("FitsOutFile::openoutputfitsfile()/fits open Error ");
+	  }
+	  else  cout << "  WARNING : file " << flnm << " is overwritten " << endl;
+	  break;
+	}
+      case unknown : 
+	printerror(status, " file seems already to exist");
+	throw FitsIOException("FitsOutFile::openoutputfitsfile()/fits open Error - existing file");
+	break;
+      }
+    }
+  }
+  fname_ = flnm;
+  if ( wrm == append ) mode_ = Fits_RW;
+  else mode_ = Fits_Create;
+  ownfptr = true;
 }
 
