Index: /trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1417)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1418)
@@ -351,4 +351,8 @@
 	  cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
 	}
+    }
+  if ( hdutype_ == FitsExtensionType_EOF )
+    {
+	throw PException("FitsFile::ReadHeader, attempt to read through EOF");
     }
 }
@@ -1764,5 +1768,5 @@
   //
   strncpy(keyname, "CREATOR", LEN_KEYWORD); 
-  keyname[LEN_KEYWORD-1] = '\0';
+  keyname[7] = '\0';
   strcpy(strval, "SOPHYA");
   strcpy(comment," SOPHYA Package - FITSIOServer ");
@@ -1789,7 +1793,10 @@
     {
       MuTyV::MTVType keytype= (*it).second.elval.Type();
-      char keyname[10];
-      strncpy(keyname,(*it).first.substr(0,64).c_str(),10);
-      string key(keyname);
+      char keyname[LEN_KEYWORD];
+      strncpy(keyname,(*it).first.substr(0,64).c_str(),LEN_KEYWORD);
+      int bout = ((*it).first.substr(0,64).length() < LEN_KEYWORD) ? (*it).first.substr(0,64).length() : LEN_KEYWORD-1;
+      keyname[bout] = '\0';
+      string key((*it).first.substr(0,64));
+	//      string key(keyname);
       char comment[FLEN_COMMENT];
       char strval[FLEN_VALUE]= "";
@@ -1934,7 +1941,19 @@
 void FitsOutFile::insertKeywordOnHeader(string keyname, double value, string comment)
 {
-  char* cvalue = new char[16];
+  char cvalue[16];
   sprintf(cvalue,"%e",value);
-  FitsKeyword kw(keyname, string(cvalue), comment);
+  FitsKeyword kw(keyname, string(cvalue), comment, 'F');
+  mots_cles_.push_back(kw);
+}
+void FitsOutFile::insertKeywordOnHeader(string keyname, int value, string comment)
+{
+  char cvalue[16];
+  sprintf(cvalue,"%d",value);
+  FitsKeyword kw(keyname, string(cvalue), comment, 'I');
+  mots_cles_.push_back(kw);
+}
+void FitsOutFile::insertKeywordOnHeader(string keyname, string value, string comment)
+{
+  FitsKeyword kw(keyname, value , comment, 'C');
   mots_cles_.push_back(kw);
 }
@@ -1971,5 +1990,5 @@
     keyname_=string("COMMENT");
     comment_=comment;
-  }
+  } 
 
 FitsKeyword::FitsKeyword(string keyname, string value, string comment) :  keyname_(keyname), comment_(comment)
@@ -2019,14 +2038,53 @@
   }
 
+// constructeur pour les mots-cles maison (ne prvenant pas de la lecture d'un fichier fits)
+FitsKeyword::FitsKeyword(string keyname, string value, string comment, char type) :  keyname_(keyname), comment_(comment), datatype_(type)
+  {
+    char dtype;
+    const char* val= value.c_str();
+    char* valk = const_cast<char*>(val);
+    switch( datatype_ )  
+      { 
+      case 'C':
+	{
+	  strip(valk, 'B','\'');
+	  svalue_ = string(valk);
+	    break;
+	}
+      case 'I':
+	{
+	  ivalue_ = atoi(val);
+	  break;
+	}
+      case 'L':
+	{
+	  bool bb = value.c_str();
+	  ivalue_ = (int)bb;
+	  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
+    char keyname[LEN_KEYWORD];
+    char comment[FLEN_COMMENT];
+    keyname_.copy(keyname, LEN_KEYWORD); 
+    int bout = (keyname_.length() < LEN_KEYWORD) ? keyname_.length() : LEN_KEYWORD-1;
+    keyname[bout] = '\0';
+    comment_.copy( comment, FLEN_COMMENT);
+    bout = (comment_.length() < FLEN_COMMENT) ? comment_.length() : FLEN_COMMENT-1;
+    comment[bout]= '\0';
+
   int nkeys,keypos;
   fits_get_hdrpos(ptr,&nkeys,&keypos,&status);
@@ -2035,6 +2093,8 @@
       case 'C':
 	{
-	  char value[FLEN_VALUE];
-	  strncpy(value,svalue_.c_str(),FLEN_VALUE) ;
+	  char value[FLEN_VALUE]="";
+	  svalue_.copy(value, FLEN_VALUE-1);
+	  int fin =  (svalue_.length() < FLEN_VALUE) ? svalue_.length() : FLEN_VALUE-1;
+	  value[fin]= '\0';
 	  fits_write_key(ptr,TSTRING,keyname,&value, comment,&status);
 	  fits_report_error(stderr,status);
Index: /trunk/SophyaExt/FitsIOServer/fitsfile.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1417)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1418)
@@ -31,4 +31,5 @@
 FitsKeyword(string comment);
 FitsKeyword(string keyname, string value, string comment); 
+FitsKeyword(string keyname, string value, string comment, char type); 
 void writeOnFits(fitsfile* ptr);
 
@@ -294,5 +295,7 @@
    void PrintHeaderToBeAppended();
    void insertCommentLineOnHeader(string comment);
-   void insertKeywordOnHeader(string keyname, double value, string comment);  
+   void insertKeywordOnHeader(string keyname, double value, string comment); 
+   void insertKeywordOnHeader(string keyname, int value, string comment); 
+   void insertKeywordOnHeader(string keyname, string value, string comment); 
    void PutColToFits(int nocol, int nentries, r_8* donnees) const;
    void PutColToFits(int nocol, int nentries, r_4* donnees) const;
