Index: trunk/Ohana/src/addstar/Makefile
===================================================================
--- trunk/Ohana/src/addstar/Makefile	(revision 26371)
+++ trunk/Ohana/src/addstar/Makefile	(revision 26384)
@@ -81,5 +81,6 @@
 $(SRC)/ReadImageHeader.$(ARCH).o \
 $(SRC)/UpdateImageIDs.$(ARCH).o \
-$(SRC)/update_coords.$(ARCH).o
+$(SRC)/update_coords.$(ARCH).o \
+$(SRC)/psps_ids.$(ARCH).o
 
 ADDSTARD = \
@@ -118,5 +119,6 @@
 $(SRC)/opening_angle.$(ARCH).o \
 $(SRC)/replace_match.$(ARCH).o \
-$(SRC)/update_coords.$(ARCH).o
+$(SRC)/update_coords.$(ARCH).o \
+$(SRC)/psps_ids.$(ARCH).o
 
 ADDSTART = \
@@ -157,5 +159,6 @@
 $(SRC)/NewImage_Thread.$(ARCH).o \
 $(SRC)/NewReflist_Thread.$(ARCH).o \
-$(SRC)/NewRefcat_Thread.$(ARCH).o 
+$(SRC)/NewRefcat_Thread.$(ARCH).o \
+$(SRC)/psps_ids.$(ARCH).o
 
 ADDSTARC = \
@@ -206,5 +209,6 @@
 $(SRC)/ConfigInit.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
-$(SRC)/SetSignals.$(ARCH).o
+$(SRC)/SetSignals.$(ARCH).o \
+$(SRC)/psps_ids.$(ARCH).o
 
 SEDSTAR = \
Index: trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- trunk/Ohana/src/addstar/include/addstar.h	(revision 26371)
+++ trunk/Ohana/src/addstar/include/addstar.h	(revision 26384)
@@ -289,4 +289,8 @@
 PhotCode *pmm_get_photcode (char *emulsion, char *filter);
 
+#define PSPS_ID TRUE
+uint64_t CreatePSPSDetectionID(double tobs, int ccdid, int detID);
+uint64_t CreatePSPSObjectID(double ra, double dec);
+
 // this is a gnu extension?? caution!
 void *memrchr(const void *s, int c, size_t n);
Index: trunk/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- trunk/Ohana/src/addstar/src/FilterStars.c	(revision 26371)
+++ trunk/Ohana/src/addstar/src/FilterStars.c	(revision 26384)
@@ -88,14 +88,13 @@
     }
 
-# if (0) 
     if (PSPS_ID) {
       double mjd;
       mjd = ohana_sec_to_mjd (image[0].tzero);
-      // XXX this is clearly wrong : what does PSPS want?
-      stars[N].measure.extID = PSPS_create_detectid (mjd, imageID);
+      stars[N].measure.extID = CreatePSPSDetectionID(mjd, image[0].ccdnum, stars[N].measure.detID);
+    } else {
+      stars[N].measure.extID = 0;
     }
-# endif
 
-    stars[N].measure.imageID = imageID; // this value is update in UpdateImageIDs
+    stars[N].measure.imageID = imageID; // this value is updated in UpdateImageIDs
 
     N ++;
Index: trunk/Ohana/src/addstar/src/PSPS_IDs.c
===================================================================
--- trunk/Ohana/src/addstar/src/PSPS_IDs.c	(revision 26371)
+++ 	(revision )
@@ -1,71 +1,0 @@
-# include "addstar.h"
-
-uint64_7 PSPS_create_detectID (double MJDobs, int imageID) {
-
-  // MJD has a PS lifetime range of : 3288 (2009/01/01) to 9132 (2025/01/01) (< 2^14)
-
-  static double t0 = 51544.5; // MJD @ 2000/01/01,12:00:00
-
-  uint64_t iTime;
-  uint64_t detectID;
-
-  iTime = floor(tobs - t0);
-
-  // iTime takes the upper 16 bits, imageID can take up to lower 48 bits
-  detectID = (iTime << 48) | imageID;
-
-  return detectID;
-}
-
-uint64_t PSPS_create_objID (double ra, double dec) {
-
-  static double zh = 0.0083333; // zone height = 30 arcsec
-
-  uint64_t objID;
-  uint64_t part1, part2, part3;
-
-  double zid, zresid;
-  int izone;
-
-  zid = (dec + 90.0) / zh; // 0 - 180*60*2 = 21600 (< 15 bits)
-  izone = (int) floor(zid);
-  zresid = zid -  ((float) izone); // 0 - 1.0 
-  part1 = (uint64_t)( izone  * 10000000000000) ;
-  part2 = ((uint64_t)(ra * 1 000 000.)) * 10000 ; // 0 - 360.0*1e6 = 3.6e8 (< 29 bits)
-  part3 = (int) (zresid * 10000.0) ; // 0 - 10000 (1 bit == 30/10000 arcsec = 0.003 arcsec) (< 14 bits)
-
-  objID = part1 + part2 + part3;
-
-  return objID;
-}
-
-uint64_t PSPS_create_objID_eam (double ra, double dec) {
-
-  static double zh = 0.0083333; // zone height = 30 arcsec
-
-  uint64_t objID;
-  uint64_t part1, part2, part3;
-
-  double zid, zresid;
-  int izone, ira;
-
-  zid = (dec + 90.0) / zh; // 0 - 180*60*2 = 21600 (< 15 bits)
-  izone = (int) floor(zid);
-  zresid = zid -  ((float) izone); // 0 - 1.0 
-
-  ira = ra * 1 000 000; // 0 - 360.0*1e6 = 3.6e8 (< 29 bits) 
-
-  part1 = (izone << 48);
-  part2 = (ira << 16);
-  part3 = (int) (zresid * 10000.0) ; // 0 - 10000 (1 bit == 30/10000 arcsec = 0.003 arcsec) (< 14 bits)
-
-  objID = part1 | part2 | part3;
-
-  return objID;
-}
-
-// part1 : 15 bits
-// part2 : 29 bits
-// part3 : 14 bits
-// 15 + 14 + 29 bits = 58 bits...
-
Index: trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches.c	(revision 26371)
+++ trunk/Ohana/src/addstar/src/find_matches.c	(revision 26384)
@@ -271,4 +271,10 @@
     catalog[0].average[Nave].catID     	   = catID;
     catalog[0].average[Nave].flags         = 0;
+    if (PSPS_ID) {
+        catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R,
+                                                            catalog[0].average[Nave].D);
+    } else {
+        catalog[0].average[Nave].extID         = 0;
+    }
 
     objID ++;
Index: trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 26371)
+++ trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 26384)
@@ -266,4 +266,11 @@
     catalog[0].average[Nave].catID     	   = catID;
     catalog[0].average[Nave].flags         = 0;
+    if (PSPS_ID) {
+        catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R,
+                                                            catalog[0].average[Nave].D);
+    } else {
+        catalog[0].average[Nave].extID         = 0;
+    }
+
 
     objID ++;
Index: trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c	(revision 26371)
+++ trunk/Ohana/src/addstar/src/find_matches_closest_refstars.c	(revision 26384)
@@ -291,4 +291,10 @@
     catalog[0].average[Nave].catID     	   = catID;
     catalog[0].average[Nave].flags     	   = 0;
+    if (PSPS_ID) {
+        catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R,
+                                                            catalog[0].average[Nave].D);
+    } else {
+        catalog[0].average[Nave].extID         = 0;
+    }
 
     objID ++;
Index: trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 26371)
+++ trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 26384)
@@ -261,4 +261,11 @@
     catalog[0].average[Nave].catID     	   = catID;
     catalog[0].average[Nave].flags     	   = 0;
+    if (PSPS_ID) {
+        catalog[0].average[Nave].extID = CreatePSPSObjectID(catalog[0].average[Nave].R,
+                                                            catalog[0].average[Nave].D);
+    } else {
+        catalog[0].average[Nave].extID         = 0;
+    }
+
 
     objID ++;
Index: trunk/Ohana/src/addstar/src/psps_ids.c
===================================================================
--- trunk/Ohana/src/addstar/src/psps_ids.c	(revision 26384)
+++ trunk/Ohana/src/addstar/src/psps_ids.c	(revision 26384)
@@ -0,0 +1,41 @@
+# include "addstar.h"
+
+// Compute PSPS defined IDs
+
+uint64_t
+CreatePSPSDetectionID(double tobs, int ccdid, int detID)
+{
+//    double floor();
+    // t0 for detection id is 2007-01-01 00:00:00 utc
+    double  t0 = 54101.0;
+    double diff;
+    int itmp;
+    uint64_t detectid;
+        
+    diff = floor( 100000. * (tobs - t0) );
+    itmp = diff;
+    // ccdid must be < 100
+    detectid = 1000000000*((uint64_t) itmp) + 10000000 * ((uint64_t) ccdid) +
+             ((uint64_t) detID);
+
+    return detectid;
+}
+    
+uint64_t
+CreatePSPSObjectID(double ra, double dec)
+{
+    uint64_t part1, part2, part3;
+    double zid, zresid;
+    int izone;
+    double zh = 0.0083333;
+    
+    zid = (dec + 90.) / zh;             // 0 - 180*60*2 = 21600 < 15 bits
+    izone = (int) floor(zid);
+    zresid = zid -  ((float) izone);    // 0.0 - 1.0
+
+    part1 = (uint64_t)( izone  * 10000000000000) ; 
+    part2 = ((uint64_t)(ra * 1000000.)) * 10000 ; // 0 - 360*1e6 = 3.6e8 (< 29 bits)
+    part3 = (int) (zresid * 10000.0) ; // 0 - 10000 (1 bit == 30/10000 arcsec (< 14 bits)
+
+    return part1 + part2 + part3;
+}
Index: trunk/Ohana/src/libautocode/generate
===================================================================
--- trunk/Ohana/src/libautocode/generate	(revision 26371)
+++ trunk/Ohana/src/libautocode/generate	(revision 26384)
@@ -135,6 +135,6 @@
 	# FITS tables do not allow for 64bit integers.  we need to
 	# write these by splitting the value into high and low 32 bit values
-	if ($type eq "int64_t")       { $pt1 = "J"; $Np = 2*$Np; }
-	if ($type eq "uint64_t")      { $pt1 = "J"; $Np = 2*$Np; }
+	if ($type eq "int64_t")       { $pt1 = "K";}
+	if ($type eq "uint64_t")      { $pt1 = "K";}
 
 	if ($type eq "float")  	      { $pt1 = "E"; }
@@ -239,8 +239,6 @@
 	if ($type eq "uint32_t")      { $pt1 = sprintf "I%s", $length; }
 
-	# FITS tables do not allow for 64bit integers.  we need to
-	# write these by splitting the value into high and low 32 bit values
-	if ($type eq "int64_t")       { $pt1 = sprintf "I%s", $length; }
-	if ($type eq "uint64_t")      { $pt1 = sprintf "I%s", $length; }
+	if ($type eq "int64_t")       { $pt1 = sprintf "K%s", $length; }
+	if ($type eq "uint64_t")      { $pt1 = sprintf "K%s", $length; }
 
 	if ($type eq "float")  	      { $pt1 = sprintf "F%s", $length; }
@@ -324,8 +322,6 @@
 	if ($type eq "uint32_t")      { $T = "WORD"; $n = 4; }
 
-	# FITS tables do not allow for 64bit integers.  we need to
-	# write these by splitting the value into high and low 32 bit values
-	if ($type eq "int64_t")       { $T = "WORD"; $n = 4; $Np = 2*$Np; }
-	if ($type eq "uint64_t")      { $T = "WORD"; $n = 4; $Np = 2*$Np; }
+	if ($type eq "int64_t")       { $T = "DBLE"; $n = 8; }
+	if ($type eq "uint64_t")      { $T = "DBLE"; $n = 8; }
 
 	if ($type eq "float")  	      { $T = "WORD"; $n = 4; }
@@ -370,7 +366,4 @@
 	if ($type eq "int32_t")        { $Nbytes += 4*$Np; $valid = 1; }
 	if ($type eq "uint32_t")       { $Nbytes += 4*$Np; $valid = 1; }
-
-	# FITS tables do not allow for 64bit integers.  we need to
-	# write these by splitting the value into high and low 32 bit values
 	if ($type eq "int64_t")        { $Nbytes += 8*$Np; $valid = 1; }
 	if ($type eq "uint64_t")       { $Nbytes += 8*$Np; $valid = 1; }
Index: trunk/Ohana/src/libfits/table/F_define_column.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_define_column.c	(revision 26371)
+++ trunk/Ohana/src/libfits/table/F_define_column.c	(revision 26384)
@@ -23,8 +23,12 @@
   sprintf (field, "TFORM%d", Nfields);
   gfits_modify (header, field, "%s", 1, format);
-  sprintf (field, "TSCAL%d", Nfields);
-  gfits_modify (header, field, "%lf", 1, bscale);
-  sprintf (field, "TZERO%d", Nfields);
-  gfits_modify (header, field, "%lf", 1, bzero);
+
+  // add scaling parameters unless they amount to a noop
+  if ((bscale != 1.0) || (bzero != 0.0)) {
+      sprintf (field, "TSCAL%d", Nfields);
+      gfits_modify (header, field, "%lf", 1, bscale);
+      sprintf (field, "TZERO%d", Nfields);
+      gfits_modify (header, field, "%lf", 1, bzero);
+  }
 
   /* update TFIELDS & NAXIS1 */
Index: trunk/Ohana/src/libfits/table/F_get_column.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_get_column.c	(revision 26371)
+++ trunk/Ohana/src/libfits/table/F_get_column.c	(revision 26384)
@@ -1,4 +1,5 @@
 # include <ohana.h>
 # include <gfitsio.h>
+#include <inttypes.h>
 # define SWAP_BYTE { \
   char tmp; \
@@ -93,4 +94,12 @@
     }
   }
+  if (!strcmp (type, "int64_t")) {
+    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
+# ifdef BYTE_SWAP
+      SWAP_DBLE;
+# endif
+      *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
+    }
+  }
   if (!strcmp (type, "float")) {
     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
@@ -218,4 +227,12 @@
 # endif
       *(int *)Pout = *(int *)Pin*Bscale + Bzero;
+    }
+  }
+  if (!strcmp (type, "int64_t")) {
+    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
+# ifdef BYTE_SWAP
+      SWAP_DBLE;
+# endif
+      *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
     }
   }
@@ -349,4 +366,12 @@
     }
   }
+  if (!strcmp (type, "int64_t")) {
+    ALLOCATE (array, char, Ny*8);
+    Pout = array;
+    for (i = 0; i < Ny; i++, Pin+=Nx, Pout+=8) {
+      memcpy (line, Pin, Nval*Nbytes);
+      sscanf (line, "%" PRId64, (int64_t *)Pout);
+    }
+  }
   if (!strcmp (type, "float")) {
     ALLOCATE (array, char, Ny*4);
Index: trunk/Ohana/src/libfits/table/F_table_format.c
===================================================================
--- trunk/Ohana/src/libfits/table/F_table_format.c	(revision 26371)
+++ trunk/Ohana/src/libfits/table/F_table_format.c	(revision 26384)
@@ -17,16 +17,44 @@
 
   *Nbytes = 0;
-  if (*Fchar == 'X') { *Nbytes = 1;  strcpy (type, "char");   *Nval = 1 + (int) Nv / 8; }
-  if (*Fchar == 'L') { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
-  if (*Fchar == 'A') { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
-  if (*Fchar == 'B') { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
-  if (*Fchar == 'I') { *Nbytes = 2;  strcpy (type, "short");  *Nval = Nv;               }
-  if (*Fchar == 'J') { *Nbytes = 4;  strcpy (type, "int");    *Nval = Nv;               }
-  if (*Fchar == 'E') { *Nbytes = 4;  strcpy (type, "float");  *Nval = Nv;               }
-  if (*Fchar == 'D') { *Nbytes = 8;  strcpy (type, "double"); *Nval = Nv;               }
-  if (*Fchar == 'P') { *Nbytes = 8;  strcpy (type, "var");    *Nval = 2*Nv;             }
-  if (*Fchar == 'C') { *Nbytes = 8;  strcpy (type, "float");  *Nval = 2*Nv;             }
-  if (*Fchar == 'M') { *Nbytes = 16; strcpy (type, "double"); *Nval = 2*Nv;             }
-  if (!*Nbytes) { return (FALSE); }
+  switch (*Fchar) {
+  case  'X':
+    { *Nbytes = 1;  strcpy (type, "char");   *Nval = 1 + (int) Nv / 8; }
+    break;
+  case  'L':
+    { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
+    break;
+  case  'A':
+    { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
+    break;
+  case  'B':
+    { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
+    break;
+  case  'I':
+    { *Nbytes = 2;  strcpy (type, "short");  *Nval = Nv;               }
+    break;
+  case  'J':
+    { *Nbytes = 4;  strcpy (type, "int");    *Nval = Nv;               }
+    break;
+  case  'K':
+    { *Nbytes = 8;  strcpy (type, "int64_t"); *Nval = Nv;              }
+    break;
+  case  'E':
+    { *Nbytes = 4;  strcpy (type, "float");  *Nval = Nv;               }
+    break;
+  case  'D':
+    { *Nbytes = 8;  strcpy (type, "double"); *Nval = Nv;               }
+    break;
+  case  'P':
+    { *Nbytes = 8;  strcpy (type, "var");    *Nval = 2*Nv;             }
+    break;
+  case  'C':
+    { *Nbytes = 8;  strcpy (type, "float");  *Nval = 2*Nv;             }
+    break;
+  case  'M':
+    { *Nbytes = 16; strcpy (type, "double"); *Nval = 2*Nv;             }
+    break;
+  default:
+    return (FALSE);
+  }
 
   return (TRUE);
@@ -39,4 +67,5 @@
    I - 16 bit int
    J - 32 bit int
+   K - 64 bit int
    A - char
    E - float 
@@ -199,4 +228,5 @@
   short *tmpShort;
   int *tmpInt;
+  int64_t *tmpInt64;
 
   off = 0;
@@ -229,4 +259,8 @@
 	continue;
     }
+    if ((tscale == 1.0) && (tzero == 0.0)) {
+	off += Nchar; 
+	continue;
+    }
 
     if (!strcmp (type, "char"))   { 
@@ -252,4 +286,12 @@
 	  *tmpInt = *tmpInt * tscale + tzero;
 	}
+      }
+    }
+    if (!strcmp (type, "int64_t"))   { 
+      for (j = 0; j < Ny; j++) {
+        for (n = 0; n < Nval; n++) {
+          tmpInt64 = (int64_t *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
+          *tmpInt64 = *tmpInt64 * tscale + tzero;
+        }
       }
     }
@@ -269,4 +311,5 @@
   short *tmpShort;
   int *tmpInt;
+  int64_t *tmpInt64;
 
   off = 0;
@@ -299,4 +342,8 @@
 	continue;
     }
+    if ((tscale == 1.0) && (tzero == 0.0)) {
+	off += Nchar; 
+	continue;
+    }
 
     if (!strcmp (type, "char"))   { 
@@ -324,4 +371,12 @@
       }
     }
+    if (!strcmp (type, "int64_t"))   { 
+      for (j = 0; j < Ny; j++) {
+	for (n = 0; n < Nval; n++) {
+	  tmpInt64 = (int64_t *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
+	  *tmpInt64 = *tmpInt64 * tscale + tzero;
+	}
+      }
+    }
     off += Nchar;
   }
Index: trunk/Ohana/src/tools/src/ftable.c
===================================================================
--- trunk/Ohana/src/tools/src/ftable.c	(revision 26371)
+++ trunk/Ohana/src/tools/src/ftable.c	(revision 26384)
@@ -361,4 +361,8 @@
 	    memcpy (line, &data[i*Nv*Nb + Nb*j], Nb);
 	    fprintf (stdout, "%d ", *(int *)line);
+	  }
+	  if (!strcmp (type, "int64_t")) {
+	    memcpy (line, &data[i*Nv*Nb + Nb*j], Nb);
+	    fprintf (stdout, "%d ", *(int64_t*)line);
 	  }
 	  if (!strcmp (type, "float")) {
