Index: trunk/SophyaExt/FitsIOServer/fabtwriter.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fabtwriter.cc	(revision 3114)
+++ trunk/SophyaExt/FitsIOServer/fabtwriter.cc	(revision 3128)
@@ -53,4 +53,5 @@
  DoubleKey.resize(0);
  LongKey.resize(0);
+ LongLongKey.resize(0);
  StringKey.resize(0);
 
@@ -78,6 +79,6 @@
 
  // create d'un Primary HDU
- //long naxes[1] = {0};
- //if(fits_create_img(FitsPtr,BYTE_IMG,0,naxes,&sta)) {
+ //LONGLONG naxes[1] = {0};
+ //if(fits_create_imgll(FitsPtr,BYTE_IMG,0,naxes,&sta)) {
  //  printerror(sta);
  //  throw NullPtrError("FitsWriter::cr_or_upd_fits: Error creating Primary extension\n");
@@ -125,4 +126,15 @@
 }
 
+/*! Write a long long value into Fits Header */
+void FitsWriter::WriteKey(const char *keyname,LONGLONG val,char* comment)
+{
+ if(keyname==NULL || strlen(keyname)<=0) return;
+ KeyLongLong k;
+ k.keyname=keyname;
+ k.val=val;
+ if(comment) k.comment=comment; else k.comment="";
+ LongLongKey.push_back(k);
+}
+
 /*! Write a string value into Fits Header */
 void FitsWriter::WriteKey(const char *keyname,string val,char* comment)
@@ -142,5 +154,5 @@
  int sta=0;
  if(DoubleKey.size()>0)
-   for(unsigned int i=0;i<DoubleKey.size();i++) {
+   for(unsigned long i=0;i<DoubleKey.size();i++) {
      char* key = const_cast<char*>(DoubleKey[i].keyname.c_str());
      char* com = const_cast<char*>(DoubleKey[i].comment.c_str());
@@ -150,5 +162,5 @@
    }
  if(LongKey.size()>0)
-   for(unsigned int i=0;i<LongKey.size();i++) {
+   for(unsigned long i=0;i<LongKey.size();i++) {
      char* key = const_cast<char*>(LongKey[i].keyname.c_str());
      char* com = const_cast<char*>(LongKey[i].comment.c_str());
@@ -157,6 +169,14 @@
        printerror(sta);
    }
+ if(LongLongKey.size()>0)
+   for(unsigned long i=0;i<LongLongKey.size();i++) {
+     char* key = const_cast<char*>(LongLongKey[i].keyname.c_str());
+     char* com = const_cast<char*>(LongLongKey[i].comment.c_str());
+     LONGLONG val = LongLongKey[i].val;
+     if(fits_update_key(FitsPtr,TLONGLONG,key,&val,com,&sta))
+       printerror(sta);
+   }
  if(StringKey.size()>0)
-   for(unsigned int i=0;i<StringKey.size();i++) {
+   for(unsigned long i=0;i<StringKey.size();i++) {
      char* key = const_cast<char*>(StringKey[i].keyname.c_str());
      char* com = const_cast<char*>(StringKey[i].comment.c_str());
@@ -167,8 +187,9 @@
  DoubleKey.resize(0);
  LongKey.resize(0);
+ LongLongKey.resize(0);
  StringKey.resize(0);
 }
 
-void FitsWriter::printerrorwrite(const char* type,int col,long row,int sta)
+void FitsWriter::printerrorwrite(const char* type,int col,LONGLONG row,int sta)
 {
  if(sta==NUM_OVERFLOW) {NOverFlow++; return;}
@@ -176,5 +197,5 @@
  char str[256];
  sprintf(str,"FitsWriter::Write_%s: Error Writing Fits c=%d r=%ld sta=%d"
-        ,type,col,row,sta);
+        ,type,col,(long)row,sta);
  throw NotAvailableOperation(str);
 }
@@ -208,5 +229,5 @@
   int c5 = fbtw.AddCol("vard","","arcmin",TDOUBLE);    // col=4
   fbtw.SetDebug(3);
-  for(long i=0;i<1000;i++) {
+  for(LONGLONG i=0;i<1000;i++) {
     double x = i;
     fbtw.Write(c1,i,1000.*x); // if overflow, managed by cfitsio
@@ -228,9 +249,9 @@
   TVector<float>  dataf(100);
   TVector<int_4>  datal(100);
-  for(long i=0;i<9990;i+=100) {
-    long i2=i+100-1; if(i2>=9990) i2=9990-1;
-    for(long j=0;j<100;j++) datad(i) =  ...;
-    for(long j=0;j<100;j++) dataf(i) =  ...;
-    for(long j=0;j<100;j++) datal(i) =  ...;
+  for(LONGLONG i=0;i<9990;i+=100) {
+    LONGLONG i2=i+100-1; if(i2>=9990) i2=9990-1;
+    for(LONGLONG j=0;j<100;j++) datad(i) =  ...;
+    for(LONGLONG j=0;j<100;j++) dataf(i) =  ...;
+    for(LONGLONG j=0;j<100;j++) datal(i) =  ...;
     fbtw.Write(1,i,datal);
     fbtw.Write(2,i,dataf);
@@ -251,4 +272,5 @@
    cout<<"Writing Keys"<<endl;
    fbtw.WriteKey("MYKEYL",(long)123456789,"my LONG key");
+   fbtw.WriteKey("MYKEYLL",(LONGLONG)123456789,"my LONGLONG key");
    fbtw.WriteKey("MYKEYD",1.9999999,"my DOUBLE key");
    fbtw.WriteKey("MYKEYC","how are you ?","my CHAR* key");
@@ -265,4 +287,5 @@
    cout<<"Writing Keys"<<endl;
    fbtw2.WriteKey("MYKEYL",(long)-123456789,"my new LONG key");
+   fbtw2.WriteKey("MYKEYLL",(LONGLONG)-123456789,"my new LONGLONG key");
    fbtw2.WriteKey("MYKEYD",-1.9999999,"my new clef DOUBLE key");
    fbtw2.WriteKey("MYKEYC","how are you NOW ?","my new CHAR* key");
@@ -275,5 +298,5 @@
 
    cout<<">>>>> Write into the 2 tables simultaneously"<<endl;
-   for(int i=0;i<NNN;i++) {
+   for(LONGLONG i=0;i<NNN;i++) {
      fbtw.Write(i1,i,i+1.);
      fbtw.Write(i2,i,i+11.);
@@ -462,5 +485,5 @@
    throw ParmError("FitsABTWriter::createtbl: Zero column asked !\n");
 
- long nrows = 0;
+ LONGLONG nrows = 0;
  char *extname = NULL;
  char **ttype   = (char **) malloc(tfields*sizeof(char *));
@@ -472,6 +495,5 @@
    strcpy(extname,ExtName.c_str());
  }
- int i;
- for(i=0;i<tfields;i++) {
+ for(int i=0;i<tfields;i++) {
    ttype[i] = (char *) malloc((strlen(Label[i].c_str())+1)*sizeof(char));
      strcpy(ttype[i],Label[i].c_str());
@@ -491,5 +513,5 @@
  // menage
  if(extname) delete [] extname;
- for(i=0;i<tfields;i++) {
+ for(int i=0;i<tfields;i++) {
    if(ttype[i]) delete [] ttype[i];
    if(tform[i]) delete [] tform[i];
@@ -525,5 +547,5 @@
 
 /*! Write signed char (1 Byte) data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,int_1 val)
+void FitsABTWriter::Write(int col,LONGLONG row,int_1 val)
 {
 #ifdef TSBYTE
@@ -538,5 +560,5 @@
 
 /*! Write unsigned char (1 Byte) data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,uint_1 val)
+void FitsABTWriter::Write(int col,LONGLONG row,uint_1 val)
 {
   if(FirstTime) createtbl();
@@ -547,5 +569,5 @@
 
 /*! Write short (2 Bytes) data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,int_2 val)
+void FitsABTWriter::Write(int col,LONGLONG row,int_2 val)
 {
   if(FirstTime) createtbl();
@@ -556,5 +578,5 @@
 
 /*! Write unsigned short (2 Bytes) data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,uint_2 val)
+void FitsABTWriter::Write(int col,LONGLONG row,uint_2 val)
 {
   if(FirstTime) createtbl();
@@ -565,5 +587,5 @@
 
 /*! Write long (4 Bytes) data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,int_4 val)
+void FitsABTWriter::Write(int col,LONGLONG row,int_4 val)
 {
   if(FirstTime) createtbl();
@@ -576,5 +598,5 @@
 
 /*! Write unsigned long (4 Bytes) data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,uint_4 val)
+void FitsABTWriter::Write(int col,LONGLONG row,uint_4 val)
 {
   if(FirstTime) createtbl();
@@ -587,5 +609,5 @@
 
 /*! Write long long (8 Bytes) data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,int_8 val)
+void FitsABTWriter::Write(int col,LONGLONG row,int_8 val)
 {
 #ifdef TLONGLONG
@@ -600,5 +622,5 @@
 
 /*! Write float data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,float val)
+void FitsABTWriter::Write(int col,LONGLONG row,float val)
 {
   if(FirstTime) createtbl();
@@ -609,5 +631,5 @@
 
 /*! Write double data to FITS file (see below) */
-void FitsABTWriter::Write(int col,long row,double val)
+void FitsABTWriter::Write(int col,LONGLONG row,double val)
 {
   if(FirstTime) createtbl();
@@ -628,8 +650,8 @@
 
 /*! Write a vector of unsigned short (2 Bytes) data to FITS file (see below) */
-long FitsABTWriter::Write(int col,long row,TVector<uint_2>& val)
-{
-  if(FirstTime) createtbl();
-  long nel = val.Size();
+LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<uint_2>& val)
+{
+  if(FirstTime) createtbl();
+  LONGLONG nel = val.Size();
   int sta=0;
   if(fits_write_col(FitsPtr,TUSHORT,col+1,row+1,1,nel,val.Data(),&sta))
@@ -639,8 +661,8 @@
 
 /*! Write a vector of long (4 Bytes) data to FITS file (see below) */
-long FitsABTWriter::Write(int col,long row,TVector<int_4>& val)
-{
-  if(FirstTime) createtbl();
-  long nel = val.Size();
+LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<int_4>& val)
+{
+  if(FirstTime) createtbl();
+  LONGLONG nel = val.Size();
   int sta=0;
   // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
@@ -652,9 +674,9 @@
 
 /*! Write a vector of long long (8 Bytes) data to FITS file (see below) */
-long FitsABTWriter::Write(int col,long row,TVector<int_8>& val)
+LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<int_8>& val)
 {
 #ifdef TLONGLONG
   if(FirstTime) createtbl();
-  long nel = val.Size();
+  LONGLONG nel = val.Size();
   int sta=0;
   if(fits_write_col(FitsPtr,TLONGLONG,col+1,row+1,1,nel,val.Data(),&sta))
@@ -667,8 +689,8 @@
 
 /*! Write a vector of float data to FITS file (see below) */
-long FitsABTWriter::Write(int col,long row,TVector<float>&  val)
-{
-  if(FirstTime) createtbl();
-  long nel = val.Size();
+LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<float>&  val)
+{
+  if(FirstTime) createtbl();
+  LONGLONG nel = val.Size();
   int sta=0;
   if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,nel,val.Data(),&sta))
@@ -678,8 +700,8 @@
 
 /*! Write a vector of double data to FITS file (see below) */
-long FitsABTWriter::Write(int col,long row,TVector<double>& val)
-{
-  if(FirstTime) createtbl();
-  long nel = val.Size();
+LONGLONG FitsABTWriter::Write(int col,LONGLONG row,TVector<double>& val)
+{
+  if(FirstTime) createtbl();
+  LONGLONG nel = val.Size();
   int sta=0;
   if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,nel,val.Data(),&sta))
@@ -785,5 +807,5 @@
 
  int sta=0;
- if(fits_create_img(FitsPtr,BitPix,2,Naxis,&sta)) {
+ if(fits_create_imgll(FitsPtr,BitPix,2,Naxis,&sta)) {
    printerror(sta);
    throw NullPtrError("FitsImg2DWriter::createimg: Error creating image extension\n");
@@ -802,7 +824,7 @@
  uint_2* arr = new uint_2[Naxis[0]];
 
- for(int l=0;l<Naxis[1];l++) {
-   for(int c=0;c<Naxis[0];c++) arr[c] = data(l,c);
-   long deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=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,TUSHORT,deb,nel,arr,&sta);
    if(sta) {
@@ -823,7 +845,7 @@
  int_4* arr = new int_4[Naxis[0]];
 
- for(int l=0;l<Naxis[1];l++) {
-   for(int c=0;c<Naxis[0];c++) arr[c] = data(l,c);
-   long deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=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,T,deb,nel,arr,&sta);
    if(sta) {
@@ -843,7 +865,7 @@
  float* arr = new float[Naxis[0]];
 
- for(int l=0;l<Naxis[1];l++) {
-   for(int c=0;c<Naxis[0];c++) arr[c] = data(l,c);
-   long deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=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,TFLOAT,deb,nel,arr,&sta);
    if(sta) {
@@ -863,7 +885,7 @@
  double* arr = new double[Naxis[0]];
 
- for(int l=0;l<Naxis[1];l++) {
-   for(int c=0;c<Naxis[0];c++) arr[c] = data(l,c);
-   long deb = l*Naxis[0]+1, nel = Naxis[0]; int sta=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,TDOUBLE,deb,nel,arr,&sta);
    if(sta) {
@@ -972,5 +994,5 @@
 
  int sta=0;
- if(fits_create_img(FitsPtr,BitPix,3,Naxis,&sta)) {
+ if(fits_create_imgll(FitsPtr,BitPix,3,Naxis,&sta)) {
    printerror(sta);
    throw NullPtrError("FitsImg3DWriter::createimg: Error creating 3D image extension\n");
@@ -991,7 +1013,7 @@
  uint_2* arr = new uint_2[Naxis[0]];
 
- for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) {
-   for(int i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
-   long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=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,TUSHORT,deb,nel,arr,&sta);
    if(sta) {
@@ -1015,7 +1037,7 @@
  int_4* arr = new int_4[Naxis[0]];
 
- for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) {
-   for(int i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
-   long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=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,T,deb,nel,arr,&sta);
    if(sta) {
@@ -1038,7 +1060,7 @@
  float* arr = new float[Naxis[0]];
 
- for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) {
-   for(int i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
-   long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=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,TFLOAT,deb,nel,arr,&sta);
    if(sta) {
@@ -1061,7 +1083,7 @@
  double* arr = new double[Naxis[0]];
 
- for(int k=0;k<Naxis[2];k++) for(int j=0;j<Naxis[1];j++) {
-   for(int i=0;i<Naxis[0];i++) arr[i] = data(i,j,k);
-   long deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0]; int sta=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,TDOUBLE,deb,nel,arr,&sta);
    if(sta) {
