Index: /trunk/SophyaExt/FitsIOServer/fitstarray.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 863)
+++ /trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 863)
@@ -0,0 +1,152 @@
+#include "machdefs.h"
+#include "pexceptions.h" 
+#include "fitstarray.h" 
+///////////////////////////////////////////////////////////
+//   Les objets delegues pour la gestion de persistance sur fichiers fits 
+//    pout TArray
+///////////////////////////////////////////////////////////
+
+using namespace SOPHYA;
+
+template <class T>
+FITS_TArray<T>::FITS_TArray()
+{
+  dobj_=new TArray<T>;
+  ownobj=true;
+}
+
+template <class T>
+FITS_TArray<T>::FITS_TArray(char inputfile[],int hdunum)
+{
+  dobj_=new TArray<T>;
+  ownobj=true; 
+  ReadF(inputfile,hdunum);
+}
+
+template <class T>
+FITS_TArray<T>::FITS_TArray(const TArray<T> & obj) 
+{ 
+  dobj_ = new TArray<T>(obj);
+  ownobj=true; 
+}
+
+template <class T>
+FITS_TArray<T>::FITS_TArray(TArray<T> *obj) 
+{ 
+  dobj_ = obj;
+  ownobj=false; 
+}
+
+
+template <class T>
+FITS_TArray<T>::~FITS_TArray()
+{
+  if (ownobj && dobj_) delete dobj_;
+}
+
+template <class T>
+void FITS_TArray<T>::Write(char outputfile[])
+{
+  WriteF(outputfile);
+}
+
+
+
+template <class T>
+AnyDataObj* FITS_TArray<T>::DataObj()
+{
+  return(dobj_);
+}
+
+template <class T>
+void FITS_TArray<T>::ReadFromFits(const FitsFile& fn)
+{
+
+  if (!fn.IsFitsImage())
+    {
+      throw PException("ReadFromFits: the fits file seems not to be an image");
+    }
+  int dimension = fn.nbDimOfImage();
+  cout << " dimension de l'image a lire: " << dimension << endl;
+   
+  uint_4* siz = new uint_4[dimension];
+  for (int k=0; k< dimension; k++) siz[k] = fn.dimOfImageAxes()[k];
+  if(dobj_ == NULL)
+    dobj_ = new TArray<T>(dimension,siz);
+  else
+    dobj_->ReSize(dimension,siz);
+  
+  delete [] siz;
+  if (dobj_->Size() != fn.nbOfImageData() )
+  {
+    cout << " total size of TArray: " << dobj_->Size() << endl;
+    cout << " total size from fits file: " << fn.nbOfImageData() << endl;
+      throw PException("ReadFromFits: size conflict");
+  }
+  // On lit le tableau
+  fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
+
+}
+
+
+  template <class T>
+void FITS_TArray<T>::WriteToFits(const FitsFile& fn)  
+{
+  if(dobj_ == NULL) return;
+  uint_4 nbdim = dobj_->NbDimensions();
+  if ( nbdim == 0) 
+    {
+      throw PException(" FITS_TARRAY: number of dimensions of the array = 0?");
+    }
+  cout << "FITS_TARRAY: nombrede dimension du tableau a ecrire: " << nbdim << endl;
+  int* naxisn = new int[nbdim];
+  for (int k=0; k< nbdim; k++)
+    {
+      naxisn[k] = dobj_->Size(k);
+      cout << " taille de la dimension " << k << " : " << naxisn[k] << endl;
+    }
+  char type;
+  if (strncmp( typeid(T).name(),"r_8",3)==0 || strncmp( typeid(T).name(),"double",6)==0 ) type='D';
+  else 
+    if (strncmp( typeid(T).name(),"r_4",3)==0 || strncmp( typeid(T).name(),"float",5)==0 )  type='E';
+    else
+      if (strncmp( typeid(T).name(),"int_4",5)==0 || strncmp( typeid(T).name(),"int",3)==0 )  type='I';
+      else
+	{
+	  cout <<  " type du tableau= " <<  typeid(T).name() << endl;
+	  throw IOExc("FITS_TArray:: unknown type");
+	}
+
+  int nbels = 1;
+  for (int k=0; k< nbdim; k++) 
+    {
+      if (naxisn[k] > 0) nbels *= naxisn[k];
+    }
+  cout << " nombre total d'elements a copier " << nbels << endl;
+  fn.makeHeaderImageOnFits(type, nbdim, naxisn);
+  if (!dobj_->IsPacked()) 
+    {
+      cout << " IsPacked() = " << dobj_->IsPacked() << endl;
+      throw PException(" FITS_TARRAY: this case is not yet programmed");
+      
+    }
+  if (dobj_->MinStep() != 1) 
+    {
+      cout << " MinStep()) = " << dobj_->MinStep() << endl;
+      throw PException(" FITS_TARRAY: this case is not yet programmed");
+      
+    }
+  fn.putImageToFits(nbels, dobj_->Data());
+  
+  delete [] naxisn;
+}
+
+
+#ifdef __CXX_PRAGMA_TEMPLATES__
+#pragma define_template FITS_TArray<r_8>
+#pragma define_template FITS_TArray<r_4>
+#endif
+#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
+template class FITS_TArray<r_8>;
+template class FITS_TArray<r_4>;
+#endif
Index: /trunk/SophyaExt/FitsIOServer/fitstarray.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitstarray.h	(revision 863)
+++ /trunk/SophyaExt/FitsIOServer/fitstarray.h	(revision 863)
@@ -0,0 +1,48 @@
+// Guy Le Meur 04/2000
+
+
+#ifndef FITSTARRAY_SEEN
+#define FITSTARRAY_SEEN
+
+
+#include "pexceptions.h" 
+#include "tarray.h"
+#include "fitsfile.h"
+
+namespace SOPHYA {
+
+
+/////////////////////////////////////////////////////////////////////////
+// Classe pour la gestion de persistance sur fichiers fits
+/////////////////////////////////////////////////////////////////////////
+
+
+
+template <class T>
+class FITS_TArray : public FitsFile {
+
+public:
+
+FITS_TArray();
+FITS_TArray(char inputfile[],int hdunum=1);
+FITS_TArray(const TArray<T> & obj);
+FITS_TArray(TArray<T> *obj);
+virtual ~FITS_TArray();
+virtual AnyDataObj* DataObj();
+inline operator TArray<T>() { return(*dobj_); }
+void Write(char outputfile[]);
+
+protected :
+
+void ReadFromFits(const FitsFile& fn);
+void WriteToFits(const FitsFile& fn);
+
+  TArray<T> * dobj_;
+  bool ownobj;
+};
+//////////////////////////////////////////////////////////////////
+
+
+} // Fin du namespace
+
+#endif
