Index: trunk/SophyaExt/FitsIOServer/fitsioserver.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsioserver.cc	(revision 482)
+++ trunk/SophyaExt/FitsIOServer/fitsioserver.cc	(revision 488)
@@ -1,5 +1,6 @@
 //************************************************************************
 // Class for loadind and saving from FITS-formatted file to DPC objects
-// 
+//    (G. Le Meur ; Francois Touze)  OCT. 99
+//
 // methods 'load(X& x, char f[])' get from FITS file "f" a DPC object x 
 // from DPC  class X.
@@ -28,31 +29,4 @@
   nbcols=n2;
   if (naxis == 1) nbcols=1;
-  //dvl.Print();
-  DVList::ValList::const_iterator it;
-  for(it = dvl.Begin(); it != dvl.End(); it++)  
-    {
-      char datatype= (*it).second.typ;
-      char keyname[]="";
-      strcpy(keyname, (*it).first.substr(0,64).c_str());   
-      int ival=0;
-      double dval=0.;
-      char strval[]="";
-      switch (datatype)
-	{
-	case 'I' :
-	  ival=(*it).second.mtv.iv;
-	  break;
-	case 'D' :
-	  dval=(*it).second.mtv.dv;
-	  break;
-	case 'S' :
-	  strcpy(strval, (*it).second.mtv.strv); 
-	  break;
-	default :
-	  cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;
-	  break;
-	}
-    }
-
   if (naxis > 2) 
     {
@@ -72,5 +46,5 @@
   int ij=0;
   for (int j=0; j< nbcols; j++) 
-    for (int i = 0; i < nbrows; i++)  mat(i,j) = dtab_[ij++];
+    for (int i = 0; i < nbrows; i++)  mat(i,j) = (double)r_8tab_[ij++];
 }
 
@@ -100,12 +74,4 @@
     printerror( status );
 
-  /*
-  printf("Move to extensions by name and version number: (ffmnhd)\n");
-  char* binname= "Test-BINTABLE";
-  int extvers = 1;
-  fits_movnam_hdu(fptr,ANY_HDU, binname,extvers,&status);
-  fits_get_hdu_num(fptr,&hdunum);
-  printf(" %s, %ld = hdu %d, %d\n", binname, extvers, hdunum, status);
-  */
 
   if (hdutype == BINARY_TBL)
@@ -128,6 +94,4 @@
      printerror( status );
    int nrows= naxis[1];
-
-   printf("\nInformation about each column:\n");
 
    //Information about each column
@@ -151,8 +115,8 @@
    num += nfound;
 
-   for(int ii = 0; ii < tfields; ii++)
-     printf("\nColumn name & Format %8s %8s", ttype[ii],tform[ii]);
+   //for(int ii = 0; ii < tfields; ii++)
+   //  printf("\nColumn name & Format %8s %8s", ttype[ii],tform[ii]);
   
-   // select the columns with float data values (typecode = 42)
+   // select the columns with float data values 
    int typecode;
    long repeat,width;
@@ -162,5 +126,5 @@
        fits_binary_tform(tform[ii],&typecode, &repeat, &width, &status);
        //printf("\n%4s %3d %2ld %2ld", tform[ii], typecode, repeat, width);
-       if(typecode == 42) 
+       if(typecode == TFLOAT) 
 	 column.push_back(ii+1);
      }
@@ -176,4 +140,13 @@
    for(itr= column.begin(); itr != column.end(); itr++)
      strcpy(clname[index++],ttype[*itr-1]);
+
+   for( int ii = 0; ii < tfields; ii++)
+     {
+       delete [] ttype[ii];
+       delete [] tform[ii];
+     }
+   delete [] ttype;
+   delete [] tform;
+   
 
    // check if the specified keyword BLK exists
@@ -184,7 +157,10 @@
 	 printerror( status );
      }
-  
    // create a NTuple
    NTuple nt0(column.size(),clname,blk);
+
+   for(int ii = 0; ii < column.size(); ii++)
+     delete [] clname[ii];
+   delete [] clname;
 
    float value[1];
@@ -278,7 +254,18 @@
   int npixels=0;
   int nside=0;
+  long naxis;
+  int n1, n2, n3;
+
   FITS_tab_typ_ = TDOUBLE;
-  read_sphere(flnm, npixels, nside);
-
+
+  DVList dvl;
+  planck_read_img(flnm, naxis, n1, n2, n3, dvl);
+  if (naxis != 1) 
+    {
+      cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl;
+    }
+  npixels=n1;
+  nside= dvl.GetI("NSIDE");
+  
   // number of pixels in the sphere
   if (sph.NbPixels() != npixels)
@@ -302,5 +289,5 @@
 	}
     }
-  for (int j = 0; j < sph.NbPixels(); j++) sph(j)= dtab_[j];
+  for (int j = 0; j < sph.NbPixels(); j++) sph(j)= (double)r_8tab_[j];
 }
 void FitsIoServer::load(SphericalMap<float>& sph, char flnm[]) 
@@ -308,6 +295,18 @@
   int npixels=0;
   int nside=0;
+  long naxis;
+  int n1, n2, n3;
+  DVList dvl;
+
   FITS_tab_typ_ = TFLOAT;
-  read_sphere(flnm, npixels, nside);
+
+  planck_read_img(flnm, naxis, n1, n2, n3, dvl);
+  if (naxis != 1) 
+    {
+      cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl;
+    }
+  npixels=n1;
+  nside= dvl.GetI("NSIDE");
+
   // number of pixels in the sphere
   if (sph.NbPixels() != npixels)
@@ -331,10 +330,9 @@
 	}
     }
-  for (int j = 0; j < sph.NbPixels(); j++) sph(j)= ftab_[j];
+  for (int j = 0; j < sph.NbPixels(); j++) sph(j)= (float)r_4tab_[j];
 }
 
 void FitsIoServer::load(LocalMap<double>& lcm, char flnm[]) 
 {
-  int nside;
   int nbrows=0;
   int nbcols=0;
@@ -350,38 +348,4 @@
     {
       cout<<" FitsIOServer : le fichier fits n'est pas une localmap, naxis= "<<naxis<<endl;
-    }
-  //dvl.Print();
-  DVList::ValList::const_iterator it;
-  for(it = dvl.Begin(); it != dvl.End(); it++)  
-    {
-      char datatype= (*it).second.typ;
-      char keyname[]="";
-      strcpy(keyname, (*it).first.substr(0,64).c_str());   
-      int ival=0;
-      double dval=0.;
-      char strval[]="";
-      switch (datatype)
-	{
-	case 'I' :
-	  ival=(*it).second.mtv.iv;
-	  break;
-	case 'D' :
-	  dval=(*it).second.mtv.dv;
-	  break;
-	case 'S' :
-	  strcpy(strval, (*it).second.mtv.strv); 
-	  break;
-	default :
-	  cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;
-	  break;
-	}
-      if (!strcmp(keyname, "NSIDE") )
-	{
-	  nside = ival;
-	} 
-      //if (!strcmp(keyname, "ORDERING") )
-      //	{
-      //  cout << " j'ai trouve ORDERING " << endl;
-      //	} 
     }
   float theta0 = dvl.GetD("THETA0");
@@ -410,5 +374,5 @@
   int ij=0;
   for (int j=0; j< nbcols; j++) 
-    for (int i = 0; i < nbrows; i++)  lcm(i,j) = dtab_[ij++];
+    for (int i = 0; i < nbrows; i++)  lcm(i,j) = (double)r_8tab_[ij++];
 }
 
@@ -432,5 +396,4 @@
   DpcImg.Allocate(siz_x, siz_y, 0., 0);
   float* pixelPtr=DpcImg.ImagePtr();
-  //for (int i=0; i < siz_x*siz_y; i++) pixelPtr[i]=ftab_[i];
   // verifications de type
   PBaseDataTypes  dataT=DataType((r_4)0);
@@ -438,9 +401,9 @@
   if (int(dataT) !=  TypeDonnees)
     {
-      cout << " FitsIOServer : parameter DATATYPE on file is not float " << endl;
+      cout << " FitsIOServer : parameter DATATYPE on file " << flnm << " is not float " << endl;
       cout << "  eventual conversion to float is achieved by cfitsio lib " << endl;
     }
 
-  memcpy(pixelPtr, ftab_, siz_x*siz_y*DataSize(dataT));
+  memcpy(pixelPtr, r_4tab_, siz_x*siz_y*DataSize(dataT));
   const char* nom=dvl.GetS("NAME").c_str();
   DpcImg.SetNameId(dvl.GetI("IDENT"), nom);
@@ -489,6 +452,6 @@
   if (int(dataT) !=  TypeDonnees)
     {
-      cout << " FitsIOServer : parameter DATATYPE on file is not int_4 " << endl;
-      cout << "  eventual conversion to float is achieved by cfitsio lib " << endl;
+      cout << " FitsIOServer : parameter DATATYPE on file " << flnm << " is not int_4 " << endl;
+      cout << "  eventual conversion to int_4 is achieved by cfitsio lib " << endl;
     }
   memcpy(pixelPtr, i_4tab_, siz_x*siz_y*DataSize(dataT));
@@ -510,16 +473,16 @@
   cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl;
   FITS_tab_typ_ = TDOUBLE;
-  if (dtab_ != NULL ) delete[] dtab_;
-  dtab_=new double[nbrows*nbcols];
+  if (r_8tab_ != NULL ) delete[] r_8tab_;
+  r_8tab_=new r_8[nbrows*nbcols];
 
 
   int ij=0;
   for (int j=0; j< nbcols; j++) 
-    for (int i = 0; i < nbrows; i++) dtab_[ij++]= mat(i,j);
+    for (int i = 0; i < nbrows; i++) r_8tab_[ij++]= (r_8)mat(i,j);
 
   DVList dvl;
 
   planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
-
+  delete[] r_8tab_;
 }
 
@@ -568,4 +531,13 @@
 		       NULL,extname,&status) )
     printerror( status );
+
+  for( int ii = 0; ii < tfields; ii++)
+    {
+      delete [] ttype[ii];
+      delete [] tform[ii];
+    }
+  delete [] ttype;
+  delete [] tform;
+
 
   // first row in table to write
@@ -642,9 +614,9 @@
   int npixels = sph.NbPixels();
   FITS_tab_typ_ = TDOUBLE;
-  if (dtab_ != NULL ) delete[] dtab_;
-  dtab_=new double[npixels];
-
-
-  for (int j = 0; j < npixels; j++) dtab_[j]= sph(j);
+  if (r_8tab_ != NULL ) delete[] r_8tab_;
+  r_8tab_=new r_8[npixels];
+
+
+  for (int j = 0; j < npixels; j++) r_8tab_[j]= (r_8)sph(j);
   DVList dvl;
   dvl["NSIDE"] = sph.SizeIndex();
@@ -694,5 +666,5 @@
   */
 
-
+ delete[] r_8tab_;
 }
 
@@ -701,9 +673,9 @@
   int npixels = sph.NbPixels();
   FITS_tab_typ_ = TFLOAT;
-  if (ftab_ != NULL ) delete[] ftab_;
-  ftab_=new float[npixels];
-
-
-  for (int j = 0; j < npixels; j++) ftab_[j]= sph(j);
+  if (r_4tab_ != NULL ) delete[] r_4tab_;
+  r_4tab_=new r_4[npixels];
+
+
+  for (int j = 0; j < npixels; j++) r_4tab_[j]= (r_4)sph(j);
   DVList dvl;
   dvl["NSIDE"] = sph.SizeIndex();
@@ -711,5 +683,5 @@
 
   planck_write_img(filename, 1, npixels, 0, 0, dvl);
-
+  delete[] r_4tab_;
 
 }
@@ -722,10 +694,10 @@
   cout << " nombre de pts en x : " << nbrows << " en y  " << nbcols << endl;
   FITS_tab_typ_ = TDOUBLE;
-  if (dtab_ != NULL ) delete[] dtab_;
-  dtab_=new double[nbrows*nbcols];
+  if (r_8tab_ != NULL ) delete[] r_8tab_;
+  r_8tab_=new r_8[nbrows*nbcols];
 
   int ij=0;
   for (int j=0; j< nbcols; j++) 
-    for (int i = 0; i < nbrows; i++) dtab_[ij++]= locm(i,j);
+    for (int i = 0; i < nbrows; i++) r_8tab_[ij++]= (r_8)locm(i,j);
 
   DVList dvl;
@@ -749,8 +721,8 @@
   dvl["ANGLEY"] = angley;
   planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
-}
-
-
-void FitsIoServer::save(ImageR4& DpcImg,char flnm[])
+  delete[] r_8tab_;}
+
+
+void FitsIoServer::save(const ImageR4& DpcImg,char flnm[])
 {
   long naxis=2;
@@ -761,7 +733,4 @@
 
 
-  // get the values of the DpcImage
-  if (ftab_ != NULL) delete [] ftab_;
-  ftab_=DpcImg.ImagePtr();
 
   // write FITS image
@@ -784,13 +753,17 @@
   dvl["SIGFON"] = DpcImg.sigmaFond;
 
-
+  // get the values of the DpcImage
+  if (r_4tab_ != NULL) delete [] r_4tab_;
+  r_4tab_=new r_4[siz_x*siz_y];
+  PBaseDataTypes  dataT=DataType((r_4)0);
+  memcpy( r_4tab_, DpcImg.ImagePtr(), siz_x*siz_y*DataSize(dataT));
   planck_write_img(flnm, naxis, siz_x, siz_y, 0, dvl);
 
 
-  ftab_=NULL;
-}
-
-
-void FitsIoServer::save(ImageI4& DpcImg,char flnm[])
+   delete [] r_4tab_;
+}
+
+
+void FitsIoServer::save(const ImageI4& DpcImg,char flnm[])
 {
   long naxis=2;
@@ -813,7 +786,4 @@
   //if( status )  printerror( status );
 
-  // get the values of the DpcImage
-  if (i_4tab_ != NULL) delete [] i_4tab_;
-  i_4tab_=DpcImg.ImagePtr();
 
   // write FITS image
@@ -836,4 +806,10 @@
   dvl["SIGFON"] = DpcImg.sigmaFond;
 
+  // get the values of the DpcImage
+  if (i_4tab_ != NULL) delete [] i_4tab_;
+  i_4tab_=new int_4[siz_x*siz_y];
+  PBaseDataTypes  dataT=DataType((int_4)0);
+  memcpy( i_4tab_, DpcImg.ImagePtr(), siz_x*siz_y*DataSize(dataT));
+
 
   planck_write_img(flnm, naxis, siz_x, siz_y, 0, dvl);
@@ -843,5 +819,5 @@
   //if( status )  printerror( status );
 
-  i_4tab_=NULL;
+   delete [] i_4tab_;
 }
 
@@ -852,5 +828,4 @@
 {
 
-  cout << " nouveau write_img" << endl;
 
   // pointer to the FITS file, defined in fitsio.h
@@ -888,9 +863,9 @@
     {
     case TDOUBLE :
-      fits_write_img(fptr, TDOUBLE, 1, nelements, dtab_,  &status); 
+      fits_write_img(fptr, TDOUBLE, 1, nelements, r_8tab_,  &status); 
       if( status ) printerror( status );
       break;
     case TFLOAT :
-      fits_write_img(fptr, TFLOAT, 1, nelements, ftab_,  &status); 
+      fits_write_img(fptr, TFLOAT, 1, nelements, r_4tab_,  &status); 
       if( status ) printerror( status );
       break;
@@ -985,6 +960,7 @@
   if (naxis == 3)  nelements*=naxes[2];
   int anynull;
-  double dnullval=0.;
-  float fnullval=0.;
+  r_8 dnullval=0.;
+  r_4 fnullval=0.;
+  int_4 inullval=0;
   // on laisse a fits le soin de convertir le type du tableau lu vers
   // le type suppose par l'utilisateur de fitsioserver 
@@ -995,10 +971,10 @@
       if (bitpix !=  DOUBLE_IMG) 
 	{
-	  cout << " FitsIOServer : the data type on fits file is not double, "
+	  cout << " FitsIOServer : the data type on fits file " << flnm << " is not double, "
 	       << " conversion to double will be achieved by cfitsio lib " << endl; 
 	}
-      if (dtab_ != NULL) delete [] dtab_;
-      dtab_=new double[nelements];
-      fits_read_img(fptr, TDOUBLE, 1, nelements,  &dnullval, dtab_, 
+      if (r_8tab_ != NULL) delete [] r_8tab_;
+      r_8tab_=new r_8[nelements];
+      fits_read_img(fptr, TDOUBLE, 1, nelements,  &dnullval, r_8tab_, 
 		    &anynull, &status);
       if( status )  printerror( status );
@@ -1007,10 +983,10 @@
       if (bitpix !=  FLOAT_IMG) 
 	{
-	  cout << " FitsIOServer : the data type on fits file is not float, "
+	  cout << " FitsIOServer : the data type on fits file " << flnm << " is not float, "
 	       << " conversion to float will be achieved by cfitsio lib " << endl; 
 	}
-      if (ftab_ != NULL) delete [] ftab_;
-      ftab_=new float[nelements];
-      fits_read_img(fptr, TFLOAT, 1, nelements,  &fnullval, ftab_, 
+      if (r_4tab_ != NULL) delete [] r_4tab_;
+      r_4tab_=new r_4[nelements];
+      fits_read_img(fptr, TFLOAT, 1, nelements,  &fnullval, r_4tab_, 
 		    &anynull, &status);
       if( status )  printerror( status );
@@ -1021,10 +997,10 @@
       if (bitpix !=  LONG_IMG) 
 	{
-	  cout << " FitsIOServer : the data type on fits file is not long, "
+	  cout << " FitsIOServer : the data type on fits file " << flnm << " is not long, "
 	       << " conversion to long will be achieved by cfitsio lib " << endl; 
 	}
       if (i_4tab_ != NULL) delete [] i_4tab_;
       i_4tab_=new int_4[nelements];
-      fits_read_img(fptr, TINT, 1, nelements,  &fnullval, i_4tab_, 
+      fits_read_img(fptr, TINT, 1, nelements,  &inullval, i_4tab_, 
 		    &anynull, &status);
       if( status )  printerror( status );
@@ -1107,4 +1083,5 @@
     }
 
+
   // close the file
   status=0;
@@ -1213,53 +1190,4 @@
 }
 
-void  FitsIoServer::read_sphere(char flnm[], int& npixels, int& nside)
-{
-  long naxis;
-  nside=0;
-  int n1, n2, n3;
-  DVList dvl;
-  planck_read_img(flnm, naxis, n1, n2, n3, dvl);
-
-  npixels=n1;
-  //dvl.Print();
-  DVList::ValList::const_iterator it;
-  for(it = dvl.Begin(); it != dvl.End(); it++)  
-    {
-      char datatype= (*it).second.typ;
-      char keyname[]="";
-      strcpy(keyname, (*it).first.substr(0,64).c_str());   
-      int ival=0;
-      double dval=0.;
-      char strval[]="";
-      switch (datatype)
-	{
-	case 'I' :
-	  ival=(*it).second.mtv.iv;
-	  break;
-	case 'D' :
-	  dval=(*it).second.mtv.dv;
-	  break;
-	case 'S' :
-	  strcpy(strval, (*it).second.mtv.strv); 
-	  break;
-	default :
-	  cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;
-	  break;
-	}
-      if (!strcmp(keyname, "NSIDE") )
-	{
-	  nside = ival;
-	} 
-      //if (!strcmp(keyname, "ORDERING") )
-      //	{
-      //	  cout << " j'ai trouve ORDERING " << endl;
-      //	} 
-    }
-
-  if (naxis != 1) 
-    {
-      cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl;
-    }
-}
 
 
Index: trunk/SophyaExt/FitsIOServer/fitsioserver.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsioserver.h	(revision 482)
+++ trunk/SophyaExt/FitsIOServer/fitsioserver.h	(revision 488)
@@ -18,10 +18,10 @@
 public :
 
-  FitsIoServer() : FITS_tab_typ_(0),i_4tab_(NULL),ftab_(NULL),dtab_(NULL) {;}
+  FitsIoServer() : FITS_tab_typ_(0),i_4tab_(NULL),r_4tab_(NULL),r_8tab_(NULL) {;}
  ~FitsIoServer()
    {
      if (i_4tab_ != NULL) delete [] i_4tab_;
-     if (ftab_ != NULL) delete [] ftab_;
-     if (dtab_ != NULL) delete [] dtab_;
+     if (r_4tab_ != NULL) delete [] r_4tab_;
+     if (r_8tab_ != NULL) delete [] r_8tab_;
    }
 
@@ -38,6 +38,6 @@
  void save(SphericalMap<float>& sph, char flnm[]);
  void save(LocalMap<double>& locm, char flnm[]);
- void save(ImageR4& DpcImg,char flnm[]);
- void save(ImageI4& DpcImg,char flnm[]);
+ void save(const ImageR4& DpcImg,char flnm[]);
+ void save(const ImageI4& DpcImg,char flnm[]);
  void sinus_picture_projection(SphericalMap<double>& sph, char flnm[]);
  void sinus_picture_projection(SphericalMap<float>& sph, char flnm[]);
@@ -50,5 +50,4 @@
  private :
   
- void read_sphere(char flnm[],int& npixels,int& nside);
 
  // creer, ecrire une imageformat FITS, a partir des tableaux de donnees 
@@ -81,6 +80,6 @@
  int FITS_tab_typ_;
  int_4* i_4tab_;
- float* ftab_;
- double* dtab_;
+ r_4* r_4tab_;
+ r_8* r_8tab_;
 };
 
