Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1720)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1752)
@@ -839,9 +839,9 @@
       //	  status = 0;
       //	}
-      if (nentries != nrows_*repeat)
-	{
-	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
-	  throw PException(" FitsFile:::GetBinTabFCol ");
-	}
+      //   if (nentries != nrows_*repeat)
+      //	{
+      //	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
+	  //	  throw PException(" FitsFile:::GetBinTabFCol ");
+      //	}
       fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
 			    &anull,&status);
@@ -878,9 +878,9 @@
       //	  status = 0;
       //	}
-      if (nentries != nrows_*repeat)
-	{
-	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
-	  throw PException(" FitsFile:::GetBinTabFCol ");
-	}
+      //  if (nentries != nrows_*repeat)
+      //	{
+      //	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
+	  //	  throw PException(" FitsFile:::GetBinTabFCol ");
+      //	}
       fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
 			    &anull,&status);
@@ -899,7 +899,8 @@
       long repeat,width;
       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT ) 
-	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
+      cout << " en lecture fits trouve le type " << DTYPE << endl;
+      if( DTYPE != TLONG &&  DTYPE != TINT) 
+	{
+	  throw IOExc("FitsFile::GetBinTabFCol, probleme de lecture d'entiers");
 	}
       long nels=nentries;
@@ -913,9 +914,13 @@
       //	  status = 0;
       //	}
-      if (nentries != nrows_*repeat)
-	{
-	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
-	  throw PException(" FitsFile:::GetBinTabFCol ");
-	}
+      // if (nentries != nrows_*repeat)
+      //	{
+      //	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
+	  //	  throw PException(" FitsFile:::GetBinTabFCol ");
+      //	}
+
+
+
+      // voir commentaire dans putColToFits()
       fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
 			    &anull,&status);
@@ -942,9 +947,9 @@
       int    anull;
       char* cnull= "";
-      if (nentries != nrows_*repeat/width)
-	{
-	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat/width << endl;
-	  throw PException(" FitsFile:::GetBinTabFCol ");
-	}
+      // if (nentries != nrows_*repeat/width)
+      //	{
+      //	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat/width << endl;
+	  //	  throw PException(" FitsFile:::GetBinTabFCol ");
+      //	}
       long frow=1;
       long felem=1;
@@ -1623,5 +1628,5 @@
   //  for (int toto=0; toto < 10; toto++) cout << donnees[toto] << endl;
   fits_write_col(fptr_,TDOUBLE,nocol+1,1,1,nentries, donnees ,&status);
-  if( status )  printerror( status,"erreur ecriture du fichier fits" );
+  if( status )  printerror( status,"erreur ecriture col. double, dans fichier fits" );
 }
 
@@ -1656,5 +1661,5 @@
     } 
   fits_write_col(fptr_,TFLOAT,nocol+1,1,1,nentries, donnees ,&status);
-  if( status )  printerror( status,"erreur ecriture du fichier fits" );
+  if( status )  printerror( status,"erreur ecriture col. floats, dans fichier fits" );
 }
 
@@ -1683,10 +1688,26 @@
   long repeat, width;
   fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
-  if( code != TLONG &&  code != TINT &&  code != TSHORT ) 
-    {
-      cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl;
+    
+
+// la logique voudrait qu'on distingue TLONG et TINT. Mais si j'ecris 
+// et relis immediatement quelque chose en TLONG l'experience montre 
+// que ca foire. Donc, je fais tout en TINT, d'ailleurs cfitsio n'a pas
+// (apparemment) d'entiers de longueur superieure a 32 bits.
+// En fait, je n'y comprend rien. A suivre (GLM).
+  if (code == TINT || code == TLONG )
+    {
+      cout << " j'ecris des TINT" << endl;
+      fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status);
+    }
+  else if (code == TSHORT) 
+    {
+      cout << " j'ecris des TSHORT " << endl;
+      fits_write_col(fptr_,TSHORT,nocol+1,1,1,nentries, donnees ,&status);
+    }
+  else
+    {
+      cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= integers " << endl;
     } 
-  fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status);
-  if( status )  printerror( status," ecriture du fichier fits" );
+  if( status )  printerror( status,"erreur ecriture col. entiers, dans fichier fits" );
 }
 
@@ -1719,5 +1740,5 @@
     } 
   fits_write_col(fptr_,TSTRING,nocol+1,1,1,nentries, donnees ,&status);
-  if( status )  printerror( status,"erreur ecriture du fichier fits" );
+  if( status )  printerror( status,"erreur ecriture col. chars, dans fichier fits" );
 }
 
Index: trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h	(revision 1720)
+++ trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h	(revision 1752)
@@ -30,6 +30,5 @@
 void Mollweide_picture_projection(char flnm[]);
 void sinus_picture_projection(char flnm[]);
- void ReWriteFromFitsToFits(FitsInFile& headerin, FitsOutFile& os); 
-
+//void ReWriteFromFitsToFits(FitsInFile& headerin, FitsOutFile& os); 
 
 inline operator SphereHEALPix<T>() { return(*dobj_); }
Index: trunk/SophyaExt/FitsIOServer/fitsspherethetaphi.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsspherethetaphi.cc	(revision 1752)
+++ trunk/SophyaExt/FitsIOServer/fitsspherethetaphi.cc	(revision 1752)
@@ -0,0 +1,272 @@
+#include "pexceptions.h"
+#include "fitsspherethetaphi.h"
+#include "tarray.h"
+#include "fitstarray.h" 
+
+
+
+///////////////////////////////////////////////////////////////////////
+// ----objets delegues  pour la gestion de persistance I/O format fits--
+// SphereThetaPhi
+////////////////////////////////////////////////////////////////////
+
+/*!
+  \class SOPHYA::FITS_SphereThetaPhi
+  \ingroup FitsIOServer
+  FITS format I/O handler for SOPHYA::SphereThetaPhi objects.
+*/
+
+template <class T>
+FITS_SphereThetaPhi<T>::FITS_SphereThetaPhi()
+{
+  dobj_= new SphereThetaPhi<T>;
+  ownobj_= true;
+}
+
+template <class T>
+FITS_SphereThetaPhi<T>::FITS_SphereThetaPhi(char inputfile[],int hdunum)
+{
+    dobj_= new SphereThetaPhi<T>;
+    ownobj_= true;
+  Read(inputfile,hdunum);
+}
+
+template <class T>
+FITS_SphereThetaPhi<T>::FITS_SphereThetaPhi(const SphereThetaPhi<T>& obj)
+{
+   dobj_= new SphereThetaPhi<T>(obj);
+  ownobj_= true;
+}
+
+template <class T>
+FITS_SphereThetaPhi<T>::FITS_SphereThetaPhi(SphereThetaPhi<T>* obj)
+{
+  dobj_= obj;
+  ownobj_= false;
+}
+
+template <class T>
+FITS_SphereThetaPhi<T>::~FITS_SphereThetaPhi()
+{
+  if (ownobj_ && dobj_) delete dobj_;
+}
+
+template <class T>
+AnyDataObj* FITS_SphereThetaPhi<T>::DataObj()
+{
+  return(dobj_);
+}
+
+template <class T>
+void FITS_SphereThetaPhi<T>::SetDataObj(AnyDataObj & o)
+{
+  SphereThetaPhi<T> * po = dynamic_cast< SphereThetaPhi<T> * >(&o);
+  if (po == NULL) return;
+  if (ownobj_ && dobj_) delete dobj_;
+  dobj_ = po; 
+  ownobj_ = false;
+} 
+
+template <class T>
+void FITS_SphereThetaPhi<T>::WriteToFits(FitsOutFile& os) 
+{
+  if(dobj_ == NULL) 
+    { 
+      cout << " WriteToFits:: dobj_= null " << endl;
+      return;
+    }
+
+  DVList dvl( dobj_->Info() );  
+
+  SphereCoordSys* cs= dobj_->GetCoordSys();
+  string description= cs->description();
+  dvl["COORDSYS"]= description;
+
+  dvl["PIXTYPE"] = "TETAFI";
+  dvl.SetComment("PIXTYPE", "Theta-Phi-LAL Pixelization");
+  dvl["ORDERING"]= dobj_->TypeOfMap();
+  dvl.SetComment("ORDERING", " (unrelevant) ");
+
+  int IndTheta= dobj_->SizeIndex();
+  dvl["INDTHMAX"]= (int_4) IndTheta;
+  dvl.SetComment("INDTHMAX","Resolution parameter for Theta-Phi pixelization sch." );
+
+  int nPix= dobj_->NbPixels();
+  dvl["FIRSTPIX"]= (int_4) 0;
+  dvl.SetComment("FIRSTPIX", "First pixel # (0 based)");
+  dvl["LASTPIX"]= (int_4) nPix-1;
+  dvl.SetComment("LASTPIX", "Last pixel # (0 based)");
+  dvl["Content"]= "SphereThetaPhi";
+  dvl.SetComment("Content", "name of SOPHYA object");
+  
+  // On ecrit les dataBlocks 
+  vector<string> Noms(4);   
+  Noms[0] = dvl.GetS("Content");
+  Noms[1] = "NphiParBande";
+  Noms[2] = "CumulPixParBande";
+  Noms[3] = "ThetaBande";
+  string extname("SIMULATION");
+
+
+  string Type;
+  if (typeid(T) == typeid(r_8) ) Type+='D';
+  else 
+    if (typeid(T) == typeid(r_4) )  Type+='E';
+    else
+      {
+	cout <<  " type de la sphere= " <<  typeid(T).name() << endl;
+	throw IOExc("FITS_SphereThetaPhi:: unknown type");
+      }
+
+  Type += 'J';
+  Type += 'J';
+  Type += 'D';
+
+  vector<int> dummy;
+  os.makeHeaderBntblOnFits(Type, Noms, nPix, 4, &dvl, extname, dummy);
+  os.PutColToFits(0,  nPix, dobj_->pixels_.Data()); 
+  os.PutColToFits(1,  IndTheta+1, dobj_->NPhi_.Data()); 
+  os.PutColToFits(2,  IndTheta+1, dobj_->TNphi_.Data()); 
+  os.PutColToFits(3,  IndTheta+1, dobj_->Theta_.Data()); 
+}
+
+template <class T> 
+void FITS_SphereThetaPhi<T>::ReadFromFits(FitsInFile& is)
+{
+
+  if(dobj_ == NULL) 
+    {
+      dobj_= new SphereThetaPhi<T>;
+      ownobj_= true;      
+    }
+  int nbcols, nbentries;
+
+  nbcols = is.NbColsFromFits();
+  if (nbcols != 4) 
+    {
+      throw IOExc("le fichier fits n'est pas une sphere ThetaPhi");
+    }
+  DVList dvl=is.DVListFromFits();
+  nbentries = is.NentriesFromFits(0);
+  int lastpix=dvl.GetI("LASTPIX");
+  if (lastpix>0)
+    {
+      if (nbentries!=lastpix+1) 
+	{
+	  nbentries=lastpix+1;
+      	}
+    }
+  
+  // Let's Read the SphereCoordSys object
+  int id= SphereCoordSys_NEUTRAL;
+  string description= "NEUTRAL SphereCoordSystem";
+  string coordsys= dvl.GetS("COORDSYS");
+  if(coordsys.substr(0,8) == "ROTATION")
+    {
+      id= SphereCoordSys_ROTATION;
+      description= "ROTATION SphereCoordSystem";
+    } 
+  else if(coordsys.substr(0,5)  == "OTHER" )
+    {
+      id= SphereCoordSys_OTHER;
+      description= "OTHER SphereCoordSystem";
+    }
+  dobj_->SetCoordSys(new SphereCoordSys(id,description));   
+  
+  int IndThetaMax= dvl.GetI("INDTHMAX");
+  int nPix = 0;
+  if(IndThetaMax <= 0)
+    {
+      throw IOExc("FITS_SphereTheta:: No resol parameter INDTHMAX");
+    }
+  nPix = nbentries;
+  double Omega= 4.0*Pi/nPix;
+  dobj_->setParameters(IndThetaMax,nPix,Omega);
+  
+  // On lit les DataBlocks;
+  //
+  dobj_->pixels_.ReSize(nPix);
+  is.GetBinTabFCol(dobj_->pixels_.Data(),nPix,0);
+  dobj_->NPhi_.ReSize(IndThetaMax+1);
+  is.GetBinTabFCol(dobj_->NPhi_.Data(),IndThetaMax+1,1);
+  dobj_->TNphi_.ReSize(IndThetaMax+1);
+  is.GetBinTabFCol(dobj_->TNphi_.Data(),IndThetaMax+1,2);
+  dobj_->Theta_.ReSize(IndThetaMax+1);
+  is.GetBinTabFCol(dobj_->Theta_.Data(),IndThetaMax+1,3);
+}
+
+template <class T>
+void FITS_SphereThetaPhi<T>::Mollweide_picture_projection(char filename[])
+{
+  int ni = 300;
+  int nj = 600;
+  TMatrix<float> map(ni, nj);
+
+   int i,j;
+   for(i=0; i < ni; i++) 
+     {
+       double yd = (i+0.5)/ni-0.5;
+       double facteur=2.*Pi/sin(acos(yd*2));
+       double theta = (0.5-yd)*Pi;
+       for(j=0; j < nj; j++)  
+	 {
+	   double xa = (j+0.5)/nj-0.5;
+	   double phi =  xa*facteur+Pi;
+	   float th=float(theta);
+	   float ff=float(phi);
+	   if (phi<2*Pi && phi>= 0) 
+	     {
+	       map(i,j) = (float)dobj_->PixValSph(th, ff);
+	     }
+	 }
+     }
+   FitsOutFile  fout(filename);
+   fout.firstImageOnPrimaryHeader(true);
+   FITS_TArray<r_4> fta(map);
+   fta.Write(fout);
+   
+}
+template <class T>
+void FITS_SphereThetaPhi<T>::sinus_picture_projection(char filename[])
+{
+  int ni = 300;
+  int nj = 600;
+  TMatrix<float> map(ni, nj);
+
+  int i,j;
+   for(i=0; i < ni; i++) 
+     {
+       double yd = (i+0.5)/ni-0.5;
+       double theta = (0.5-yd)*Pi;
+	double facteur=1./sin(theta);
+       for(j=0; j < nj; j++)  
+	 {
+	   double xa = (j+0.5)/nj-0.5;
+	   double phi = 2.*Pi*xa*facteur+Pi;
+	   float th=float(theta);
+	   float ff=float(phi);
+	   if (phi<2*Pi && phi>= 0) 
+	     {
+	       map(i,j) = (float)dobj_->PixValSph(th, ff);
+	     }
+	 }
+     }
+   FitsOutFile  fout(filename);
+   fout.firstImageOnPrimaryHeader(true);
+   FITS_TArray<r_4> fta(map);
+   fta.Write(fout);
+
+   
+}
+
+
+#ifdef __CXX_PRAGMA_TEMPLATES__
+#pragma define_template FITS_SphereThetaPhi<r_8>
+#pragma define_template FITS_SphereThetaPhi<r_4>
+//#pragma define_template FITS_SphereThetaPhi<int_4>
+#endif
+#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
+template class FITS_SphereThetaPhi<r_8>;
+template class FITS_SphereThetaPhi<r_4>;
+//template class FITS_SphereThetaPhi<int_4>;
+#endif
Index: trunk/SophyaExt/FitsIOServer/fitsspherethetaphi.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsspherethetaphi.h	(revision 1752)
+++ trunk/SophyaExt/FitsIOServer/fitsspherethetaphi.h	(revision 1752)
@@ -0,0 +1,63 @@
+#ifndef FITSSPHERETHETAPHI_SEEN
+#define FITSSPHERETHETAPHI_SEEN
+
+
+// Guy Le Meur 10/2001
+
+
+#include "spherethetaphi.h"
+#include "anydataobj.h"
+#include "fitsfile.h"
+namespace SOPHYA {
+///////////////////////////////////////////////////////////////////////
+// ------------- Classe pour la gestion de persistance I/O format fits--
+// spherethetaphi
+//////////////////////////////////////////////////////////////////////
+template <class T>
+class FITS_SphereThetaPhi : public FitsIOHandler  
+{
+public:
+
+FITS_SphereThetaPhi();
+FITS_SphereThetaPhi(char inputfile[],int hdunum=0); 
+FITS_SphereThetaPhi(const SphereThetaPhi<T>& obj);
+FITS_SphereThetaPhi(SphereThetaPhi<T>* obj);
+virtual ~FITS_SphereThetaPhi();
+virtual AnyDataObj* DataObj();
+virtual void        SetDataObj(AnyDataObj & o);
+
+void Mollweide_picture_projection(char flnm[]);
+void sinus_picture_projection(char flnm[]);
+
+
+inline operator SphereThetaPhi<T>() { return(*dobj_); }
+
+
+protected:
+
+virtual void ReadFromFits(FitsInFile& is);
+virtual void WriteToFits(FitsOutFile& os) ;
+SphereThetaPhi<T>* dobj_;
+bool ownobj_;
+
+
+
+};
+
+
+//////////////////////////////////////////////////////////////////
+
+template <class T>
+inline FitsOutFile& operator << (FitsOutFile& fios, SphereThetaPhi<T> & sph)
+  { FITS_SphereThetaPhi<T> fih(&sph); fih.Write(fios); return (fios); }
+
+template <class T>
+inline FitsInFile& operator >> (FitsInFile& fiis, SphereThetaPhi<T> & sph)
+  { FITS_SphereThetaPhi<T> fih(&sph); fih.Read(fiis); return (fiis); }
+
+
+
+} // Fin du namespace
+
+
+#endif
