Index: trunk/SophyaExt/FitsIOServer/fabtwriter.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fabtwriter.cc	(revision 3660)
+++ trunk/SophyaExt/FitsIOServer/fabtwriter.cc	(revision 3668)
@@ -736,5 +736,6 @@
   Constructor.
   \param fname : FITS file name to be written (a new fits file is created)
-  \param bitpix : image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
   \param lp : debug level
 */
@@ -751,5 +752,6 @@
   Constructor.
   \param cfname : FITS file name to be written (a new fits file is created)
-  \param bitpix : image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
   \param lp : debug level
 */
@@ -767,5 +769,6 @@
   \param fname : FITS file name to be written (created or updated)
   \param update : file is created if FALSE, open for update if TRUE
-  \param bitpix : image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
   \param lp : debug level
 */
@@ -783,5 +786,6 @@
   \param cfname : FITS file name to be written (created or updated)
   \param update : file is created if FALSE, open for update if TRUE
-  \param bitpix : image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix standard: image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix extended: image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
   \param lp : debug level
 */
@@ -815,4 +819,27 @@
 
  FirstTime = false;
+}
+
+/*!
+  Write an unsigned byte image to FITS file.
+  \warning TMatrix data(Naxis2,Naxis1) means Data(row,column)
+*/
+void FitsImg2DWriter::Write(TMatrix<uint_1>& data)
+{
+ Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg();
+ uint_1* arr = new uint_1[Naxis[0]];
+
+ for(LONGLONG l=0;l<Naxis[1];l++) {
+   for(LONGLONG c=0;c<Naxis[0];c++) arr[c] = data(l,c);
+   LONGLONG deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=0;
+   fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
+   if(sta) {
+     printerrorwrite("uint_1",0,l,sta); delete [] arr;
+     throw
+       NotAvailableOperation("FitsImg2DRd::Write(TMatrix<uint_1>): Error Writing Fits file\n");
+   }
+ }
+
+ delete [] arr;
 }
 
@@ -923,5 +950,6 @@
   Constructor.
   \param fname : FITS file name to be written (a new fits file is created)
-  \param bitpix : 3D image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
   \param lp : debug level
 */
@@ -938,5 +966,6 @@
   Constructor.
   \param cfname : FITS file name to be written (a new fits file is created)
-  \param bitpix : 3D image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
   \param lp : debug level
 */
@@ -954,5 +983,6 @@
   \param fname : FITS file name to be written (created or updated)
   \param update : file is created if FALSE, open for update if TRUE
-  \param bitpix : 3D image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
   \param lp : debug level
 */
@@ -970,5 +1000,6 @@
   \param cfname : FITS file name to be written (created or updated)
   \param update : file is created if FALSE, open for update if TRUE
-  \param bitpix : 3D image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix standard: 3D image type (BYTE_IMG,SHORT_IMG,LONG_IMG,LONGLONG_IMG,FLOAT_IMG,DOUBLE_IMG)
+  \param bitpix extended: 3D image type (SBYTE_IMG,USHORT_IMG,ULONG_IMG)
   \param lp : debug level
 */
@@ -1002,4 +1033,38 @@
 
  FirstTime = false;
+}
+
+/*! Create the 3D imageby yourself, ONLY use it with Write(TVector<>& data) */
+void FitsImg3DWriter::CreateImg(LONGLONG naxis1,LONGLONG naxis2,LONGLONG naxis3)
+{
+ Naxis[0]=naxis1;
+ Naxis[1]=naxis2;
+ Naxis[2]=naxis3;
+ createimg();
+}
+
+/*!
+  Write an unsigned byte 3D image to FITS file.
+*/
+void FitsImg3DWriter::Write(TArray<uint_1>& data)
+{
+ if(data.Rank()!=3)
+   throw ParmError("FitsImg3DRd::Write(TArray<uint_1>): not a 3D array\n");
+
+ Naxis[0]=data.SizeX(); Naxis[1]=data.SizeY(); Naxis[2]=data.SizeZ(); createimg();
+ uint_1* arr = new uint_1[Naxis[0]];
+
+ for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
+   for(LONGLONG i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
+   LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
+   fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
+   if(sta) {
+     printerrorwrite("uint_1",j,k,sta); delete [] arr;
+     throw
+       NotAvailableOperation("FitsImg3DRd::Write(TArray<uint_1>): Error Writing Fits file\n");
+   }
+ }
+
+ delete [] arr;
 }
 
@@ -1099,4 +1164,120 @@
 }
 
+/*!
+  Write an unsigned byte Vector<> image to 3D FITS file.
+  Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
+  so IMG(i,j,k) = Vector(i)
+*/
+void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<uint_1>& data)
+{
+ if(FirstTime)
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): use CreateImg first !\n");
+ if(data.Size()!=Naxis[0])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): wrong vector size\n");
+ if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): j or k out of range\n");
+ uint_1* arr = const_cast<uint_1 *>(data.Data());
+ LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
+ fits_write_img(FitsPtr,TBYTE,deb,nel,arr,&sta);
+ if(sta) {
+   printerrorwrite("uint_1",j,k,sta); delete [] arr;
+   throw
+     NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_1>&): Error Writing Fits file\n");
+ }
+}
+
+/*!
+  Write an unsigned short Vector<> image to 3D FITS file.
+  Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
+  so IMG(i,j,k) = Vector(i)
+*/
+void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<uint_2>& data)
+{
+ if(FirstTime)
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): use CreateImg first !\n");
+ if(data.Size()!=Naxis[0])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): wrong vector size\n");
+ if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): j or k out of range\n");
+ uint_2* arr = const_cast<uint_2 *>(data.Data());
+ LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
+ fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta);
+ if(sta) {
+   printerrorwrite("uint_2",j,k,sta); delete [] arr;
+   throw
+     NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<uint_2>&): Error Writing Fits file\n");
+ }
+}
+
+/*!
+  Write an long Vector<> image to 3D FITS file.
+  Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
+  so IMG(i,j,k) = Vector(i)
+*/
+void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<int_4>& data)
+{
+ if(FirstTime)
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): use CreateImg first !\n");
+ if(data.Size()!=Naxis[0])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): wrong vector size\n");
+ if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): j or k out of range\n");
+ int T = (sizeof(long)==4) ? TLONG: TINT;
+ int_4* arr = const_cast<int_4 *>(data.Data());
+ LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
+ fits_write_img(FitsPtr,T,deb,nel,arr,&sta);
+ if(sta) {
+   printerrorwrite("int_4",j,k,sta); delete [] arr;
+   throw
+     NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<int_4>&): Error Writing Fits file\n");
+ }
+}
+
+/*!
+  Write an float Vector<> image to 3D FITS file.
+  Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
+  so IMG(i,j,k) = Vector(i)
+*/
+void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<float>& data)
+{
+ if(FirstTime)
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): use CreateImg first !\n");
+ if(data.Size()!=Naxis[0])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): wrong vector size\n");
+ if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): j or k out of range\n");
+ float* arr = const_cast<float *>(data.Data());
+ LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
+ fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta);
+ if(sta) {
+   printerrorwrite("float",j,k,sta); delete [] arr;
+   throw
+     NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<float>&): Error Writing Fits file\n");
+ }
+}
+
+/*!
+  Write an double Vector<> image to 3D FITS file.
+  Vector is stored in Naxis1, j (resp. k) indicate place within Naxis2 (resp. Naxis3):
+  so IMG(i,j,k) = Vector(i)
+*/
+void FitsImg3DWriter::Write(LONGLONG j, LONGLONG k,TVector<double>& data)
+{
+ if(FirstTime)
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): use CreateImg first !\n");
+ if(data.Size()!=Naxis[0])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): wrong vector size\n");
+ if(j<0 || j>=Naxis[1] || k<0 || k>=Naxis[2])
+   throw ParmError("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): j or k out of range\n");
+ double* arr = const_cast<double *>(data.Data());
+ LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=0;
+ fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta);
+ if(sta) {
+   printerrorwrite("double",j,k,sta); delete [] arr;
+   throw
+     NotAvailableOperation("FitsImg3DRd::Write(LONGLONG,LONGLONG,TVector<double>&): Error Writing Fits file\n");
+ }
+}
+
 /*! Print infos. */
 void FitsImg3DWriter::Print(ostream& os) const
