Index: trunk/SophyaExt/FitsIOServer/fitsioserver.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsioserver.cc	(revision 603)
+++ trunk/SophyaExt/FitsIOServer/fitsioserver.cc	(revision 605)
@@ -10,8 +10,11 @@
 //************************************************************************
 
+#include "machdefs.h" 
 #include <iostream.h>
 #include <list>
+#include <string>
 
 #include "fitsioserver.h" 
+#include "pexceptions.h" 
 #include "strutil.h"
 
@@ -49,4 +52,70 @@
 }
 
+void FitsIoServer::load(TMatrix<float>& mat,char flnm[]) 
+{
+  int nbrows=0;
+  int nbcols=0;
+  FITS_tab_typ_ = TFLOAT;
+  long naxis;
+  int n1, n2, n3;
+  DVList dvl;
+  planck_read_img(flnm, naxis, n1, n2, n3, dvl);
+
+  nbrows=n1;
+  nbcols=n2;
+  if (naxis == 1) nbcols=1;
+  if (naxis > 2) 
+    {
+      cout<<"  FitsIOServer : le fichier fits n'est pas une matrice, naxis= " <<naxis<< endl;
+    }
+
+  // number of components
+  if (mat.NRows() != nbrows || mat.NCols() != nbcols )
+    {
+      cout << " found " << nbrows << " rows ";
+      cout << "  expected " << mat.NRows()  << endl;
+      cout << " found " << nbcols << " columns " ;
+      cout << "  expected " <<  mat.NCols()  << endl;
+      mat.ReSize(nbrows,nbcols);
+      cout << " resize the vector to nbrows=  " << nbrows  << " nbcols= " << nbcols << endl;
+    }
+  int ij=0;
+  for (int j=0; j< nbcols; j++) 
+    for (int i = 0; i < nbrows; i++)  mat(i,j) = (float)r_4tab_[ij++];
+}
+
+void FitsIoServer::load(TMatrix<int_4>& mat,char flnm[]) 
+{
+  int nbrows=0;
+  int nbcols=0;
+  FITS_tab_typ_ = TINT;
+  long naxis;
+  int n1, n2, n3;
+  DVList dvl;
+  planck_read_img(flnm, naxis, n1, n2, n3, dvl);
+
+  nbrows=n1;
+  nbcols=n2;
+  if (naxis == 1) nbcols=1;
+  if (naxis > 2) 
+    {
+      cout<<"  FitsIOServer : le fichier fits n'est pas une matrice, naxis= " <<naxis<< endl;
+    }
+
+  // number of components
+  if (mat.NRows() != nbrows || mat.NCols() != nbcols )
+    {
+      cout << " found " << nbrows << " rows ";
+      cout << "  expected " << mat.NRows()  << endl;
+      cout << " found " << nbcols << " columns " ;
+      cout << "  expected " <<  mat.NCols()  << endl;
+      mat.ReSize(nbrows,nbcols);
+      cout << " resize the vector to nbrows=  " << nbrows  << " nbcols= " << nbcols << endl;
+    }
+  int ij=0;
+  for (int j=0; j< nbcols; j++) 
+    for (int i = 0; i < nbrows; i++)  mat(i,j) = (int_4)i_4tab_[ij++];
+}
+
 void FitsIoServer::load(NTuple& ntpl,char flnm[],int hdunum) 
 
@@ -80,5 +149,6 @@
     {
       printf("Error:: this HDU is not a binary table\n");
-      exit ( status );
+      throw IOExc("FitsIoServer::load(NTuple& ," + (string)flnm + ") Error Not a bin table !");
+//      exit ( status );
     }
 
@@ -276,5 +346,6 @@
 	{
 	  cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl;
-	  exit(0);
+	  throw IOExc("FitsIoServer::load(SphericalMap<double>& ," + (string)flnm + ") Error NSide<0 !");
+//	  exit(0);
 	}
       if (nside != sph.SizeIndex())
@@ -286,5 +357,5 @@
 	{
 	  cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
-	  exit(0);
+//	  exit(0);   $CHECK$   Ca peut etre OK , non ??  Reza 20/11/99
 	}
     }
@@ -320,5 +391,6 @@
 	{
 	  cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl;
-	  exit(0);
+	  throw IOExc("FitsIoServer::load(SphericalMap<float>& ," + (string)flnm + ", ) Error No resolution parameter !");
+//	  exit(0);
 	}
       if (nside != sph.SizeIndex())
@@ -330,5 +402,5 @@
 	{
 	  cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
-	  exit(0);
+//	  exit(0);   $CHECK$ - Il ne faut pas sortir, me semble-t-il , Reza 20/11/99
 	}
     }
@@ -363,5 +435,6 @@
 	{
 	  cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl;
-	  exit(0);
+	  throw IOExc("FitsIoServer::load(SphereGorski<double>& ," + (string)flnm + ", )  No resol parameter !");
+//	  exit(0);
 	}
       if (nside != sph.SizeIndex())
@@ -373,5 +446,5 @@
 	{
 	  cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
-	  exit(0);
+//	  exit(0);   $CHECK$ - ne pas sortir , Reza 20/11/99
 	}
     }
@@ -405,5 +478,6 @@
 	{
 	  cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl;
-	  exit(0);
+	  throw IOExc("FitsIoServer::load(SphericalMap<float>& ," + (string)flnm + ") No resolution param !");
+//	  exit(0);
 	}
       if (nside != sph.SizeIndex())
@@ -415,5 +489,5 @@
 	{
 	  cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
-	  exit(0);
+//	  exit(0);  $CHECK$ - Ne pas sortir , Reza 20/11/99
 	}
     }
@@ -561,5 +635,5 @@
   cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl;
   FITS_tab_typ_ = TDOUBLE;
-  if (r_8tab_ != NULL ) delete[] r_8tab_;
+  if (r_8tab_ != NULL ) { delete[] r_8tab_;  r_8tab_ = NULL; }
   r_8tab_=new r_8[nbrows*nbcols];
 
@@ -572,6 +646,49 @@
 
   planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
-  delete[] r_8tab_;
-}
+  delete[] r_8tab_;  r_8tab_ = NULL; 
+}
+
+void FitsIoServer::save( TMatrix<float>& mat, char filename[])   
+{
+  int nbrows = mat.NRows();
+  int nbcols = mat.NCols();
+  long naxis = nbcols > 1 ? 2 : 1; 
+  cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl;
+  FITS_tab_typ_ = TFLOAT;
+  if (r_4tab_ != NULL ) { delete[] r_4tab_;  r_4tab_ = NULL; }  
+  r_4tab_=new r_4[nbrows*nbcols];
+
+
+  int ij=0;
+  for (int j=0; j< nbcols; j++) 
+    for (int i = 0; i < nbrows; i++) r_4tab_[ij++]= (r_4)mat(i,j);
+
+  DVList dvl;
+
+  planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
+  delete[] r_4tab_;  r_4tab_ = NULL;
+}
+
+void FitsIoServer::save( TMatrix<int_4>& mat, char filename[])   
+{
+  int nbrows = mat.NRows();
+  int nbcols = mat.NCols();
+  long naxis = nbcols > 1 ? 2 : 1; 
+  cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl;
+  FITS_tab_typ_ = TINT;
+  if (i_4tab_ != NULL ) { delete[]  i_4tab_;   i_4tab_ = NULL; }
+  i_4tab_=new int_4[nbrows*nbcols];
+
+
+  int ij=0;
+  for (int j=0; j< nbcols; j++) 
+    for (int i = 0; i < nbrows; i++) i_4tab_[ij++]= (int_4)mat(i,j);
+
+  DVList dvl;
+
+  planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
+  delete[] i_4tab_;  i_4tab_ = NULL;
+}
+
 
 void FitsIoServer::save(NTuple& ntpl,char flnm[])
@@ -702,5 +819,5 @@
   int npixels = sph.NbPixels();
   FITS_tab_typ_ = TDOUBLE;
-  if (r_8tab_ != NULL ) delete[] r_8tab_;
+  if (r_8tab_ != NULL ) { delete[] r_8tab_;  r_8tab_ = NULL; }
   r_8tab_=new r_8[npixels];
 
@@ -754,5 +871,5 @@
   */
 
- delete[] r_8tab_;
+ delete[] r_8tab_;  r_8tab_ = NULL;
 }
 
@@ -761,5 +878,5 @@
   int npixels = sph.NbPixels();
   FITS_tab_typ_ = TFLOAT;
-  if (r_4tab_ != NULL ) delete[] r_4tab_;
+  if (r_4tab_ != NULL ) { delete[] r_4tab_;  r_4tab_ = NULL; }
   r_4tab_=new r_4[npixels];
 
@@ -771,5 +888,5 @@
 
   planck_write_img(filename, 1, npixels, 0, 0, dvl);
-  delete[] r_4tab_;
+  delete[] r_4tab_;  r_4tab_ = NULL;
 
 }
@@ -778,5 +895,5 @@
   int npixels = sph.NbPixels();
   FITS_tab_typ_ = TFLOAT;
-  if (r_4tab_ != NULL ) delete[] r_4tab_;
+  if (r_4tab_ != NULL ) { delete[] r_4tab_;  r_4tab_ = NULL; }
   r_4tab_=new r_4[npixels];
 
@@ -793,5 +910,5 @@
   char* comment1="     Sky Map Pixelisation Specific Keywords";
   planck_write_bntbl(filename, npixels, typeOfContent, extname, comment1, dvl);
-  delete[] r_4tab_;
+  delete[] r_4tab_;  r_4tab_ = NULL;
 
 }
@@ -800,5 +917,5 @@
   int npixels = sph.NbPixels();
   FITS_tab_typ_ = TDOUBLE;
-  if (r_8tab_ != NULL ) delete[] r_8tab_;
+  if (r_8tab_ != NULL ) { delete[] r_8tab_;  r_8tab_ = NULL; }
   r_8tab_=new r_8[npixels];
 
@@ -815,5 +932,5 @@
   char* comment1="     Sky Map Pixelisation Specific Keywords";
   planck_write_bntbl(filename, npixels, typeOfContent, extname, comment1, dvl);
-  delete[] r_8tab_;
+  delete[] r_8tab_;  r_8tab_ = NULL;
 
 }
@@ -826,5 +943,5 @@
   cout << " nombre de pts en x : " << nbrows << " en y  " << nbcols << endl;
   FITS_tab_typ_ = TDOUBLE;
-  if (r_8tab_ != NULL ) delete[] r_8tab_;
+  if (r_8tab_ != NULL ) { delete[] r_8tab_;  r_8tab_ = NULL; }
   r_8tab_=new r_8[nbrows*nbcols];
 
@@ -853,5 +970,6 @@
   dvl["ANGLEY"] = angley;
   planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
-  delete[] r_8tab_;}
+  delete[] r_8tab_;  r_8tab_ = NULL;
+}
 
 
@@ -894,5 +1012,5 @@
 
   // get the values of the DpcImage
-  if (r_4tab_ != NULL) delete [] r_4tab_;
+  if (r_4tab_ != NULL) { delete [] r_4tab_;  r_4tab_ = NULL; }
   r_4tab_=new r_4[siz_x*siz_y];
   PBaseDataTypes  dataT=DataType((r_4)0);
@@ -901,5 +1019,5 @@
 
 
-   delete [] r_4tab_;
+   delete [] r_4tab_;  r_4tab_ = NULL;
 }
 
@@ -954,5 +1072,5 @@
 
   // get the values of the DpcImage
-  if (i_4tab_ != NULL) delete [] i_4tab_;
+  if (i_4tab_ != NULL) { delete [] i_4tab_;  i_4tab_ = NULL; }
   i_4tab_=new int_4[siz_x*siz_y];
   PBaseDataTypes  dataT=DataType((int_4)0);
@@ -966,5 +1084,5 @@
   //if( status )  printerror( status );
 
-   delete [] i_4tab_;
+   delete [] i_4tab_;  i_4tab_ = NULL;
 }
 
@@ -1260,5 +1378,5 @@
 	       << " conversion to double will be achieved by cfitsio lib " << endl; 
 	}
-      if (r_8tab_ != NULL) delete [] r_8tab_;
+      if (r_8tab_ != NULL) { delete [] r_8tab_;  r_8tab_ = NULL; }
       r_8tab_=new r_8[nelements];
       fits_read_img(fptr, TDOUBLE, 1, nelements,  &dnullval, r_8tab_, 
@@ -1272,5 +1390,5 @@
 	       << " conversion to float will be achieved by cfitsio lib " << endl; 
 	}
-      if (r_4tab_ != NULL) delete [] r_4tab_;
+      if (r_4tab_ != NULL) { delete [] r_4tab_;  r_4tab_ = NULL; } 
       r_4tab_=new r_4[nelements];
       fits_read_img(fptr, TFLOAT, 1, nelements,  &fnullval, r_4tab_, 
@@ -1286,5 +1404,5 @@
 	       << " conversion to long will be achieved by cfitsio lib " << endl; 
 	}
-      if (i_4tab_ != NULL) delete [] i_4tab_;
+      if (i_4tab_ != NULL) { delete [] i_4tab_;  i_4tab_ = NULL; }
       i_4tab_=new int_4[nelements];
       fits_read_img(fptr, TINT, 1, nelements,  &inullval, i_4tab_, 
@@ -1400,5 +1518,6 @@
     {
       cout << "FitsIoServer:: le fichier fits ne contient pas d'extension binary table" << endl;
-      return;
+      throw IOExc("FitsIoServer::planck_read_bntbl(" + (string)flnm + ") Error No bin table extension !");
+//      return;
     }
   fits_movabs_hdu(fptr, hdunum,&hdutype,&status);
@@ -1407,5 +1526,6 @@
     {
       cout << "FitsIoServer:: this HDU is not a binary table " << endl;
-      exit(status);
+      throw IOExc("FitsIoServer::planck_read_bntbl(" + (string)flnm + ") Error Not a bin table (1) !");
+//      exit(status);
     }
    char xtension[FLEN_VALUE];
@@ -1418,5 +1538,6 @@
      {
       cout << "FitsIoServer::  not a binary table " << endl;
-      exit(status);
+      throw IOExc("FitsIoServer::planck_read_bntbl(" + (string)flnm + ") Error Not a bin table (2) !");
+//      exit(status);
      }
    fits_get_hdrpos(fptr,&nkeys,&keypos,&status);
@@ -1427,5 +1548,6 @@
     {
       cout << "FitsIoServer:: il y a plus d'une colonne" << endl;
-      return;
+      throw IOExc("FitsIoServer::planck_read_bntbl(" + (string)flnm + ") Error >1 column !");
+//      return;
     }
   fits_get_num_rows(fptr, &nrows, &status);
@@ -1461,5 +1583,5 @@
 	       << " conversion to double will be achieved by cfitsio lib " << endl; 
 	}
-      if (r_8tab_ != NULL) delete [] r_8tab_;
+      if (r_8tab_ != NULL) { delete [] r_8tab_;  r_8tab_ = NULL; }
       r_8tab_=new r_8[ npixels];
       fits_read_col(fptr, TDOUBLE, 1, 1, 1, nelements,  &dnullval, 
@@ -1475,5 +1597,5 @@
 	       << " conversion to float will be achieved by cfitsio lib " << endl; 
 	}
-      if (r_4tab_ != NULL) delete [] r_4tab_;
+      if (r_4tab_ != NULL) { delete [] r_4tab_;  r_4tab_ = NULL; }
       r_4tab_=new r_4[nelements];
       fits_read_col(fptr, TFLOAT, 1, 1, 1, nelements,  &fnullval, 
@@ -1489,5 +1611,5 @@
 	       << " conversion to long will be achieved by cfitsio lib " << endl; 
 	}
-      if (i_4tab_ != NULL) delete [] i_4tab_;
+      if (i_4tab_ != NULL) { delete [] i_4tab_;  i_4tab_ = NULL; }
       i_4tab_=new int_4[nelements];
       fits_read_col(fptr, TLONG, 1, 1, 1, nelements,  &inullval, 
Index: trunk/SophyaExt/FitsIOServer/fitsioserver.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsioserver.h	(revision 603)
+++ trunk/SophyaExt/FitsIOServer/fitsioserver.h	(revision 605)
@@ -28,4 +28,6 @@
 
  void load(TMatrix<double>& mat, char flnm[]);
+ void load(TMatrix<float>& mat, char flnm[]);
+ void load(TMatrix<int_4>& mat, char flnm[]);
  void load(NTuple& ntpl,char flnm[],int hdunum);
  void load(SphericalMap<double>& sph, char flnm[]);
@@ -34,7 +36,9 @@
  void load(ImageR4& DpcImg,char flnm[]);
  void load(ImageI4& DpcImg,char flnm[]);
- void load(SphereGorski<float>& sph, char flnm[], int hdunum); 
- void load(SphereGorski<double>& sph, char flnm[], int hdunum); 
+ void load(SphereGorski<float>& sph, char flnm[], int hdunum=2); 
+ void load(SphereGorski<double>& sph, char flnm[], int hdunum=2); 
  void save(TMatrix<double>& mat, char flnm[]);
+ void save(TMatrix<float>& mat, char flnm[]);
+ void save(TMatrix<int_4>& mat, char flnm[]);
  void save(NTuple& ntpl,char flnm[]);
  void save(SphericalMap<double>& sph, char flnm[]);
