Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1142)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1143)
@@ -40,5 +40,4 @@
 FitsFile::~FitsFile()
 {
-  cout << " destructeur FitsFile " << endl;
   int status = 0;
   if( fptr_ != NULL)
@@ -106,5 +105,4 @@
 void FitsInFile::InitNull()
 {
-  cout << " init FitsInFile " << endl;
   bitpix_ = 0;
   naxis_ = 0;
@@ -215,5 +213,4 @@
   fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
   if( status ) printerror( status );
-  //  cout << " dimension lue " << naxis << endl;
   // read the NAXISn keywords to get image size
   long* naxes = new long[naxis] ;
@@ -232,8 +229,7 @@
 
 
-//void FitsInFile::ReadFInit(char flnm[],int hdunum) 
 void FitsInFile::ReadFInit(int hdunum) 
 {
-  // InitNull();
+   InitNull();
   // int status = 0;
   
@@ -275,4 +271,13 @@
 }
 
+DVList  FitsInFile::DVListFromPrimaryHeader() const
+   {
+     int status;
+     DVList dvl;
+     KeywordsIntoDVList(fptr_, dvl, 1);
+     int hdutype = 0;
+     if (hdunum_ > 0) fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
+     return dvl;
+   }
 
 
@@ -281,4 +286,5 @@
   int status = 0;
   int hdutype;
+  InitNull();
   fits_movrel_hdu(fptr_, 1,&hdutype,&status); 
   if( status ) printerror( status," lecture du header suivant" );
@@ -484,5 +490,4 @@
 void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
     {
-      cout <<" entree GetBinTabFCol " << endl;
       int status= 0;
       int DTYPE;
@@ -735,8 +740,36 @@
   char card[FLEN_CARD];  
   char *comkey = "COMMENT";
+  char comment[FLEN_COMMENT];
 
   // shift with the number of mandatory keywords
-  int num= 8;
-
+  //  int num= 8;
+    int num= 0;
+    // primary header
+    if (hdunum == 1) 
+      {
+	// read NAXIS
+	int naxis=0;
+	fits_read_key(fileptr,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(fileptr,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;
   for(j = num+1; j <= nkeys; j++)
@@ -760,21 +793,25 @@
 	    { 
 	    case 'C':
-	      dvl[keyname]= strval;	  
+	      fits_read_key(fileptr,TSTRING,keyname,strval,comment,&status);
+	      dvl[keyname]= strval;
+	      dvl.SetComment(keyname, comment);
 	      break;
 	    case 'I':
 	      int ival;
-	      fits_read_key(fileptr,TINT,keyname,&ival,NULL,&status);
+	      fits_read_key(fileptr,TINT,keyname,&ival,comment,&status);
 	        dvl[keyname]= (int_4) ival;		// Portage mac DY
+		dvl.SetComment(keyname, comment);
 	      break;
 	    case 'L':
 	      int ilog;
-	      if(strncmp(strval,"T",1) == 0) ilog= 1;
-	      else ilog= 0;
+	      fits_read_key(fileptr,TLOGICAL,keyname,&ilog,comment,&status);
 	      dvl[keyname]= (int_4) ilog;
+	      dvl.SetComment(keyname, comment);
 	      break;
 	    case 'F':
 	      double dval;
-	      fits_read_key(fileptr,TDOUBLE,keyname,&dval,NULL,&status);
+	      fits_read_key(fileptr,TDOUBLE,keyname,&dval,comment,&status);
 	      dvl[keyname]= dval;
+	      dvl.SetComment(keyname, comment);
 	      break;
 	    }
@@ -817,5 +854,5 @@
 
 
-void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn) 
+void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn,  DVList &dvl) 
 {
   int status = 0;
@@ -824,5 +861,8 @@
   if (hdunum_ == 1)
     {
-      if (imageOnPrimary_ == false) fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
+      if (imageOnPrimary_ == false)
+	{ 
+	  fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
+	  writeSignatureOnFits();	}
       else  hdunum_--;
     }
@@ -844,4 +884,9 @@
 
   hdunum_++;
+
+  // write supplementary keywords
+  //  dvl.Print();
+  addKeywordsOfDVList(dvl);
+
   delete [] naxes;
   if( status ) printerror( status, "erreur creation HDU IMAGE"  );
@@ -854,5 +899,5 @@
   fits_write_img(fptr_,TDOUBLE,1,npix,map,&status); 
   if( status ) printerror( status, "erreur ecriture putImageToFits" );
-  writeSignatureOnFits();
+  //  writeSignatureOnFits();
 }
 
@@ -863,5 +908,5 @@
   fits_write_img(fptr_,TFLOAT,1,npix, map,&status); 
   if( status ) printerror( status, "erreur ecriture putImageToFits" );
-  writeSignatureOnFits();
+  //  writeSignatureOnFits();
 
 }
@@ -873,5 +918,5 @@
   fits_write_img(fptr_,TINT,1,npix,map,&status); 
   if( status ) printerror( status, "erreur ecriture putImageToFits" );
-  writeSignatureOnFits();
+  //  writeSignatureOnFits();
 }
 
@@ -954,43 +999,5 @@
   //
   // write supplementary keywords
-  //
-  // get names and values from the join DVList object
-  //  dvl.Print();
-  fits_write_comment(fptr_,"--------------------------------------", &status);
-  DVList::ValList::const_iterator it;
-  for(it = dvl.Begin(); it != dvl.End(); it++)
-    {
-      char keytype= (*it).second.elval.typ;
-      char keyname[10];
-      strncpy(keyname,(*it).first.substr(0,64).c_str(),10);
-      char comment[FLEN_COMMENT];
-      switch (keytype)
-	{
-	case 'I' :
-	  {
-	    int ival=(*it).second.elval.iv;
-	    strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
-	    fits_write_key(fptr_,TINT,keyname,&ival,comment,&status);
-	    break;
-	  }
-	case 'D' :
-	  {
-	    double dval=(*it).second.elval.dv;
-	    strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
-	    fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status);
-	    break;
-	  }
-	case 'S' :
-	  {
-	    char strval[128];
-	    strncpy(strval,(*it).second.elval.strv->c_str(),127);
-	    strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
-	    fits_write_key(fptr_,TSTRING,keyname,&strval,comment,&status);
-	    break;
-	  }
-	} 
-  if( status )  printerror( status,"fitsfile: probleme ecriture mot-cle du dvlist" );
-    }
-  fits_write_comment(fptr_,"--------------------------------------", &status);
+  addKeywordsOfDVList(dvl);
 
 }
@@ -1097,4 +1104,13 @@
 }
 
+void  FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
+{
+  int status = 0;
+  int hdutype;
+  fits_movabs_hdu(fptr_,1,&hdutype,&status);
+  addKeywordsOfDVList(dvl);
+  fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
+}
+
 
 void FitsOutFile::writeSignatureOnFits() const
@@ -1110,5 +1126,5 @@
   fits_write_key(fptr_, TSTRING, keyname, &strval, comment, &status);
   if( status ) printerror( status );
-
+  fits_write_date(fptr_, &status);
   fits_write_comment(fptr_,"..............................................", &status);
   fits_write_comment(fptr_, " SOPHYA package - FITSIOSever ", &status);
@@ -1120,5 +1136,53 @@
 
 
-
-
-
+void FitsOutFile::addKeywordsOfDVList(DVList& dvl) const
+{
+  int status = 0;
+  fits_write_comment(fptr_,"---------- keywords from SOPHYA ---------", &status);
+  if (hdunum_ == 1) writeSignatureOnFits();
+  DVList::ValList::const_iterator it;
+  for(it = dvl.Begin(); it != dvl.End(); it++)
+    {
+      char keytype= (*it).second.elval.typ;
+      char keyname[10];
+      strncpy(keyname,(*it).first.substr(0,64).c_str(),10);
+      char comment[FLEN_COMMENT];
+      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 ) 
+	{
+	  status = 0;
+	  switch (keytype)
+	    {
+	    case 'I' :
+	      {
+		int ival=(*it).second.elval.iv;
+		strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
+		fits_write_key(fptr_,TINT,keyname,&ival,comment,&status);
+		break;
+	      }
+	    case 'D' :
+	      {
+		double dval=(*it).second.elval.dv;
+		strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
+		fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status);
+		break;
+	      }
+	    case 'S' :
+	      {
+		char strval[128];
+		strncpy(strval,(*it).second.elval.strv->c_str(),127);
+		strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
+		fits_write_key(fptr_,TSTRING,keyname,&strval,comment,&status);
+		break;
+	      }
+	    } 
+	}
+  if( status )  printerror( status,"fitsfile: probleme ecriture mot-cle du dvlist" );
+    }
+  fits_write_comment(fptr_,"--------------------------------------", &status);
+}
+
+
+
Index: trunk/SophyaExt/FitsIOServer/fitsfile.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1142)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1143)
@@ -58,5 +58,5 @@
 opens a file 'flnm' 
 
-gets parameters in header (hdunum)
+gets parameters in extension-header (hdunum)
 
 calls the method 'ReadFromFits' from the inherited  object
@@ -125,5 +125,5 @@
    static  void printerror(int&) ;
    static  void printerror(int&,char* texte) ;
-   inline void InitNull() { cout << " init fitsfile " << endl; fptr_= NULL; hdutype_= 0; hdunum_ = 1; 
+   inline void InitNull() { fptr_= NULL; hdutype_= 0; hdunum_ = 1; 
    fits_status_ = 0;}
 
@@ -150,5 +150,5 @@
    //   FitsInFile(char flnm[], int hdunum=0);
    FitsInFile(char flnm[]);
-   ~FitsInFile() {  cout << " destructeur FitsInFile " << endl; };
+   ~FitsInFile() { ; };
 
 
@@ -170,4 +170,7 @@
    */
 inline const DVList& DVListFromFits() const { return dvl_;}
+
+/* get the keywords of primary header in a DVList */
+DVList  DVListFromPrimaryHeader() const;
 
 void moveToFollowingHeader();
@@ -347,5 +350,5 @@
    FitsOutFile();
    FitsOutFile(char flnm[], bool OldFile=false);
-   ~FitsOutFile() {  cout << " destructeur FitsOutFile " << endl;};
+   ~FitsOutFile() { ;};
    inline void InitNull() {imageOnPrimary_=false;}
 
@@ -368,5 +371,6 @@
 \param <naxisn>  array containind sizes of the different dimensions
   */
-  void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
+  void makeHeaderImageOnFits(char type, int nbdim, int* naxisn,  DVList &dvl) ;
+
 
   /*! write double data from array 'map'on an IMAGE extension 
@@ -391,5 +395,6 @@
 
   /*! create an BINTABLE header on FITS file.
-\param <fieldType> array containing characters denoting types of the different column (see method ColTypeFromFits)
+\param <fieldType> array conta
+ining characters denoting types of the different column (see method ColTypeFromFits)
 \param <Noms>  array of the names of columns
 \param <nentries>  number of data of each column
@@ -416,8 +421,18 @@
   void putColToFits(int nocol, int nentries, char** donnees) const;
 
+/////////////////////////////////////////////////////////////
+//       methods for managing any type of FITS extension
+////////////////////////////////////////////////////////
+
+
+/* put keywords from a DVList into the primary header of the fits-file */
+void  DVListIntoPrimaryHeader(DVList& dvl) const;
+
+
+
   private :
 
   void writeSignatureOnFits() const; 
-
+  void addKeywordsOfDVList(DVList& dvl) const;
 
   bool imageOnPrimary_;
Index: trunk/SophyaExt/FitsIOServer/fitsntuple.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsntuple.cc	(revision 1142)
+++ trunk/SophyaExt/FitsIOServer/fitsntuple.cc	(revision 1143)
@@ -119,5 +119,5 @@
   delete [] ColName;
 
-  r_4* ligne = new r_4[nbcols];
+  float* ligne = new float[nbcols];
 
   int firstln, lastln;
@@ -136,5 +136,5 @@
     {
       is.GetBinTabLine(numLigne, ligne);
-      dobj_->Fill(ligne);
+      dobj_->Fill((r_4*)ligne);
     }
   delete [] ligne;
@@ -161,5 +161,4 @@
   // extension name
   char* extname = "NTuple_Binary_tbl"; 
-  dvl.Print();
 
   char** Noms = new char*[ncols];   
Index: trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1142)
+++ trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1143)
@@ -78,5 +78,5 @@
     }
 
-  DVList dvl;  
+  DVList dvl( dobj_->Info() );  
 
   SphereCoordSys* cs= dobj_->GetCoordSys();
@@ -99,6 +99,4 @@
   dvl.SetComment("LASTPIX", "Last pixel # (0 based)");
   dvl["Content"]= "SphereHEALPix";
-  dvl["EXTNAME"]= "SIMULATION";
-  dvl["COMMENT"]= "Sky Map Pixelisation Specific Keywords";
    
   // On ecrit les dataBlocks 
@@ -106,6 +104,5 @@
   Noms[0]= new char[15];
   strncpy(Noms[0],dvl.GetS("Content").c_str(),15);
-  char extname[15];
-  strncpy(extname,dvl.GetS("EXTNAME").c_str(),15);
+  char extname[15] = "SIMULATION";
 
   char Type[2];
@@ -198,5 +195,5 @@
   // on effectue le decoupage en tranches 
   dobj_->SetThetaSlices();
-  dobj_->Info()=is.DVListFromFits();
+    dobj_->Info()  = is.DVListFromFits();
 
 
Index: trunk/SophyaExt/FitsIOServer/fitstarray.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 1142)
+++ trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 1143)
@@ -94,4 +94,5 @@
   // On lit le tableau
   is.GetSingleColumn( dobj_->Data(),dobj_->Size());
+    dobj_->Info()  = is.DVListFromFits();
 
 }
@@ -133,5 +134,5 @@
     }
   cout << " nombre total d'elements a copier " << nbels << endl;
-  os.makeHeaderImageOnFits(type, nbdim, naxisn);
+  os.makeHeaderImageOnFits(type, nbdim, naxisn, dobj_->Info());
   if (!dobj_->IsPacked()) 
     {
Index: trunk/SophyaExt/FitsIOServer/fitsxntuple.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsxntuple.cc	(revision 1142)
+++ trunk/SophyaExt/FitsIOServer/fitsxntuple.cc	(revision 1143)
@@ -142,14 +142,14 @@
   delete [] ColName;
 
-    r_8* dligne;
-    r_4* fligne;
-    int_4* iligne;
+    double* dligne;
+    float* fligne;
+    int* iligne;
     char** cligne;
 
-  if (DfitsCol.size()>0) dligne = new r_8[DfitsCol.size()];
+  if (DfitsCol.size()>0) dligne = new double[DfitsCol.size()];
   else dligne=NULL;
-  if (FfitsCol.size()>0) fligne = new r_4[FfitsCol.size()];
+  if (FfitsCol.size()>0) fligne = new float[FfitsCol.size()];
   else fligne=NULL;
-  if (IfitsCol.size()>0) iligne = new int_4[IfitsCol.size()];
+  if (IfitsCol.size()>0) iligne = new int[IfitsCol.size()];
   else iligne=NULL;
   if (SfitsCol.size()>0) 
@@ -176,5 +176,5 @@
     {
       is.GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
-      dobj_->Fill(dligne, fligne, iligne, cligne);    
+      dobj_->Fill((r_8*)dligne, (r_4*)fligne, (int_4*)iligne, cligne);    
     }
     delete [] dligne;
@@ -202,5 +202,4 @@
   // extension name
   char* extname = "XNTuple_Binary_tbl"; 
-  dvl.Print();
   char** Noms = new char*[ncols];   
   int k;
