Index: trunk/SophyaExt/FitsIOServer/fitsioserver.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsioserver.cc	(revision 608)
+++ trunk/SophyaExt/FitsIOServer/fitsioserver.cc	(revision 609)
@@ -341,6 +341,6 @@
   if (sph.NbPixels() != npixels)
     {
-      cout << " found " << npixels << " pixels" << endl;
-      cout << " expected " << sph.NbPixels() << endl;
+      //DBG      cout << " found " << npixels << " pixels" << endl;
+      //DBG cout << " expected " << sph.NbPixels() << endl;
       if (nside <= 0 ) 
 	{
@@ -352,11 +352,11 @@
 	{ 
 	  sph.Resize(nside);
-	  cout << " resizing the sphere to nside=  " << nside  << endl;
-	}
-      else
-	{
-	  cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
+	  cout << "FitsIoServer::load(SphereGorski<double> ...) ReSizing to NSide= " << nside  << endl;
+	}
+      //      else
+      //	{
+      //	  cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
 //	  exit(0);   $CHECK$   Ca peut etre OK , non ??  Reza 20/11/99
-	}
+      //	}
     }
   for (int j = 0; j < sph.NbPixels(); j++) sph(j)= (double)r_8tab_[j];
@@ -386,6 +386,6 @@
   if (sph.NbPixels() != npixels)
     {
-      cout << " found " << npixels << " pixels" << endl;
-      cout << " expected " << sph.NbPixels() << endl;
+      //DBG      cout << " found " << npixels << " pixels" << endl;
+      //DBG      cout << " expected " << sph.NbPixels() << endl;
       if (nside <= 0 ) 
 	{
@@ -397,11 +397,11 @@
 	{ 
 	  sph.Resize(nside);
-	  cout << " resizing the sphere to nside=  " << nside  << endl;
-	}
-      else
-	{
-	  cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
+	  cout << "FitsIoServer::load(SphereGorski<float> ...) ReSizing to NSide= " << nside  << endl;
+	}
+      //      else
+      //	{
+      //	  cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
 //	  exit(0);   $CHECK$ - Il ne faut pas sortir, me semble-t-il , Reza 20/11/99
-	}
+      //	}
     }
   //  cout << " fin relecture debut transfert" << endl;
@@ -716,5 +716,5 @@
 
   // extension name
-  char extname[] = "NTuple_Binary_tbl";
+  char * extname = "NTuple_Binary_tbl";
 
   // define the name, and the datatype for the tfields columns
@@ -760,5 +760,5 @@
 	}
       fits_write_col(fptr,TFLOAT,i+1,firstrow,firstelem,nrows,dens,&status);
-      delete []dens;
+      delete[] dens;
     }
 
@@ -774,7 +774,7 @@
     {
       char keytype= (*it).second.typ;
-      char keyname[9]="";
+      char keyname[10];
       strncpy(keyname,(*it).first.substr(0,64).c_str(),8);
-      char comment[FLEN_COMMENT]="";
+      char comment[FLEN_COMMENT];
 
       switch (keytype)
@@ -796,6 +796,6 @@
 	case 'S' :
 	  {
-	    char strval[]="";
-	    strcpy(strval,(*it).second.mtv.strv);
+	    char strval[128];
+	    strncpy(strval,(*it).second.mtv.strv,127);
 	    strcpy(comment,"S character string");
 	    fits_write_key(fptr,TSTRING,keyname,&strval,comment,&status);
@@ -1151,18 +1151,22 @@
 
   //dvl.Print();
+  char keyname[16];
+  int flen_keyword = 9;
+  char comment[FLEN_COMMENT];
+  char strval[128];
+
   DVList::ValList::const_iterator it;
   for(it = dvl.Begin(); it != dvl.End(); it++)  
     {
       int datatype=  key_type_PL2FITS( (*it).second.typ);
-      char keyname[]="";
-      int flen_keyword = 9;
       // FLEN_KEYWORD est la longueur max d'un mot-cle. Il doit y avoir une 
       // erreur dans la librairie fits qui donne FLEN_KEYWORD=72 
       // contrairement a la notice qui donne FLEN_KEYWORD=9 (ch. 5, p.39)
-      strncpy(keyname, (*it).first.substr(0,64).c_str(),flen_keyword-1);
-      char comment[FLEN_COMMENT]="";
+      //$CHECK$ Reza 20/11/99
+      //      strncpy(keyname, (*it).first.substr(0,64).c_str(),flen_keyword-1);
+      strncpy(keyname, (*it).first.substr(0,64).c_str(),flen_keyword);  
+      keyname[flen_keyword] = '\0';
       int ival=0;
       double dval=0.;
-      char strval[]="";
       switch (datatype)
 	{
@@ -1170,4 +1174,5 @@
 	  ival=(*it).second.mtv.iv;
 	  strcpy(comment,"I entier");
+//DBG          cerr << " Writing I " << (string)keyname << " = " << ival << endl;
 	  fits_write_key(fptr, datatype, keyname, &ival, comment, &status);
 	  break;
@@ -1175,9 +1180,11 @@
 	  dval=(*it).second.mtv.dv;
 	  strcpy(comment,"D double");
+//DBG          cerr << " Writing D " << (string)keyname << " = " << dval << endl;
 	  fits_write_key(fptr, datatype, keyname, &dval, comment, &status);
 	  break;
 	case TSTRING :
-	  strcpy(strval, (*it).second.mtv.strv);
+	  strncpy(strval, (*it).second.mtv.strv, 128); strval[127] = '\0';
 	  strcpy(comment,"S character string");
+//DBG          cerr << " Writing S " << (string)keyname << " = " << (string)strval << endl;
 	  fits_write_key(fptr, datatype, keyname, &strval, comment, &status);
 	  break;
@@ -1188,4 +1195,18 @@
       if( status ) printerror( status );
     }
+
+  strncpy(keyname, "CREATOR",flen_keyword); keyname[flen_keyword] = '\0';
+  strcpy(strval, "SOPHYA");
+  strcpy(comment," SOPHYA Package - FITSIOServer ");
+  fits_write_key(fptr, TSTRING, keyname, &strval, comment, &status);
+  if( status ) printerror( status );
+
+  fits_write_comment(fptr,"..............................................", &status);
+  fits_write_comment(fptr, " SOPHYA package - FITSIOSever ", &status);
+  fits_write_comment(fptr, " (C) LAL/IN2P3-CNRS Orsay,  FRANCE 1999", &status);
+  fits_write_comment(fptr, " (C) DAPNIA/CEA     Saclay, FRANCE 1999", &status);
+  fits_write_comment(fptr,"..............................................", &status);
+  if( status ) printerror( status );
+
   // close the file
   fits_close_file(fptr, &status);
@@ -1207,5 +1228,6 @@
 
   // create new FITS file  
-  fits_create_file(&fptr, flnm, &status); 
+  fits_create_file(&fptr, flnm, &status);
+  //DBG  cerr << " DBG - Apres fits_create_file status = " << status << endl;
   if( status )  printerror( status );
 
@@ -1216,4 +1238,5 @@
   // write the current date
   fits_write_date(fptr, &status);
+  //DBG  cerr << " DBG - Apres write_date status = " << status << endl;
   if( status )  printerror( status );
 
@@ -1242,4 +1265,5 @@
  fits_create_tbl(fptr,BINARY_TBL,nrows,tfields,ttype,tform,
 		 NULL,extname,&status);
+  //DBG  cerr << " DBG - Apres create_tbl status = " << status << endl;
   if( status )  printerror( status );
   for( int ii = 0; ii < tfields; ii++)
@@ -1255,16 +1279,18 @@
     case TDOUBLE :
       fits_write_col(fptr, TDOUBLE, 1, 1, 1, nelements, r_8tab_, &status);
-      if( status )  printerror( status, "probleme dans ecriture du tableau de doubles" );
+      if( status ) 
+        printerror( status, "planck_write_bntbl: Error writing double table" );
       break;
 
-
     case TFLOAT :
-      for (int kk=0; kk<10; kk++) cout << r_4tab_[kk] << endl;
+ //DBG!!! $CHECK$ Reza      for (int kk=0; kk<10; kk++) cout << r_4tab_[kk] << endl;
       fits_write_col(fptr, TFLOAT, 1, 1, 1, nelements, r_4tab_, &status);
-      if( status ) printerror( status );
+      if( status ) 
+        printerror( status, "planck_write_bntbl: Error writing float table" );
       break;
     case TINT :
       fits_write_col(fptr, TINT, 1, 1, 1, nelements, i_4tab_, &status);
-      if( status ) printerror( status );
+      if( status ) 
+        printerror( status, "planck_write_bntbl: Error writing int table");
       break;
     default :
@@ -1275,8 +1301,10 @@
   fits_write_comment(fptr, " ", &status);
   fits_write_comment(fptr, " ", &status);
+  //DBG  cerr << " DBG - Apres write_comment1 status = " << status << endl;  
   if( status ) printerror( status );
   fits_write_comment(fptr,"--------------------------------------------", &status);
   fits_write_comment(fptr, comment1, &status);
   fits_write_comment(fptr,"--------------------------------------------", &status);
+  //DBG  cerr << " DBG - Apres write_comment2 status = " << status << endl;  
   if( status ) printerror( status );
 
@@ -1290,10 +1318,11 @@
     {
       int datatype=  key_type_PL2FITS( (*it).second.typ);
-      char keyname[]="";
-      strncpy(keyname, (*it).first.substr(0,64).c_str(),flen_keyword-1);
-      char comment[FLEN_COMMENT]="";
+      char keyname[16];
+      strncpy(keyname, (*it).first.substr(0,64).c_str(),flen_keyword);
+      keyname[flen_keyword] = '\0';
+      char comment[FLEN_COMMENT];
       int ival=0;
       double dval=0.;
-      char strval[]="";
+      char strval[128];
       switch (datatype)
 	{
@@ -1301,4 +1330,5 @@
 	  ival=(*it).second.mtv.iv;
 	  strcpy(comment," ");
+//DBG          cerr << " Writing I " << (string)keyname << " = " << ival << endl;
 	  fits_write_key(fptr, datatype, keyname, &ival, comment, &status);
 	  break;
@@ -1306,9 +1336,11 @@
 	  dval=(*it).second.mtv.dv;
 	  strcpy(comment," ");
+//DBG          cerr << " Writing D " << (string)keyname << " = " << dval << endl;
 	  fits_write_key(fptr, datatype, keyname, &dval, comment, &status);
 	  break;
 	case TSTRING :
-	  strcpy(strval, (*it).second.mtv.strv);
+	  strncpy(strval, (*it).second.mtv.strv, 128); strval[127] = '\0';
 	  strcpy(comment," ");
+//DBG          cerr << " Writing S " << (string)keyname << " = " << (string)strval << endl;
 	  fits_write_key(fptr, datatype, keyname, &strval, comment, &status);
 	  break;
@@ -1319,14 +1351,15 @@
       if( status ) printerror( status );
     }
-  //char keyname[]="";
-  //char strval[]="";
-  //char comment[FLEN_COMMENT]="";
-  //strncpy(keyname, "CREATOR",flen_keyword-1);
-  //strcpy(strval, "SOPHYA");
-  //strcpy(comment," Orsay");
-  //fits_write_key(fptr, TSTRING, keyname, &strval, comment, &status);
-  //if( status ) printerror( status );
+  char keyname[16];
+  char strval[32];
+  char comment[FLEN_COMMENT];
+  strncpy(keyname, "CREATOR",flen_keyword); keyname[flen_keyword] = '\0';
+  strcpy(strval, "SOPHYA");
+  strcpy(comment," SOPHYA Package - FITSIOServer ");
+  fits_write_key(fptr, TSTRING, keyname, &strval, comment, &status);
+  if( status ) printerror( status );
   // close the file
   fits_close_file(fptr, &status);
+  //DBG  cerr << " DBG - Apres close status = " << status << endl;  
   if( status )  printerror( status );
 }
@@ -1420,11 +1453,11 @@
   int num = 0;
   char comment2[FLEN_COMMENT] = "x";
-  char keyname[]= "";
-  char datekey[]= "DATE";
-  char endkey[] = "END";
+  char keyname[16];
+  char * datekey= "DATE";
+  char * endkey= "END";
   char typ='x';
   int ival;
   double dval;
-  char strval[]="";
+  char strval[90];
   // on a convenu que les mots cles utilisateur sont apres le mot cle DATE
   // on va jusqu'au mot cle DATE
@@ -1437,5 +1470,5 @@
       num++;
       fits_read_record(fptr, num, card, &status);
-      strncpy(keyname,card,flen_keyword-1);
+      strncpy(keyname,card,flen_keyword-1); keyname[10] = '\0';
     }
   if (status != 0 ) 
@@ -1449,5 +1482,5 @@
       // on lit un record pour recuperer le nom du mot-cle
       fits_read_record(fptr, num, card, &status);
-      strncpy(keyname,card,flen_keyword-1);
+      strncpy(keyname,card,flen_keyword-1);  keyname[10] = '\0';
       char value[FLEN_VALUE];
       // on recupere le premier caractere du commentaire, qui contient 
@@ -1481,5 +1514,6 @@
 	      break;
 	    default :
-	      cout << " FITSIOSERVER::planck_read_img : type de donnee non prevu " << endl;
+	      //	      cout << " FITSIOSERVER::planck_read_img -> DVList Type ? for key " 
+	      //                   << (string)keyname << endl;
 	      break;
 	    }
@@ -1533,5 +1567,5 @@
    if( status )  printerror( status );
 
-  char binta[] = "BINTABLE";
+  char * binta = "BINTABLE";
   if (  strncmp(xtension, binta,8) != 0) 
     //   if (xtension !="BINTABLE")
@@ -1631,5 +1665,5 @@
   char dtype;
   //char bidon[LEN_KEYWORD];
-  char comkey[] = "COMMENT";
+  char * comkey = "COMMENT";
 
    for(int j = 1; j <= nkeys; j++)
