Index: /trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1352)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1353)
@@ -345,4 +345,32 @@
 }
 
+bool FitsInFile::hasKeyword(string keyw, int hdunum)
+     {
+       bool has=false;
+       int status = 0;
+       if (hdunum != hdunum_ )
+	 {
+	   int hdutype;
+	   fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
+	 }
+
+       char value[FLEN_VALUE];
+       char* keyname= const_cast<char*>(keyw.c_str());
+       fits_read_keyword(fptr_,keyname,value,NULL,&status);
+       if (status == 0)
+	 has = true;
+       else 
+	 if (status == KEY_NO_EXIST ) status =0;
+	 else fits_report_error(stderr,status); 
+       if (hdunum != hdunum_ )
+	 {
+	   int hdutype;
+	   if (hdunum_ != 0)
+	     fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
+	   else 	     fits_movabs_hdu(fptr_,1,&hdutype,&status);
+
+	 }
+       return has;
+     }
 
 void FitsInFile::GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn)
@@ -510,5 +538,5 @@
     else
       {
-	cout << " hdutype= " << (int) hdutype_ << endl;
+	cout << " hdutype= " << hdutype_ << endl;
 	throw PException("FitsFile::NbColsFromFits, HDU  not supported");
       }
@@ -528,5 +556,5 @@
       else
 	{
-	  cout << "hdutype= " << (int) hdutype_ << endl;
+	  cout << "hdutype= " << hdutype_ << endl;
 	  throw PException("FitsFile::NentriesFromFits, this HDU is not supported");
 	}
@@ -712,5 +740,5 @@
 \param <nentries>  number of data to be read
 */
-void FitsInFile::GetBinTabFCol(r_8* valeurs,int nentries, int NoCol) const
+void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
     {
       int status= 0;
@@ -749,5 +777,5 @@
  same as previous method with float data 
 */
-void FitsInFile::GetBinTabFCol(r_4* valeurs,int nentries, int NoCol) const
+void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
     {
       int status= 0;
@@ -786,5 +814,5 @@
 */
 
-void FitsInFile::GetBinTabFCol(int_4* valeurs,int nentries, int NoCol) const
+void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
     {
       int status= 0;
@@ -853,5 +881,5 @@
 \param <nentries>  number of data to be read
 */
-void FitsInFile::GetSingleColumn(r_8* map, int nentries) const
+void FitsInFile::GetSingleColumn(double* map, int nentries) const
 { 
   int status = 0;
@@ -880,5 +908,5 @@
     else
       {
-      cout << " hdutype= " << (int) hdutype_ << endl;
+      cout << " hdutype= " << hdutype_ << endl;
       throw IOExc("FitsFile::GetSingleColumn, this HDU is unknown");
       }
@@ -888,5 +916,5 @@
 same as above with float data 
 */
-void FitsInFile::GetSingleColumn(r_4* map, int nentries) const
+void FitsInFile::GetSingleColumn(float* map, int nentries) const
 {
   int status = 0;
@@ -913,5 +941,5 @@
     else
       {
-      cout << " hdutype= " << (int) hdutype_ << endl;
+      cout << " hdutype= " << hdutype_ << endl;
       throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
       }
@@ -921,5 +949,5 @@
  same as above with int data 
 */
-void FitsInFile::GetSingleColumn( int_4* map, int nentries) const
+void FitsInFile::GetSingleColumn( int* map, int nentries) const
 {
   int status = 0;
@@ -946,5 +974,5 @@
     else
       {
-      cout << " hdutype= " << (int) hdutype_ << endl;
+      cout << " hdutype= " << hdutype_ << endl;
       throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
       }
@@ -1305,4 +1333,5 @@
 	  throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
 	}
+
   // on ajoute eventuellement un dvlist prepare et la doc SOPHYA
   hdunum_++;
@@ -1313,5 +1342,9 @@
     }
 
-  // write supplementary keywords
+  // header format FITS
+   
+   writeAppendedHeaderOnFits();
+
+  // write supplementary keywords (from SOPHYA)
   //  dvl.Print();
   if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl);
@@ -1328,5 +1361,5 @@
 \param <nbData>  number of data to be written
 */
-void FitsOutFile::PutImageToFits(int nbData, r_8* map) const
+void FitsOutFile::PutImageToFits(int nbData, double* map) const
 {
   int status = 0;
@@ -1340,5 +1373,5 @@
 same as previous method with float data 
 */
-void FitsOutFile::PutImageToFits(int nbData, r_4* map) const
+void FitsOutFile::PutImageToFits(int nbData, float* map) const
 {
   int status = 0;
@@ -1352,5 +1385,5 @@
 
  same as previous method with int data */
-void FitsOutFile::PutImageToFits( int nbData, int_4* map) const
+void FitsOutFile::PutImageToFits( int nbData, int* map) const
 {
   int status = 0;
@@ -1455,5 +1488,15 @@
 		  NULL,extn,&status);
   if( status ) printerror( status );
-  // on ajoute eventuellement un dvlist prepare
+
+  int ii;
+  for(ii = 0; ii < tfields; ii++)
+    {
+      delete [] tform[ii];
+    }
+  delete [] ttype;
+  delete [] tform;
+
+  // on ajoute eventuellement des mots-cles
+
   if ( hdunum_ == 0 )
     {
@@ -1463,15 +1506,14 @@
     }
   else  hdunum_++;
-  int ii;
-  for(ii = 0; ii < tfields; ii++)
-    {
-      delete [] tform[ii];
-    }
-  delete [] ttype;
-  delete [] tform;
-  //
-  // write supplementary keywords
+
+  // header format FITS
+   
+   writeAppendedHeaderOnFits();
+
+  // write SOPHYA keywords
   if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl);
 }
+
+ 
 
 /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
@@ -1480,5 +1522,6 @@
 \param <nentries>  number of data to be written
 */
-void FitsOutFile::PutColToFits(int nocol, int nentries, r_8* donnees) const
+
+void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
 {
   int status = 0;
@@ -1509,5 +1552,5 @@
 same as previous method with float data 
 */
-void FitsOutFile::PutColToFits(int nocol, int nentries, r_4* donnees) const
+void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
 {
   int status = 0;
@@ -1541,5 +1584,5 @@
 same as previous method with int data 
 */
-void FitsOutFile::PutColToFits(int nocol, int nentries, int_4* donnees) const
+void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
 {
   int status = 0;
@@ -1702,6 +1745,6 @@
       char strval[FLEN_VALUE]= "";
       char *comkey = "COMMENT";
-      fits_read_keyword(fptr_, keyname, strval, NULL, &status);
-      if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 ) 
+      //      fits_read_keyword(fptr_, keyname, strval, NULL, &status);
+      //  if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 ) 
 	{
 	  string coco = dvl.GetComment(key);
@@ -1762,2 +1805,261 @@
     }
 
+
+/*! \fn void  FitsOutFile::appendInHeader(FitsInFile& infits, int hdunum)
+
+get a header from FitsInFile and append to the header beeing built
+(shifting mandatory keywords)
+*/ 
+
+void FitsOutFile::appendInputHeader(FitsInFile& infits, int hdunum)
+{
+  int status = 0;
+  int hdutype;
+  fitsfile* fptr=infits.fitsfilePtr();
+  fits_movabs_hdu(fptr,hdunum,&hdutype,&status);
+  if( status ) fits_report_error(stderr,status);
+
+  // get number of keywords
+  int nkeys,keypos;
+  fits_get_hdrpos(fptr,&nkeys,&keypos,&status);
+  if( status ) fits_report_error(stderr,status);
+  // shift with the number of mandatory keywords
+  int num= 0;
+  // if primary header
+    if (hdunum == 1) 
+      {
+	// read NAXIS
+	int naxis=0;
+	fits_read_key(fptr,TINT,"NAXIS",&naxis,NULL,&status);
+	// number of mandatory keywords
+	num = naxis+3;
+      }
+    // extensions
+    else
+      {
+	if (hdutype == IMAGE_HDU)
+	  {
+	    // read NAXIS
+	    int naxis=0;
+	    fits_read_key(fptr,TINT,"NAXIS",&naxis,NULL,&status);
+	    // number of mandatory keywords
+	    num = naxis+5;
+	  }
+	else
+	  if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
+	    {
+	      // number of mandatory keywords
+	      num = 8;
+	    }
+      }
+  int j;
+  char keyname[LEN_KEYWORD];  
+  char value[FLEN_VALUE];
+  char comment[FLEN_COMMENT];
+  for(j = num+1; j <= nkeys; j++)
+    {
+      char dtype;
+      fits_read_keyn(fptr,j,keyname,value,comment,&status);
+      if(status) 
+	{
+	  fits_report_error(stderr,status);
+	  status=0;
+	}
+      string  kn(keyname);
+      string  cm(comment);
+      string  val(value);
+      FitsKeyword kw(kn, val, cm);
+      mots_cles_.push_back(kw);
+    }
+}
+void FitsOutFile::writeAppendedHeaderOnFits()
+{
+  for (list<FitsKeyword>::iterator it=mots_cles_.begin(); it !=mots_cles_.end(); it++)
+    {
+      (*it).writeOnFits(fptr_);
+    } 
+  mots_cles_.clear();
+}
+
+void FitsOutFile::insertKeywordOnHeader(string keyname, double value, string comment)
+{
+  char* cvalue = new char[16];
+  sprintf(cvalue,"%e",value);
+  //  char* kn = const_cast<char*>(keyname.c_str());
+  //  char* cm = const_cast<char*>(comment.c_str());
+  FitsKeyword kw(keyname, string(cvalue), comment);
+  mots_cles_.push_back(kw);
+}
+
+void FitsOutFile::insertCommentLineOnHeader(string comment)
+{
+  FitsKeyword kw(comment);
+  mots_cles_.push_back(kw);
+}
+
+void FitsOutFile::PrintHeaderToBeAppended()
+{
+  cout << " contenu du header en cours de fabrication " << endl;
+  for (list<FitsKeyword>::iterator it=mots_cles_.begin(); it !=mots_cles_.end(); it++)
+    {
+      (*it).Print();
+    } 
+}
+
+
+FitsKeyword::FitsKeyword()
+  {
+    datatype_=' ';
+    keyname_ = string("");
+    dvalue_=0.;
+    ivalue_=1;
+    svalue_=string("");
+    comment_=string("");
+  }
+
+FitsKeyword::FitsKeyword(string comment)
+  {
+    datatype_=' ';
+    keyname_=string("COMMENT");
+    comment_=comment;
+  }
+
+FitsKeyword::FitsKeyword(string keyname, string value, string comment) :  keyname_(keyname), comment_(comment)
+  {
+    int status=0;
+    char dtype;
+    const char* val= value.c_str();
+    char* valk = const_cast<char*>(val);
+    fits_get_keytype(valk,&dtype,&status);
+    if(status) 
+      {
+	status=0;
+	datatype_=' ';
+      }
+    else     datatype_=dtype;
+    
+    switch( datatype_ )  
+      { 
+      case 'C':
+	{
+	  svalue_ = string(val);
+	    break;
+	}
+      case 'I':
+	{
+	  ivalue_ = atoi(val);
+	  break;
+	}
+      case 'L':
+	{
+	  //	  cout << " ATTENTION : pb a regler avec logical!" << endl;
+	  if (value[0] == 'T') ivalue_ = 1;
+	  else ivalue_ = 0;
+	  break;
+	  }
+      case 'F':
+	{
+	  dvalue_ = atof(val);
+	  break;
+	}
+      case 'X':
+	{
+	  throw IOExc("FitsKeyword , complex keyword value not supported");
+	}
+      }
+  }
+
+void FitsKeyword::writeOnFits(fitsfile* ptr) 
+  {
+    int status=0;
+    //    char* keyname = new char[LEN_KEYWORD];
+    //   char* comment = new char[FLEN_COMMENT];
+    char* keyname;
+    char* comment;
+    keyname = const_cast<char*>(keyname_.c_str());
+    comment = const_cast<char*>(comment_.c_str());
+  // get number of keywords
+  int nkeys,keypos;
+  fits_get_hdrpos(ptr,&nkeys,&keypos,&status);
+    switch( datatype_ )  
+      { 
+      case 'C':
+	{
+	  char value[FLEN_VALUE];
+	  strncpy(value,svalue_.c_str(),FLEN_VALUE) ;
+	  fits_write_key(ptr,TSTRING,keyname,&value, comment,&status);
+	  fits_report_error(stderr,status);
+	  break;
+	}
+      case 'I':
+	{
+	  fits_write_key(ptr,TINT,keyname,&ivalue_, comment,&status);
+	  fits_report_error(stderr,status);
+	  break;
+	}
+      case 'L':
+	{
+	  fits_write_key(ptr,TLOGICAL,keyname,&ivalue_, comment,&status);
+	  fits_report_error(stderr,status);
+	  break;
+	}
+      case 'F':
+	{
+	  fits_write_key(ptr,TDOUBLE,keyname,&dvalue_, comment,&status);
+	  fits_report_error(stderr,status);
+	  break;
+	}
+      case 'X':
+	{
+	  cout << "FitsKeyword : complex keyword value not supported" << endl;;
+	}
+      default :
+	{
+	  char *comkey = "COMMENT";
+	  if(strncmp(keyname,comkey,LEN_KEYWORD-1) == 0)
+	    {
+	      fits_write_comment(ptr,comment,&status);
+	      fits_report_error(stderr,status);
+	    }
+	  else
+	    {
+	      cout << " WARNING  (FitsKeyword::writeOnFits) : unrecognized keyword : " << keyname_ << endl;
+	    }
+	}
+      }
+  }
+
+void FitsKeyword::Print()
+  {
+    switch( datatype_ )  
+      { 
+      case 'C':
+	{
+	  cout << " mot cle : " << keyname_ << " valeur : " << svalue_ << " commentaire : " << comment_ <<endl;
+	  break;
+	}
+      case 'I':
+	{
+	  cout << " mot cle : " << keyname_ << " valeur : " << ivalue_ << " commentaire : " << comment_ <<endl;
+	  break;
+	}
+      case 'L':
+	{
+	  cout << " mot cle : " << keyname_ << " valeur : " << ivalue_ << " commentaire : " << comment_ <<endl;
+	  break;
+	}
+      case 'F':
+	{
+	  cout << " mot cle : " << keyname_ << " valeur : " << dvalue_ << " commentaire : " << comment_ <<endl;
+	  break;
+	}
+      case 'X':
+	{
+	  cout << "FitsKeyword : complex keyword value not supported" << endl;;
+	}
+      default :
+	{
+	  cout << " mot cle : " << keyname_ << " commentaire : "  << comment_ <<endl;
+	}
+      }
+  }
Index: /trunk/SophyaExt/FitsIOServer/fitsfile.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1352)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1353)
@@ -20,10 +20,35 @@
   class FitsInFile;
   class FitsOutFile;
-  
+
+
+
+class  FitsKeyword
+{
+
+ public:
+
+FitsKeyword();
+FitsKeyword(string comment);
+FitsKeyword(string keyname, string value, string comment); 
+void writeOnFits(fitsfile* ptr);
+
+void Print();
+
+ private:
+
+  char datatype_;
+  string keyname_;
+  double dvalue_;
+  int ivalue_;
+  string svalue_;
+  string comment_;
+};
+
+
 
 //
 //! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
 
- class FitsIOHandler {
+class FitsIOHandler {
 
 
@@ -77,4 +102,5 @@
    inline void firstImageOnPrimaryHeader(bool choice) {imageOnPrimary_=choice;}
    inline int currentHeaderIndex() {return hdunum_;}
+   inline fitsfile* fitsfilePtr() {return fptr_;}
  
 
@@ -107,6 +133,8 @@
    int  NbBlocks();
    static void GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl  );
-   void        ReadHeader(int hdunum);
- 
+
+   void  ReadHeader(int hdunum);
+bool hasKeyword(string keyw, int hdunum);
+
   /*! \return a reference on a DVList containing the keywords from FITS file */
   inline const DVList& DVListFromFits() const { return dvl_;}
@@ -157,4 +185,6 @@
 /*! \return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
 inline bool IsFitsTable() const {return (hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL);}
+
+
 
 
@@ -195,4 +225,8 @@
   void    GetSingleColumn(int_4* map, int nentries) const;
 
+
+
+
+
   private :
 
@@ -253,4 +287,9 @@
 
    void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* dvl, string extname,  vector<int> taille_des_chaines) ;
+   void appendInputHeader(FitsInFile& headerin, int hdunum);
+   void writeAppendedHeaderOnFits();
+   void PrintHeaderToBeAppended();
+   void insertCommentLineOnHeader(string comment);
+   void insertKeywordOnHeader(string keyname, double value, string comment);  
    void PutColToFits(int nocol, int nentries, r_8* donnees) const;
    void PutColToFits(int nocol, int nentries, r_4* donnees) const;
@@ -277,4 +316,6 @@
 
   DVList* dvlToPrimary_; /**< for transferring keywords when creating primary header */
+  list<FitsKeyword>  mots_cles_;
+
  };
 
@@ -292,10 +333,11 @@
    vector<string>  cdata_;
    vector<string> ColName_;
-
  };
 
 
+
+
+
 } // Fin du namespace
 
-
 #endif
Index: /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1352)
+++ /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1353)
@@ -63,5 +63,4 @@
   ownobj_ = false;
 } 
-
 
 
Index: /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h	(revision 1352)
+++ /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h	(revision 1353)
@@ -30,4 +30,5 @@
 void Mollweide_picture_projection(char flnm[]);
 void sinus_picture_projection(char flnm[]);
+ void ReWriteFromFitsToFits(FitsInFile& headerin, FitsOutFile& os); 
 
 
